feat: Validation Kernel — Patch Schema, Invariants, and Cryptographic Verification#5
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThis PR introduces a comprehensive Patch Operations validation system featuring JSON schema enforcement, Ed25519 cryptographic signing and verification, invariant validation across operations, test fixtures, and CI/CD integration via GitHub Actions workflow. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Patch Document
participant Validator as validatePatchOpsDocument()
participant AJV as AJV Schema Validator
participant InvariantChecker as Invariant Checker
participant Crypto as Crypto Utilities
participant Keyring as Keyring
Client->>Validator: validatePatchOpsDocument(doc)
Validator->>AJV: Validate against PATCH_OPS_SCHEMA.v1.json
alt Schema Valid
AJV-->>Validator: ok
Validator->>InvariantChecker: Run invariant checks
InvariantChecker->>InvariantChecker: Check cardinality, reverse mapping, ordering, duplicates
InvariantChecker->>Crypto: canonicalize(payload)
Crypto-->>InvariantChecker: canonical JSON
InvariantChecker->>Crypto: prefixedBlake3(canonical)
Crypto-->>InvariantChecker: payloadDigest
InvariantChecker->>InvariantChecker: Compare with signature.payloadDigest
alt Digest Mismatch
InvariantChecker-->>Validator: INV_011_DIGEST_MISMATCH
else Digest Match
InvariantChecker->>Keyring: loadKeyring()
Keyring-->>InvariantChecker: KeyringEntry map
InvariantChecker->>Crypto: verifyEd25519DetachedHex(sig, payload, pubKey)
Crypto-->>InvariantChecker: verification result
alt Sig Valid
InvariantChecker-->>Validator: all invariants pass
else Sig Invalid
InvariantChecker-->>Validator: INV_012_SIG_FAILED
end
end
else Schema Invalid
AJV-->>Validator: validation errors
Validator-->>Client: ValidateResult { ok: false, errors: [...SCHEMA errors] }
end
Validator-->>Client: ValidateResult { ok, errors? }
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Rationale: Heterogeneous additions spanning cryptographic logic (Ed25519 detached signatures, blake3 hashing, keyring management), comprehensive schema validation with 13 invariants enforced across multiple files, and dense logic in validatePatchOps.ts (410 lines with caching, payload canonicalization, and invariant aggregation). Requires careful verification of signature verification correctness, invariant logic soundness, schema enforcement rigor, and cryptographic utility reliability. Multiple high-impact files demand separate reasoning pathways. Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
… Verification - **Patch Validation Kernel**: Strict AJV schema validator + 13-invariant checker - **Ed25519 Signature Verification**: Full detached-signature pipeline with Blake3 digests - **Test Matrix**: 31-test single-fault mutation suite covering all invariants - **Machine Error Codes**: InvariantCode enum for stable, assertable validation errors - **CI Gate**: GitHub workflow for automated patch validation on PRs - `src/validation/validatePatchOps.ts` - Core validator with schema + invariant checking - `src/validation/crypto.ts` - Ed25519 signature verification, Blake3 hashing, canonicalization - `src/validation/InvariantCode.ts` - Structured error codes (13 invariants) - `schemas/PATCH_OPS_SCHEMA.v1.json` - Locked JSON schema for patch operations - `test/matrix/*` - Comprehensive test matrix with golden fixture methodology - `scripts/create-fixture.ts` - Deterministic golden fixture generator - `.github/workflows/patch-ops-gate.yml` - CI gate for patch validation - Fixed 5 AJV strict-mode blockers (if/then schemas, additionalProperties) - Added support for KEY- and did:key:z6 keyId formats - Changed signature to hex encoding (128-char pattern) - Added edge, revertsOpId, schemaVersion properties - 31 tests: 17 invariant tests + 8 schema boundary + 6 signature verification - Single-fault mutation methodology using golden fixture - Test helpers: resignPatch, clonePatch, buildTwoOpPatch, assertInvariantFail - Removed committed test private key, added to .gitignore - Keys derived from deterministic non-secret seed for testing - Keyring-based public key resolution (trust/keyring.json) All tests passing (31/31). Ready for review.
76ce8d6 to
8caf72f
Compare
Fixes: - DepAnalysis: transitiveCount fallback `?? direct` → `?? 0` (#10) Wrong fallback inflated blocker scores for tasks with DONE dependents. - DashboardApp: drawer render guard `> 0` → `> 4` to prevent negative content widths during early animation frames (#4) - DashboardApp: add onComplete to drawer tween for exact snap (#7) - DashboardApp: remove dead `focus-panel` from ViewAction union (#5) - dashboard-view: campaign DAG falls back to declaration order when sortedCampaignIds is empty after filtering (#8) - my-stuff-drawer: guard pw < 10 returns empty string (#1) - my-stuff-drawer: use true pendingReview.length for label (#2) - check-graph-algorithms.sh: quote $SCAN_DIRS (#16) Tests: - Fix drawer test to assert on drawer-unique content (#13) - Add [ / ] view cycling tests with wraparound (#14) - Add 6 renderMyStuffDrawer unit tests (agent scope, empty width, submissions filtering, activity feed, pending count label) (#3) Total: 729 tests (up from 721)
Summary
Extracts the Validation Kernel from Milestone 3 as a standalone, reviewable PR. This provides the cryptographic and schema foundation for patch validation.
InvariantCodeenum for stable, machine-assertable validation errorspatch-ops-gate.yml) for automated patch validation on PRsKey Components
src/validation/validatePatchOps.ts- Core validator with schema + invariant checkingsrc/validation/crypto.ts- Ed25519 signature verification, Blake3 hashing, canonicalizationsrc/validation/InvariantCode.ts- Structured error codes (13 invariants)schemas/PATCH_OPS_SCHEMA.v1.json- Locked JSON schema for patch operationstest/matrix/*- Comprehensive test matrix with golden fixture methodologyscripts/create-fixture.ts- Deterministic golden fixture generator.github/workflows/patch-ops-gate.yml- CI gate for patch validationSchema Hardening
KEY-anddid:key:z6keyId formatsedge,revertsOpId,schemaVersionpropertiesTest Coverage
✅ 31/31 tests passing
Golden fixture methodology with deterministic lineage metadata.
Security
.gitignoretrust/keyring.json)Test Plan
npm test— 31/31 tests passDependencies
This PR is self-contained and has no dependencies. The parent Milestone 3 PR (#4) will be rebased on top of this once merged.
Related