// R-P12c — worker seam tests: envelope parsing (tenant mismatch fail-closed) // and companion-consumer skip behaviour for non-automation events. import { describe, expect, test } from "vitest"; import { AutomationExecutorJobError, parseAutomationExecutorOutboxJob } from "./automation-forward.js"; describe("parseAutomationExecutorOutboxJob", () => { test("accepts a well-formed automation.execution.requested envelope", () => { expect( parseAutomationExecutorOutboxJob({ eventType: "automation.execution.requested", tenantId: "tenant-a", payload: { executionId: "exec-1", tenantId: "tenant-a" }, }) ).toEqual({ tenantId: "tenant-a", executionId: "exec-1" }); }); test("rejects foreign event types, missing ids and tenant mismatches fail-closed", () => { expect(() => parseAutomationExecutorOutboxJob({ eventType: "workflow.trigger.event", tenantId: "t", payload: {} })).toThrow(AutomationExecutorJobError); expect(() => parseAutomationExecutorOutboxJob({ eventType: "automation.execution.requested", tenantId: "", payload: { executionId: "e" } })).toThrow( AutomationExecutorJobError ); expect(() => parseAutomationExecutorOutboxJob({ eventType: "automation.execution.requested", tenantId: "tenant-a", payload: { executionId: "exec-1", tenantId: "tenant-b" }, }) ).toThrow(/tenantId mismatch/); }); });