Skip to content

test(tui): pin truecolor in colour tests instead of inheriting COLORTERM - #1558

Merged
1jehuang merged 1 commit into
1jehuang:masterfrom
Kenmege:test/tui-pin-truecolor-in-colour-tests
Sep 29, 2026
Merged

1jehuang merged 1 commit into
1jehuang:masterfrom
Kenmege:test/tui-pin-truecolor-in-colour-tests

Conversation

@Kenmege

@Kenmege Kenmege commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Closes #1557.

Problem

Three colour tests assert exact truecolor output, but they take the colour capability from the environment running them. With COLORTERM unset they quantize to 256 colours and fail. This happens on macOS and Linux; they pass only when the shell exports COLORTERM=truecolor.

  • jcode-tui-style: configured_role_recolors_role_cells_and_named_colors_only, configured_colors_survive_the_light_theme_pass
  • jcode-tui-workspace: render_workspace_map_colors_completed_tiles_green

Change

Test-only in effect:

  • jcode-tui-style/src/palette.rs: the shared buffer_tests palette helper calls the crate's existing color::pin_truecolor_for_tests() before drawing. The jcode-tui palette topology tests already use that same pin.
  • jcode-tui-workspace/src/color_support.rs: color_capability() returns TrueColor under cfg!(test), so only this crate's own unit tests are affected. The crate has no separate pin hook, and none of its tests exercise the 256-colour path through color_capability(). The quantizer tests call rgb_to_xterm256 directly, and the glyph-safe tests call the detection functions. Release and dependent-crate builds are unchanged.

Verification (rustc 1.98.1, macOS arm64)

Before (master 4c4d965):

$ env -u COLORTERM -u TERM_PROGRAM cargo test -p jcode-tui-style -p jcode-tui-workspace --lib --no-fail-fast
test palette::buffer_tests::configured_role_recolors_role_cells_and_named_colors_only ... FAILED
test palette::light_theme_interaction::configured_colors_survive_the_light_theme_pass ... FAILED
test result: FAILED. 80 passed; 2 failed; 1 ignored
test workspace_map_widget::tests::render_workspace_map_colors_completed_tiles_green ... FAILED
test result: FAILED. 23 passed; 1 failed; 0 ignored

$ COLORTERM=truecolor cargo test -p jcode-tui-style -p jcode-tui-workspace --lib --no-fail-fast
test result: ok. 82 passed; 0 failed; 1 ignored
test result: ok. 24 passed; 0 failed; 0 ignored

After, both with COLORTERM unset and with COLORTERM=truecolor:

test result: ok. 82 passed; 0 failed; 1 ignored
test result: ok. 24 passed; 0 failed; 0 ignored
  • cargo clippy -p jcode-tui-style -p jcode-tui-workspace --no-deps --all-targets --all-features -- -D warnings: exit 0.
  • rustfmt --edition 2024 --check on both files: clean.

🤖 Generated with Claude Code

Three tests assert exact truecolor output but take the colour capability
from the environment running them: jcode-tui-style's palette buffer and
light-theme tests, and jcode-tui-workspace's completed-tile colour test.
With COLORTERM unset they quantize to 256 colours and fail, on macOS and
Linux alike; they pass only when the shell exports COLORTERM=truecolor.

The palette test helper now calls the crate's existing
pin_truecolor_for_tests(), as the jcode-tui palette topology tests do,
and jcode-tui-workspace reports truecolor under its own unit tests
(no test there exercises the 256-colour path through
color_capability(); the quantizer tests call rgb_to_xterm256 directly).

Closes 1jehuang#1557

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Low risk] Test setup pins color output mode for consistency.

Do not merge until the light-theme test passes independently of terminal settings and test order. The workspace coverage concern is non-blocking.

Findings

  1. P1 Light-theme test remains unpinned ▶
  2. P2 Unit tests bypass color detection ▶
Fix with agent prompt
### Issue 1
crates/jcode-tui-style/src/palette.rs:540
This pin applies only to the buffer-test helper. The light-theme test sets up its palette separately, so on a 256-color terminal it quantizes the configured color and fails its exact RGB assertion when run alone. It passes after an earlier buffer test leaves the process-wide pin set. Pin truecolor in the light-theme test’s own setup before merging.

### Issue 2
crates/jcode-tui-workspace/src/color_support.rs:17-19
Returning `TrueColor` for every workspace unit test prevents those tests from exercising the complete 256-color path through `color_capability()` and `rgb()`. Under a 256-color terminal, a unit-test build now returns `Rgb(35, 40, 50)` rather than `Indexed(235)`. The existing quantizer tests still pass, so they cannot catch a failure in this output path. This coverage gap is non-blocking; limit the override to the rendering test that needs it.

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 pins truecolor for palette buffer tests and forces truecolor in workspace unit-test builds. The light-theme test still fails when run alone on a 256-color terminal, so its test-order dependency must be fixed before merging. The workspace override also leaves the complete 256-color output path untested.

Reviews (1) · Last reviewed commit: "test(tui): pin truecolor in colour tests..."

let _lock = TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let _restore = Restore;
// The assertions compare exact truecolor output; never depend on the runner's COLORTERM.
crate::color::pin_truecolor_for_tests();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Light-theme test remains unpinned

This pin applies only to the buffer-test helper. The light-theme test sets up its palette separately, so on a 256-color terminal it quantizes the configured color and fails its exact RGB assertion when run alone. It passes after an earlier buffer test leaves the process-wide pin set. Pin truecolor in the light-theme test’s own setup before merging.

Artifacts

Exact verification script

  • This is the verbatim script executed from `/home/user/repo` to run and capture all three test conditions.

Isolated light-theme test without truecolor

  • The isolated test ran with truecolor detection unset and failed its RGB assertion with exit code 101.

Light-theme test after earlier palette tests

  • The sequential palette run executed the earlier pinning tests before the light-theme test, which passed with exit code 0.

Isolated light-theme test with truecolor enabled

  • The isolated test ran with `COLORTERM=truecolor` and passed with exit code 0, confirming the capability condition.

View artifacts

T-Rex Ran code and verified through T-Rex

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-tui-style/src/palette.rs
Line: 540

Comment:
**Light-theme test remains unpinned**

This pin applies only to the buffer-test helper. The light-theme test sets up its palette separately, so on a 256-color terminal it quantizes the configured color and fails its exact RGB assertion when run alone. It passes after an earlier buffer test leaves the process-wide pin set. Pin truecolor in the light-theme test’s own setup before merging.

---

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

Comment on lines +17 to +19
if cfg!(test) {
return ColorCapability::TrueColor;
}

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 Unit tests bypass color detection

Returning TrueColor for every workspace unit test prevents those tests from exercising the complete 256-color path through color_capability() and rgb(). Under a 256-color terminal, a unit-test build now returns Rgb(35, 40, 50) rather than Indexed(235). The existing quantizer tests still pass, so they cannot catch a failure in this output path. This coverage gap is non-blocking; limit the override to the rendering test that needs it.

Artifacts

Exact 256-color Rust probe

  • This authored test calls the actual color-support code and asserts indexed output under a forced 256-color terminal, making the missing path observable.

Exact before-and-after probe commands

  • This executed script compiles the same probe against the parent and PR sources, then captures each command, working directory, exit code, and output.

Parent source under a 256-color terminal

  • The probe ran against the parent source with `TERM=xterm-256color` and passed with `Color256` and `Indexed(235)`.

PR source under a 256-color terminal

  • The same probe ran against the PR source and failed after observing `TrueColor` and `Rgb(35, 40, 50)`, confirming the bypass.

Existing color-support tests under a 256-color terminal

  • The crate's 13 existing color-support tests all passed with `TERM=xterm-256color`, showing they do not catch this output-path regression.

View artifacts

T-Rex Ran code and verified through T-Rex

Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/jcode-tui-workspace/src/color_support.rs
Line: 17-19

Comment:
**Unit tests bypass color detection**

Returning `TrueColor` for every workspace unit test prevents those tests from exercising the complete 256-color path through `color_capability()` and `rgb()`. Under a 256-color terminal, a unit-test build now returns `Rgb(35, 40, 50)` rather than `Indexed(235)`. The existing quantizer tests still pass, so they cannot catch a failure in this output path. This coverage gap is non-blocking; limit the override to the rendering test that needs it.

---

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!

@greptile-apps

greptile-apps Bot commented Sep 28, 2026

Copy link
Copy Markdown

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 Light-theme RGB test depends on an earlier truecolor pin ▶

    • Bug
      • With terminal truecolor unset, configured_colors_survive_the_light_theme_pass fails its exact RGB assertion when selected alone. It passes in the sequential palette run after buffer_tests executes. Confidence is high for this demonstrated order dependence.
    • Cause
      • buffer_tests::with_palette pins a process-global truecolor override at crates/jcode-tui-style/src/palette.rs:540, but the separate light-theme test at line 634 does not. Without that pin, the configured color is quantized before the assertion at line 666.
    • Fix
      • Pin truecolor in the light-theme test's own setup before rendering, rather than relying on another test to run first.
  • P2 Unit-test builds cannot exercise the 256-color rgb output path ▶

    • Bug
      • With TERM=xterm-256color and other terminal-detection variables absent, rgb(35,40,50) returns Rgb(35, 40, 50) in the PR's unit-test build instead of Indexed(235). Existing tests still pass because they call the quantizer directly rather than testing this output path.
    • Cause
      • The unconditional cfg!(test) return at crates/jcode-tui-workspace/src/color_support.rs:17–19 bypasses capability detection for every unit test.
    • Fix
      • Keep terminal detection testable in unit builds; control the environment or inject a capability for tests that require truecolor, and add a test of rgb() under Color256.

@1jehuang
1jehuang merged commit be4b098 into 1jehuang:master Sep 29, 2026
1 check 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.

Colour tests in jcode-tui-style and jcode-tui-workspace fail when COLORTERM is unset

2 participants