import { describe, expect, it } from "vitest"; import { parseSafeJobResponse } from "./jobs"; const retryingJob = { id: "job-1", runEndpointId: "run-local", capability: "process.start", idempotencyKey: "idem-1", state: "retrying", progress: { percent: 10, message: "Run acknowledgement deadline expired" }, retryPolicy: { maxAttempts: 3, initialBackoffSeconds: 2, maxBackoffSeconds: 60 }, attempt: 1, nextAttemptAt: "2026-07-18T12:00:02Z", reconcileCount: 1, reconcileOutcome: "missing from Run journal", createdAt: "2026-07-18T12:00:00Z", updatedAt: "2026-07-18T12:00:00Z" }; describe("safe job projection schema", () => { it("accepts retry and reconciliation metadata", () => { expect(parseSafeJobResponse(retryingJob)).toMatchObject({ state: "retrying", attempt: 1, retryPolicy: { maxAttempts: 3 }, reconcileCount: 1 }); }); it.each(["leaseToken", "leaseTokenHash", "sessionToken", "secretRef", "hostPath", "socket"])("rejects forbidden %s fields", (field) => { expect(() => parseSafeJobResponse({ ...retryingJob, [field]: "forbidden" })).toThrow(/forbidden field/); }); it("accepts safe typed execution metadata without private content", () => { const parsed = parseSafeJobResponse({ ...retryingJob, state: "succeeded", executionResult: { kind: "file.write", version: 2, checksum: "sha256:" + "a".repeat(64), sizeBytes: 18, summary: "atomic compare-and-swap file write" } }); expect(parsed.executionResult).toMatchObject({ kind: "file.write", version: 2, sizeBytes: 18 }); expect(parsed.executionResult).not.toHaveProperty("content"); expect(() => parseSafeJobResponse({ ...retryingJob, executionResult: { content: "private" } })).toThrow(/forbidden field/); }); });