Files
lobster/test/read_line.test.ts
xingzhouandPeter Steinberger c440ca57d1 fix(runtime): cancelled workflows no longer continue external commands (#119)
* fix(runtime): stop process-backed work on cancellation

* fix(runtime): invalidate cancelled resume state

* Revert "fix(runtime): invalidate cancelled resume state"

This reverts commit 0f7d291f98.

* fix(runtime): narrow cancellation to safe child processes

* fix(runtime): stop after completed search cancellation

* fix(runtime): halt direct pipelines after cancellation

Preserve completed in-flight stage results while preventing later direct pipeline stages from starting after parent cancellation.

* fix(runtime): consume aborted approval resumes

* fix(runtime): cancelled workflows no longer continue external commands

* fix(workflow): propagate custom parent cancellation

* fix(runtime): preserve pre-aborted resume state

* fix(runtime): stop lazy handoff after cancellation

* fix(workflow): close remaining cancellation boundaries

* fix(runtime): preserve workflow resumes during setup cancellation

* fix(runtime): close final cancellation persistence gaps

* fix(runtime): stop lazy handoff after cancellation

* fix(runtime): interrupt blocked lazy handoff reads

* fix(runtime): terminate cancellation process trees

* fix(runtime): await process tree termination

* fix(runtime): terminate workflow process trees

* fix(runtime): bridge CLI cancellation

* fix(cli): preserve cancellation lifecycle

* fix(cli): abort stalled signal-aware commands

* fix(cli): release aborted interactive prompts

* fix(cli): preserve sequential prompt input

* fix(cli): preserve buffered prompt input

* fix(cli): handle prompt EOF after buffered input

* fix(runtime): preserve UTF-8 subprocess output

* fix(workflow): preserve retryable resume before execution

* fix(workflow): roll back cancelled resume replacement

* fix(state): roll back cancelled monitor snapshot

* fix(resume): preserve cancelled gate capabilities

* fix(resume): close cancellation rollback windows

* fix(resume): harden cancellation state cleanup

* fix(runtime): close resumed cancellation gaps

* fix(runtime): preserve cancellation cleanup

* fix(runtime): close cancellation lifecycle gaps

* fix(runtime): harden resumed cancellation boundaries

* fix(workflow): consume timed-out resume capabilities

* fix(workflow): preserve resume policy boundaries

* fix(runtime): preserve cancellation cleanup liveness

* fix(runtime): harden cancellation cleanup

* fix(runtime): stop lazy output after cancellation

* fix(runtime): settle cancellation cleanup

* fix(runtime): preserve safe input resumes

* fix(runtime): prevent consumed resume replays

* fix(runtime): serialize approval resume consumption

* fix(runtime): prevent concurrent safe gate forks

* fix(runtime): close cancellation review gaps

* fix(llm): restore cache after cancelled refresh

* fix(runtime): close remaining cancellation windows

* fix(runtime): preserve cancellation recovery invariants

* fix(runtime): prevent stale resume recovery

* fix(runtime): preserve resume claim recovery

* fix(runtime): retry pre-dispatch claims safely

* fix(state): synchronize rollback-safe reads

* fix(resume): discard cancelled pipeline successors

* fix(runtime): harden cancellation and state locking

* fix(runtime): recover durable cancellation failures

* fix(runtime): preserve legacy workflow cancellation

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-08-13 10:54:20 -07:00

97 lines
2.9 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { spawn } from "node:child_process";
import { once } from "node:events";
import { EventEmitter } from "node:events";
import { PassThrough } from "node:stream";
import { readLineFromStream } from "../src/read_line.js";
test("readLineFromStream resolves on newline", async () => {
const input = new PassThrough();
const promise = readLineFromStream(input);
input.write("yes\n");
input.end();
const value = await promise;
assert.equal(value, "yes");
});
test("readLineFromStream accepts sequential reads from one stream", async () => {
const input = new PassThrough();
const first = readLineFromStream(input);
input.write("yes\n");
assert.equal(await first, "yes");
const second = readLineFromStream(input, { timeoutMs: 50 });
input.write("no\n");
assert.equal(await second, "no");
input.end();
});
test("readLineFromStream preserves the next line from a combined input chunk", async () => {
const input = new PassThrough();
const first = readLineFromStream(input);
input.end("yes\nno\n");
assert.equal(await first, "yes");
assert.equal(await readLineFromStream(input), "no");
});
test("readLineFromStream returns buffered input after a child pipe reaches EOF", async () => {
const child = spawn(process.execPath, ["-e", "process.stdout.write('yes\\npartial')"], {
stdio: ["ignore", "pipe", "inherit"],
});
assert.ok(child.stdout);
const first = readLineFromStream(child.stdout);
assert.equal(await first, "yes");
await once(child, "close");
assert.equal(await readLineFromStream(child.stdout, { timeoutMs: 50 }), "partial");
});
test("readLineFromStream drains a buffer that remains readable after EOF", async () => {
let buffered: Buffer | null = Buffer.from("partial");
const input = Object.assign(new EventEmitter(), {
readableEnded: true,
closed: true,
read() {
const value = buffered;
buffered = null;
return value;
},
pause() {},
resume() {},
}) as unknown as NodeJS.ReadableStream;
assert.equal(await readLineFromStream(input), "partial");
});
test("readLineFromStream resolves on end without newline", async () => {
const input = new PassThrough();
const promise = readLineFromStream(input);
input.write("partial");
input.end();
const value = await promise;
assert.equal(value, "partial");
});
test("readLineFromStream times out when no input arrives", async () => {
const input = new PassThrough();
await assert.rejects(
() => readLineFromStream(input, { timeoutMs: 5 }),
/Timed out waiting for input/,
);
});
test("readLineFromStream rejects when its signal is aborted", async () => {
const input = new PassThrough();
const controller = new AbortController();
const promise = readLineFromStream(input, { signal: controller.signal });
controller.abort(new Error("input cancelled"));
await assert.rejects(() => promise, /input cancelled/);
assert.equal(input.readableFlowing, false);
input.end();
});