fix: preserve live verification owners across windows and durable stops

This commit is contained in:
阿白叔 committed 2026-11-17 18:44:02 +08:00
1 parent 6175bdb254
commit a606ed9179
5 files changed
+170 -12

No files matched your search

+70
View File
@@ -89,3 +89,73 @@ def test_storage_failure_pauses_dispatcher_without_replaying_forever(service,tmp
service.start(task,request_id='run');wait_idle(service)
assert service.control.closing and len(calls)<=2
assert (service.data_root/'verification/engine-paused.json').is_file()
def test_other_window_recovery_and_close_do_not_interrupt_live_owner(service,tmp_path,monkeypatch):
from dx_productivity.trial_task_center.store import TaskStore
from dx_productivity.trial_task_center.verification.service import VerificationService
from dx_productivity.trial_task_center import netlist_verification
entered=Event();release=Event()
def native(capture,output,*,stop_event):
entered.set();release.wait(5);output.mkdir(parents=True,exist_ok=True)
return {'status':'success','complete':True,'graph':graph(output),'outputs':{}}
monkeypatch.setattr(netlist_verification,'_export_saved_capture',native)
task,item=imported(service,tmp_path);run=service.start(task,request_id='owner');assert entered.wait(3)
other_store=TaskStore(service.repo.store.path);other=VerificationService(other_store,service.data_root)
try:
recovered=other.recover()
assert recovered.get('live_owners')==1
assert service.repo.latest_attempt(item,1)['state']=='running'
other.start(task,request_id='observe')
assert not other.busy
other.begin_shutdown()
assert not service.repo._one('verification_runs','run_id',run['run_id'])['stop_requested']
finally:release.set();wait_idle(service);other.begin_shutdown();other_store.close()
assert service.read_item(item)['status']=='consistent'
def test_stop_from_another_window_is_observed_during_native_export(service,tmp_path,monkeypatch):
from dx_productivity.trial_task_center.store import TaskStore
from dx_productivity.trial_task_center.verification.service import VerificationService
from dx_productivity.trial_task_center import netlist_verification
entered=Event()
def native(capture,output,*,stop_event):
entered.set();stop_event.wait(2)
return {'status':'cancelled','complete':False}
monkeypatch.setattr(netlist_verification,'_export_saved_capture',native)
task,item=imported(service,tmp_path);run=service.start(task,request_id='owner');assert entered.wait(3)
other_store=TaskStore(service.repo.store.path);other=VerificationService(other_store,service.data_root)
try:
other.stop(run['run_id'],request_id='foreign-stop');wait_idle(service)
assert service.read_item(item)['status']=='stopped'
finally:other.begin_shutdown();other_store.close()
def test_owner_exit_without_cli_exit_proof_remains_unknown(service,tmp_path,monkeypatch):
from dx_productivity.trial_task_center.verification import ownership
task,item=imported(service,tmp_path)
attempt=service.repo.create_attempt(item,1,request_id='lost')
service.repo.claim(attempt['attempt_id'],owner_id=service.control.owner_id)
ownership.write_owner(service,'attempts',attempt['attempt_id'],service.control.owner_id)
# This includes a reused PID: the original creation identity is gone.
monkeypatch.setattr(ownership,'_process_gone',lambda identity:True)
recovered=service.recover()
assert recovered['blocked']==1 and recovered['published']==0
assert service.repo.attempt(attempt['attempt_id'])['resource_state']=='unknown'
def test_recovery_publishes_intact_staged_result_without_reexport(service,tmp_path,monkeypatch):
from dx_productivity.trial_task_center import netlist_verification
from dx_productivity.trial_task_center.verification.runner import run_attempt
calls=[]
def native(capture,output,*,stop_event):
calls.append(1);output.mkdir(parents=True,exist_ok=True)
return {'status':'success','complete':True,'graph':graph(output),'outputs':{}}
monkeypatch.setattr(netlist_verification,'_export_saved_capture',native)
_,item=imported(service,tmp_path);attempt=service.repo.create_attempt(item,1,request_id='staged')
with monkeypatch.context() as patch:
patch.setattr(service.repo,'finish',lambda *args,**kwargs:False)
assert not run_attempt(service,attempt['attempt_id'],stop_event=Event())['published']
recovered=service.recover()
assert recovered['published']==1 and len(calls)==2
assert service.read_item(item)['status']=='consistent' and not service.busy