fix(cli): avoid O(n²) spinner truncation in CI#3943
Conversation
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
Walkthrough
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi @ADITYA-CODE-SOURCE, thanks for your interest in contributing! This project requires that pull request authors are vouched, and you are not in the list of vouched users. This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details. |
| const rawCodes = sequence.slice(2, -1); | ||
| const codes = rawCodes === "" ? [0] : rawCodes.split(";").map(Number); | ||
|
|
||
| return codes.some((code) => !ansiResetCodes.has(code)); |
There was a problem hiding this comment.
🟡 updateAnsiState ignores previous SGR state on partial resets, causing terminal attribute leaks
updateAnsiState accepts a hasActiveSgr parameter but never uses it when the sequence ends with m (line 24). It only checks whether the current sequence's codes are non-reset codes. When a partial reset is encountered (e.g. \x1b[39m to reset foreground), the function returns false even if other attributes (e.g. bold from a prior \x1b[1;31m) are still active.
Example trace showing the bug
For input \x1b[1;31mhe\x1b[39mllo world with truncation at 4 visible chars:
\x1b[1;31m→ codes=[1,31], 1 not in resetCodes →hasActiveSgr = true✓- 'h','e' → visible chars
\x1b[39m→ codes=[39], 39 IS in resetCodes →codes.some(code => !ansiResetCodes.has(code))returnsfalse→hasActiveSgr = false✗- 'l','l' → 4 visible chars reached, truncate
hasActiveSgrisfalse→ no\x1b[0mappended
Result: \x1b[1;31mhe\x1b[39mll... — bold (code 1) leaks into subsequent terminal output.
The fix should consult hasActiveSgr when all codes in the current sequence are reset codes but none is a full reset (code 0). Only a full reset (\x1b[0m) or explicit reset of every active attribute should clear the state.
| return codes.some((code) => !ansiResetCodes.has(code)); | |
| if (codes.some((code) => !ansiResetCodes.has(code))) return true; | |
| if (codes.includes(0)) return false; | |
| return hasActiveSgr; |
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
truncateMessage()with a single-pass ANSI-aware truncation pathTesting
corepack pnpm --filter trigger.dev test src/utilities/windows.test.ts