| 103 | // The history path is redirected to a tmp file so we can assert a piped |
| 104 | // session leaves ZERO history behind. |
| 105 | function runShellScript( |
| 106 | lines: string[], |
| 107 | args: string[], |
| 108 | historyPath: string, |
| 109 | ): Promise<{ stdout: string; stderr: string; exitCode: number }> { |
| 110 | return new Promise((resolve, reject) => { |
| 111 | const child = spawn('node', [BIN_PATH, 'shell', ...args], { |
| 112 | env: { |
| 113 | ...process.env, |
| 114 | LOG_LEVEL: 'error', |
| 115 | WIGOLO_DATA_DIR: join(import.meta.dirname, '..', 'fixtures', 'repl-test-data'), |
| 116 | WIGOLO_SHELL_HISTORY_PATH: historyPath, |
| 117 | }, |
| 118 | stdio: ['pipe', 'pipe', 'pipe'], |
| 119 | }); |
| 120 | let stdout = ''; |
| 121 | let stderr = ''; |
| 122 | child.stdout.on('data', (d: Buffer) => { stdout += d.toString(); }); |
| 123 | child.stderr.on('data', (d: Buffer) => { stderr += d.toString(); }); |
| 124 | child.on('error', reject); |
| 125 | child.on('close', (code) => resolve({ stdout, stderr, exitCode: code ?? 1 })); |
| 126 | child.stdin.write(lines.join('\n') + '\n'); |
| 127 | child.stdin.end(); |
| 128 | }); |
| 129 | } |
| 130 | |
| 131 | describe('REPL NDJSON scripting', () => { |
| 132 | // CONTRACT (as implemented): |