80 lines
4.6 KiB
TypeScript
80 lines
4.6 KiB
TypeScript
import { test } from '@japa/runner'
|
|
import { DEFAULT_RULES, RuleSet, ownerOf, uploadTool, explored } from '#lib/rules/index'
|
|
import { sevenZipVolume } from '#lib/files/index'
|
|
|
|
const rules = new RuleSet({ ...DEFAULT_RULES, samplePercent: 0, priorities: {}, droppedSignatures: ['nyuu\talt.binaries.misc'] })
|
|
const file = (name: string, totalParts: number, firstMessageId: string, group = 'alt.binaries.ath', poster = 'someone@example.com (Someone)') => ({
|
|
name,
|
|
totalParts,
|
|
groups: [group],
|
|
firstMessageId,
|
|
poster,
|
|
})
|
|
const NGPOST = 'b94268bc702040f7b811d5318f727e4f@ngPost'
|
|
const NYUU = 'FmFwIaTpGgUiSfYcMwFlMeRo-1790637260478@nyuu'
|
|
|
|
test.group('rules / owner', () => {
|
|
test('a crosspost belongs to the indexed group with the lowest priority, whatever the Xref order', ({ assert }) => {
|
|
const priorities = { 'alt.binaries.boneless': 1, 'alt.binaries.ath': 3, 'alt.binaries.added.later': 1001 }
|
|
assert.equal(ownerOf(['alt.binaries.ath', 'alt.binaries.boneless'], priorities), 'alt.binaries.boneless')
|
|
assert.equal(ownerOf(['alt.binaries.added.later', 'alt.binaries.ath'], priorities), 'alt.binaries.ath')
|
|
assert.equal(ownerOf(['alt.binaries.not.indexed'], priorities), null)
|
|
})
|
|
})
|
|
|
|
test.group('rules / verdicts', () => {
|
|
test("a dropped poster's uploads are dropped whatever they are; others with the word in their name are not", ({ assert }) => {
|
|
const pics = (poster: string) => rules.judge('k', [file('!index0001.jpg', 1, NYUU, 'alt.binaries.erotica', poster)])
|
|
assert.include(pics('@_CelebMovie_@'), { rule: 'poster', key: 'celebmovie' })
|
|
assert.include(pics('@__Celeb_Movie__@'), { rule: 'poster', key: 'celebmovie' })
|
|
assert.include(pics('NudeCelebs@CelebWow.com'), { rule: 'poster', key: 'celebwow' })
|
|
assert.include(pics('@nude-celebs'), { rule: 'poster', key: 'nudecelebs' })
|
|
assert.deepEqual(pics('celeborn@not.here (Celeborn)'), { rule: null })
|
|
assert.deepEqual(pics('"CelebTA.com" <from@celebta.com>'), { rule: null })
|
|
assert.deepEqual(new RuleSet({ ...DEFAULT_RULES, droppedPosters: [], samplePercent: 0, priorities: {}, droppedSignatures: [] }).judge('k', [file('a.jpg', 1, NYUU, 'g', '@_CelebMovie_@')]), { rule: null })
|
|
})
|
|
|
|
test('a readable file keeps its whole release', ({ assert }) => {
|
|
assert.deepEqual(rules.judge('k', [file('Hs7dKq2LmZ9xWv3RtYp1Qa.part01.rar', 50, NGPOST), file('Some.Show.S01E01.1080p.nfo', 1, NGPOST)]), { rule: null })
|
|
})
|
|
|
|
test('bare executables are dropped, sidecars aside; an executable among other content is kept', ({ assert }) => {
|
|
assert.include(rules.judge('k', [file('How to Make Love to a Woman 2010.scr', 10, NYUU), file('How to Make Love to a Woman 2010.par2', 1, NYUU)]), { rule: 'executable', key: 'scr' })
|
|
assert.include(rules.judge('k', [file('Adobe Illustrator CS2 + ssg keygen.zip .exe', 3, NYUU)]), { rule: 'executable', key: 'exe' })
|
|
assert.deepEqual(rules.judge('k', [file('Some.App.v1.0.part1.rar', 50, NYUU), file('setup.exe', 2, NYUU)]), { rule: null })
|
|
})
|
|
|
|
test('random names: per-article with few parts, garbage by tool or signature, else kept', ({ assert }) => {
|
|
assert.include(rules.judge('k', [file('Hs7dKq2LmZ9xWv3RtYp1Qa', 2, NYUU)]), { rule: 'per-article', key: 'nyuu' })
|
|
assert.include(rules.judge('k', [file('Hs7dKq2LmZ9xWv3RtYp1Qa.part01.rar', 50, NGPOST)]), { rule: 'garbage', key: 'ngPost alt.binaries.ath' })
|
|
assert.include(rules.judge('k', [file('Hs7dKq2LmZ9xWv3RtYp1Qa.part01.rar', 50, NYUU, 'alt.binaries.misc')]), { rule: 'garbage', key: 'nyuu alt.binaries.misc' })
|
|
assert.deepEqual(rules.judge('k', [file('Hs7dKq2LmZ9xWv3RtYp1Qa.part01.rar', 50, NYUU)]), { rule: null })
|
|
})
|
|
})
|
|
|
|
test.group('rules / upload tools', () => {
|
|
test('posting tools are told apart by their Message-IDs', ({ assert }) => {
|
|
assert.equal(uploadTool(NYUU), 'nyuu')
|
|
assert.equal(uploadTool(NGPOST), 'ngPost')
|
|
assert.equal(uploadTool('part1of69.lOlWzvSHabJCBTVrs0ts@AdultPoster.local'), 'partNofM')
|
|
assert.equal(uploadTool('DLugnv3ZrVBv8Z9I69nU_19o112@JBinUp.local'), 'JBinUp')
|
|
assert.equal(uploadTool('t3Y4mV92YCp0McxDc5@zLZlsw.RYqes'), 'random')
|
|
assert.equal(uploadTool(null), 'other')
|
|
})
|
|
|
|
test('the sampled share is stable per key and about the percentage', ({ assert }) => {
|
|
assert.equal(explored('some-release', 2), explored('some-release', 2))
|
|
const kept = Array.from({ length: 10_000 }, (_, i) => explored(`release-${i}`, 2)).filter(Boolean).length
|
|
assert.isAbove(kept, 150)
|
|
assert.isBelow(kept, 250)
|
|
})
|
|
})
|
|
|
|
test.group('files / volumes', () => {
|
|
test('7z volume numbers', ({ assert }) => {
|
|
assert.equal(sevenZipVolume('x.7z.001'), 1)
|
|
assert.equal(sevenZipVolume('x.7z'), 0)
|
|
assert.isNull(sevenZipVolume('x.rar'))
|
|
})
|
|
})
|