~james/core

core/web/src/lib/migration/liar.test.ts -rw-r--r-- 1.7 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { describe, expect, it } from "vitest";
import { readLiarRecords } from "#lib/migration/liar.ts";
import { buildRepoCar } from "#lib/migration/repoCar.ts";

const streamOf = (bytes: Uint8Array) =>
	new Blob([bytes as BlobPart]).stream() as ReadableStream<Uint8Array>;

const did = "did:plc:alice";
const star = { $type: "org.tangled.feed.star", createdAt: "2026-01-01T00:00:00.000Z" };

describe("readLiarRecords", () => {
	it("keeps org.tangled records and drops everything else", async () => {
		const car = await buildRepoCar(did, [
			{ collection: "org.tangled.feed.star", rkey: "3aaaaaaaaaaaa", value: star },
			{
				collection: "org.tangled.actor.profile",
				rkey: "self",
				value: { $type: "org.tangled.actor.profile", description: "hi" }
			},
			{
				collection: "app.bsky.feed.post",
				rkey: "3bbbbbbbbbbbb",
				value: { $type: "app.bsky.feed.post", text: "x", createdAt: star.createdAt }
			}
		]);

		const records = await readLiarRecords(streamOf(car));

		expect(records.map((r) => `${r.collection}/${r.rkey}`).sort()).toEqual([
			"org.tangled.actor.profile/self",
			"org.tangled.feed.star/3aaaaaaaaaaaa"
		]);
		expect(records.find((r) => r.rkey === "self")?.value).toEqual({
			$type: "org.tangled.actor.profile",
			description: "hi"
		});
	});

	it("reads every record when two of them are identical and share a block", async () => {
		const car = await buildRepoCar(
			did,
			[
				{ collection: "org.tangled.feed.star", rkey: "3aaaaaaaaaaaa", value: star },
				{ collection: "org.tangled.feed.star", rkey: "3bbbbbbbbbbbb", value: star }
			],
			{ recordBlocksFirst: true }
		);

		const records = await readLiarRecords(streamOf(car));

		expect(records.map((r) => r.rkey).sort()).toEqual(["3aaaaaaaaaaaa", "3bbbbbbbbbbbb"]);
	});
});