Repository navigation
fix: a gate that cannot see all of its input stops with exit 2 (PL-1822) - #125
Conversation
…-1822)
`oo-ratchet coupling SRC --threshold` exited 0 when a module did not parse:
it printed an empty row for the file and a PASS table over the modules that
did parse. The `oo` view exited 1 with the same empty row and no cause.
Both views now exit 2 when any module failed to parse, and the table views
end with one line per such module naming the cause:
ERROR: pkg/bad.py could not be parsed: invalid syntax (bad.py, line 1)
The JSON views keep the {"file", "error"} row and exit 2. `--check` and
`--update` are unchanged: they already fail on a touched unparseable module.
Failing on the unfixed code (tests/incomplete_scan/test_unparseable_module.py,
first draft of the same cases):
FAILED ...test_threshold_view_exits_2_naming_the_file[coupling]
pkg/bad.py (empty row) assert 0 == 2
FAILED ...test_threshold_view_exits_2_naming_the_file[oo]
pkg/bad.py (empty row) assert 1 == 2
FAILED ...test_json_view_exits_2 assert 0 == 2
Passing after the fix:
uv run pytest tests/incomplete_scan/test_unparseable_module.py -m ""
....... [100%]
Two characterizations pinned the old exit 1 for an oo view over a broken
module (tests/oo/test_oo_scoring_domain.py, tests/test_qodo_fixes.py); they
now pin exit 2 and the ERROR line.
…L-1822)
`Sources.files` enumerated modules with `Path.rglob`, which skips a directory
it cannot read without a word. A package with an unreadable subdirectory was
scored without it, so oo, coupling, suppressions, design and layers could all
pass without measuring that code.
The enumeration now walks the tree with `Path.walk(on_error=...)`, and a
listing error raises the new `IncompleteScanError` (core/domain/errors.py).
It is neither an `OSError` nor a `StateError`, so no gate's "unreadable file"
handler can turn it into an error row or a plain FAIL. The dispatcher
(`__main__.Dispatcher._call`) catches it for every gate and exits 2:
oo-ratchet coupling: error: incomplete scan: cannot read pkg/locked: Permission denied
Failing on the unfixed code (pkg/locked at mode 000, first draft):
FAILED ...test_gate_exits_2_naming_the_directory[coupling] assert 0 == 2
FAILED ...test_gate_exits_2_naming_the_directory[oo] assert 0 == 2
FAILED ...test_gate_exits_2_naming_the_directory[suppressions]
"total": 0, "by_file": {} assert 0 == 2
FAILED ...test_gate_exits_2_naming_the_directory[design]
"files_scanned": 1 assert 0 == 2
Passing after the fix:
uv run pytest tests/incomplete_scan/test_unreadable_directory.py -m ""
........ [100%]
(coupling --threshold/--json, oo --threshold/--check, suppressions, design,
layers, and an --namespace scan.)
…sitory" (PL-1822)
`GitRepo` found its root with `git rev-parse --show-toplevel` through `_run`,
which dropped git's stderr and returned None for every nonzero exit. A
checkout git refuses to open ("detected dubious ownership", an unsupported
`core.repositoryformatversion`) therefore looked like a directory outside any
repository, and the gates fell back to the cwd for config and cap keys.
`GitRepo._toplevel` now reads git's answer (in the C locale): only "not a git
repository (or any ...)" is absence, a state the gates handle. Any other
refusal, and a git that times out, raises `IncompleteScanError`, which the
dispatcher turns into exit 2 with git's own message:
oo-ratchet coupling: error: incomplete scan: git refused the repository at
/.../repo: fatal: detected dubious ownership in repository at '/.../repo' ...
A missing git binary is still "git unavailable", as before.
Failing on the unfixed code (first draft of the same cases):
FAILED ...test_dubious_ownership_exits_2_with_gits_message assert 0 == 2
FAILED ...test_unsupported_repository_format_exits_2 assert 0 == 2
Passing after the fix:
uv run pytest tests/incomplete_scan/test_git_refusal.py -m ""
..... [100%]
(dubious ownership through coupling --threshold, oo --check and suppressions
--check via git's GIT_TEST_ASSUME_DIFFERENT_OWNER; repository format 99; and a
directory outside any repository still scans with exit 0.)
…L-1822)
`SourceSelection.name`, the package spelling coupling import resolution used,
was `self.anchor.name`. For `oo-ratchet coupling .` run inside the package
that is `Path(".").name == ""`, so no absolute import (`from pkg.b import x`)
resolved: a real import cycle reported 0 and efferent coupling dropped to 0,
while the same package scanned from its parent reported the cycle.
The count was right for the edges it saw; the package name was wrong. The
fix removes `name` and uses `package_name`, which already derived the name
from the normalized absolute anchor (unresolved, so a symlinked package keeps
the name it was given). `ModuleSource` loses its `name` member; coupling's
TreeScan and design's ShadowScan read `package_name`.
Failing on the unfixed code (first draft):
FAILED ...test_cycle_count_does_not_depend_on_cwd
{'efferent_coupling': 0.0} != {'efferent_coupling': 1.0}
{'circular_imports': 0.0} != {'circular_imports': 1.0}
Passing after the fix:
uv run pytest tests/incomplete_scan/test_scan_from_inside.py -m ""
.... [100%]
(JSON equal from both cwds; `coupling .`, `../pkg` and `./` from inside all
FAIL circular_imports 1.00.)
…eline (PL-1822) REFERENCE.md gains an Incomplete Scans section. CHANGELOG names the adopters vox, quarry, lux, z-spec and punt-kit. oo-baseline/audit come from make update-oo with --base-ref 7b04026 --require-base (no regression). The coupling baseline is not in this commit: update-coupling refused three rows (see the unit report).
…ord exit 2 (PL-1822) The Path.walk enumeration dropped a directory named *.py, which rglob yielded; the scorers then failed on reading it. tests/suppression/test_suppression_ratchet.py TestSuppressionFailClosed failed on the walk (DID NOT RAISE OSError; main() == 0 instead of 1) and passes again. The core_real coupling and oo view transcripts recorded exit 0/1 for a --json view over an unparseable module; they now record exit 2 (one code field each).
…(PL-1822) One new error type for an incomplete scan: defined in core/domain/errors.py (public_names 2 -> 3), raised by sources.py (efferent_coupling 0 -> 1), caught by the dispatcher in __main__.py (efferent_coupling 4 -> 5). Blessed with --rebaseline-files and a recorded reason; oo/scoring.py and source_set.py LCOM improved. check-coupling against 7b04026: three rows RELAXED, four IMPROVED, 'PASS: no regressions'.
…ery ratchet action with exit 2 (PL-1822)
Review round 1, items 1, 2 and 4.
1. `--check` kept only parse errors in touched files (core/application/
check.py), so an unparseable module outside the diff passed: "No Python
files touched -- trivial pass". `--update` refused only the touched one and
wrote the rest. `Measurement.complete()` now raises `IncompleteScanError`
when any module in the scan did not parse; Check (before it resolves a base,
so a first adoption is stopped too), Update, Reconcile and the waive actions
call it before any verdict or write. The parse-error / parse-refused
verdict paths that no operation can produce any more are deleted from
update.py, oocli, couplingview, gatecli and outcomelog.
2. An unreadable touched module exited 1 with "touched file(s) failed to
parse". Reading moved to one place, `Sources.text` (through
`SourceSelection.text`), which raises `cannot read <file>: <reason>`
(permissions, not UTF-8, a directory named like a module); a syntax error
is still an error row, a different message.
4. coupling/trees.py read a package `__init__.py` and treated an OSError as
"absent" for package metrics; it now reads through `Sources.text`.
design/output.py adds `IncompleteScanError` to the errors it reports as exit 2.
Failing on the unfixed code (tests/incomplete_scan/test_ratchet_scan.py):
test_check_exits_2_on_an_untouched_unparseable_module[oo]
No Python files touched -- trivial pass assert 0 == 2
test_check_exits_2_on_an_untouched_unparseable_module[coupling]
No scored Python files touched assert 0 == 2
test_check_exits_2_on_a_touched_unparseable_module[oo|coupling]
FAIL: touched file(s) failed to parse: pkg/a.py assert 1 == 2
test_update_exits_2_on_an_unparseable_module_and_writes_nothing[oo]
Baseline updated ... files improved: 0 assert 0 == 2
test_check_exits_2_on_an_unreadable_touched_module[oo|coupling]
FAIL: touched file(s) failed to parse: pkg/a.py assert 1 == 2
test_coupling_exits_2_on_an_unreadable_package_init
exit 2 via an error row, no "cannot read pkg/sub/__init__.py"
Passing after the fix:
uv run pytest tests/incomplete_scan -m ""
........................................ [100%]
22 existing tests and recorded transcripts pinned "row kept, exit 1" for an
unparseable or undecodable module; they now pin IncompleteScanError and that
nothing was written (four coupling transcripts re-recorded, diff checked:
only code, the message line, and no first-adoption write; two unused OO golden
entries dropped; the design encoding scenario now reads "cannot read ...: not
UTF-8"). test_update_backfill's "failure" scenario uses a metric regression
instead of a syntax error, since a syntax error no longer reaches the writer.
…ing ref is unresolved (PL-1822)
Review round 1, items 3, 5 and 6.
3. `GitRepo.resolve` read every nonzero git exit, and a missing git binary, as
"unresolved"; without --require-base and with no baseline that passed as a
first adoption (bases.py). It now asks git whether the ref names anything
(`rev-parse --verify --quiet`, exit 1 with no message = absent), then peels
it. A named ref that points at a missing object, a merge base git cannot
compute, and a git that cannot start raise IncompleteScanError with git's
message. A literal object id the repository lacks (a shallow clone, a typo)
and a ref that does not exist stay unresolved, as do origin/main and HEAD
sharing no history. `_run` callers keep their None-on-failure contract; a
timeout reads as a failed call.
5. `_toplevel` ran git with cwd = the source; for a single-file source that
raised "[Errno 20] Not a directory". It now runs in the file's directory;
a source not on disk is outside any repository, as before.
6. Every git call from GitRepo runs with LC_ALL=C and LANGUAGE=C (one `_call`),
so "not a git repository" and the ref answers read the same in any locale.
Failing on the unfixed code (tests/incomplete_scan/test_git_failures.py):
test_a_merge_base_git_cannot_compute_exits_2[oo|coupling]
No base and no in-tree baseline -- first-adoption bootstrap pass
assert 0 == 2
test_a_base_ref_naming_a_missing_commit_exits_2 assert 0 == 2
test_a_missing_git_binary_exits_2
git did not run ...; treating it as unavailable ... bootstrap pass
assert 0 == 2
test_a_single_file_source_finds_its_repository
oo-ratchet goal: [Errno 20] Not a directory: PosixPath('pkg/a.py')
Passing after the fix:
uv run pytest tests/incomplete_scan -m ""
........................................ [100%]
test_git_is_read_in_the_c_locale (de_DE locale, outside a repository: exit 0,
every git call carries LC_ALL=C) passes on this host's git either way; it
guards the override. tests/design/test_design_snapshot.py's fake
subprocess.run now accepts and passes through `env`.
…o and coupling baselines (PL-1822) REFERENCE.md: every ratchet action stops on a module that does not parse anywhere in the scan; an unreadable module has its own message; the --update and files_regressed rows no longer describe kept parse-error rows. docs/ratchet.tex: OUTCOME gains incompleteScan (exit 2); new Scan, CompleteScan and IncompleteScan schemas; OoCheck, CplCheck and NeverLoosenUpdate include CompleteScan in place of brokenTouched/parseErrTouched. fuzz -t type-checks it with no errors. CHANGELOG names the round-1 behavior changes for vox, quarry, lux, z-spec and punt-kit. oo baseline/audit from make update-oo, coupling baseline/audit from make update-coupling plus the leader's bless of scores.py efferent_coupling 0 -> 1, all with --base-ref 7b04026 --require-base; check-oo and check-coupling both PASS.
…anError coupling rows (PL-1822)
… (PL-1822)
Path.glob skipped a directory it could not list, so roots = ["parts/*/ns"]
with parts/b at mode 000 dropped parts/b/ns from the scan and oo/coupling
--check passed a regressed module there. Root patterns now expand segment by
segment with os.scandir and raise IncompleteScanError on any listing error.
Before:
FAILED test_glob_root_over_unlistable_directory_exits_2[oo]
AssertionError: No Python files touched -- trivial pass; assert 0 == 2
FAILED test_glob_root_over_unlistable_directory_exits_2[coupling]
AssertionError: No scored Python files touched; assert 0 == 2
After:
tests/incomplete_scan/test_unreadable_directory.py: 10 passed
… (PL-1822)
The audit compared only the parse-clean files with the baseline, so an
unbaselined module that did not parse was invisible and the audit printed
PASS. It now reads the measurement through Measurement.complete(), as every
other oo action does.
Before:
FAILED test_audit_completeness_exits_2_on_an_unbaselined_unparseable_module
AssertionError: PASS: baseline complete for 2 scored files; assert 0 == 2
After:
tests/incomplete_scan/test_unparseable_module.py: 8 passed
…dule (PL-1822)
test_missing_file_flagged_hidden_and_broken_excluded pinned the bug the
previous commit fixed: it expected --audit-completeness to report on the
parse-clean files and leave sub/broken.py out. Split it: hidden files are
still excluded, and an unparseable module now raises IncompleteScanError.
Before (after the fix, old test):
FAILED TestCompleteness::test_missing_file_flagged_hidden_and_broken_excluded
IncompleteScanError: sub/broken.py could not be parsed
After:
tests/oo/test_oo_ratchet.py -k Completeness: 3 passed
suppressions read modules with tokenize.open and caught OSError and UnicodeDecodeError into a plain FAIL (exit 1). ModuleIndex caught read and decode errors into its skipped list, so layers exited 1 (FAIL: cannot read or parse) and design exited 0 listing the module as skipped. Reads now go through Sources.text, which raises IncompleteScanError, and nothing downgrades it: suppressions falls back to Sources.text when its cookie-aware read fails, SourceSelection.read_source uses Sources.text, and ModuleIndex catches only SyntaxError and ValueError. layers exits 2 on a skipped (unparseable) module too; design keeps it advisory in skipped. REFERENCE, DESIGN and the CHANGELOG PL-1822 entry describe the new exits. Before (tests/incomplete_scan/test_unreadable_file.py): 11 failed, 1 passed, e.g. layers: FAIL: cannot read or parse: pkg/locked.py; assert 1 == 2 design: ... skipped (unparseable): pkg/locked.py; assert 0 == 2 suppressions: FAIL: [Errno 13] Permission denied: 'pkg/locked.py'; assert 1 == 2 suppressions: FAIL: 'utf-8' codec can't decode byte 0xe9 ...; assert 1 == 2 layers bad.py: FAIL: cannot read or parse: pkg/bad.py; assert 1 == 2 After: tests/incomplete_scan: 55 passed Three suppressions tests and one layers test pinned the old exit 1 and were moved to IncompleteScanError.
GitRepo.show and exists_at ran git in the user's locale, but _absent reads
git's English "does not exist in". Under a translated git a missing
baseline or path raised GitError instead of reading as absent. Both now go
through _call, which sets LC_ALL=C and LANGUAGE=C; a missing git binary now
stops the scan (exit 2) as it does for every other git call.
Before:
FAILED test_a_translated_git_still_reads_a_missing_path_as_absent
GitError: git show HEAD:missing.json errored: Schwerwiegend: Pfad
'missing.json' existiert nicht in 'HEAD'
After:
tests/incomplete_scan: 56 passed
…-1822) make update-oo with --base-ref d4bda73 --require-base: pass, 0 regressed. make update-coupling refused src/oo_ratchet/layers/scan.py (efferent_coupling regressed: it now imports core.domain.errors for IncompleteScanError); its coupling baseline is unchanged and the refusal is in the audit log.
…canError (PL-1822)
…chive locale exit 2 (PL-1822)
Q1: oo on a single file that does not parse returned 'FAIL: cannot score'
(exit 1) before the incomplete-scan handling ran. OoGate._unscorable is
deleted: the view now exits 2 with 'ERROR: <file> could not be parsed:
<cause>' and the actions stop with 'incomplete scan: <file> could not be
parsed', as for a directory.
R3b: on Python 3.14 Path.exists is False on EACCES, so a source under a
mode-600 directory printed 'Not found' (exit 1). The source guards in oo,
coupling, suppressions, layers and goal (cli, summary, next, propose) now ask
Sources.present, which uses Presence and turns 'cannot tell' into
IncompleteScanError. GitRepo._toplevel uses Presence too, so it no longer
reads 'cannot tell' as 'not in a repository'.
L1 scope: archive_paths now runs git with the same C-locale environment as
_call, show and exists_at (GitRepo._c_locale). New tests cover a translated
git end to end: a first-adoption --check, a spy over every git call a --check
makes (including git show), and archive_paths.
H2: the --audit-completeness test moves to test_ratchet_scan.py, and the
CHANGELOG and REFERENCE action lists name --audit-completeness. REFERENCE's
Incomplete Scans section names design's advisory exception.
Two older tests pinned 'FAIL: cannot score' exit 1 and now expect exit 2 /
IncompleteScanError; the stale golden row test_target_missing_and_unscorable#1
is removed.
Before (src changes reverted, new tests kept):
FAILED test_single_file_view_exits_2_naming_the_file[argv0,argv1]
AssertionError: FAIL: cannot score pkg/bad.py; assert 1 == 2
FAILED test_single_file_check_exits_2_naming_the_file
AssertionError: FAIL: cannot score pkg/bad.py; assert 1 == 2
FAILED test_source_under_an_unlistable_parent_exits_2[oo,coupling,layers]
AssertionError: Not found: outer/pkg; assert 1 == 2
FAILED test_source_under_an_unlistable_parent_exits_2[suppressions]
AssertionError: not found: outer/pkg; assert 1 == 2
FAILED test_source_under_an_unlistable_parent_exits_2[goal]
oo-ratchet goal: Not found: outer/pkg
FAILED test_repository_lookup_under_an_unlistable_parent_raises
DID NOT RAISE PresenceError
FAILED test_archive_paths_runs_git_in_the_c_locale (env not C)
Before L1 (gitrepo.py at 6711f86):
FAILED test_a_first_adoption_check_passes_under_a_translated_git
FAIL: git show ...:.punt-labs/oo-ratchet/oo-baseline.json errored:
Schwerwiegend: Pfad ... existiert nicht in ...; assert 1 == 0
FAILED test_a_check_reads_every_git_answer_in_the_c_locale (same)
After:
tests/core_real/test_oo_gate.py tests/test_qodo_fixes.py
tests/incomplete_scan: 143 passed
… (PL-1822) The coupling update refused the previous commit's new imports: goal flows imported source_set at runtime, gitrepo imported presence, and a second SourceSelection method broke the class's method cap. - SourceSelection gets one method, exists(); gate_options and oogate build a SourceSelection, the goal flows call it on theirs (no new imports). - GitRepo._mode stats the start path itself and raises IncompleteScanError on 'cannot tell' (exit 2, not a PresenceError FAIL); _toplevel stays under the complexity target. make update-oo: pass, 0 regressed. make update-coupling refused src/oo_ratchet/core/adapters/oogate.py max_lcom/avg_lcom (0.038 -> 0.077) after deleting _unscorable; left unblessed. tests/test_class_debt_sources.py failed with 25 > 24 methods before this change and passes after; tests/incomplete_scan, tests/core_real, tests/oo, tests/goal, tests/test_qodo_fixes.py all pass.
… (PL-1822) check-design --enforce found three added size-cap findings (classes over 25 methods): Sources, SourceSelection and GitRepo. - The root-glob expansion moves to a private _RootPattern class in sources.py. Its ** walk no longer asks Path.is_dir, which is False on 3.14 when stat fails. - SourceSelection.exists is gone. The source guard is GateOptions.present (Sources.present), and the Requested protocol carries it for OoGate. - GitRepo's C-locale env and stat helper become module functions. - goal propose now checks its source first, as goal show does. Its flows printed 'Not found' for a source under an unsearchable parent; the test_source_under_an_unlistable_parent_exits_2[argv5] case failed with 'oo-ratchet goal: Not found: outer/pkg' without the guard and passes with it. check-design --base-ref d4bda73 --enforce: neutral, 0 tier0/tier1 added. make update-oo: pass. Full make test on this tree: 3489 passed, 4 skipped.
A reset or reconcile over a module that does not parse, or a directory it cannot list, now stops with IncompleteScanError (exit 2) before PR 124's coverage check; the five rebaseline-scope tests that expected exit 1 now expect that, and still assert nothing is written.
PR Summary by Qodofix: a gate that cannot see all of its input stops with exit 2 (PL-1822)
AI Description
Merge Risk
|
Code Review by Qodo
1.
|
…b Actions (PL-1822)
CI failed 13 incomplete_scan tests: their --update seeding refused under
GITHUB_ACTIONS ('refusing to write baseline under GITHUB_ACTIONS without
--allow-ci-write'), and the dubious-ownership test passed as a first adoption
because actions/checkout trusts every directory in the runner's global git
config. An autouse fixture unsets GITHUB_ACTIONS for these tests, and the
ownership test points git at an empty global config.
Proof: tests/incomplete_scan passes with GITHUB_ACTIONS=true and a global
config of safe.directory='*'.
…o worktree-agent-aa079e9156c7da6be
…ixer's two commits (PL-1822) The Qodo Fixer's e6d48fa reported every decode failure as 'not valid under its declared encoding', including a module with no cookie (UTF-8 by default), so test_non_utf8_module_exits_2_naming_it[suppressions] failed: 'cannot read pkg/latin.py: not UTF-8' was no longer printed. A UTF-8 decode failure now falls back to SourceSelection.text, which names it; only another declared encoding gets the cookie message. New tests: - test_glob_root_matches_with_the_platforms_case_rule: with a case-folding normcase, parts/*/App* matches parts/x/app. Before 7a29076 (fnmatchcase): 'assert [] == [.../parts/x/app]'. After: passes. - test_suppressions_refuses_a_module_its_coding_cookie_rejects: an ascii cookie over UTF-8 text exits 2.
|
verified: 0122767
|
What changed
Fixes PL-1822. A gate that cannot see all of its input now stops with exit 2 and names the cause, instead of passing over the part it read (
IncompleteScanError).The full list is the PL-1822 entry in CHANGELOG.md and "Incomplete Scans" in docs/REFERENCE.md.
Parsing. A module anywhere in the scan that does not parse stops every ratchet action with exit 2, touched or not, and nothing is written. This covers
--check,--update,--reconcile,--rebaseline,--relax,--rebaseline-filesandoo --audit-completeness.Unreadable input. Each of these exits 2, in every gate:
git.
Smaller changes.
coupling .names the package from the absolute path.designwithout--base-refstays advisory on a syntax error. A read or decode failure still exits 2.Baseline and audit formats are unchanged. PR #124's partial-source refusal still applies. A reset over a module that does not parse now stops earlier, with exit 2 (
incomplete scan), rather than exit 1; nothing is written in either case.How it was proven
Tests under
tests/incomplete_scan/, each failing before its fix. They cover:--audit-completeness.Local review ran two rounds (code-reviewer, silent-failure-hunter, qodo). It found two High wrong-passes (the root glob and
--audit-completeness), which are fixed. Every other finding is fixed, each with a test that fails first.Ratchet rows that rose were blessed with audited reasons (
--source PL-1822):errors.pygained one public name;sources.pyandlayers/scan.pyimport the new error;oogate.pyLCOM rose to 0.077 after deleting_unscorable.Demo
demo confirmed: 0122767
Built a git repo with
pkg/a.pyandpkg/sub/s.pybaselined, then broke it in two ways. Same script,main(c72f4cd) against this branch (0122767), both installed: