Skip to content

Derive ipc-mock broker-event payloads from shared zod schemas#216

Merged
willwashburn merged 1 commit into
mainfrom
audit/mock-schema-derivation
Jun 10, 2026
Merged

Derive ipc-mock broker-event payloads from shared zod schemas#216
willwashburn merged 1 commit into
mainfrom
audit/mock-schema-derivation

Conversation

@willwashburn

Copy link
Copy Markdown
Member

Summary

Closes audit item M2.3. The 1,163-line ipc-mock.ts was a parallel implementation whose broker-event payload shapes could silently drift from the real zod schemas introduced in PR #214.

  • Export per-variant inferred types from broker-events.ts — 31 Extract<ValidatedBrokerEvent, { kind: 'X' }> aliases, one per known event kind, with a shared doc comment.
  • satisfies on every fabricated event literal in the mock — AgentSpawnedEvent, AgentReleasedEvent, RelayInboundEvent — so any future schema change that alters a required field breaks the mock at compile time, not at runtime.
  • Dev-only runtime guardclassifyBrokerEvent runs inside handleInjectedBrokerEvent and throws on status === 'malformed'; this code never ships in the real app.
  • BrokerEventLike.kind tightened from kind?: string to kind: string to match BrokerEventPayload.

Drifted/invalid shapes corrected

Site Problem Fix
broker.spawnAgent agent_spawned emitted without runtime — required by agentSpawned schema (runtime: z.string()) Added runtime: agent.runtime || 'mock'
spawnAgents harness same omission Added runtime: 'mock'

Both other fabricated events (agent_released, relay_inbound) already carried all required fields; satisfies confirms this statically.

Test evidence

npm run typecheck   ✓  (0 errors, 0 new warnings)
npm run lint        ✓  (0 errors, 57 pre-existing warnings unchanged)
npx vitest run      ✓  302/302 passed
npm run build:web   ✓
npm run test:fidelity  ✓  6/6 passed
npm run test:stress    ✓  2/2 passed (1000-agent pty-heavy: minFps=32, avgFps=48.9)

🤖 Generated with Claude Code

Export per-variant inferred types from broker-events.ts (Extract on the
discriminated union), then anchor every broker-event literal the mock
fabricates with `satisfies <VariantType>` so a schema change becomes a
compile error instead of silent drift.

Two payloads were genuinely invalid against the current schema and are
now fixed:
- agent_spawned emitted by broker.spawnAgent was missing the required
  `runtime` field (schema: `runtime: z.string()`).
- agent_spawned emitted by spawnAgents harness had the same omission.

Also adds a dev-only runtime guard in handleInjectedBrokerEvent:
classifyBrokerEvent now runs on every injected event and throws on
`malformed` status — this file never ships in the real app, so the
guard catches bad payloads in CI before they silently reach stores.

BrokerEventLike.kind is tightened from optional to required to match
the BrokerEventPayload contract every real event satisfies.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@willwashburn, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 43 minutes and 22 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ab033a81-cf65-490d-a1d3-eec9da21608b

📥 Commits

Reviewing files that changed from the base of the PR and between c46e320 and 64fae98.

📒 Files selected for processing (2)
  • src/renderer/src/lib/ipc-mock.ts
  • src/shared/schemas/broker-events.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch audit/mock-schema-derivation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@willwashburn willwashburn merged commit 0970016 into main Jun 10, 2026
5 checks passed
@willwashburn willwashburn deleted the audit/mock-schema-derivation branch June 10, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant