Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(llm-providers): fail if oauth-broker maps stay a Codex ternary
Jose Gabriel Ramirez Encinascb2a592d9824
diff --git a/packages/llm-providers/index.cjs b/packages/llm-providers/index.cjsindex b40537872..396bba366 100644--- a/packages/llm-providers/index.cjs+++ b/packages/llm-providers/index.cjs@@ -221,18 +221,48 @@ function isCredentialSlotOwnedByProvider(provider, credentialSlot) {return canonical.includes(credentialSlot)}-/** @type {Record<string, 'static-credentials' | 'oauth-broker'>} */-const PROVIDER_AUTH_MODE = Object.freeze(- Object.fromEntries(- PROVIDER_IDS.map(id => [id, id === 'codex-subscription' ? 'oauth-broker' : 'static-credentials'])- )-)+const OAUTH_BROKER_IDS = Object.freeze(['codex-subscription'])-/** @type {Record<string, 'static' | 'dynamic'>} */-const PROVIDER_MODEL_CATALOG_MODE = Object.freeze(- Object.fromEntries(PROVIDER_IDS.map(id => [id, id === 'codex-subscription' ? 'dynamic' : 'static']))+/**+ * Pure map builder so tests can inject a second broker id without editing+ * production PROVIDER_IDS. Production maps call this with OAUTH_BROKER_IDS.+ * @param {readonly string[]} ids+ * @param {readonly string[]} brokerIds+ */+function buildProviderMaps(ids, brokerIds) {+ const brokers = new Set(brokerIds)+ return {+ PROVIDER_AUTH_MODE: Object.freeze(+ Object.fromEntries(+ ids.map(id => [id, brokers.has(id) ? 'oauth-broker' : 'static-credentials'])+ )+ ),+ PROVIDER_MODEL_CATALOG_MODE: Object.freeze(+ Object.fromEntries(ids.map(id => [id, brokers.has(id) ? 'dynamic' : 'static']))+ ),+ }+}++const { PROVIDER_AUTH_MODE, PROVIDER_MODEL_CATALOG_MODE } = buildProviderMaps(+ PROVIDER_IDS,+ OAUTH_BROKER_IDS)+/** @type {Record<string, string | undefined>} */+const PROVIDER_EXECUTE_SCOPE = Object.freeze({+ 'codex-subscription': 'llm:codex:execute',+})++/** @type {Record<string, string | undefined>} */+const PROVIDER_PROXY_APP = Object.freeze({+ 'codex-subscription': 'codex-llm-proxy',+})++/** @type {Record<string, string | undefined>} */+const PROVIDER_PROXY_SERVICE = Object.freeze({+ 'codex-subscription': 'codex-llm-proxy',+})+function providerDescriptor(id) {if (!isLlmProviderId(id)) {throw new Error(`[llm-providers] unknown provider '${String(id)}'`)@@ -244,6 +274,9 @@ function providerDescriptor(id) {modelCatalogMode: PROVIDER_MODEL_CATALOG_MODE[id],credentialSlots: PROVIDER_CREDENTIAL_SLOTS[id],nonSecretEnv: PROVIDER_NON_SECRET_ENV[id],+ executeScope: PROVIDER_EXECUTE_SCOPE[id],+ proxyApp: PROVIDER_PROXY_APP[id],+ proxyService: PROVIDER_PROXY_SERVICE[id],})}@@ -269,6 +302,8 @@ module.exports = {PROVIDER_NON_SECRET_ENV,PROVIDER_AUTH_MODE,PROVIDER_MODEL_CATALOG_MODE,+ OAUTH_BROKER_IDS,+ buildProviderMaps,isCredentialSlotOwnedByProvider,isLlmProviderId,isRunnableLlmModelId,diff --git a/packages/llm-providers/index.d.ts b/packages/llm-providers/index.d.tsindex 80d53800c..2838bedb3 100644--- a/packages/llm-providers/index.d.ts+++ b/packages/llm-providers/index.d.ts@@ -102,10 +102,21 @@ export interface ProviderDescriptor {credentialSlots: readonly CredentialSlot[]nonSecretEnv: readonly NonSecretEnvVar[]defaultModel?: string+ executeScope?: string+ proxyApp?: string+ proxyService?: string}export declare const PROVIDER_AUTH_MODE: Record<LlmProviderId, ProviderAuthMode>export declare const PROVIDER_MODEL_CATALOG_MODE: Record<LlmProviderId, ProviderModelCatalogMode>+export declare const OAUTH_BROKER_IDS: readonly ['codex-subscription']+export declare function buildProviderMaps(+ ids: readonly string[],+ brokerIds: readonly string[],+): {+ PROVIDER_AUTH_MODE: Readonly<Record<string, ProviderAuthMode>>+ PROVIDER_MODEL_CATALOG_MODE: Readonly<Record<string, ProviderModelCatalogMode>>+}export declare function providerDescriptor(id: LlmProviderId): ProviderDescriptorexport declare function requireStaticCredentialSlot(descriptor: Pick<ProviderDescriptor, 'authMode' | 'credentialSlots'>,diff --git a/packages/llm-providers/index.test.cjs b/packages/llm-providers/index.test.cjsnew file mode 100644index 000000000..7b95db7db--- /dev/null+++ b/packages/llm-providers/index.test.cjs@@ -0,0 +1,34 @@+'use strict'++const { describe, it } = require('node:test')+const assert = require('node:assert/strict')+const providers = require('./index.cjs')++describe('buildProviderMaps', () => {+ it('exports a pure builder that classifies injected broker ids without editing production maps', () => {+ assert.equal(typeof providers.buildProviderMaps, 'function')+ const maps = providers.buildProviderMaps(+ ['openai', 'codex-subscription', 'fixture-broker'],+ ['codex-subscription', 'fixture-broker']+ )+ assert.equal(maps.PROVIDER_AUTH_MODE['fixture-broker'], 'oauth-broker')+ assert.equal(maps.PROVIDER_AUTH_MODE.openai, 'static-credentials')+ assert.equal(maps.PROVIDER_AUTH_MODE['codex-subscription'], 'oauth-broker')+ assert.equal(maps.PROVIDER_MODEL_CATALOG_MODE['fixture-broker'], 'dynamic')+ assert.equal(maps.PROVIDER_MODEL_CATALOG_MODE.openai, 'static')+ })++ it('keeps production maps Codex-only and rejects unknown ids', () => {+ assert.deepEqual(providers.OAUTH_BROKER_IDS, ['codex-subscription'])+ assert.equal(providers.PROVIDER_AUTH_MODE['codex-subscription'], 'oauth-broker')+ assert.equal(providers.PROVIDER_AUTH_MODE.openai, 'static-credentials')+ assert.equal(providers.PROVIDER_MODEL_CATALOG_MODE['codex-subscription'], 'dynamic')+ assert.throws(() => providers.providerDescriptor('not-a-provider'))+ assert.throws(() => providers.providerDescriptor('fixture-broker'))+ const desc = providers.providerDescriptor('codex-subscription')+ assert.equal(desc.authMode, 'oauth-broker')+ assert.equal(desc.executeScope, 'llm:codex:execute')+ assert.equal(desc.proxyApp, 'codex-llm-proxy')+ assert.equal(desc.proxyService, 'codex-llm-proxy')+ })+})diff --git a/packages/llm-providers/package.json b/packages/llm-providers/package.jsonindex 8f6cfd475..01a3b32e8 100644--- a/packages/llm-providers/package.json+++ b/packages/llm-providers/package.json@@ -14,7 +14,7 @@},"license": "MIT","scripts": {- "test": "node --check index.cjs",+ "test": "node --check index.cjs && node --test index.test.cjs","build": "node --check index.cjs"}}