Import CBB refresh verify r4 stability baseline
Preserve tested Verify source, authoritative READY checks, bounded bridge retries, diagnostics and failure-only reporting. Include 336-test suite and packaging assets; exclude live Mentor samples, field logs, backups and distributions.
This commit is contained in:
commit
11a2b2e46e
130 files changed
+19267
No files matched your search
@@ -0,0 +1,140 @@
|
||||
from pathlib import Path
|
||||
|
||||
from cbb_refresh_verify.status_bridge import (
|
||||
BridgeResult,
|
||||
BridgeUnavailable,
|
||||
BridgeResponseError,
|
||||
parse_bridge_response,
|
||||
StatusBridgeClient,
|
||||
)
|
||||
import pytest
|
||||
|
||||
|
||||
def test_parse_ready_response_preserves_raw_evidence():
|
||||
result = parse_bridge_response(
|
||||
'{"ok":true,"status":"READY","source":"IsVerifiedReuseBlock","raw_status":2}'
|
||||
)
|
||||
assert result.status == "READY"
|
||||
assert result.source == "IsVerifiedReuseBlock"
|
||||
assert result.raw_status == 2
|
||||
|
||||
|
||||
def test_parse_rejects_success_without_authoritative_status():
|
||||
try:
|
||||
parse_bridge_response('{"ok":true,"status":"UNKNOWN"}')
|
||||
except BridgeResponseError as error:
|
||||
assert "authoritative" in str(error)
|
||||
else:
|
||||
raise AssertionError("missing authoritative status must be rejected")
|
||||
|
||||
|
||||
def test_unavailable_bridge_has_actionable_diagnostic(tmp_path):
|
||||
missing = tmp_path / "CbbStatusBridge32.exe"
|
||||
try:
|
||||
raise BridgeUnavailable(missing)
|
||||
except BridgeUnavailable as error:
|
||||
assert str(missing) in str(error)
|
||||
assert "32-bit" in str(error)
|
||||
|
||||
|
||||
def test_bridge_rejects_mismatched_response_identity():
|
||||
line = ('{"ok":true,"request_id":"request-2","block_name":"OTHER",'
|
||||
'"lmc_file":"C:/lib/other.lmc","status":"READY",'
|
||||
'"source":"IsVerifiedReuseBlock","raw_status":1}')
|
||||
|
||||
with pytest.raises(BridgeResponseError, match='请求标识'):
|
||||
parse_bridge_response(line, expected_request_id='request-1',
|
||||
expected_block='TARGET', expected_lmc='C:/lib/mentor_lib.lmc')
|
||||
|
||||
|
||||
def test_bridge_accepts_correlated_response():
|
||||
line = ('{"ok":true,"request_id":"request-1","block_name":"TARGET",'
|
||||
'"lmc_file":"C:/lib/mentor_lib.lmc","status":"READY",'
|
||||
'"source":"IsVerifiedReuseBlock","raw_status":1}')
|
||||
|
||||
result = parse_bridge_response(line, expected_request_id='request-1',
|
||||
expected_block='TARGET', expected_lmc='C:/lib/mentor_lib.lmc')
|
||||
|
||||
assert result == BridgeResult(
|
||||
'READY', 'IsVerifiedReuseBlock', 1, '', result.response,
|
||||
request_id='request-1', block_name='TARGET', lmc_file='C:/lib/mentor_lib.lmc')
|
||||
|
||||
|
||||
def test_bridge_accepts_legacy_response_with_redundant_unc_separators():
|
||||
line = ('{"ok":true,"request_id":"request-1","block_name":"TARGET",'
|
||||
'"lmc_file":"\\\\\\\\\\\\\\\\192.168.0.252\\\\\\\\eda\\\\\\\\lib\\\\\\\\mentor_lib.lmc",'
|
||||
'"status":"READY","source":"IsVerifiedReuseBlock","raw_status":1}')
|
||||
|
||||
result = parse_bridge_response(
|
||||
line,
|
||||
expected_request_id='request-1',
|
||||
expected_block='TARGET',
|
||||
expected_lmc=r'\\192.168.0.252\eda\lib\mentor_lib.lmc',
|
||||
)
|
||||
|
||||
assert result.status == 'READY'
|
||||
|
||||
|
||||
def test_one_shot_client_preserves_mapped_drive_in_request(tmp_path, monkeypatch):
|
||||
executable = tmp_path / 'CbbStatusBridge32.exe'
|
||||
executable.touch()
|
||||
captured = {}
|
||||
|
||||
class Process:
|
||||
returncode = 0
|
||||
|
||||
def communicate(self, request_line, timeout):
|
||||
import json
|
||||
request = json.loads(request_line)
|
||||
captured.update(request)
|
||||
return json.dumps({
|
||||
'ok': True,
|
||||
'request_id': request['request_id'],
|
||||
'block_name': request['block_name'],
|
||||
'lmc_file': request['lmc_file'],
|
||||
'status': 'READY',
|
||||
'source': 'IsVerifiedReuseBlock',
|
||||
}), ''
|
||||
|
||||
monkeypatch.setattr(
|
||||
'cbb_refresh_verify.status_bridge.subprocess.Popen',
|
||||
lambda *args, **kwargs: Process(),
|
||||
)
|
||||
StatusBridgeClient(executable).query(Path(r'Y:\library\mentor_lib.lmc'), 'TARGET')
|
||||
|
||||
assert captured['lmc_file'] == r'Y:\library\mentor_lib.lmc'
|
||||
|
||||
|
||||
def test_one_shot_client_passes_private_read_opt_in_to_bridge(tmp_path, monkeypatch):
|
||||
executable = tmp_path / 'CbbStatusBridge32.exe'
|
||||
executable.touch()
|
||||
captured = {}
|
||||
|
||||
class Process:
|
||||
returncode = 0
|
||||
|
||||
def communicate(self, request_line, timeout):
|
||||
import json
|
||||
request = json.loads(request_line)
|
||||
response = {
|
||||
'ok': True,
|
||||
'request_id': request['request_id'],
|
||||
'block_name': request['block_name'],
|
||||
'lmc_file': request['lmc_file'],
|
||||
'status': 'READY',
|
||||
'source': 'IsVerifiedReuseBlock',
|
||||
'raw_status': 1,
|
||||
}
|
||||
return json.dumps(response), ''
|
||||
|
||||
def popen(*args, **kwargs):
|
||||
captured.update(kwargs.get('env') or {})
|
||||
return Process()
|
||||
|
||||
monkeypatch.setattr('cbb_refresh_verify.status_bridge.subprocess.Popen', popen)
|
||||
result = StatusBridgeClient(
|
||||
executable, env={'CBB_STATUS_BRIDGE_ALLOW_PRIVATE': '1'}
|
||||
).query(tmp_path / 'mentor_lib.lmc', 'TARGET')
|
||||
|
||||
assert result.status == 'READY'
|
||||
assert captured['CBB_STATUS_BRIDGE_ALLOW_PRIVATE'] == '1'
|
||||
Reference in new issue
Block a user