Skip to content

fork: TUI test isolation fix (also open upstream as #1366) - #3

Closed
ianalitis wants to merge 1 commit into
masterfrom
pr/tui-lib-test-failures
Closed

ianalitis wants to merge 1 commit into
masterfrom
pr/tui-lib-test-failures

Conversation

@ianalitis

@ianalitis ianalitis commented Sep 21, 2026 •

Copy link
Copy Markdown
Owner

Fork-side PR so this change is reviewed by Greptile here as well as upstream.

The same commit is open upstream as 1jehuang#1366
for issue 1jehuang#1365.

gather_git_info spawns a live git probe in test binaries again on master,
so jcode-tui --lib failure sets are order-dependent and differ per runner.
This restores the #[cfg(test)] read-only path from 1jehuang#1133 and narrows one
frame assertion that depended on how many frames the process had rendered.

cargo test -p jcode-tui --lib -- --test-threads=1: 19 failed before, 17 after
(2332 -> 2334 passing).

RetriggerConfidence Score: 4/5

The PR is not yet safe to merge because the updated account-clearing test selects a label that cannot exist and therefore fails before exercising the behavior under test.

Findings

  1. P2 Unreachable test cache branch ▶
  2. P2 Switch test proves no transition ▶
Fix with agent prompt
### Issue 1
crates/jcode-tui/src/tui/app/helpers.rs:1124-1131
This block can never compile: the enclosing function has `#[cfg(not(test))]`, so test builds exclude the whole function, while non-test builds exclude this inner block. The active `#[cfg(test)]` implementation at lines 1094–1103 already provides the read-only cache behavior. Keeping this duplicate dead code makes the explanation misleading and creates a second implementation that can drift from the real test path.

```suggestion

```

### Issue 2
crates/jcode-tui/src/tui/app/tests/commands_accounts_02/part_01.rs:553-560
This test asserts that the only inserted OpenAI account is already active, then asks `/account switch` to select that same account. The final assertion would therefore still pass if command submission or the switch operation were a no-op. Create a second account and make a different account active before submitting the command so this remains a meaningful regression test.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Summary

This PR prevents test builds from probing the live Git repository and makes a background-task rendering assertion target the suppressed card rather than unrelated box-drawing UI.

  • Adds a read-only Git-info cache path for tests while retaining stale-while-revalidate behavior in production.
  • Replaces a frame-wide border assertion with content-specific suppression checks.
  • Changes made since the previous review also restore incorrect hardcoded account-label assumptions in an unrelated test.

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

`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.
Comment on lines +1124 to +1131
#[cfg(test)]
{
return GIT_INFO_CACHE
.lock()
.ok()
.and_then(|guard| guard.as_ref().map(|(_, cached, _)| cached.clone()))
.flatten();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unreachable test cache branch

This block can never compile: the enclosing function has #[cfg(not(test))], so test builds exclude the whole function, while non-test builds exclude this inner block. The active #[cfg(test)] implementation at lines 1094–1103 already provides the read-only cache behavior. Keeping this duplicate dead code makes the explanation misleading and creates a second implementation that can drift from the real test path.

Suggested change
#[cfg(test)]
{
return GIT_INFO_CACHE
.lock()
.ok()
.and_then(|guard| guard.as_ref().map(|(_, cached, _)| cached.clone()))
.flatten();
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-tui/src/tui/app/helpers.rs
Line: 1124-1131

Comment:
**Unreachable test cache branch**

This block can never compile: the enclosing function has `#[cfg(not(test))]`, so test builds exclude the whole function, while non-test builds exclude this inner block. The active `#[cfg(test)]` implementation at lines 1094–1103 already provides the read-only cache behavior. Keeping this duplicate dead code makes the explanation misleading and creates a second implementation that can drift from the real test path.

```suggestion

```

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Comment on lines 560 to 567
rt.block_on(async {
app.input = "/account switch openai2".to_string();
app.input = format!("/account switch {assigned}");
app.submit_input();

assert_eq!(
crate::auth::codex::active_account_label().as_deref(),
Some("openai-1")
Some(assigned.as_str())
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Switch test proves no transition

This test asserts that the only inserted OpenAI account is already active, then asks /account switch to select that same account. The final assertion would therefore still pass if command submission or the switch operation were a no-op. Create a second account and make a different account active before submitting the command so this remains a meaningful regression test.

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-tui/src/tui/app/tests/commands_accounts_02/part_01.rs
Line: 560-567

Comment:
**Switch test proves no transition**

This test asserts that the only inserted OpenAI account is already active, then asks `/account switch` to select that same account. The final assertion would therefore still pass if command submission or the switch operation were a no-op. Create a second account and make a different account active before submitting the command so this remains a meaningful regression test.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@ianalitis
ianalitis force-pushed the pr/tui-lib-test-failures branch from 603e3b5 to 211067f Compare September 21, 2026 23:20
@ianalitis

Copy link
Copy Markdown
Owner Author

Closing this fork-side validation PR now that the corresponding upstream PR 1jehuang#1366 was merged. Keeping the branch untouched.

@ianalitis ianalitis closed this Sep 27, 2026
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