Skip to content

test: split three oversized test files by topic (part 1 of 2) - #20537

Merged
bolichen97 merged 1 commit into
mainfrom
refactor/linecap-t15-test-prompts
Oct 15, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
refactor/linecap-t15-test-prompts

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Bring test/test_prompts.py and test/test_runtime_reconcile.py from about 4,800 lines each to at most 1,600, and move the first half of test/test_apps_registry_coverage.py out, without changing a single test.

test/test_prompts.py (4858 lines), test/test_runtime_reconcile.py (4825) and test/test_apps_registry_coverage.py (4797) are each more than twice the 2,000-line cap the line-cap campaign enforces. A file that large is hard to navigate and to review, and every test added to one makes the eventual split bigger.

Why it matters

The maintainers' rule is that no hand-written file may exceed 2,000 lines. These three files break it, and the files' topics are already separate (discovery vs authoring, the reconciler core vs every sweep's lease gate, the registry's helpers vs its build step), so a reader looking for one topic has to scroll past the others. Splitting along those seams makes each topic findable by file name and gives each file room to grow.

Not a goal

  • Changing, renaming, fixing, de-flaking or re-parametrizing any test. Every test moves with an identical AST, except one docstring that named a neighbour by position.
  • Changing production code. Only tests, test helpers, path-keyed list rows and one prose citation change.
  • Fixing the pre-existing semgrep findings that move with their tests: they are marked, not rewritten.
  • Finishing test/test_apps_registry_coverage.py: its front half moves in part 2 of this series (one PR cannot hold all three files under the 900 KB review-diff cap).

What changed (motivation → approach → change)

Each file splits along its own section banners and test classes, grouped by the behaviour under test. The original path stays as one of the parts, as one contiguous run of its BASE code. Helpers and fixtures used by more than one part move to a non-test *_helpers.py module that every part imports by name. A recipe tool did the move from BASE, so it can be re-run after a rebase instead of hand-merged.

Origin (lines) Stays in the original New parts
test_prompts.py (4858 → 1397) discovery and reading: SOP descriptions, the listing, the discovery gate, the bounded local lookup, @mention expansion, the read API, the descriptor gate, the _run_chat paths and off-loop reads _authoring (1322): create, update and delete; _link_gates (1457): the no-link read gate, the uniform link refusal, the pinned directory, the by-name fallback, local scope, ancestor loops, a root swapped after validation; _caller_gates (463): app tokens, the placeholder session key, non-owners
test_runtime_reconcile.py (4825 → 1357) the reconciler core and the app backend table _wiring (1391): argv condition, kill budget, the cross-gateway pid union, record retraction, the notification memory, the warn-once ledger; _sweep_gates (963): the lease gate on every sweep; _tenancy (919): tenancy, the pinned identity, the barrier, the leak scan and its positive control
test_apps_registry_coverage.py (4797 → 3597) everything from the streamed-log-line tests to TestRunAppBuild (part 2 moves the front half) _install (556): install refusals and the un-poison routine; _characterization (538): behaviour a move of the registry must not change

Helper modules: prompts_helpers.py (374 lines), runtime_reconcile_helpers.py (317), apps_registry_coverage_helpers.py (184).

Glue, the only lines whose AST or comments change:

  • Fixtures that tests request by parameter are re-declared @pytest.fixture(name="x") def x_fixture(...) (the test/meetings_helpers.py convention), so a parameter never shadows an import: aim_dir, mock_sel, block_sensitive_reads, block_sensitive_discovery, agent_root, cache_dir, pip_importable, bundled_interpreter. The autouse fixtures (_isolate_home, _no_turn_tail, _explicit_registry_execution_admission) are imported into every part.
  • pytestmark = pytest.mark.keep_runtime_ownership_tables is copied into every runtime part, so each test keeps its BASE fixture behaviour. Every tenancy claim stays in _tenancy with the leak scan that reads that module's own source, and its positive control is still the module's last test.
  • Two remainder module docstrings gain a paragraph naming where the moved topics live; one new section banner heads the warn-once ledger tests; three banners stay above their sections' first tests. The runtime remainder's comment on its pytestmark is reworded to stay true (the positive control it described is in _tenancy).
  • Two moved docstrings that named a neighbour by position are corrected (L29 prose citation): TestRefusalLineVerb's build-pass test names TestRunAppBuild's root-data test, which stays in the original, and bundled_interpreter says "each case using it". This is the one test-class AST change.
  • Nine pre-existing semgrep findings move into new files. Each gets an own-line # nosemgrep: <rule> -- <reason> directly above it, code unchanged; the one sleep also gets an own-line # flake-ok: <reason>.

Rows and citations: test/requires-real-symlinks.txt re-points the 13 entries of moved prompt tests. test/wait_discipline_baseline.txt moves the registry-coverage row to test_apps_registry_coverage_characterization.py, which holds both waits (count unchanged). .github/file-line-cap-baseline.txt deletes the two finished rows and lowers the registry-coverage row to 3597. test/conftest.py's _reset_runtime_ownership_tables docstring names test_runtime_reconcile_tenancy's leak scan.

Backwards compatibility

Compatible: test-only change. Every collected test keeps its class, name and parameters (the multiset is identical before and after). No other test module imports from these three files. No production module, import path, patch target or CLI changes.

Removes nothing: every test, fixture and helper still exists, moved with an identical AST apart from the glue listed above. The two tests named by test/windows-expected-failures.txt and the reads test/test_source_pin_budget.py budgets for test/test_prompts.py stay in that file.

Tests

No test was added or rewritten. These checks show the move lost nothing:

Check Result
pytest --collect-only at BASE vs HEAD over the 3 origins + 8 new test files 797 = 797; the (class, name, params) multiset is identical
pytest --fixtures-per-test, 27 sampled tests across every part, BASE vs HEAD identical fixture closures
the 11 split test files at -n 3, HEAD and BASE 796 passed, 1 skipped on both (the same _run_chat mock skip)
guard tests: wait-discipline, gap lists, host-service, CI surface, local gate, line cap, source-pin budget, spawn env, leaked-runtime, backend record, diff signals 500 passed
test/test_flake_pattern_ratchet.py (-n0, against the merge-base) 53 passed; with the wait-discipline ratchet and the line-cap guard, 211 passed
semgrep 1.78, CI configs, --baseline-commit BASE, over the 15 changed .py files 0 findings; with --disable-nosem over the 11 new files exactly the 9 marked findings
profile backend gate floor (black, subprocess encoding, comment history, brand, agent-sdk, sync-io, harness parity, feature map, loop locks, testpaths, cwd reads, docs-lint, memory-store seam, …) 39/39 exit 0
isort / flake8 / black --check over the changed files; scripts/check_file_line_cap.py clean; 0 failures
leak-scan reach (mutation) un-binding one claim in _tenancy fails the scan (unbound at [91]); dropping one release fails it (5 claims but only 4 releases)

scripts/local-gate.py --base <BASE> --dry-run selects 463 backend and 362 frontend test files, because test/conftest.py and .github/ changed: over the ~600-file local cap, so the floor above ran instead (CI runs the full suites). The diff touches no frontend file.

Move audit

test/test_prompts.py: 4858 -> 1397 lines; moved 99.16% (python-ast)
   changed: aim_dir [FunctionDef] 17 lines                    (re-declared with name=, body unchanged)
   changed: block_sensitive_reads [FunctionDef] 12 lines      (re-declared with name=, body unchanged)
   changed: mock_sel [FunctionDef] 6 lines                    (re-declared with name=, body unchanged)
   changed: block_sensitive_discovery [FunctionDef] 3 lines   (re-declared with name=, body unchanged)
test/test_runtime_reconcile.py: 4825 -> 1357 lines; moved 98.61% (python-ast)
   changed: Expr [Expr] 55 lines                              (module docstring: names where the moved topics live)
   changed: agent_root [FunctionDef] 6 lines                  (re-declared with name=, body unchanged)
test/test_apps_registry_coverage.py: 4797 -> 3597 lines; moved 97.3% (python-ast)
   changed: TestRefusalLineVerb [ClassDef] 54 lines           (one docstring: names TestRunAppBuild's root-data test, no longer "above")
   changed: pip_importable [FunctionDef] 25 lines             (re-declared with name=, body unchanged)
   changed: bundled_interpreter [FunctionDef] 18 lines        (re-declared with name=; docstring "each case below" -> "each case using it")
   changed: Expr [Expr] 14 lines                              (module docstring: names the two new parts)
   changed: cache_dir [FunctionDef] 6 lines                   (re-declared with name=, body unchanged)

Every changed unit is glue or an L29 prose fix: the eight fixtures re-declared with name= (bodies unchanged except one phrase of bundled_interpreter's docstring), the two module docstrings, and one docstring in TestRefusalLineVerb. Comments are not in the AST, so the reworded pytestmark comment in test_runtime_reconcile.py does not show here. Every other test function and class moved with an identical AST; the units moved out of the black-baselined test_apps_registry_coverage.py are black-formatted in their new files, AST-identical. git diff origin/main...HEAD is 758,125 bytes.

Moved semgrep sites, each with an own-line marker (rule, new file): kirocrew.test-autouse-shared-monkeypatch ×6 (prompts_helpers.py ×2, test_prompts_link_gates.py, apps_registry_coverage_helpers.py, test_apps_registry_coverage_install.py, test_apps_registry_coverage_characterization.py), kirocrew.test-sleep-as-barrier ×1 (test_prompts_authoring.py, also flake-ok), kirocrew.test-bare-monkeypatch-undo ×1 (test_prompts_link_gates.py), kirocrew.mock-pid-allocatable ×1 (apps_registry_coverage_helpers.py). Semgrep cannot parse the keyword-only lambda in test_the_sweep_gate_audits_both_outcomes, as at BASE; it moves to test_runtime_reconcile_sweep_gates.py, and the other runtime parts now parse fully with no finding.

Diff alignment: each original keeps one contiguous run of its BASE code after its header, and git diff BASE -- <file> and git diff --minimal BASE -- <file> add the same lines (--numstat): test_prompts.py 16/16, test_runtime_reconcile.py 11/11, test_apps_registry_coverage.py 16/16 (import, docstring and comment glue only).

Logger names: no new module defines a logger; moved caplog tests read production loggers.

Content scan: the moved literals the internal scan could read are AKIAIOSFODNN7EXAMPLE (the documented example key), aws_secret_access_key = SHOULD-NOT-APPEAR (a non-secret value, the same shape merged #11227 and #17540 added) and 64-hex cache digests (as in merged #20047). No home path moves in this PR.

CI path references

None: no workflow filter, explicit file list, AUTOSDE.yaml glob or sensitive-change glob names these files.

Manual verification

N/A: unit coverage is sufficient. This is a test-only move; the collected-test multiset and a full run of every moved test show it.

Related Issues

Part of #20192

Follow-up: #20383 (pre-existing shapes moved verbatim; de-flake there)

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

test_prompts.py (4,858 lines), test_runtime_reconcile.py (4,825) and
test_apps_registry_coverage.py (4,797) are each more than twice the
2,000-line cap. Each splits along its own section banners and test
classes, by the behaviour under test, into the original path plus
topic siblings named test_<stem>_<topic>.py. Helpers and fixtures that
several parts share move to a non-test <stem>_helpers.py module that
every part imports by name.

test_prompts.py keeps discovery and reading (1,397 lines); authoring,
the shared link and swap defences, and the caller gates move to
_authoring, _link_gates and _caller_gates. test_runtime_reconcile.py
keeps the reconciler core and the app backend table (1,357); the
pass's inputs and outputs, every sweep's lease gate, and tenancy with
its leak scan move to _wiring, _sweep_gates and _tenancy. The tenancy
part holds every tenancy claim, so the leak scan over its own source
and the positive control at its end keep their reach.
test_apps_registry_coverage.py moves its shared fakes and its tail run
(install refusals, characterization) to _install and _characterization
(3,597 lines left); part 2 moves the front run so TestRunAppBuild is
what the original keeps. One PR cannot hold all of it under the review
lanes' diff cap.

Every test function and class moves with an identical AST except
TestRefusalLineVerb, whose one docstring named a neighbour "above" that
stays in the original. The collected (class, name, params) multiset is
identical (797 tests). Glue: fixtures that tests request by parameter
are re-declared pytest.fixture(name=...); pytestmark
keep_runtime_ownership_tables is copied into every runtime part; two
remainder module docstrings name where the moved topics live, and the
runtime remainder's table comment and one helper docstring are reworded
to stay true; an own-line nosemgrep marker sits above each of the nine
pre-existing semgrep findings that move into a new file.

requires-real-symlinks.txt re-points 13 node ids, the wait-discipline
row follows its waits, the line-cap baseline drops two rows and lowers
one, and test/conftest.py's ownership-table fixture names the tenancy
module's leak scan.

Part of #20192
@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners October 14, 2026 23:20
@bolichen97
bolichen97 requested a review from CrysisDeu October 14, 2026 23:20
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 14, 2026
@bolichen97
bolichen97 enabled auto-merge (squash) October 14, 2026 23:35
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 02c96fabb9b7a5e850b9c707acc1c44788548202 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 02c96fabb9b7a5e850b9c707acc1c44788548202 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] 02c96fa

Description read

[DESCRIPTION-READ] 64559e5c10a02213dcd43e85d372752acd76192e23881deee5c6c7fe74dc2fde

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ⏭️ skipped

Revision 02c96fabb9b7a5e850b9c707acc1c44788548202 ships no reviewable capability (docs, tests or generated files only), so there is nothing to inventory. Advisory — does not block merge.

@github-actions

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 02c96fabb9b7a5e850b9c707acc1c44788548202 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 02c96fa

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 02c96fabb9b7a5e850b9c707acc1c44788548202: <one-sentence reason>

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 02c96fabb9b7a5e850b9c707acc1c44788548202 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 02c96fa

Verdict parsed from the review's SHA-scoped output markers for commit 02c96fabb9b7a5e850b9c707acc1c44788548202.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 02c96fabb9b7a5e850b9c707acc1c44788548202: <one-sentence reason>

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 15, 2026
@bolichen97
bolichen97 merged commit a608704 into main Oct 15, 2026
101 checks passed
@bolichen97
bolichen97 deleted the refactor/linecap-t15-test-prompts branch October 15, 2026 00:58
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants