fix(core): preserve Uint8Array in document fields for CBOR round-trip#1721
fix(core): preserve Uint8Array in document fields for CBOR round-trip#1721
Conversation
…R round-trip
sanitizeDocumentFields() treated Uint8Array as a generic object, iterating
numeric keys and producing a plain {} on retrieval. DAG-CBOR natively
supports byte strings, so the fix is to return Uint8Array as-is before
the generic object branch (same pattern as existing Date handling).
Adds regression tests for empty, small, large, nested, array, and
multi-field Uint8Array documents.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
WalkthroughAdds a Uint8Array type check to Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
core/tests/fireproof/uint8array-roundtrip.test.ts (1)
27-28: Minor: redundantnew Uint8Array()wrapping.After asserting
toBeInstanceOf(Uint8Array)on line 27, the wrap on line 28 is unnecessary—you can compare directly:- expect(new Uint8Array(doc.payload)).toEqual(data); + expect(doc.payload).toEqual(data);This pattern repeats in other tests (lines 38, 47, 59-60, 71-72). Not blocking, but simplifies assertions.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@core/tests/fireproof/uint8array-roundtrip.test.ts` around lines 27 - 28, The tests redundantly wrap doc.payload in new Uint8Array after already asserting it is a Uint8Array; update assertions to compare doc.payload directly to data (e.g., replace expect(new Uint8Array(doc.payload)).toEqual(data) with expect(doc.payload).toEqual(data)), and apply the same change for the other occurrences noted (the assertions around lines referencing doc.payload and data in this test file).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@core/tests/fireproof/uint8array-roundtrip.test.ts`:
- Around line 27-28: The tests redundantly wrap doc.payload in new Uint8Array
after already asserting it is a Uint8Array; update assertions to compare
doc.payload directly to data (e.g., replace expect(new
Uint8Array(doc.payload)).toEqual(data) with expect(doc.payload).toEqual(data)),
and apply the same change for the other occurrences noted (the assertions around
lines referencing doc.payload and data in this test file).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f3c4e25e-1acf-43d9-9e96-83b6e5fabed5
📒 Files selected for processing (2)
core/base/crdt-helpers.tscore/tests/fireproof/uint8array-roundtrip.test.ts
core/base/crdt-helpers.ts
Outdated
| }) as T; | ||
| } else if (typeof obj === "object" && obj !== null) { | ||
| // Preserve Uint8Array for CBOR byte string encoding | ||
| if (obj instanceof Uint8Array) { |
There was a problem hiding this comment.
there is. cement ./src/coerce-binary.ts
21:export function isUint8Array(value: unknown): value is Uint8Array {
There was a problem hiding this comment.
why wee need that all test -- one should be enough --- and one who show that this was wrong?
Address PR review: - Replace instanceof Uint8Array with isUint8Array() from @adviser/cement - Reduce test file to 2 tests: basic round-trip + nested (was 6) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
sanitizeDocumentFields()to returnUint8Arrayas-is instead of iterating numeric keys and producing a plain object. DAG-CBOR natively supports byte strings — the sanitizer just needs to not destroy the type.Fixes the known bug from fireproof-legacy.txt where
Uint8Arraystored in docs got converted to{0: 1, 1: 2, ...}plain objects.Test plan
pnpm buildpasses🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests