From 093c4efd67385eba0de45789c734aeeceb254a73 Mon Sep 17 00:00:00 2001 From: t Date: Sat, 5 Sep 2026 12:10:20 +0900 Subject: [PATCH 1/3] refactor(combos): isolate combo identifier helpers (split S11 L1/5) --- src/combos/identifiers.ts | 90 ++++++++++++++++++++++++++++++++++++ src/combos/types.ts | 96 ++------------------------------------- 2 files changed, 93 insertions(+), 93 deletions(-) create mode 100644 src/combos/identifiers.ts diff --git a/src/combos/identifiers.ts b/src/combos/identifiers.ts new file mode 100644 index 0000000000..118eb4291d --- /dev/null +++ b/src/combos/identifiers.ts @@ -0,0 +1,90 @@ +import { SUPPORTED_NATIVE_OPENAI_SLUGS } from "../codex/catalog/native-models"; +import type { OcxComboConfig, OcxComboTarget, OcxConfig } from "../types"; + +export const COMBO_NAMESPACE = "combo"; + +export function preservesPhysicalComboProvider( + config: Pick, +): boolean { + return Object.hasOwn(config.providers, COMBO_NAMESPACE) + && Object.keys(config.combos ?? {}).length === 0; +} + +const COMBO_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/; + +/** True only for an explicitly opted-in bare native-family alias. */ +export function isNativeAliasCombo( + combo: { alias?: string | null; nativeAlias?: boolean }, +): boolean { + const alias = typeof combo.alias === "string" ? combo.alias.trim() : ""; + return combo.nativeAlias === true + && SUPPORTED_NATIVE_OPENAI_SLUGS.has(alias); +} + +export function targetKey(target: Pick): string { + return `${target.provider}/${target.model}`; +} + +export function parseComboModelId(modelId: string): string | null { + const slash = modelId.indexOf("/"); + if (slash <= 0 || modelId.slice(0, slash) !== COMBO_NAMESPACE) return null; + const id = modelId.slice(slash + 1); + return id.length > 0 ? id : null; +} + +export function comboModelId(id: string): string { + return `${COMBO_NAMESPACE}/${id}`; +} + +/** Public model id clients request: the alias when set, else the default `combo/`. */ +export function comboPublicModelId(id: string, combo: { alias?: string | null }): string { + const alias = typeof combo.alias === "string" ? combo.alias.trim() : ""; + return alias || comboModelId(id); +} + +/** + * Persisted selector that hides a combo from discovery. Native aliases keep the canonical + * `combo/` selector because their bare public id remains the native OpenAI disable key. + */ +export function comboDisabledModelId( + id: string, + combo: { alias?: string | null; nativeAlias?: boolean }, +): string { + return isNativeAliasCombo(combo) ? comboModelId(id) : comboPublicModelId(id, combo); +} + +/** Every persisted selector that can refer to this combo in `disabledModels`. */ +export function comboDisabledModelSelectors( + id: string, + combo: { alias?: string | null; nativeAlias?: boolean }, +): string[] { + const canonical = comboModelId(id); + const preferred = comboDisabledModelId(id, combo); + return preferred === canonical ? [canonical] : [canonical, preferred]; +} + +/** + * Resolve a client-requested model id to a combo config key. The canonical `combo/` + * form wins first (back-compat); otherwise an exact alias match across configured combos. + */ +export function resolveComboId( + config: { combos?: Record }, + modelId: string, +): string | null { + const direct = parseComboModelId(modelId); + if (direct) return direct; + const combos = config.combos; + if (!combos) return null; + for (const [id, raw] of Object.entries(combos)) { + if (!raw || typeof raw !== "object") continue; + const alias = typeof raw.alias === "string" ? raw.alias.trim() : ""; + if (alias && alias === modelId) return id; + } + return null; +} + + +export function isValidComboId(id: string): boolean { + return COMBO_ID_PATTERN.test(id); +} + diff --git a/src/combos/types.ts b/src/combos/types.ts index b3dec16d09..ef9f3802a6 100644 --- a/src/combos/types.ts +++ b/src/combos/types.ts @@ -1,25 +1,10 @@ import { isCodexReasoningEffort } from "../reasoning-effort"; import { SUPPORTED_NATIVE_OPENAI_SLUGS } from "../codex/catalog/native-models"; -import type { - OcxComboConfig, - OcxComboDefaultEffort, - OcxComboReasoningEffortMode, - OcxComboStrategy, - OcxComboTarget, - OcxConfig, - OcxProviderConfig, -} from "../types"; +import type { OcxComboConfig, OcxComboDefaultEffort, OcxComboReasoningEffortMode, OcxComboStrategy, OcxComboTarget, OcxProviderConfig } from "../types"; +import { COMBO_NAMESPACE, isValidComboId, targetKey } from "./identifiers"; -export const COMBO_NAMESPACE = "combo"; +export { COMBO_NAMESPACE, preservesPhysicalComboProvider, isNativeAliasCombo, targetKey, parseComboModelId, comboModelId, comboPublicModelId, comboDisabledModelId, comboDisabledModelSelectors, resolveComboId, isValidComboId } from "./identifiers"; -export function preservesPhysicalComboProvider( - config: Pick, -): boolean { - return Object.hasOwn(config.providers, COMBO_NAMESPACE) - && Object.keys(config.combos ?? {}).length === 0; -} - -const COMBO_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/; /** * Public alias shape: one optional "/" segment, each segment id-shaped. Bare aliases * (no "/") are the masquerade case — the combo answers to a mandated model id with no @@ -51,77 +36,6 @@ export interface NormalizedComboConfig { targets: Array>; } -/** True only for an explicitly opted-in bare native-family alias. */ -export function isNativeAliasCombo( - combo: { alias?: string | null; nativeAlias?: boolean }, -): boolean { - const alias = typeof combo.alias === "string" ? combo.alias.trim() : ""; - return combo.nativeAlias === true - && SUPPORTED_NATIVE_OPENAI_SLUGS.has(alias); -} - -export function targetKey(target: Pick): string { - return `${target.provider}/${target.model}`; -} - -export function parseComboModelId(modelId: string): string | null { - const slash = modelId.indexOf("/"); - if (slash <= 0 || modelId.slice(0, slash) !== COMBO_NAMESPACE) return null; - const id = modelId.slice(slash + 1); - return id.length > 0 ? id : null; -} - -export function comboModelId(id: string): string { - return `${COMBO_NAMESPACE}/${id}`; -} - -/** Public model id clients request: the alias when set, else the default `combo/`. */ -export function comboPublicModelId(id: string, combo: { alias?: string | null }): string { - const alias = typeof combo.alias === "string" ? combo.alias.trim() : ""; - return alias || comboModelId(id); -} - -/** - * Persisted selector that hides a combo from discovery. Native aliases keep the canonical - * `combo/` selector because their bare public id remains the native OpenAI disable key. - */ -export function comboDisabledModelId( - id: string, - combo: { alias?: string | null; nativeAlias?: boolean }, -): string { - return isNativeAliasCombo(combo) ? comboModelId(id) : comboPublicModelId(id, combo); -} - -/** Every persisted selector that can refer to this combo in `disabledModels`. */ -export function comboDisabledModelSelectors( - id: string, - combo: { alias?: string | null; nativeAlias?: boolean }, -): string[] { - const canonical = comboModelId(id); - const preferred = comboDisabledModelId(id, combo); - return preferred === canonical ? [canonical] : [canonical, preferred]; -} - -/** - * Resolve a client-requested model id to a combo config key. The canonical `combo/` - * form wins first (back-compat); otherwise an exact alias match across configured combos. - */ -export function resolveComboId( - config: { combos?: Record }, - modelId: string, -): string | null { - const direct = parseComboModelId(modelId); - if (direct) return direct; - const combos = config.combos; - if (!combos) return null; - for (const [id, raw] of Object.entries(combos)) { - if (!raw || typeof raw !== "object") continue; - const alias = typeof raw.alias === "string" ? raw.alias.trim() : ""; - if (alias && alias === modelId) return id; - } - return null; -} - /** * Cross-combo alias checks that need the full combos map (uniqueness). Kept separate * from `comboConfigIssues` so config-file validation and the management API share it. @@ -393,10 +307,6 @@ export function comboDefaultEffort( : null; } -export function isValidComboId(id: string): boolean { - return COMBO_ID_PATTERN.test(id); -} - export function listComboIds(config: { combos?: Record }): string[] { return Object.keys(config.combos ?? {}).sort((a, b) => a.localeCompare(b)); } From aa695d9330c2f3feafb2ffca66ed8aafdac9d118 Mon Sep 17 00:00:00 2001 From: t Date: Sat, 5 Sep 2026 12:11:11 +0900 Subject: [PATCH 2/3] test(combos): cover the identifiers leaf seam (split S11 L1/5) --- tests/codex-integration/combos.test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/codex-integration/combos.test.ts b/tests/codex-integration/combos.test.ts index a1c40616c0..9aff287f03 100644 --- a/tests/codex-integration/combos.test.ts +++ b/tests/codex-integration/combos.test.ts @@ -62,6 +62,9 @@ import { } from "../../src/providers/quota-routing-cache"; import { catalogConvergenceFactory } from "../helpers/catalog-convergence"; import { removeTreeWithRetry } from "../helpers/remove-tree"; +import * as publicCombos from "../../src/combos"; +import * as comboIdentifiers from "../../src/combos/identifiers"; +import { repoPath } from "../helpers/repo-root"; const VALID_COMBO = { targets: [{ provider: "a", model: "m1" }] }; @@ -1201,3 +1204,25 @@ describe("combo generation reconciliation", () => { expect(pickComboTarget(original, "free")?.target.provider).toBe("b"); }); }); + +test("combo identifiers leaf preserves public export identity without facade imports", () => { + const names = [ + "COMBO_NAMESPACE", + "preservesPhysicalComboProvider", + "isNativeAliasCombo", + "targetKey", + "parseComboModelId", + "comboModelId", + "comboPublicModelId", + "comboDisabledModelId", + "comboDisabledModelSelectors", + "resolveComboId", + "isValidComboId", + ] as const; + for (const name of names) { + expect(publicCombos[name]).toBe(comboIdentifiers[name]); + } + const source = readFileSync(repoPath("src", "combos", "identifiers.ts"), "utf8"); + expect(source.split(/\r?\n/).some(line => /from\s+["']\.\/(types|index)["']/.test(line))) + .toBe(false); +}); From 0c914bf265ce38c57498c21ccf81f0202b9c133c Mon Sep 17 00:00:00 2001 From: t Date: Sat, 5 Sep 2026 12:13:21 +0900 Subject: [PATCH 3/3] refactor(combos): trim the trailing blank line left by the identifiers move (split S11 L1/5) --- src/combos/identifiers.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/combos/identifiers.ts b/src/combos/identifiers.ts index 118eb4291d..ff2f231215 100644 --- a/src/combos/identifiers.ts +++ b/src/combos/identifiers.ts @@ -87,4 +87,3 @@ export function resolveComboId( export function isValidComboId(id: string): boolean { return COMBO_ID_PATTERN.test(id); } -