Files
oh-my-pi/packages/coding-agent/test/worker-selector.test.ts
T
can1357 aa014717dc refactor(coding-agent): restored static computer worker start hook
- The pi-utils/mime subpath fix made the computer worker graph lazy-safe,
  so the dynamic-import dispatch added for laziness is no longer needed;
  cli.ts and the bundled-host fixture statically import
  startComputerWorker() per the no-inline-import rule.
- worker-entry keeps the selector-guarded direct-source auto-start; the
  worker-selector test now pins the exported hook contract. Verified
  --no-addons CLI startup stays addon-free and the bundled/compiled
  worker-host tests pass.
2026-08-03 00:19:58 +02:00

47 lines
1.8 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from "bun:test";
import { runCli } from "../src/cli";
import * as computerWorkerEntry from "../src/tools/computer/worker-entry";
// 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"));
});
});
describe("computer worker entry", () => {
it("is side-effect-free to import outside a worker and exposes a named start function", () => {
// Importing on the main thread (no parentPort) must not start the worker
// core; the CLI host and bundled hosts call the exported hook explicitly.
expect(computerWorkerEntry.startComputerWorker).toBeFunction();
});
});