Skip to content

refactor(rust): move lib.rs's test module below the code it tests - #435

Merged
PathGao merged 1 commit into
masterfrom
refactor/move-lib-tests-to-the-end
Aug 3, 2026
Merged

refactor(rust): move lib.rs's test module below the code it tests#435
PathGao merged 1 commit into
masterfrom
refactor/move-lib-tests-to-the-end

Conversation

@PathGao

@PathGao PathGao commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #434 — it touches the same region of lib.rs, so this is based on that branch rather than master. Once #434 squash-merges, GitHub retargets this to master and the duplicate drops by patch-id.

The problem

lib.rs is laid out helpers → tests → commands:

  21 – 512    helper functions
 513 – 2364   #[cfg(test)] mod tests          1852 lines, 39% of the file
2366 –        mod setup; mod tab_transfer; …
       …      every #[tauri::command] in the application

Opening the file to find convert_markdown or save_file_content means scrolling past 1852 lines of assertions for code you have not reached yet. After:

before after
first #[tauri::command] line 2366 line 518
#[cfg(test)] mod tests line 513 line 2891

setup.rs already does it this way — its tests sit at the end, below 1117 lines of installer code. This is the file falling in line with the convention its sibling already follows, not a new convention.

It is a pure move

Rust does not care about item order within a module, so nothing needed rewriting. Verified rather than asserted:

  • The 1852-line block is byte-identical. diff of the block extracted from HEAD against the block extracted from the result: no output.
  • A sorted line-by-line diff of the entire file before vs after differs only by the three-line comment banner and one blank line added at the seam. Nothing else moved, changed, or vanished.
npm test      562 / 562
npm run check 644 files, 0 errors
cargo test    149 passed          (149 before)
cargo clippy  3 warnings          (3 before — same three)
cargo fmt     53 diff hunks       (53 before — all pre-existing, rustfmt is not enforced here)

Why this does not break the source-reading tests

Two tests include_str! this file and search their own source: the preprocessing-step registry (every_convert_markdown_preprocessing_step_is_registered) and #434's raw-buffer fail-safe check. Both locate their subject by string search, not by line offset, so moving a block below them changes nothing. Confirmed by the unchanged cargo test count rather than by reading them.

Not covered

  • This is placement only. The audit that produced it also observed that the markdown pipeline inside lib.rs is now ~1157 lines across 27 functions with no AppHandle, State or IO dependencies — pure &str → String, and the most module-shaped thing in the crate. Cutting src-tauri/src/markdown/ out of lib.rs is the change that would actually reduce the file; it is a real refactor with a real review surface and is deliberately not attempted here.
  • The banner is a comment, not a mechanism. Nothing stops a future test module being added mid-file. setup.rs and this file now agree by convention only.
  • Line numbers in any external notes referring to lib.rs are invalidated. Nothing in the repo does so — the source-reading tests search by string, and no comment cites a line number in this file.

🤖 Generated with Claude Code

Base automatically changed from fix/guard-the-load-bearing-invariants to master August 3, 2026 09:26
`lib.rs` opened with its helper functions, then 1852 lines of
`#[cfg(test)] mod tests`, and only then the Tauri commands that are the
file's reason for existing. Reading it meant scrolling past 39% of the
file — assertions for code you had not reached yet — before the first
`#[tauri::command]`.

The module moves verbatim to the end. First command goes from line 2366
to 518.

Rust does not care about item order inside a module, so this is a pure
move: the 1852 lines are byte-identical, and a sorted line-by-line diff
of the whole file before and after differs only by the three-line
comment banner and one blank line added at the seam.

setup.rs already does it this way — its own tests sit at the end, below
1117 lines of installer code — so this is the file falling in line with
the convention its sibling already follows, not a new one.

Nothing else changes. The source-reading tests that `include_str!` their
own file (the preprocessing-step registry, the raw-buffer fail-safe
check) search by string rather than by offset, so they are unaffected;
`cargo test` is 149 before and after.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@PathGao
PathGao force-pushed the refactor/move-lib-tests-to-the-end branch from aadca8f to ba02fe4 Compare August 3, 2026 09:29
@PathGao
PathGao merged commit d521543 into master Aug 3, 2026
4 checks passed
@PathGao
PathGao deleted the refactor/move-lib-tests-to-the-end branch August 3, 2026 10:11
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