Skip to content

#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 into
developfrom
issue-617-engine-new-reads-ambient-disk-git-state
Aug 24, 2026
Merged

#617: Engine::new() reads ambient disk/git state during construction — give it a test constructor instead of patching leaks one at a time#662
JDonaghy merged 3 commits into
developfrom
issue-617-engine-new-reads-ambient-disk-git-state

Conversation

@JDonaghy

Copy link
Copy Markdown
Owner

Closes #617

Automated PR opened by coordinator for review of issue #617.

JDonaghy and others added 3 commits August 24, 2026 03:34
…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
JDonaghy force-pushed the issue-617-engine-new-reads-ambient-disk-git-state branch from 41ab66b to 774517c Compare August 24, 2026 03:35
@JDonaghy
JDonaghy merged commit caeb28d into develop Aug 24, 2026
2 checks passed
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.

Engine::new() reads ambient disk/git state during construction — give it a test constructor instead of patching leaks one at a time

1 participant