Judge the releases whose facts changed every 2 minutes, all daily
Test and deploy / test (push) Successful in 51s
Test and deploy / edge (push) Successful in 2m3s
Test and deploy / deploy (push) Successful in 1m5s

A full round took 35-38 min of each hour and grew with every inspection
the prober added. Triggers note changed releases in judge_dirty; the
judge judges those (and releases a file hash of theirs tipped to
repeated) by every rule, and every release in a daily full round for
what time changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daan MeijerandClaude Opus 5.5 committed 2026-10-19 20:10:49 +02:00
1 parent 036e2a8397
commit 76e52f69ce
6 files changed
+366 -63

No files matched your search

+73 -2
View File
@@ -80,7 +80,7 @@ test.group('ReleaseJudge', (group) => {
const spotted = await release('yy12CD34ef56GH78ij90', { readable: false, ...placed })
await db.table('release_spots').insert({ release_id: spotted, spot_id: 's@x', files: 1 })
const round = await new ReleaseJudge().round()
const round = await new ReleaseJudge().full()
const verdicts = new Map((await db.from('release_verdicts').select('release_id', 'rule')).map((v) => [Number(v.release_id), v.rule]))
assert.equal(verdicts.get(dead), 'dead')
assert.isUndefined(verdicts.get(halfDead))
@@ -107,11 +107,82 @@ test.group('ReleaseJudge', (group) => {
// A password found: the next round takes the verdict back.
await db.table('release_passwords').insert({ release_id: locked, password: 'found', source: 'nzb' })
const again = await new ReleaseJudge().round()
const again = await new ReleaseJudge().full()
assert.equal(again.rules.locked.removed, 1)
// Verdicts that stay are not written again.
assert.equal(again.rules.repeated.added, 0)
assert.equal(again.rules.fake.added, 0)
assert.isNull(await db.from('release_verdicts').where('release_id', locked).first())
})
test('judges the releases whose facts changed, and those a hash of theirs tipped over', async ({ assert }) => {
let n = 0
const settled = new Date(Date.now() - 3 * 86400_000)
const release = async (name: string, extra: Record<string, unknown> = {}) => {
n++
const key = `jc${String(n).padStart(6, '0')}`.padEnd(40, '0')
const [row] = await db
.table('releases')
.insert({ release_key: key, identity_key: key, name, source: 'stem', groups: '[]', files: 3, posted_at: settled, readable: true, settled_at: settled, ...extra })
.returning('id')
return Number(row.id)
}
const judge = new ReleaseJudge()
const verdict = async (id: number) => (await db.from('release_verdicts').where('release_id', id).first())?.rule
const dirty = async () => Number((await db.from('judge_dirty').count('* as n'))[0].n)
// New releases are noted; a passworded one is locked, until a password turns up.
const locked = await release('Locked.Thing', { passworded: true })
assert.isAbove(await dirty(), 0)
let round = await judge.changed()
assert.equal(await verdict(locked), 'locked')
assert.equal(round.rules.locked.added, 1)
assert.equal(await dirty(), 0)
await db.table('release_passwords').insert({ release_id: locked, password: 'pw', source: 'nzb' })
round = await judge.changed()
assert.isUndefined(await verdict(locked))
assert.equal(round.rules.locked.removed, 1)
// Probes: a release whose probed articles are all missing is dead once the prober's statuses come in.
const dead = await release('Gone.Movie.2020.1080p')
const ids = await db.table('probe_candidates').multiInsert([
{ release_id: dead, kind: 'lone', message_id: '<jc1@x>', file: 'a', status: 'waiting' },
{ release_id: dead, kind: 'lone', message_id: '<jc2@x>', file: 'b', status: 'waiting' },
]).returning('id')
await judge.changed()
assert.isUndefined(await verdict(dead))
await db.from('probe_candidates').whereIn('id', ids.map((r: { id: string }) => r.id)).update({ status: 'missing' })
await judge.changed()
assert.equal(await verdict(dead), 'dead')
// One file in 19 releases, one of them locked: the 20th makes them all repeated, the locked one too (repeated
// comes first), though only the 20th changed.
const hash = 'b'.repeat(32)
const holders: number[] = []
for (let i = 0; i < 19; i++) holders.push(await release(`holder${i}`, i === 0 ? { passworded: true } : {}))
for (const [i, id] of holders.entries()) await db.table('file_hashes').insert({ candidate_id: 30000 + i, release_id: id, hash16k: hash, size: 5000 })
await judge.changed()
assert.equal(await verdict(holders[0]), 'locked')
assert.isUndefined(await verdict(holders[1]))
const twentieth = await release('holder19')
await db.table('file_hashes').insert({ candidate_id: 30019, release_id: twentieth, hash16k: hash, size: 5000 })
round = await judge.changed()
assert.equal(round.releases, 20)
const rules = new Set()
for (const id of [...holders, twentieth]) rules.add(await verdict(id))
assert.deepEqual([...rules], ['repeated'])
// A verdict nothing noted stays until the full round; it's due a day after the last one.
const stale = await release('Fine.Release')
await judge.changed()
await db.table('release_verdicts').insert({ release_id: stale, rule: 'fake', rule_version: 1 })
await judge.changed()
assert.equal(await verdict(stale), 'fake')
await db.from('judge_state').update({ full_at: new Date(Date.now() - 2 * 86400_000) })
assert.isTrue(await judge.fullDue())
round = await judge.full()
assert.isUndefined(await verdict(stale))
assert.equal(await verdict(dead), 'dead')
assert.isFalse(await judge.fullDue())
})
})