Fork Horse repository, listed by its owner. Publisher snapshot.

packages/forkhorse-gatekeeper/test/local/offline-worker.ts

Snapshot at 34e3175

Containing directory

1,996 bytes · typescriptView raw
1// ONLY for an isolated run-local copy. Never deploy this entrypoint: Core identity and state
2// are synthetic, and every other outbound request is refused. Production builds exclude it.
3import { fixtureState } from "../../../forkhorse-dashboard/test/fixtures.ts";
4import worker from "../../src/worker/index.ts";
5export { GatekeeperVendor, UserAccount, AgentAccount, AgentVerifier, ForkGatekeeper } from "../../src/worker/index.ts";
6const started = Date.now();
7const networkFetch = globalThis.fetch;
8globalThis.fetch = async (input: RequestInfo | URL, init?: RequestInit): Promise<Response> => {
9  const request = new Request(input, init);
10  const url = new URL(request.url);
11  // Enabled only by the isolated full-OS test build. The fixture listener is loopback-only.
12  if (import.meta.env.MODE === "full-os") {
13    if (!["https://core.fixture.idiot.tax", "https://git.fixture.idiot.tax"].includes(url.origin)) {
14      throw new Error("This local fixture refuses external traffic.");
15    }
16    return networkFetch(new Request(`http://127.0.0.1:4181${url.pathname}`, request));
17  }
18  if (url.origin !== "https://core.fixture.idiot.tax" || request.headers.get("authorization") !== "Bearer fixture-agent-credential-only") {
19    throw new Error("This local fixture refuses external traffic.");
20  }
21  if (url.pathname === "/projects/fixture/me") return Response.json({ role: "agent", agent: "local-fixture", forks: [{ repoName: "fork-alpha", remote: "https://git.fixture.idiot.tax/fork-alpha.git", head: "a".repeat(40), createdAt: "2026-01-01T00:00:00Z" }] });
22  if (url.pathname === "/projects/fixture/state") {
23    const state = fixtureState(); state.project.id = "fixture";
24    state.packets[0].title = `LOCAL FIXTURE batch ${Math.floor((Date.now() - started) / 250)}`;
25    state.packets[0].goal = "Synthetic Core snapshots in the pinned local OS. No live data or inference.";
26    return Response.json(state);
27  }
28  throw new Error("Unsupported local fixture request.");
29};
30export default worker;
31