Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(e2e): type-check the node-unit suites and pin the single-use Codex redeem
Alfredo Lopez7029337e66e2
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 716800e60..026eff3ee 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.601",+ "version": "0.1.602","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.601",+ "version": "0.1.602","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --git a/control-api/package.json b/control-api/package.jsonindex a4c6f4544..8ec051e38 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.601",+ "version": "0.1.602","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/test/services.llmProviderAttemptRedemption.realPostgres.integration.test.ts b/control-api/test/services.llmProviderAttemptRedemption.realPostgres.integration.test.tsindex e9fc99234..544bcba64 100644--- a/control-api/test/services.llmProviderAttemptRedemption.realPostgres.integration.test.ts+++ b/control-api/test/services.llmProviderAttemptRedemption.realPostgres.integration.test.ts@@ -63,7 +63,33 @@ describeRealPostgres('Codex ticket redemption on real PostgreSQL', () => {}})- it('lets exactly one of 20 concurrent redeems win', async () => {+ function redeemDeps() {+ return {+ enabled: true as const,+ encryptionKey: KEY,+ loadSecrets: loadCodexSubscriptionSecrets,+ withTransaction: async <T>(work: (tx: never) => Promise<T>): Promise<T> => {+ const client = await pool.connect()+ try {+ await client.query('BEGIN')+ const result = await work(client as never)+ await client.query('COMMIT')+ return result+ } catch (error) {+ try {+ await client.query('ROLLBACK')+ } catch {+ // keep the original error+ }+ throw error+ } finally {+ client.release()+ }+ },+ }+ }++ async function issueTicket(requestHash: string) {const attempt = await insertLlmProviderAttempt(pool, {callerKind: 'host',hostRef: 'research-host',@@ -71,7 +97,7 @@ describeRealPostgres('Codex ticket redemption on real PostgreSQL', () => {attemptGeneration: 1,providerAttemptIndex: 1,model: 'gpt-5.1',- requestHash: 'd'.repeat(64),+ requestHash,policyRevision: 1,policyHash: 'e'.repeat(64),budgetReservationId: 'unbudgeted',@@ -92,6 +118,27 @@ describeRealPostgres('Codex ticket redemption on real PostgreSQL', () => {budgetReservationId: attempt.budgetReservationId,connectionRevision: attempt.connectionRevision,})+ return { attempt, issued }+ }++ async function ledgerState(jti: string, attemptId: string) {+ const ticket = await pool.query<{ status: string; redeemed_at: Date | null }>(+ `SELECT status, redeemed_at FROM llm_provider_attempt_tickets WHERE jti = $1`,+ [jti]+ )+ const attempt = await pool.query<{ status: string }>(+ `SELECT status FROM llm_provider_attempts WHERE id = $1`,+ [attemptId]+ )+ return {+ ticketStatus: ticket.rows[0]?.status,+ redeemedAt: ticket.rows[0]?.redeemed_at ?? null,+ attemptStatus: attempt.rows[0]?.status,+ }+ }++ it('lets exactly one of 20 concurrent redeems win', async () => {+ const { attempt, issued } = await issueTicket('d'.repeat(64))const results = await Promise.allSettled(Array.from({ length: 20 }, () =>@@ -100,29 +147,7 @@ describeRealPostgres('Codex ticket redemption on real PostgreSQL', () => {executionTicket: issued.executionTicket,requestHash: attempt.requestHash,},- {- enabled: true,- encryptionKey: KEY,- loadSecrets: loadCodexSubscriptionSecrets,- withTransaction: async work => {- const client = await pool.connect()- try {- await client.query('BEGIN')- const result = await work(client as never)- await client.query('COMMIT')- return result- } catch (error) {- try {- await client.query('ROLLBACK')- } catch {- // keep the original error- }- throw error- } finally {- client.release()- }- },- }+ redeemDeps())))@@ -148,4 +173,30 @@ describeRealPostgres('Codex ticket redemption on real PostgreSQL', () => {}}})++ // maxRetriesPerAttempt is 1 because a ticket redeems once: a proxy retry of+ // the same attempt after a committed redeem is a replay, not a second try.+ it('refuses a sequential second redeem of a committed ticket without touching the ledger', async () => {+ const { attempt, issued } = await issueTicket('7'.repeat(64))++ const first = await redeemLlmProviderAttempt(+ { executionTicket: issued.executionTicket, requestHash: attempt.requestHash },+ redeemDeps()+ )+ expect(first.accessToken).toBe('access-usable')+ const afterFirst = await ledgerState(issued.claims.jti, attempt.id)+ expect(afterFirst).toEqual({+ ticketStatus: 'redeemed',+ redeemedAt: expect.any(Date),+ attemptStatus: 'redeemed',+ })++ await expect(+ redeemLlmProviderAttempt(+ { executionTicket: issued.executionTicket, requestHash: attempt.requestHash },+ redeemDeps()+ )+ ).rejects.toMatchObject({ code: 'ticket_replayed' })+ expect(await ledgerState(issued.claims.jti, attempt.id)).toEqual(afterFirst)+ })})diff --git a/docs/architecture/codex-subscription-transport-contract.md b/docs/architecture/codex-subscription-transport-contract.mdindex 2c0bb99a5..48979ed38 100644--- a/docs/architecture/codex-subscription-transport-contract.md+++ b/docs/architecture/codex-subscription-transport-contract.md@@ -48,6 +48,16 @@ OAuth scopes: `openid`, `profile`, `email`, `offline_access`.All values are finite and greater than zero. `maxRetriesPerAttempt` is `1`:one physical execution per ticket. A retry or fallback must mint a new attempt.+The value is not a counter the proxy consults; it is a property of the+single-use redeem in control-api, enforced in three layers inside one+transaction: the ticket row is locked and must still be `issued`, the attempt+must still be `authorized`, and the consuming `UPDATE` matches only+`status = 'issued'`. A second redeem of the same ticket fails with+`ticket_replayed` and leaves the ledger unchanged. The real-PostgreSQL tests+`services.llmProviderAttemptRedemption.realPostgres.integration.test.ts`+(sequential replay and 20 concurrent redeems) and+`services.grokProviderAttemptRedemption.refresh.realPostgres.integration.test.ts`+(Grok replay) pin this behaviour.| Limit | Value || --------------------- | ------- |diff --git a/scripts/e2e/run-vitest-e2e.sh b/scripts/e2e/run-vitest-e2e.shindex 22830419f..ba1530fc5 100755--- a/scripts/e2e/run-vitest-e2e.sh+++ b/scripts/e2e/run-vitest-e2e.sh@@ -240,6 +240,10 @@ cd "${PROJECT_DIR}"ensure_vitest_dependenciesif [[ "${VITEST_SUITE_GROUP}" == "node-unit" ]]; then+ # Vitest strips types without checking them; tsconfig.node-unit.json lists+ # the same suites as DEFAULT_NODE_UNIT_VITEST_SUITES and checks them first.+ log "Type-checking Vitest E2E (node-unit)"+ (cd tests/e2e && npm run typecheck:node-unit)run_selected_vitest_suites "$@"exit 0fidiff --git a/scripts/tests/test-e2e-vitest-node-unit-gate.sh b/scripts/tests/test-e2e-vitest-node-unit-gate.shindex eb4cf9c99..c0a5bd41d 100755--- a/scripts/tests/test-e2e-vitest-node-unit-gate.sh+++ b/scripts/tests/test-e2e-vitest-node-unit-gate.sh@@ -79,8 +79,60 @@ require_node_unit_suite() {fi}+# Vitest strips types without checking them, so the node-unit suites are only+# type-checked through tsconfig.node-unit.json. Its files must be exactly the+# suites the runner executes: a suite in one list and not the other either runs+# unchecked or is checked and never run.+require_node_unit_typecheck_matches_runner() {+ local tsconfig="${ROOT_DIR}/tests/e2e/tsconfig.node-unit.json"+ if [[ ! -f "${tsconfig}" ]]; then+ echo "missing node-unit typecheck config: ${tsconfig}" >&2+ exit 1+ fi+ local runner_suites tsconfig_suites+ runner_suites="$(awk '+ $0 == "DEFAULT_NODE_UNIT_VITEST_SUITES=(" { inarray = 1; next }+ inarray && $0 == ")" { inarray = 0 }+ inarray && $0 !~ /^ *#/ && NF { gsub(/^ +| +$/, ""); print }+ ' "${RUNNER}" | sort)"+ tsconfig_suites="$(awk '+ /"files": \[/ { inarray = 1; next }+ inarray && /\]/ { inarray = 0 }+ inarray { gsub(/[ ",]/, ""); if (length($0)) print }+ ' "${tsconfig}" | sort)"+ if [[ -z "${runner_suites}" ]]; then+ echo "no node-unit suites found in ${RUNNER}" >&2+ exit 1+ fi+ if [[ "${runner_suites}" != "${tsconfig_suites}" ]]; then+ printf 'tsconfig.node-unit.json files differ from DEFAULT_NODE_UNIT_VITEST_SUITES\nrunner:\n%s\ntsconfig:\n%s\n' \+ "${runner_suites}" "${tsconfig_suites}" >&2+ exit 1+ fi+}++# The typecheck must sit in the node-unit branch and run before the suites, so+# a type error stops the job even when every test would pass.+require_node_unit_typecheck_before_suites() {+ if ! awk '+ $0 == "if [[ \"${VITEST_SUITE_GROUP}\" == \"node-unit\" ]]; then" { inblock = 1; next }+ inblock && $0 == "fi" { inblock = 0 }+ inblock && index($0, "npm run typecheck:node-unit") { typecheck = NR }+ inblock && index($0, "run_selected_vitest_suites") { suites = NR }+ END { exit(typecheck && suites && typecheck < suites ? 0 : 1) }+ ' "${RUNNER}"; then+ echo "missing node-unit typecheck before run_selected_vitest_suites in ${RUNNER}" >&2+ exit 1+ fi+}+require_contains "${RUNNER}" "DEFAULT_NODE_UNIT_VITEST_SUITES=(" \"node-unit suite registry"+require_contains "${ROOT_DIR}/tests/e2e/package.json" \+ '"typecheck:node-unit": "tsc -p tsconfig.node-unit.json"' \+ "node-unit typecheck script"+require_node_unit_typecheck_matches_runner+require_node_unit_typecheck_before_suitesrequire_contains "${RUNNER}" "gfsUploadV2Fixtures.test.ts" \"descriptor fixture suite registration"require_node_unit_suite "integration/codex-subscription-contract-freeze.test.ts" \diff --git a/tests/e2e/package-lock.json b/tests/e2e/package-lock.jsonindex 54012259b..358a86daf 100644--- a/tests/e2e/package-lock.json+++ b/tests/e2e/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-e2e-tests",- "version": "0.1.91",+ "version": "0.1.92","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-e2e-tests",- "version": "0.1.91",+ "version": "0.1.92","devDependencies": {"@clerum/llm-provider-attempt-contract": "file:../../packages/llm-provider-attempt-contract","@types/jsonwebtoken": "^9.0.10",diff --git a/tests/e2e/package.json b/tests/e2e/package.jsonindex e1c88b7a1..2f5d506d8 100644--- a/tests/e2e/package.json+++ b/tests/e2e/package.json@@ -1,11 +1,12 @@{"name": "clerum-e2e-tests",- "version": "0.1.91",+ "version": "0.1.92","private": true,"type": "module","scripts": {"test": "vitest run","test:watch": "vitest",+ "typecheck:node-unit": "tsc -p tsconfig.node-unit.json","test:verbose": "vitest run --reporter=verbose","test:rpc-proxy-e2e": "vitest run rpc-proxy/security.e2e.test.ts","test:rpc-proxy-e2e:watch": "vitest rpc-proxy/security.e2e.test.ts",diff --git a/tests/e2e/tsconfig.node-unit.json b/tests/e2e/tsconfig.node-unit.jsonnew file mode 100644index 000000000..bec9f95d6--- /dev/null+++ b/tests/e2e/tsconfig.node-unit.json@@ -0,0 +1,8 @@+{+ "extends": "./tsconfig.json",+ "compilerOptions": {+ "noEmit": true+ },+ "include": [],+ "files": ["gfsUploadV2Fixtures.test.ts", "integration/codex-subscription-contract-freeze.test.ts"]+}