import { describe, expect, it } from "bun:test"; import { buildFlowActionSucceededObservationSeed, toFlowActionSucceededObservationSeed, } from "./flow-action-succeeded-observation"; const navigationSeed = { flowId: "flow-1", flowVersionId: "flow-version-1", flowVersionNumber: 3, flowRunId: "flow-run-1", actionPlacementId: "navigation-placement-1", actionKind: "navigation-action" as const, }; describe("Flow Action Succeeded observation seed", () => { it("copies and freezes a valid source-neutral seed", () => { const source = { ...navigationSeed }; const seed = buildFlowActionSucceededObservationSeed(source); source.flowId = "spoofed-flow"; expect(seed).toEqual(navigationSeed); expect(Object.isFrozen(seed)).toBe(true); expect(() => { (seed as { flowId: string }).flowId = "spoofed-flow"; }).toThrow(); }); it("cross-binds a valid seed to its executor kind", () => { const parsed = toFlowActionSucceededObservationSeed( navigationSeed, "navigation-action", ); expect(parsed).toEqual(navigationSeed); expect(parsed).not.toBe(navigationSeed); expect(Object.isFrozen(parsed)).toBe(true); expect( toFlowActionSucceededObservationSeed(navigationSeed, "runtime-action"), ).toBeNull(); }); it("drops incomplete, malformed, and expanded provenance", () => { for (const candidate of [ { ...navigationSeed, flowRunId: "" }, { ...navigationSeed, flowVersionNumber: 0 }, { ...navigationSeed, responseId: "response-1" }, { ...navigationSeed, actionKind: "remote-action" }, ]) { expect( toFlowActionSucceededObservationSeed(candidate, "navigation-action"), ).toBeNull(); } }); });