Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(codex): add complete T0 subscription gate

Alfredo Lopeza675be556566
diff --git a/.github/workflows/ci-public.yml b/.github/workflows/ci-public.yml
index 91c1be1ad..e1a829f73 100644
--- a/.github/workflows/ci-public.yml
+++ b/.github/workflows/ci-public.yml
@@ -67,6 +67,8 @@ jobs:
- packages/workflow-runtime-core
- packages/workflow-sdk
- packages/network-policy-core
+ - packages/llm-provider-attempt-contract
+ - codex-llm-proxy
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
@@ -125,8 +127,10 @@ jobs:
# network-policy-core is a hand-authored .cjs + .d.ts with no tsconfig, so
# `tsc --noEmit` resolves no project (like mcp-servers). Its .d.ts is kept
# aligned with the runtime by the "runtime exports stay aligned" node:test.
+ # llm-provider-attempt-contract is the same shape: hand-authored .cjs + .d.ts,
+ # no tsconfig; node --test keeps the types aligned with the runtime.
- name: Typecheck (tsc --noEmit)
- if: matrix.service != 'mcp-servers' && matrix.service != 'packages/desktop-app-links' && matrix.service != 'packages/network-policy-core'
+ if: matrix.service != 'mcp-servers' && matrix.service != 'packages/desktop-app-links' && matrix.service != 'packages/network-policy-core' && matrix.service != 'packages/llm-provider-attempt-contract'
working-directory: ${{ matrix.service }}
run: npx tsc --noEmit
@@ -209,6 +213,23 @@ jobs:
echo 'real-Postgres control-api lane reported skipped tests' >&2
exit 1
fi
+ # Codex subscription suites must stay inside the real-Postgres filter.
+ # A rename or move that drops them from `*realPostgres*` would otherwise
+ # still pass the aggregate counts above.
+ for suite in \
+ db.codexSubscriptionConnection.realPostgres.integration \
+ services.codexSubscriptionOAuth.realPostgres.integration \
+ services.codexSubscriptionCatalog.realPostgres.integration \
+ services.llmProviderAttemptAuthorization.realPostgres.integration \
+ services.llmProviderAttemptStore.realPostgres.integration \
+ services.llmProviderAttemptRedemption.realPostgres.integration \
+ services.llmProviderAttemptFinalization.realPostgres.integration
+ do
+ grep -Fq "$suite" "$normalized_log" || {
+ echo "real-Postgres control-api lane omitted Codex suite ${suite}" >&2
+ exit 1
+ }
+ done
- name: Install gfs-controller dependencies
working-directory: gfs-controller
diff --git a/Makefile b/Makefile
index 90b5adc7a..3d6757b41 100644
--- a/Makefile
+++ b/Makefile
@@ -120,6 +120,10 @@ test-unit-all: ## Run unit tests across all services
fi
@echo "All unit tests passed."
+.PHONY: test-codex-subscription-t0
+test-codex-subscription-t0: ## Run the Codex subscription T0 aggregator (counts, no skips)
+ @bash scripts/tests/test-codex-subscription-t0.sh
+
# ── Build Preflight ──────────────────────────────────────────────────
.PHONY: build-preflight
build-preflight: ## Run local build preflight across deployable packages
diff --git a/desktop-app/src/types.ts b/desktop-app/src/types.ts
index e2bcae04f..5254b07bc 100644
--- a/desktop-app/src/types.ts
+++ b/desktop-app/src/types.ts
@@ -1041,6 +1041,10 @@ export interface HostModelOption {
name: string
displayName?: string
contextWindowTokens?: number
+ /** Last-known catalog row; hidden from new picks unless it is already selected. */
+ stale?: boolean
+ /** Operator-disabled catalog row; hidden from new picks unless it is already selected. */
+ disabled?: boolean
}
/**
diff --git a/desktop-app/ui/src/components/agents/ModelSelector.tsx b/desktop-app/ui/src/components/agents/ModelSelector.tsx
index 03a3403f8..28e23585b 100644
--- a/desktop-app/ui/src/components/agents/ModelSelector.tsx
+++ b/desktop-app/ui/src/components/agents/ModelSelector.tsx
@@ -20,6 +20,20 @@ export interface ModelSelectorProps {
/** How long the "applies to your next message" confirmation badge stays up. */
const APPLIED_BADGE_MS = 4000
+/** Broker-backed hosts have no static default; the operator must name a model. */
+const CODEX_SUBSCRIPTION_PROVIDER = 'codex-subscription'
+const SELECT_MODEL_LABEL = 'Select model'
+
+function isBrokerBackedProvider(provider: string): boolean {
+ return provider === CODEX_SUBSCRIPTION_PROVIDER
+}
+
+function isOfferedForNewPick(option: HostModelOption, sessionModel: string | null): boolean {
+ const isCurrent = Boolean(sessionModel) && option.name === sessionModel
+ if (isCurrent) return true
+ return !option.stale && !option.disabled
+}
+
/** Human label for a model: operator `displayName` if set, else the raw name. */
function modelLabel(name: string, options: HostModelOption[]): string {
const match = options.find(option => option.name === name)
@@ -29,9 +43,11 @@ function modelLabel(name: string, options: HostModelOption[]): string {
/**
* Per-session model selector for the chat indicators row (R2), sat next to the
* agent title and context-window chip. Shows the effective model
- * (`sessionModel ?? hostDefault`) and, on click, a popover listing the allowed
- * models. Choosing one applies it to the NEXT task ("applies to your next
- * message" — R2.5).
+ * (`sessionModel ?? hostDefault`, except broker-backed Codex which never
+ * invents a default) and, on click, a popover listing the allowed models.
+ * Stale/disabled catalog rows stay hidden from new picks unless they are the
+ * saved session selection. Choosing one applies it to the NEXT task
+ * ("applies to your next message" — R2.5).
*
* Visibility / degraded rules:
* - Hidden entirely until the model list loads, and when the host predates the
@@ -76,10 +92,18 @@ export function ModelSelector({ agentRef, chatId, placement = 'down' }: ModelSel
return () => window.clearTimeout(timeoutId)
}, [applied])
- const effectiveModel = data ? (data.sessionModel ?? data.hostDefault) : ''
- const effectiveLabel = useMemo(
- () => (data ? modelLabel(effectiveModel, data.models) : ''),
- [data, effectiveModel]
+ const effectiveModel = data
+ ? (data.sessionModel ?? (isBrokerBackedProvider(data.provider) ? '' : data.hostDefault))
+ : ''
+ const effectiveLabel = useMemo(() => {
+ if (!data) return ''
+ if (!effectiveModel && isBrokerBackedProvider(data.provider)) return SELECT_MODEL_LABEL
+ return modelLabel(effectiveModel, data.models)
+ }, [data, effectiveModel])
+ const offeredModels = useMemo(
+ () =>
+ data ? data.models.filter(option => isOfferedForNewPick(option, data.sessionModel)) : [],
+ [data]
)
const handleSelect = useCallback(
@@ -169,9 +193,9 @@ export function ModelSelector({ agentRef, chatId, placement = 'down' }: ModelSel
{error}
</p>
)}
- {data.models.length ? (
+ {offeredModels.length ? (
<ul className="model-selector-list">
- {data.models.map(option => {
+ {offeredModels.map(option => {
const isActive = option.name === effectiveModel
return (
<li key={option.name}>
diff --git a/desktop-app/ui/src/components/agents/__tests__/ModelSelector.test.tsx b/desktop-app/ui/src/components/agents/__tests__/ModelSelector.test.tsx
index c751a9bc4..38af98e52 100644
--- a/desktop-app/ui/src/components/agents/__tests__/ModelSelector.test.tsx
+++ b/desktop-app/ui/src/components/agents/__tests__/ModelSelector.test.tsx
@@ -136,6 +136,48 @@ describe('ModelSelector', () => {
expect(root?.classList.contains('model-selector--up')).toBe(true)
})
+ it('does not invent a Codex default when the session has no selected model', () => {
+ setHook({
+ data: baseData({
+ provider: 'codex-subscription',
+ hostDefault: '',
+ sessionModel: null,
+ models: [
+ { name: 'gpt-5.3', displayName: 'GPT-5.3' },
+ { name: 'gpt-5.2', displayName: 'GPT-5.2' },
+ ],
+ }),
+ })
+ renderSelector()
+ expect(screen.getByRole('button', { name: /Model — Select model/ })).toBeTruthy()
+ expect(screen.queryByRole('button', { name: /GPT-5\.3/ })).toBeNull()
+ fireEvent.click(screen.getByRole('button', { name: /Model —/ }))
+ expect(
+ screen.getByRole('menuitemradio', { name: /GPT-5\.3/ }).getAttribute('aria-checked')
+ ).toBe('false')
+ expect(screen.queryByText('default')).toBeNull()
+ })
+
+ it('hides stale and disabled Codex models from new picks, keeping a saved selection', () => {
+ setHook({
+ data: baseData({
+ provider: 'codex-subscription',
+ hostDefault: '',
+ sessionModel: 'gpt-5.2-stale',
+ models: [
+ { name: 'gpt-5.3', displayName: 'GPT-5.3' },
+ { name: 'gpt-5.2-stale', displayName: 'GPT-5.2', stale: true },
+ { name: 'gpt-5.1-off', displayName: 'GPT-5.1', disabled: true },
+ ],
+ }),
+ })
+ renderSelector()
+ fireEvent.click(screen.getByRole('button', { name: /Model — GPT-5\.2/ }))
+ expect(screen.getByRole('menuitemradio', { name: /GPT-5\.3/ })).toBeTruthy()
+ expect(screen.getByRole('menuitemradio', { name: /GPT-5\.2/ })).toBeTruthy()
+ expect(screen.queryByRole('menuitemradio', { name: /GPT-5\.1/ })).toBeNull()
+ })
+
it('surfaces the inline error from a rejected switch without changing selection', () => {
setHook({
data: baseData(),
diff --git a/desktop-app/ui/src/hooks/__tests__/useHostModels.test.tsx b/desktop-app/ui/src/hooks/__tests__/useHostModels.test.tsx
index e63cc6076..412574a4c 100644
--- a/desktop-app/ui/src/hooks/__tests__/useHostModels.test.tsx
+++ b/desktop-app/ui/src/hooks/__tests__/useHostModels.test.tsx
@@ -205,3 +205,27 @@ describe('useHostModels — R2 new-chat composer (no chatId yet)', () => {
act(() => result.current.store.clearPreChatModel(AGENT))
})
})
+
+describe('useHostModels — Codex subscription (no silent default)', () => {
+ it('does not seed a Codex session from the first catalog model when hostDefault is empty', async () => {
+ const getHostModels = vi.fn(async () =>
+ baseModels({
+ provider: 'codex-subscription',
+ hostDefault: '',
+ sessionModel: null,
+ models: [
+ { name: 'gpt-5.3', displayName: 'GPT-5.3' },
+ { name: 'gpt-5.2', displayName: 'GPT-5.2' },
+ ],
+ })
+ )
+ installClerum(getHostModels, vi.fn())
+
+ const { result } = renderHook(() => useHostModels(AGENT, CHAT))
+ await waitFor(() => expect(result.current.data).toBeTruthy())
+
+ expect(result.current.data?.provider).toBe('codex-subscription')
+ expect(result.current.data?.sessionModel).toBeNull()
+ expect(result.current.data?.hostDefault).toBe('')
+ })
+})
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useAgentChatController.pendingModel.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useAgentChatController.pendingModel.test.tsx
index fe3c27a50..2d02d58b1 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/useAgentChatController.pendingModel.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/useAgentChatController.pendingModel.test.tsx
@@ -193,6 +193,22 @@ describe('useAgentChatController — R2 "Option A" pending-model piggyback', ()
expect(readPending(chatId)).toBeUndefined()
})
+ it('does not invent a Codex catalog default when sending without a pending model', async () => {
+ const { invokeHostMessage } = installClerumHarness()
+ render(
+ <AgentTaskTrackerProvider>
+ <AgentChatHarness />
+ </AgentTaskTrackerProvider>
+ )
+
+ await createChat()
+ fireEvent.click(screen.getByRole('button', { name: 'Send message' }))
+ await waitFor(() => expect(invokeHostMessage).toHaveBeenCalledTimes(1))
+
+ const payload = invokeHostMessage.mock.calls[0]?.[1] as Record<string, unknown>
+ expect('model' in payload).toBe(false)
+ })
+
it('(e) omits model entirely when there is no pending selection', async () => {
const { invokeHostMessage } = installClerumHarness()
render(
diff --git a/docs/testing/codex-subscription-validation.md b/docs/testing/codex-subscription-validation.md
index 058d3e474..f69bd0208 100644
--- a/docs/testing/codex-subscription-validation.md
+++ b/docs/testing/codex-subscription-validation.md
@@ -4,8 +4,11 @@ Evidence lanes for `codex-subscription`. One lane does not stand in for another.
## Lanes
-- **T0** — unit, schema, hash, contracts, typecheck, lint, build. Includes
- `make test-codex-subscription-t0` once that aggregator exists.
+- **T0** — unit, schema, hash, contracts, typecheck, lint, build. The
+ aggregator is `make test-codex-subscription-t0`. It fails when a required
+ suite is missing, executes zero tests, reports skipped/todo cases, or
+ exits non-zero. Flag-off compatibility still uses `make test-unit-all`,
+ `make test-contracts`, and `make build-preflight`.
- **T1** — real PostgreSQL. `CONTROL_API_REAL_PG_REQUIRED=1`. A missing DSN,
skipped suite, or zero tests is FAIL.
- **Manifest** — Kustomize, images, ServiceAccount/RBAC, secrets, gateways,
@@ -28,6 +31,8 @@ contract. The freeze test is
## Commands
```bash
+make test-codex-subscription-t0
+
cd tests/e2e
npm test -- --run integration/codex-subscription-contract-freeze.test.ts
```
diff --git a/scripts/tests/test-codex-subscription-t0.sh b/scripts/tests/test-codex-subscription-t0.sh
new file mode 100755
index 000000000..c8b1194a8
--- /dev/null
+++ b/scripts/tests/test-codex-subscription-t0.sh
@@ -0,0 +1,222 @@
+#!/usr/bin/env bash
+# Codex subscription T0 aggregator.
+#
+# Fails when a required suite is missing, executes zero tests, reports
+# skipped/todo cases, or exits non-zero. Exit 0 alone is never enough: the
+# script parses machine-readable counts from Vitest or node:test.
+set -u
+
+ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
+FAIL=0
+GROUPS_RUN=0
+
+pass() { echo "PASS: $1"; }
+fail() { echo "FAIL: $1"; FAIL=1; }
+
+require_file() {
+ local rel="$1"
+ if [[ ! -f "${ROOT}/${rel}" ]]; then
+ fail "missing required suite ${rel}"
+ return 1
+ fi
+ return 0
+}
+
+strip_ansi() {
+ sed $'s/\033\\[[0-9;]*m//g'
+}
+
+# Return 0 when the captured reporter proves at least one passing test and
+# zero skipped/todo cases. Supports Vitest summaries and node:test counters.
+assert_executed_counts() {
+ local name="$1"
+ local log="$2"
+ local normalized
+ normalized="$(mktemp)"
+ strip_ansi <"$log" >"$normalized"
+
+ local vitest_passed
+ vitest_passed="$(
+ grep -Eo 'Tests[[:space:]]+[1-9][0-9]* passed' "$normalized" | head -n 1 || true
+ )"
+ local node_tests
+ node_tests="$(
+ grep -E 'tests[[:space:]]+[1-9][0-9]*$' "$normalized" | awk '{print $NF}' | tail -n 1 || true
+ )"
+ local node_pass
+ node_pass="$(
+ grep -E 'pass[[:space:]]+[1-9][0-9]*$' "$normalized" | awk '{print $NF}' | tail -n 1 || true
+ )"
+
+ if [[ -z "${vitest_passed}" && -z "${node_pass}" ]]; then
+ fail "${name}: executed zero passing tests"
+ echo "----- ${name} reporter -----"
+ cat "$normalized"
+ rm -f "$normalized"
+ return 1
+ fi
+
+ if [[ -n "${node_tests}" && -n "${node_pass}" && "${node_tests}" != "${node_pass}" ]]; then
+ fail "${name}: node:test pass count ${node_pass} does not match tests ${node_tests}"
+ rm -f "$normalized"
+ return 1
+ fi
+
+ if grep -Eq '(Test Files|Tests).*[1-9][0-9]* skipped' "$normalized"; then
+ fail "${name}: Vitest reported skipped tests"
+ rm -f "$normalized"
+ return 1
+ fi
+ if grep -Eq '(Test Files|Tests).*[1-9][0-9]* todo' "$normalized"; then
+ fail "${name}: Vitest reported todo tests"
+ rm -f "$normalized"
+ return 1
+ fi
+ if grep -Eq '^(#|ℹ) skipped[[:space:]]+[1-9]' "$normalized"; then
+ fail "${name}: node:test reported skipped tests"
+ rm -f "$normalized"
+ return 1
+ fi
+ if grep -Eq '^(#|ℹ) todo[[:space:]]+[1-9]' "$normalized"; then
+ fail "${name}: node:test reported todo tests"
+ rm -f "$normalized"
+ return 1
+ fi
+ if grep -Eiq 'no test files|no tests found' "$normalized"; then
+ fail "${name}: reporter found no tests"
+ rm -f "$normalized"
+ return 1
+ fi
+
+ rm -f "$normalized"
+ return 0
+}
+
+run_group() {
+ local name="$1"
+ local prefix="$2"
+ shift 2
+ local files=("$@")
+ local rel
+ if [[ "${#files[@]}" -eq 0 ]]; then
+ fail "${name}: group listed no suite files"
+ return 1
+ fi
+ for rel in "${files[@]}"; do
+ require_file "${prefix}/${rel}" || return 1
+ done
+
+ local log
+ log="$(mktemp)"
+ local npm_args=(--prefix "${ROOT}/${prefix}" test --)
+ npm_args+=("${files[@]}")
+
+ echo "── ${name} ──"
+ if ! (
+ cd "${ROOT}"
+ FORCE_COLOR=0 NO_COLOR=1 npm "${npm_args[@]}"
+ ) >"$log" 2>&1; then
+ fail "${name}: command failed"
+ cat "$log"
+ rm -f "$log"
+ return 1
+ fi
+
+ if ! assert_executed_counts "$name" "$log"; then
+ rm -f "$log"
+ return 1
+ fi
+
+ GROUPS_RUN=$((GROUPS_RUN + 1))
+ pass "${name}"
+ rm -f "$log"
+}
+
+require_ci_matrix_entry() {
+ local entry="$1"
+ if ! grep -Eq "^[[:space:]]+- ${entry}$" "${ROOT}/.github/workflows/ci-public.yml"; then
+ fail "ci-public.yml matrix is missing ${entry}"
+ return 1
+ fi
+ pass "ci-public.yml matrix includes ${entry}"
+}
+
+echo "Codex subscription T0 aggregator"
+
+if [[ ! -f "${ROOT}/scripts/tests/test-codex-subscription-t0.sh" ]]; then
+ fail "aggregator script is missing"
+fi
+
+require_ci_matrix_entry "codex-llm-proxy"
+require_ci_matrix_entry "packages/llm-provider-attempt-contract"
+
+run_group "shared-contract" "packages/llm-provider-attempt-contract" "index.test.cjs"
+
+run_group "control-api" "control-api" \
+ "test/llmProviders.test.ts" \
+ "test/services.codexSubscriptionOAuth.test.ts" \
+ "test/services.codexSubscriptionCatalog.test.ts" \
+ "test/services.llmProviderAttemptAuthorizer.test.ts" \
+ "test/services.llmProviderAttemptTicket.test.ts" \
+ "test/services.llmProviderAttemptRedemption.test.ts" \
+ "test/services.llmProviderAttemptFinalization.test.ts"
+
+run_group "codex-llm-proxy" "codex-llm-proxy" \
+ "test/codexTransport.conformance.test.ts" \
+ "test/controlApiClient.test.ts" \
+ "test/originPolicy.test.ts" \
+ "test/redaction.test.ts" \
+ "test/server.security.test.ts"
+
+run_group "mcp-host" "mcp-host" \
+ "src/llm/__tests__/codexSubscription.test.ts" \
+ "src/llm/__tests__/codexLlmProxyClient.test.ts" \
+ "src/llm/__tests__/providerAttemptAuthorizer.test.ts" \
+ "src/llm/failover/__tests__/engine.test.ts" \
+ "src/pluginWorkloadSdk/promptBridge/llmBridge.failover.test.ts"
+
+run_group "host-context-controller" "host-context-controller" \
+ "src/codexExecutionProjection.test.ts" \
+ "src/hostReconciler.codexScopeProvenance.test.ts" \
+ "src/networkPolicyReconciler.test.ts"
+
+run_group "workflow-recipes" "workflow-recipes" \
+ "src/workflow/codexExecutionProjection.test.ts" \
+ "src/workflow/workflowReconciler.codexScopeProvenance.test.ts" \
+ "src/workflow/networkPolicyFactory.codex.test.ts"
+
+run_group "control-ui" "control-ui" \
+ "components/__tests__/CodexSubscriptionConnection.test.tsx" \
+ "components/__tests__/HostWizard.test.tsx" \
+ "components/__tests__/RecipeEditor.test.tsx"
+
+node_major=$(node --version | sed -n 's/^v\([0-9][0-9]*\).*/\1/p')
+if [[ "${node_major}" != "24" ]]; then
+ fail "Desktop T0 requires Node 24.x (got $(node --version))"
+else
+ pass "Node $(node --version) for Desktop T0"
+ if ! (
+ cd "${ROOT}/desktop-app"
+ npm run verify:electron
+ ); then
+ fail "desktop-app verify:electron failed"
+ else
+ pass "desktop-app verify:electron"
+ run_group "desktop-app" "desktop-app" \
+ "ui/src/components/agents/__tests__/ModelSelector.test.tsx" \
+ "ui/src/hooks/__tests__/useHostModels.test.tsx" \
+ "ui/src/hooks/domain/__tests__/useAgentChatController.pendingModel.test.tsx"
+ fi
+fi
+
+if [[ "${GROUPS_RUN}" -lt 8 ]]; then
+ fail "expected 8 T0 groups, ran ${GROUPS_RUN}"
+fi
+
+if [[ "${FAIL}" -ne 0 ]]; then
+ echo "Codex subscription T0 FAILED"
+ exit 1
+fi
+
+echo "Codex subscription T0 passed (${GROUPS_RUN} groups)"
+exit 0