offPeakExecution.test.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { describe, expect, it } from "vitest";
  2. import { modelExecutionSchema } from "../src/model-execution.js";
  3. import {
  4. offPeakLifecycleNotificationSchema,
  5. offPeakControlParamsSchema,
  6. } from "../src/off-peak-execution.js";
  7. describe("闲时驻内存执行协议", () => {
  8. it("接受后台执行元数据,生命周期通知严格拒绝凭据", () => {
  9. expect(
  10. modelExecutionSchema.parse({
  11. selectionScope: "execution",
  12. offPeak: { executionId: "run", ticketId: "ticket", providerErrorCode: "3102" },
  13. subagents: { foregroundModel: "submission", background: "allow" },
  14. }).offPeak?.executionId,
  15. ).toBe("run");
  16. const event = {
  17. sessionId: "session",
  18. executionId: "run",
  19. offPeakTaskId: "task",
  20. type: "ticket_needed",
  21. renewalId: 1,
  22. expiredTicketId: "ticket",
  23. };
  24. expect(offPeakLifecycleNotificationSchema.parse(event)).toEqual(event);
  25. expect(
  26. offPeakLifecycleNotificationSchema.safeParse({ ...event, requestAuth: { apiKey: "secret" } })
  27. .success,
  28. ).toBe(false);
  29. });
  30. it("换票强制执行身份和续票编号,取消不携带票据凭据", () => {
  31. const control = {
  32. sessionId: "session",
  33. executionId: "run",
  34. action: "replace_ticket",
  35. renewalId: 1,
  36. ticketId: "new",
  37. requestAuth: { headers: { ticket: "new" } },
  38. };
  39. expect(offPeakControlParamsSchema.parse(control)).toEqual(control);
  40. expect(offPeakControlParamsSchema.safeParse({ ...control, renewalId: undefined }).success).toBe(
  41. false,
  42. );
  43. expect(
  44. offPeakControlParamsSchema.safeParse({
  45. sessionId: "session",
  46. executionId: "run",
  47. action: "cancel",
  48. }).success,
  49. ).toBe(true);
  50. expect(offPeakControlParamsSchema.safeParse({ ...control, action: "cancel" }).success).toBe(
  51. false,
  52. );
  53. });
  54. });