infrastructure/tests/daily-driver.py
2026-11-04 21:39:11 +00:00

34 lines
1.3 KiB
Python

"""Failure and overlap must preserve the last successful candidate pointer."""
import fcntl
import importlib.util
import json
from pathlib import Path
import sys
import tempfile
spec = importlib.util.spec_from_file_location('daily', Path(__file__).parents[1] / 'pipeline/daily-core.py')
daily = importlib.util.module_from_spec(spec)
spec.loader.exec_module(daily)
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
private = root / 'private'
private.mkdir()
pointer = private / 'latest-candidate.json'
pointer.write_text('{"previous":true}\n')
config = root / 'config.json'
config.write_text(json.dumps({'private_root': str(private), 'source_root': str(root / 'absent')}))
sys.argv = ['daily-core.py', str(config)]
try:
daily.main()
except FileNotFoundError:
pass
else:
raise AssertionError('Missing inputs accepted')
states = list(private.glob('*/run.json'))
assert len(states) == 1 and json.loads(states[0].read_text())['state'] == 'failed'
with (private / 'daily-core.lock').open('a') as lock:
fcntl.flock(lock, fcntl.LOCK_EX)
daily.main()
assert len(list(private.glob('skipped-*.json'))) == 1
assert pointer.read_text() == '{"previous":true}\n'
print('PASS: durable failure, overlap record, prior candidate preservation')