fix(dsh): reconcile resumed progress with checkpoint evidence
This commit is contained in:
1 parent
d3bdff81e5
commit
5cb8b6ac83
8 files changed
+187
-3
No files matched your search
@@ -4,6 +4,7 @@ from types import SimpleNamespace as NS
|
||||
import pytest
|
||||
|
||||
from dx_productivity.dsh.cad_verification import CadVerificationAdapter
|
||||
from test_run_journal import project_service, evidence
|
||||
|
||||
|
||||
def service(tmp_path, *, probe=True, interrupted=False):
|
||||
@@ -43,3 +44,24 @@ def test_adapter_rejects_missing_task_without_inventing_counts(tmp_path):
|
||||
result = CadVerificationAdapter(svc).preflight(['missing'])
|
||||
assert result['status'] == 'blocked'
|
||||
assert result['projects'][0]['component_count'] is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('state,blocker', [('batch_failed', 'failed_items'), (None, 'queue_incomplete')])
|
||||
def test_after_run_requires_successful_complete_evidence(project_service, state, blocker):
|
||||
service, _, _, ids, _ = project_service
|
||||
if state:
|
||||
evidence(service, ids[0], state)
|
||||
context = service.task_context(ids[0])
|
||||
assert context.progress.failed_items == (1 if state else 0)
|
||||
assert not context.interrupted
|
||||
result = CadVerificationAdapter(service).after_run(ids[:1])
|
||||
assert result['status'] == 'uncertain'
|
||||
assert blocker in result['blockers']
|
||||
|
||||
|
||||
def test_after_run_keeps_verified_no_match_distinct_from_saved(project_service):
|
||||
service, _, _, ids, _ = project_service
|
||||
evidence(service, ids[0])
|
||||
result = CadVerificationAdapter(service).after_run(ids[:1])
|
||||
assert result['status'] == 'ready' and result['blockers'] == []
|
||||
assert result['tasks'][0]['saved_items'] == 0 and result['tasks'][0]['no_match_items'] == 1
|
||||
@@ -0,0 +1,53 @@
|
||||
"""Original queue recovery across a fatal receipt-write boundary."""
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
from threading import Event
|
||||
|
||||
import pytest
|
||||
|
||||
from dx_productivity.dsh.execution_runs import execute_confirmed_run
|
||||
from dx_productivity.dsh.run_journal import RunJournal
|
||||
from dx_productivity.dsh.task_lifecycle import preflight
|
||||
from test_run_journal import project_service
|
||||
|
||||
|
||||
def test_second_resume_after_fatal_exit_preserves_verified_progress_and_runs_each_task_once(project_service, monkeypatch):
|
||||
service, _, data, ids, _ = project_service
|
||||
calls = []
|
||||
active = {'stop': Event(), 'pause': True}
|
||||
def worker(command, timeout):
|
||||
queue, job = Path(command[3]), command[-1]
|
||||
calls.append(next(key for key in ids if key in queue.parts))
|
||||
with (queue / 'status.tsv').open('a', encoding='utf8') as stream:
|
||||
stream.write(f'{job}\tno_match\tbatch_closed\tControlled verified no match\n')
|
||||
if active['pause']:
|
||||
active['stop'].set()
|
||||
return subprocess.CompletedProcess(command, 0, '', '')
|
||||
for task_id in ids:
|
||||
preparer = service.for_project_task(task_id)._quick_run_preparer
|
||||
preparer._process_runner = worker
|
||||
preparer._cscript_resolver = lambda: Path('cscript.exe')
|
||||
run_id = 'd' * 32
|
||||
first = execute_confirmed_run(service, data, ids, preflight(service, ids), active['stop'], run_id)
|
||||
assert first['status'] == 'paused' and calls == ids[:1]
|
||||
original = RunJournal(data).inspect(service, run_id)
|
||||
active['stop'] = Event()
|
||||
class FatalExit(BaseException):
|
||||
pass
|
||||
with monkeypatch.context() as patch:
|
||||
def fatal_finish(*args, **kwargs):
|
||||
raise FatalExit('exit after checkpoint, before final receipt')
|
||||
patch.setattr(RunJournal, 'finish', fatal_finish)
|
||||
with pytest.raises(FatalExit):
|
||||
execute_confirmed_run(service, data, ids, preflight(service, ids, allow_completed=True),
|
||||
active['stop'], run_id, resume=original)
|
||||
assert calls == ids[:2]
|
||||
restarted = RunJournal(data).inspect(service, run_id)
|
||||
assert restarted['status'] == 'running' and restarted['resume_ready'], restarted['blockers']
|
||||
assert restarted['remaining_task_ids'] == ids[2:]
|
||||
active.update(stop=Event(), pause=False)
|
||||
last = execute_confirmed_run(service, data, ids, preflight(service, ids, allow_completed=True),
|
||||
active['stop'], run_id, resume=restarted)
|
||||
assert last['status'] == 'completed' and last['queue_id'] == run_id
|
||||
assert calls == ids
|
||||
assert all(task['saved_items'] == 0 and task['no_match_items'] == 1 for task in last['tasks'])
|
||||
@@ -1,6 +1,9 @@
|
||||
from dx_productivity.dsh.resume_diff import resume_diff
|
||||
from dx_productivity.dsh.run_journal import RunJournal
|
||||
from test_run_journal import project_service, checkpoint, evidence
|
||||
from dx_productivity.trial_task_center.task_queue import _plan_hash
|
||||
from dx_productivity.trial_task_center.models import TaskStatus
|
||||
import pytest
|
||||
|
||||
|
||||
def test_real_service_plan_changes_are_reported(project_service):
|
||||
@@ -46,3 +49,51 @@ def test_missing_current_hash_cannot_be_silently_ignored(project_service):
|
||||
'queue_available': True, 'resume_ready': True, 'tasks': []})
|
||||
assert value['safe'] is False
|
||||
assert value['changed'] == ids
|
||||
|
||||
|
||||
def test_completed_checkpoint_requires_matching_current_evidence(project_service):
|
||||
service, _, data, ids, hashes = project_service
|
||||
journal = RunJournal(data)
|
||||
journal.begin('c' * 32, ids, hashes)
|
||||
checkpoint(data, 'c' * 32, ids, hashes, {ids[0]: 'completed'})
|
||||
report = journal.inspect(service, 'c' * 32)
|
||||
assert not report['resume_ready']
|
||||
assert 'checkpoint_evidence_mismatch' in report['blockers']
|
||||
evidence(service, ids[0])
|
||||
assert journal.inspect(service, 'c' * 32)['resume_ready']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('checkpoint_state', ['running', 'completed'])
|
||||
def test_crash_during_resumed_run_accepts_verified_progress_but_not_old_terminal_changes(project_service, checkpoint_state):
|
||||
service, store, data, ids, _ = project_service
|
||||
hashes = {key: _plan_hash(service.for_project_task(key), key) for key in ids}
|
||||
journal = RunJournal(data)
|
||||
journal.begin('b' * 32, ids, hashes)
|
||||
evidence(service, ids[0])
|
||||
for state in (TaskStatus.READY, TaskStatus.RUNNING, TaskStatus.COMPLETED):
|
||||
store.set_task_status(ids[0], state)
|
||||
checkpoint(data, 'b' * 32, ids, hashes, {ids[0]: 'completed', ids[1]: 'paused'})
|
||||
baseline = []
|
||||
for task_id in ids:
|
||||
context = service.task_context(task_id)
|
||||
baseline.append({'task_id': task_id, 'interrupted': context.interrupted,
|
||||
**{key: getattr(context.progress, key) for key in
|
||||
('saved_items', 'failed_items', 'no_match_items', 'queue_complete')}})
|
||||
journal.finish('b' * 32, {'status': 'paused', 'tasks': baseline,
|
||||
'entries': [{'task_id': key, 'state': 'completed' if key == ids[0] else 'paused' if key == ids[1] else 'pending'} for key in ids]})
|
||||
assert journal.inspect(service, 'b' * 32)['resume_ready']
|
||||
journal.resume('b' * 32)
|
||||
evidence(service, ids[1])
|
||||
for state in (TaskStatus.READY, TaskStatus.RUNNING, TaskStatus.COMPLETED):
|
||||
store.set_task_status(ids[1], state)
|
||||
checkpoint(data, 'b' * 32, ids, hashes, {ids[0]: 'completed', ids[1]: checkpoint_state})
|
||||
report = journal.inspect(service, 'b' * 32)
|
||||
assert report['resume_ready'], report['blockers']
|
||||
assert report['diff']['evidence_changes']
|
||||
assert all(row['expected_progress'] for row in report['diff']['evidence_changes'])
|
||||
# The run cannot rewrite or lose evidence for a task already terminal in
|
||||
# the last durable receipt, even while later tasks legitimately advance.
|
||||
root = service.for_project_task(ids[0])._quick_run_preparer.data_root / 'quick-run'
|
||||
(root / 'status.tsv').write_text('job_id\tstate\tcode\tmessage\n', encoding='utf8')
|
||||
changed = journal.inspect(service, 'b' * 32)
|
||||
assert not changed['resume_ready'] and 'evidence_changed' in changed['blockers']
|
||||
Reference in new issue
Block a user