import { describe, expect, it } from "vitest"; import { ModelRetryBudget, modelNetworkStatusEventJsonSchema } from "../src/model/index.js"; import { getCurrentModelInvocationContext, runWithModelInvocationContext, } from "../src/model/invocation-context.js"; // docs/dynamic-workflow/concurrency.md「Unbounded retries for workflow traffic」:重试预算档位是 runtime-only 字段; // 状态事件用 maxAttempts = 0 表示无上限,协议 schema 的下界因此是 0。 describe("ModelRetryBudget", () => { it("exposes default, unbounded and single-attempt budget tiers", () => { // 合入加速失败回退后新增单次预算;保留工作流无界预算,不能让旧枚举断言排斥新档位。 expect(ModelRetryBudget).toEqual({ Default: "default", Unbounded: "unbounded", SingleAttempt: "single-attempt", }); }); it("is a runtime-only request field and stays out of the model request JSON schema", async () => { const { modelTextRequestJsonSchema } = await import("../src/model/index.js"); const properties = (modelTextRequestJsonSchema as { properties: Record }) .properties; expect(properties).not.toHaveProperty("modelRetryBudget"); expect(properties).not.toHaveProperty("modelRequestSessionType"); }); it("allows maxAttempts = 0 (unbounded marker) in the network status schema", () => { const properties = ( modelNetworkStatusEventJsonSchema as { properties: Record } ).properties; expect(properties.maxAttempts?.minimum).toBe(0); // attempt 仍从 1 起:只有预算总数才有「无上限」这个哨兵。 expect(properties.attempt?.minimum).toBe(1); }); it("travels with the model invocation context", () => { const seen = runWithModelInvocationContext( { modelRetryBudget: ModelRetryBudget.Unbounded }, () => getCurrentModelInvocationContext()?.modelRetryBudget, ); expect(seen).toBe("unbounded"); expect(getCurrentModelInvocationContext()).toBeUndefined(); }); });