respond-to-coordinator.test.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. RESPOND_TO_COORDINATOR_MAX_CONTENT_CHARS,
  4. RespondToCoordinatorInputSchema,
  5. RespondToCoordinatorOutputSchema,
  6. } from "../src/index.js";
  7. describe("RespondToCoordinator contract", () => {
  8. it("accepts only summary and message as provider input", () => {
  9. expect(
  10. RespondToCoordinatorInputSchema.parse({
  11. summary: "进度更新",
  12. message: "已完成入口定位,正在验证异常路径。",
  13. }),
  14. ).toEqual({
  15. summary: "进度更新",
  16. message: "已完成入口定位,正在验证异常路径。",
  17. });
  18. for (const routingField of ["to", "agentId", "childSessionId", "parentSessionId"]) {
  19. expect(() =>
  20. RespondToCoordinatorInputSchema.parse({
  21. summary: "进度更新",
  22. message: "继续检查。",
  23. [routingField]: "model_supplied_route",
  24. }),
  25. ).toThrow();
  26. }
  27. });
  28. it("enforces summary and message content limits", () => {
  29. expect(() => RespondToCoordinatorInputSchema.parse({ summary: "", message: "x" })).toThrow();
  30. expect(
  31. RespondToCoordinatorInputSchema.parse({
  32. summary: "x",
  33. message: "x".repeat(RESPOND_TO_COORDINATOR_MAX_CONTENT_CHARS),
  34. }).message,
  35. ).toHaveLength(RESPOND_TO_COORDINATOR_MAX_CONTENT_CHARS);
  36. expect(() =>
  37. RespondToCoordinatorInputSchema.parse({
  38. summary: "x",
  39. message: "x".repeat(RESPOND_TO_COORDINATOR_MAX_CONTENT_CHARS + 1),
  40. }),
  41. ).toThrow();
  42. });
  43. it("rejects provider-private routing fields in runtime output", () => {
  44. expect(
  45. RespondToCoordinatorOutputSchema.parse({
  46. status: "success",
  47. responseId: "response_1",
  48. message: "Response queued for the coordinator.",
  49. }),
  50. ).toMatchObject({ status: "success", responseId: "response_1" });
  51. for (const routingField of ["agentId", "childSessionId", "parentSessionId", "to"]) {
  52. expect(() =>
  53. RespondToCoordinatorOutputSchema.parse({
  54. status: "success",
  55. responseId: "response_1",
  56. message: "Response queued for the coordinator.",
  57. [routingField]: "model_supplied_route",
  58. }),
  59. ).toThrow();
  60. }
  61. });
  62. });