task-output.test.ts 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. TASK_OUTPUT_PROVIDER_DESCRIPTION,
  4. TaskOutputInputJsonSchema,
  5. TaskOutputInputSchema,
  6. } from "../src/tools/task-output.js";
  7. describe("TaskOutput contracts", () => {
  8. it("exposes the canonical provider description", () => {
  9. expect(TASK_OUTPUT_PROVIDER_DESCRIPTION).toBe(
  10. [
  11. "DEPRECATED: Background tasks return their output file path in the tool result, and you receive a <task-notification> with the same path when the task completes.",
  12. "- For bash tasks: prefer using the Read tool on that output file path — it contains stdout/stderr.",
  13. "- For local_agent tasks: use the Agent tool result directly. Do NOT Read the .output file — it is a symlink to the full subagent conversation transcript (JSONL) and will overflow your context window.",
  14. "- For remote_agent tasks: prefer using the Read tool on the output file path — it contains the streamed remote session output (same as bash).",
  15. "",
  16. "- Retrieves output from a running or completed task (background shell, agent, or remote session)",
  17. "- Takes a task_id parameter identifying the task",
  18. "- Returns the task output along with status information",
  19. "- Use block=true (default) to wait for task completion",
  20. "- Use block=false for non-blocking check of current status",
  21. "- Task IDs can be found using the /tasks command",
  22. "- Works with all task types: background shells, async agents, and remote sessions",
  23. ].join("\n"),
  24. );
  25. });
  26. it("exposes the canonical provider input schema", () => {
  27. expect(TaskOutputInputJsonSchema).toEqual({
  28. type: "object",
  29. properties: {
  30. task_id: {
  31. type: "string",
  32. description: "The task ID to get output from",
  33. },
  34. block: {
  35. type: "boolean",
  36. default: true,
  37. description: "Whether to wait for completion",
  38. },
  39. timeout: {
  40. type: "number",
  41. default: 30_000,
  42. minimum: 0,
  43. maximum: 600_000,
  44. description: "Max wait time in ms",
  45. },
  46. },
  47. required: ["task_id", "block", "timeout"],
  48. additionalProperties: false,
  49. $schema: "https://json-schema.org/draft/2020-12/schema",
  50. });
  51. });
  52. it("applies defaults and accepts only the supported semantic boolean strings", () => {
  53. expect(TaskOutputInputSchema.parse({ task_id: "agent_1" })).toEqual({
  54. task_id: "agent_1",
  55. block: true,
  56. timeout: 30_000,
  57. });
  58. expect(
  59. TaskOutputInputSchema.parse({
  60. task_id: "agent_1",
  61. block: "false",
  62. timeout: 0,
  63. }),
  64. ).toEqual({
  65. task_id: "agent_1",
  66. block: false,
  67. timeout: 0,
  68. });
  69. expect(TaskOutputInputSchema.parse({ task_id: "agent_1", block: "true" }).block).toBe(true);
  70. expect(
  71. TaskOutputInputSchema.safeParse({
  72. task_id: "agent_1",
  73. block: "1",
  74. }).success,
  75. ).toBe(false);
  76. });
  77. it("rejects unknown fields and out-of-range timeout values", () => {
  78. expect(
  79. TaskOutputInputSchema.safeParse({
  80. task_id: "agent_1",
  81. extra: true,
  82. }).success,
  83. ).toBe(false);
  84. expect(
  85. TaskOutputInputSchema.safeParse({
  86. task_id: "agent_1",
  87. timeout: 600_001,
  88. }).success,
  89. ).toBe(false);
  90. });
  91. });