fix: scope release proofs and bind PCB opening consent

This commit is contained in:
阿白叔 committed 2026-11-12 16:02:53 +08:00
1 parent 42d0cebc54
commit 466f400514
33 files changed
+1358 -61

No files matched your search

+42
View File
@@ -221,6 +221,48 @@ def test_export_does_not_adopt_unrelated_existing_native_owner(project, tmp_path
assert len(started) == 3
def test_export_does_not_adopt_existing_child_of_reused_parent_pid(project, tmp_path, monkeypatch):
import cbb_refresh_verify.native_engineering_identity as identity
import win32api
source, _ = project
root = tmp_path/'exports'; root.mkdir()
# This process predates the exporter; its historical parent PID has been reused.
unrelated = dict(pid=888888, parent=987654, name='python.exe', executable='python.exe',
command='python other-tool.py', created='20261111120000.000000+480')
monkeypatch.setattr(identity, '_process_snapshot', lambda: [unrelated])
monkeypatch.setattr(identity, '_database_released', lambda _: True)
monkeypatch.setattr(identity, 'validate_export_output', lambda *_: None)
monkeypatch.setattr(win32api, 'OpenProcess', lambda *a: pytest.fail('adopted another tool'))
class Finished:
pid = 987654
returncode = 0
def __init__(self, *a, **k): pass
def poll(self): return 0
monkeypatch.setattr(identity.subprocess, 'Popen', Finished)
result = identity._run_exports(source, root, tmp_path, 1)
assert result['success'] and result['safe_to_continue']
def test_export_lineage_rejects_reused_owner_and_its_new_children():
from cbb_refresh_verify.native_engineering_identity import _export_descendants, _process_birth
old = '20261112120000.000000+480'
new = '20261112120100.000000+480'
tracked = {10: _process_birth(old), 20: _process_birth(old)}
rows = [dict(pid=20, parent=10, created=new), dict(pid=30, parent=20, created=new)]
assert _export_descendants(rows, tracked, set()) == []
assert 30 not in tracked
# An orphaned real child can outlive its exact original parent.
rows = [dict(pid=40, parent=10, created=new)]
assert _export_descendants(rows, tracked, set()) == rows
def test_export_lineage_rejects_child_older_than_native_handle_birth():
from cbb_refresh_verify.native_engineering_identity import _export_descendants, _process_birth
tracked = {10: _process_birth('20261112120000.000000+480')}
rows = [dict(pid=20, parent=10, created='20261111120000.000000+480')]
assert _export_descendants(rows, tracked, set()) == []
@pytest.mark.parametrize('remains_alive,database_busy', [(False, False), (True, False), (False, True)])
def test_export_reobserves_access_denied_child_before_deciding_release(
project, tmp_path, monkeypatch, remains_alive, database_busy):