import { test } from 'node:test'; import assert from 'node:assert/strict'; import { applyOverlay, blobCid, diffAgainstBase } from '../src/index.ts'; test('diffAgainstBase without a base returns the whole tree sorted by path', () => { const current = new Map([ ['src/main.ts', 'cid-main'], ['index.html', 'cid-index'], ]); assert.deepEqual( [...diffAgainstBase(undefined, current)], [ ['index.html', 'cid-index'], ['src/main.ts', 'cid-main'], ], ); }); test('diffAgainstBase with a base returns changed and added paths, and null for removed ones', () => { const base = new Map([ ['README.md', 'cid-readme'], ['index.html', 'cid-index'], ['old.js', 'cid-old'], ]); const current = new Map([ ['README.md', 'cid-readme'], ['index.html', 'cid-index-2'], ['src/new.ts', 'cid-new'], ]); assert.deepEqual( [...diffAgainstBase(base, current)], [ ['index.html', 'cid-index-2'], ['old.js', null], ['src/new.ts', 'cid-new'], ], ); }); test('applyOverlay replaces, adds, and deletes base paths', () => { const base = new Map([ ['README.md', 'readme'], ['index.html', 'v1'], ['old.js', 'old'], ]); const overlay = new Map([ ['index.html', 'v2'], ['old.js', null], ['a.txt', 'a'], ]); assert.deepEqual( [...applyOverlay(base, overlay)], [ ['README.md', 'readme'], ['a.txt', 'a'], ['index.html', 'v2'], ], ); }); test('blobCid matches the raw sha-256 CIDs a PDS assigns', async () => { assert.equal(await blobCid(new Uint8Array()), 'bafkreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku'); assert.equal( await blobCid(new TextEncoder().encode('

hi

')), 'bafkreihh7o3pxp2m4kkjcpvwfnj76a5hkrtett64bwbe3hr2fncucubpp4', ); });