codex-request-sanitizer.test.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { describe, expect, it } from "vitest";
  2. import { sanitizeCodexRequest } from "@/app/v1/_lib/codex/utils/request-sanitizer";
  3. describe("Codex 请求清洗 - instructions 透传", () => {
  4. it("应忽略 force_official,始终透传 instructions", async () => {
  5. const originalInstructions = "用户自定义 instructions(必须原样透传)";
  6. const input: Record<string, unknown> = {
  7. instructions: originalInstructions,
  8. max_tokens: 123,
  9. temperature: 0.7,
  10. };
  11. const output = await sanitizeCodexRequest(input, "gpt-5-codex", "force_official", 1, {
  12. isOfficialClient: false,
  13. });
  14. expect(output.instructions).toBe(originalInstructions);
  15. expect(output).not.toHaveProperty("_canRetryWithOfficialInstructions");
  16. expect(output).not.toHaveProperty("max_tokens");
  17. expect(output).not.toHaveProperty("temperature");
  18. expect(output.store).toBe(false);
  19. expect(output.parallel_tool_calls).toBe(true);
  20. });
  21. it("当客户端显式设置 parallel_tool_calls=false 时应保留(默认不强制覆写)", async () => {
  22. const input: Record<string, unknown> = {
  23. instructions: "abc",
  24. parallel_tool_calls: false,
  25. };
  26. const output = await sanitizeCodexRequest(input, "gpt-5-codex", "auto", 1, {
  27. isOfficialClient: false,
  28. });
  29. expect(output.parallel_tool_calls).toBe(false);
  30. expect(input.parallel_tool_calls).toBe(false);
  31. });
  32. it("auto 策略也不应写入私有重试标记", async () => {
  33. const originalInstructions = "abc";
  34. const input: Record<string, unknown> = { instructions: originalInstructions };
  35. const output = await sanitizeCodexRequest(input, "gpt-5-codex", "auto", 1, {
  36. isOfficialClient: false,
  37. });
  38. expect(output.instructions).toBe(originalInstructions);
  39. expect(output).not.toHaveProperty("_canRetryWithOfficialInstructions");
  40. });
  41. });