modelSelection.test.ts 1008 B

12345678910111213141516171819202122232425262728293031
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. formatModelPickerValue,
  4. modelSelectionSchema,
  5. parseModelPickerValue,
  6. } from "../src/model-selection.js";
  7. describe("ModelSelection value", () => {
  8. it("projects provider, slash-containing model and reasoning into a picker value", () => {
  9. const selection = {
  10. providerId: "openrouter",
  11. modelId: "vendor/model:free",
  12. options: { reasoningLevel: "high" },
  13. };
  14. expect(parseModelPickerValue(formatModelPickerValue(selection))).toEqual(selection);
  15. });
  16. it("rejects request-only maxOutputTokens in a selection", () => {
  17. expect(
  18. modelSelectionSchema.safeParse({
  19. providerId: "openrouter",
  20. modelId: "vendor/model:free",
  21. options: { maxOutputTokens: 16_384, reasoningLevel: "high" },
  22. }).success,
  23. ).toBe(false);
  24. });
  25. it("rejects values without an explicit provider", () => {
  26. expect(() => parseModelPickerValue("model-only")).toThrow("模型选择缺少 Provider");
  27. });
  28. });