modelThoughtOption.test.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { describe, expect, it } from "vitest";
  2. import type { ModelSelectionView } from "@zcode/services";
  3. import { resolveModelThoughtOption } from "@/lib/modelThoughtOption.js";
  4. const registryView: ModelSelectionView = {
  5. revision: 3,
  6. providers: [
  7. {
  8. providerId: "provider-demo",
  9. config: {
  10. kind: "api",
  11. label: "Provider Demo",
  12. apiFormat: "anthropic-messages",
  13. baseURL: "https://example.test",
  14. apiKey: "secret",
  15. models: ["reasoning-model", "plain-model"],
  16. },
  17. models: [
  18. {
  19. modelId: "reasoning-model",
  20. config: {
  21. optionSpecs: {
  22. reasoningLevel: {
  23. values: ["low", "high", "max"],
  24. },
  25. maxOutputTokens: {
  26. max: 64_000,
  27. },
  28. },
  29. },
  30. },
  31. {
  32. modelId: "plain-model",
  33. config: {
  34. optionSpecs: {
  35. maxOutputTokens: {
  36. max: 64_000,
  37. },
  38. },
  39. },
  40. },
  41. ],
  42. },
  43. ],
  44. };
  45. describe("resolveModelThoughtOption", () => {
  46. it("uses Registry optionSpecs as the authoritative reasoning definition", () => {
  47. expect(
  48. resolveModelThoughtOption({
  49. modelSelectionView: registryView,
  50. providerId: "provider-demo",
  51. modelId: "reasoning-model",
  52. }),
  53. ).toEqual({
  54. id: "thought_level",
  55. name: "Thought Level",
  56. category: "thought_level",
  57. type: "select",
  58. // 候选档位来自 Registry,但缺失的用户选择不能被自动补成最高档。
  59. currentValue: "",
  60. options: [
  61. { value: "low", name: "low" },
  62. { value: "high", name: "high" },
  63. { value: "max", name: "max" },
  64. ],
  65. });
  66. });
  67. it.each([
  68. ["high", "high"],
  69. ["medium", ""],
  70. ])("resolves the explicit reasoning %s to %s without picking a replacement", (input, value) => {
  71. expect(
  72. resolveModelThoughtOption({
  73. modelSelectionView: registryView,
  74. providerId: "provider-demo",
  75. modelId: "reasoning-model",
  76. currentValue: input,
  77. })?.currentValue,
  78. ).toBe(value);
  79. });
  80. it("does not fall back to stale metadata or model-name hardcode when Registry is present", () => {
  81. expect(
  82. resolveModelThoughtOption({
  83. modelSelectionView: registryView,
  84. providerId: "provider-demo",
  85. modelId: "GLM-5.2",
  86. }),
  87. ).toBeNull();
  88. expect(
  89. resolveModelThoughtOption({
  90. modelSelectionView: registryView,
  91. providerId: "provider-demo",
  92. modelId: "plain-model",
  93. }),
  94. ).toBeNull();
  95. });
  96. it("returns null when the Registry model is missing", () => {
  97. expect(
  98. resolveModelThoughtOption({
  99. modelSelectionView: registryView,
  100. providerId: "provider-demo",
  101. modelId: "missing-model",
  102. }),
  103. ).toBeNull();
  104. });
  105. });