fix(run): redact secrets from what the config, collected test files, and reporters print

Merged
OK
2mo ago
+558-57

User code runs in the e2e run process too, and what it printed reached the terminal with secrets in the clear. Worker output was redacted, except the config's top-level output, which each worker printed before it registered the config's secrets.

  • packages/e2e/src/run/process-output.ts: RunnerOutput redacts every write to process.stdout and process.stderr in the runner process with the process-wide secret ledger. While the config loads, output is held until the load registers the secrets. If the load fails, the output is dropped and a warning printed in its place. Each worker's bootstrap uses the same hold, ConfigLoadHold.
  • packages/e2e/src/cli/run-output.ts: e2e run claims both streams for the run. Only the list reporter writes to the terminal past the redactor.
  • While the list reporter is up, runner output goes through ListReporter.processOutput and prints under stdout | runner / stderr | runner, the way worker output does, on stdout, in a pipe too. On main, the live window painted over it in a TTY. This includes Node warnings raised in the runner, such as the TypeScript loader's unreadable-tsconfig warning, which used to go to stderr (typescript-loader.test.ts updated). Without the list reporter, output stays on its own stream.
  • The runner registers the static secrets once the config has loaded (runner.ts, loadConfig).
  • Not stacked on #826. Its McpOutput puts both streams on one stderr with one redactor and flushes per tool call. Here the streams stay apart and route around the live window. The two share StreamRedactor and the hold-while-loading rule. Once both land, McpOutput can adopt ConfigLoadHold.
flowchart LR
  U["user code in the runner<br/>config, collection, reporters"] --> H{config loading?}
  H -- yes --> Q[held]
  Q -- loaded --> R
  Q -- failed --> X[dropped, warning]
  H -- no --> R[StreamRedactor per stream]
  R --> L{list reporter up?}
  L -- yes --> LR[printed above the live window]
  L -- no --> T[terminal]

Still unredacted, as on main: the config's top-level output in e2e list, e2e cache, and e2e explore, and an uncaught error in the runner, which Node writes straight to fd 2.

Verified

Ran it locally: yes

  • testbed, scratch config with secrets: { apiToken }. The config logs the value at top level. A test file logs it at top level and in its body. A custom reporter logs it in onEvent and onRunFinished. Ran e2e run in a 120x40 tmux pane (TTY, live window) and captured the final screen.
  • tests/integration/run-user-output.test.ts runs the built CLI. It fails on main and passes here. Mutation check: dropping the worker hold, or the runner's registerStaticSecrets, fails it again.
  • The testbed suite passes, test:stress output matches main, and --reporter json still prints a parseable report.

main: the secret is printed in clear. The runner's test file top level and reporter onEvent lines are missing from the screen: they were written, unredacted, then painted over by the live window.

config top level: leak-token-1234567
config top level stderr: leak-token-1234567

 RUN  e2e v0.17.0 apps/testbed
      run … · targets: web


 ✓ target "web" command ready 88ms
stdout |  web
config top level: leak-token-1234567
stderr |  web
config top level stderr: leak-token-1234567
stdout |  web
test file top level: <secret:apiToken>

stdout |  web  tests-leak/leak.e2e.ts > prints
test body: <secret:apiToken>
 ✓  web  tests-leak/leak.e2e.ts (1 test) 1.64s
   ✓ prints 1.64s

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  10:10:12
   Duration  1.98s (startup 88ms)
     Report  .e2e/report.json

reporter onRunFinished: leak-token-1234567

this branch:

config top level: <secret:apiToken>
config top level stderr: <secret:apiToken>

 RUN  e2e v0.17.0 apps/testbed
      run … · targets: web

stdout | runner
test file top level: <secret:apiToken>
 ✓ target "web" command ready 89ms
stdout |  web
config top level: <secret:apiToken>
stderr |  web
config top level stderr: <secret:apiToken>
stdout |  web
test file top level: <secret:apiToken>
stdout | runner
reporter onEvent: <secret:apiToken>
stdout |  web  tests-leak/leak.e2e.ts > prints
test body: <secret:apiToken>
 ✓  web  tests-leak/leak.e2e.ts (1 test) 1.67s
   ✓ prints 1.67s

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  10:10:19
   Duration  2.02s (startup 89ms)
     Report  .e2e/report.json

reporter onRunFinished: <secret:apiToken>