pi-mono/packages/chord/test/next-node/fixtures/workers/control.ts
Mario Zechner 8959ad6e68 feat(chord): Chord v2 slice 10, HTTP and workers
chord/next/http: a Web fetch handler built from the registry Http (routes, wraps,
sockets, hosts, relays, CSP sources) and Authenticators, responses as descriptions,
a security baseline on by default, Chord's own Node listener as a host-lifetime
object, nodeRequest for apps mounting it, links and plugin sockets.
chord/next/workers: a forked worker per address, started on demand, stopped when
idle, never restarted by itself, plugins built by the server and shipped.
Plugins: kinds with platform and host packages, createPluginRuntime, scripts(kind),
rollout results per host, imports of other plugins by name. Kernel: RouteHandle
(retry, suspend), no route backoff, anonymous host.root, origins only from relays.
ws is an optional peer dependency.
2026-10-31 20:40:36 +00:00

47 lines
1.6 KiB
TypeScript

// Fixture contracts (slice 10): the session kind the workers serve, the fixture worker's `Control` and its start data.
import { hostKind, int, method, remote, str } from "../../../../src/next/contracts/index.ts";
/** The host kind of the fixture workers. */
export const Session = hostKind("session", { id: str() });
/** What the fixture worker does on request, at its own address. */
export const Control = remote("test.control", {
version: 1,
params: { id: str() },
hostAddress: ({ id }) => Session({ id }),
variants: {
main: {
methods: {
crash: method(int()),
fatal: method(str()),
block: method(int()),
blockThenCrash: method(int()),
busy: method(int()),
localCalls: method(int(), int()),
},
},
},
});
/** The fixture worker's start data: how it behaves. */
export type WorkerBehaviour = {
/** Exit with this code before connecting. */
readonly exit?: number;
/** Throw an error with this message before connecting (`fatal`, redacted: `secret…` words removed). */
readonly fatal?: string;
/** `false`: never connect (the start timer). */
readonly connect?: boolean;
/** Wait this long after connecting, before the load. */
readonly loadMs?: number;
/** Never load. */
readonly hang?: boolean;
/** A file the closers append their names to, in the order they run. */
readonly log?: string;
/** How long the second closer takes. */
readonly closeMs?: number;
/** After its load: close its IPC channel and block, alive (the server must reap it). */
readonly disconnectAndBlock?: boolean;
/** 300 ms after its load: this many sequential local calls, then `local calls sent <n>` on stdout. */
readonly localCalls?: number;
};