Files
pikasTech-HWLAB/internal/hwpod/hwpod.test.ts
T

27 lines
1.3 KiB
TypeScript

/*
* SPEC: PJ2026-010103 HWPOD 服务。
* 实现引用: draft-2026-07-20-hwpod-temporal-split。
* 责任: HWPOD L0 合同与 activity 转发回归。
*/
import { afterEach, test, expect } from "bun:test";
import { executeHwpodOperation } from "./activities.ts";
import { validateHwpodOperationInput } from "./contracts.ts";
const originalFetch = globalThis.fetch;
afterEach(() => { globalThis.fetch = originalFetch; });
test("validates stable HWPOD operation identity", () => {
const input = validateHwpodOperationInput({ operationId: "op-1", runtimeApiUrl: "http://runtime/", plan: { planId: "plan-1" } });
expect(input.operationId).toBe("op-1");
expect(input.runtimeApiUrl).toBe("http://runtime");
});
test("forwards an HWPOD activity without changing the plan", async () => {
let received: any;
globalThis.fetch = (async (_url: any, init: any) => { received = JSON.parse(String(init.body)); return Response.json({ ok: true, status: "completed", planId: received.planId }); }) as any;
const result = await executeHwpodOperation({ operationId: "op-2", runtimeApiUrl: "http://runtime", plan: { planId: "plan-2", nodeId: "node-1", hwpodId: "pod-1", ops: [{ op: "node.health" }] } });
expect(received.planId).toBe("plan-2");
expect(result.ok).toBe(true);
expect(result.operationId).toBe("op-2");
});