fix: preflight short batch attempts and preserve cleanup causes
This commit is contained in:
1 parent
b21960cda1
commit
7d5ea814ec
11 files changed
+332
-94
No files matched your search
@@ -199,7 +199,7 @@ def test_possible_mutation_prevents_automatic_replay(tmp_path, monkeypatch):
|
||||
calls = []
|
||||
def monitor(*args, **kwargs):
|
||||
calls.append(1)
|
||||
path = next((Path(command[3]) / 'batch-attempts').rglob('job.json'))
|
||||
path = next((runtime.path.parent / 'attempts').rglob('job.json'))
|
||||
record = json.loads(path.read_text())
|
||||
record['state'] = 'mutation_possible'
|
||||
path.write_text(json.dumps(record))
|
||||
@@ -228,7 +228,7 @@ def test_previous_checkpoint_invalidated_before_new_worker(tmp_path, monkeypatch
|
||||
raise WorkerMonitorError('cannot certify empty project')
|
||||
runtime.cad.checkpoint = fail_checkpoint
|
||||
# No retry after evidence has been marked as possibly modified.
|
||||
path = next((Path(command[3]) / 'batch-attempts').rglob('job.json'))
|
||||
path = next((runtime.path.parent / 'attempts').rglob('job.json'))
|
||||
record = json.loads(path.read_text())
|
||||
record['state'] = 'mutation_possible'
|
||||
path.write_text(json.dumps(record))
|
||||
@@ -247,6 +247,9 @@ def test_attempt_publication_failure_never_launches_worker(tmp_path, monkeypatch
|
||||
with runtime, pytest.raises(OSError):
|
||||
runtime.run_worker(command, 5)
|
||||
assert not Cad.created
|
||||
assert not Desktop.created
|
||||
from dx_productivity.trial_task_center.batch_resources import pending_resources
|
||||
assert pending_resources(runtime.root) == ()
|
||||
|
||||
|
||||
def test_boundary_pause_does_not_abort_current_cad_startup(tmp_path, monkeypatch):
|
||||
@@ -498,3 +501,45 @@ def test_identity_conflict_never_rebuilds_or_launches_another_worker(tmp_path, m
|
||||
assert len(workers) == (1 if conflict.startswith('checkpoint') or conflict == 'worker_identity' else 0)
|
||||
assert runtime.generation == 1 and not runtime.record['retries']
|
||||
assert Desktop.created[0].released
|
||||
|
||||
|
||||
def test_request_session_identity_is_uuid_bound(tmp_path):
|
||||
from dx_productivity.trial_task_center.batch_runtime import BatchCadRuntime
|
||||
session = '12345678-1234-5678-1234-567812345678'
|
||||
runtime = BatchCadRuntime(tmp_path, 'bom_import', session_id=session)
|
||||
assert runtime.session_id == session.replace('-', '')
|
||||
with pytest.raises(ValueError):
|
||||
BatchCadRuntime(tmp_path, 'bom_import', session_id='../escape')
|
||||
|
||||
|
||||
def test_cleanup_preserves_primary_bom_error_and_report(tmp_path):
|
||||
from dx_productivity.trial_task_center.batch_runtime import BatchCadRuntime
|
||||
primary = TaskCenterError('bom_inspection', 'read failed')
|
||||
primary.bom_report = object()
|
||||
Desktop.fail_release = True
|
||||
with pytest.raises(TaskCenterError) as caught:
|
||||
with BatchCadRuntime(tmp_path, 'bom_import', desktop_factory=Desktop) as runtime:
|
||||
with runtime.native_scope(tmp_path / 'operation'):
|
||||
pass
|
||||
raise primary
|
||||
error = caught.value
|
||||
assert error.primary_error is primary
|
||||
assert error.cleanup_error is not None
|
||||
assert error.bom_report is primary.bom_report
|
||||
assert 'BOM' in error.message and '已核验任务结果保留' not in error.message
|
||||
assert runtime.record['primary_error']['code'] == primary.code
|
||||
assert runtime.record['cleanup_error']
|
||||
Desktop.fail_release = False
|
||||
from dx_productivity.trial_task_center.batch_resources import cleanup_pending_resources
|
||||
cleanup_pending_resources(tmp_path)
|
||||
|
||||
|
||||
def test_attempts_live_under_short_session_root(tmp_path, monkeypatch):
|
||||
import subprocess
|
||||
command, _ = command_for(tmp_path)
|
||||
runtime = worker_runtime(tmp_path, monkeypatch, lambda command, *a, **k:
|
||||
subprocess.CompletedProcess(command, 0, '', ''))
|
||||
with runtime:
|
||||
runtime.run_worker(command, 5)
|
||||
assert list((runtime.path.parent / 'attempts').rglob('job.json'))
|
||||
assert not (Path(command[3]) / 'batch-attempts').exists()
|
||||
Reference in new issue
Block a user