workflow-settings.test.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. AmendWorkflowInputJsonSchema,
  4. AmendWorkflowInputSchema,
  5. CreateWorkflowInputJsonSchema,
  6. CreateWorkflowInputSchema,
  7. parseWorkflowSettingsAdjustment,
  8. } from "../src/index.js";
  9. // docs/dynamic-workflow/launch.md「Adjusting the settings in the window」
  10. describe("adjustable_settings on the workflow tools' input", () => {
  11. const block = { subagent_model: true, concurrency_ceiling: 13 };
  12. it("is accepted by both runtime schemas and strict about its own keys", () => {
  13. expect(
  14. CreateWorkflowInputSchema.safeParse({ script: "x", adjustable_settings: block }).success,
  15. ).toBe(true);
  16. expect(
  17. AmendWorkflowInputSchema.safeParse({ run_id: "r", adjustable_settings: block }).success,
  18. ).toBe(true);
  19. expect(
  20. CreateWorkflowInputSchema.safeParse({
  21. script: "x",
  22. adjustable_settings: { ...block, extra: 1 },
  23. }).success,
  24. ).toBe(false);
  25. });
  26. it("is never offered to the model", () => {
  27. const createProps = (CreateWorkflowInputJsonSchema as { properties?: object }).properties ?? {};
  28. const amendProps = (AmendWorkflowInputJsonSchema as { properties?: object }).properties ?? {};
  29. expect(createProps).not.toHaveProperty("adjustable_settings");
  30. expect(amendProps).not.toHaveProperty("adjustable_settings");
  31. });
  32. });
  33. describe("parseWorkflowSettingsAdjustment", () => {
  34. it("keeps the two known fields in the tool's tri-state", () => {
  35. expect(
  36. parseWorkflowSettingsAdjustment({ subagent_model: "a/b$high", max_concurrency: 4 }),
  37. ).toEqual({
  38. subagent_model: "a/b$high",
  39. max_concurrency: 4,
  40. });
  41. expect(
  42. parseWorkflowSettingsAdjustment({ subagent_model: null, max_concurrency: null }),
  43. ).toEqual({
  44. subagent_model: null,
  45. max_concurrency: null,
  46. });
  47. });
  48. it("drops unknown keys, and answers nothing when no known key is left", () => {
  49. expect(parseWorkflowSettingsAdjustment({ max_concurrency: 2, color: "red" })).toEqual({
  50. max_concurrency: 2,
  51. });
  52. expect(parseWorkflowSettingsAdjustment({ color: "red" })).toBeUndefined();
  53. expect(parseWorkflowSettingsAdjustment(undefined)).toBeUndefined();
  54. });
  55. it("has no upper limit on the bound: the default parallelism is a starting point, not a cap", () => {
  56. expect(parseWorkflowSettingsAdjustment({ max_concurrency: 50_000 })).toEqual({
  57. max_concurrency: 50_000,
  58. });
  59. });
  60. it("rejects a malformed value as a whole", () => {
  61. expect(parseWorkflowSettingsAdjustment({ max_concurrency: 0 })).toBeUndefined();
  62. expect(parseWorkflowSettingsAdjustment({ subagent_model: " " })).toBeUndefined();
  63. });
  64. });
  65. // docs/dynamic-workflow/launch.md「Models the script names」
  66. describe("model_bindings on the workflow tools' input (never in the window's answer)", () => {
  67. const bindings = { "GLM-5.3-Flash": "zhipu/GLM-5.3-Flash", " spaced ": "acme/gpt-5" };
  68. it("is accepted by both runtime schemas, keys kept verbatim, and never offered to the model", () => {
  69. const create = CreateWorkflowInputSchema.safeParse({ script: "x", model_bindings: bindings });
  70. expect(create.success).toBe(true);
  71. expect(create.data?.model_bindings).toEqual(bindings);
  72. expect(
  73. AmendWorkflowInputSchema.safeParse({ run_id: "r", model_bindings: bindings }).success,
  74. ).toBe(true);
  75. expect(JSON.stringify(CreateWorkflowInputJsonSchema)).not.toContain("model_bindings");
  76. expect(JSON.stringify(AmendWorkflowInputJsonSchema)).not.toContain("model_bindings");
  77. });
  78. it("is bounded: empty names, blank models and oversized tables are rejected", () => {
  79. expect(
  80. CreateWorkflowInputSchema.safeParse({ script: "x", model_bindings: { "": "a/b" } }).success,
  81. ).toBe(false);
  82. expect(
  83. CreateWorkflowInputSchema.safeParse({ script: "x", model_bindings: { a: " " } }).success,
  84. ).toBe(false);
  85. const huge = Object.fromEntries(Array.from({ length: 65 }, (_, index) => [`m${index}`, "a/b"]));
  86. expect(CreateWorkflowInputSchema.safeParse({ script: "x", model_bindings: huge }).success).toBe(
  87. false,
  88. );
  89. });
  90. it("an answer cannot carry model_bindings: the window never offers them, so the key is dropped", () => {
  91. expect(
  92. parseWorkflowSettingsAdjustment({ model_bindings: { a: "zhipu/GLM-5.3" } }),
  93. ).toBeUndefined();
  94. expect(
  95. parseWorkflowSettingsAdjustment({
  96. max_concurrency: 3,
  97. model_bindings: { a: "zhipu/GLM-5.3" },
  98. }),
  99. ).toEqual({ max_concurrency: 3 });
  100. });
  101. });