Derive ipc-mock broker-event payloads from shared zod schemas#216
Conversation
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>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Review limit reached
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 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary
Closes audit item M2.3. The 1,163-line
ipc-mock.tswas a parallel implementation whose broker-event payload shapes could silently drift from the real zod schemas introduced in PR #214.broker-events.ts— 31Extract<ValidatedBrokerEvent, { kind: 'X' }>aliases, one per known event kind, with a shared doc comment.satisfieson 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.classifyBrokerEventruns insidehandleInjectedBrokerEventand throws onstatus === 'malformed'; this code never ships in the real app.BrokerEventLike.kindtightened fromkind?: stringtokind: stringto matchBrokerEventPayload.Drifted/invalid shapes corrected
broker.spawnAgentagent_spawnedemitted withoutruntime— required byagentSpawnedschema (runtime: z.string())runtime: agent.runtime || 'mock'spawnAgentsharnessruntime: 'mock'Both other fabricated events (
agent_released,relay_inbound) already carried all required fields;satisfiesconfirms this statically.Test evidence
🤖 Generated with Claude Code