modelStateUpdateGuard.test.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { describe, expect, it } from "vitest";
  2. import { shouldApplyModelStateUpdateForTaskModel } from "../src/lib/modelStateUpdateGuard.js";
  3. describe("shouldApplyModelStateUpdateForTaskModel", () => {
  4. it("rejects session initialization updates for a different task model identity", () => {
  5. expect(
  6. shouldApplyModelStateUpdateForTaskModel({
  7. currentModelValue: "custom:default-deepseek:deepseek-v4-flash",
  8. incomingModelValue: "runtime-provider/deepseek-chat",
  9. reason: "session_initialized",
  10. }),
  11. ).toBe(false);
  12. });
  13. it("accepts equivalent custom and provider-qualified model identities", () => {
  14. expect(
  15. shouldApplyModelStateUpdateForTaskModel({
  16. currentModelValue: "custom:runtime-provider:deepseek-v4-flash",
  17. incomingModelValue: "runtime-provider/deepseek-v4-flash",
  18. reason: "session_initialized",
  19. }),
  20. ).toBe(true);
  21. });
  22. it("keeps explicit model changed events usable even when the current value is stale", () => {
  23. expect(
  24. shouldApplyModelStateUpdateForTaskModel({
  25. currentModelValue: "old-provider/old-model",
  26. incomingModelValue: "new-provider/new-model",
  27. reason: "model_changed",
  28. }),
  29. ).toBe(true);
  30. });
  31. it("treats an OpenRouter colon suffix as model identity instead of variant", () => {
  32. expect(
  33. shouldApplyModelStateUpdateForTaskModel({
  34. currentModelValue: "openrouter/nvidia/nemotron-3-ultra-550b-a55b:free",
  35. incomingModelValue: "openrouter/nvidia/nemotron-3-ultra-550b-a55b",
  36. reason: "session_initialized",
  37. }),
  38. ).toBe(false);
  39. });
  40. it("ignores only the reserved dollar variant when comparing model identity", () => {
  41. expect(
  42. shouldApplyModelStateUpdateForTaskModel({
  43. currentModelValue: "custom-openai/agent-model$fast",
  44. incomingModelValue: "custom-openai/agent-model$slow",
  45. reason: "session_initialized",
  46. }),
  47. ).toBe(true);
  48. });
  49. });