Files
oh-my-pi/packages/coding-agent/test/worker-selector.test.ts
T
roboomp 30953d3bfe fix(cli): errored on unknown __omp_worker_ selectors
Unknown reserved __omp_worker_* selectors hit the worker-host re-entry
seam, runWorkerEntrypoint returned false, and the ignored result let the
process exit 0 with empty stdout/stderr. A stale or mistyped selector
looked healthy to parent processes and install smoke paths.

Check runWorkerEntrypoint's return at the dispatch seam: an unrecognized
selector now writes "Error: unknown worker selector: <arg>" to stderr and
sets a nonzero exit code without starting a worker. Known selectors and
normal CLI arguments are unchanged.

Fixes #5712
2026-07-16 14:15:44 +00:00

38 lines
1.3 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from "bun:test";
import { runCli } from "../src/cli";
// The worker-host re-entry seam dispatches any `__omp_worker_*` selector to
// `runWorkerEntrypoint`. An unrecognized selector must fail loudly rather than
// exit 0 with empty output, so a stale/mistyped selector cannot look healthy to
// a parent process or install smoke path (issue #5712).
describe("worker selector dispatch", () => {
beforeEach(() => {
process.exitCode = 0;
});
afterEach(() => {
vi.restoreAllMocks();
process.exitCode = 0;
});
it("fails with a nonzero exit and stderr error on an unknown selector", async () => {
const stderr = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
await runCli(["__omp_worker_does_not_exist"]);
expect(process.exitCode).toBe(1);
expect(stderr).toHaveBeenCalledWith("Error: unknown worker selector: __omp_worker_does_not_exist\n");
});
it("leaves normal root flags untouched", async () => {
const stdout = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
const stderr = vi.spyOn(process.stderr, "write").mockImplementation(() => true);
await runCli(["--version"]);
expect(process.exitCode).toBe(0);
expect(stdout).toHaveBeenCalled();
expect(stderr).not.toHaveBeenCalledWith(expect.stringContaining("unknown worker selector"));
});
});