Skip to content

test: split four oversized test files by the behaviour they cover - #21397

Merged
bolichen97 merged 1 commit into
mainfrom
refactor/linecap-t32-test-subagent-coverage
Oct 17, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
refactor/linecap-t32-test-subagent-coverage

Conversation

@bolichen97

@bolichen97 bolichen97 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Bring test_subagent_coverage.py, test_voice_reply.py, test_trusted_apps_api.py and test_onboarding_import_coverage.py from over 3,100 lines each to at most 1,600, without changing a single test.

Each of the four files is more than half again over the 2,000-line cap the line-cap campaign enforces (3,158 / 3,145 / 3,141 / 3,135 lines). A file that large is slow to navigate and review, and every test added to it makes the eventual split bigger.

Why it matters

The maintainers' rule is that no hand-written file may exceed 2,000 lines, and all four break it. Their topics are already separate (a subagent's bookkeeping vs what happens when it finishes vs steering a live run; text preparation vs each TTS provider's synthesis vs the pipeline around it; the trust endpoints vs registry grants vs a withdrawal that fails part-way; parsers vs writers vs per-source readers), so a reader looking for one topic scrolls past the others. Splitting along those seams makes each topic findable by file name and leaves each file room to grow.

Not a goal

  • Changing, renaming, fixing, de-flaking or re-parametrizing any test. Every test function and class moves with an identical AST.
  • Changing production code. Only tests, test helpers, two path-keyed list rows and one prose citation change.
  • Fixing the pre-existing semgrep findings and timing shapes that move with their tests: they are marked, not rewritten.

What changed (motivation → approach → change)

Each file keeps one contiguous run of its own classes and hands the rest to topic parts, along its existing section banners. Helpers more than one part uses move to a non-test *_helpers.py module that every part imports by name; a helper only one part uses moves with that part. 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_subagent_coverage.py (3,158 → 1,225) module probes (memory, CPU, cgroup), env parsing, agent and governance vetting, slot / pid / cost / stall bookkeeping, read surfaces, queue depth, the stagger gate _completion (1,424): the injection-failure notice, continuable conversations, wave and batch bookkeeping with the done-but-unreported hold, digest holds, announce; _live_runs (557): session sharing, intentional cancel, steer and follow-up, the reaper's clocks
test_voice_reply.py (3,145 → 944) markdown, SSML, validation, sentence splitting; provider and engine resolution, rate mapping, SAPI command, system voices _synthesis (1,464): _synthesize_system / _piper / _polly, including temp-file ownership under cancellation; _pipeline (758): the dispatcher, Slack upload, end-to-end and streaming replies, text-type detection, stitch_mp3s cleanup
test_trusted_apps_api.py (3,141 → 1,570) the snapshot, GET, grant, revoke and allow-all endpoints, the enforcement property, and regression sections 1-4 (corrupt config, revoke teardown, over-disable, builtin names) _registry (409): sections 5-6, registry-name grants and what the snapshot reports; _withdrawal (1,041): uninstall, overlay-owned grants, failed teardowns, the blanket switch, the lifecycle lock
test_onboarding_import_coverage.py (3,135 → 1,087) parsers and projections: JSON5, scalars, config, MCP specs, chunking, schedules, file readers, tree walks, the plan parser _writers (967): every writer's conflict / rollback branch and the apply_import failure paths; _sources (1,112): SQLite sidecars, Codex, Hermes, Lineage, OpenClaw, root discovery, skill packaging

Helper modules (below 150 lines because they hold only what two or more parts share): subagent_coverage_helpers.py (41), voice_reply_helpers.py (154), trusted_apps_api_helpers.py (131), onboarding_import_coverage_helpers.py (50).

Glue, the only lines whose AST or comments change:

  • Fixtures that tests request by parameter and that more than one module uses are re-declared @pytest.fixture(name="x") def x_fixture(...), bodies unchanged, so a parameter never shadows an import: home, mock_sel, _polly_consented. The autouse _no_argv_prefixers keeps its name and is imported into every voice module; pytestmark = usefixtures("isolate_mcp_host_paths") and the three-line _api() are copied into both onboarding parts. _api() returns the kiro_crew.onboarding_import facade and is a per-file facade accessor, kept verbatim in each part the guard scans: test_onboarding_import_refactor_contract.py resolves, file by file, which local names hold the facade before it reads that file's patches.
  • Module docstrings: each part gets one; each original's names what it still covers and where the rest went.
  • Nine pre-existing semgrep findings move to a new path. Each gets an own-line # nosemgrep: <rule> -- <reason> directly above it (between decorator and def for the autouse fixtures), code unchanged. The moved timing shapes (zero-delay yields, a 20 ms finisher delay, three cancelled hour-long placeholder sleeps, one bounded 10 ms poll, awaits of in-memory or cancelled tasks, three kiro_crew.subagent.time.monotonic patches) each get an own-line # flake-ok: <reason>.
  • Black formats the moved code in the new files. test_voice_reply.py and test_trusted_apps_api.py stay in .github/black-baseline.txt and are not reformatted.

Rows and citations: .github/file-line-cap-baseline.txt deletes the four rows. test/wait_discipline_baseline.txt moves the test_subagent_coverage.py row to test_subagent_coverage_live_runs.py, which holds its one wait (count unchanged). One test/test_monitor_arming_preference.py docstring names test_trusted_apps_api_withdrawal.py as the home of the _EDITABLE_CONFIG membership pin.

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 four 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.

Tests

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

Check Result
pytest --collect-only at BASE (4 origins) vs HEAD (4 originals + 8 parts) 950 = 950; the (class, name, params) multiset is identical
pytest --fixtures-per-test -v (private and autouse fixtures included), BASE vs HEAD identical fixture sets for all 950 tests
markers per test (iter_markers(), BASE vs HEAD) identical for all 950
the 12 split test files, -n 3 and -n0 950 passed at BASE; 950 passed at HEAD in both modes
every corpus gate scripts/leaf_test_scope.py derives (522 tree-scanning test files) plus the 13 changed test files, -n 3 --dist loadgroup 41,353 passed, 156 skipped, 5 xfailed, 0 failed
every test that scans test sources through source_corpus / repo_files() (80 files, including test_onboarding_import_refactor_contract.py) plus the 13 changed test files, -n 3 --dist loadgroup 7,475 passed, 20 skipped, 0 failed
test_flake_pattern_ratchet.py (-n0, against the merge-base), test_wait_discipline_ratchet.py, test_file_line_cap.py, test_subagent_spawn_host_pin.py 224 passed
semgrep 1.78, the CI configs, --baseline-commit <BASE> --error, over the 19 changed files 0 findings, no parse errors; with --disable-nosem exactly the 9 marked findings
isort / flake8 / black --check on the changed files; check_comment_history.py, check_brand_name.py, check_black_formatting.py, check_subprocess_encoding.py, check_file_line_cap.py, docs_lint.py, check_cwd_relative_repo_reads.py, check_harness_parity.py, check_feature_map.py clean; 0 failures
list reach (mutation) restoring the BASE wait-discipline row fails both of that ratchet's tests (test_subagent_coverage_live_runs.py: 0 -> 1, 1 -> 0 test_subagent_coverage.py); the HEAD row passes

scripts/local-gate.py --base <BASE> --dry-run selects 17 backend files (all included above) and 367 cross-surface vitest specs; no website file reads these test files, so the vitest run is left to CI.

Move audit

test/test_subagent_coverage.py: 3158 -> 1225 lines; moved 99.65% (python-ast)
   changed: Expr [Expr] 10 lines                       (module docstring)
test/test_voice_reply.py: 3145 -> 944 lines; moved 99.02% (python-ast)
   changed: _polly_consented [FunctionDef] 27 lines    (re-declared with name=, body unchanged)
   changed: Expr [Expr] 1 lines                        (module docstring)
test/test_trusted_apps_api.py: 3141 -> 1570 lines; moved 99.12% (python-ast)
   changed: Expr [Expr] 12 lines                       (module docstring: one paragraph added)
   changed: home [FunctionDef] 6 lines                 (re-declared with name=, body unchanged)
   changed: mock_sel [FunctionDef] 6 lines             (re-declared with name=, body unchanged)
test/test_onboarding_import_coverage.py: 3135 -> 1087 lines; moved 99.67% (python-ast)
   changed: Expr [Expr] 10 lines                       (module docstring)

Every changed unit is glue: three fixtures re-declared with name= and the four module docstrings. Every test function and class moved with an identical AST. git diff origin/main...HEAD is 687,008 bytes.

Diff alignment: git diff BASE -- <file> and git diff --minimal BASE -- <file> add the same lines for every original (--numstat): test_subagent_coverage.py 8/1941, test_voice_reply.py 11/2212, test_trusted_apps_api.py 10/1581, test_onboarding_import_coverage.py 7/2055, on both (docstring and import glue only).

Moved semgrep sites, each with an own-line marker: kirocrew.test-sleep-as-barrier ×4 (_live_runs), kirocrew.test-autouse-shared-monkeypatch ×4 (voice_reply_helpers.py, _synthesis ×2, _pipeline), python.lang.security.audit.insecure-file-permissions ×1 (voice_reply_helpers.py, the fake binary's chmod 0o755).

Logger names: no new module defines a logger.

Content scan: the moved literals the internal scan could read are AKIAIOSFODNN7EXAMPLE (the documented example key) and "HOME": "/home/x" (the same literal merged #12647 added).

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

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners October 16, 2026 21:55
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ⏭️ skipped

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

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 689d4d6a80924b0630335c39d21c45f6b3ee95f3 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 github-actions Bot added the readiness: checking Automated validation is still running label Oct 16, 2026
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] 689d4d6

Description read

[DESCRIPTION-READ] d446acd1309d38c501ed98ade70813068e3f42214727855c3633208d1cc0aa47

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

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 689d4d6a80924b0630335c39d21c45f6b3ee95f3 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 689d4d6

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

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 689d4d6a80924b0630335c39d21c45f6b3ee95f3 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 689d4d6

Verdict parsed from the review's SHA-scoped output markers for commit 689d4d6a80924b0630335c39d21c45f6b3ee95f3.

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

@bolichen97
bolichen97 enabled auto-merge (squash) October 16, 2026 22:05
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 16, 2026
test_subagent_coverage.py, test_voice_reply.py, test_trusted_apps_api.py
and test_onboarding_import_coverage.py were each over 3,100 lines, past
the 2,000-line cap. Each keeps a contiguous run of its classes and hands
the rest to topic parts named after the behaviour under test; helpers
more than one part uses move to a non-test *_helpers.py module that
every part imports by name.

Every test moves with an identical AST: the collected (class, name,
params) multiset, the markers and the fixtures of all 950 tests are the
same before and after. The glue is the module docstrings, three fixtures
re-declared with name= so a parameter never shadows an import, and
own-line flake-ok / nosemgrep comments above pre-existing timing shapes
and semgrep findings that move to a new path.

The four line-cap baseline rows go, the one wait-discipline row follows
its wait to test_subagent_coverage_live_runs.py, and one docstring in
test_monitor_arming_preference.py names the membership pin's new file.

Part of #20192
@bolichen97
bolichen97 force-pushed the refactor/linecap-t32-test-subagent-coverage branch from 83da349 to 689d4d6 Compare October 17, 2026 00:14
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 17, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by a maintainer. The triage automation held this on a size, path, category or move-check rule only; every review lane is clean.

@bolichen97
bolichen97 merged commit 0607aed into main Oct 17, 2026
103 checks passed
@bolichen97
bolichen97 deleted the refactor/linecap-t32-test-subagent-coverage branch October 17, 2026 02:03
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 17, 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