Skip to content

Commit 19471e3

Browse files
committed
fix(oracle): match test/doc markers on directory segments only, not the filename
The dotted-component match in _is_test_path also examined the FILE name (the last path segment), so a product finding in a file literally named 'Test.cs' / 'Doc.cs' / 'Foo.Tests.cs' was dropped from the product diff (under-counting real findings). Iterate directory segments only (segs[:-1]); the file's own name no longer classifies it as non-product. Test-*directories* (Newtonsoft.Json.Tests, src/Test/) still drop. Adds selftest negatives for the marker-named product files. (Codex P2 on #147.) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011YMngnax1jsy378fSAZb9r
1 parent e661573 commit 19471e3

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

‎scripts/oracle_compare.py‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,13 @@ def _is_test_path(path: str) -> bool:
378378
(e.g. Polly's `src/Snippets/Docs/*`, where ~20 `HttpResponseMessage`/`HttpClient`
379379
examples are never disposed by design) — counting them as product leaks inflates
380380
the oracle-only recall gap with example code that was never meant to dispose."""
381-
for seg in path.lower().split("/"):
382-
# Split each segment on '.' before matching, for the ubiquitous .NET
381+
# Only DIRECTORY segments classify a finding as non-product — NEVER the file's own
382+
# name (the last segment). A product file literally named `Test.cs` / `Doc.cs` /
383+
# `Foo.Tests.cs` is real product code and must NOT be dropped from the diff, or we
384+
# under-count findings (Codex). So iterate the directory segments only (`segs[:-1]`).
385+
segs = path.lower().split("/")
386+
for seg in segs[:-1]:
387+
# Split each directory segment on '.' before matching, for the ubiquitous .NET
383388
# `<Project>.Tests` / `Foo.Benchmarks` directory convention: the dir
384389
# `Newtonsoft.Json.Tests` is ONE path segment, so a bare-segment check
385390
# misses it (and silently drags ~485 test findings into the diff). Matching
@@ -576,10 +581,13 @@ def _selftest() -> int:
576581
fails.append("_is_test_path should match dotted .NET test/benchmark project dirs")
577582
# ...but a product dir whose name merely *starts with* a marker word is NOT
578583
# excluded — exact match for snippet/doc guards against dropping real code, and
579-
# the dot-split must leave a non-test dotted product namespace untouched.
584+
# the dot-split must leave a non-test dotted product namespace untouched. Critically,
585+
# the dot-split must NOT look at the FILE name: a product file literally named
586+
# `Test.cs` / `Doc.cs` / `Foo.Tests.cs` is real code, not a test tree (Codex).
580587
if any(_is_test_path(p) for p in ("Dapper/SqlMapper.cs", "src/Lib/A.cs",
581588
"src/SnippetEngine/Foo.cs", "src/Documentation/Api.cs",
582-
"Src/Newtonsoft.Json/JsonSerializer.cs")):
589+
"Src/Newtonsoft.Json/JsonSerializer.cs",
590+
"src/Test.cs", "src/Doc.cs", "src/Foo.Tests.cs")):
583591
fails.append("_is_test_path should not match product paths")
584592
# the scope note is gated on mode, not count: a product-only run that excluded
585593
# nothing must still say so (else it reads like a full-scope run).

0 commit comments

Comments
 (0)