|
1 | 1 | import fs from 'node:fs'; |
2 | 2 |
|
3 | 3 | import path from 'node:path'; |
| 4 | +import { withCommandHost } from '@agent-device/host-kit/command'; |
4 | 5 | import { afterEach, expect, test } from 'vitest'; |
5 | 6 | import { openAppLogOutput, readAppLogOutputTail } from './platform-runtime-app-log-output.ts'; |
6 | 7 | import { bindTestCommandHost, mkdtempForTestSync } from '@agent-device/test-kit'; |
@@ -94,3 +95,25 @@ function finalSymlinkFixture(label: string) { |
94 | 95 | fs.symlinkSync(outsidePath, outputPath); |
95 | 96 | return { sessionsDir, outputPath, outsidePath }; |
96 | 97 | } |
| 98 | + |
| 99 | +test('redacts with the patterns of the command host, not the process', async () => { |
| 100 | + const root = mkdtempForTestSync('agent-device-app-log-redact-'); |
| 101 | + roots.push(root); |
| 102 | + const sessionsDir = path.join(root, 'sessions'); |
| 103 | + const outputPath = path.join(sessionsDir, 'one', 'app.log'); |
| 104 | + fs.mkdirSync(path.dirname(outputPath), { recursive: true }); |
| 105 | + |
| 106 | + await withCommandHost( |
| 107 | + { |
| 108 | + host: { env: { AGENT_DEVICE_APP_LOG_REDACT_PATTERNS: 'secret-\\d+' }, cwd: root }, |
| 109 | + requestEnv: undefined, |
| 110 | + }, |
| 111 | + async () => { |
| 112 | + const sink = await openAppLogOutput(sessionsDir, outputPath); |
| 113 | + await sink.write('token secret-42 leaked\n'); |
| 114 | + await sink[Symbol.asyncDispose](); |
| 115 | + }, |
| 116 | + ); |
| 117 | + |
| 118 | + expect(fs.readFileSync(outputPath, 'utf8')).toBe('token [REDACTED] leaked\n'); |
| 119 | +}); |
0 commit comments