zcodeNetworkDebugStatus.test.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { describe, expect, it } from "vitest";
  2. import { zcodeTaskNetworkDebugStatusFromPayload } from "../src/zcode-network-debug-status.js";
  3. describe("zcodeTaskNetworkDebugStatusFromPayload", () => {
  4. it("projects model network status payloads with headers and without response data", () => {
  5. const event = zcodeTaskNetworkDebugStatusFromPayload({
  6. taskId: "task-1",
  7. traceId: "trace-1",
  8. inputId: "input-1",
  9. eventId: "event-1",
  10. payload: {
  11. type: "model_request_failed",
  12. requestId: "request-1",
  13. timestamp: "2026-06-10T00:00:00.000Z",
  14. model: {
  15. providerId: "openai",
  16. modelId: "model-test",
  17. },
  18. transport: "http",
  19. attempt: 2,
  20. maxAttempts: 3,
  21. statusCode: 429,
  22. message: "rate limited",
  23. responseData: { body: "should not be projected" },
  24. requestHeaders: {
  25. authorization: "[redacted]",
  26. },
  27. responseHeaders: {
  28. "retry-after": "1",
  29. },
  30. },
  31. });
  32. expect(event).toEqual(
  33. expect.objectContaining({
  34. type: "task_network_debug_status",
  35. taskId: "task-1",
  36. traceId: "trace-1",
  37. inputId: "input-1",
  38. eventKey: "event-1",
  39. statusType: "model_request_failed",
  40. requestId: "request-1",
  41. providerId: "openai",
  42. modelId: "model-test",
  43. transport: "http",
  44. attempt: 2,
  45. maxAttempts: 3,
  46. statusCode: 429,
  47. message: "rate limited",
  48. requestHeaders: {
  49. authorization: "[redacted]",
  50. },
  51. responseHeaders: {
  52. "retry-after": "1",
  53. },
  54. requestHeaderCount: 1,
  55. responseHeaderCount: 1,
  56. }),
  57. );
  58. expect(event).not.toHaveProperty("responseData");
  59. });
  60. it("ignores the admission-wait status types (workflow-adaptive-concurrency v3 决策 44)", () => {
  61. for (const type of ["model_request_queued", "model_request_admitted"]) {
  62. expect(
  63. zcodeTaskNetworkDebugStatusFromPayload({
  64. taskId: "task-1",
  65. traceId: "trace-1",
  66. payload: {
  67. type,
  68. requestId: "request-1",
  69. timestamp: "2026-09-08T00:00:00.000Z",
  70. model: { providerId: "prov", modelId: "alpha" },
  71. transport: "http",
  72. attempt: 1,
  73. maxAttempts: 0,
  74. queuedMs: 100,
  75. },
  76. }),
  77. ).toBeNull();
  78. }
  79. });
  80. });