Files
usenet-indexer/tests/unit/edge/scan.spec.ts
T
Daan MeijerandClaude Opus 5.5 03ca96b255
Test and deploy / test (push) Successful in 47s
Test and deploy / edge (push) Successful in 1m45s
Test and deploy / deploy (push) Successful in 2m5s
Fix findCounter infinite loop; corpus filter skips chunks past 256 MB
lastIndexOf('(', -1) searches from 0 again, so a subject starting with a "("
that isn't a counter, without a quote, looped forever. The corpus filter hit
it at 11:23 on Oct 24: the coordinator (and corpus:filter) spun at 100% CPU
for 10 hours and no range finished. The Rust find_counter stops at 0 already.

A chunk inflating past V8's longest string can't be filtered as text; such a
chunk is now stored unfiltered instead of throwing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 21:08:22 +02:00

45 lines
3.5 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'))
// A "(" at the start that isn't a counter, no quote: no segment (it looped forever, LOG.md 2026-10-24 (102)).
assert.isNull(scanner.segment(9, '(Some Show) S01E01 x264', 'p', '', '<o@x>', '1', xref, 'alt.binaries.test'))
assert.equal(scanner.segment(9, '(Some Show) S01E01.mkv (3/9)', 'p', '', '<o@x>', '1', xref, 'alt.binaries.test')?.number, 3)
})
})