fix(dsh): address intervention cancellation and verification review
Core regression / Python 3.12 core, intervention UI and release configuration (push) Failing after 21s
Core regression / JavaScript syntax (push) Successful in 3s
Core regression / Python 3.12 core, intervention UI and release configuration (pull_request) Failing after 21s
Core regression / JavaScript syntax (pull_request) Successful in 3s

This commit is contained in:
阿白叔 committed 2026-11-05 11:58:32 +08:00
1 parent de9cb2908d
commit 775bc23dc3
26 files changed
+1280 -119

No files matched your search

+63 -5
View File
@@ -66,7 +66,7 @@ def test_operation_progress_does_not_hide_stuck_query_and_recovery_starts_new_ep
operation, query = object(), object()
coordinator.watch(operation, '导入 BOM', 'task-1', 'bom', now=0)
coordinator.watch(query, '读取资源', '', area, now=0)
coordinator.progress('row 2', now=100)
coordinator.progress('row 2', operation, now=100)
coordinator.check_stalled(now=121)
assert len(events) == 1 and events[0]['task_id'] == ''
coordinator.progress('resource reply received', query, now=130)
@@ -90,8 +90,9 @@ def test_resource_states_enter_ai_once_and_recover(ui):
assert events[0]['cleanup_allowed'] is True
window._resource_status.records = ()
window._observe_dsh_resource_blockers()
window._resource_status.error = OSError('resource query failed')
window._observe_dsh_resource_blockers()
window._resource_status._failed(OSError('resource query failed'))
assert len(events) == 1
window._resource_status._failed(OSError('resource query failed'))
assert events[-1]['issue_code'] == 'resource_inspection_failed'
assert len(events) == 2
window._resource_status.error = None
@@ -126,7 +127,8 @@ def test_ai_retry_healthy_resources_are_not_release_failures(ui, monkeypatch):
window._dsh_blockers.enqueue = lambda **value: events.append(value) or True
active = object()
monkeypatch.setattr(window, '_dsh_automation', SimpleNamespace(worker=active, _owns_execution_lane=True,
latest={'status': 'retrying'}, cancel_pending=lambda value: None))
latest={'status': 'retrying'}, cancel_pending=lambda value: None,
can_cancel=False, cancel=lambda: None))
window._workers.add(active)
window._resource_status.known = True
window._resource_status.records = ({'state': 'ready', 'session_id': 'auto-owned-session'},)
@@ -206,11 +208,67 @@ def test_resource_diagnosis_keeps_previous_cad_stop_intent(ui, monkeypatch, qtbo
assert window._dsh_run_stop.is_set()
@pytest.mark.parametrize('complete_while_disabled', [False, True])
def test_completed_blocker_restarts_only_after_explicit_switch_cycle(complete_while_disabled):
events = []
state = {'enabled': True}
window = SimpleNamespace(auto_intervention_check=SimpleNamespace(isChecked=lambda: state['enabled']))
coordinator = DshBlockerCoordinator(window, lambda **value: events.append(dict(value)) or True)
coordinator.report('bom', 'task-1', 'bom_validation_failed', 'bad row')
original_run = events[0]['run_id']
if not complete_while_disabled:
coordinator.completed(original_run)
for _ in range(3):
coordinator.report('bom', 'task-1', 'bom_validation_failed', 'bad row')
coordinator.replay_pending()
assert len(events) == 1
state['enabled'] = False
coordinator.set_enabled(False)
if complete_while_disabled:
coordinator.completed(original_run)
state['enabled'] = True
coordinator.set_enabled(True)
assert len(events) == 2 and events[-1]['run_id'] != original_run
coordinator.report('bom', 'task-1', 'bom_validation_failed', 'bad row')
assert len(events) == 2
def test_completed_while_disabled_restarts_once_but_healthy_clear_cancels():
events, cancelled = [], []
state = {'enabled': True}
window = SimpleNamespace(auto_intervention_check=SimpleNamespace(isChecked=lambda: state['enabled']))
coordinator = DshBlockerCoordinator(window, lambda **value: events.append(dict(value)) or True, cancelled.append)
coordinator.report('resources', '', 'batch_resources_pending', 'held')
run_id = events[0]['run_id']
state['enabled'] = False
coordinator.set_enabled(False)
coordinator.completed(run_id)
coordinator.clear('resources')
state['enabled'] = True
coordinator.set_enabled(True)
assert len(events) == 1 and cancelled == [run_id]
def test_progress_only_resets_actual_worker_even_in_same_area():
events = []
window = SimpleNamespace(auto_intervention_check=SimpleNamespace(isChecked=lambda: True))
coordinator = DshBlockerCoordinator(window, lambda **value: events.append(dict(value)) or True)
first, second = object(), object()
coordinator.watch(first, 'first BOM', 'task-1', 'bom', now=0)
coordinator.watch(second, 'second BOM', 'task-2', 'bom', now=0)
coordinator.progress('row 2', first, now=100)
coordinator.check_stalled(now=121)
assert [event['task_id'] for event in events] == ['task-2']
with pytest.raises(TypeError):
coordinator.progress('unscoped progress', now=130)
def test_global_resource_evidence_actions_work_with_a_task_selected(ui, monkeypatch):
window = ui.window
calls = []
monkeypatch.setattr(window, '_dsh_view', SimpleNamespace(context={'revision': 'r'}, shutdown=lambda: None))
monkeypatch.setattr(window, '_dsh_automation', SimpleNamespace(
latest={'task_id': '', 'incident_id': 'a' * 24}, resubmit=lambda value: calls.append(value)))
latest={'task_id': '', 'incident_id': 'a' * 24}, resubmit=lambda value: calls.append(value),
can_cancel=False, cancel=lambda: None))
window._handle_dsh_action({'task_id': window._task_id, 'revision': 'r', 'action': 'retry_issue'})
assert calls == ['a' * 24]