Repository navigation
test(tui): pin truecolor in colour tests instead of inheriting COLORTERM - #1558
Conversation
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]>
|
| 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(); |
There was a problem hiding this 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.
Artifacts
- 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.
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.| if cfg!(test) { | ||
| return ColorCapability::TrueColor; | ||
| } |
There was a problem hiding this 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.
Artifacts
- 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.
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!
Comments Outside DiffThese 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.
|
Closes #1557.
Problem
Three colour tests assert exact truecolor output, but they take the colour capability from the environment running them. With
COLORTERMunset they quantize to 256 colours and fail. This happens on macOS and Linux; they pass only when the shell exportsCOLORTERM=truecolor.jcode-tui-style:configured_role_recolors_role_cells_and_named_colors_only,configured_colors_survive_the_light_theme_passjcode-tui-workspace:render_workspace_map_colors_completed_tiles_greenChange
Test-only in effect:
jcode-tui-style/src/palette.rs: the sharedbuffer_testspalette helper calls the crate's existingcolor::pin_truecolor_for_tests()before drawing. Thejcode-tuipalette topology tests already use that same pin.jcode-tui-workspace/src/color_support.rs:color_capability()returnsTrueColorundercfg!(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 throughcolor_capability(). The quantizer tests callrgb_to_xterm256directly, 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):
After, both with
COLORTERMunset and withCOLORTERM=truecolor:cargo clippy -p jcode-tui-style -p jcode-tui-workspace --no-deps --all-targets --all-features -- -D warnings: exit 0.rustfmt --edition 2024 --checkon both files: clean.🤖 Generated with Claude Code