resume-workflow-run.test.ts 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. RESUME_WORKFLOW_RUN_TOOL_NAME,
  4. ResumeWorkflowRunInputJsonSchema,
  5. ResumeWorkflowRunInputSchema,
  6. ResumeWorkflowRunOutputJsonSchema,
  7. ResumeWorkflowRunOutputSchema,
  8. } from "../src/tools/resume-workflow-run.js";
  9. // 成功输出只有一个形状:run 恢复后在后台飞行,携勿轮询引导。失败走 ToolHandlerFailure
  10. // 不进输出 schema,所以这里没有失败形用例(handler 侧的测试钉那五条 reason)。
  11. const BACKGROUNDED = {
  12. ok: true,
  13. runId: "dwfrun-1",
  14. response: "The workflow run resumed in the background with ID: dwfrun-1.",
  15. status: "backgrounded" as const,
  16. backgroundTaskId: "dwfrun-1",
  17. };
  18. describe("ResumeWorkflowRun input schema", () => {
  19. it("names the tool exactly as it registers", () => {
  20. expect(RESUME_WORKFLOW_RUN_TOOL_NAME).toBe("ResumeWorkflowRun");
  21. });
  22. // snake_case 随 GetWorkflowRun 的 run_id / TaskOutput 的 task_id:在模型眼里这三个键是
  23. // 同一族的 run/task 标识,命名风格分叉只会让它在工具之间猜。
  24. it("requires a non-empty snake_case run_id", () => {
  25. expect(ResumeWorkflowRunInputSchema.parse({ run_id: "dwfrun-1" })).toEqual({
  26. run_id: "dwfrun-1",
  27. });
  28. expect(ResumeWorkflowRunInputSchema.safeParse({ run_id: "" }).success).toBe(false);
  29. expect(ResumeWorkflowRunInputSchema.safeParse({}).success).toBe(false);
  30. expect(ResumeWorkflowRunInputSchema.safeParse({ runId: "dwfrun-1" }).success).toBe(false);
  31. });
  32. it("stays strict about unknown keys", () => {
  33. expect(
  34. ResumeWorkflowRunInputSchema.safeParse({ run_id: "dwfrun-1", force: true }).success,
  35. ).toBe(false);
  36. });
  37. it("requires run_id as the only property in the model-facing JSON schema", () => {
  38. const schema = ResumeWorkflowRunInputJsonSchema as {
  39. properties?: Record<string, unknown>;
  40. required?: string[];
  41. };
  42. expect(Object.keys(schema.properties ?? {})).toEqual(["run_id"]);
  43. expect(schema.required).toEqual(["run_id"]);
  44. });
  45. });
  46. describe("ResumeWorkflowRun output schema", () => {
  47. it("roundtrips the backgrounded success shape", () => {
  48. const parsed = ResumeWorkflowRunOutputSchema.parse(BACKGROUNDED);
  49. expect(parsed).toEqual(BACKGROUNDED);
  50. });
  51. // backgroundTaskId ≡ runId 是取消/查询/通知共用键的恒等式;schema 只钉「在场且非空」,
  52. // 等值本身由 handler 构造保证(handler 侧测试钉 ===)。
  53. it("requires every field of the success shape — there is no failure variant here", () => {
  54. expect(ResumeWorkflowRunOutputSchema.safeParse({ ...BACKGROUNDED, status: "completed" }).success).toBe(
  55. false,
  56. );
  57. expect(
  58. ResumeWorkflowRunOutputSchema.safeParse({ ...BACKGROUNDED, backgroundTaskId: "" }).success,
  59. ).toBe(false);
  60. expect(ResumeWorkflowRunOutputSchema.safeParse({ ok: true, runId: "dwfrun-1" }).success).toBe(
  61. false,
  62. );
  63. });
  64. it("stays strict about unknown keys", () => {
  65. expect(ResumeWorkflowRunOutputSchema.safeParse({ ...BACKGROUNDED, extra: 1 }).success).toBe(
  66. false,
  67. );
  68. });
  69. it("projects the success shape into the model-facing JSON schema", () => {
  70. const schema = ResumeWorkflowRunOutputJsonSchema as {
  71. properties?: Record<string, unknown>;
  72. required?: string[];
  73. };
  74. expect(Object.keys(schema.properties ?? {})).toEqual([
  75. "ok",
  76. "runId",
  77. "response",
  78. "status",
  79. "backgroundTaskId",
  80. ]);
  81. expect(schema.required).toEqual(["ok", "runId", "response", "status", "backgroundTaskId"]);
  82. });
  83. });