Initial commit

This commit is contained in:
2026-04-08 11:55:27 +01:00
commit 470a1c15b8
36 changed files with 4932 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
import assert from "node:assert/strict";
import test from "node:test";
import {
computeBinaryHash,
decryptBytes,
encryptBytes,
generateVaultKey,
mergeTextRevisions
} from "../../packages/sync-engine/src";
test("encryptBytes round-trips binary payloads", async () => {
const vaultKey = await generateVaultKey("test-key");
const original = new Uint8Array([1, 2, 3, 4, 5]).buffer;
const encrypted = await encryptBytes(original, vaultKey);
const decrypted = await decryptBytes(encrypted, vaultKey);
assert.deepEqual([...new Uint8Array(decrypted)], [1, 2, 3, 4, 5]);
});
test("computeBinaryHash is stable for identical binary payloads", async () => {
const first = await computeBinaryHash(new Uint8Array([9, 8, 7, 6]).buffer);
const second = await computeBinaryHash(new Uint8Array([9, 8, 7, 6]).buffer);
assert.equal(first, second);
});
test("mergeTextRevisions reports conflicts when both sides diverge", () => {
const result = mergeTextRevisions({
base: "alpha",
local: "alpha local",
remote: "alpha remote"
});
assert.equal(result.status, "conflict");
assert.match(result.content, /<<<<<<< LOCAL/);
assert.match(result.content, />>>>>>> REMOTE/);
});