Merge PR #8929: fix(catalog): register plain Codex route for worker -wm SKUs (@STRML)

This commit is contained in:
can1357
2026-08-19 01:39:18 +02:00
2 changed files with 264 additions and 24 deletions
@@ -11,6 +11,7 @@ import { resolveProviderModels } from "@oh-my-pi/pi-catalog/model-manager";
import { getSupportedEfforts } from "@oh-my-pi/pi-catalog/model-thinking";
import { openaiCodexModelManagerOptions } from "@oh-my-pi/pi-catalog/provider-models/special";
import type { ModelSpec } from "@oh-my-pi/pi-catalog/types";
import { resolveProviderModelReference } from "@oh-my-pi/pi-coding-agent/config/model-resolver";
describe("Codex model discovery", () => {
it("marks discovered models for provider-native V2 compaction", async () => {
@@ -538,4 +539,149 @@ describe("Codex model discovery", () => {
await fs.rm(tempDir, { recursive: true, force: true });
}
});
it("registers a plain route when the backend advertises only the worker `-wm` slug", async () => {
const fetchFn: typeof fetch = Object.assign(
async () =>
new Response(
JSON.stringify({
models: [
{
slug: "gpt-5.6-luna-wm",
display_name: "GPT-5.6 Luna",
context_window: 272_000,
default_reasoning_level: "medium",
supported_reasoning_levels: ["low", "medium", "high"],
input_modalities: ["text", "image"],
supported_in_api: true,
},
],
}),
),
{ preconnect() {} },
);
const result = await fetchCodexModels({
accessToken: "test-token",
baseUrl: "https://codex.example/backend-api",
clientVersion: "0.99.0",
fetchFn,
});
// The authoritative `-wm` row stays surfaced verbatim…
const workerModel = result?.models.find(model => model.id === "gpt-5.6-luna-wm");
expect(workerModel).toBeDefined();
// …and the configured plain slug must also resolve to a real route.
const plainModel = result?.models.find(model => model.id === "gpt-5.6-luna");
expect(plainModel).toBeDefined();
expect(plainModel?.provider).toBe("openai-codex");
// Both rows are the same model: the worker variant shares the plain
// SKU's base metadata, so the 1M window floor applies to both.
expect(workerModel?.contextWindow).toBe(1_000_000);
expect(plainModel?.contextWindow).toBe(1_000_000);
});
it("keeps the plain route through authoritative discovery that advertises only the `-wm` slug", async () => {
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "pi-catalog-codex-luna-wm-"));
const fetchFn: typeof fetch = Object.assign(
async () =>
new Response(
JSON.stringify({
models: [
{
slug: "gpt-5.6-luna-wm",
display_name: "GPT-5.6 Luna",
default_reasoning_level: "medium",
supported_reasoning_levels: ["low", "medium", "high"],
input_modalities: ["text", "image"],
supported_in_api: true,
},
],
}),
),
{ preconnect() {} },
);
try {
const options = openaiCodexModelManagerOptions({
resolveAccounts: async () => [{ accessToken: "test-token" }],
fetch: fetchFn,
});
// No artificial static input: the bundled Codex catalog is the real
// gate that licenses the plain-route synthesis.
const result = await resolveProviderModels(
{ ...options, cacheDbPath: path.join(tempDir, "models.db") },
"online",
);
const ids = result.models.map(model => model.id);
expect(ids).toContain("gpt-5.6-luna");
expect(ids).toContain("gpt-5.6-luna-wm");
// Same engine the runtime uses: resolving the configured
// `openai-codex/gpt-5.6-luna` must bind to the plain route by exact
// id, not fall through to the `-wm` fuzzy match.
const resolved = resolveProviderModelReference("openai-codex", "gpt-5.6-luna", result.models);
expect(resolved?.id).toBe("gpt-5.6-luna");
expect(resolved?.provider).toBe("openai-codex");
// An explicitly configured worker slug still resolves verbatim.
const resolvedWm = resolveProviderModelReference("openai-codex", "gpt-5.6-luna-wm", result.models);
expect(resolvedWm?.id).toBe("gpt-5.6-luna-wm");
} finally {
await fs.rm(tempDir, { recursive: true, force: true });
}
});
it("keeps a `-wm` slug verbatim when it has no bundled plain counterpart", async () => {
const fetchFn: typeof fetch = Object.assign(
async () =>
new Response(
JSON.stringify({
models: [
{
slug: "gpt-9.9-mystery-wm",
display_name: "GPT-9.9 Mystery (worker)",
input_modalities: ["text"],
supported_in_api: true,
},
],
}),
),
{ preconnect() {} },
);
const result = await fetchCodexModels({
accessToken: "test-token",
baseUrl: "https://codex.example/backend-api",
clientVersion: "0.99.0",
fetchFn,
});
// No bundled `gpt-9.9-mystery` entry, so no phantom plain route is made up.
expect(result?.models.map(model => model.id)).toEqual(["gpt-9.9-mystery-wm"]);
});
it("leaves a non-worker slug untouched by the worker-mapping rule", async () => {
const fetchFn: typeof fetch = Object.assign(
async () =>
new Response(
JSON.stringify({
models: [
{
slug: "gpt-5.6-luna",
display_name: "GPT-5.6 Luna",
default_reasoning_level: "medium",
supported_reasoning_levels: ["low", "medium", "high"],
input_modalities: ["text", "image"],
supported_in_api: true,
},
],
}),
),
{ preconnect() {} },
);
const result = await fetchCodexModels({
accessToken: "test-token",
baseUrl: "https://codex.example/backend-api",
clientVersion: "0.99.0",
fetchFn,
});
expect(result?.models.map(model => model.id)).toEqual(["gpt-5.6-luna"]);
});
});