Skip to content

fix(tui): stop the live git probe leaking host repo state into tests - #1366

Merged
1jehuang merged 1 commit into
1jehuang:masterfrom
ianalitis:pr/tui-lib-test-failures
Sep 23, 2026
Merged

1jehuang merged 1 commit into
1jehuang:masterfrom
ianalitis:pr/tui-lib-test-failures

Conversation

@ianalitis

Copy link
Copy Markdown
Contributor

Fixes #1365. Restores the behavior #1133 introduced and that master has since lost.

Problem

gather_git_info spawns a background thread that shells out to git and writes
the answer into a process-global cache. In a test binary the first caller gets
None and later tests inherit whatever repository cargo test ran from, so
frame assertions depend on test order and on whether the developer's checkout is
clean.

On master (2a4edaa02):

$ cargo test -p jcode-tui --lib -- --test-threads=1
test result: FAILED. 2332 passed; 19 failed; 18 ignored

Two of those are the onboarding "recent project" tests, which assert on a notice
that the leaked git state overwrites. seed_git_info_cache_for_tests still
exists (the onboarding golden test calls it) but is no longer honored, so seeding
does not stop the probe from replacing it.

Fix

Restore the #[cfg(test)] read path in gather_git_info: tests read the cache
and never spawn the probe, and seed_git_info_cache_for_tests is again the only
way to inject git data. Production behavior is unchanged.

The second commit narrows
test_background_task_markdown_is_suppressed_even_if_role_was_lost, which
asserted the rendered frame contains no box-drawing character at all. Info-widget
overlays legitimately draw their own bordered box in the right margin, and whether
they are docked depends on how many frames the process has already rendered, so
that assertion was order-dependent rather than a statement about the card. The
card assertions themselves are untouched.

Verification

cargo test -p jcode-tui --lib -- --test-threads=1:

Result
master 2332 passed, 19 failed
this change 2334 passed, 17 failed

The remaining failures are tracked in #1340, #1342 and the other open jcode-tui
issues; this PR only removes the order dependence that made the set unstable.
cargo fmt -p jcode-tui -- --check is clean.

`gather_git_info` spawns a background thread that shells out to `git` and writes
the answer into a process-global cache. The first caller in a test binary sees
`None`, but every test after it inherits the developer's real branch,
ahead/behind and dirty counts, so frame assertions depended on how many tests
ran before them and on whether the checkout was clean. `master` therefore
reports different `jcode-tui --lib` failures on different machines and on
different runs of the same machine.

Tests now read that cache without ever spawning the probe, and
`seed_git_info_cache_for_tests` remains the explicit way to opt in to git data
for the tests that want it.

This also narrows `test_background_task_markdown_is_suppressed_even_if_role_was_lost`,
which asserted the frame contains no box-drawing character at all. Info-widget
overlays legitimately draw their own bordered box in the right margin, and
whether they are docked depends on how many frames the process has already
rendered, so that assertion was order-dependent rather than a statement about
the card under test. The card assertions themselves are unchanged.

Measured on `master` (`cargo test -p jcode-tui --lib -- --test-threads=1`):
19 failed before, 17 failed after, with the remaining failures tracked separately
(#1340, #1342). Two of the failures this removes are the onboarding
"recent project" tests that fail or pass depending on the developer's git state.
@greptile-apps

greptile-apps Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

Not merge-safe until the account tests use the canonical labels returned when accounts are inserted.

What we checked:

  • T-Rex produced a proof for the posted P1 finding and linked it to the corresponding review comment. T-Rex
  • T-Rex executed the Account-label check script to verify the finding. T-Rex
  • A log named Account-label check output was generated to document the results of the check. T-Rex

Summary

  • Test isolation and cache behavior changes remain in place.
  • Two account-management tests now assume numeric labels that newly inserted accounts do not receive.

The account-label issue must be fixed before merging because it makes the affected test paths fail before exercising their intended behavior.

Reviews (3) · Last reviewed commit: "fix(tui): stop the live git probe leakin..."

@greptile-apps

greptile-apps Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff

These findings sit on lines the diff does not cover, so they could not be posted inline. Each one leaves this list once its file changes.

  • P1 Use assigned account labels crates/jcode-tui/src/tui/app/tests/commands_accounts_02/part_01.rs:560 ▶

    upsert_account canonicalizes a new account label rather than retaining the requested numeric label. This test switches to openai2 but expects openai-1; the inserted account is actually labeled openai-otter, so the assertion fails. The same numeric-label assumption in state_model_poke_02/part_01.rs calls set_active_account("claude-3"), which fails before the cleanup assertions run because no such account exists. Preserve and use the labels returned by each upsert_account call so these tests exercise their intended behavior.

@ianalitis

Copy link
Copy Markdown
Contributor Author

The P1 points at commands_accounts_02/part_01.rs and state_model_poke_02/part_01.rs, which are outside this PR's scope.

I split that fix out so each change is independently reviewable: it is now #1368 for issue #1367, and this PR is back to the single isolation commit that its title and description describe.

Two notes from that work, since they affect how you read this PR:

  • Your P2 there was right: with one account auto-activated, /account switch <that label> proved nothing, and the test passed with the switch removed. It now uses two accounts and fails without the switch.
  • cargo test -p jcode-tui --lib -- --test-threads=1 on this PR alone is 17 failed (from 19 on master); with fix(tui): stop two account tests asserting labels the store never assigns #1368 applied it is 15.

@1jehuang
1jehuang merged commit ed8d804 into 1jehuang:master Sep 23, 2026
1 check passed
KooshaPari pushed a commit to KooshaPari/KCode that referenced this pull request Oct 9, 2026
…jehuang#1366)

`gather_git_info` spawns a background thread that shells out to `git` and writes
the answer into a process-global cache. The first caller in a test binary sees
`None`, but every test after it inherits the developer's real branch,
ahead/behind and dirty counts, so frame assertions depended on how many tests
ran before them and on whether the checkout was clean. `master` therefore
reports different `jcode-tui --lib` failures on different machines and on
different runs of the same machine.

Tests now read that cache without ever spawning the probe, and
`seed_git_info_cache_for_tests` remains the explicit way to opt in to git data
for the tests that want it.

This also narrows `test_background_task_markdown_is_suppressed_even_if_role_was_lost`,
which asserted the frame contains no box-drawing character at all. Info-widget
overlays legitimately draw their own bordered box in the right margin, and
whether they are docked depends on how many frames the process has already
rendered, so that assertion was order-dependent rather than a statement about
the card under test. The card assertions themselves are unchanged.

Measured on `master` (`cargo test -p jcode-tui --lib -- --test-threads=1`):
19 failed before, 17 failed after, with the remaining failures tracked separately
(1jehuang#1340, 1jehuang#1342). Two of the failures this removes are the onboarding
"recent project" tests that fail or pass depending on the developer's git state.
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.

TUI test isolation regressed: gather_git_info probes the live repo again, so jcode-tui failures are order-dependent

2 participants