Skip to content

test(cachekit): drive decode-bounds vectors through both ByteStorage.unpack bindings (LAB-6334) - #245

Merged
27Bslash6 merged 5 commits into
mainfrom
lab-6334-unpack-decode-bounds
Oct 23, 2026
Merged

27Bslash6 merged 5 commits into
mainfrom
lab-6334-unpack-decode-bounds

Conversation

@27Bslash6

@27Bslash6 27Bslash6 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What

cachekit-core 0.7.0 (on main since #240) pre-scans the envelope bytes in ByteStorage::retrieve before its typed decode. Nothing in this repo proved that either unpack binding applies it. This PR runs every decode-bounds.json vector (1.2.0, 19 reject / 3 accept) through both envelope entry points:

  • Node lane: decode-bounds.protocol.test.ts gains a ByteStorage.unpack (NAPI) site, new ByteStorage() from @cachekit-io/cachekit-core-ts.
  • Workers lane: a new test/workers/decode-bounds.workers.test.ts runs the same assertions through the wasm ByteStorage.unpack inside workerd.
  • The vector loader, build() and the two envelope assertions move to test/fixtures/decode-bounds-vectors.ts. It has no node:* imports, so workerd loads it. This follows the wire-vectors.ts pattern. The Node lane keeps its sha256 pin over the raw file bytes.
  • The test header no longer says the pinned core has no envelope pre-scan. It now says both lanes cover the envelope entry point.

No production code changes.

The assertions

Each reject vector must throw a message that starts with deserialization failed: decode pre-scan: . The match runs from the start of the message, because a typed-decode error can echo attacker bytes in the middle of its message. The prefix alone is not enough: the pre-scan's own end-of-input rejection carries it too. So, as cachekit-core's tests/decode_bounds_vectors.rs does, depth-only and overclaim-only vectors also pin their rule's reason, while incomplete-only and multi-reason vectors pin the prefix:

  • a vector tagged only depth must give nests deeper than 100 levels, core's envelope bound;
  • a vector tagged only overclaim must give a reason starting declares more .

Each accept vector must get past the pre-scan. These are not envelopes, so core's typed decode refuses them, and the test requires that refusal: deserialization failed: not followed by decode pre-scan: . Any other error, such as a wasm trap, fails the test.

build() hands every site its input as a view at a non-zero offset, with the reserved marker 0xc1 on both sides. A pooled Node Buffer or a network read arrives this way. A decoder that ignores byteOffset, or reads past byteLength, sees bytes that are not the input. The old Buffer.concat build gave the value sites this coverage by accident, through Node's buffer pool. Now it is deliberate, and it reaches both unpack bindings too. The fixture is typed by its JSON import and checked by pnpm type-check:tests, as wire-vectors.ts is.

Evidence

Both bindings were built from source against a mutated copy of cachekit-core 0.7.0, and both lanes were run against each build:

Mutant NAPI lane Workers lane
summed-slot check deleted 9 red (every element-overclaim-only vector) 9 red
depth check deleted 2 red (both depth-only vectors) 2 red
envelope bound 100 → 1024 2 red (both depth-only vectors) 2 red
pre-scan skipped entirely 19 red (every reject vector) 19 red
unmutated 0.7.0 22 green 22 green

The slot-check row is the case a prefix-only assertion misses: with that check gone, every one of those vectors still fails with the decode pre-scan: prefix, at end of input. Dropping byteOffset from the value decoders' DataView (serializer.ts:127) turns 3 value-site tests red.

pnpm lint, pnpm type-check, pnpm type-check:tests, pnpm test (2013 passed, 1 skipped) and pnpm --filter @cachekit-io/cachekit test:workers (193 passed) pass locally.

Docs

No user-facing surface changes. Published @cachekit-io/cachekit 0.2.1 pins cachekit-core-ts and cachekit-core-wasm at exactly 0.2.0, and both of those embed core 0.6.0. So the protocol's SDK feature matrix keeps the TypeScript cells unreleased until a published @cachekit-io/cachekit depends on bindings that embed core 0.7.0. That matrix change is cachekit-io/protocol#203.

…unpack bindings

cachekit-core 0.7.0 pre-scans the envelope bytes in ByteStorage::retrieve before its typed decode. Run every decode-bounds.json vector through the NAPI unpack in the Node lane and the wasm unpack inside workerd, so both envelope entry points prove they apply it.

Reject vectors must fail with the pre-scan message matched from its start; vectors that break one rule alone also pin that rule's reason, because the pre-scan's end-of-input rejection carries the same prefix. Accept vectors must get past the pre-scan. The vector loader and these assertions move to a shared fixture module that workerd can load.
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between b41d3c5 and 3a57806.

📒 Files selected for processing: 1
  • packages/cachekit/test/protocol/decode-bounds.protocol.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Summary by CodeRabbit

  • Tests
    • Added consistent checks across NAPI and Workers for inputs that should be rejected during envelope validation or proceed to deserialisation.
    • Expanded decoding-bound coverage for depth limits and declared-size mismatches.
    • Shared test vectors now ensure both execution environments check the same accepted and rejected inputs, including whether failures occur during envelope validation or later deserialisation.

Walkthrough

The change adds shared helpers for decode-bounds vectors and uses them to test envelope pre-scan behaviour through NAPI and Workers ByteStorage.unpack.

Changes

Decode-bounds test coverage

Layer / File(s) Summary
Shared vectors and assertions
packages/cachekit/test/fixtures/decode-bounds-vectors.ts
Defines typed vectors, builds guarded input buffers, and provides assertions for expected pre-scan rejection or later deserialisation failure.
NAPI and Workers coverage
packages/cachekit/test/protocol/decode-bounds.protocol.test.ts, packages/cachekit/test/workers/decode-bounds.workers.test.ts
Uses the shared assertions to check reject and accept vectors through NAPI and Workers ByteStorage.unpack. The protocol test also retains the fixture hash check and updates its test documentation.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Merge Risk: ⚪ Minimal · up to 3a578

No actionable merge-blocking risk remains from the reviewed changes.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarises the main change: testing decode-bounds vectors through both ByteStorage.unpack bindings.
Description check Passed The description directly explains the shared test vectors, NAPI and Workers coverage, assertions, mutation evidence, and validation results.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@codecov

codecov Bot commented Oct 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Accept vectors now require core's typed-decode failure rather than any error
without the pre-scan tag, so a trap or other non-decode error cannot pass for
"past the pre-scan". build() hands every site an offset view with reserved-marker
guard bytes on both sides, restoring the byteOffset coverage the pooled Buffer
gave the value sites. The fixture is checked by its typed JSON import, as
wire-vectors.ts does, and build() reuses construct().
@kodus-27b

kodus-27b Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the `@kody start-review` command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Providing Context (Files & MCPs)

Add these hints in your PR description (or a comment) to unlock deeper checks:

  • Ticket / Acceptance Criteria: `Refs: ABC-123` (Linear/Jira/Asana/ClickUp/Trello) or a direct ticket link.
  • Bugfix Validation: a Sentry/Datadog/Bugsnag event link (or paste the stack trace/error message).
  • Endpoint Risk: mention the route (e.g., `POST /api/payments`) or controller/action name.
  • Attach a repo file as context: use an explicit marker like `@file:docs/guide.mdx#L10-L50` (replace with your real path).
  • API Contract Docs: include `@file:openapi.yaml` or `@file:swagger.json` when changing routes/schemas.
  • Definition of Done / Standards: include `@file:DOD.md` or `@file:CONTRIBUTING.md` if your repo has them.
  • Design System Source of Truth: include `@file:ui/index.ts` (replace with your DS entrypoint path).
  • Feature Flags: include the flag key/name and `@file:flags.ts` / `@file:config.json` (and optionally the PostHog flag name).
  • Edge/CDN Rules: link the Cloudflare rule/zone or describe the intended redirect/header behavior.
  • Attach an MCP tool output: use `@mcp<provider|tool>` (replace with an installed MCP provider + tool, e.g., `@mcp<sentry|events.search>`).
Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ✅

Access your configuration settings here.

kodus-27b[bot]
kodus-27b Bot previously approved these changes Oct 23, 2026
@kodus-27b

kodus-27b Bot commented Oct 23, 2026

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the `@kody start-review` command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Providing Context (Files & MCPs)

Add these hints in your PR description (or a comment) to unlock deeper checks:

  • Ticket / Acceptance Criteria: `Refs: ABC-123` (Linear/Jira/Asana/ClickUp/Trello) or a direct ticket link.
  • Bugfix Validation: a Sentry/Datadog/Bugsnag event link (or paste the stack trace/error message).
  • Endpoint Risk: mention the route (e.g., `POST /api/payments`) or controller/action name.
  • Attach a repo file as context: use an explicit marker like `@file:docs/guide.mdx#L10-L50` (replace with your real path).
  • API Contract Docs: include `@file:openapi.yaml` or `@file:swagger.json` when changing routes/schemas.
  • Definition of Done / Standards: include `@file:DOD.md` or `@file:CONTRIBUTING.md` if your repo has them.
  • Design System Source of Truth: include `@file:ui/index.ts` (replace with your DS entrypoint path).
  • Feature Flags: include the flag key/name and `@file:flags.ts` / `@file:config.json` (and optionally the PostHog flag name).
  • Edge/CDN Rules: link the Cloudflare rule/zone or describe the intended redirect/header behavior.
  • Attach an MCP tool output: use `@mcp<provider|tool>` (replace with an installed MCP provider + tool, e.g., `@mcp<sentry|events.search>`).
Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ✅

Access your configuration settings here.

kodus-27b[bot]
kodus-27b Bot previously approved these changes Oct 23, 2026
@27Bslash6

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@27Bslash6

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Oct 23, 2026
# Conflicts:
#	packages/cachekit/test/protocol/decode-bounds.protocol.test.ts
@27Bslash6

Copy link
Copy Markdown
Contributor Author

@kody review --force

@kodus-27b

kodus-27b Bot commented Oct 23, 2026

Copy link
Copy Markdown

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the `@kody start-review` command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Providing Context (Files & MCPs)

Add these hints in your PR description (or a comment) to unlock deeper checks:

  • Ticket / Acceptance Criteria: `Refs: ABC-123` (Linear/Jira/Asana/ClickUp/Trello) or a direct ticket link.
  • Bugfix Validation: a Sentry/Datadog/Bugsnag event link (or paste the stack trace/error message).
  • Endpoint Risk: mention the route (e.g., `POST /api/payments`) or controller/action name.
  • Attach a repo file as context: use an explicit marker like `@file:docs/guide.mdx#L10-L50` (replace with your real path).
  • API Contract Docs: include `@file:openapi.yaml` or `@file:swagger.json` when changing routes/schemas.
  • Definition of Done / Standards: include `@file:DOD.md` or `@file:CONTRIBUTING.md` if your repo has them.
  • Design System Source of Truth: include `@file:ui/index.ts` (replace with your DS entrypoint path).
  • Feature Flags: include the flag key/name and `@file:flags.ts` / `@file:config.json` (and optionally the PostHog flag name).
  • Edge/CDN Rules: link the Cloudflare rule/zone or describe the intended redirect/header behavior.
  • Attach an MCP tool output: use `@mcp<provider|tool>` (replace with an installed MCP provider + tool, e.g., `@mcp<sentry|events.search>`).
Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ✅

Access your configuration settings here.

@27Bslash6

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@27Bslash6
27Bslash6 merged commit 2dffdc4 into main Oct 23, 2026
16 checks passed
@27Bslash6
27Bslash6 deleted the lab-6334-unpack-decode-bounds branch October 23, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant