diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 055b648..8d6d525 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,21 +27,35 @@ jobs: components: rustfmt - run: cargo fmt --check - # The SDKs and the VS Code extension, against their fake incode/agent. + # The SDKs and the VS Code extension, against their fake incode/agent. The + # SDKs on the oldest runtimes they promise (Node 18, Python 3.9) as well as + # current ones; the extension on the Node VS Code ships. Python 3.9 is past + # its end of life and setup-python has no build of it for the Ubuntu + # `ubuntu-latest` now is (26.04: "The version '3.9' ... was not found"), so + # that leg runs on 22.04. sdk-and-editor: - runs-on: ubuntu-latest + name: sdk-and-editor (node ${{ matrix.node }}, python ${{ matrix.python }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - { node: 18, python: "3.9", os: ubuntu-22.04 } + - { node: 20, python: "3.12", os: ubuntu-latest } + - { node: 22, python: "3.12", os: ubuntu-latest } steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: 22 + node-version: ${{ matrix.node }} - uses: actions/setup-python@v5 with: - python-version: "3.12" + python-version: ${{ matrix.python }} - run: python3 -m unittest discover sdk/python/tests - run: npm ci && npm test working-directory: sdk/typescript - run: npm ci && npm run compile && npm test + if: matrix.node == 22 working-directory: editors/vscode test: diff --git a/sdk/python/incode_sdk/__init__.py b/sdk/python/incode_sdk/__init__.py index ab91b26..f35a377 100644 --- a/sdk/python/incode_sdk/__init__.py +++ b/sdk/python/incode_sdk/__init__.py @@ -1,6 +1,7 @@ """Drive the incode coding agent from Python. * :func:`run_task` — one instruction, ``incode -t ... --output-format json``. +* :func:`stream_task` — the same, ``stream-json``: each event as it arrives. * :class:`Session` — an interactive session over ACP, ``incode --acp``. * :mod:`incode_sdk.aio` — awaitable wrappers of both. """ @@ -30,11 +31,14 @@ ) from .fs import FsAccessDenied, FsError, WorkspaceFS # noqa: E402 from .session import PromptStream, Session, allow_all, reject_all # noqa: E402 -from .task import TaskResult, TaskUsage, run_task # noqa: E402 +from .task import TaskEvent, TaskResult, TaskStream, TaskUsage, run_task, stream_task # noqa: E402 __all__ = [ "__version__", "run_task", + "stream_task", + "TaskEvent", + "TaskStream", "TaskResult", "TaskUsage", "Session", diff --git a/sdk/python/incode_sdk/task.py b/sdk/python/incode_sdk/task.py index e5dc0e5..f740dbf 100644 --- a/sdk/python/incode_sdk/task.py +++ b/sdk/python/incode_sdk/task.py @@ -1,14 +1,16 @@ -"""One-shot runs: ``incode -t "" --output-format json``.""" +"""One-shot runs: ``incode -t "" --output-format json`` (:func:`run_task`) +or ``stream-json``, one event at a time (:func:`stream_task`).""" import json import os import subprocess +import threading from dataclasses import dataclass, field -from typing import Any, Dict, List, Mapping, Optional, Sequence, Union +from typing import Any, Dict, Iterator, List, Mapping, Optional, Sequence, Union from .errors import IncodeError, IncodeTimeout, ProtocolError, TaskFailed -__all__ = ["TaskResult", "TaskUsage", "run_task", "build_task_argv"] +__all__ = ["TaskEvent", "TaskResult", "TaskStream", "TaskUsage", "run_task", "stream_task", "build_task_argv"] PathLike = Union[str, "os.PathLike[str]"] @@ -91,10 +93,12 @@ def build_task_argv( permission_mode: Optional[str] = None, incode_path: Union[PathLike, Sequence[str]] = "incode", extra_args: Sequence[str] = (), + output_format: str = "json", ) -> List[str]: - """The command line :func:`run_task` runs.""" + """The command line :func:`run_task` (``json``) or :func:`stream_task` + (``stream-json``) runs.""" argv = _command(incode_path) - argv += ["-t", task, "--output-format", "json"] + argv += ["-t", task, "--output-format", output_format] if workspace is not None: argv += ["-w", os.fspath(workspace)] if model: @@ -198,6 +202,159 @@ def run_task( return result +@dataclass +class TaskEvent: + """One line of ``incode -t ... --output-format stream-json`` before the + result: ``type`` is ``init``, ``text``, ``thinking``, ``notice``, + ``tool_use``, ``tool_result`` or ``usage`` (src/task_run.rs + ``Report::event``); ``data`` is the whole object.""" + + type: str + data: Dict[str, Any] + + +class TaskStream: + """A ``stream-json`` run: iterate it for :class:`TaskEvent`\\ s as they + arrive. When iteration ends, :attr:`result` holds the run's + :class:`TaskResult`; a failed run raises at the end of iteration, as + :func:`run_task` would (:class:`TaskFailed`, :class:`IncodeTimeout`, + :class:`IncodeError`, :class:`ProtocolError`). :meth:`wait` drains what is + left and returns the result.""" + + def __init__(self, argv: List[str], timeout: Optional[float], env: Optional[Mapping[str, str]]): + self.result: Optional[TaskResult] = None + self._timeout = timeout + self._timed_out = False + self._stderr: List[str] = [] + try: + self._proc = subprocess.Popen( + argv, + stdin=subprocess.DEVNULL, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=env, + ) + except FileNotFoundError as e: + raise IncodeError("could not start incode: %s (looked for %r)" % (e.strerror, argv[0])) from e + except PermissionError as e: + raise IncodeError("could not start incode: %s (%r)" % (e.strerror, argv[0])) from e + # stderr is read on its own thread, so a full pipe never stalls the run. + self._stderr_thread = threading.Thread(target=self._read_stderr, daemon=True) + self._stderr_thread.start() + self._timer: Optional[threading.Timer] = None + if timeout is not None: + self._timer = threading.Timer(timeout, self._kill_for_time) + self._timer.daemon = True + self._timer.start() + self._events = self._run() + + def _read_stderr(self) -> None: + assert self._proc.stderr is not None + for chunk in iter(lambda: self._proc.stderr.read(4096), b""): # type: ignore[union-attr] + self._stderr.append(_text(chunk)) + + def _kill_for_time(self) -> None: + self._timed_out = True + self._proc.kill() + + @property + def stderr(self) -> str: + """What incode wrote on stderr so far.""" + return "".join(self._stderr) + + def __iter__(self) -> Iterator[TaskEvent]: + return self._events + + def wait(self) -> TaskResult: + """Read the rest of the run and return its result (raising as + iteration would).""" + for _ in self._events: + pass + assert self.result is not None + return self.result + + def _run(self) -> Iterator[TaskEvent]: + assert self._proc.stdout is not None + data: Optional[Dict[str, Any]] = None + try: + for raw in self._proc.stdout: + line = _text(raw).strip() + if not line: + continue + try: + value = json.loads(line) + except ValueError: + self._proc.kill() + self._finish() + raise ProtocolError( + "incode -t printed a line that is not JSON: %r" % line[:500], stderr=self.stderr + ) from None + if not isinstance(value, dict): + continue + if value.get("type") == "result": + data = value + continue + yield TaskEvent(type=str(value.get("type") or ""), data=value) + finally: + code = self._finish() + if self._timed_out: + raise IncodeTimeout("incode -t did not finish within %ss" % self._timeout, stderr=self.stderr) + if data is None: + if code != 0: + raise IncodeError("incode -t failed before producing a result", stderr=self.stderr, exit_code=code) + raise ProtocolError("incode -t printed no JSON result object", stderr=self.stderr, exit_code=code) + self.result = TaskResult.from_json(data, exit_code=code, stderr=self.stderr) + if self.result.is_error or code != 0: + raise TaskFailed( + "incode -t reported an error: %s" % (self.result.error or "unknown error"), + result=self.result, + stderr=self.stderr, + exit_code=code, + ) + + def _finish(self) -> int: + code = self._proc.wait() + if self._timer is not None: + self._timer.cancel() + self._stderr_thread.join(timeout=5) + # Both pipes are done with once the process has exited and stderr is + # read: closed, so a program streaming many runs does not leak them. + for pipe in (self._proc.stdout, self._proc.stderr): + if pipe is not None: + pipe.close() + return code + + +def stream_task( + task: str, + *, + workspace: Optional[PathLike] = None, + model: Optional[str] = None, + permission_mode: Optional[str] = None, + timeout: Optional[float] = None, + incode_path: Union[PathLike, Sequence[str]] = "incode", + env: Optional[Mapping[str, str]] = None, + extra_args: Sequence[str] = (), +) -> TaskStream: + """Run one instruction with ``incode -t ... --output-format stream-json``: + a :class:`TaskStream` yielding each event as it arrives, then holding the + result. Takes the arguments :func:`run_task` takes.""" + argv = build_task_argv( + task, + workspace=workspace, + model=model, + permission_mode=permission_mode, + incode_path=incode_path, + extra_args=extra_args, + output_format="stream-json", + ) + full_env = None + if env is not None: + full_env = dict(os.environ) + full_env.update(env) + return TaskStream(argv, timeout, full_env) + + def _text(data: Any) -> str: if data is None: return "" diff --git a/sdk/python/tests/test_task.py b/sdk/python/tests/test_task.py index 2e0b7f0..d70bd93 100644 --- a/sdk/python/tests/test_task.py +++ b/sdk/python/tests/test_task.py @@ -6,7 +6,7 @@ from _support import FAKE -from incode_sdk import IncodeError, IncodeTimeout, ProtocolError, TaskFailed, TaskResult, run_task +from incode_sdk import IncodeError, IncodeTimeout, ProtocolError, TaskFailed, TaskResult, run_task, stream_task from incode_sdk.aio import run_task_async from incode_sdk.task import build_task_argv @@ -114,5 +114,59 @@ def test_async(self): self.assertEqual(result.result, "done: hello") +class StreamTaskTest(unittest.TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.ws = self.tmp.name + + def tearDown(self): + self.tmp.cleanup() + + def test_events_arrive_in_order_then_the_result(self): + argv_file = os.path.join(self.ws, "argv.json") + stream = stream_task("add a test", workspace=self.ws, incode_path=FAKE, env={"FAKE_INCODE_ARGV": argv_file}) + events = list(stream) + self.assertEqual([e.type for e in events], ["init", "text", "tool_use", "tool_result", "usage"]) + self.assertEqual(events[1].data["text"], "working on: add a test") + self.assertEqual(events[2].data["name"], "Read") + self.assertIsNotNone(stream.result) + self.assertEqual(stream.result.result, "done: add a test") + self.assertEqual(stream.result.usage.input_tokens, 120) + with open(argv_file, encoding="utf-8") as f: + argv = json.load(f) + self.assertIn("stream-json", argv) + self.assertNotIn("result", [e.type for e in events], "the result is not an event") + + def test_wait_returns_the_result(self): + self.assertEqual(stream_task("hello", workspace=self.ws, incode_path=FAKE).wait().result, "done: hello") + + def test_a_failed_run_raises_at_the_end_with_its_events_seen(self): + seen = [] + with self.assertRaises(TaskFailed) as cm: + for event in stream_task("fail now", workspace=self.ws, incode_path=FAKE): + seen.append(event.type) + self.assertEqual(seen[0], "init") + self.assertTrue(cm.exception.result.is_error) + + def test_a_line_that_is_not_json_is_a_protocol_error(self): + with self.assertRaises(ProtocolError): + list(stream_task("events-garbage", workspace=self.ws, incode_path=FAKE)) + + def test_a_crash_is_an_incode_error_with_stderr(self): + with self.assertRaises(IncodeError) as cm: + list(stream_task("crash", workspace=self.ws, incode_path=FAKE)) + self.assertIn("could not start", cm.exception.stderr) + + def test_a_timeout_kills_the_run(self): + with self.assertRaises(IncodeTimeout): + list(stream_task("sleep", workspace=self.ws, incode_path=FAKE, timeout=1)) + + def test_argv(self): + self.assertEqual( + build_task_argv("hi", output_format="stream-json"), + ["incode", "-t", "hi", "--output-format", "stream-json"], + ) + + if __name__ == "__main__": unittest.main() diff --git a/sdk/testing/fake_incode.py b/sdk/testing/fake_incode.py index a9935cd..358652d 100755 --- a/sdk/testing/fake_incode.py +++ b/sdk/testing/fake_incode.py @@ -13,6 +13,10 @@ ``sleep`` -> sleeps 30 s (for timeouts) otherwise -> success, ``result`` is ``"done: "`` + With ``--output-format stream-json``, the events ``init``, ``text``, + ``tool_use``, ``tool_result`` and ``usage`` come first, one per line + (``events-garbage`` adds a line that is not JSON after them). + * ``fake_incode.py --acp`` speaks ACP (newline-delimited JSON-RPC 2.0) on stdin/stdout, mirroring ``src/acp_agent``: ``initialize``, ``session/new``, ``session/load``, ``session/prompt``, ``session/cancel``, ``session/set_mode``, @@ -108,6 +112,21 @@ def run_task(args): result["error"] = "nothing to do: the instruction is empty" if not task.strip() else "the agent failed: fake failure" else: result["result"] = "done: " + task + if fmt == "stream-json": + # The events src/task_run.rs `Report::init` / `Report::event` write + # before the result, one JSON object per line. + for event in ( + {"type": "init", "session_id": result["session_id"], "agent": "claude-code", "model": result["model"]}, + {"type": "text", "text": "working on: " + task}, + {"type": "tool_use", "id": "t1", "name": "Read", "input": {"path": "README.md"}}, + {"type": "tool_result", "id": "t1", "output": "read it", "is_error": False}, + {"type": "usage", "input_tokens": 120, "output_tokens": 45, "cache_creation_tokens": 7, "cache_read_tokens": 300}, + ): + sys.stdout.write(json.dumps(event) + "\n") + sys.stdout.flush() + if word == "events-garbage": + sys.stdout.write("this is not json\n") + sys.stdout.flush() if fmt in ("json", "stream-json"): sys.stdout.write(json.dumps(result) + "\n") else: diff --git a/sdk/typescript/src/index.ts b/sdk/typescript/src/index.ts index 082f270..c200b1e 100644 --- a/sdk/typescript/src/index.ts +++ b/sdk/typescript/src/index.ts @@ -7,8 +7,8 @@ export { AcpError, AgentCrashed, IncodeError, IncodeTimeout, ProtocolError, TaskFailed } from "./errors.js"; export type { ErrorDetails } from "./errors.js"; -export { buildTaskArgv, parseTaskResult, runTask } from "./task.js"; -export type { IncodePath, RunTaskOptions, TaskResult, TaskUsage } from "./task.js"; +export { buildTaskArgv, parseTaskResult, runTask, streamTask } from "./task.js"; +export type { IncodePath, RunTaskOptions, TaskEvent, TaskResult, TaskStream, TaskUsage } from "./task.js"; export { parseUpdate, PermissionRequest } from "./events.js"; export type { AvailableCommands, diff --git a/sdk/typescript/src/task.ts b/sdk/typescript/src/task.ts index 49acdda..10f66db 100644 --- a/sdk/typescript/src/task.ts +++ b/sdk/typescript/src/task.ts @@ -1,6 +1,10 @@ -/** One-shot runs: `incode -t "" --output-format json`. */ +/** + * One-shot runs: `incode -t "" --output-format json` (`runTask`), or + * `stream-json`, one event at a time (`streamTask`). + */ import { spawn } from "node:child_process"; +import { createInterface } from "node:readline"; import { IncodeError, IncodeTimeout, ProtocolError, TaskFailed } from "./errors.js"; @@ -95,10 +99,14 @@ export function parseTaskResult(data: Record, exitCode: number }; } -/** The command line `runTask` runs, as `[command, ...args]`. */ -export function buildTaskArgv(task: string, options: RunTaskOptions = {}): string[] { +/** The command line `runTask` (`json`) or `streamTask` (`stream-json`) runs, as `[command, ...args]`. */ +export function buildTaskArgv( + task: string, + options: RunTaskOptions = {}, + outputFormat: "json" | "stream-json" = "json", +): string[] { const argv = commandOf(options.incodePath); - argv.push("-t", task, "--output-format", "json"); + argv.push("-t", task, "--output-format", outputFormat); if (options.workspace !== undefined) argv.push("-w", options.workspace); if (options.model) argv.push("-m", options.model); if (options.permissionMode) argv.push("-p", options.permissionMode); @@ -197,3 +205,135 @@ export function runTask(task: string, options: RunTaskOptions = {}): Promise; +} + +/** + * A `stream-json` run. Iterate it (`for await`) for its events as they arrive; + * `result` resolves with the run's `TaskResult`, or rejects as `runTask` would + * (`TaskFailed`, `IncodeTimeout`, `IncodeError`, `ProtocolError`). Iterating to + * the end throws that same error. + */ +export interface TaskStream extends AsyncIterable { + readonly result: Promise; +} + +/** Run one instruction with `incode -t ... --output-format stream-json`. Takes `runTask`'s options. */ +export function streamTask(task: string, options: RunTaskOptions = {}): TaskStream { + const [command, ...args] = buildTaskArgv(task, options, "stream-json"); + const queue: TaskEvent[] = []; + let wake: (() => void) | null = null; + let finished = false; + let stderr = ""; + let timedOut = false; + let aborted = false; + let notJson: string | null = null; + let resultData: Record | null = null; + let spawnError: NodeJS.ErrnoException | null = null; + + const child = spawn(command as string, args, { + stdio: ["ignore", "pipe", "pipe"], + env: options.env ? { ...process.env, ...options.env } : process.env, + }); + child.stderr.setEncoding("utf8"); + child.stderr.on("data", (d: string) => (stderr += d)); + const lines = createInterface({ input: child.stdout, crlfDelay: Infinity }); + lines.on("line", (raw: string) => { + const line = raw.trim(); + if (line === "" || notJson !== null) return; + let value: unknown; + try { + value = JSON.parse(line); + } catch { + notJson = line; + child.kill("SIGKILL"); + return; + } + if (!value || typeof value !== "object" || Array.isArray(value)) return; + const data = value as Record; + if (data["type"] === "result") { + resultData = data; + return; + } + queue.push({ type: typeof data["type"] === "string" ? data["type"] : "", data }); + wake?.(); + }); + + const timer = + options.timeoutMs !== undefined + ? setTimeout(() => { + timedOut = true; + child.kill("SIGKILL"); + }, options.timeoutMs) + : undefined; + const onAbort = (): void => { + aborted = true; + child.kill("SIGKILL"); + }; + options.signal?.addEventListener("abort", onAbort, { once: true }); + if (options.signal?.aborted) onAbort(); + + const exited = new Promise((resolve) => { + child.on("error", (err: NodeJS.ErrnoException) => { + spawnError = err; + resolve(null); + }); + child.on("close", (code) => resolve(code)); + }); + + const result = exited.then((code): TaskResult => { + finished = true; + if (timer) clearTimeout(timer); + options.signal?.removeEventListener("abort", onAbort); + wake?.(); + if (spawnError) throw new IncodeError(`could not start incode: ${spawnError.message} (${command})`, { stderr }); + if (timedOut) throw new IncodeTimeout(`incode -t did not finish within ${options.timeoutMs}ms`, { stderr }); + if (aborted) throw new IncodeError("incode -t was aborted", { stderr }); + if (notJson !== null) { + throw new ProtocolError(`incode -t printed a line that is not JSON: ${JSON.stringify((notJson as string).slice(0, 500))}`, { + stderr, + exitCode: code, + }); + } + if (resultData === null) { + if (code !== 0) throw new IncodeError("incode -t failed before producing a result", { stderr, exitCode: code }); + throw new ProtocolError("incode -t printed no JSON result object", { stderr, exitCode: code }); + } + const parsed = parseTaskResult(resultData, code, stderr); + if (parsed.isError || code !== 0) { + throw new TaskFailed(`incode -t reported an error: ${parsed.error ?? "unknown error"}`, parsed, { + stderr, + exitCode: code, + }); + } + return parsed; + }); + // Handled here so a caller that only iterates is not warned of an + // unhandled rejection; `result` itself still rejects for whoever awaits it. + result.catch(() => undefined); + + return { + result, + async *[Symbol.asyncIterator](): AsyncIterator { + for (;;) { + const next = queue.shift(); + if (next !== undefined) { + yield next; + continue; + } + if (finished) break; + await new Promise((resolve) => (wake = resolve)); + wake = null; + } + await result; + }, + }; +} diff --git a/sdk/typescript/test/index.test.ts b/sdk/typescript/test/index.test.ts new file mode 100644 index 0000000..b11cb7e --- /dev/null +++ b/sdk/typescript/test/index.test.ts @@ -0,0 +1,30 @@ +// The package entry (src/index.ts): what a consumer of `@incord/incode-sdk` +// can import, and that it works through that import. + +import assert from "node:assert/strict"; +import { describe, it } from "node:test"; + +import * as entry from "../src/index.js"; +import { FAKE, tempDirs } from "./support.js"; + +describe("the package entry (src/index.ts)", () => { + it("exports the one-shot runs, runTask and streamTask", () => { + assert.equal(typeof entry.runTask, "function"); + assert.equal(typeof entry.streamTask, "function"); + assert.equal(typeof entry.buildTaskArgv, "function"); + assert.equal(typeof entry.parseTaskResult, "function"); + }); + + it("streams a run through the entry, events then result", async () => { + const dirs = tempDirs(); + try { + const stream = entry.streamTask("hello", { workspace: dirs.ws, incodePath: FAKE }); + const types: string[] = []; + for await (const event of stream) types.push(event.type); + assert.deepEqual(types, ["init", "text", "tool_use", "tool_result", "usage"]); + assert.equal((await stream.result).result, "done: hello"); + } finally { + dirs.cleanup(); + } + }); +}); diff --git a/sdk/typescript/test/task.test.ts b/sdk/typescript/test/task.test.ts index 40cbd8a..464ae06 100644 --- a/sdk/typescript/test/task.test.ts +++ b/sdk/typescript/test/task.test.ts @@ -3,7 +3,16 @@ import * as fs from "node:fs"; import * as path from "node:path"; import { afterEach, beforeEach, describe, it } from "node:test"; -import { buildTaskArgv, IncodeError, IncodeTimeout, parseTaskResult, ProtocolError, runTask, TaskFailed } from "../src/index.js"; +import { + buildTaskArgv, + IncodeError, + IncodeTimeout, + parseTaskResult, + ProtocolError, + runTask, + streamTask, + TaskFailed, +} from "../src/index.js"; import { FAKE, tempDirs, type TempDirs } from "./support.js"; describe("runTask", () => { @@ -113,5 +122,58 @@ describe("runTask", () => { it("builds the argv", () => { assert.deepEqual(buildTaskArgv("hi"), ["incode", "-t", "hi", "--output-format", "json"]); + assert.deepEqual(buildTaskArgv("hi", {}, "stream-json"), ["incode", "-t", "hi", "--output-format", "stream-json"]); + }); +}); + +describe("streamTask", () => { + let dirs: TempDirs; + beforeEach(() => { + dirs = tempDirs(); + }); + afterEach(() => dirs.cleanup()); + + it("yields each event in order, then the result", async () => { + const argvFile = path.join(dirs.root, "argv.json"); + const stream = streamTask("add a test", { workspace: dirs.ws, incodePath: FAKE, env: { FAKE_INCODE_ARGV: argvFile } }); + const types: string[] = []; + let text = ""; + for await (const event of stream) { + types.push(event.type); + if (event.type === "text") text = String(event.data["text"]); + } + assert.deepEqual(types, ["init", "text", "tool_use", "tool_result", "usage"]); + assert.equal(text, "working on: add a test"); + const result = await stream.result; + assert.equal(result.result, "done: add a test"); + assert.equal(result.usage.inputTokens, 120); + assert.ok((JSON.parse(fs.readFileSync(argvFile, "utf8")) as string[]).includes("stream-json")); + }); + + it("rejects a failed run at the end of iteration, after its events", async () => { + const seen: string[] = []; + await assert.rejects( + (async () => { + for await (const event of streamTask("fail now", { workspace: dirs.ws, incodePath: FAKE })) seen.push(event.type); + })(), + TaskFailed, + ); + assert.equal(seen[0], "init"); + }); + + it("rejects a line that is not JSON", async () => { + await assert.rejects(streamTask("events-garbage", { workspace: dirs.ws, incodePath: FAKE }).result, ProtocolError); + }); + + it("rejects a crash with incode's stderr", async () => { + await assert.rejects(streamTask("crash", { workspace: dirs.ws, incodePath: FAKE }).result, (e: unknown) => { + assert.ok(e instanceof IncodeError); + assert.match(e.stderr ?? "", /could not start/); + return true; + }); + }); + + it("kills a run that takes too long", async () => { + await assert.rejects(streamTask("sleep", { workspace: dirs.ws, incodePath: FAKE, timeoutMs: 1000 }).result, IncodeTimeout); }); });