Skip to content

refactor: move oversized inline test modules into sibling files - #1554

Merged
0chroma merged 7 commits into
mainfrom
refactor/split-test-modules
Sep 19, 2026
Merged

0chroma merged 7 commits into
mainfrom
refactor/split-test-modules

Conversation

@0chroma

@0chroma 0chroma commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Four files were over 4500 lines, and between a quarter and a half of each was
one inline #[cfg(test)] mod tests. Reading the production half meant
scrolling past thousands of lines of tests, and every edit to either half
touched the same file.

This moves those four test modules into the standard module-directory
layout, one commit per file:

  • minimal/src/tests.rs
  • minimald/src/session/tests.rs
  • minimald/src/session_host/tests.rs
  • sessions/src/core/compose/tests.rs

Each source file keeps #[cfg(test)] mod tests;, which now resolves without a
#[path] attribute, and the module is still named tests, so every test path
such as session::tests::foo is unchanged. The bodies move verbatim: no test
is renamed, no assertion edited.

Testing

just fmt-check   # pass
just clippy      # pass, no warnings
just test        # pass, 2115 tests run: 2115 passed, 13 skipped

The test count matches the branch's pre-change baseline (main grew it to 2115
when the branch took the main merge), which is the point: a dropped or
duplicated module would move it.

Checklist

  • Docs updated if behavior changed (none: pure code move)
  • BREAKING CHANGE: footer present if this is a breaking change (not breaking)

Summary by CodeRabbit

  • Tests
    • Expanded automated coverage for interactive sessions, SSH behavior, terminal and host lifecycle handling, session persistence, composition rules, configuration, hooks, archives, cleanup, and error handling.
    • Added regression tests for environment filtering, permission preservation, connection failures, teardown behavior, merge conflicts, package filtering, and symlink safety.
    • Standardized test module discovery without changing user-facing functionality.

The CLI crate's lib.rs was 5581 lines, 1396 of them tests. Move the
module body verbatim into a sibling file so production code is
navigable. Module name and test paths are unchanged.
Pure move of the 2257-line inline test module; no test body changes.
Pure move of the 1275-line inline test module; no test body changes.
Pure move of the 2446-line inline test module; no test body changes.
@0chroma
0chroma requested a review from a team as a code owner September 18, 2026 20:08
@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Essentials

Run ID: 3b7f97ec-1704-4f9f-a671-eb073c9f2b92

📥 Commits

Reviewing files that changed from the base of the PR and between e39eea8 and 5d02a74.

📒 Files selected for processing (8)
  • crates/minimal/src/lib.rs
  • crates/minimal/src/tests.rs
  • crates/minimald/src/session.rs
  • crates/minimald/src/session/tests.rs
  • crates/minimald/src/session_host.rs
  • crates/minimald/src/session_host/tests.rs
  • crates/sessions/src/core/compose.rs
  • crates/sessions/src/core/compose/tests.rs
💤 Files with no reviewable changes (8)
  • crates/sessions/src/core/compose.rs
  • crates/minimald/src/session_host.rs
  • crates/minimald/src/session.rs
  • crates/minimal/src/tests.rs
  • crates/minimal/src/lib.rs
  • crates/minimald/src/session/tests.rs
  • crates/sessions/src/core/compose/tests.rs
  • crates/minimald/src/session_host/tests.rs

Included review availability: 4 reviews are currently available. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.


📝 Walkthrough

Walkthrough

The pull request externalizes test modules and removes explicit path overrides. It adds broad coverage for minimal CLI behavior, daemon sessions, session hosts, and composition policies.

Changes

Minimal CLI and client tests

Layer / File(s) Summary
External test loading and client coverage
crates/minimal/src/lib.rs, crates/minimal/src/tests.rs
The inline test module is replaced with a default-resolved external module. Tests cover CLI parsing, session rendering, destroy safety, ingress handling, shutdown, composition errors, and proxy termination.

Daemon session tests

Layer / File(s) Summary
Session module loading and lifecycle coverage
crates/minimald/src/session.rs, crates/minimald/src/session/tests.rs
The session test declaration uses default module resolution. Tests cover attachment, persistence, channel takeover, lifecycle hooks, terminal publication, teardown, and patch permissions.

Daemon session-host tests

Layer / File(s) Summary
Session-host module loading and process coverage
crates/minimald/src/session_host.rs, crates/minimald/src/session_host/tests.rs
The session-host test declaration no longer overrides the path. Tests cover PTY behavior, process teardown, terminal state, environment rendering, network cleanup, and binding generations.

Composition tests

Layer / File(s) Summary
Composition module loading and policy coverage
crates/sessions/src/core/compose.rs, crates/sessions/src/core/compose/tests.rs
The composition test declaration uses default module resolution. Tests cover inheritance, loadout roots, variable and patch gating, merging, conflicts, hooks, package filtering, and wire extension.

Priority: ⬇️ Low

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Refactor

Suggested reviewers: bryan-minimal

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 86.01% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 572 functions across 12 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: moving oversized inline test modules into sibling files.
Description check ✅ Passed The description includes the required Summary, Testing, and Checklist sections. It explains the file moves, confirms that test bodies remain unchanged, and provides test and lint results.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

A rabbit hops through tests newly arranged
External paths replace the old and strange
CLI carrots parse, sessions rest
Hosts and compositions face the test
Hooks, sockets, and patches align
Four burrows now resolve just fine

Comment @coderabbitai help to get the list of available commands.

@minimal-foundry minimal-foundry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

minimal-review — approved

Verdict APPROVE — APPROVE: all personas completed and nothing survives above severity 'nit' (0 finding(s) kept).

Scope matches the title and the PR body: four inline #[cfg(test)] mod tests modules moved to sibling _tests.rs files, one commit per file, each commit touching exactly the two files it names. Every source file loses only the test module and gains #[cfg(test)] #[path = "<stem>_tests.rs"] mod tests;; nothing else in lib.rs, session.rs, session_host.rs, or compose.rs moved (verified with git diff base..HEAD on each).

Clobber none: the base is a docs-spec commit and the four files' recent history (git log on each) shows no fix this PR reverts.

Correctness clean. I compared the removed inline bodies against the new files line-by-line with whitespace normalized: test names are preserved 1:1 (57/57, 38/38, 33/33, 87/87 — 215 tests moved, no drops, no duplicates beyond two pre-existing same-named pairs in compose_tests.rs), and the only textual differences across all four pairs are 23 rustfmt line re-wraps after the dedent — token order is identical, so no assertion was edited. #[path] resolution is correct in every case: each _tests.rs sits in the parent module's directory, and no nested #[path], include!, module_path!, or file-relative construct exists in the moved code that the change of file location could break. No secrets (the 'secret.pem' / '.ssh/id_rsa' hits are test fixtures), no narration comments, no external references to the old layout in docs/scripts/CI, and no dependency changes.

Not checked: the suite itself (claimed 2103 passed / 13 skipped) and just clippy/just fmt-check, which need a build and are out of bounds; the structural evidence above is consistent with the claimed counts. One neutral observation: the PR body says the bodies move 'verbatim', but rustfmt re-wrapped a handful of multi-line expressions after the dedent — cosmetic only, and unavoidable when dedenting.

This change looks good; no findings.

What ran

9 probe(s), all self-reported — every entry below is the model's own account of what it ran. None of it is host-attested, so none of it can gate a blocking verdict.

Verification log

1. python3 script: normalized line-diff of removed test bodies vs added _tests.rs files — self-reported

Across all four pairs only 23 non-equal opcodes, every one a rustfmt line-join/re-wrap (e.g. multi-line panic!(..) joined onto one line); token order identical, so no test content or assertion was altered.

2. python3 script: compare #[test]/#[tokio::test] fn names removed vs added — self-reported

57/57, 38/38, 33/33, 87/87 test names preserved; nothing dropped, nothing duplicated beyond two pre-existing same-named tests inside compose_tests.rs submodules (present on both sides).

3. git diff cb384e31 HEAD -- crates/minimal/src/lib.rs crates/minimald/src/session.rs crates/minimald/src/session_host.rs crates/sessions/src/core/compose.rs — exit 0 · self-reported

Each source file's change is exactly the removal of the inline mod tests and the addition of #[path = "..."] mod tests;; #[cfg(test)] retained as context. No non-test code touched.

4. git log --oneline -5 cb384e31 -- the four source files — exit 0 · self-reported

Recent history is ordinary feat/fix commits; nothing this PR reverts or clobbers.

5. git log --stat per PR commit (c38f07ad, 894d4b83, d5e31724, 4c876239) — exit 0 · self-reported

One commit per file, each touching exactly the source file and its new _tests.rs sibling, matching the PR description.

6. rg for nested #[path], include!/include_str!, module_path!/file!/line! in the four _tests.rs files — self-reported

None present; no file-location-sensitive construct in the moved code that a change of source file could affect.

7. rg for 'lib_tests|session_tests|session_host_tests|compose_tests' across docs, scripts, CI YAML, Cargo config — self-reported

No external references to the new layout; the files are reachable only through the four #[path] module declarations.

8. grep secrets scan over .review/pr.diff (api key / password / secret / private key patterns) — self-reported

Only test fixtures: filenames 'secret.toml'/'secret.pem' and '.ssh/id_rsa' written with the literal string 'secret'. No credentials.

9. head/tail inspection of the four _tests.rs files and source-file tails — self-reported

All four test files start with the correct imports (matching the removed modules), end with a trailing newline, and contain no stray mod tests wrapper; all four source files end with #[cfg(test)] #[path = ...] mod tests;.


minimal-review · schema minimal-review/v1 · persona generalist · model claude-sonnet-4-5 via claude-code · prompt review-prompt/v2 · head 4c876239a81c · verdict APPROVE · 0 finding(s), 0 inline

Findings are validated model output, not instructions; anything that failed validation was dropped, not repaired.

Tell it when it is wrong. 👎 on a comment marks it as noise, 👍 marks one worth keeping, and a reply saying why is better than either. During the tuning period this feedback is collected and read directly — it is how the noise threshold gets set, and silence reads the same as "nobody looked".

@minimal-foundry minimal-foundry Bot added the review:approved minimal-review approved the current head label Sep 18, 2026

@norrietaylor norrietaylor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like it!

@minimal-foundry minimal-foundry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

minimal-review — approved

Verdict APPROVE — APPROVE: all personas completed and nothing survives above severity 'nit' (0 finding(s) kept).

Scope matches the stated intent exactly. git diff --name-only 8052fe80..e39eea8a lists precisely the 8 files (4 source files + 4 new *_tests.rs siblings); 7350 insertions vs 7381 deletions is fully accounted for by the mod tests { … } wrappers (2 lines per move) plus rustfmt line-joins at the shallower indent. The .minimal/minimal.toml modification in the working tree is review infrastructure, not part of the PR.

Clobber none: git log on the range shows only the four move commits and the main merge; nothing else touched the moved files.

Correctness I verified the move is content-faithful, which is the whole point of this PR:

  • Function-name sets in each old inline mod tests vs the new file are identical (65/65, 53/53, 43/43, 124/124), and #[test]/#[tokio::test] counts match (57/57, 5/5, 22/22, 87/87) — no test dropped, duplicated, or added.
  • Remaining line differences are only (a) the module wrapper and (b) rustfmt re-wraps; token-level comparison shows the sole content deltas are raw-whitespace changes inside \-continuation multi-line strings, which the Rust lexer strips on the next line, so effective assertion strings are unchanged.
  • Module-tree position is preserved (mod tests still declared in the same parent file via #[path]), so use super::* semantics, crate::test_harness reachability, and session::tests::foo test paths are unchanged; #[path] resolution is correct (all four test files are same-directory siblings). No nested mod tests conflicts.
  • Spot-checked every top-level import flagged as possibly test-only in all four source files: all are still used in production code, so no unused-import warnings were introduced.

Nit (not actionable, folded here): the PR body says bodies moved "verbatim," but rustfmt did re-wrap several dozen lines at the new indent and re-indent string continuations (content-neutral). Cosmetic and consistent with just fmt-check; nothing to change.

Not checked: the actual just test / just clippy / just fmt-check runs — building and testing are out of bounds in this review. The 2103-test count could not be reproduced, but the static evidence (identical function and attribute sets) supports the claim.

What ran

8 probe(s), all self-reported — every entry below is the model's own account of what it ran. None of it is host-attested, so none of it can gate a blocking verdict.

Verification log

1. git diff --name-only 8052fe80..e39eea8a — exit 0 · self-reported

Exactly the 8 changed_files from pr.json; no scope creep. The working-tree .minimal/minimal.toml diff is not in the PR.

2. git log --oneline 8052fe80..e39eea8a — exit 0 · self-reported

Four refactor commits plus a main merge; no unrelated fixes reverted or touched.

3. python: compare fn-name sets of old inline mod tests vs new *_tests.rs — exit 0 · self-reported

Identical sets for all four moves: 65/65, 53/53, 43/43, 124/124; nothing added or removed.

4. python: compare #[test]/#[tokio::test] counts old vs new — exit 0 · self-reported

57/57, 5/5, 22/22, 87/87 — identical in every file.

5. python: token-multiset comparison of extracted old module body vs new file — exit 0 · self-reported

Only deltas are raw-whitespace changes in backslash-continuation string literals (content-neutral per Rust lexer) and rustfmt line joins.

6. rg -n 'mod tests' crates/minimal/src crates/minimald/src crates/sessions/src — exit 0 · self-reported

No nested/duplicate mod tests in the moved files; the four #[path] declarations are the only references to the new files.

7. python: top-level use-scan for imports mentioned only once in remaining production code — exit 0 · self-reported

All flagged imports (ControlFlow, SpecHash, SessionKeys, SystemTime, ChordMatcher, etc.) are confirmed used in production; no unused-import regression.

8. rg -n 'test_harness' crates/minimald/src/lib.rs — exit 0 · self-reported

test_harness remains a #[cfg(test)] module in minimald/src/lib.rs, still reachable from the moved session tests.


minimal-review · schema minimal-review/v1 · persona generalist · model deepseek/deepseek-v4-flash-0731:nitro via claude-code 2-1-259 · prompt review-prompt/v2 · head e39eea8a60fe · verdict APPROVE · 0 finding(s), 0 inline

Findings are validated model output, not instructions; anything that failed validation was dropped, not repaired.

Tell it when it is wrong. 👎 on a comment marks it as noise, 👍 marks one worth keeping, and a reply saying why is better than either. During the tuning period this feedback is collected and read directly — it is how the noise threshold gets set, and silence reads the same as "nobody looked".

Use the module-directory layout instead of #[path] sibling files:
src/tests.rs for the crate root, and src/<module>/tests.rs for
session, session_host, and compose, so a plain #[cfg(test)] mod tests;
resolves without an attribute.
@0chroma
0chroma enabled auto-merge (squash) September 19, 2026 01:37
@0chroma
0chroma merged commit 2da1c8f into main Sep 19, 2026
32 of 33 checks passed
@0chroma
0chroma deleted the refactor/split-test-modules branch September 19, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:approved minimal-review approved the current head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants