feat(schemas): add Tier-0 finalDecisionPayloadSchema + parseTypedPayload helper (PR2/3)#36
Merged
Merged
Conversation
…oad helper
PR2 of 3 from dashboard-zod-trust-boundary plan.
## Schemas package
Add packages/schemas/src/audit-events.ts (Tier 0, zero internal deps):
- finalDecisionPayloadSchema — runtime-validated FINAL_DECISION audit
payload. Single permissive z.object accepts canonical camelCase
(post-PR1), legacy snake_case (pre-PR1 historical DB rows), and the
chat-approval-limited shape. Transform normalizes to canonical
camelCase output. Passthrough preserves unknown fields for
forward-compat.
- participantMetadataSchema — stricter than participantSchema.metadata
(z.record(z.unknown()) at Tier 0 stays loose for backwards compat).
Rejects non-plain objects (Date, Map, Set, class instances) — closes
round-3 finding C. Transform returns fresh object — closes finding E.
- consensusMetaSchema — extracted shape for consensusMeta sub-object.
Includes 15 unit tests covering canonical/legacy/limited shapes,
forward-compat passthrough, mutation-safety, and rejection of primitives.
## Dashboard helper
Add parseTypedPayload to apps/dashboard/src/lib/safeJson.ts:
- Generic primitive: parseTypedPayload<S>(input, schema, context).
- Returns discriminated tagged result: {status:'empty'|'invalid'|'ok'}.
TypeScript exhaustive-switch catches missed cases at compile time —
closes the silent-fallback bug class.
- Empty input (null/undefined/""/whitespace) → 'empty' (legitimate
pending state). JSON.parse failure or schema rejection → 'invalid'
(data corruption / drift). Validated and transformed → 'ok'.
- Dev-mode warns log input length only; never raw content (no
token/PII leak).
Includes 12 unit tests covering empty/invalid/ok branches, schema
transforms, dev-mode logging, no-leak guarantee.
## Producer contract test promotion
Producer contract tests added in PR1 (#35) now also validate emit shapes
through the Tier-0 schema. Catches drift at the source if any future
change reintroduces snake_case OR shapes the schema rejects.
## Dashboard deps
Add @consensus-tools/schemas (workspace:*) and zod ^3.23.0 as runtime
dependencies of apps/dashboard. PR3 wires the schema into the dashboard
render paths and DriftBanner component.
## Changeset
Minor bump for @consensus-tools/schemas (new public exports).
## Verification
- pnpm build — 23/23 successful
- pnpm test — 47/47 turbo tasks pass (schemas 38, core 73, workflows
35, sdk-node 33, dashboard 48, all others unchanged)
- pnpm typecheck — 42/42 successful
- pnpm dep-check — clean (226 modules, 424 deps)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR2 of 3 from
~/.gstack/projects/consensus-tools-toolkit/ceo-plans/dashboard-zod-trust-boundary.md. Builds on PR #35.Changes
Schemas package — Tier 0 (zero deps preserved)
packages/schemas/src/audit-events.ts(new):finalDecisionPayloadSchemaz.objectaccepts canonical camelCase + legacy snake_case + chat-approval-limited shape..transform()normalizes to canonical output..passthrough()preserves unknown fields (forward-compat).participantMetadataSchemaparticipantSchema.metadata(which staysz.record(z.unknown())for backwards-compat per /plan-eng-review decision). Rejects Date/Map/Set/class instances (closes round-3 finding C); transform returns fresh object (closes finding E).consensusMetaSchemanode-executor.tsand historically present in DB rows.15 unit tests cover the matrix in plan T02/T03 acceptance: canonical/legacy/limited shapes, forward-compat passthrough, mutation-safety, primitive rejection.
Dashboard helper
apps/dashboard/src/lib/safeJson.tsextended withparseTypedPayload:Generic primitive that takes any zod schema. PR3 will add thin wrappers (
parseFinalDecision,parseParticipantMetadata) and use this directly fromEventTimelinewith a discriminated event-payload schema. The discriminated tagged result forces callers to handle'invalid'explicitly — TypeScript's exhaustive switch closes the silent-fallback class of bug.12 unit tests: empty/invalid/ok branches, schema transforms, dev-mode logging, no-leak guarantee.
Producer contract test promotion
PR1's producer contract tests (in core, workflows, sdk-node) now also validate emit shapes through
finalDecisionPayloadSchema. Catches drift at the source if any future change reintroduces snake_case or otherwise breaks the canonical shape.Dashboard runtime deps
Adds
@consensus-tools/schemas: workspace:*andzod: ^3.23.0toapps/dashboard/package.json. Required for PR3 to import the schema. Dashboard isprivate: trueand excluded from changesets/publish.Changeset
.changeset/audit-events-schema.md— minor bump for@consensus-tools/schemas(new public exports). Documents the 2026-09-01 sunset for legacy shapes.Test Coverage
pnpm build— 23/23 successfulpnpm test— 47/47 turbo tasks passpnpm typecheck— 42/42 successfulpnpm dep-check— clean (226 modules, 424 deps)Plan reconciliation
packages/schemas/src/audit-events.ts.transform()(decision 4){status, value}(decision 8)parseTypedPayload<T>primitive (decision 9)z.object+.transform(), NOT discriminated union (decision 10)Out of scope for PR2 (lands in PR3): dashboard wiring, DriftBanner, @testing-library/react infra, 4 regression tests for findings B/D/E/F.
Test plan
decision, wrong types, primitives, datesparseTypedPayloaddiscriminates empty / invalid / ok🤖 Generated with Claude Code