model-execution-key-id.test.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { describe, expect, it } from "vitest";
  2. import { zcodeSessionSendParamsSchema } from "@zcode/shared";
  3. import { createModelExecutionContext } from "../src/zcode-protocol/model-execution.js";
  4. describe("请求期 Key ID 执行上下文", () => {
  5. it("协议与冻结投影保留真实 ID,不将其加入模型 Header", async () => {
  6. const requestAuth = { apiKey: "pat", apiKeyId: "real-key-id", accountScope: "a".repeat(64) };
  7. const execution = createModelExecutionContext(
  8. zcodeSessionSendParamsSchema.shape.modelExecution
  9. .unwrap()
  10. .parse({ selectionScope: "execution", requestAuth }),
  11. );
  12. const value = await execution.requestDependencies?.requestAuth?.source?.resolve({
  13. attempt: 1,
  14. providerId: "account:bigmodel-off-peak",
  15. modelId: "glm",
  16. });
  17. expect(value).toEqual(requestAuth);
  18. expect(Object.isFrozen(value)).toBe(true);
  19. });
  20. it("原样透传 selectionFallback 声明,包括发起方声明的退回目标", () => {
  21. // 退回目标必须完整到达 core:冷恢复竞态下 runtime 可能没有常驻选择,这是唯一的退回依据。
  22. const selectionFallback = {
  23. providerId: "account:bigmodel-highspeed-card",
  24. rules: [
  25. { reason: "highspeed_card_expired" as const, providerErrorCode: "3402" },
  26. { reason: "highspeed_request_failed" as const },
  27. ],
  28. target: {
  29. providerId: "account:bigmodel-team-coding-plan",
  30. modelId: "GLM-5.3",
  31. options: { reasoningLevel: "low" },
  32. },
  33. };
  34. const execution = createModelExecutionContext(
  35. zcodeSessionSendParamsSchema.shape.modelExecution
  36. .unwrap()
  37. .parse({ selectionScope: "execution", selectionFallback }),
  38. );
  39. expect(execution.selectionFallback).toEqual(selectionFallback);
  40. });
  41. });