Repository navigation
refactor(checks): one function per file across attestation_guard and platforms_mirror - #1102
Merged
Merged
Conversation
…platforms_mirror Splits the last modules in internals/checks/src that carried more than one over-threshold module-scope function, taking the package to zero one-function-per-file violations at max_lines = 1. Each module keeps its named export and the private helpers move out, one function per module with a colocated unit test: - attestation_guard/gate.py keeps run; verdict moves to verdict.py - attestation_guard/git_ops.py splits into deleted_files.py and commit_messages.py - attestation_guard/report.py keeps report; the two annotation builders move to deletion_annotation.py and near_miss_annotation.py - platforms_mirror/gate.py keeps run; read moves to read.py - platforms_mirror/typescript_table.py keeps typescript_table; requoted, without_comments (with its token regex) and as_json move to their own modules Pure refactor -- no behavior change.
…namespace The two extracted helpers are patched by string rather than imported, so the unit test keeps its isolation while asserting that typescript_table resolves without_comments and as_json in its own module namespace.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Final lane of the
one-function-per-fileratchet campaign.internals/checks/srcwas the last source root with violations at the strictest threshold; this takes it to zero atmax_lines = 1.Fixes #1101
Scope note
The issue listed four violations, all in
attestation_guard. Re-measuring onmainfound eight —platforms_mirror/gate.pyandplatforms_mirror/typescript_table.pycarry four more that a threshold-12 pass left behind. All eight are fixed here, since the goal is zero for the root.Holder choices
Every split keeps the module's named export in place and moves the private helpers out, one function per module with a colocated test — matching the convention the earlier
platforms_mirrorsplits established (problems.py::problems,literal.py::literal, …).attestation_guard/gate.pyrunverdict→verdict.pyrunis the composition rootcli.pyimports. Keeping it in place leaves its*keyword-only marker out of the diff, so the mutant that needed a dedicated assertion when #1052 landed is not re-litigated.attestation_guard/git_ops.pydeleted_files.py,commit_messages.pyattestation_guard/report.pyreportdeletion_annotation,near_miss_annotationreportowns the_ADVICEconstant. Keeping it means no constant moves, avoiding the known "moved constant survives mutation" trap.restore_commandis a 1-line body — invisible to the rule — and stays withreportand_ADVICE.platforms_mirror/gate.pyrunread→read.pyrunis 22 lines of f-strings; moving it would put all of them in the diff for the mutation gate. Moving the 2-linereadchanges almost nothing.platforms_mirror/typescript_table.pytypescript_tablerequoted,without_comments(with_TOKENS),as_jsontypescript_tablecarries the threeParseErrormessages._TOKENSmoves withwithout_comments, its only caller;without_comments_test.pycovers all five alternation branches so a mutated regex cannot survive.Verification
just preflight --conventions .github/workflows/internals-checks-ci.yml— 0 failing pairs, 0 skipped (colocated-test,one-function-per-file,unit-lint,integration-lint,unit-coverage,mutation,e2e-verify,declared-deps,uv-sync).unit mutation: 25 mutants, zero survivors. No exemptions added; the repo's exemption count stays at zero.Violation count for
internals/checks/srcatmax_lines = 1, measured with a/tmpcopy of the config (no repo config was touched — the threshold change is a separate PR):Also 0 on
0.0.115, which is npmlatestas of this PR — it moved up from0.0.111mid-flight.Manual run
The failure path was exercised directly with an injected deletion plus a misspelled bypass line; it emits the per-file annotation, the near-miss diagnostic, the restore command and the advice — byte-identical to the pre-split output.
E2E Verification
packages/pythonchangepackages/tschangepackages/rustchangepackages/python/e2e-attestations/<branch>.jsonreceipt written ifpackages/pythonchanged — N/Apackages/ts/e2e-attestations/<branch>.jsonreceipt written ifpackages/tschanged — N/Ajust e2e-attest-internals-checks(uv run python -m pytest tests/e2e -x -qininternals/checks)internals/checks/e2e-attestations/claude-ofpf-attestation-guard-split-r7m2.json;git show --staton that commit shows one file added and no sibling receipts deleted.Changelog / Migrations
<root>/<pkg>/changelog.d/— not required.internals/**is outside changelog-gate scope:changelog_gate/decide.pysets_ROOTS = ("packages", "plugins").<root>/<pkg>/migrations.d/— not required; pure refactor, no public API and no behavior change.PARITY.mdis unaffected — no SDK public API is touched.