Files
cbb-refresh-verify-795/tests/test_icdb_address.py
T
阿白叔 11a2b2e46e 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.
2026-09-29 15:05:20 +08:00

57 lines
2.0 KiB
Python

from pathlib import Path
def test_parse_icdb_server_address_extracts_port_and_hosts(tmp_path):
from cbb_refresh_verify.mentor_adapter import parse_icdb_server_address
address = tmp_path / "sAddress.adr"
address.write_text(
"guid\n127.0.0.1\n192.168.1.10\n10062\n1094\n"
"vt40T8RtWJOG2cE2Nlvc5A\n535943\n",
encoding="ascii",
)
assert parse_icdb_server_address(address) == {
"port": 10062,
"hosts": ["127.0.0.1", "192.168.1.10"],
}
def test_stale_icdb_address_is_moved_to_evidence(tmp_path, monkeypatch):
from cbb_refresh_verify import mentor_adapter
database = tmp_path / "database"
address = database / "cdbsvr" / "sAddress.adr"
address.parent.mkdir(parents=True)
address.write_text("guid\n127.0.0.1\n10062\n1094\n", encoding="ascii")
monkeypatch.setattr(mentor_adapter, "probe_icdb_server", lambda hosts, port: (False, "10062 unreachable"))
events = []
result = mentor_adapter.prepare_icdb_address(
database,
tmp_path / "evidence",
emit=lambda **event: events.append(event),
)
assert result["status"] == "STALE_MOVED"
assert not address.exists()
moved = list((tmp_path / "evidence" / "diagnostics" / "cdbsvr").glob("sAddress.adr.stale-*"))
assert len(moved) == 1
assert moved[0].read_text(encoding="ascii") == "guid\n127.0.0.1\n10062\n1094\n"
assert events[-1]["stage"] == "icdb_address_stale"
def test_live_icdb_address_is_left_in_place(tmp_path, monkeypatch):
from cbb_refresh_verify import mentor_adapter
database = tmp_path / "database"
address = database / "cdbsvr" / "sAddress.adr"
address.parent.mkdir(parents=True)
address.write_text("guid\n127.0.0.1\n10062\n1094\n", encoding="ascii")
monkeypatch.setattr(mentor_adapter, "probe_icdb_server", lambda hosts, port: (True, "127.0.0.1:10062"))
result = mentor_adapter.prepare_icdb_address(database, tmp_path / "evidence")
assert result["status"] == "LIVE"
assert address.is_file()