|
6 | 6 | isResolvedSecretModelContentUnchanged, |
7 | 7 | projectResolvedSecretDiagnosticError, |
8 | 8 | projectResolvedSecretModelContent, |
| 9 | + projectResolvedSecretModelJsonContent, |
9 | 10 | projectResolvedSecretModelJsonStrings, |
10 | 11 | } from '@/executor/utils/resolved-secret-content-projection' |
11 | 12 | import { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry' |
@@ -288,6 +289,88 @@ describe('projectResolvedSecretModelContent', () => { |
288 | 289 | }) |
289 | 290 | }) |
290 | 291 |
|
| 292 | +describe('projectResolvedSecretModelJsonContent', () => { |
| 293 | + it('normalizes dates using their JSON wire representation', () => { |
| 294 | + const registry = new ResolvedSecretTraceRegistry() |
| 295 | + const createdAt = new Date('2026-08-05T12:34:56.789Z') |
| 296 | + |
| 297 | + expect(projectResolvedSecretModelJsonContent({ createdAt }, registry)).toEqual({ |
| 298 | + safe: true, |
| 299 | + value: { createdAt: '2026-08-05T12:34:56.789Z' }, |
| 300 | + }) |
| 301 | + expect(createdAt).toBeInstanceOf(Date) |
| 302 | + }) |
| 303 | + |
| 304 | + it('projects active secrets emitted by toJSON after materialization', () => { |
| 305 | + const registry = new ResolvedSecretTraceRegistry([ |
| 306 | + { name: 'TOKEN', plaintext: 'secret-value', encryptedValue: 'ciphertext' }, |
| 307 | + ]) |
| 308 | + registry.recordResolved('TOKEN', 'secret-value') |
| 309 | + |
| 310 | + expect( |
| 311 | + projectResolvedSecretModelJsonContent( |
| 312 | + { |
| 313 | + toJSON: () => ({ authorization: 'Bearer secret-value' }), |
| 314 | + }, |
| 315 | + registry |
| 316 | + ) |
| 317 | + ).toEqual({ |
| 318 | + safe: true, |
| 319 | + value: { authorization: 'Bearer {{TOKEN}}' }, |
| 320 | + }) |
| 321 | + }) |
| 322 | + |
| 323 | + it('does not invoke JSON serialization when provenance is incomplete', () => { |
| 324 | + const registry = new ResolvedSecretTraceRegistry() |
| 325 | + registry.markIncomplete() |
| 326 | + const toJSON = vi.fn(() => ({ value: 'untrusted' })) |
| 327 | + |
| 328 | + expect(projectResolvedSecretModelJsonContent({ toJSON }, registry)).toEqual({ safe: false }) |
| 329 | + expect(toJSON).not.toHaveBeenCalled() |
| 330 | + }) |
| 331 | + |
| 332 | + it('uses native JSON semantics for undefined and non-finite numbers', () => { |
| 333 | + const registry = new ResolvedSecretTraceRegistry() |
| 334 | + |
| 335 | + expect( |
| 336 | + projectResolvedSecretModelJsonContent( |
| 337 | + { |
| 338 | + omitted: undefined, |
| 339 | + undefinedInArray: [undefined], |
| 340 | + nan: Number.NaN, |
| 341 | + infinities: [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY], |
| 342 | + }, |
| 343 | + registry |
| 344 | + ) |
| 345 | + ).toEqual({ |
| 346 | + safe: true, |
| 347 | + value: { |
| 348 | + undefinedInArray: [null], |
| 349 | + nan: null, |
| 350 | + infinities: [null, null], |
| 351 | + }, |
| 352 | + }) |
| 353 | + }) |
| 354 | + |
| 355 | + it('returns a controlled unsafe result for values JSON cannot serialize', () => { |
| 356 | + const registry = new ResolvedSecretTraceRegistry() |
| 357 | + const cyclic: Record<string, unknown> = {} |
| 358 | + cyclic.self = cyclic |
| 359 | + |
| 360 | + expect(projectResolvedSecretModelJsonContent(cyclic, registry)).toEqual({ safe: false }) |
| 361 | + expect(projectResolvedSecretModelJsonContent({ value: 1n }, registry)).toEqual({ safe: false }) |
| 362 | + }) |
| 363 | + |
| 364 | + it('enforces the byte limit after secret aliases are projected', () => { |
| 365 | + const registry = new ResolvedSecretTraceRegistry([ |
| 366 | + { name: 'X', plaintext: 'x', encryptedValue: 'ciphertext' }, |
| 367 | + ]) |
| 368 | + registry.recordResolved('X', 'x') |
| 369 | + |
| 370 | + expect(projectResolvedSecretModelJsonContent({ a: 'x' }, registry, 9)).toEqual({ safe: false }) |
| 371 | + }) |
| 372 | +}) |
| 373 | + |
291 | 374 | describe('projectResolvedSecretDiagnosticError', () => { |
292 | 375 | it('projects plaintext and internal aliases without mutating the runtime error', () => { |
293 | 376 | const secret = 'diagnostic-secret-value' |
|
0 commit comments