|
6 | 6 | sanitizeEnvForLogging, |
7 | 7 | sanitizePayloadForLogging, |
8 | 8 | sanitizeStderr, |
9 | | - sanitizeStderrTail |
| 9 | + sanitizeStderrTail, |
| 10 | + describeDapEventBodyForLog |
10 | 11 | } from '../../src/utils/env-sanitizer.js'; |
11 | 12 |
|
12 | 13 | describe('sanitizeEnvForLogging', () => { |
@@ -341,3 +342,35 @@ describe('sanitizeStderrTail', () => { |
341 | 342 | expect(sanitizeStderrTail(' \n \r\n')).toBe(''); |
342 | 343 | }); |
343 | 344 | }); |
| 345 | + |
| 346 | +describe('describeDapEventBodyForLog (issue #852)', () => { |
| 347 | + const token = 'ghp_A1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q7r8S9t0'; |
| 348 | + |
| 349 | + it('keeps only the shape of an output event: category and length, never the text', () => { |
| 350 | + const output = `token=${token}\n`; |
| 351 | + const described = describeDapEventBodyForLog('output', { category: 'stdout', output }); |
| 352 | + expect(described).toEqual({ category: 'stdout', outputLength: output.length }); |
| 353 | + expect(JSON.stringify(described)).not.toContain('ghp_'); |
| 354 | + }); |
| 355 | + |
| 356 | + it('defaults a missing category to console and a missing text to length 0', () => { |
| 357 | + expect(describeDapEventBodyForLog('output', {})).toEqual({ category: 'console', outputLength: 0 }); |
| 358 | + expect(describeDapEventBodyForLog('output', undefined)).toEqual({ category: 'console', outputLength: 0 }); |
| 359 | + }); |
| 360 | + |
| 361 | + it('sanitizes every other event body like a request payload', () => { |
| 362 | + const described = describeDapEventBodyForLog('process', { |
| 363 | + name: 'app', |
| 364 | + env: { SECRET: 'x' }, |
| 365 | + note: `bearer ${token}` |
| 366 | + }) as Record<string, unknown>; |
| 367 | + expect(described.env).toBe('<1 env vars redacted>'); |
| 368 | + expect(String(described.note)).not.toContain(token); |
| 369 | + expect(described.name).toBe('app'); |
| 370 | + }); |
| 371 | + |
| 372 | + it('passes a stopped body through unchanged in shape', () => { |
| 373 | + expect(describeDapEventBodyForLog('stopped', { reason: 'breakpoint', threadId: 1 })) |
| 374 | + .toEqual({ reason: 'breakpoint', threadId: 1 }); |
| 375 | + }); |
| 376 | +}); |
0 commit comments