provider-timeout-schemas.test.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { describe, expect, test } from "vitest";
  2. import { CreateProviderSchema, UpdateProviderSchema } from "@/lib/validation/schemas";
  3. describe("Provider timeout schemas", () => {
  4. test("CreateProviderSchema accepts 1 second streaming first-byte timeout and 0 as disabled", () => {
  5. const disabled = CreateProviderSchema.parse({
  6. name: "test-provider",
  7. url: "https://example.com",
  8. key: "sk-test",
  9. first_byte_timeout_streaming_ms: 0,
  10. });
  11. const enabled = CreateProviderSchema.parse({
  12. name: "test-provider",
  13. url: "https://example.com",
  14. key: "sk-test",
  15. first_byte_timeout_streaming_ms: 1000,
  16. streaming_idle_timeout_ms: 60000,
  17. request_timeout_non_streaming_ms: 60000,
  18. });
  19. expect(disabled.first_byte_timeout_streaming_ms).toBe(0);
  20. expect(enabled.first_byte_timeout_streaming_ms).toBe(1000);
  21. });
  22. test("UpdateProviderSchema rejects streaming first-byte timeout below 1 second", () => {
  23. expect(() =>
  24. UpdateProviderSchema.parse({
  25. first_byte_timeout_streaming_ms: 999,
  26. })
  27. ).toThrow("流式首字节超时不能少于1秒");
  28. });
  29. test("UpdateProviderSchema accepts 0 as disabled for streaming first-byte timeout", () => {
  30. const parsed = UpdateProviderSchema.parse({
  31. first_byte_timeout_streaming_ms: 0,
  32. });
  33. expect(parsed.first_byte_timeout_streaming_ms).toBe(0);
  34. });
  35. test("UpdateProviderSchema accepts 1800 second non-streaming timeout upper bound", () => {
  36. const parsed = UpdateProviderSchema.parse({
  37. request_timeout_non_streaming_ms: 1_800_000,
  38. });
  39. expect(parsed.request_timeout_non_streaming_ms).toBe(1_800_000);
  40. });
  41. });