40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
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/);
|
|
});
|