test(security-scanner): add TTY prompt tests using Bun.Terminal
Merged
RO
3mo ago+8137+8137+0123456789012345678901234567890123456789-2588-2588-0123456789012345678901234567890123456789
Summary
- Integrate TTY testing into the existing security scanner matrix tests
- Uses the new
Bun.TerminalAPI to create a pseudo-terminal environment for testing interactive prompts
Changes
test/cli/install/bun-security-scanner-matrix-runner.ts:
- Add
hasTTYandttyResponseoptions toSecurityScannerTestOptionsinterface - When
hasTTYis true, useBun.Terminalto spawn the process in a PTY environment - Add TTY-specific assertions to verify:
- The "Continue anyway? [y/N]" prompt appears
- "Continuing with installation..." message when user responds 'y'
- "Installation cancelled." message when user responds 'n'
- Non-TTY mode shows "Security warnings found. Cannot prompt for confirmation (no TTY)."
- Add new "TTY warning prompts" describe block with tests covering:
installandaddcommandslocalandnpmscanner typesyandnuser responses
- Update assertions to correctly handle the case where installation proceeds after user accepts warning
Example
// In TTY mode, use Bun.Terminal to handle interactive prompts
await using terminal = new Bun.Terminal({
cols: 80,
rows: 24,
data(_term, data) {
const text = new TextDecoder().decode(data);
errAndOut += text;
// When we see the prompt, send the configured response
if (!responseSent && errAndOut.includes("Continue anyway? [y/N]")) {
responseSent = true;
terminal.write(ttyResponse + "\n");
}
},
});
await using proc = Bun.spawn(cmd, {
cwd: dir,
env: bunEnv,
terminal,
});
Test plan
- All 8 new TTY tests pass with
bun bd test test/cli/install/bun-security-scanner-matrix-without-node-modules.test.ts -t "TTY" - Existing matrix tests still pass
- Tests are skipped on Windows (PTY not available)
š¤ Generated with Claude Code