Files
paper-atlas/tests/test_icaps2026.py
codex-bot 4d2df2a826
Metadata integrity checks / metadata (push) Failing after 2m30s
Preserve ICAPS 2026 official acceptance and presentation boundaries
2026-11-17 00:08:49 +08:00

96 lines
5.6 KiB
Python

import gzip
import json
from pathlib import Path
import tempfile
import unittest
from paper_atlas.collectors import icaps2026 as c
class ICAPS2026Test(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.bundle = json.loads(gzip.decompress((Path(__file__).parent/'fixtures/icaps2026-source.json.gz').read_bytes()))
def snapshots(self, root):
root.mkdir()
for name, html in self.bundle['pages'].items():
(root/name).write_text(html)
(root/'manifest.json').write_text(json.dumps(self.bundle['manifest']))
return root
def test_full_listing_matches_independently_recorded_literals(self):
rows = c.parse_listing(self.bundle['pages']['accepted.html'])
self.assertEqual([{k: r[k] for k in ('section', 'title', 'authors_literal')} for r in rows],
[{k: r[k] for k in ('section', 'title', 'authors_literal')} for r in self.bundle['expected']])
self.assertEqual(sum(r['section'] == c.MAIN for r in rows), 90)
self.assertEqual(sum(r['section'] == c.PREVIOUS for r in rows), 10)
self.assertTrue(all(len(r['authors']) >= 2 for r in rows))
def test_incomplete_and_duplicate_listing_rejected(self):
html = self.bundle['pages']['accepted.html']
with self.assertRaises(ValueError):
c.parse_listing(html.replace('class=paper>', 'class=omitted>', 1))
with self.assertRaisesRegex(ValueError, 'repeated paper title'):
c.parse_listing(html.replace(self.bundle['expected'][1]['title'], self.bundle['expected'][0]['title']))
def test_changed_edition_or_section_rejected(self):
html = self.bundle['pages']['accepted.html']
for changed in [html.replace('ICAPS 2026</h1>', 'ICAPS 2027</h1>'),
html.replace(c.MAIN, 'Workshop Papers')]:
with self.assertRaises(ValueError):
c.parse_listing(changed)
def test_ambiguous_author_lists_not_guessed(self):
for literal in ['Anonymous', 'Alice, and Bob', 'Alice and Bob and Carol', 'Alice, Bob and name@example.org']:
with self.assertRaises(ValueError):
c.authors_from_literal(literal)
self.assertEqual(c.authors_from_literal('Augusto B. Corrêa, Simon Dold and Malte Helmert'),
['Augusto B. Corrêa', 'Simon Dold', 'Malte Helmert'])
def test_collection_separates_presentations_and_unresolved_tracks(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp); src = self.snapshots(root/'src'); out = root/'out'
report = c.collect(out, snapshots=src)
self.assertEqual((report['records'], report['previously_published_presentations'], report['missing_abstract_count']), (90, 10, 90))
self.assertEqual(report['public_rejected_availability'], 'unknown')
rows = [json.loads(l) for l in Path(report['files'][0]['file']).read_text().splitlines()]
previous = json.loads((out/report['previously_published_file']).read_text())
self.assertFalse(previous['ingestion_ready']); self.assertEqual(previous['count'], 10)
self.assertFalse({r['title'] for r in rows} & {r['title'] for r in previous['records']})
self.assertTrue(all(r['track'] == 'main_tracks_unclassified' and r['status'] == 'accepted' for r in rows))
self.assertTrue(all(not r['identifiers'] and not r['submission_identifiers'] and r['abstract'] is None and not r['tags'] for r in rows))
self.assertEqual(len({r['external_id'] for r in rows}), 90)
self.assertTrue(all(r['metadata']['source_entry_key']['value'] in r['external_id'] for r in rows))
self.assertFalse(report['database_written']); self.assertFalse(report['pdfs_downloaded'])
self.assertEqual(report['files'][0]['status'], 'partial')
with self.assertRaisesRegex(ValueError, 'Output exists'):
c.collect(out, snapshots=src)
def test_tampering_retains_failure_without_success_receipt(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp); src = self.snapshots(root/'src')
(src/'accepted.html').write_text('tampered')
with self.assertRaisesRegex(ValueError, 'hash changed'):
c.collect(root/'out', snapshots=src)
self.assertTrue((root/'out/failed.json').exists())
self.assertFalse((root/'out/collection-report.json').exists())
def test_receipt_redirect_naive_time_and_duplicate_source_rejected(self):
for kind in ('redirect', 'time', 'duplicate'):
with self.subTest(kind=kind), tempfile.TemporaryDirectory() as tmp:
root = Path(tmp); src = self.snapshots(root/'src'); p = src/'manifest.json'; r = json.loads(p.read_bytes())
if kind == 'redirect': r['sources'][0]['final_url'] = 'https://example.org/challenge'
if kind == 'time': r['at'] = '2026-11-16T12:00:00'
if kind == 'duplicate': r['sources'][1] = r['sources'][0]
p.write_text(json.dumps(r))
with self.assertRaises(ValueError):
c.collect(root/'out', snapshots=src)
self.assertFalse((root/'out/collection-report.json').exists())
def test_snapshot_symlink_rejected(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp); src = self.snapshots(root/'src'); p = src/'accepted.html'; raw = p.read_bytes(); p.unlink(); target = root/'external.html'; target.write_bytes(raw); p.symlink_to(target)
with self.assertRaisesRegex(ValueError, 'Unsafe'):
c.collect(root/'out', snapshots=src)