// SPDX-License-Identifier: GPL-3.0-only // Copyright (C) 2026 poli0981 (SkullMute) // // quarantine.mjs (hard rule 5: move, never delete) and extract-urls.mjs (the // lychee feed) — the two scripts the scheduled workflows run. import { existsSync, readFileSync } from 'node:fs'; import { join } from 'node:path'; import { describe, expect, it } from 'vitest'; import { project, run } from './fixture'; const entry = (status: string, links: Record = {}, evidence?: string) => JSON.stringify({ name: 'X', links, security: { status, evidence } }); describe('quarantine', () => { it('moves flagged entries out of the content tree and reports them to the workflow', () => { const root = project({ 'src/data/apps/bad-app.json': entry('flagged'), 'src/data/apps/good-app.json': entry('clean'), 'src/data/apps/broken.json': '{ nope', }); const r = run('quarantine.mjs', root, { env: { GITHUB_OUTPUT: join(root, 'out.txt') } }); expect(r.code).toBe(0); expect(r.out).toContain('moved bad-app.json → data/quarantine/'); expect(r.out).toContain('skipping unparseable broken.json'); expect(existsSync(join(root, 'src/data/apps/bad-app.json'))).toBe(false); expect(readFileSync(join(root, 'data/quarantine/bad-app.json'), 'utf8')).toBe(entry('flagged')); expect(existsSync(join(root, 'src/data/apps/good-app.json'))).toBe(true); expect(readFileSync(join(root, 'out.txt'), 'utf8')).toBe('moved=bad-app\n'); }); it('is idempotent, and reports an empty move list', () => { const root = project({ 'src/data/apps/good-app.json': entry('clean') }); const r = run('quarantine.mjs', root, { env: { GITHUB_OUTPUT: join(root, 'out.txt') } }); expect(r.out).toContain('nothing flagged'); expect(readFileSync(join(root, 'out.txt'), 'utf8')).toBe('moved=\n'); }); it('never overwrites a quarantined file, and never moves a malformed slug', () => { const root = project({ 'src/data/apps/twice.json': entry('flagged'), 'data/quarantine/twice.json': entry('flagged', { homepage: 'https://old.test/' }), 'src/data/apps/Not A Slug.json': entry('flagged'), }); const r = run('quarantine.mjs', root); expect(r.code).toBe(1); expect(r.out).toContain('twice.json already in quarantine — leaving both for review'); expect(r.out).toContain('refusing to move Not A Slug.json'); expect(existsSync(join(root, 'src/data/apps/twice.json'))).toBe(true); expect(readFileSync(join(root, 'data/quarantine/twice.json'), 'utf8')).toContain('old.test'); }); }); describe('extract-urls', () => { const apps = { 'src/data/apps/a.json': entry( 'clean', { homepage: 'https://b.test/', repo: null }, 'https://vt.test/a', ), 'src/data/apps/b.json': entry('clean', { homepage: 'https://a.test/', download: 'https://b.test/', }), }; it('prints every official URL once, sorted', () => { const r = run('extract-urls.mjs', project(apps)); expect(r.code).toBe(0); expect(r.stdout).toBe('https://a.test/\nhttps://b.test/\nhttps://vt.test/a\n'); }); it('with --added, checks only the URLs on lines a diff adds', () => { // A re-check PR rewrites evidence; a data PR adds a whole new file. const diff = [ 'diff --git a/src/data/apps/a.json b/src/data/apps/a.json', '--- a/src/data/apps/a.json', '+++ b/src/data/apps/a.json', '@@ -19,2 +19,2 @@', '- "evidence": "https://vt.test/old",', '+ "evidence": "https://vt.test/new",', '- "checkedAt": "2026-07-30"', '+ "checkedAt": "2026-10-23"', 'diff --git a/src/data/apps/new.json b/src/data/apps/new.json', '+++ b/src/data/apps/new.json', '+ "homepage": "https://new.test",', '+ "repo": null,', '+ "download": "https://new.test/get?os=win",', ' unchanged "https://context.test/"', ].join('\n'); const r = run('extract-urls.mjs', project(apps), { args: ['--added'], input: diff }); expect(r.code).toBe(0); expect(r.stdout).toBe('https://new.test\nhttps://new.test/get?os=win\nhttps://vt.test/new\n'); }); it('with --added and an empty diff, prints nothing', () => { const r = run('extract-urls.mjs', project(apps), { args: ['--added'], input: '' }); expect(r.code).toBe(0); expect(r.stdout).toBe(''); }); it('keeps going past a malformed file, but fails the run', () => { const root = project({ ...apps, 'src/data/apps/c.json': '{' }); const r = run('extract-urls.mjs', root); expect(r.code).toBe(1); expect(r.out).toContain('skipping c.json'); expect(r.stdout).toContain('https://vt.test/a'); }); });