model-retry-budget.test.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { describe, expect, it } from "vitest";
  2. import { ModelRetryBudget, modelNetworkStatusEventJsonSchema } from "../src/model/index.js";
  3. import {
  4. getCurrentModelInvocationContext,
  5. runWithModelInvocationContext,
  6. } from "../src/model/invocation-context.js";
  7. // docs/dynamic-workflow/concurrency.md「Unbounded retries for workflow traffic」:重试预算档位是 runtime-only 字段;
  8. // 状态事件用 maxAttempts = 0 表示无上限,协议 schema 的下界因此是 0。
  9. describe("ModelRetryBudget", () => {
  10. it("exposes default, unbounded and single-attempt budget tiers", () => {
  11. // 合入加速失败回退后新增单次预算;保留工作流无界预算,不能让旧枚举断言排斥新档位。
  12. expect(ModelRetryBudget).toEqual({
  13. Default: "default",
  14. Unbounded: "unbounded",
  15. SingleAttempt: "single-attempt",
  16. });
  17. });
  18. it("is a runtime-only request field and stays out of the model request JSON schema", async () => {
  19. const { modelTextRequestJsonSchema } = await import("../src/model/index.js");
  20. const properties = (modelTextRequestJsonSchema as { properties: Record<string, unknown> })
  21. .properties;
  22. expect(properties).not.toHaveProperty("modelRetryBudget");
  23. expect(properties).not.toHaveProperty("modelRequestSessionType");
  24. });
  25. it("allows maxAttempts = 0 (unbounded marker) in the network status schema", () => {
  26. const properties = (
  27. modelNetworkStatusEventJsonSchema as { properties: Record<string, { minimum?: number }> }
  28. ).properties;
  29. expect(properties.maxAttempts?.minimum).toBe(0);
  30. // attempt 仍从 1 起:只有预算总数才有「无上限」这个哨兵。
  31. expect(properties.attempt?.minimum).toBe(1);
  32. });
  33. it("travels with the model invocation context", () => {
  34. const seen = runWithModelInvocationContext(
  35. { modelRetryBudget: ModelRetryBudget.Unbounded },
  36. () => getCurrentModelInvocationContext()?.modelRetryBudget,
  37. );
  38. expect(seen).toBe("unbounded");
  39. expect(getCurrentModelInvocationContext()).toBeUndefined();
  40. });
  41. });