Debian Codegraph @

scripts/test-fidelity-report.sh

raw
1 #!/usr/bin/env bash
2
3 set -euo pipefail
4
5 python3 - <<'PY'
6 from pathlib import Path
7 import re
8
9 root = Path(".")
10 test_impl_files = sorted(
11 path
12 for path in root.rglob("*_test.go")
13 if path.is_file()
14 and ".git" not in path.parts
15 and ".worktrees" not in path.parts
16 and "build" not in path.parts
17 )
18 fixture_files = sorted(
19 path
20 for path in list(root.glob("testdata/**/*")) + list(root.glob("**/testdata/**/*")) + list(root.glob("evaluations/suites/**/*"))
21 if path.is_file()
22 and ".git" not in path.parts
23 and ".worktrees" not in path.parts
24 and "build" not in path.parts
25 )
26
27 def read(path):
28 return path.read_text(errors="ignore")
29
30 mock_terms = re.compile(r"(?<![A-Za-z0-9_-])(mock|stub|fake)(?![A-Za-z0-9_-])", re.IGNORECASE)
31 helper_terms = re.compile(r"^\s*func\s+[A-Za-z_][A-Za-z0-9_]*\s*\(", re.MULTILINE)
32 assert_terms = re.compile(r"\b(t\.Fatalf|t\.Fatal|t\.Errorf|t\.Error|cmp\.Diff|reflect\.DeepEqual|strings\.Contains)\b")
33 external_signals = {
34 "httptest_server": re.compile(r"\bhttptest\.NewServer\b"),
35 "real_shell_exec": re.compile(r"\bexec\.Command\b|/bin/sh|bash"),
36 "temp_filesystem": re.compile(r"\bt\.TempDir\b|os\.CreateTemp|os\.WriteFile|os\.Mkdir"),
37 "golden_or_fixture": re.compile(r"\btestdata\b|fixture|golden|snapshot", re.IGNORECASE),
38 "real_cli_process": re.compile(r"\bos\.Args\b|runMainHelper|runClnkrdHelper"),
39 }
40
41 print("test fidelity report")
42 print("mode: manual-report-only")
43 print(f"test_impl_files={len(test_impl_files)} fixtures={len(set(fixture_files))}")
44
45 print("test_impl:")
46 for path in test_impl_files:
47 text = read(path)
48 line_count = text.count("\n") + (1 if text else 0)
49 helpers = len(helper_terms.findall(text))
50 assertions = len(assert_terms.findall(text))
51 mocks = len(mock_terms.findall(text))
52 signal_hits = [name for name, pattern in external_signals.items() if pattern.search(text)]
53 print(
54 f"- {path}: lines={line_count} helper_defs={helpers} "
55 f"assertions={assertions} mock_words={mocks} "
56 f"integration_signals={','.join(signal_hits) if signal_hits else 'none'}"
57 )
58
59 print("fixture_summary:")
60 by_suffix = {}
61 for path in set(fixture_files):
62 by_suffix[path.suffix or "<none>"] = by_suffix.get(path.suffix or "<none>", 0) + 1
63 if by_suffix:
64 for suffix, count in sorted(by_suffix.items()):
65 print(f"- {suffix}: {count}")
66 else:
67 print("- none")
68
69 print("mock_or_fake_mentions:")
70 found = False
71 for path in test_impl_files:
72 for lineno, line in enumerate(read(path).splitlines(), start=1):
73 if mock_terms.search(line):
74 print(f"- {path}:{lineno}: {line.strip()[:160]}")
75 found = True
76 if not found:
77 print("- none")
78
79 print("integration_fidelity_signals:")
80 all_text = "\n".join(read(path) for path in test_impl_files)
81 for name, pattern in external_signals.items():
82 print(f"- {name}: {'yes' if pattern.search(all_text) else 'no'}")
83
84 print("fail_before_pass_evidence:")
85 print("- not detected automatically; record sabotage or mutation command in review notes when changing behavior")
86 PY