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
54
55
56
57
58
59
import assert from "node:assert/strict";
import { test } from "node:test";
import { safeParse } from "@atcute/lexicons/validations";
import { IngestBatchSchema, checkIngestBatch, namespaceOf } from "../src/ingest";
const segment = {
idx: 6000,
name: "seg_00000004mo.jss",
sizeBytes: 268937693,
checksum: "0a1b2c3d4e5f6071",
eventCount: 3178197,
blockCount: 818,
minSeq: 21322223343,
maxSeq: 21325402013,
minWitnessedAt: 1785768533809776,
maxWitnessedAt: 1785768618450665,
collections: [
{ nsid: "app.bsky.feed.like", count: 1885670 },
{ nsid: "app.bsky.feed.post", count: 620964 },
],
} as const;
test("accepts a well-formed batch and preserves values", () => {
const result = safeParse(IngestBatchSchema, { segments: [segment] });
assert.ok(result.ok);
assert.equal(result.value.segments.length, 1);
assert.deepEqual(result.value.segments[0], segment);
assert.equal(checkIngestBatch(result.value), null);
});
test("rejects an empty batch", () => {
assert.equal(safeParse(IngestBatchSchema, { segments: [] }).ok, false);
});
test("rejects non-integer counts", () => {
const bad = { ...segment, collections: [{ nsid: "app.bsky.feed.like", count: "many" }] };
assert.equal(safeParse(IngestBatchSchema, { segments: [bad] }).ok, false);
});
test("flags duplicate collections within a segment", () => {
const dup = { ...segment, collections: [...segment.collections, { nsid: "app.bsky.feed.like", count: 1 }] };
const result = safeParse(IngestBatchSchema, { segments: [dup] });
assert.ok(result.ok);
assert.match(checkIngestBatch(result.value) ?? "", /duplicate nsid/);
});
test("flags seq ranges that run backwards", () => {
const result = safeParse(IngestBatchSchema, { segments: [{ ...segment, minSeq: 5, maxSeq: 4 }] });
assert.ok(result.ok);
assert.match(checkIngestBatch(result.value) ?? "", /maxSeq < minSeq/);
});
test("namespaceOf takes the first two labels", () => {
assert.equal(namespaceOf("app.bsky.feed.like"), "app.bsky");
assert.equal(namespaceOf("net.anisota.beta.game.log"), "net.anisota");
assert.equal(namespaceOf("sh.tangled"), "sh.tangled");
});