mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-18 05:19:29 +08:00
87 lines
3.0 KiB
TypeScript
87 lines
3.0 KiB
TypeScript
/* The piped-stdin differential case table — event-loop.test.ts's cases,
|
|
* extracted so the Linux lane runs the IDENTICAL fixtures with the
|
|
* IDENTICAL stdin scripts through its container (docker exec -i carries
|
|
* the pipe; EOF propagates when the harness closes its end). Fixture
|
|
* programs live in tests/fixtures/event-loop. */
|
|
|
|
export interface StdinScript {
|
|
/** Writes performed in order; `delayMs` waits BEFORE the write. */
|
|
writes: { delayMs: number; data: string }[];
|
|
/** Close the write end after the writes (false = hold the pipe open
|
|
* until the child exits on its own — the timeout paths). */
|
|
end: boolean;
|
|
}
|
|
|
|
export interface EventLoopCase {
|
|
title: string;
|
|
fixture: string;
|
|
script: StdinScript;
|
|
}
|
|
|
|
export const eventLoopCases: EventLoopCase[] = [
|
|
{
|
|
title: "read-all: one instant write, then EOF",
|
|
fixture: "stdin-read-all.ts",
|
|
script: { writes: [{ delayMs: 0, data: "hello stdin\nsecond line\n" }], end: true },
|
|
},
|
|
{
|
|
title: "read-all: chunked writes with delays, then EOF",
|
|
fixture: "stdin-read-all.ts",
|
|
script: {
|
|
writes: [
|
|
{ delayMs: 0, data: "alpha " },
|
|
{ delayMs: 60, data: "beta " },
|
|
{ delayMs: 60, data: "gamma\n" },
|
|
],
|
|
end: true,
|
|
},
|
|
},
|
|
{
|
|
title: "read-all: immediate EOF, no data",
|
|
fixture: "stdin-read-all.ts",
|
|
script: { writes: [], end: true },
|
|
},
|
|
{
|
|
title: "race-timeout: instant data wins the race",
|
|
fixture: "stdin-race-timeout.ts",
|
|
script: { writes: [{ delayMs: 0, data: "abc" }], end: true },
|
|
},
|
|
{
|
|
title: "race-timeout: silent open pipe — timeout wins, destroy releases the loop",
|
|
fixture: "stdin-race-timeout.ts",
|
|
script: { writes: [], end: false },
|
|
},
|
|
{
|
|
title: "race-timeout: immediate EOF — 'end' wins",
|
|
fixture: "stdin-race-timeout.ts",
|
|
script: { writes: [], end: true },
|
|
},
|
|
// node:readline — the question/close slice (SEMANTICS.md; the close
|
|
// emit is SYNCHRONOUS, so the prompt shape's close-listener resolve
|
|
// wins over the answer's, exactly Node).
|
|
// node:readline cases assert only chunking-INDEPENDENT outcomes (a
|
|
// burst consumed by a closing interface takes its surplus with it, so
|
|
// where chunk boundaries fall — a load-dependent race — must not decide
|
|
// the expected output; the stdin unit's own contract).
|
|
{
|
|
title: "readline: prompt answered, second prompt sees EOF",
|
|
fixture: "rl-question.ts",
|
|
script: { writes: [{ delayMs: 0, data: "yes\n" }], end: true },
|
|
},
|
|
{
|
|
title: "readline: EOF before any line — close wins, the partial discards",
|
|
fixture: "rl-question.ts",
|
|
script: { writes: [{ delayMs: 20, data: "partial" }], end: true },
|
|
},
|
|
{
|
|
title: "readline: sequential questions on one interface, CRLF terminators, surplus drops",
|
|
fixture: "rl-lines.ts",
|
|
script: { writes: [{ delayMs: 20, data: "one one\r\ntwo\nthree unheard\n" }], end: true },
|
|
},
|
|
{
|
|
title: "readline: immediate EOF closes the interface",
|
|
fixture: "rl-lines.ts",
|
|
script: { writes: [], end: true },
|
|
},
|
|
];
|