feat: kernel constraints pipeline enforcement#409
Merged
Conversation
Migrate all 9 packages from Zod 3.22.x to Zod 4.3.6. This is a
breaking change for downstream TypeScript consumers who compile
against exported @peac/schema types (z.infer<> types are not
assignment-compatible across Zod majors).
Schema changes:
- z.record() single-arg form removed in Zod 4: add explicit
z.string() key schema in 5 locations (schema, control, mcp-server)
- .default({}) on object schemas requires output-type-compatible
values in Zod 4: use .prefault({}) for input-type defaults (policy.ts)
- ZodError.errors alias removed: use .issues in test assertions
- issue.path typed as PropertyKey[] (was (string | number)[]): add
casts at 2 call sites (protocol/issue.ts, cli/validators.ts)
No behavioral changes to schema validation, receipt issuance, or
verification. All 4138 tests pass across 167 test files.
Workspace enforcement:
- pnpm.overrides forces zod@^4.3.6 across all workspace packages
- Prevents mixed Zod 3/4 which causes runtime TypeError
Wire validateKernelConstraints() into issue() and verify pipelines. Fail-closed: violations reject before signing (issue) or before schema validation (verify). Changes: - issue.ts: constraint check after claims build, before Zod parse - verify-local.ts: constraint check after signature, before schema - verify.ts: constraint check after decode, before Zod parse - errors.ts: E_CONSTRAINT_VIOLATION error code + factory function - verify-local.ts: E_CONSTRAINT_VIOLATION added to VerifyLocalErrorCode - verify.ts: 'constraint_violation' added to VerifyFailure reasons New: docs/specs/KERNEL-CONSTRAINTS.md normative specification Tests: 11 new (issue + verify constraint boundary tests)
Merged
Rename test to clarify intent and use items directly instead of unused exactArray + smallArray indirection.
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
validateKernelConstraints()intoissue()andverifyLocal()/verifyReceipt()pipelines (DD-121)E_CONSTRAINT_VIOLATIONwith factory functiondocs/specs/KERNEL-CONSTRAINTS.mdEnforcement points
issue()IssueErrorwithE_CONSTRAINT_VIOLATIONverifyLocal()parseReceiptClaims()VerifyLocalFailurewith codeE_CONSTRAINT_VIOLATIONverifyReceipt()ReceiptClaims.parse()VerifyFailurewith reasonconstraint_violationZero impact on valid receipts
Constraints match existing
JSON_EVIDENCE_LIMITSvalues. No valid receipt that currently passes will be rejected.Changes
packages/schema/src/errors.ts: AddedE_CONSTRAINT_VIOLATIONtoERROR_CODES, addedcreateConstraintViolationError()factorypackages/protocol/src/issue.ts: Constraint check inserted after claims object build (line 295)packages/protocol/src/verify-local.ts: Constraint check after signature verification,E_CONSTRAINT_VIOLATIONadded toVerifyLocalErrorCodepackages/protocol/src/verify.ts: Constraint check after decode,constraint_violationreason added toVerifyFailuredocs/specs/KERNEL-CONSTRAINTS.md: Normative specification with constraint values, enforcement semantics, types, and cross-referencesTest plan
Non-goals (explicitly deferred)
Spec deltas
Round 2 hardening
Ordering precedence (normative)
Added to
docs/specs/KERNEL-CONSTRAINTS.md: