test: accept independent verification tasks and evidence workflows
This commit is contained in:
1 parent
ec677a2864
commit
211d139653
26 files changed
+616
-138
No files matched your search
@@ -0,0 +1,22 @@
|
||||
from threading import Event
|
||||
|
||||
|
||||
def test_mixed_result_inspector_shows_error_and_keeps_new_task_enabled(ui,qtbot):
|
||||
from pathlib import Path
|
||||
import sys
|
||||
sys.path.insert(0,str(Path(__file__).parents[1]/'v1_1'))
|
||||
from test_independent_verification_rules import export,evaluate
|
||||
from dx_productivity.trial_task_center.verification.evidence import build_evidence
|
||||
from test_independent_verification_contracts import payload
|
||||
import copy
|
||||
v=ui.service.verification;task=v.create_task('人工复核',request_id='accept')['task_id']
|
||||
row=payload();item=v.repo.publish(task,(row,),submission_id='direct')['accepted'][0]['item_id']
|
||||
a=export();b=copy.deepcopy(a);b['graph']['components']['a']['pins']['loop']['number']='2';b['graph']['components']['a']['pins']['GND']['number']='1'
|
||||
result=evaluate(a,b);result.update(resource_state='released',evidence=build_evidence(a['graph'],b['graph'],result['issues'],binding={}))
|
||||
attempt=v.repo.create_attempt(item,1,request_id='a');v.repo.claim(attempt['attempt_id'],owner_id='controlled')
|
||||
v.repo.finish(attempt['attempt_id'],generation=1,result=result)
|
||||
page=ui.window.verification_panel;page.open_task(task,item);ui.window.verification_action.trigger()
|
||||
qtbot.waitUntil(lambda:'异常' in page.inspector.heading.text())
|
||||
assert page.new_button.isEnabled() and page.inspector.pin_table.rowCount()==2
|
||||
assert page.inspector.diagram.pins[0]['endpoint'][2]=='1'
|
||||
assert '已处理 1/1' in page.footer.text()
|
||||
@@ -6,3 +6,13 @@ def test_close_and_controls_do_not_block_new_task_creation(ui,qtbot):
|
||||
assert page.start_button.isEnabled() and page.new_button.isEnabled()
|
||||
page.begin_shutdown()
|
||||
assert page.new_button.isEnabled()
|
||||
|
||||
|
||||
def test_shutdown_is_idempotent_after_store_is_released(ui,qtbot):
|
||||
page=ui.window.verification_panel
|
||||
page.shutdown()
|
||||
original=page.service.begin_shutdown
|
||||
def forbidden():raise AssertionError('closed page must not access released store')
|
||||
page.service.begin_shutdown=forbidden
|
||||
try:page.shutdown()
|
||||
finally:page.service.begin_shutdown=original
|
||||
@@ -0,0 +1,68 @@
|
||||
import copy
|
||||
import json
|
||||
from pathlib import Path
|
||||
from threading import Event
|
||||
from test_independent_verification_intake import service
|
||||
from test_independent_verification_runner import imported
|
||||
from test_independent_verification_rules import export
|
||||
from test_verification_control import wait_idle
|
||||
|
||||
|
||||
def test_end_to_end_mixed_batch_is_nonblocking_and_exports_same_evidence(service,tmp_path,monkeypatch):
|
||||
from dx_productivity.trial_task_center import netlist_verification
|
||||
from dx_productivity.trial_task_center.history_store import HistoryRepository
|
||||
from dx_productivity.trial_task_center.retention import maintain_quick_run_storage
|
||||
task,item=imported(service,tmp_path)
|
||||
original=service.repo.revision(item,1)['payload']
|
||||
rows=[]
|
||||
for key in ('rename','swap','missing'):
|
||||
row={k:v for k,v in original.items() if k not in {'payload_digest','input_state'}};row['item_key']=key;row['display_name']=key
|
||||
if key=='missing':row['before_ref']=None
|
||||
rows.append(row)
|
||||
service.publish_inputs(task,rows,submission_id='batch')
|
||||
def native(capture,output,*,stop_event):
|
||||
graph=export()
|
||||
aid=output.parent.name;attempt=service.repo.attempt(aid);name=service.repo.item(attempt['item_id'])['display_name']
|
||||
if output.name=='after':
|
||||
if name=='swap':
|
||||
graph['graph']['components']['a']['pins']['loop']['number']='2';graph['graph']['components']['a']['pins']['GND']['number']='1'
|
||||
if name=='rename':
|
||||
graph['graph']['components']['a']['pins']['outloop']=graph['graph']['components']['a']['pins'].pop('loop')
|
||||
graph['graph']['nets'][0]['endpoints'][0][1]='outloop'
|
||||
return graph
|
||||
monkeypatch.setattr(netlist_verification,'_export_saved_capture',native)
|
||||
run=service.start(task,request_id='all');wait_idle(service)
|
||||
summary=service.read_task(task)['summary']
|
||||
assert [summary[k] for k in ('consistent','warning','different','unavailable')]==[1,1,1,1]
|
||||
report=service.export_task(task,tmp_path/'reports',request_id='report')
|
||||
saved=json.loads((report/'task.json').read_text(encoding='utf-8'))
|
||||
swapped=next(r for r in saved['items'] if r['display_name']=='swap')
|
||||
assert swapped['attempt']['result']['verdict']=='DIFFERENT'
|
||||
assert any(p['connection_changed'] for p in swapped['attempt']['result']['evidence']['pins'])
|
||||
history=HistoryRepository(service.repo.store);assert history.page(query='工程校验').total==3
|
||||
snapshot=history.clear_snapshot();history.clear(snapshot.cutoff_id)
|
||||
maintain_quick_run_storage(service.data_root,max_age_days=0,min_entries=0)
|
||||
assert service.read_item(item)['status']=='consistent'
|
||||
assert service.repo.store._connection.execute('SELECT COUNT(*) FROM execution_operations').fetchone()[0]==0
|
||||
|
||||
|
||||
def test_required_pin_text_does_not_claim_unread_pin_value_is_equal():
|
||||
from dx_productivity.trial_task_center.verification.rules import evaluate
|
||||
from dx_productivity.trial_task_center.verification.contracts import default_plan
|
||||
plan=default_plan();plan['optional_checks'].remove('pin_text');plan['required_checks'].append('pin_text')
|
||||
assert evaluate(export(),export(),expectations=None,check_plan=plan)['verdict']=='INCOMPLETE'
|
||||
|
||||
|
||||
def test_acceptance_cli_labels_controlled_format_evidence(tmp_path):
|
||||
import subprocess,sys
|
||||
from test_native_cli_netlist import project_fixture,graph
|
||||
fixture=tmp_path/'fixture'
|
||||
for phase in ('before','after'):
|
||||
folder=fixture/phase;folder.mkdir(parents=True)
|
||||
project_fixture(folder);graph(folder)
|
||||
script=Path(__file__).parents[2]/'tools/verify_independent_verification.py'
|
||||
result=subprocess.run([sys.executable,str(script),'--fixture-root',str(fixture),'--output',str(tmp_path/'acceptance')],capture_output=True,text=True,timeout=20)
|
||||
assert result.returncode==0,result.stderr
|
||||
summary=json.loads((tmp_path/'acceptance/acceptance.json').read_text(encoding='utf-8'))
|
||||
assert summary['evidence_kind']=='controlled-format-fixture' and summary['inputs_unchanged']
|
||||
assert summary['replacement_operations']==0
|
||||
@@ -11,8 +11,14 @@ from test_native_cli_netlist import project_fixture
|
||||
def service(tmp_path):
|
||||
from dx_productivity.trial_task_center.verification.service import VerificationService
|
||||
store = TaskStore(tmp_path/'tasks.db')
|
||||
try: yield VerificationService(store,tmp_path/'data')
|
||||
finally: store.close()
|
||||
verification=VerificationService(store,tmp_path/'data')
|
||||
try: yield verification
|
||||
finally:
|
||||
verification.begin_shutdown()
|
||||
thread=verification.control.thread
|
||||
if thread is not None:thread.join(10)
|
||||
assert not verification.busy,'Verification must finish before its store is closed'
|
||||
store.close()
|
||||
|
||||
|
||||
def test_pair_import_creates_same_input_contract_without_replacement(service,tmp_path):
|
||||
@@ -84,3 +90,21 @@ def test_complete_delivery_can_be_reconciled_under_another_notification(service,
|
||||
assert len(first['accepted'])==1
|
||||
assert len(second['duplicates'])==1 and not second['rejected']
|
||||
assert second['task_id']==first['task_id']
|
||||
|
||||
|
||||
def test_import_evidence_validation_does_not_hold_store_lock(service,tmp_path,monkeypatch):
|
||||
from threading import Thread
|
||||
a=tmp_path/'a';b=tmp_path/'b';a.mkdir();b.mkdir()
|
||||
before,after=project_fixture(a),project_fixture(b)
|
||||
task=service.create_task('导入',request_id='c')['task_id']
|
||||
read=service.artifacts.read;entered=Event();release=Event();created=Event();errors=[]
|
||||
def slow(*args):entered.set();release.wait(5);return read(*args)
|
||||
monkeypatch.setattr(service.artifacts,'read',slow)
|
||||
def import_pair():
|
||||
try:service.import_pair(task,before,after,request_id='i',stop_event=Event())
|
||||
except Exception as error:errors.append(error)
|
||||
worker=Thread(target=import_pair);worker.start();assert entered.wait(3)
|
||||
creator=Thread(target=lambda:(service.create_task('另一个',request_id='other'),created.set()));creator.start()
|
||||
try:assert created.wait(.5)
|
||||
finally:release.set();worker.join(5);creator.join(5)
|
||||
assert not errors
|
||||
@@ -39,3 +39,32 @@ def test_new_version_has_no_old_green_and_filters_are_literal(repo):
|
||||
assert len(q.read_task(task,query='%_')['items'])==1
|
||||
assert not q.read_task(task,query='missing')['items']
|
||||
with pytest.raises(TaskCenterError):q.read_task(task,cursor={'offset':1,'binding':'bad'})
|
||||
|
||||
|
||||
def test_slow_evidence_read_does_not_lock_task_creation(repo):
|
||||
from threading import Event,Thread
|
||||
from dx_productivity.trial_task_center.verification.queries import VerificationQueries
|
||||
task=repo.create_task('读取',request_id='c')['task_id']
|
||||
item=repo.publish(task,(payload(),),submission_id='s')['accepted'][0]['item_id']
|
||||
a=repo.create_attempt(item,1,request_id='a');repo.claim(a['attempt_id'],owner_id='o')
|
||||
repo.finish(a['attempt_id'],generation=1,result={'resource_state':'released','verdict':'CONSISTENT'})
|
||||
entered=Event();release=Event();created=Event();q=VerificationQueries(repo)
|
||||
def validate(_):entered.set();release.wait(3)
|
||||
q.validator=validate
|
||||
read=Thread(target=lambda:q.read_task(task));read.start();assert entered.wait(2)
|
||||
writer=Thread(target=lambda:(repo.create_task('新任务',request_id='new'),created.set()));writer.start()
|
||||
try:assert created.wait(.5)
|
||||
finally:release.set();read.join(3);writer.join(3)
|
||||
|
||||
|
||||
def test_previous_attempt_is_readable_without_replacing_current_result(repo):
|
||||
from dx_productivity.trial_task_center.verification.queries import VerificationQueries
|
||||
task=repo.create_task('历史',request_id='c')['task_id']
|
||||
item=repo.publish(task,(payload(),),submission_id='s')['accepted'][0]['item_id']
|
||||
attempts=[]
|
||||
for n,verdict in enumerate(('DIFFERENT','CONSISTENT')):
|
||||
a=repo.create_attempt(item,1,request_id=str(n));repo.claim(a['attempt_id'],owner_id='o')
|
||||
repo.finish(a['attempt_id'],generation=a['generation'],result={'resource_state':'released','verdict':verdict});attempts.append(a)
|
||||
q=VerificationQueries(repo)
|
||||
assert q.read_item(item,attempt_id=attempts[0]['attempt_id'])['verdict']=='DIFFERENT'
|
||||
assert q.read_item(item)['verdict']=='CONSISTENT'
|
||||
@@ -84,3 +84,15 @@ def test_missing_pin_number_cannot_prove_equal_and_error_beats_unknown():
|
||||
b['graph']['components']['b']['attributes']['Value']='WRONG'
|
||||
result=evaluate(a,b,expectations={'changes':{}})
|
||||
assert result['verdict']=='DIFFERENT' and result['unknown_checks']
|
||||
|
||||
|
||||
def test_duplicate_physical_number_introduced_is_hard_error():
|
||||
a=export();b=copy.deepcopy(a);b['graph']['components']['a']['pins']['loop']['number']='2'
|
||||
result=evaluate(a,b)
|
||||
assert result['verdict']=='DIFFERENT'
|
||||
assert any(i['check_id']=='physical_pins' and i['state']=='error' for i in result['issues'])
|
||||
|
||||
|
||||
def test_required_semantics_without_proven_type_is_incomplete():
|
||||
plan=default_plan();plan['optional_checks'].remove('pin_semantics');plan['required_checks'].append('pin_semantics')
|
||||
assert evaluate(export(),export(),check_plan=plan)['verdict']=='INCOMPLETE'
|
||||
@@ -81,3 +81,31 @@ def test_schema_survives_reopen_and_does_not_change_execution_tables(tmp_path):
|
||||
assert VerificationRepository(store).task(task['task_id'])['name'] == '持久任务'
|
||||
assert store._connection.execute('SELECT COUNT(*) FROM execution_operations').fetchone()[0] == 0
|
||||
finally: store.close()
|
||||
|
||||
|
||||
def test_commit_acknowledgement_loss_can_be_retried_without_duplicates(repo,monkeypatch):
|
||||
from contextlib import contextmanager
|
||||
original=repo.store.transaction
|
||||
fired=False
|
||||
@contextmanager
|
||||
def lost_reply():
|
||||
nonlocal fired
|
||||
with original():yield
|
||||
if not fired:
|
||||
fired=True;raise OSError('lost response after commit')
|
||||
with monkeypatch.context() as patch:
|
||||
patch.setattr(repo.store,'transaction',lost_reply)
|
||||
with pytest.raises(OSError):repo.create_task('持久结果',request_id='lost')
|
||||
result=repo.create_task('持久结果',request_id='lost')
|
||||
assert repo.task(result['task_id'])['name']=='持久结果'
|
||||
assert repo.connection.execute('SELECT COUNT(*) FROM verification_tasks').fetchone()[0]==1
|
||||
|
||||
|
||||
def test_two_threads_cannot_claim_same_attempt(repo):
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
task=repo.create_task('任务',request_id='c')['task_id']
|
||||
item=repo.publish(task,(payload(),),submission_id='s')['accepted'][0]['item_id']
|
||||
attempt=repo.create_attempt(item,1,request_id='a')
|
||||
with ThreadPoolExecutor(2) as pool:
|
||||
results=list(pool.map(lambda owner:repo.claim(attempt['attempt_id'],owner_id=owner),('one','two')))
|
||||
assert sum(row is not None for row in results)==1
|
||||
@@ -57,3 +57,35 @@ def test_recovery_never_automatically_runs_and_unknown_owner_blocks(service,tmp_
|
||||
assert result['blocked']==1 and not service.busy
|
||||
assert service.repo.attempt(attempt['attempt_id'])['state']=='stopping'
|
||||
assert service.read_item(item)['verdict'] is None
|
||||
|
||||
|
||||
def test_durable_stop_wins_race_with_final_result_commit(service,tmp_path,monkeypatch):
|
||||
from dx_productivity.trial_task_center import netlist_verification
|
||||
task,item=imported(service,tmp_path)
|
||||
def native(capture,output,*,stop_event):
|
||||
output.mkdir(parents=True,exist_ok=True)
|
||||
return {'status':'success','complete':True,'graph':graph(output),'outputs':{}}
|
||||
monkeypatch.setattr(netlist_verification,'_export_saved_capture',native)
|
||||
finish=service.repo.finish
|
||||
def stop_before_commit(attempt_id,*,generation,result):
|
||||
if result.get('attempt_state')=='succeeded':
|
||||
attempt=service.repo.attempt(attempt_id)
|
||||
service.stop(attempt['run_id'],request_id='race-stop')
|
||||
return finish(attempt_id,generation=generation,result=result)
|
||||
monkeypatch.setattr(service.repo,'finish',stop_before_commit)
|
||||
service.start(task,request_id='run');wait_idle(service)
|
||||
assert service.read_item(item)['status']=='stopped'
|
||||
|
||||
|
||||
def test_storage_failure_pauses_dispatcher_without_replaying_forever(service,tmp_path,monkeypatch):
|
||||
from dx_productivity.trial_task_center import netlist_verification
|
||||
task,item=imported(service,tmp_path);calls=[]
|
||||
def native(capture,output,*,stop_event):
|
||||
output.mkdir(parents=True,exist_ok=True)
|
||||
return {'status':'success','complete':True,'graph':graph(output),'outputs':{}}
|
||||
def unavailable(*args,**kwargs):calls.append(1);raise OSError('storage unavailable')
|
||||
monkeypatch.setattr(netlist_verification,'_export_saved_capture',native)
|
||||
monkeypatch.setattr(service.repo,'finish',unavailable)
|
||||
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()
|
||||
@@ -47,3 +47,22 @@ def test_corrupt_evidence_cannot_remain_green_or_export(service,tmp_path,monkeyp
|
||||
assert service.read_item(item)['status']=='unavailable'
|
||||
assert service.read_task(task)['summary']['consistent']==0
|
||||
with pytest.raises(TaskCenterError):service.export_task(task,tmp_path/'reports',request_id='bad')
|
||||
|
||||
|
||||
def test_missing_fixed_expectation_cannot_keep_a_green_result(service,tmp_path,monkeypatch):
|
||||
from test_native_cli_netlist import graph
|
||||
from dx_productivity.trial_task_center import netlist_verification
|
||||
from dx_productivity.trial_task_center.verification.runner import run_attempt
|
||||
_,item=imported(service,tmp_path)
|
||||
expected=service.artifacts.put('expectations',{'changes':{}})
|
||||
row={k:v for k,v in service.repo.revision(item,1)['payload'].items() if k not in {'payload_digest','input_state'}}
|
||||
row.update(input_version=2,expectation_ref=expected)
|
||||
service.publish_inputs(service.repo.item(item)['task_id'],(row,),submission_id='expectations')
|
||||
def native(capture,output,*,stop_event):
|
||||
output.mkdir(parents=True,exist_ok=True)
|
||||
return {'status':'success','complete':True,'graph':graph(output),'outputs':{}}
|
||||
monkeypatch.setattr(netlist_verification,'_export_saved_capture',native)
|
||||
attempt=service.repo.create_attempt(item,2,request_id='a');run_attempt(service,attempt['attempt_id'],stop_event=Event())
|
||||
assert service.read_item(item)['status']=='consistent'
|
||||
(service.artifacts.directory(expected['manifest_id'])/'manifest.json').unlink()
|
||||
assert service.read_item(item)['status']=='unavailable'
|
||||
Reference in new issue
Block a user