Files
usenet-indexer/tests/unit/edge/scan.spec.ts
T
Daan MeijerandClaude Opus 5.5 638cfa1dcd
Test and deploy / test (push) Successful in 22s
Test and deploy / deploy (push) Skipped
Rebuild: a lean overview scan for the edge worker
The worker reads the XOVER reply's text directly: fields by position, the
owner from the Xref without arrays (crossposts leave before any subject
parsing), a subject parsed once per file (cached without its segment
counter), a file's details as one shared object, dates as numbers.
Garbage collection had been ~22% of the time.

Same results as parseOverviews + segmentFromHeader on 800k real lines.
edge:bench (one core): boneless 137k → 193k headers/s (CPU 21 → 12.8 s),
ath (2013) 143k → 303k; peak RSS 1.15 / 0.87 GB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 01:13:41 +02:00

42 lines
3.1 KiB
TypeScript

import { test } from '@japa/runner'
import { SegmentScanner, scanOverviewText } from '#lib/edge/scan'
import { segmentFromHeader } from '#lib/headers/index'
const priorities = { 'alt.binaries.boneless': 1, 'alt.binaries.test': 2 }
test.group('edge / scanOverviewText and SegmentScanner', () => {
test('reads the fields of overview lines, Xref without its name', ({ assert }) => {
const text =
'101\tShow - "a.mkv" yEnc (1/2)\tposter <p@x>\tMon, 05 Oct 2026 10:00:00 +0000\t<one@test>\t\t700000\t5000\tXref: news.example alt.binaries.test:101\r\n' +
'102\tShow - "a.mkv" yEnc (2/2) 1234\tposter <p@x>\tMon, 05 Oct 2026 10:00:01 +0000\t<two@test>\t<ref@x>\t1234\t10\tXref: news.example alt.binaries.test:102 alt.binaries.boneless:9\r\n'
const lines: string[][] = []
scanOverviewText(text, (...fields) => lines.push(fields.map(String)))
assert.deepEqual(lines, [
['101', 'Show - "a.mkv" yEnc (1/2)', 'poster <p@x>', 'Mon, 05 Oct 2026 10:00:00 +0000', '<one@test>', '700000', 'news.example alt.binaries.test:101'],
['102', 'Show - "a.mkv" yEnc (2/2) 1234', 'poster <p@x>', 'Mon, 05 Oct 2026 10:00:01 +0000', '<two@test>', '1234', 'news.example alt.binaries.test:102 alt.binaries.boneless:9'],
])
})
test('the owner is the indexed group with the lowest priority in the Xref', ({ assert }) => {
const scanner = new SegmentScanner()
assert.equal(scanner.owner('news.example alt.binaries.test:5 alt.binaries.boneless:9', 'alt.binaries.test', priorities), 'alt.binaries.boneless')
assert.equal(scanner.owner('news.example alt.binaries.test:5 alt.binaries.other:9', 'alt.binaries.test', priorities), 'alt.binaries.test')
assert.equal(scanner.owner('news.example', 'alt.binaries.test', priorities), 'alt.binaries.test')
})
test('segments match segmentFromHeader, and share their file details', ({ assert }) => {
const scanner = new SegmentScanner()
const subject = (n: number) => `[03/10] - "Some.Release.part02.rar" yEnc (${n}/137) 51315352`
const xref = 'news.example alt.binaries.test:7'
const a = scanner.segment(7, subject(12), 'poster <p@x>', 'Mon, 05 Oct 2026 10:00:00 +0000', '<m12@x>', '700000', xref, 'alt.binaries.test')!
const b = scanner.segment(8, subject(13), 'poster <p@x>', 'Mon, 05 Oct 2026 10:00:00 +0000', '<m13@x>', '700000', xref, 'alt.binaries.test')!
const old = segmentFromHeader({ 'subject': subject(12), 'from': 'poster <p@x>', 'date': 'Mon, 05 Oct 2026 10:00:00 +0000', 'message-id': '<m12@x>', ':bytes': '700000', 'xref': xref }, 'alt.binaries.test', 7)!
assert.deepEqual([a.fileKey, a.number, a.totalParts, a.messageId, a.bytes, a.file.name, a.file.groups, a.file.release?.key], [old.fileKey, old.number, old.totalParts, old.messageId, old.bytes, old.name, old.groups, old.release?.key])
assert.strictEqual(a.file, b.file)
assert.equal(b.number, 13)
// Obfuscated, or a counter only before the name: no segment.
assert.isNull(scanner.segment(9, 'Xq8r2KdLm3Zw91PqA7zz', 'p', '', '<o@x>', '1', xref, 'alt.binaries.test'))
assert.isNull(scanner.segment(9, '(1/2) "x.bin" yEnc', 'p', '', '<o@x>', '1', xref, 'alt.binaries.test'))
})
})