Skip to content

[Test Quality] Assert ANSI colorization in pretty stats output - #11395

Merged
lpcox merged 1 commit into
mainfrom
test-quality/colorize-pretty-output-91bb9828375a9d85
Nov 10, 2026
Merged

lpcox merged 1 commit into
mainfrom
test-quality/colorize-pretty-output-91bb9828375a9d85

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Contract

formatStats(stats, 'pretty', colorize) in src/logs/stats-formatter.ts (see awf logs stats in CLAUDE.md) emits ANSI colors only when colorize is true, and otherwise emits plain text.

Previous weakness

should work with colorize enabled only asserted expect(output).toBeTruthy(). Ignoring the colorize flag would still pass it.

Change

The test now forces chalk.level = 1 (restored in finally) and asserts three things:

  • The plain output has no ANSI escapes.
  • The colored output has ANSI escapes.
  • The colored output with escapes stripped equals the plain output.

Evidence

Commands:

  • npm run build was not needed; the test runs through ts-jest.
  • ./node_modules/.bin/jest --runInBand --no-coverage --runTestsByPath src/logs/stats-formatter.test.ts

Results:

  • Baseline: 26/26 passed.
  • With the temporary production mutation const c = false ? chalk : ... (colors ignored):
    • The old test would still pass, because its output is still truthy.
    • The new test fails: Expected substring: "\u001b[".
    • The mutation was reverted afterwards.
  • Final clean rerun: 26/26 passed.
  • eslint on the test file reports 0 errors and 1 security/detect-non-literal-regexp warning. The RegExp is built from a constant ESC character to avoid no-control-regex.

CI

The root Jest suite (src/**) runs this file in the existing unit-test job.

Limits

This is a component-level test of the formatter. It is not container or network enforcement evidence. No tests were removed.

Generated by Test Quality Improver · copilot · auto (Claude Sonnet 5.5) · ~23 AIC · ⌖ ~1 AIC · ⊞ 11.5K · ◷

  • expires on Dec 10, 2026, 4:44 AM UTC

@lpcox
lpcox marked this pull request as ready for review November 10, 2026 04:44
Copilot AI adaptive review requested due to automatic review settings November 10, 2026 04:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are identified, and the test coverage directly checks both ANSI formatting behavior and preservation of the underlying text.

No open issues 🎉

What changed in this PR

This PR strengthens the pretty statistics formatter test to verify that the colorize flag controls ANSI output without changing the underlying text.

Changes:

  • Temporarily forces Chalk color output while restoring its original configuration afterward.
  • Verifies plain output has no ANSI escapes.
  • Verifies colored output has ANSI escapes and matches plain output after escape removal.
File Description
src/​logs/​stats-formatter.test.ts Adds assertions covering plain and ANSI-colored pretty stats output, including equivalence after stripping escape sequences.

Review effort: Lite (auto)

@github-actions

Copy link
Copy Markdown
Contributor Author

✅ Copilot review passed with no inline comments.

@github-actions[bot] Add the ready-for-aw label to this PR to trigger agentic CI smoke tests.

@lpcox
lpcox merged commit b5de920 into main Nov 10, 2026
43 of 62 checks passed
@lpcox
lpcox deleted the test-quality/colorize-pretty-output-91bb9828375a9d85 branch November 10, 2026 16:38
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.

2 participants