|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | +import { applyProviderConfigHints, buildCatalogEntries } from "../src/codex/catalog"; |
| 3 | +import type { OcxProviderConfig } from "../src/types"; |
| 4 | + |
| 5 | +function nativeTemplate(): Record<string, unknown> { |
| 6 | + return { |
| 7 | + slug: "gpt-5.5", |
| 8 | + display_name: "gpt-5.5", |
| 9 | + description: "Native GPT model", |
| 10 | + priority: 1, |
| 11 | + visibility: "list", |
| 12 | + base_instructions: "You are Codex, a coding agent based on GPT-5.", |
| 13 | + supported_reasoning_levels: [ |
| 14 | + { effort: "low", description: "native low" }, |
| 15 | + { effort: "medium", description: "native medium" }, |
| 16 | + { effort: "high", description: "native high" }, |
| 17 | + { effort: "xhigh", description: "native xhigh" }, |
| 18 | + ], |
| 19 | + }; |
| 20 | +} |
| 21 | + |
| 22 | +function provider(overrides: Partial<OcxProviderConfig> = {}): OcxProviderConfig { |
| 23 | + return { |
| 24 | + adapter: "openai-chat", |
| 25 | + baseUrl: "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1", |
| 26 | + apiKey: "sk-test", |
| 27 | + modelReasoningEfforts: { "qwen3.8-max": ["low", "medium", "xhigh"] }, |
| 28 | + ...overrides, |
| 29 | + }; |
| 30 | +} |
| 31 | + |
| 32 | +function advertisedLevels(entry: Record<string, unknown> | undefined): string[] { |
| 33 | + const rows = (entry?.supported_reasoning_levels ?? []) as { effort?: string }[]; |
| 34 | + return rows.map(level => level.effort).filter((effort): effort is string => typeof effort === "string"); |
| 35 | +} |
| 36 | + |
| 37 | +function hintedQwen(prov: OcxProviderConfig): Record<string, unknown> { |
| 38 | + const hinted = applyProviderConfigHints( |
| 39 | + "alibaba-token-plan-intl", |
| 40 | + prov, |
| 41 | + { id: "qwen3.8-max", provider: "alibaba-token-plan-intl" }, |
| 42 | + ); |
| 43 | + const entries = buildCatalogEntries(nativeTemplate(), [], [hinted]); |
| 44 | + return entries.find(e => e.slug === "alibaba-token-plan-intl/qwen3.8-max") ?? {}; |
| 45 | +} |
| 46 | + |
| 47 | +describe("#1870 preserveExactReasoningRungs", () => { |
| 48 | + test("provider-wide flag suppresses synthetic max/ultra rungs", () => { |
| 49 | + const entry = hintedQwen(provider({ preserveExactReasoningRungs: true })); |
| 50 | + expect(advertisedLevels(entry)).toEqual(["low", "medium", "xhigh"]); |
| 51 | + }); |
| 52 | + |
| 53 | + test("per-model flag scopes suppression to the named model", () => { |
| 54 | + const entry = hintedQwen(provider({ |
| 55 | + modelPreserveExactReasoningRungs: { "qwen3.8-max": true }, |
| 56 | + })); |
| 57 | + expect(advertisedLevels(entry)).toEqual(["low", "medium", "xhigh"]); |
| 58 | + }); |
| 59 | + |
| 60 | + test("synthetic max/ultra rungs remain advertised by default", () => { |
| 61 | + const entry = hintedQwen(provider()); |
| 62 | + expect(advertisedLevels(entry)).toEqual(["low", "medium", "xhigh", "max", "ultra"]); |
| 63 | + }); |
| 64 | + |
| 65 | + test("per-model false overrides a provider-wide true", () => { |
| 66 | + const entry = hintedQwen(provider({ |
| 67 | + preserveExactReasoningRungs: true, |
| 68 | + modelPreserveExactReasoningRungs: { "qwen3.8-max": false }, |
| 69 | + })); |
| 70 | + expect(advertisedLevels(entry)).toEqual(["low", "medium", "xhigh", "max", "ultra"]); |
| 71 | + }); |
| 72 | + |
| 73 | + test("re-hinting a cached model clears a stale exact-rung flag", () => { |
| 74 | + const flagged = applyProviderConfigHints( |
| 75 | + "alibaba-token-plan-intl", |
| 76 | + provider({ preserveExactReasoningRungs: true }), |
| 77 | + { id: "qwen3.8-max", provider: "alibaba-token-plan-intl" }, |
| 78 | + ); |
| 79 | + expect(flagged.preserveExactReasoningRungs).toBe(true); |
| 80 | + |
| 81 | + // A cached model produced by an earlier hint pass still carries the flag; |
| 82 | + // re-hinting with a config that resolves to false must clear it. |
| 83 | + const cleared = applyProviderConfigHints( |
| 84 | + "alibaba-token-plan-intl", |
| 85 | + provider(), |
| 86 | + flagged, |
| 87 | + ); |
| 88 | + expect(cleared.preserveExactReasoningRungs).toBeUndefined(); |
| 89 | + const entries = buildCatalogEntries(nativeTemplate(), [], [cleared]); |
| 90 | + const entry = entries.find(e => e.slug === "alibaba-token-plan-intl/qwen3.8-max"); |
| 91 | + expect(advertisedLevels(entry)).toEqual(["low", "medium", "xhigh", "max", "ultra"]); |
| 92 | + }); |
| 93 | + |
| 94 | + test("empty or none reasoning ladders never grow synthetic rungs regardless of flag", () => { |
| 95 | + const entryEmpty = hintedQwen(provider({ |
| 96 | + modelReasoningEfforts: { "qwen3.8-max": [] }, |
| 97 | + preserveExactReasoningRungs: false, |
| 98 | + })); |
| 99 | + expect(advertisedLevels(entryEmpty)).toEqual([]); |
| 100 | + |
| 101 | + const entryNone = hintedQwen(provider({ |
| 102 | + modelReasoningEfforts: { "qwen3.8-max": ["none"] }, |
| 103 | + preserveExactReasoningRungs: false, |
| 104 | + })); |
| 105 | + expect(advertisedLevels(entryNone)).toEqual(["none"]); |
| 106 | + }); |
| 107 | + |
| 108 | + test("exact-rung flag preserves custom default reasoning effort within the ladder", () => { |
| 109 | + const entry = hintedQwen(provider({ |
| 110 | + preserveExactReasoningRungs: true, |
| 111 | + modelDefaultReasoningEfforts: { "qwen3.8-max": "xhigh" }, |
| 112 | + })); |
| 113 | + expect(advertisedLevels(entry)).toEqual(["low", "medium", "xhigh"]); |
| 114 | + expect(entry.default_reasoning_level).toBe("xhigh"); |
| 115 | + }); |
| 116 | +}); |
0 commit comments