Repository navigation
Add disabled Context accounting fixtures with strict CI coverage - #1254
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Pre-merge checks:
|
There was a problem hiding this comment.
4 issues found across 14 files
Confidence score: 4/5
validateContextAccountingInput.tsaccepts the nil and max UUIDs aspayerId, even though they are sentinel values rather than authenticated payers. Reject those values so they cannot be used as payer IDs.runContextAccountingAttempt.tsis 112 lines, over the stated 100-line limit. Extract the attempt phases into focused helpers.reconcileContextAccountingAttempt.tsduplicates the terminal-result projection fromrunContextAccountingAttempt.ts, which risks the two paths drifting. Extract a shared helper and use it in both places.- The
hold-v1-reservation ID pattern is repeated invalidateContextReservationReceipt.tsand other files, so the pinned format could drift. Define a shared schema and reuse it, including infinishContextAccountingAttempt.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="lib/context/accounting/validateContextReservationReceipt.ts">
<violation number="1" location="lib/context/accounting/validateContextReservationReceipt.ts:8">
P3: The `hold-v1-` reservation-ID pattern is now repeated across several files. Extract one shared schema (for example `reservationIdSchema`) and reuse it here and in `finishContextAccountingAttempt`, so the pinned format has a single source of truth.</violation>
</file>
<file name="lib/context/accounting/validateContextAccountingInput.ts">
<violation number="1" location="lib/context/accounting/validateContextAccountingInput.ts:10">
P3: `z.uuid()` accepts the nil UUID `00000000-0000-0000-0000-000000000000` and the max UUID `ffffffff-ffff-ffff-ffff-ffffffffffff` as `payerId`. Those are sentinel values, not authenticated payers, and they would become a shared ledger partition and wallet account key. Reject them explicitly in the payer schema.</violation>
</file>
<file name="lib/context/accounting/runContextAccountingAttempt.ts">
<violation number="1" location="lib/context/accounting/runContextAccountingAttempt.ts:11">
P2: Custom agent: **Enforce Clear Code Style and Maintainability Practices**
This 112-line module exceeds the rule’s under-100-line limit. Extract the attempt phases into focused helpers so the file stays below the cap.</violation>
</file>
<file name="lib/context/accounting/reconcileContextAccountingAttempt.ts">
<violation number="1" location="lib/context/accounting/reconcileContextAccountingAttempt.ts:19">
P3: This terminal-phase mapping and reused-result shape duplicate the `if (prior)` branch in `runContextAccountingAttempt`. Extract one shared helper for the terminal-result projection and call it from both places, so a future phase change cannot update only one path.</violation>
</file>
Architecture diagram
sequenceDiagram
participant CI as CI Workflow
participant TS as tsc (Strict Types)
participant Tests as Vitest Fixtures
participant Fixture as Accounting Fixture
participant Adapter as Context Accounting Adapter
participant Services as Injected Services
participant Ledger as Payer Ledger
participant Wallet as Credit Wallet (Mock)
Note over CI,TS: NEW: Strict Type Checking Gate
CI->>TS: pnpm exec tsc --noEmit (context-accounting)
TS-->>CI: Type check result
CI->>Tests: pnpm exec vitest run lib/context/accounting
Tests->>Fixture: Create test fixture
Fixture->>Adapter: runContextAccountingAttempt(input)
Adapter->>Services: authorize(input)
Services-->>Adapter: OK
Adapter->>Ledger: transact(payerId, check prior attempt)
Ledger-->>Adapter: No prior attempt
Adapter->>Services: findAcceptedReuse(input)
Services-->>Adapter: null (no reuse)
Adapter->>Ledger: transact(payerId, admitContextAccountingAttempt)
Ledger->>Ledger: Check request/pilot ceilings
Ledger-->>Adapter: Admitted (created: true)
Adapter->>Services: reserveCreditsOnce({operationKey})
Services->>Wallet: Reserve credits
Wallet-->>Services: Reservation held
Services-->>Adapter: Reservation receipt (held)
Adapter->>Services: authorize(input) - recheck
Services-->>Adapter: OK
Adapter->>Ledger: transact(payerId, set phase to dispatching)
Ledger-->>Adapter: Attempt dispatching
Adapter->>Services: dispatch(input)
Services-->>Adapter: Completion (0-4 credits)
Adapter->>Ledger: transact(payerId, set completed)
Ledger-->>Adapter: Attempt completed
Adapter->>Services: settleCreditReservation or releaseCreditReservation
Services->>Wallet: Settle/release hold
Wallet-->>Services: Receipt
Services-->>Adapter: Updated state
Adapter-->>Fixture: Final state (settled/released/pending)
Note over Adapter,Services: Error/Reconciliation Path
Adapter->>Services: reserveCreditsOnce fails or ambiguous
Services-->>Adapter: Error or reused hold
Adapter->>Ledger: Keep phase admitted/pending
Adapter-->>Fixture: pending_reconciliation (full exposure retained)
Note over Fixture,Wallet: Reconciliation (separate entry point)
Tests->>Fixture: reconcileContextAccountingAttempt(input)
Fixture->>Adapter: Reconcile attempt
Adapter->>Ledger: Check attempt state
Ledger-->>Adapter: Found (completed/cancelled)
Adapter->>Services: finishContextAccountingAttempt
Services->>Wallet: Settle or release
Wallet-->>Services: Receipt
Services-->>Adapter: State updated
Adapter-->>Fixture: Final reconciled state
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
| import type { ContextAccountingServices } from "./types"; | ||
|
|
||
| /** Disabled consumer: all effects injected; no production caller, wallet, provider or policy defaults. */ | ||
| export async function runContextAccountingAttempt( |
There was a problem hiding this comment.
P2: Custom agent: Enforce Clear Code Style and Maintainability Practices
This 112-line module exceeds the rule’s under-100-line limit. Extract the attempt phases into focused helpers so the file stays below the cap.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/context/accounting/runContextAccountingAttempt.ts, line 11:
<comment>This 112-line module exceeds the rule’s under-100-line limit. Extract the attempt phases into focused helpers so the file stays below the cap.</comment>
<file context>
@@ -0,0 +1,112 @@
+import type { ContextAccountingServices } from "./types";
+
+/** Disabled consumer: all effects injected; no production caller, wallet, provider or policy defaults. */
+export async function runContextAccountingAttempt(
+ raw: unknown,
+ services: ContextAccountingServices,
</file context>
| .discriminatedUnion("state", [ | ||
| z.strictObject({ | ||
| state: z.literal("held"), | ||
| reservationId: z.string().regex(/^hold-v1-[a-f0-9]{64}$/), |
There was a problem hiding this comment.
P3: The hold-v1- reservation-ID pattern is now repeated across several files. Extract one shared schema (for example reservationIdSchema) and reuse it here and in finishContextAccountingAttempt, so the pinned format has a single source of truth.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/context/accounting/validateContextReservationReceipt.ts, line 8:
<comment>The `hold-v1-` reservation-ID pattern is now repeated across several files. Extract one shared schema (for example `reservationIdSchema`) and reuse it here and in `finishContextAccountingAttempt`, so the pinned format has a single source of truth.</comment>
<file context>
@@ -0,0 +1,25 @@
+ .discriminatedUnion("state", [
+ z.strictObject({
+ state: z.literal("held"),
+ reservationId: z.string().regex(/^hold-v1-[a-f0-9]{64}$/),
+ creditsHeld: z.number().int().positive().safe(),
+ spendableCredits: z.number().int().nonnegative().safe(),
</file context>
| .strictObject({ | ||
| mode: z.literal("fixture"), | ||
| billing: z.literal("context_owned"), | ||
| payerId: z.uuid(), |
There was a problem hiding this comment.
P3: z.uuid() accepts the nil UUID 00000000-0000-0000-0000-000000000000 and the max UUID ffffffff-ffff-ffff-ffff-ffffffffffff as payerId. Those are sentinel values, not authenticated payers, and they would become a shared ledger partition and wallet account key. Reject them explicitly in the payer schema.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/context/accounting/validateContextAccountingInput.ts, line 10:
<comment>`z.uuid()` accepts the nil UUID `00000000-0000-0000-0000-000000000000` and the max UUID `ffffffff-ffff-ffff-ffff-ffffffffffff` as `payerId`. Those are sentinel values, not authenticated payers, and they would become a shared ledger partition and wallet account key. Reject them explicitly in the payer schema.</comment>
<file context>
@@ -0,0 +1,22 @@
+ .strictObject({
+ mode: z.literal("fixture"),
+ billing: z.literal("context_owned"),
+ payerId: z.uuid(),
+ requestId: id,
+ pilotId: id,
</file context>
| payerId: z.uuid(), | |
| payerId: z.uuid().refine(value => !/^(0{8}-0{4}-0{4}-0{4}-0{12}|f{8}-f{4}-f{4}-f{4}-f{12})$/i.test(value), "payerId must not be a sentinel UUID"), |
| throw new Error("Attempt unavailable or changed"); | ||
| return structuredClone(current); | ||
| }); | ||
| if (["settled", "released", "insufficient", "reused"].includes(attempt.phase)) |
There was a problem hiding this comment.
P3: This terminal-phase mapping and reused-result shape duplicate the if (prior) branch in runContextAccountingAttempt. Extract one shared helper for the terminal-result projection and call it from both places, so a future phase change cannot update only one path.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At lib/context/accounting/reconcileContextAccountingAttempt.ts, line 19:
<comment>This terminal-phase mapping and reused-result shape duplicate the `if (prior)` branch in `runContextAccountingAttempt`. Extract one shared helper for the terminal-result projection and call it from both places, so a future phase change cannot update only one path.</comment>
<file context>
@@ -0,0 +1,29 @@
+ throw new Error("Attempt unavailable or changed");
+ return structuredClone(current);
+ });
+ if (["settled", "released", "insufficient", "reused"].includes(attempt.phase))
+ return {
+ state: attempt.phase,
</file context>
…ntext-accounting-strict-ci
There was a problem hiding this comment.
0 issues found across 1 file (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: Auto-approval blocked by 8 unresolved issues from previous reviews.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 3 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Requires human review: Auto-approval blocked by 4 unresolved issues from previous reviews.
View guided diff | Turn on auto-fix | Re-trigger cubic
Problem and behavior
Context request/pilot accounting needs admission ceilings and replay-safe reservation handling. This isolated successor of #1250 carries its disabled, dependency-injected adapter and 36 offline fixtures, composes current main (
10fce9198fc4bacf184405e7792563fec90f7496) through a normal merge, and closes review comment 4604591480 by adding ongoing strict type coverage.The separate Context Accounting Strict Types workflow runs on pull requests to main and pushes to main. It follows the repository Node22/pnpm9 setup and directly runs
pnpm exec tsc --noEmit --project tsconfig.context-accounting.json, including negative assertions for Promise-returning and value-or-Promise transaction callbacks. No package.json, existing test workflow, lockfile, or runtime accounting code changes were made relative to the composed candidate. README now describes the automated gate. The fixture transaction method also enforces the synchronous callback constraint directly, rejects thenables before committing draft changes, and consumes late rejections. Direct compile regressions, rollback/queue-continuation tests, a bounded reuse assertion and a specific billing rejection assertion cover the four reviewed quality findings; a comment clarifies the zero-credit validation placeholder without changing billing.Original #1250 and its sealed evidence remain unchanged. This PR is the reviewable successor, not a second rollout. No production caller, wallet, provider, policy, migration or activation is added. This remains a partial fixture-only contribution toward recoupable/app#2123; the shared reservation composition and intended-account acceptance gates remain separately owned.
Validation
9929d685ba8784f6b7529bb4893527eea7f2e1f7, retaining the normal main composition. All exact-head required checks passed, including the strict callback checker and full test workflow. Automated delta review found zero new issues; prior review threads remain for human disposition.Merge remains held for explicit approval.
Summary by cubic
Adds a disabled, dependency-injected context accounting adapter with 32 offline fixtures, plus a dedicated strict type-checking CI workflow, without wiring it into any production path.
The adapter stays fixture-only: no production caller, wallet, provider, policy, migration, or activation is added, and all services and ceilings must be supplied.
Behavior covered
billing: "endpoint_owned"is rejected.CI gate
Context Accounting Strict Typesworkflow runstsc --noEmitontsconfig.context-accounting.jsonfor PRs and pushes to main.Written for commit 9929d68. Summary will update on new commits.
Coordinator source disposition
Recoup OS accepts exact
9929d685ba8784f6b7529bb4893527eea7f2e1f7as a disabled, unwired accounting contract and its strict CI gate. The synchronous fixture boundary, bounded wait and specific validation regressions are fixed and independently reviewed; exact-head required checks pass. No production route, workflow or provider imports this consumer.The remaining suggestions are non-blocking in this scope: UUID syntax is followed by required injected payer authorization before admission, so accepting UUID sentinels does not establish an authorization bypass; cohesive phase orchestration has no verified universal 100-line cap; current terminal projections and reservation patterns agree and their behavior is regression-covered. No live identity policy or broad refactor is silently adopted. Before wiring, actual authenticated attribution, durable storage, approved policy, reservation composition and reconciliation must be qualified. This source release supplies none of those runtime prerequisites and does not close the owning epic.