Preserve failed-run checkpoint when snapshot receipts are invalid
Metadata integrity checks / metadata (push) Successful in 2m44s

This commit is contained in:
2026-11-15 22:47:27 +08:00
parent 8b7bc6d871
commit 93f00d1a64
2 changed files with 11 additions and 6 deletions
+9 -6
View File
@@ -6,7 +6,6 @@ import hashlib
import json
from pathlib import Path
import re
import tempfile
import unicodedata
from paper_atlas.io.html import Document, Node, clean
@@ -147,11 +146,15 @@ def collect(out, *, snapshots=None, cache=None):
evidence = {}; receipts = {}
if snapshots is not None:
root = Path(snapshots)
for r in json.loads((root/'receipts.json').read_bytes()):
name = r['file']
if not isinstance(name, str) or Path(name).name != name or name in receipts:
raise ValueError('Unsafe or repeated snapshot receipt')
receipts[name] = r
try:
for r in json.loads((root/'receipts.json').read_bytes()):
name = r['file']
if not isinstance(name, str) or Path(name).name != name or name in receipts:
raise ValueError('Unsafe or repeated snapshot receipt')
receipts[name] = r
except Exception as error:
(out/'failed.json').write_text(json.dumps({'status': 'failed_not_complete', 'error_type': type(error).__name__, 'database_written': False})+'\n')
raise
def page(name, url):
if snapshots is not None:
path = root/name
+2
View File
@@ -96,3 +96,5 @@ class Rss2026Tests(unittest.TestCase):
receipts=[*self.fixture['receipts'],{**self.fixture['receipts'][0],'file':'../outside'}]
(self.snap/'receipts.json').write_text(json.dumps(receipts))
with self.assertRaisesRegex(ValueError,'Unsafe'):rss.collect(self.root/'unsafe',snapshots=self.snap)
self.assertTrue((self.root/'unsafe/failed.json').exists())
self.assertFalse((self.root/'unsafe/collection-report.json').exists())