fix: stop batch when native session recovery is exhausted
This commit is contained in:
1 parent
a011e8eab6
commit
2c88be99ce
3 files changed
+54
-2
No files matched your search
@@ -166,6 +166,49 @@ def test_only_transient_native_process_failure_requests_one_proven_rebuild(tmp_p
|
||||
assert result is None and len(scopes) == 1 and not recoveries
|
||||
|
||||
|
||||
@pytest.mark.parametrize('failure', ['timeout', 'crash'])
|
||||
@pytest.mark.parametrize('recovery_allowed', [True, False])
|
||||
def test_native_session_failure_stops_batch_after_retry_or_denied_budget_without_cad_fallback(
|
||||
tmp_path, monkeypatch, failure, recovery_allowed):
|
||||
from dx_productivity.trial_task_center.quick_run import QuickRunPreparer
|
||||
project, reader, stop, calls, released = reader_fixture(tmp_path)
|
||||
reader.timeout = 0
|
||||
scopes, recoveries, cad_calls = [], [], []
|
||||
class BatchRuntime:
|
||||
def native_scope(self, evidence):
|
||||
scope = reader.desktop_factory('shared')
|
||||
scope.cleanup_record = {'workers_closed': True}
|
||||
scope.identity = {'session_id': 'batch', 'generation': 1,
|
||||
'attempt_id': f'native-{len(scopes) + 1}'}
|
||||
original = scope.start_process
|
||||
def start(command, **options):
|
||||
process = original(command, **options)
|
||||
process.poll = lambda: None if failure == 'timeout' else 0xC0000005
|
||||
process.close = lambda: None
|
||||
return process
|
||||
scope.start_process = start
|
||||
scopes.append(evidence)
|
||||
return scope
|
||||
def recover_native_failure(self, project, evidence, reason):
|
||||
recoveries.append(evidence)
|
||||
return recovery_allowed
|
||||
def run_worker(self, *args, **kwargs):
|
||||
cad_calls.append(args)
|
||||
raise AssertionError('native session failure must stop before CAD fallback')
|
||||
monkeypatch.setattr(runtime, 'NativeInventoryReader', lambda *args, **kwargs: reader)
|
||||
preparer = QuickRunPreparer(tmp_path / 'cad-data')
|
||||
with pytest.raises(TaskCenterError) as caught:
|
||||
preparer._discover_project_sheets(project, ('OLD',), collect_components=True, runtime=BatchRuntime())
|
||||
assert caught.value.code == 'inventory_session'
|
||||
assert len(scopes) == len(released) == (2 if recovery_allowed else 1)
|
||||
assert len(recoveries) == 1 and not cad_calls
|
||||
record = json.loads((scopes[-1] / 'native-inventory.json').read_text(encoding='utf-8'))
|
||||
assert record['state'] == 'session_failed' and record['source_hashes_unchanged']
|
||||
assert record['cleanup']['workers_closed']
|
||||
proof = json.loads((scopes[-1] / 'native-retry-proof.json').read_text(encoding='utf-8'))
|
||||
assert proof['workers_closed'] and proof['binding']['attempt_id'] == f'native-{len(scopes)}'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('failure', ['malformed', 'timeout'])
|
||||
def test_safe_native_failure_allows_com_fallback_only_after_desktop_release(tmp_path, failure):
|
||||
project, reader, stop, calls, released = reader_fixture(
|
||||
|
||||
Reference in new issue
Block a user