Files
openclaude/scripts/provider-launch.test.ts
T
JATMN 5b9daef605 feat(providers): add Command Code hybrid gateway (#2196)
* feat(providers): add focused Command Code hybrid gateway

Register Command Code as a descriptor-first OpenAI-compatible aggregating gateway with a hybrid catalog, dedicated CMD_API_KEY credentials, and the same surgical sibling wiring used by LLMTR.

* fix(providers): reject Command Code placeholder keys and restore saved secrets on relaunch

Treat CMD_API_KEY placeholders as unusable at request time, and migrate a profile-owned persisted OPENAI_API_KEY into CMD_API_KEY on canonical Command Code restart when dedicated keys are missing.

* fix(providers): re-apply Command Code when the dedicated key drifts

Profile apply already writes CMD_API_KEY, but alignment only compared OPENAI_API_KEY, so a stale dedicated secret could keep winning request auth.

* fix(providers): isolate Command Code from leftover OpenAI keys

Selecting --provider commandcode left a distinct generic OPENAI_API_KEY in-process because Command Code shared LLMTR's fallback path. Mirror the dedicated credential or clear the generic key on the canonical endpoint.

* fix: enforce Command Code transport contract

* fix: apply model override before validation

* fix: support inline model overrides

* fix: align early model parsing with CLI

* fix: address Command Code review feedback

* fix: validate Command Code profile models

* fix: keep startup model display in sync

* fix: avoid echoing rejected Command Code models

* fix: share effective model flag parsing

* fix: preserve teammate provider overrides

* fix: isolate command code startup state

* fix: align command code startup state

* fix: close command code route gaps

* fix: preserve teammate route precedence

* fix: align launcher and root option parsing

* fix: preserve model and credential semantics

* fix: reject Claude aliases on Command Code

* fix: preserve root --model after a consumed delimiter

Required-value options such as --system-prompt consume a following -- token, so early Command Code model recovery must scan the full argv instead of truncating at the first delimiter.

* fix: reject Command Code Claude models in /model and lists

The shared Chat Completions predicate only inspected whole strings, and
/model still applied OpenClaude aliases. Reject list members and block
those selections on the Command Code route.

* fix: ignore nested --model when applying --provider

Command Code preflight was last-wins on full argv, so a nested aimlapi/auto-mode --model could abort provider selection even when the root session model was valid.

* fix: unmount Ink if /model wait times out

The Command Code /model tests left the Ink instance registered when waitForCondition rejected, which can leak into later tests.

* fix: enforce Command Code contracts at profile write time

Reject incompatible models and capture dedicated CMD credentials in
toProfile so Console OAuth env adoption and other add/update callers
cannot persist Chat Completions-invalid Command Code state. Align
background session metadata with the same root --model argv slice used
at CLI startup.

* fix: persist Command Code dedicated keys over leftover OpenAI env

Env adoption that copies OPENAI_API_KEY must not store a generic secret
on a canonical Command Code profile when CMD_API_KEY is present. Document
that the route still requires explicit selection.

* fix: test background session root --model from launch argv

Replace the source-text assertion with the shared metadata helper used by
handleBgFlag so nested aimlapi/auto-mode --model flags cannot silently
become the recorded session model.

* fix(commandcode): unify route validation contracts

* fix(commandcode): preserve explicit profile credentials

* fix(cli): preserve explicit provider routing

* fix(cli): align provider option consumers

* fix(commandcode): align credential and discovery contracts

* docs(commandcode): clarify Claude model support

* fix(bg): align persisted provider metadata

* fix(commandcode): preserve model and base defaults
2026-09-06 08:28:34 +08:00

95 lines
3.2 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import {
getOpenAILaunchCredentialError,
hasUsableOpenAILaunchCredential,
} from './provider-launch.ts'
describe('provider-launch OpenAI credential validation', () => {
test('accepts valid OPENAI_API_KEYS before placeholder OPENAI_API_KEY fallback', () => {
expect(
hasUsableOpenAILaunchCredential({
OPENAI_API_KEYS: 'sk-openai-a,sk-openai-b',
OPENAI_API_KEY: 'SUA_CHAVE',
} as NodeJS.ProcessEnv),
).toBe(true)
})
test('rejects placeholder OPENAI_API_KEYS before singular fallback', () => {
expect(
hasUsableOpenAILaunchCredential({
OPENAI_API_KEYS: 'sk-openai-a,SUA_CHAVE',
OPENAI_API_KEY: 'sk-openai-single',
} as NodeJS.ProcessEnv),
).toBe(false)
})
test('accepts a dedicated Command Code credential on its selected route', () => {
expect(
hasUsableOpenAILaunchCredential({
CLAUDE_CODE_USE_OPENAI: '1',
OPENAI_BASE_URL: 'https://api.commandcode.ai/provider/v1',
CMD_API_KEY: 'cmd-key',
} as NodeJS.ProcessEnv),
).toBe(true)
})
test('accepts the Command Code fallback credential on its selected route', () => {
expect(
hasUsableOpenAILaunchCredential({
CLAUDE_CODE_USE_OPENAI: '1',
OPENAI_BASE_URL: 'https://api.commandcode.ai/provider/v1',
COMMANDCODE_API_KEY: 'fallback-key',
} as NodeJS.ProcessEnv),
).toBe(true)
})
test('rejects a generic credential for the dedicated-only Command Code route', () => {
expect(
hasUsableOpenAILaunchCredential({
CLAUDE_CODE_USE_OPENAI: '1',
OPENAI_BASE_URL: 'https://api.commandcode.ai/provider/v1',
OPENAI_API_KEY: 'generic-key',
} as NodeJS.ProcessEnv),
).toBe(false)
})
test.each([
'CMD_API_KEY',
'COMMANDCODE_API_KEY',
'COMMAND_CODE_API_KEY',
] as const)(
'rejects a placeholder %s on the selected Command Code route',
credentialEnvVar => {
expect(
hasUsableOpenAILaunchCredential({
CLAUDE_CODE_USE_OPENAI: '1',
OPENAI_BASE_URL: 'https://api.commandcode.ai/provider/v1',
[credentialEnvVar]: 'SUA_CHAVE',
} as NodeJS.ProcessEnv),
).toBe(false)
},
)
test('reports Command Code credential guidance for its selected route', () => {
expect(
getOpenAILaunchCredentialError({
CLAUDE_CODE_USE_OPENAI: '1',
OPENAI_BASE_URL: 'https://api.commandcode.ai/provider/v1',
} as NodeJS.ProcessEnv),
).toBe(
'CMD_API_KEY is required for the Command Code route (fallbacks: COMMANDCODE_API_KEY or COMMAND_CODE_API_KEY) and cannot include placeholder values such as SUA_CHAVE. Set one of those environment variables, rerun the launcher, then use /provider to save the Command Code profile.',
)
})
test('preserves generic OpenAI credential guidance outside Command Code', () => {
expect(
getOpenAILaunchCredentialError({
CLAUDE_CODE_USE_OPENAI: '1',
OPENAI_BASE_URL: 'https://api.openai.com/v1',
} as NodeJS.ProcessEnv),
).toBe(
'OPENAI_API_KEYS or OPENAI_API_KEY is required for openai profile and cannot include SUA_CHAVE. Run: bun run profile:init -- --provider openai --api-key <key>',
)
})
})