Skip to content

CI compiles the TUI lib tests but never runs them, hiding ~21 failures #592

Closed

Description

@1jehuang

Problem

cargo test -p jcode-tui fails with ~21 failures on a clean master, but CI never catches it because the Linux test job only compiles the lib tests:

cargo test --target $TARGET --lib --bins --no-run

It then runs only -p jcode-app-core --lib retention_readiness, --test provider_matrix, and --test e2e. The ~2000 TUI unit tests are built and thrown away.

Two consequences:

  1. Real breakage sits on master unnoticed. Until 4f968a8 the TUI lib tests did not even compile on master: three call sites still used ServerEvent::MessageEnd as a unit variant after it gained a stop_reason field. CI was green the whole time because --no-run on a failing test target was the only gate, and the compile error was in test-only code.
  2. The remaining failures are environment-dependent. Most are reasoning/trace rendering tests that read the developer's real ~/.jcode/config.toml. With reasoning_display = "off" set locally, ~13 of them fail. They also pollute each other through process-global catalog/UI state, so the failing set shifts between runs and several pass in isolation.

Reproduce

cargo test -p jcode-tui                      # ~21 failures
cargo test -p jcode-tui -- --test-threads=1  # still ~21, so not purely a race
cargo test -p jcode-tui tui::app::tests::gc_keeps_single_trace_indefinitely  # passes alone

Example: gc_keeps_single_trace_indefinitely asserts trace_count == 1 but gets 0, because reasoning_display resolves from the real user config rather than the test's temp JCODE_HOME.

Suggested fix

  1. Actually run the lib tests in CI (a separate step, or drop --no-run), so test-only compile errors and regressions surface.
  2. Make the reasoning/trace tests hermetic: they should force reasoning_display explicitly instead of inheriting whatever the developer configured. with_temp_jcode_home sets JCODE_HOME, but config resolution still reaches the real file in these paths.
  3. Isolate the process-global catalog/UI state these tests share, so the outcome does not depend on test ordering.

Found while releasing v0.58.0. Not a regression from that release: master shows the same failures, and the release fixed the compile breakage plus three jcode-base failures that were also red on master.

Activity

  1. 1jehuang commented on Jul 25, 2026

    @1jehuang
    OwnerAuthor

    Narrowed down: ~21 failures became ~2-4, and the remainder are load-sensitive, not broken code

    Re-measured on current master. The count dropped from ~21 to 2-4 per run (other fixes landed in the meantime, including the two hermeticity fixes in jcode-base). The important finding is that the remaining failures are not code defects, so "turn the lib tests on in CI" needs to be paired with fixing these, or CI will be permanently red.

    Two distinct causes:

    1. Wall-clock latency benchmarks asserted as unit tests

    test_debug_command_side_panel_latency_bench_reports_immediate_redraw asserts a hard threshold:

    value["summary"]["latency_ms"]["p95"].as_f64().unwrap_or_default() < 16.0,
    "headless side-panel p95 latency should stay within a 60fps frame budget"

    It measured p95 = 16.21ms against a 16.0ms budget while this machine was at load average 10-18 on 8 cores (several agents building in parallel). It passes in isolation. smoothness_benchmark_simulated_streaming_turn_stays_within_budget is the same shape.

    A shared CI runner is exactly the environment where a 60fps wall-clock budget is least reliable. These should either be #[ignore]d by default and run explicitly as benchmarks, gated behind an env var, or given a budget that reflects contended CI hardware.

    2. Process-global state shared across tests

    The rest vary run to run and pass in isolation, e.g. gather_ambient_info_filters_to_session_reminders_when_ambient_disabled (fails at .expect("ambient info")), test_remote_mixed_catalog_keeps_jcode_subscription_separate_from_other_providers, and several test_tui_* catalog tests. That file already carries a comment about an "unrelated in-flight cache refresh" overwriting "the cleared process-global cache with data loaded under another test's JCODE_HOME", so this is a known-hard area.

    For reference, the two jcode-base cases with the same root cause were fixable by scoping: one needed with_clean_provider_test_env, the other the shared test-env lock. cargo test -p jcode-base went from 1-2 intermittent failures to 1130 passing across three consecutive runs.

    Revised suggestion

    Ordering matters here:

    1. Reclassify the wall-clock benchmarks so they cannot fail a correctness run.
    2. Fix the remaining global-state leaks by scoping (env lock + private JCODE_HOME).
    3. Then enable the lib tests in CI, so the gate lands green and stays meaningful.

    Enabling the gate first would just make master permanently red and train everyone to ignore it.

  2. 1jehuang commented on Jul 25, 2026

    @1jehuang
    OwnerAuthor

    Measured: the suite passes serially, so this is parallelism, not broken code

    Concrete numbers on current master, which change the recommendation.

    Serial: cargo test -p jcode-tui --lib -- --test-threads=1 → 1977 passed, 0 failed (2 of 3 runs; the third had 1 unrelated flake).

    Parallel (default): 2-4 failures per run, and a different set each run:

    run failures
    1 overscroll_reveal_does_not_relayout_transcript, test_remote_mixed_catalog_keeps_jcode_subscription_separate_from_other_providers, test_tui_cerebras_paste_key_lifecycle_has_no_degraded_success_messages
    2 test_debug_command_side_panel_latency_bench_reports_immediate_redraw, test_save_and_restore_reload_state_preserves_split_view_mode, test_tui_openai_compatible_empty_catalog_does_not_switch_to_profile_default
    3 test_changelog_overlay_repeated_renders_are_stable, gather_ambient_info_filters_to_session_reminders_when_ambient_disabled

    Every one of them passes in isolation. So there is no correctness bug hiding here: the tests contend on process-global state (model catalog, ambient cache, render state, JCODE_HOME) and on wall-clock budgets.

    This makes the CI change cheap

    Rather than fixing every leak before enabling the gate, CI can run the TUI lib tests serially and get a meaningful signal today. It costs ~27s serial vs ~15s parallel for 1977 tests, which is noise next to the compile CI already pays for with --no-run.

    That would have caught the failure this issue was filed for: the lib tests did not compile on master (three ServerEvent::MessageEnd call sites left as unit variants after the enum gained a stop_reason field), and --no-run on a broken test target was the only gate.

    Longer term the shared state is still worth scoping, since ordering-dependent tests are fragile and hide real regressions. But that is a cleanup, not a prerequisite.

    Done in this pass

    • The side-panel p95 budget is now opt-in via JCODE_TEST_PERF_ASSERTIONS=1, with a printed note otherwise, so a loaded host cannot fail a correctness run. Verified in both directions with an artificially impossible budget.
    • Earlier: the two jcode-base leaks were scoped properly (with_clean_provider_test_env / the shared env lock); that crate now runs 1130 passing across three consecutive runs.

    Remaining for whoever picks this up: switch the CI step to run the lib tests (serially), then chip away at the global-state scoping.

  3. 1jehuang commented on Jul 25, 2026

    @1jehuang
    OwnerAuthor

    Done: CI now runs the TUI library tests

    Landed and verified green on master (run 30148283115, all 9 jobs pass).

    The gate (11cda7dcb, b8f917f03): the Linux job now runs cargo test -p jcode-tui --lib -- --test-threads=1. CI executed 1969 tests where it previously executed zero.

    Three decisions, each forced by a measurement rather than a guess:

    1. Serial. 1977 pass with --test-threads=1; in parallel 2-4 fail per run, a different set each time, every one passing in isolation. Costs ~40s, and the target was already being compiled.
    2. Linux only. Windows runs its own targeted test set and macOS adds no signal for a terminal UI.
    3. 8 tests skipped. They need a real desktop: the six copy_badge_shortcut tests drive an actual clipboard and fail with Failed to copy headlessly, and two render tests depend on terminal color support. I only found these by pushing the gate and reading the runner logs, so they are excluded explicitly rather than left to redden the build.

    Verified the gate catches the original bug: reintroducing one of the unit-variant ServerEvent::MessageEnd call sites makes the step exit 101, where the old --no-run gate stayed green.

    Also found and fixed a related blind spot. While verifying, Windows failed at Build release binary with cannot update the lock file ... because --locked was passed: arboard had been added to jcode-desktop2/Cargo.toml without regenerating Cargo.lock. Only the Windows jobs pass --locked, so that commit passed 8 of 9 jobs and failed Windows a long way from its cause. Fixed the lockfile (ffff86753) and added a cargo metadata --locked gate to Quality Guardrails and to scripts/check_guardrails.sh (23b402919), verified to exit 101 against the broken lockfile and 0 after.

    Left open deliberately

    The process-global state scoping. It is real technical debt (that is why the gate has to run serially, and why the 8 skips are blunt), but it is a cleanup rather than a prerequisite, and the gate is now protecting against the compile-level breakage that motivated this issue.

    Closing since the headline problem is fixed. Worth a fresh issue for the shared-state scoping if someone wants to make the suite parallel-safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions