feat: receive verification inputs and import project pairs

This commit is contained in:
阿白叔 committed 2026-11-17 15:36:17 +08:00
1 parent f5d39f6261
commit 76074f8d11
5 files changed
+324

No files matched your search

@@ -0,0 +1,86 @@
from pathlib import Path
from threading import Event
import json
import pytest
from dx_productivity.trial_task_center.store import TaskStore
from dx_productivity.trial_task_center.errors import TaskCenterError
from test_native_cli_netlist import project_fixture
@pytest.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()
def test_pair_import_creates_same_input_contract_without_replacement(service,tmp_path):
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='create')['task_id']
result = service.import_pair(task,before,after,request_id='import',stop_event=Event())
item = result['accepted'][0]['item_id']
row = service.repo.revision(item,1)['payload']
assert row['input_state']=='ready' and row['expectation_ref'] is None
assert service.import_pair(task,before,after,request_id='import',stop_event=Event())==result
assert service.repo.latest_attempt(item,1) is None
before_capture = service.artifacts.read(row['before_ref'],'snapshot')
assert Path(before_capture['database_path']).read_bytes()==b'saved-database'
Path(before_capture['database_path']).write_bytes(b'tampered')
with pytest.raises(TaskCenterError): service.artifacts.read(row['before_ref'],'snapshot')
def test_same_source_and_cancel_do_not_publish_items(service,tmp_path):
project = project_fixture(tmp_path)
task = service.create_task('任务',request_id='c')['task_id']
with pytest.raises(TaskCenterError): service.import_pair(task,project,project,request_id='i',stop_event=Event())
stopped=Event(); stopped.set()
with pytest.raises(TaskCenterError): service.import_pair(task,project,project,request_id='j',stop_event=stopped)
assert service.repo.connection.execute('SELECT COUNT(*) FROM verification_items').fetchone()[0]==0
def test_missing_handoff_evidence_remains_visible_and_duplicate_delivery_does_not_repeat(service):
report={'task_id':'execution-task','project_path':'F:/board.prj',
'execution':{'state':'completed','saved_items':1},'status':'unavailable','reason':'capture failed'}
result=service.receive_successful_results({'run_id':'run','netlist_verification':{'execution-task':report}},submission_id='handoff')
item=result['accepted'][0]['item_id']
assert service.repo.revision(item,1)['payload']['input_state']=='unavailable'
assert service.receive_successful_results({'run_id':'run','netlist_verification':{'execution-task':report}},submission_id='handoff')==result
assert service.repo.connection.execute('SELECT COUNT(*) FROM verification_items').fetchone()[0]==1
def test_unsaved_handoff_is_not_accepted_as_success(service):
report={'task_id':'e','project_path':'F:/board.prj','execution':{'state':'failed','saved_items':0}}
result=service.receive_successful_results({'run_id':'r','netlist_verification':{'e':report}},submission_id='bad')
assert not result['accepted']
def test_artifact_reference_cannot_escape_managed_directory(service):
with pytest.raises(TaskCenterError):
service.artifacts.read({'manifest_id':'../../secret','sha256':'1'*64},'snapshot')
def test_malformed_row_does_not_block_good_rows(service):
task=service.create_task('任务',request_id='c')['task_id']
result=service.publish_inputs(task,(None,{}),submission_id='mixed')
assert len(result['rejected'])==2
def test_complete_delivery_can_be_reconciled_under_another_notification(service,tmp_path):
from dx_productivity.trial_task_center.native_netlist import capture_project, _hash
reports={}
for phase in ('before','after'):
folder=tmp_path/phase; folder.mkdir()
capture=capture_project(project_fixture(folder),service.data_root/phase/'capture')
path=service.data_root/phase/'export.json'
path.write_text(json.dumps({'capture':capture}),encoding='utf-8')
reports[phase]={'export_path':str(path),'export_sha256':_hash(path)}
reports.update(project_path='board.prj',execution={'state':'completed','saved_items':1},expected_changes={})
receipt={'run_id':'r','queue_id':'q','netlist_verification':{'e':reports}}
first=service.receive_successful_results(receipt,submission_id='receipt')
checkpoint=dict(receipt); checkpoint['run_id']='q'
second=service.receive_successful_results(checkpoint,submission_id='checkpoint')
assert len(first['accepted'])==1
assert len(second['duplicates'])==1 and not second['rejected']
assert second['task_id']==first['task_id']