tests/tui_spec: remove the NO_COLOR env race behind the flaky suite #164

Merged
sirius merged 2 commits from onionwire/t_75caf868-onionwire-tui-tests-no_color-env-race-ma into main 2026-09-27 18:08:48 +00:00
Owner

Fixes the NO_COLOR env race that made tests/tui_spec.rs flaky (card t_75caf868).

What was wrong

alert_line_prefixes_when_no_color flipped the process-global NO_COLOR without the ASCII_ENV mutex the other env-touching tests in the same binary hold. A concurrent remove_var("NO_COLOR") could win, alert_line() then resolved to Rgb/Ansi16 and the ! assertion failed on a run with no code change (measured 1/12 runs at cc1201d).

Change

  • tui::alert_line_for_mode(mode, msg, width) is the new seam; alert_line() is a one-line delegate passing color_mode(), so production behaviour is identical.
  • The test injects ColorMode::None / ColorMode::Rgb instead of mutating the environment, and pins three shapes: None prefixes ! in None mode, Rgb leaves the message verbatim, and an already-prefixed alert is not double-prefixed.
  • Same-class second race, surfaced by the 20x repeat: wallets_settings_menu_frame_shows_the_shipped_footer compares a rendered frame against a status_footer_phased computed moments earlier, and both read ascii_chrome() / color_mode() live. A concurrent ONIONWIRE_ASCII=1 made the two sides disagree. It now takes the same ASCII_ENV lock and forces unicode mode.

Evidence

  • cargo test --locked -> exit 0, 35 suites, 472 passed, 0 failed, 4 ignored
  • cargo clippy --locked --all-targets -- -D warnings -> exit 0
  • cargo test --locked --test tui_spec x60 -> 60 ok, 0 failures
  • assertion has teeth: with the prefix dropped from the no-colour path the test fails with expected ... prefix in None mode: "peer down" (reverted)
  • ONIONWIRE_ASCII=1 cargo test --locked --test tui_spec -> 37 passed, so no unlocked test's outcome depends on the ambient value
  • rustfmt --check diff counts match HEAD (src/tui.rs 16 == 16 inherited; tests/tui_spec.rs 3 vs HEAD 4)

No production behaviour change; no new dependency.

Fixes the `NO_COLOR` env race that made `tests/tui_spec.rs` flaky (card t_75caf868). ## What was wrong `alert_line_prefixes_when_no_color` flipped the process-global `NO_COLOR` without the `ASCII_ENV` mutex the other env-touching tests in the same binary hold. A concurrent `remove_var("NO_COLOR")` could win, `alert_line()` then resolved to Rgb/Ansi16 and the `! ` assertion failed on a run with no code change (measured 1/12 runs at cc1201d). ## Change - `tui::alert_line_for_mode(mode, msg, width)` is the new seam; `alert_line()` is a one-line delegate passing `color_mode()`, so production behaviour is identical. - The test injects `ColorMode::None` / `ColorMode::Rgb` instead of mutating the environment, and pins three shapes: `None` prefixes `! ` in None mode, Rgb leaves the message verbatim, and an already-prefixed alert is not double-prefixed. - Same-class second race, surfaced by the 20x repeat: `wallets_settings_menu_frame_shows_the_shipped_footer` compares a rendered frame against a `status_footer_phased` computed moments earlier, and both read `ascii_chrome()` / `color_mode()` live. A concurrent `ONIONWIRE_ASCII=1` made the two sides disagree. It now takes the same `ASCII_ENV` lock and forces unicode mode. ## Evidence - `cargo test --locked` -> exit 0, 35 suites, 472 passed, 0 failed, 4 ignored - `cargo clippy --locked --all-targets -- -D warnings` -> exit 0 - `cargo test --locked --test tui_spec` x60 -> 60 ok, 0 failures - assertion has teeth: with the prefix dropped from the no-colour path the test fails with `expected ... prefix in None mode: "peer down"` (reverted) - `ONIONWIRE_ASCII=1 cargo test --locked --test tui_spec` -> 37 passed, so no unlocked test's outcome depends on the ambient value - rustfmt `--check` diff counts match HEAD (src/tui.rs 16 == 16 inherited; tests/tui_spec.rs 3 vs HEAD 4) No production behaviour change; no new dependency.
tests/tui_spec: remove the NO_COLOR env race behind the flaky suite
Some checks failed
android-ci / android (pull_request) Has been cancelled
ci / test (pull_request) Successful in 6m23s
ci / sdk (pull_request) Successful in 1m17s
ci / fuzz (pull_request) Successful in 5m6s
a9cb0d5758
`alert_line_prefixes_when_no_color` flipped the process-global `NO_COLOR`
without the `ASCII_ENV` mutex the other env-touching tests in this binary
hold, so a concurrent `remove_var("NO_COLOR")` could win and make
`alert_line()` resolve to Rgb/Ansi16 — the `! ` assertion then failed on an
otherwise green run (measured 1/12 runs at cc1201d).

Inject the colour mode instead of reading the environment in the test:

* `tui::alert_line_for_mode(mode, msg, width)` — `alert_line()` is now a
  one-line delegate passing `color_mode()`, so production behaviour is
  unchanged and the no-colour path is asserted without touching the env.
* The test now pins all three shapes of that path: `None` prefixes `! `,
  Rgb leaves the message verbatim, and an already-prefixed alert is not
  double-prefixed.

Also fix the second, same-class race the 20x repeat surfaced:
`wallets_settings_menu_frame_shows_the_shipped_footer` compares a rendered
frame against `status_footer_phased` computed moments earlier, and both read
`ascii_chrome()`/`color_mode()` live — a concurrent `ONIONWIRE_ASCII=1` made
the two sides disagree (✓/… vs ok/...). It now takes the same `ASCII_ENV`
lock and forces the unicode mode.

Evidence (TMPDIR=/home/lancelot/.hermes/tmp/onionwire-tui):
* cargo test --locked -> exit 0, 35 suites, 472 passed, 0 failed, 4 ignored
* cargo clippy --locked --all-targets -- -D warnings -> exit 0
* cargo test --locked --test tui_spec x60 -> 60 ok, 0 failures
* teeth: with the `! ` prefix removed from the None path, the test fails
  ("expected '! ' prefix in None mode: \"peer down\"") — reverted.
* ONIONWIRE_ASCII=1 cargo test --locked --test tui_spec -> 37 passed (no
  unlocked test's outcome depends on the ambient value)
* rustfmt --edition 2024 --check on both files: only the inherited hunks
  (src/tui.rs 16 == HEAD 16; tests/tui_spec.rs 3 vs HEAD 4, one inherited
  hunk reformatted away by this edit)
Merge branch 'main' into onionwire/t_75caf868-onionwire-tui-tests-no_color-env-race-ma
Some checks failed
ci / test (pull_request) Failing after 29s
ci / sdk (pull_request) Successful in 1m11s
ci / fuzz (pull_request) Successful in 5m10s
android-ci / android (pull_request) Successful in 12m5s
0149e105b0
sirius merged commit dca69bad6f into main 2026-09-27 18:08:48 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/onionwire!164
No description provided.