|
8 | 8 | pickComboTarget, |
9 | 9 | targetKey, |
10 | 10 | } from "../../src/combos"; |
11 | | -import { comboFailureCooldownScope, comboFailureDecision } from "../../src/combos/failover"; |
| 11 | +import { codexAccountModelRefusalHardStopCode, comboFailureCooldownScope, comboFailureDecision } from "../../src/combos/failover"; |
12 | 12 | import { adapterFailureFromMessage, inferHttpStatusFromAdapterMessage } from "../../src/lib/errors"; |
13 | 13 | import type { OcxConfig } from "../../src/types"; |
14 | 14 |
|
@@ -172,6 +172,34 @@ describe("combo failure hop/stop verdicts", () => { |
172 | 172 | response: { error: null } }))).toBe("hop"); |
173 | 173 | }); |
174 | 174 |
|
| 175 | + test("nested HTTP refusal selects one carrier without borrowing body metadata", () => { |
| 176 | + const refusal = "The 'gpt-6-astra' model is not supported when using Codex with a ChatGPT account."; |
| 177 | + for (const response of [{ detail: refusal }, { error: { message: refusal } }]) { |
| 178 | + const body = JSON.stringify({ response }); |
| 179 | + expect(comboFailureDecision(400, body)).toBe("hop"); |
| 180 | + expect(comboFailureDecision(400, `Provider error 400: ${body}`)).toBe("hop"); |
| 181 | + expect(comboFailureDecision(400, body, { codexModelRefusal: "other" })).toBe("stop"); |
| 182 | + expect(comboFailureDecision(400, body, { code: "origin_rejected" })).toBe("stop"); |
| 183 | + expect(comboFailureDecision(400, body, { code: "upstream_no_response" })).toBe("stop"); |
| 184 | + expect(comboFailureDecision(400, body, { code: "cyber_policy" })).toBe("stop"); |
| 185 | + expect(comboFailureDecision(499, body)).toBe("stop"); |
| 186 | + expect(comboFailureDecision(422, body)).toBe("stop"); |
| 187 | + expect(comboFailureDecision(400, body.slice(0, -1))).toBe("stop"); |
| 188 | + expect(comboFailureDecision(400, JSON.stringify({ response, padding: "x".repeat(16_384) }))).toBe("stop"); |
| 189 | + } |
| 190 | + expect(comboFailureDecision(400, JSON.stringify({ response: { error: { |
| 191 | + code: "upstream_no_response", message: refusal, |
| 192 | + } } }), { code: "unsupported_model", codexModelRefusal: "other" })).toBe("hop"); |
| 193 | + for (const body of [ |
| 194 | + { detail: null, response: { detail: refusal } }, |
| 195 | + { detail: "bad input", response: { detail: refusal } }, |
| 196 | + { error: null, response: { error: { message: refusal } } }, |
| 197 | + { error: { message: "bad input" }, response: { error: { message: refusal } } }, |
| 198 | + { response: { error: { message: "bad input" } }, codexModelRefusal: "refusal" }, |
| 199 | + { response: { error: { message: "bad input" }, codexModelRefusal: "refusal" } }, |
| 200 | + ]) expect(comboFailureDecision(400, JSON.stringify(body))).toBe("stop"); |
| 201 | + }); |
| 202 | + |
175 | 203 | test("402 and 425 hop instead of ending the chain", () => { |
176 | 204 | expect(comboFailureDecision(402, "payment required")).toBe("hop"); |
177 | 205 | expect(comboFailureDecision(425, "too early")).toBe("hop"); |
@@ -572,3 +600,31 @@ describe("response_format capability refusal, second gateway", () => { |
572 | 600 | } |
573 | 601 | }); |
574 | 602 | }); |
| 603 | + |
| 604 | +describe("HTTP hard-code evidence excludes diagnostic types", () => { |
| 605 | + test("code/type matrix inspects dedicated code fields only at either level", () => { |
| 606 | + const codes: Array<[unknown, string | undefined]> = [ |
| 607 | + ["cyber_policy", "cyber_policy"], ["upstream_no_response", "upstream_no_response"], |
| 608 | + ["origin-rejected", "origin_rejected"], ["unsupported_model", undefined], ["unknown_code", undefined], |
| 609 | + ["", undefined], [" ", undefined], [undefined, undefined], [null, undefined], [17, undefined], [{}, undefined], |
| 610 | + ]; |
| 611 | + for (const nested of [false, true]) { |
| 612 | + for (const [code, expected] of codes) { |
| 613 | + for (const type of ["cyber_policy", "upstream_no_response", "upstream_reset_replay_refused", "origin_rejected", "invalid_request_error", null, undefined]) { |
| 614 | + const record = { error: { code, type, message: "fixture failure" } }; |
| 615 | + const body = JSON.stringify(nested ? { response: record } : record); |
| 616 | + expect(codexAccountModelRefusalHardStopCode(400, body)).toBe(expected); |
| 617 | + } |
| 618 | + } |
| 619 | + } |
| 620 | + }); |
| 621 | + |
| 622 | + test("a genuine code in another record still wins over a nonhard code and diagnostic type", () => { |
| 623 | + const diagnostic = { error: { code: "unsupported_model", type: "cyber_policy", message: "fixture failure" } }; |
| 624 | + const hard = { code: "upstream_no_response" }; |
| 625 | + for (const body of [{ ...diagnostic, response: hard }, { ...hard, response: diagnostic }]) { |
| 626 | + expect(codexAccountModelRefusalHardStopCode(400, JSON.stringify(body))).toBe("upstream_no_response"); |
| 627 | + expect(comboFailureDecision(400, JSON.stringify(body))).toBe("stop"); |
| 628 | + } |
| 629 | + }); |
| 630 | +}); |
0 commit comments