-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(cli): avoid O(n²) spinner truncation in CI #3943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ADITYA-CODE-SOURCE
wants to merge
1
commit into
triggerdotdev:main
from
ADITYA-CODE-SOURCE:fix/cli-truncate-message-ci-hang
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { afterEach, describe, expect, it } from "vitest"; | ||
| import { truncateMessage } from "./windows.js"; | ||
|
|
||
| const originalIsTTY = process.stdout.isTTY; | ||
| const originalColumns = process.stdout.columns; | ||
|
|
||
| function mockStdout(options: { isTTY: boolean; columns?: number | undefined }) { | ||
| Object.defineProperty(process.stdout, "isTTY", { | ||
| configurable: true, | ||
| value: options.isTTY, | ||
| }); | ||
|
|
||
| Object.defineProperty(process.stdout, "columns", { | ||
| configurable: true, | ||
| value: options.columns, | ||
| }); | ||
| } | ||
|
|
||
| afterEach(() => { | ||
| Object.defineProperty(process.stdout, "isTTY", { | ||
| configurable: true, | ||
| value: originalIsTTY, | ||
| }); | ||
|
|
||
| Object.defineProperty(process.stdout, "columns", { | ||
| configurable: true, | ||
| value: originalColumns, | ||
| }); | ||
| }); | ||
|
|
||
| describe("truncateMessage", () => { | ||
| it("returns the original message when stdout is not a TTY", () => { | ||
| mockStdout({ isTTY: false, columns: undefined }); | ||
|
|
||
| const message = "a".repeat(500); | ||
|
|
||
| expect(truncateMessage(message)).toBe(message); | ||
| }); | ||
|
|
||
| it("returns the original message when stdout has no columns", () => { | ||
| mockStdout({ isTTY: true, columns: undefined }); | ||
|
|
||
| const message = "a".repeat(500); | ||
|
|
||
| expect(truncateMessage(message)).toBe(message); | ||
| }); | ||
|
|
||
| it("does not truncate short messages", () => { | ||
| expect(truncateMessage("hello", 20)).toBe("hello"); | ||
| }); | ||
|
|
||
| it("truncates long plain messages", () => { | ||
| expect(truncateMessage("hello world", 12)).toBe("hell..."); | ||
| }); | ||
|
|
||
| it("truncates ANSI-colored messages without counting escape codes", () => { | ||
| const message = "\x1b[31mhello world\x1b[39m"; | ||
|
|
||
| expect(truncateMessage(message, 12)).toBe("\x1b[31mhell\x1b[0m..."); | ||
| }); | ||
|
|
||
| it("preserves terminal hyperlink escapes when truncating", () => { | ||
| const open = "\u001b]8;;https://trigger.dev\u0007"; | ||
| const close = "\u001b]8;;\u0007"; | ||
| const message = `${open}hello world${close}`; | ||
|
|
||
| expect(truncateMessage(message, 12)).toBe(`${open}hell${close}...`); | ||
| }); | ||
| }); |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡
updateAnsiStateignores previous SGR state on partial resets, causing terminal attribute leaksupdateAnsiStateaccepts ahasActiveSgrparameter but never uses it when the sequence ends withm(line 24). It only checks whether the current sequence's codes are non-reset codes. When a partial reset is encountered (e.g.\x1b[39mto reset foreground), the function returnsfalseeven 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 worldwith truncation at 4 visible chars:\x1b[1;31m→ codes=[1,31], 1 not in resetCodes →hasActiveSgr = true✓\x1b[39m→ codes=[39], 39 IS in resetCodes →codes.some(code => !ansiResetCodes.has(code))returnsfalse→hasActiveSgr = false✗hasActiveSgrisfalse→ no\x1b[0mappendedResult:
\x1b[1;31mhe\x1b[39mll...— bold (code 1) leaks into subsequent terminal output.The fix should consult
hasActiveSgrwhen 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.Was this helpful? React with 👍 or 👎 to provide feedback.