fix: address PCB access review in CLI and desktop
This commit was merged in pull request #20.
This commit is contained in:
1 parent
2d6acc1180
commit
7c239e123b
11 files changed
+151
-16
No files matched your search
@@ -60,11 +60,13 @@ def test_supervisor_acknowledged_failed_open_can_close_empty_shell_with_address(
|
||||
|
||||
|
||||
@pytest.mark.parametrize('aliased', [False, True])
|
||||
def test_late_release_is_rechecked_before_later_same_library_item(tmp_path, monkeypatch, aliased):
|
||||
@pytest.mark.parametrize('first_status', ['FAIL', 'SKIPPED'])
|
||||
def test_late_release_is_rechecked_before_later_same_library_item(tmp_path, monkeypatch, aliased, first_status):
|
||||
library = tmp_path/'lib.lmc'
|
||||
calls, checks = [], []
|
||||
failed = verify_runner.VerifyResult('FAIL', stderr='bad database', safe_to_continue=False,
|
||||
evidence_path=tmp_path/'result.json', error_category='MENTOR_DATABASE_LOAD_FAILED')
|
||||
failed = verify_runner.VerifyResult(first_status, stderr='native operation declined', safe_to_continue=False,
|
||||
evidence_path=tmp_path/'result.json',
|
||||
error_category='PCB_OPEN_SKIPPED' if first_status == 'SKIPPED' else 'MENTOR_DATABASE_LOAD_FAILED')
|
||||
def verify(request):
|
||||
calls.append(request.block_name)
|
||||
return failed if request.block_name == 'Bad' else verify_runner.VerifyResult('PASS')
|
||||
@@ -78,7 +80,7 @@ def test_late_release_is_rechecked_before_later_same_library_item(tmp_path, monk
|
||||
results = verify_runner.run_batch([verify_runner.VerifyRequest(library, n, tmp_path)
|
||||
for n in ('Bad','Good')], verifier=verify)
|
||||
assert calls == ['Bad','Good']
|
||||
assert [r.status for r in results] == ['FAIL','PASS']
|
||||
assert [r.status for r in results] == [first_status,'PASS']
|
||||
assert results[0].safe_to_continue
|
||||
|
||||
|
||||
|
||||
@@ -228,6 +228,37 @@ def test_unattended_readwrite_checks_actual_shared_database_handle(tmp_path, mon
|
||||
assert not resumed.error_code
|
||||
assert (evidence/'pcb-open-resource-proof.json').is_file()
|
||||
|
||||
from cbb_refresh_verify import native_repair
|
||||
address = work/'database/cdbsvr/sAddress.adr'
|
||||
address.parent.mkdir()
|
||||
address.write_text('recorded address')
|
||||
verdict = 'NOT_IN_USE'
|
||||
inspected = []
|
||||
|
||||
def inspect(target, root, **kwargs):
|
||||
assert kwargs['inspection_only'] is True
|
||||
assert target.project == project and target.database == address.parent.parent
|
||||
inspected.append(target.database)
|
||||
output = (f'Loading project file [{project}].\nChecking if project is in use.\n'
|
||||
+ ("Project is not in use. Full iCDB Project Backup's functionality is available.\n"
|
||||
"Backup information loaded correctly." if verdict == 'NOT_IN_USE' else 'Project is in use.'))
|
||||
return dict(status=verdict, repair_required=False, inspection_only=True,
|
||||
repair_requested=False, native_pid=100, native_exit_code=0,
|
||||
native_identity=dict(pid=100, created_handle=1, image='iCDBProjectBackup.exe',
|
||||
owner_sid='test', session_id=1),
|
||||
release={'native_exited': True}, project=str(project),
|
||||
database=str(target.database), output=output)
|
||||
|
||||
monkeypatch.setattr(native_repair, 'run_native_repair', inspect)
|
||||
unoccupied, _ = run('address-checked-unoccupied', 6)
|
||||
assert not unoccupied.error_code and inspected == [address.parent.parent]
|
||||
verdict = 'IN_USE'
|
||||
occupied, _ = run('address-checked-occupied', 7)
|
||||
assert occupied.error_code == 'PCB_OPEN_SKIPPED' and 'PCB_OPEN_DATABASE_IN_USE' in occupied.detail
|
||||
assert inspected == [address.parent.parent]*2
|
||||
assert address.read_text() == 'recorded address'
|
||||
address.unlink()
|
||||
|
||||
project.write_text('KEY PCBDesignPath "PCB/A.pcb"\nKEY iCDBDir "../../../outside"\n')
|
||||
unbound, _ = run('wrong-project-database', 7)
|
||||
assert 'iCDBDir' in unbound.detail
|
||||
@@ -261,3 +292,31 @@ def test_stop_during_receipt_never_sends_native_yes(tmp_path, monkeypatch):
|
||||
controller.handle(snapshot(), (snapshot(),), **options)
|
||||
shown[0].choose('continue')
|
||||
assert controller.handle(snapshot(), (snapshot(),), **options).error_code == 'USER_CANCELLED'
|
||||
|
||||
|
||||
def test_headless_opt_in_checks_resources_without_presenting_dialog(tmp_path, monkeypatch):
|
||||
import json
|
||||
from cbb_refresh_verify import pcb_open_consent as consent
|
||||
|
||||
monkeypatch.setattr(consent, 'validate_owner', lambda *_: {'target': 'bound'})
|
||||
checked = []
|
||||
|
||||
def guard(_, __, *, require_complete_proof):
|
||||
checked.append(require_complete_proof)
|
||||
return nullcontext()
|
||||
|
||||
monkeypatch.setattr(consent, 'resource_guard', guard)
|
||||
controller = consent.OpenController(dict(root=str(tmp_path), block_name='A', lmc_file='lib.lmc',
|
||||
project='A.prj', pcb='A.pcb', desktop='CbbVerify_test'), auto_confirm=True)
|
||||
actions = []
|
||||
|
||||
def perform(_, action, phase):
|
||||
actions.append(action['target']['control_id'])
|
||||
return SimpleNamespace(error_code='', accepted_controls=tuple(actions), detail='', channel='win32_button_click')
|
||||
|
||||
result = controller.handle(snapshot(), (snapshot(),), target_pid=20, launcher_pid=10, worker_pid=5,
|
||||
show=None, perform=perform)
|
||||
assert not result.error_code
|
||||
assert checked == [True] and actions == [6]
|
||||
receipt = json.loads((tmp_path/'pcb-open-user-choice.json').read_text(encoding='utf-8'))
|
||||
assert receipt['decision_origin'] == 'headless_opt_in'
|
||||
@@ -166,3 +166,17 @@ def test_retained_mapping_logs_context_and_confirmed_release_guidance(batch_cli,
|
||||
assert 'Z:' in notice and r'\\server\share' in notice
|
||||
assert '释放残留会话' in notice and '确认' in notice
|
||||
assert 'net use' not in notice.lower()
|
||||
|
||||
|
||||
def test_batch_cli_can_enable_verified_pcb_open(batch_cli, monkeypatch):
|
||||
app, runner, _, _, _ = batch_cli
|
||||
received = []
|
||||
|
||||
def run(requests, **kwargs):
|
||||
received.extend(request.auto_confirm_pcb_open for request in requests)
|
||||
return [VerifyResult('PASS') for _ in requests]
|
||||
|
||||
monkeypatch.setattr(runner, 'run_batch', run)
|
||||
assert app.main(['--batch-lmc', 'lib.lmc', '--block', 'One']) == 0
|
||||
assert app.main(['--batch-lmc', 'lib.lmc', '--block', 'One', '--auto-confirm-pcb-open']) == 0
|
||||
assert received == [False, True]
|
||||
@@ -320,3 +320,20 @@ def test_double_click_shows_complete_skipped_reason(qtbot, tmp_path, monkeypatch
|
||||
qtbot.mouseClick(copy, Qt.LeftButton)
|
||||
assert QApplication.clipboard().text() == reason
|
||||
dialog.close()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('enabled', [False, True])
|
||||
def test_pcb_open_option_is_bound_only_to_ordinary_verify(qtbot, tmp_path, monkeypatch, enabled):
|
||||
requests = []
|
||||
|
||||
def verify(request):
|
||||
requests.append(request)
|
||||
return VerifyResult('SKIPPED')
|
||||
|
||||
window = load_window(qtbot, tmp_path, monkeypatch, verifier=verify)
|
||||
window.auto_confirm_pcb_open_check.setChecked(enabled)
|
||||
assert window._request('Beta').auto_confirm_pcb_open is None
|
||||
window._run(['Beta'])
|
||||
qtbot.waitUntil(lambda: not window.busy)
|
||||
assert len(requests) == 1
|
||||
assert requests[0].auto_confirm_pcb_open is enabled
|
||||
Reference in new issue
Block a user