Files
PotentialStorage/test/utils/extended-json.test.ts
T
Claude df7de27e20
CI / Node 24 (pull_request) Successful in 11s
CI / Node 26 (pull_request) Successful in 12s
CI / Node 22 (pull_request) Successful in 13s
Composite: don't undo writes made while a full sync is scanning
A write made during a full sync could be scanned in the replica but not in
the (read-ahead) source scan, so the diff removed it, and echo tracking then
consumed the server's echo. Keys written during a sync are now left out of
the diff. Deterministic regression test with a read-ahead source.

Also exclude -0 from the Extended JSON property test (JSON has no -0).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017Qxbkp4tA7G5SCWjzWuxmE
2026-10-23 08:47:18 +00:00

33 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import fc from 'fast-check'
import { ExtendedJson } from '../../src/utils/extended-json.js'
describe('ExtendedJson', () => {
it('round-trips bigint and Uint8Array, nested anywhere', () => {
const value = { a: 1n, b: [new Uint8Array([0, 1, 255]), -(2n ** 70n)], c: { d: new Uint8Array(0), e: 'plain', f: null } }
expect(ExtendedJson.stringify({ n: 5n, bytes: new Uint8Array([171, 205]) })).toBe('{"n":"<bigint: 5n>","bytes":"<uint8array: abcd>"}')
expect(ExtendedJson.parse(ExtendedJson.stringify(value))).toEqual(value)
})
it('round-trips arbitrary data (property)', () => {
const data = fc.letrec((tie) => ({
value: fc.oneof(
{ depthSize: 'small' },
fc.bigInt(),
fc.uint8Array(),
fc.string(),
fc.double({ noNaN: true, noDefaultInfinity: true }).map((x) => (x === 0 ? 0 : x)) /* JSON has no -0 */,
fc.boolean(),
fc.constant(null),
fc.array(tie('value')),
fc.dictionary(fc.string(), tie('value')),
),
})).value
fc.assert(
fc.property(data, (v) => {
expect(ExtendedJson.parse(ExtendedJson.stringify(v))).toEqual(v)
}),
)
})
})