from pathlib import Path import tempfile import unittest from intelligence_radar.publications import publish, verify from intelligence_radar.store import put class PublicationTests(unittest.TestCase): def setUp(self): self.temp = tempfile.TemporaryDirectory() self.addCleanup(self.temp.cleanup) self.root = Path(self.temp.name) self.capture = put(self.root, 'captures', {'source': 'example', 'content_sha256': 'abc'}) def publication(self, **extra): value = {'schema_version': 1, 'title': 'Two profiles, no winner', 'reviewer': 'ada', 'reviewed_at': '2026-10-04T12:00:00+00:00', 'claims': [{'statement': 'The capture lists a price.', 'disposition': 'included', 'capture_id': self.capture}, {'statement': 'No access evidence.', 'disposition': 'excluded', 'exclusion_reason': 'Requester access was not observed.'}]} value.update(extra) return value def test_publication_links_captures_and_is_not_a_draft(self): ident = publish(self.root, self.publication()) self.assertEqual(publish(self.root, self.publication()), ident) text = (self.root / 'digests' / 'reviewed' / f'{ident}.md').read_text(encoding='utf-8') self.assertTrue(text.startswith('# Reviewed publication\n')) self.assertIn(self.capture, text) self.assertIn('Requester access was not observed.', text) self.assertFalse((self.root / 'digests' / 'daily').exists()) self.assertEqual(verify(self.root), 1) def test_included_claim_without_capture_is_refused(self): value = self.publication() value['claims'] = [{'statement': 'Unsourced.', 'disposition': 'included'}] with self.assertRaisesRegex(ValueError, 'capture'): publish(self.root, value) def test_correction_links_an_earlier_revision(self): original = publish(self.root, self.publication()) correction = publish(self.root, self.publication( title='Corrected', supersedes=original, claims=[{'statement': 'The price claim was withdrawn.', 'disposition': 'excluded', 'exclusion_reason': 'The capture did not show that price.'}])) self.assertIn(original, (self.root / 'digests' / 'reviewed' / f'{correction}.md').read_text()) self.assertEqual(verify(self.root), 2) with self.assertRaisesRegex(ValueError, 'earlier publication'): publish(self.root, self.publication(supersedes='0' * 64)) def test_review_time_requires_a_timezone(self): with self.assertRaisesRegex(ValueError, 'timezone'): publish(self.root, self.publication(reviewed_at='2026-10-04T12:00:00')) if __name__ == '__main__': unittest.main()