Repository navigation
fix: preserve nested command failure diagnostics #3089
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
Merged
Merged
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
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,48 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { test } from 'vitest'; | ||
| import { redactDiagnosticData } from './redaction.ts'; | ||
|
|
||
| test('stderr retains nested command failure details beyond 400 characters', () => { | ||
| const stderr = `Launch request denied\n${'Context line\n'.repeat(50)}Underlying reason: device locked`; | ||
| assert.equal(redactDiagnosticData({ stderr }).stderr, stderr); | ||
| }); | ||
|
|
||
| test('stderr preserves its head and tail within an 8192-character budget', () => { | ||
| const stderr = `Launch request denied\n${'x'.repeat(9000)}\nUnderlying reason: device locked`; | ||
| const result = redactDiagnosticData({ stderr }); | ||
| assert.equal(result.stderr.length, 8192); | ||
| assert.ok(result.stderr.startsWith('Launch request denied\n')); | ||
| assert.ok(result.stderr.endsWith('\nUnderlying reason: device locked')); | ||
| assert.match(result.stderr, /<truncated>/); | ||
| assert.deepEqual(redactDiagnosticData(result), result); | ||
| }); | ||
|
|
||
| test('stderr at the budget is preserved without truncation', () => { | ||
| const stderr = 'x'.repeat(8192); | ||
| assert.equal(redactDiagnosticData({ stderr }).stderr, stderr); | ||
| }); | ||
|
|
||
| test('expanded stderr redacts secrets before retaining its head and tail', () => { | ||
| const stderr = [ | ||
| 'Launch request denied token=head-secret', | ||
| 'x'.repeat(500), | ||
| 'password=middle-secret', | ||
| 'x'.repeat(9000), | ||
| 'Underlying reason: bearer tail-secret', | ||
| 'https://user:pass@example.com/error?token=query-secret', | ||
| ].join('\n'); | ||
| const result = redactDiagnosticData({ nested: { stderr }, apiKey: 'field-secret' }); | ||
| assert.equal(result.apiKey, '[REDACTED]'); | ||
| assert.ok(result.nested.stderr.startsWith('Launch request denied token=[REDACTED]')); | ||
| assert.ok(result.nested.stderr.includes('Underlying reason: [REDACTED]')); | ||
| assert.ok(result.nested.stderr.endsWith('https://REDACTED:REDACTED@example.com/error?REDACTED')); | ||
| assert.doesNotMatch(result.nested.stderr, /head-secret|middle-secret|tail-secret|query-secret/); | ||
| }); | ||
|
|
||
| test('other diagnostic strings retain the 400-character limit', () => { | ||
| const result = redactDiagnosticData({ message: 'm'.repeat(500), stdout: 'o'.repeat(500) }); | ||
| assert.equal(result.message.length, 400); | ||
| assert.equal(result.stdout.length, 400); | ||
| assert.ok(result.message.endsWith('...<truncated>')); | ||
| assert.ok(result.stdout.endsWith('...<truncated>')); | ||
| }); |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
P3: The new head/tail truncation can split an emoji at either retained boundary, so JSON consumers receive an unpaired surrogate and the diagnostic character is corrupted. Trim each retained boundary when it cuts a surrogate pair before concatenating the marker.
Prompt for AI agents