Assert the debug output's value, not its colour - #21
Merged
Merged
Conversation
The token test looked for "Token:" in what _outputOptions wrote. chalk colours the option name, so an ANSI reset sits between the name and the colon, and the assertion only held where chalk had gone quiet -- any run whose stdout is a pipe, meaning CI and every scripted run. It failed the first time the suite ran in a terminal, during a release. The captured output now goes through stripVTControlCharacters, so the test asserts the value it was always about rather than the spelling it arrived in. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What broke
npm run releasefails atnpm test, on a test I added in #20:The redaction itself works — the
assert.notInclude(output, "<the token>")beside itpasses. What fails is the next assertion.
_outputOptionswriteschalk.yellow("Token") + ": <hidden>", so with colour on there is an ANSI reset betweenthe name and the colon and the literal
Token:never appears.chalk goes quiet when stdout is not a TTY. That covers CI and every scripted run, so the
test passed on the PR, passed on the merge to master, and passed every time I ran it. It
failed the first time it ran in a terminal, which was your release.
This is exactly what AGENTS.md says not to do:
My mistake, and the reason the release stopped.
The fix
Normalise at the boundary with
stripVTControlCharactersfromnode:util— a built-in,available well under the
>= 24engines floor, so no new dependency and nono-control-regexsuppression. The assertion then readsToken: <hidden>, the value itwas always about.
No change to
lib/. The redaction behaviour merged in #20 is unaffected.Verification
Reproduced first, on master, before the fix:
After:
The whole suite is clean under forced colour, not just this test, so nothing else in it
asserts on chalk's rendering.
npm run lintis clean apart from the pre-existingmocha/no-pending-testswarning intest/Gren.spec.js.Follow-up worth doing separately
CI only ever sees a pipe, so it cannot catch this class of bug by construction: a
coloured-string assertion is always green there and always red for you. Running the suite
once more with
FORCE_COLORset closes that gap. I could not include it here — pushing a.github/workflows/change needs a token withworkflowscope, which this one does nothave — so the diff is below if you want it:
- run: npm ci - run: npm test + - name: Test with colour forced on + run: npm test + env: + # chalk goes quiet when stdout is a pipe, which is all CI ever sees. A test that + # asserts on a coloured string passes here and fails for whoever runs it by hand. + FORCE_COLOR: 1 - run: npm run lintIt is additive: the existing uncoloured runs are untouched, and I verified the full suite
passes under forced colour on both the with-token and without-token paths.
🤖 Generated with Claude Code