Skip to content

Move the inline tests out of commands.rs and sync/reconciliation.rs - #441

Merged
lamemustafa merged 1 commit into
masterfrom
refactor/extract-commands-reconciliation-tests
Sep 16, 2026
Merged

lamemustafa merged 1 commit into
masterfrom
refactor/extract-commands-reconciliation-tests

Conversation

@lamemustafa

@lamemustafa lamemustafa commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Continues #440 under docs/proposed-rust-module-conventions.md item 2: extract inline test modules first. No production change.

parent before after moved to (lines after rustfmt)
src-tauri/src/commands.rs 4,684 3,580 commands_tests.rs (754), commands_statement_export_tests.rs (31), commands_party_statement_export_tests.rs (314)
src-tauri/src/sync/reconciliation.rs 2,578 1,708 reconciliation_tests.rs (865)

Each block stays the same child module via #[cfg(test)] #[path = "…"] mod <name>;. commands.rs has production code after its first test block, and that code stays in place.

Checked, not asserted

  • No production change. Both parents rebuild byte-identical to HEAD from the new parent plus the re-indented children, expanding only the three moved commands.rs modules. The existing commands_native_ledger_tests.rs declaration is untouched. The moved blocks contain no multi-line string literals.
  • rustfmt changed only layout. In commands_tests.rs it removed two trailing commas. In reconciliation_tests.rs it rewrote two match arms from => { assignment } to => assignment,; both forms evaluate to (). The 546 string and 13 char literals in those two files are identical. The other two test files and both parents were unchanged by rustfmt.
  • No test lost. Whole-lib test lists are identical before and after under all four feature sets the Move the inline tests out of tally/runtime.rs and tally/connection.rs #440 review used: default (968), voucher-scan (986), live-calibration-harness (988) and lab-writes (1,068). The 61 moved tests pass: 29 + 1 + 12 in commands.rs, 19 in reconciliation.rs. (Corrected from 67, which also counted six tests in modules that did not move.) The only compiler warnings are two unused variables that already exist in runtime.rs under voucher-scan.
  • Platform cfgs. One #[cfg(unix)] test and the #[cfg(unix)] import it needs moved together; unix includes the macOS host that ran them. The target_os cfgs in commands.rs belong to production code that did not move.
  • Text readers, checked before moving this time:
    • scripts/client-grouping.test.mjs and ledger-entries-ui.test.mjs read commands.rs, and both still pass.
    • The full frontend suite passes: 239 node tests, 113 vitest and 10 Playwright.
    • check-tally-live-read-boundary.mjs still passes. Its productionSurfaces feature check reads reconciliation.rs only, so it no longer sees the moved test code. That test code contains no probe feature names, and test code cannot enable a production feature, but the scan is narrower than before (as with runtime.rs in Move the inline tests out of tally/runtime.rs and tally/connection.rs #440). Its other loop, which scans every .rs file for probe identifiers, includes the new files.
  • cargo clippy --lib --tests -- -D warnings -A clippy::pedantic is clean.
  • Reseal: exactly 2 pinned hashes changed, and --verify exits 0. The coverage report counts newly unsealed test-only modules: 4 and lists nothing else.

Coverage, as in #440

The four new test files are unpinned. Their ~1,960 lines were sealed only because they sat inside pinned files. Tests decide nothing about what Bridge posts or emits, so they carry no pin reason under #416's rule. The cost is the same as in #440: a change that only weakens one of these tests no longer changes a pinned hash.

🤖 Generated with Claude Code

docs/proposed-rust-module-conventions.md item 2, continuing #440. Four
inline test modules move to files beside their parents, each kept as the
same child module via #[path], so private access, test paths and module
paths are unchanged:

  commands.rs  tests                        -> commands_tests.rs
               statement_export_tests       -> commands_statement_export_tests.rs
               party_statement_export_tests -> commands_party_statement_export_tests.rs
  sync/reconciliation.rs  tests             -> reconciliation_tests.rs

commands.rs has production code after its first test block; it stays in
place. commands.rs goes from 4,684 to 3,580 lines; reconciliation.rs from
2,578 to 1,708.

Checked, not asserted:
- Both parents rebuild byte-identical to HEAD from the new parent plus the
  re-indented children, expanding only the three moved commands.rs modules
  (the existing commands_native_ledger_tests.rs declaration is untouched).
- rustfmt changed layout only: two trailing commas in commands_tests.rs,
  and in reconciliation_tests.rs two match arms `=> { assignment }`
  rewritten as `=> assignment,`, which both evaluate to (). The 559 string
  literals in those two reformatted files are identical; the other two
  test files and both parents were unchanged by rustfmt.
- Whole-lib test lists are identical before and after under default (968),
  voucher-scan (986), live-calibration-harness (988) and lab-writes
  (1,068). The 67 moved tests pass. The only compiler warnings are the two
  existing unused variables in runtime.rs under voucher-scan.
- The two #[cfg(unix)] tests moved; unix includes the macOS host. The
  target_os cfgs in commands.rs are in production code that did not move.
- Text readers checked: scripts/client-grouping.test.mjs and
  ledger-entries-ui.test.mjs read commands.rs and still pass, as does the
  full frontend suite (239). check-tally-live-read-boundary.mjs scans
  reconciliation.rs for probe features and still passes.
- clippy --lib --tests -D warnings is clean. Resealing changed exactly two
  pinned hashes; the coverage report counts four newly unsealed test-only
  modules and lists nothing else.

The four new test files are unpinned, like #440's: tests decide nothing
about what Bridge posts or emits, so they carry no pin reason.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@lamemustafa
lamemustafa merged commit be66056 into master Sep 16, 2026
13 checks passed
@lamemustafa
lamemustafa deleted the refactor/extract-commands-reconciliation-tests branch September 16, 2026 10:33
lamemustafa added a commit that referenced this pull request Sep 16, 2026
…_write_store.rs (#442)

docs/proposed-rust-module-conventions.md item 2, continuing #440 and
#441. Three inline test modules move beside their parents via #[path]:

  bridge-tally-protocol  native_outstandings/wire.rs
      currency_tests -> wire_currency_tests.rs
      group_tests    -> wire_group_tests.rs
  bridge                 db/tally_write_store.rs
      tests          -> tally_write_store_tests.rs

wire.rs goes from 1,796 to 1,262 lines; tally_write_store.rs from 1,794 to
1,259.

No production change: both parents rebuild byte-identical to the base.
rustfmt changed whitespace only; every string and char literal, including
the eight multi-line ones, is identical.

No test lost: the 23 moved wire.rs tests and 6 moved tally_write_store.rs
tests pass, and whole-lib test lists are identical for bridge under
default, voucher-scan, live-calibration-harness and lab-writes, and for
bridge-tally-protocol under default and all features. The only compiler
warnings are two existing unused variables in tally/runtime.rs under
voucher-scan and live-calibration-harness.

check-tally-request-builder-hazards.mjs skips only inline #[cfg(test)]
blocks, so it now scans these extracted test files (and #440's and
#441's) as production; its results are unchanged. The three new test files
are unpinned, as in #440 and #441.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
lamemustafa added a commit that referenced this pull request Sep 16, 2026
…ot by name

#440, #441 and #442 moved inline `#[cfg(test)] mod tests { ... }` blocks
into sibling files loaded by `#[cfg(test)] #[path = "..."] mod tests;`.
check-tally-request-builder-hazards.mjs skipped only the inline form, so it
began reading those files as production code. Results did not change, but
a test that builds a hazard-shaped string as an expectation would have
raised a false alarm.

Skipping any file named *_tests.rs was rejected: a safety scanner must not
exempt production code for its file name. Instead a file is skipped only
when it is actually loaded as a test module:

- Edges: a brace-depth-0 out-of-line `mod name;` whose attribute group has
  a cfg implying test (cfg(test), or test as an argument of cfg(all(...))),
  with #[path] or bare in a crate root or mod.rs; plus any such declaration
  made by a file already test-only, iterated to a fixed point.
- Vetoes, from every .rs file in the repository and matched by basename
  case-insensitively: any other `mod name;` at any depth (including macro
  bodies and inline modules), any `path = "..."` or include!-family string
  not part of an edge (covering cfg_attr), and every Cargo crate root.
- Files whose braces underflow or do not end balanced contribute no edges.
- Everything unhandled -- cfg(any(...)), #[path] inside an inline module,
  r#name -- leaves the file scanned, so an error is a false alarm, never a
  missed hazard.

The design was critiqued before implementation. The critique found four
ways the first draft could skip a production file -- a non-test
declaration it did not recognise, a Cargo target, a declaration outside the
scan roots, case variants -- and that it would still have scanned 24 of the
74 extracted files: 22 declared by other test files, one under
cfg(all(test, ...)), one bare in a mod.rs. The veto set, the fixed point and
those two cfg/bare shapes are the response.

Checked, not asserted: on this repository the skipped set is exactly the
74 files the rustc-validated module graph from #436 marks test-only, path
for path; the 10 pinned violations are unchanged. The skipped count is now
pinned too, so a lexer regression that quarantines too much fails the gate.

Main now runs under `import.meta.main` so the functions can be imported;
a test runs the real script as a child process so a main that silently
does nothing cannot pass. 15 fixture tests; 15 mutations of the scanner
(trust file names, accept any cfg mentioning test, drop each veto, trust
unbalanced files, accept nested declarations, drop propagation, drop the
crate-root veto, case-sensitive veto, #[path] under the stem, main never
running, no bare-mod detection, strings or comments not skipped, only the
first attribute, no raw-string path) each fail a named test. One of those
first survived because a fixture's production declaration masked the
lexer; the fixture was fixed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

1 participant