-
Notifications
You must be signed in to change notification settings - Fork 34
test: property-check the unsupported-model fallback invariants #574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import * as fc from "fast-check"; | ||
| import { | ||
| DEFAULT_UNSUPPORTED_CODEX_FALLBACK_CHAIN, | ||
| resolveUnsupportedCodexFallbackModel, | ||
| } from "../../lib/request/fetch-helpers.js"; | ||
|
|
||
| // The canonical model names the default fallback chain knows about, plus the | ||
| // reasoning-effort suffixes and provider prefixes the canonicalizer strips. | ||
| const CHAIN_MODELS = Object.keys(DEFAULT_UNSUPPORTED_CODEX_FALLBACK_CHAIN); | ||
| const EFFORT_SUFFIXES = ["", "-none", "-minimal", "-low", "-medium", "-high", "-xhigh"]; | ||
| const PREFIXES = ["", "openai/", "models/"]; | ||
|
|
||
| const arbChainModel = fc.constantFrom(...CHAIN_MODELS); | ||
|
|
||
| // A spelled variant of a chain model that must canonicalize back to it: | ||
| // optional provider prefix, optional effort suffix, arbitrary casing. | ||
| const arbSpelledModel = fc | ||
| .tuple( | ||
| arbChainModel, | ||
| fc.constantFrom(...PREFIXES), | ||
| fc.constantFrom(...EFFORT_SUFFIXES), | ||
| fc.boolean(), | ||
| ) | ||
| .map(([model, prefix, suffix, upper]) => ({ | ||
| canonical: model, | ||
| spelled: upper | ||
| ? `${prefix}${model}${suffix}`.toUpperCase() | ||
| : `${prefix}${model}${suffix}`, | ||
| })); | ||
|
|
||
| const UNSUPPORTED_BODY = { | ||
| error: { | ||
| message: | ||
| "The requested model is not supported when using Codex with a ChatGPT account.", | ||
| }, | ||
| }; | ||
|
|
||
| function canonicalChainTargets(model: string): string[] { | ||
| return DEFAULT_UNSUPPORTED_CODEX_FALLBACK_CHAIN[model] ?? []; | ||
| } | ||
|
|
||
| describe("resolveUnsupportedCodexFallbackModel properties", () => { | ||
| it("never falls back when the feature toggle is off", () => { | ||
| fc.assert( | ||
| fc.property(arbSpelledModel, ({ spelled }) => { | ||
| expect( | ||
| resolveUnsupportedCodexFallbackModel({ | ||
| requestedModel: spelled, | ||
| errorBody: UNSUPPORTED_BODY, | ||
| fallbackOnUnsupportedCodexModel: false, | ||
| fallbackToGpt52OnUnsupportedGpt53: true, | ||
| }), | ||
| ).toBeUndefined(); | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it("never falls back when the error body is not an unsupported-model error", () => { | ||
| fc.assert( | ||
| fc.property( | ||
| arbSpelledModel, | ||
| fc.oneof( | ||
| fc.constant(null), | ||
| fc.constant("plain text"), | ||
| fc.record({ error: fc.record({ message: fc.constant("rate limited") }) }), | ||
| ), | ||
| ({ spelled }, errorBody) => { | ||
| expect( | ||
| resolveUnsupportedCodexFallbackModel({ | ||
| requestedModel: spelled, | ||
| errorBody, | ||
| fallbackOnUnsupportedCodexModel: true, | ||
| fallbackToGpt52OnUnsupportedGpt53: true, | ||
| }), | ||
| ).toBeUndefined(); | ||
| }, | ||
| ), | ||
| ); | ||
| }); | ||
|
|
||
| it("only ever returns a chain member that is neither current nor attempted", () => { | ||
| fc.assert( | ||
| fc.property( | ||
| arbSpelledModel, | ||
| fc.uniqueArray(arbChainModel, { maxLength: 6 }), | ||
| fc.boolean(), | ||
| ({ canonical, spelled }, attemptedModels, legacyEdge) => { | ||
| const result = resolveUnsupportedCodexFallbackModel({ | ||
| requestedModel: spelled, | ||
| errorBody: UNSUPPORTED_BODY, | ||
| attemptedModels, | ||
| fallbackOnUnsupportedCodexModel: true, | ||
| fallbackToGpt52OnUnsupportedGpt53: legacyEdge, | ||
| }); | ||
|
|
||
| if (result === undefined) return; | ||
| // Any spelling of the requested model resolves through the same | ||
| // canonical chain entry. | ||
| expect(canonicalChainTargets(canonical)).toContain(result); | ||
| expect(result).not.toBe(canonical); | ||
| expect(attemptedModels).not.toContain(result); | ||
| if (!legacyEdge && canonical === "gpt-5.3-codex") { | ||
| expect(result).not.toBe("gpt-5.2-codex"); | ||
| } | ||
| }, | ||
| ), | ||
| ); | ||
| }); | ||
|
|
||
| it("returns the first chain target when nothing was attempted", () => { | ||
| fc.assert( | ||
| fc.property(arbSpelledModel, ({ canonical, spelled }) => { | ||
| const result = resolveUnsupportedCodexFallbackModel({ | ||
| requestedModel: spelled, | ||
| errorBody: UNSUPPORTED_BODY, | ||
| fallbackOnUnsupportedCodexModel: true, | ||
| fallbackToGpt52OnUnsupportedGpt53: true, | ||
| }); | ||
|
|
||
| const [firstTarget] = canonicalChainTargets(canonical); | ||
| expect(result).toBe(firstTarget); | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it("returns undefined once every chain target has been attempted", () => { | ||
| fc.assert( | ||
| fc.property(arbSpelledModel, ({ canonical, spelled }) => { | ||
| expect( | ||
| resolveUnsupportedCodexFallbackModel({ | ||
| requestedModel: spelled, | ||
| errorBody: UNSUPPORTED_BODY, | ||
| attemptedModels: canonicalChainTargets(canonical), | ||
| fallbackOnUnsupportedCodexModel: true, | ||
| fallbackToGpt52OnUnsupportedGpt53: true, | ||
| }), | ||
| ).toBeUndefined(); | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it("treats attempted-model spellings the same as canonical names", () => { | ||
| fc.assert( | ||
| fc.property( | ||
| arbSpelledModel, | ||
| fc.constantFrom(...PREFIXES), | ||
| fc.constantFrom(...EFFORT_SUFFIXES), | ||
| ({ canonical, spelled }, prefix, suffix) => { | ||
| const targets = canonicalChainTargets(canonical); | ||
| const [firstTarget] = targets; | ||
| if (!firstTarget) return; | ||
| // Attempting the first target under any spelling skips it. | ||
| const result = resolveUnsupportedCodexFallbackModel({ | ||
| requestedModel: spelled, | ||
| errorBody: UNSUPPORTED_BODY, | ||
| attemptedModels: [`${prefix}${firstTarget}${suffix}`], | ||
| fallbackOnUnsupportedCodexModel: true, | ||
| fallbackToGpt52OnUnsupportedGpt53: true, | ||
| }); | ||
| expect(result).not.toBe(firstTarget); | ||
| if (result !== undefined) { | ||
| expect(targets).toContain(result); | ||
| } | ||
| }, | ||
| ), | ||
| ); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.