Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(ok): prove Windows shell readiness by evaluation, not by proxy (#4104)

Nick Gomezae417659edd3
diff --git a/packages/desktop/tests/smoke/_helpers/terminal-ready.test.ts b/packages/desktop/tests/smoke/_helpers/terminal-ready.test.ts
index 2e80c9403..420e37e82 100644
--- a/packages/desktop/tests/smoke/_helpers/terminal-ready.test.ts
+++ b/packages/desktop/tests/smoke/_helpers/terminal-ready.test.ts
@@ -1,6 +1,12 @@
import { describe, expect, test } from 'vitest';
import { waitForShellReady } from './terminal-ready';
+function evaluateArithmeticProbe(command: string): string {
+ return command.replace(/\$\(\((\d+)\*(\d+)\)\)/u, (_match, left, right) =>
+ String(Number(left) * Number(right)),
+ );
+}
+
describe('terminal smoke shell readiness', () => {
test('requires evaluated Windows output instead of accepting the echoed probe', async () => {
let text = '\u001b]0;C:\\Program Files\\PowerShell\\7\\pwsh.exe\u0007';
@@ -19,9 +25,7 @@ describe('terminal smoke shell readiness', () => {
continuationPrompt = true;
} else {
text += `\r\n${command}`;
- text += `\r\n${command.replace(/\$\(\((\d+)\*(\d+)\)\)/u, (_match, left, right) =>
- String(Number(left) * Number(right)),
- )}`;
+ text += `\r\n${evaluateArithmeticProbe(command)}`;
}
return Promise.resolve();
},
@@ -53,11 +57,7 @@ describe('terminal smoke shell readiness', () => {
if (command === '') return Promise.resolve('PowerShell startup');
readsAfterSend += 1;
if (readsAfterSend === 1) return Promise.resolve(command);
- return Promise.resolve(
- command.replace(/\$\(\((\d+)\*(\d+)\)\)/u, (_match, left, right) =>
- String(Number(left) * Number(right)),
- ),
- );
+ return Promise.resolve(evaluateArithmeticProbe(command));
},
(nextCommand) => {
commandsSent += 1;
@@ -92,9 +92,7 @@ describe('terminal smoke shell readiness', () => {
},
(command) => {
commandSentAtRead = reads;
- text += `\r\n${command.replace(/\$\(\((\d+)\*(\d+)\)\)/u, (_match, left, right) =>
- String(Number(left) * Number(right)),
- )}`;
+ text += `\r\n${evaluateArithmeticProbe(command)}`;
return Promise.resolve();
},
{
@@ -109,6 +107,35 @@ describe('terminal smoke shell readiness', () => {
expect(commandSentAtRead).toBe(5);
});
+ test('probes anyway when rendered Windows output never settles', async () => {
+ let text = 'PowerShell starting';
+ let reads = 0;
+ const commands: string[] = [];
+
+ await waitForShellReady(
+ () => {
+ reads += 1;
+ text += ` tick${reads}`;
+ return Promise.resolve(text);
+ },
+ (command) => {
+ commands.push(command);
+ if (commands.length > 1) {
+ text += `\r\n${evaluateArithmeticProbe(command)}`;
+ }
+ return Promise.resolve();
+ },
+ {
+ platform: 'win32',
+ interval: 5,
+ timeout: 1_000,
+ resetTerminalInput: () => Promise.resolve(),
+ },
+ );
+
+ expect(commands).toHaveLength(2);
+ });
+
test('fails loud when a Windows caller omits the line reset', async () => {
await expect(
waitForShellReady(
@@ -121,6 +148,43 @@ describe('terminal smoke shell readiness', () => {
).rejects.toThrow(/requires resetTerminalInput/u);
});
+ test('still fails loud when the Windows probe is never evaluated', async () => {
+ let text = 'PowerShell starting';
+ const commands: string[] = [];
+ await expect(
+ waitForShellReady(
+ () => Promise.resolve(text),
+ (command) => {
+ commands.push(command);
+ text += `\r\n${command}`;
+ return Promise.resolve();
+ },
+ {
+ platform: 'win32',
+ interval: 5,
+ timeout: 200,
+ resetTerminalInput: () => Promise.resolve(),
+ },
+ ),
+ ).rejects.toThrow();
+ expect(commands).not.toHaveLength(0);
+ });
+
+ test('still fails loud on POSIX when the buffer never settles', async () => {
+ let reads = 0;
+ await expect(
+ waitForShellReady(
+ () => {
+ reads += 1;
+ return Promise.resolve(`zsh tick${reads}`);
+ },
+ () => Promise.resolve(),
+ { platform: 'darwin', interval: 5, timeout: 200 },
+ ),
+ ).rejects.toThrow();
+ expect(reads).toBeGreaterThan(1);
+ });
+
test('retains the quiet-buffer readiness contract on POSIX', async () => {
let text = 'shell startup';
let commandsSent = 0;
diff --git a/packages/desktop/tests/smoke/_helpers/terminal-ready.ts b/packages/desktop/tests/smoke/_helpers/terminal-ready.ts
index 96ab7345d..ab3109726 100644
--- a/packages/desktop/tests/smoke/_helpers/terminal-ready.ts
+++ b/packages/desktop/tests/smoke/_helpers/terminal-ready.ts
@@ -1,8 +1,7 @@
-import { randomUUID } from 'node:crypto';
import { expect } from '@playwright/test';
-import { terminalSmokeShellCommands } from './terminal-smoke-shell';
+import { buildInputReadyProbe } from './terminal-smoke-shell';
-const WINDOWS_SETTLE_TIMEOUT_MS = 10_000;
+const WINDOWS_SETTLE_BUDGET_DIVISOR = 3;
export async function waitForShellReady(
readTerminalText: () => Promise<string>,
@@ -20,16 +19,14 @@ export async function waitForShellReady(
throw new Error('Windows shell readiness requires resetTerminalInput');
}
const startedAt = Date.now();
- await waitForQuietTerminalText(
+ await settleTerminalTextBestEffort(
readTerminalText,
- Math.min(timeout, WINDOWS_SETTLE_TIMEOUT_MS),
+ Math.floor(timeout / WINDOWS_SETTLE_BUDGET_DIVISOR),
quietPolls,
interval,
);
- const token = `OK_INPUT_READY_${randomUUID().replaceAll('-', '')}`;
- const marker = `${token}_42_READY`;
- const probe = terminalSmokeShellCommands('win32').arithmetic(token, 6, 7, 'READY');
+ const { marker, command: probe } = buildInputReadyProbe('win32');
let attempted = false;
const remainingTimeout = Math.max(interval, timeout - (Date.now() - startedAt));
await expect(async () => {
@@ -48,6 +45,19 @@ export async function waitForShellReady(
await waitForQuietTerminalText(readTerminalText, timeout, quietPolls, interval);
}
+async function settleTerminalTextBestEffort(
+ readTerminalText: () => Promise<string>,
+ timeout: number,
+ quietPolls: number,
+ interval: number,
+): Promise<void> {
+ try {
+ await waitForQuietTerminalText(readTerminalText, timeout, quietPolls, interval);
+ } catch {
+ return;
+ }
+}
+
async function waitForQuietTerminalText(
readTerminalText: () => Promise<string>,
timeout: number,
diff --git a/packages/desktop/tests/smoke/_helpers/terminal-smoke-shell.ts b/packages/desktop/tests/smoke/_helpers/terminal-smoke-shell.ts
index b47cc4794..7893f96f0 100644
--- a/packages/desktop/tests/smoke/_helpers/terminal-smoke-shell.ts
+++ b/packages/desktop/tests/smoke/_helpers/terminal-smoke-shell.ts
@@ -1,3 +1,4 @@
+import { randomUUID } from 'node:crypto';
import { mkdirSync, writeFileSync } from 'node:fs';
import { join, win32 } from 'node:path';
import { psQuoteArg } from '@inkeep/open-knowledge-core';
@@ -74,6 +75,21 @@ export function terminalSmokeShellCommands(
};
}
+export interface InputReadyProbe {
+ marker: string;
+ command: string;
+}
+
+export function buildInputReadyProbe(
+ platform: NodeJS.Platform = process.platform,
+): InputReadyProbe {
+ const token = `OK_INPUT_READY_${randomUUID().replaceAll('-', '')}`;
+ return {
+ marker: `${token}_42_READY`,
+ command: terminalSmokeShellCommands(platform).arithmetic(token, 6, 7, 'READY'),
+ };
+}
+
interface TerminalSmokeEnvironmentOptions {
env?: Record<string, string | undefined>;
pathPrefix?: string;
diff --git a/packages/desktop/tests/support/pty-readiness.test-helper.ts b/packages/desktop/tests/support/pty-readiness.test-helper.ts
index 804abf11c..1972ac8c4 100644
--- a/packages/desktop/tests/support/pty-readiness.test-helper.ts
+++ b/packages/desktop/tests/support/pty-readiness.test-helper.ts
@@ -86,6 +86,9 @@ const DEFAULT_READY_INTERVAL_MS = 50;
const DEFAULT_QUIET_SAMPLES = 20;
const DEFAULT_READY_TIMEOUT_MS = 12_000;
const RECEIVED_TAIL_CHARS = 400;
+const DEFAULT_INPUT_READY_ATTEMPTS = 4;
+const DEFAULT_INPUT_READY_TIMEOUT_MS = 4_000;
+const INPUT_READY_RESET_FROM_ATTEMPT = 2;
const sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
@@ -142,6 +145,54 @@ export async function waitForShellReady(
);
}
+export const INPUT_READY_RESET = '\u0003';
+
+export interface EvaluatedInputProbe {
+ input: string;
+ marker: string;
+ reset: string;
+}
+
+export interface EvaluatedInputOptions extends WaitOptions {
+ attempts?: number;
+}
+
+export async function waitForEvaluatedInput(
+ stream: PtyStream,
+ send: (data: string) => void,
+ probe: EvaluatedInputProbe,
+ label: string,
+ options: EvaluatedInputOptions = {},
+): Promise<number> {
+ if (probe.input.includes(probe.marker)) {
+ throw new Error(`readiness probe input must not contain its marker: ${probe.marker}`);
+ }
+ const attempts = options.attempts ?? DEFAULT_INPUT_READY_ATTEMPTS;
+ const waitOptions: WaitOptions = {
+ timeoutMs: options.timeoutMs ?? DEFAULT_INPUT_READY_TIMEOUT_MS,
+ ...(options.intervalMs === undefined ? {} : { intervalMs: options.intervalMs }),
+ };
+ let lastError: Error | null = null;
+ for (let attempt = 0; attempt < attempts; attempt += 1) {
+ if (attempt >= INPUT_READY_RESET_FROM_ATTEMPT) send(probe.reset);
+ send(probe.input);
+ try {
+ await waitForCondition(
+ stream,
+ () => stream.read().includes(probe.marker),
+ label,
+ waitOptions,
+ );
+ return attempt + 1;
+ } catch (error) {
+ lastError = error as Error;
+ if (stream.failure() !== null) throw lastError;
+ }
+ }
+ const detail = lastError?.message ?? `timeout waiting for: ${label}`;
+ throw new Error(`${detail} (gave up after ${attempts} attempts)`, { cause: lastError });
+}
+
export function buildCwdFileProofCommand(platform: NodeJS.Platform, fileName: string): string {
if (!/^[A-Za-z0-9._-]+$/u.test(fileName) || fileName === '.' || fileName === '..') {
throw new Error(`invalid cwd proof file name: ${fileName}`);
diff --git a/packages/desktop/tests/utility/pty-host-real-io.test.ts b/packages/desktop/tests/utility/pty-host-real-io.test.ts
index 50cf9bf5b..944b45f68 100644
--- a/packages/desktop/tests/utility/pty-host-real-io.test.ts
+++ b/packages/desktop/tests/utility/pty-host-real-io.test.ts
@@ -101,6 +101,9 @@ describe('PTY host — real shell I/O (Node runtime)', () => {
const outputDir = mkdtempSync(join(tmpdir(), 'ok-real-pty-wrapper-'));
try {
const output = await runHarness(outputDir);
+ for (const line of output.split(/\r?\n/u).filter((l) => l.startsWith('INPUT_READY '))) {
+ console.log(line);
+ }
expect(output).toContain(SUCCESS_RESULT);
} finally {
removeTempDirBestEffort(outputDir);
diff --git a/packages/desktop/tests/utility/pty-host.real-io-harness.ts b/packages/desktop/tests/utility/pty-host.real-io-harness.ts
index 2e4ca91db..d56c64638 100644
--- a/packages/desktop/tests/utility/pty-host.real-io-harness.ts
+++ b/packages/desktop/tests/utility/pty-host.real-io-harness.ts
@@ -4,11 +4,16 @@ import { createRequire } from 'node:module';
import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
import type { SpawnPty } from '../../src/utility/pty-host.ts';
-import { terminalSmokeShellCommands } from '../smoke/_helpers/terminal-smoke-shell.ts';
+import {
+ buildInputReadyProbe,
+ terminalSmokeShellCommands,
+} from '../smoke/_helpers/terminal-smoke-shell.ts';
import {
buildCwdFileProofCommand,
createPtyHostProbe,
+ INPUT_READY_RESET,
waitForCondition,
+ waitForEvaluatedInput,
waitForShellReady,
} from '../support/pty-readiness.test-helper.ts';
@@ -48,38 +53,31 @@ const shellCommands = terminalSmokeShellCommands();
const CWD_PROOF_FILE = '.ok-pty-cwd-proof';
const WINDOWS_LAUNCH_WAIT = { timeoutMs: 20_000 } as const;
-function createWindowsReadinessLaunch(): {
- marker: string;
- launchCommand: { executable: string; args: string[] };
-} | null {
- if (process.platform !== 'win32') return null;
- const marker = `OK_SHELL_READY_${randomUUID().replaceAll('-', '')}`;
- return {
- marker,
- launchCommand: { executable: 'cmd.exe', args: ['/d', '/c', 'echo', marker] },
- };
+async function waitForWindowsInputReady(
+ host: ReturnType<typeof createHost>,
+ ptyId: string,
+ label: string,
+): Promise<void> {
+ const probe = buildInputReadyProbe();
+ const attempts = await waitForEvaluatedInput(
+ host.streamOf(ptyId),
+ (data) => host.send({ type: 'input', ptyId, data }),
+ { input: `${probe.command}\r`, marker: probe.marker, reset: INPUT_READY_RESET },
+ label,
+ );
+ console.log(`INPUT_READY ${label} attempts=${attempts}`);
}
async function waitForInteractiveShellReady(
host: ReturnType<typeof createHost>,
ptyId: string,
label: string,
- windowsLaunchMarker: string | null,
): Promise<void> {
- const stream = host.streamOf(ptyId);
if (process.platform === 'win32') {
- if (windowsLaunchMarker === null) {
- throw new Error('Windows input-driven scenarios require a startup launch marker');
- }
- await waitForCondition(
- stream,
- () => stream.read().includes(windowsLaunchMarker),
- label,
- WINDOWS_LAUNCH_WAIT,
- );
+ await waitForWindowsInputReady(host, ptyId, label);
return;
}
- await waitForShellReady(stream, label);
+ await waitForShellReady(host.streamOf(ptyId), label);
}
async function main(): Promise<void> {
@@ -92,22 +90,9 @@ async function main(): Promise<void> {
writeFileSync(join(tmp, CWD_PROOF_FILE), cwdToken, 'utf8');
const host = createHost(BASE_ENV);
const io = host.streamOf('io');
- const readiness = createWindowsReadinessLaunch();
try {
- host.send({
- type: 'create',
- ptyId: 'io',
- cwd: tmp,
- cols: 80,
- rows: 24,
- ...(readiness === null ? {} : { launchCommand: readiness.launchCommand }),
- });
- await waitForInteractiveShellReady(
- host,
- 'io',
- 'interactive shell ready at project root',
- readiness?.marker ?? null,
- );
+ host.send({ type: 'create', ptyId: 'io', cwd: tmp, cols: 80, rows: 24 });
+ await waitForInteractiveShellReady(host, 'io', 'interactive shell ready at project root');
host.send({
type: 'input',
ptyId: 'io',
@@ -140,21 +125,12 @@ async function main(): Promise<void> {
OK_LOCK_KIND: 'interactive',
});
const env = host.streamOf('env');
- const readiness = createWindowsReadinessLaunch();
try {
- host.send({
- type: 'create',
- ptyId: 'env',
- cwd: tmp,
- cols: 80,
- rows: 24,
- ...(readiness === null ? {} : { launchCommand: readiness.launchCommand }),
- });
+ host.send({ type: 'create', ptyId: 'env', cwd: tmp, cols: 80, rows: 24 });
await waitForInteractiveShellReady(
host,
'env',
'interactive shell ready with desktop markers stripped',
- readiness?.marker ?? null,
);
host.send({
type: 'input',
@@ -215,17 +191,10 @@ async function main(): Promise<void> {
'PowerShell EncodedCommand output',
WINDOWS_LAUNCH_WAIT,
);
- const interactiveToken = `OK_INTERACTIVE_${randomUUID().replaceAll('-', '')}`;
- host.send({
- type: 'input',
- ptyId: 'launch',
- data: `${shellCommands.arithmetic(interactiveToken, 6, 7, 'READY')}\r`,
- });
- await waitForCondition(
- launch,
- () => launch.read().includes(`${interactiveToken}_42_READY`),
+ await waitForWindowsInputReady(
+ host,
+ 'launch',
'PowerShell remains interactive after EncodedCommand',
- WINDOWS_LAUNCH_WAIT,
);
if (host.errorOf('launch') !== null) {
throw new Error(`PowerShell launch failed: ${host.errorOf('launch')}`);
diff --git a/packages/desktop/tests/utility/pty-readiness.test.ts b/packages/desktop/tests/utility/pty-readiness.test.ts
index a1980792e..45ab933c3 100644
--- a/packages/desktop/tests/utility/pty-readiness.test.ts
+++ b/packages/desktop/tests/utility/pty-readiness.test.ts
@@ -3,8 +3,10 @@ import type { PtyProcessLike, PtySpawnOptions, SpawnPty } from '../../src/utilit
import {
buildCwdFileProofCommand,
createPtyHostProbe,
+ INPUT_READY_RESET,
type PtyStream,
waitForCondition,
+ waitForEvaluatedInput,
waitForShellReady,
} from '../support/pty-readiness.test-helper.ts';
@@ -268,3 +270,196 @@ describe('driving a real host through a shell that starts slowly', () => {
}
});
});
+
+const INPUT_READY_MARKER = 'OK_INPUT_READY_deadbeef_42_READY';
+const INPUT_READY_PROBE = {
+ input: 'Write-Output "OK_INPUT_READY_deadbeef_$((6*7))_READY"\r',
+ marker: INPUT_READY_MARKER,
+ reset: INPUT_READY_RESET,
+} as const;
+const INPUT_READY_FAST = { timeoutMs: 60, intervalMs: 5, attempts: 5 } as const;
+const INPUT_READY_EXHAUSTED = new RegExp(
+ `timeout waiting for: input ready[\\s\\S]*gave up after ${INPUT_READY_FAST.attempts} attempts`,
+ 'u',
+);
+
+function driveEvaluatingShell(
+ stream: FakeStream,
+ options: { swallowFirst: number; evaluates?: boolean; corruptsLine?: boolean },
+): { sent: string[]; send: (data: string) => void } {
+ const sent: string[] = [];
+ let swallowed = 0;
+ let partialLine = false;
+ return {
+ sent,
+ send: (data) => {
+ sent.push(data);
+ if (data === INPUT_READY_RESET) {
+ partialLine = false;
+ return;
+ }
+ const typed = data.replace(/\r$/u, '');
+ const output = evaluateFakePowerShellCommand(typed);
+ if (output === null) return;
+ if (swallowed < options.swallowFirst) {
+ swallowed += 1;
+ if (options.corruptsLine === true) partialLine = true;
+ return;
+ }
+ if (options.evaluates === false) return;
+ if (partialLine) return;
+ stream.emit(`${typed}\r\n${output}\r\n`);
+ },
+ };
+}
+
+describe('evaluated-input readiness', () => {
+ test('pins the line reset as a real ETX rather than an empty string', () => {
+ expect(INPUT_READY_PROBE.reset).toBe('\u0003');
+ });
+
+ test('sends once when the shell evaluates the first probe', async () => {
+ const stream = createFakeStream();
+ const shell = driveEvaluatingShell(stream, { swallowFirst: 0 });
+ const attempts = await waitForEvaluatedInput(
+ stream,
+ shell.send,
+ INPUT_READY_PROBE,
+ 'input ready',
+ INPUT_READY_FAST,
+ );
+ expect(attempts).toBe(1);
+ expect(shell.sent).toEqual([INPUT_READY_PROBE.input]);
+ });
+
+ test('recovers when a console still initializing swallows the first keystrokes', async () => {
+ const stream = createFakeStream();
+ const shell = driveEvaluatingShell(stream, { swallowFirst: 2 });
+ const attempts = await waitForEvaluatedInput(
+ stream,
+ shell.send,
+ INPUT_READY_PROBE,
+ 'input ready',
+ INPUT_READY_FAST,
+ );
+ expect(attempts).toBe(3);
+ expect(stream.read()).toContain(INPUT_READY_MARKER);
+ expect(shell.sent).toEqual([
+ INPUT_READY_PROBE.input,
+ INPUT_READY_PROBE.input,
+ INPUT_READY_PROBE.reset,
+ INPUT_READY_PROBE.input,
+ ]);
+ });
+
+ test('recovers a wholly dropped probe by re-sending, without a reset', async () => {
+ const stream = createFakeStream();
+ const shell = driveEvaluatingShell(stream, { swallowFirst: 1 });
+ const attempts = await waitForEvaluatedInput(
+ stream,
+ shell.send,
+ INPUT_READY_PROBE,
+ 'input ready',
+ INPUT_READY_FAST,
+ );
+ expect(attempts).toBe(2);
+ expect(shell.sent).toEqual([INPUT_READY_PROBE.input, INPUT_READY_PROBE.input]);
+ });
+
+ test('needs the reset when a dropped probe left a partial line', async () => {
+ const stream = createFakeStream();
+ const shell = driveEvaluatingShell(stream, { swallowFirst: 1, corruptsLine: true });
+ const attempts = await waitForEvaluatedInput(
+ stream,
+ shell.send,
+ INPUT_READY_PROBE,
+ 'input ready',
+ INPUT_READY_FAST,
+ );
+ expect(attempts).toBe(3);
+ expect(shell.sent).toEqual([
+ INPUT_READY_PROBE.input,
+ INPUT_READY_PROBE.input,
+ INPUT_READY_PROBE.reset,
+ INPUT_READY_PROBE.input,
+ ]);
+ });
+
+ test('a shell that only echoes the probe never reports ready', async () => {
+ const stream = createFakeStream();
+ await expect(
+ waitForEvaluatedInput(
+ stream,
+ (data) => stream.emit(data),
+ INPUT_READY_PROBE,
+ 'input ready',
+ INPUT_READY_FAST,
+ ),
+ ).rejects.toThrow(INPUT_READY_EXHAUSTED);
+ expect(stream.read()).toContain('Write-Output');
+ expect(stream.read()).not.toContain(INPUT_READY_MARKER);
+ });
+
+ test('a shell that never evaluates fails once the attempt budget is spent', async () => {
+ const stream = createFakeStream();
+ const shell = driveEvaluatingShell(stream, { swallowFirst: 0, evaluates: false });
+ await expect(
+ waitForEvaluatedInput(stream, shell.send, INPUT_READY_PROBE, 'input ready', INPUT_READY_FAST),
+ ).rejects.toThrow(INPUT_READY_EXHAUSTED);
+ expect(shell.sent.filter((data) => data === INPUT_READY_PROBE.input)).toHaveLength(
+ INPUT_READY_FAST.attempts,
+ );
+ });
+
+ test('falls back to the module attempt budget when the caller omits one', async () => {
+ const stream = createFakeStream();
+ const shell = driveEvaluatingShell(stream, { swallowFirst: 0, evaluates: false });
+ await expect(
+ waitForEvaluatedInput(stream, shell.send, INPUT_READY_PROBE, 'input ready', {
+ timeoutMs: INPUT_READY_FAST.timeoutMs,
+ intervalMs: INPUT_READY_FAST.intervalMs,
+ }),
+ ).rejects.toThrow(/gave up after 4 attempts/u);
+ expect(shell.sent.filter((data) => data === INPUT_READY_PROBE.input)).toHaveLength(4);
+ });
+
+ test('rejects a probe whose own echo would satisfy it', async () => {
+ const stream = createFakeStream();
+ const shell = driveEvaluatingShell(stream, { swallowFirst: 0 });
+ await expect(
+ waitForEvaluatedInput(
+ stream,
+ shell.send,
+ { ...INPUT_READY_PROBE, input: `echo ${INPUT_READY_MARKER}` },
+ 'input ready',
+ INPUT_READY_FAST,
+ ),
+ ).rejects.toThrow(/must not contain its marker/u);
+ expect(shell.sent).toEqual([]);
+ });
+
+ test('chains the underlying wait failure as the cause', async () => {
+ const stream = createFakeStream();
+ const shell = driveEvaluatingShell(stream, { swallowFirst: 0, evaluates: false });
+ const error = await waitForEvaluatedInput(
+ stream,
+ shell.send,
+ INPUT_READY_PROBE,
+ 'input ready',
+ INPUT_READY_FAST,
+ ).catch((thrown: unknown) => thrown as Error);
+ expect(error).toBeInstanceOf(Error);
+ expect(error.cause).toBeInstanceOf(Error);
+ expect((error.cause as Error).message).toMatch(/timeout waiting for: input ready/u);
+ });
+
+ test('a dead shell short-circuits instead of burning the attempt budget', async () => {
+ const stream = createFakeStream();
+ const shell = driveEvaluatingShell(stream, { swallowFirst: 99 });
+ stream.fail('exited (code 1, signal none)');
+ await expect(
+ waitForEvaluatedInput(stream, shell.send, INPUT_READY_PROBE, 'input ready', INPUT_READY_FAST),
+ ).rejects.toThrow(/shell failed before input ready/u);
+ expect(shell.sent).toEqual([INPUT_READY_PROBE.input]);
+ });
+});