refactor(rust): move lib.rs's test module below the code it tests - #435
Merged
Conversation
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
force-pushed
the
refactor/move-lib-tests-to-the-end
branch
from
August 3, 2026 09:29
aadca8f to
ba02fe4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #434 — it touches the same region of
lib.rs, so this is based on that branch rather thanmaster. Once #434 squash-merges, GitHub retargets this tomasterand the duplicate drops by patch-id.The problem
lib.rsis laid out helpers → tests → commands:Opening the file to find
convert_markdownorsave_file_contentmeans scrolling past 1852 lines of assertions for code you have not reached yet. After:#[tauri::command]#[cfg(test)] mod testssetup.rsalready 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:
diffof the block extracted fromHEADagainst the block extracted from the result: no output.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 unchangedcargo testcount rather than by reading them.Not covered
lib.rsis now ~1157 lines across 27 functions with noAppHandle,Stateor IO dependencies — pure&str → String, and the most module-shaped thing in the crate. Cuttingsrc-tauri/src/markdown/out oflib.rsis the change that would actually reduce the file; it is a real refactor with a real review surface and is deliberately not attempted here.setup.rsand this file now agree by convention only.lib.rsare 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