import base64 import gzip import hashlib import json from pathlib import Path import tempfile import unittest from paper_atlas.collectors import recsys2026 as c class RecSys2026Test(unittest.TestCase): @classmethod def setUpClass(cls): cls.fixture=json.loads(gzip.decompress((Path(__file__).parent/'fixtures/recsys2026-source.json.gz').read_bytes())) cls.files={n:base64.b64decode(raw) for n,raw in cls.fixture['files'].items()} cls.body=cls.files[c.SNAPSHOT+'/recsys-contributions.html'] def materialize(self,root): for name,raw in self.files.items(): path=root/name;path.parent.mkdir(parents=True,exist_ok=True);path.write_bytes(raw) def test_all263_observations_against_independent_gold(self): items=c.parse_program(self.body) keys=self.fixture['independent_gold'][0].keys() self.assertEqual([{k:r[k] for k in keys} for r in items],self.fixture['independent_gold']) self.assertEqual(len(items),263);self.assertEqual(len({r['doi'] for r in items}),260) self.assertEqual(sum(bool(r['review_flags']) for r in items),6) variants=[r for r in items if r['doi']=='10.1145/3773078.3831839'] self.assertNotEqual(variants[0]['title'],variants[1]['title']);self.assertNotEqual(variants[0]['authors'],variants[1]['authors']) self.assertNotEqual(variants[0]['abstract'],variants[1]['abstract']) def test_installed_format_tracks_evidence_and_original_fields(self): with tempfile.TemporaryDirectory() as tmp: root=Path(tmp);src=root/'src';self.materialize(src);out=root/'out' report=c.collect(out,snapshots=src) self.assertEqual((report['records'],report['unique_dois'],report['missing_abstract_count']),(263,260,0)) self.assertFalse(report['database_written']);self.assertFalse(report['pdfs_downloaded']);self.assertEqual(report['network_requests'],0);self.assertEqual(report['approved_for_import'],0) self.assertEqual(report['track_counts'],{k:n for k,_,n in c.TRACKS});self.assertEqual(report['duplicate_doi_observations'],6) gold={r['locator']:r for r in self.fixture['independent_gold']};seen=set() for manifest in report['files']: path=Path(manifest['file']);raw=path.read_bytes();self.assertEqual(hashlib.sha256(raw).hexdigest(),manifest['file_sha256']) rows=[json.loads(l) for l in raw.splitlines()];self.assertEqual(len(rows),manifest['count']);self.assertEqual(manifest['status'],'partial') for r in rows: item=r['metadata']['program_fields'];locator=item['locator'];seen.add(locator);expected=gold[locator] for key in expected:self.assertEqual(item[key],expected[key]) self.assertEqual(r['external_id'],'2026/'+locator);self.assertEqual(r['title'],expected['title']);self.assertEqual(r['authors'],expected['authors']);self.assertEqual(r['abstract'],expected['abstract']) self.assertEqual(r['track'],manifest['track']);self.assertEqual(r['identifiers'],{'doi':expected['doi']});self.assertEqual(r['submission_identifiers'],[{'scheme':'publication_doi','value':expected['doi']}]) self.assertEqual(r['tags'],[{'namespace':'recsys_program:contribution_type','value':expected['type_labels'][0]}]);self.assertFalse(r['metadata']['original_decision_signature_verified']) self.assertEqual(seen,set(gold));self.assertEqual((out/'evidence/recsys-contributions.html').read_bytes(),self.body) with self.assertRaisesRegex(ValueError,'Output exists'):c.collect(out,snapshots=src) def test_edition_and_track_label_drift_rejected(self): for old,new in [(b'RecSys 26 - Accepted Contributions',b'RecSys 25 - Accepted Contributions'),(b'>Long Papers',b'>Workshops'),(b"title='Research'",b"title='Unreviewed'")]: with self.subTest(old=old),self.assertRaises(ValueError):c.parse_program(self.body.replace(old,new,1)) def test_duplicate_locator_missing_author_and_foreign_doi_rejected(self): for old,new in [(b'accordion-1-slide-2"',b'accordion-1-slide-1"'),(b'by Md Aminul Islam, Kathryn Vasilaky and Elena Zheleva',b'by '),(b'https://doi.org/10.1145/3773078.3831824',b'https://doi.org/10.1145/9999999.3831824')]: with self.subTest(old=old),self.assertRaises(ValueError):c.parse_program(self.body.replace(old,new,1)) def test_math_markup_requires_review_and_is_not_flattened(self): changed=self.body.replace(b'Learning-to-rank (LTR)',b'Learning-to-rank 2 (LTR)',1) with self.assertRaisesRegex(ValueError,'markup'):c.parse_program(changed) def test_corruption_and_missing_receipt_body_preserve_failure(self): for kind in ('manifest','body','missing'): with tempfile.TemporaryDirectory() as tmp: root=Path(tmp);src=root/'src';self.materialize(src);path=src/c.SNAPSHOT/('manifest.json' if kind=='manifest' else 'recsys-contributions.html') if kind=='missing':path.unlink() else:path.write_bytes(path.read_bytes()+b' ') with self.assertRaises((ValueError,FileNotFoundError)):c.collect(root/'out',snapshots=src) self.assertTrue((root/'out/failed.json').exists());self.assertFalse((root/'out/collection-report.json').exists()) def test_symlink_source_and_root_rejected(self): for kind in ('source','root'): with tempfile.TemporaryDirectory() as tmp: root=Path(tmp);src=root/'src';self.materialize(src);path=src/c.SNAPSHOT/'recsys-contributions.html' if kind=='source' else src original=path.with_name(path.name+'-original');path.rename(original);path.symlink_to(original,target_is_directory=kind=='root') with self.assertRaisesRegex(ValueError,'Unsafe'):c.collect(root/'out',snapshots=src)