automationRunId.test.ts 1.1 KB

12345678910111213141516171819202122232425262728
  1. import { describe, expect, it } from "vitest";
  2. import { parseAutomationRunId } from "../src/automation-types.js";
  3. describe("parseAutomationRunId", () => {
  4. it("解析 schedule runId 的 automationId 与 scheduledAt", () => {
  5. expect(parseAutomationRunId("automation-1:1700000000000")).toEqual({
  6. automationId: "automation-1",
  7. trigger: "schedule",
  8. scheduledAt: 1_700_000_000_000,
  9. });
  10. });
  11. it("解析 manual runId,不产出 scheduledAt", () => {
  12. expect(parseAutomationRunId("automation-1:manual:run-1")).toEqual({
  13. automationId: "automation-1",
  14. trigger: "manual",
  15. });
  16. });
  17. it("不符合契约的输入一律返回 null,不猜格式", () => {
  18. expect(parseAutomationRunId("command-uuid-without-colon")).toBeNull();
  19. expect(parseAutomationRunId(":1700000000000")).toBeNull();
  20. expect(parseAutomationRunId("automation-1:not-a-timestamp")).toBeNull();
  21. expect(parseAutomationRunId("automation-1:manual:")).toBeNull();
  22. expect(parseAutomationRunId("automation-1:-5")).toBeNull();
  23. expect(parseAutomationRunId("automation-1:1700000000000.5")).toBeNull();
  24. });
  25. });