model-pattern-matcher.test.ts 1.1 KB

123456789101112131415161718192021222324
  1. import { describe, expect, it } from "vitest";
  2. import { matchesPattern } from "@/lib/model-pattern-matcher";
  3. import type { ProviderModelRedirectMatchType } from "@/types/provider";
  4. describe("matchesPattern", () => {
  5. it.each<[ProviderModelRedirectMatchType, string, string, boolean]>([
  6. ["exact", "claude-opus-4-1", "claude-opus-4-1", true],
  7. ["exact", "claude-opus-4-1", "claude-opus-4-2", false],
  8. ["prefix", "claude-opus", "claude-opus-4-1", true],
  9. ["prefix", "gpt", "claude-opus-4-1", false],
  10. ["suffix", "20251001", "claude-opus-4-1-20251001", true],
  11. ["suffix", "20251002", "claude-opus-4-1-20251001", false],
  12. ["contains", "opus", "claude-opus-4-1", true],
  13. ["contains", "sonnet", "claude-opus-4-1", false],
  14. ["regex", "^claude-(opus|sonnet)-4", "claude-opus-4-1", true],
  15. ["regex", "^gpt-", "claude-opus-4-1", false],
  16. ])("supports %s matching", (matchType, pattern, model, expected) => {
  17. expect(matchesPattern(model, matchType, pattern)).toBe(expected);
  18. });
  19. it("returns false for invalid regex patterns instead of throwing", () => {
  20. expect(matchesPattern("claude-opus-4-1", "regex", "[")).toBe(false);
  21. });
  22. });