Files
usenet-indexer/tests/functional/release_category.spec.ts
T
Daan MeijerandClaude Fable 5.1 2580f20a43
Test and deploy / test (push) Successful in 51s
Test and deploy / edge (push) Successful in 1m48s
Test and deploy / deploy (push) Skipped
voyager 3: the batch store writes releases once, by id references and bytea keys
Each release chunk is a release inserted once: release_key the SHA-1 of
the identity, the owner group and the first article (deterministic; no
numbering under a group lock), identity_key the identity's SHA-1 bytes,
poster_id and group_set_id through catalog_refs (cached per process),
source as a code (weak-stem added), the name into release_texts. A
finished release's candidates are claimable at once; a provisional tail
release is finished by a later chunk of its key, a finished one sent again
is left alone. Gone: joins into earlier releases and across groups, key
numbering, the group lock, the fragment merger. Interim: chunks, counts
and samples keyed by ranges.block_id, a range without a block gets one.

Readers follow: search (posters and group_sets joined, words through
release_texts, posters by id, source by code), the par2 merger, the
sidecar folder, the judge's scraped rule, the spot inspector, the spotter,
the NZB service, releases:regroup, edge:bench. Tests insert fixtures
through tests/functional/helpers/releases.ts; the suites pass again.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-10-25 21:04:03 +01:00

68 lines
3.9 KiB
TypeScript

import { test } from '@japa/runner'
import db from '@adonisjs/lucid/services/db'
import testUtils from '@adonisjs/core/services/test_utils'
import { insertReleases } from '#tests/functional/helpers/releases'
const categoryOf = async (name: string) => Number((await db.rawQuery(`SELECT release_category(?) AS c`, [name])).rows[0].c)
test.group('Release categories', (group) => {
group.each.setup(() => testUtils.db().withGlobalTransaction())
test('by name: the sources and codes the first function lost or missed, XXX, audio, books, games', async ({ assert }) => {
const expected: [string, number][] = [
// Lost to knex's bindings in migration 1200 (`blu-$1ray`, `web-$2dl`, `h\.$326[45]`).
['Some.Movie.2020.BluRay.DTS-X', 2040],
['Some.Movie.2020.WEB-DL.DDP5', 2030],
['Some.Movie.2020.H.264', 2030],
['Some.Movie.2020.2160p.WEB-DL', 2045],
// TV codes it missed.
['Rizzoli & Isles S01e07[Mux XviD', 5030],
['Rush S04E01E02 WS PDTVXviD', 5030],
['Show.S01E02.1080p.WEB', 5040],
['Show.1x02.HDTV', 5030],
['Resolution 1920x1080 wallpapers', 8010],
['Studio.24.10.22.Some.Name.XXX.1080p.MP4-GRP', 6040],
['Studio.Some.Name.XXX.2160p', 6045],
['Some.Name.XXX.IMAGESET-GRP', 6060],
['Artist-Album-WEB-2026-GRP', 3010],
['Artist - Album (2020) FLAC', 3040],
['Author - Title (Audiobook)', 3030],
['Book.Title.EPUB', 7020],
['Game.Title-CODEX', 4050],
['Game.Title.NSW-VENOM', 1000],
['TsIgNBewuFbuwWy', 8010],
]
const got: [string, number][] = []
for (const [name] of expected) got.push([name, await categoryOf(name)])
assert.deepEqual(got, expected)
})
test("the name's, else the inner name's, else a given one (a spot's), else the groups'", async ({ assert }) => {
const row = (key: string, extra: { name: string } & Record<string, unknown>) => ({ release_key: key.padEnd(40, '0'), identity_key: key.padEnd(40, '0'), source: 'stem', files: 1, groups: '["alt.binaries.misc"]', ...extra })
const [a, b, c, d] = await insertReleases([
row('a', { name: 'Show.S01E02.1080p.WEB' }),
row('b', { name: 'TsIgNBewuFbuwWy' }),
row('c', { name: 'TsIgNBewuFbuwWy', groups: '["alt.binaries.pictures.erotica.puffies"]' }),
// A spot's release of its own, inserted with the spot's category.
row('d', { name: 'Some spot title', category: 2040 }),
])
const letters = new Map([[a, 'a'], [b, 'b'], [c, 'c'], [d, 'd']])
const byName = async () => Object.fromEntries((await db.from('releases').select('id', 'category')).map((r) => [letters.get(Number(r.id)), r.category]))
assert.deepEqual(await byName(), { a: 5040, b: 8010, c: 6060, d: 2040 })
// The prober finds an inner name; a spot links a release (the spot inspector sets a Misc one's category).
await db.from('releases').where('id', b).update({ inner_name: 'Some.Movie.2020.1080p.BluRay.x264-GRP.mkv' })
await db.from('releases').where('id', c).update({ category: 5030 })
await db.from('releases').where('id', c).update({ inner_name: 'nothing.bin' })
assert.deepEqual(await byName(), { a: 5040, b: 2040, c: 5030, d: 2040 })
})
test("a spot's category in Newznab's", async ({ assert }) => {
const { rows } = await db.rawQuery(
`SELECT spot_category(0, '{"a":[9],"z":[0]}') AS movie_hd, spot_category(0, '{"a":[15],"z":[1]}') AS series_uhd, spot_category(0, '{"a":[0],"z":[3]}') AS erotica,
spot_category(0, '{"a":[5]}') AS epub, spot_category(0, '{"z":[4]}') AS picture, spot_category(1, '{"a":[8]}') AS flac, spot_category(1, '{"a":[0],"z":[3]}') AS audiobook,
spot_category(2, '{"a":[0]}') AS pc_game, spot_category(2, '{"a":[12]}') AS console, spot_category(3, '{}') AS app`
)
assert.deepEqual(rows[0], { movie_hd: 2040, series_uhd: 5045, erotica: 6070, epub: 7020, picture: null, flac: 3040, audiobook: 3030, pc_game: 4050, console: 1000, app: 4000 })
})
})