#617: Engine::new() reads ambient disk/git state during construction — give it a test constructor instead of patching leaks one at a time - #662
Merged
JDonaghy merged 3 commits intoAug 24, 2026
Conversation
…d of overwriting it after Engine::new() reads Settings::load(), SessionState::load(), HistoryState::load(), and git::current_branch() from the test runner's real $HOME and repo state, then consumes session.explorer_visible to decide whether to call app_shell.hide_sidebar() before the constructor even returns. test_engine() used to call Engine::new() and reset the loaded fields afterward, but that doesn't reliably undo hide_sidebar()'s effect (#615) since the decision is already baked into app_shell by the time the post-hoc assignment runs. Add Engine::new_for_test(), a #[cfg(test)] constructor that builds settings, session, history, and git_branch from in-memory defaults up front and never touches disk or shells out to git. Both it and Engine::new() now delegate to a shared new_from_state() so the rest of the constructor logic isn't duplicated. Update test_engine() to call it and drop the accumulated per-field resets.
…est() Fixes review findings from iteration 1: - src/render.rs's test_engine() and src/tui_main/panels.rs's sc_panel_tests::test_engine() both called bare Engine::new() and reactively reset individual fields (or, in render.rs's case, didn't reset git_branch/sc_ahead/sc_behind/session at all) — exactly the per-field-reset pattern #617 exists to eliminate. Both now call Engine::new_for_test() and drop the now-redundant manual resets, matching the already-fixed render_impl.rs fixture. - new_from_state()'s settings_mtime was computed via an unconditional disk read regardless of caller, undermining new_for_test()'s "never touches disk" doc comment. It's now passed in by the caller: new() still computes it from disk, new_for_test() passes None. - Engine::open() (test-only helper, 6 call sites in core/engine/tests.rs) now builds on new_for_test() instead of new(). - Documented the new_for_test() convention in docs/PATTERNS.md so it spreads to future hermetic/rendering/snapshot tests instead of remaining a one-fixture fix. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
CI's `Test (Linux, headless)` job failed while every local lane was green.
The job is the only one that runs `cargo fmt -- --check` and
`cargo clippy --no-default-features -- -D warnings` (the GUI job runs
`cargo test` alone), so a lint failure surfaces as exactly one red check
and zero red tests — which is why it read like a phantom test regression.
Root cause: CI uses `dtolnay/rust-toolchain@stable`, which moved to
1.98.0 (released 2026-08-18) while this machine was still on 1.97.1.
Clippy 1.98 turns three pre-existing, previously-clean sites into
`-D warnings` errors:
* `core::engine::keys` — `drain_collect`: `self.keymap_buf.drain(..)
.collect()` is `std::mem::take(&mut self.keymap_buf)`.
* `core::engine::source_control` — `useless_format`: `format!` over a
string literal with no arguments is `.to_string()`.
* `core::lsp` — `chunks_exact_to_as_chunks`: `chunks_exact(5)` over a
constant chunk size is `as_chunks::<5>().0`, which also drops five
bounds checks per token by handing the loop a `&[u32; 5]`.
All three are behaviour-preserving rewrites of the exact same semantics
(`as_chunks().0` drops a trailing partial group just like
`chunks_exact`), and all three sites keep their existing coverage:
`core::lsp::tests::test_decode_semantic_tokens_*`,
`test_ssh_passphrase_dialog_shown`, and the keymap-replay tests.
Verified under BOTH toolchains so the fix does not quietly raise the
MSRV: `cargo +1.98.0 fmt -- --check` and `cargo +1.98.0 clippy
--no-default-features -- -D warnings` are clean, and 1.97.1 still passes
`cargo build/test --no-default-features`, `cargo test` (GUI on) and
`cargo clippy -- -D warnings`.
Also merges `develop` (#661 Tooltip builder migration, which touches the
same `src/render.rs` / `src/tui_main/panels.rs` fixtures this branch
edits) so the tested tree matches the PR's merge commit, and documents
this whole failure shape in CLAUDE.md so the next single-red-check-no-red-
tests run is diagnosed in one `rustup check` instead of a repro hunt.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
JDonaghy
force-pushed
the
issue-617-engine-new-reads-ambient-disk-git-state
branch
from
August 24, 2026 03:35
41ab66b to
774517c
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.
Closes #617
Automated PR opened by coordinator for review of issue #617.