| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699 |
- #!/usr/bin/env python3
- """Tests for non-ChipWatcher UART/RS232 receipt validation."""
- from __future__ import annotations
- import json
- import hashlib
- import re
- import sys
- import tempfile
- import unittest
- from pathlib import Path
- sys.dont_write_bytecode = True
- ROOT = Path(__file__).resolve().parents[2]
- sys.path.insert(0, str(ROOT / "tools"))
- from uart_receipts import ( # noqa: E402
- _parse_host_sensor_report_text,
- backend_capabilities,
- build_parser,
- build_protocol_offline_receipt,
- compute_file_hash,
- validate_cpld_bmc_acceptance_v1_receipt,
- validate_real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt,
- validate_real_bmc_j6_windows_gate_v2_receipt,
- validate_offline_fidelity_gate_v1_receipt,
- validate_final_gate_v2_receipt,
- validate_uart_receipt,
- )
- class UartReceiptsTests(unittest.TestCase):
- def valid_offline_toolchain(self) -> dict:
- tool_safety = {
- "opens_com_ports": False,
- "toggles_dtr_rts": False,
- "installs_drivers": False,
- "programs_flash": False,
- "touches_ptc_fan_bmc": False,
- }
- tools = {
- "python": {"name": "python", "status": "present", "path": r"C:\Python\python.exe"},
- "iverilog": {"name": "iverilog", "status": "present", "path": r"C:\tools\iverilog.exe"},
- "vvp": {"name": "vvp", "status": "present", "path": r"C:\tools\vvp.exe"},
- "verilator": {"name": "verilator", "status": "present", "path": r"C:\tools\verilator_bin.exe"},
- "yosys": {"name": "yosys", "status": "present", "path": r"C:\tools\yosys.exe"},
- "sby": {"name": "sby", "status": "present", "path": r"C:\tools\sby.exe"},
- "cocotb": {"name": "python_module:cocotb", "status": "present", "python": r"C:\venv\Scripts\python.exe"},
- "td_cli": {"name": "td_commands_prompt", "status": "present", "path": r"C:\TD\bin\td_commands_prompt.exe"},
- }
- return {
- "status": "pass",
- "toolchain": {"status": "pass", "tools": tools},
- "manifest": {
- "install_roots": {
- "oss_cad_suite": r"C:\Users\Administrator\CodexToolchains\CPLD\oss-cad-suite\latest",
- "cocotb_venv": r"C:\Users\Administrator\CodexToolchains\CPLD\venvs\pid-study-cocotb-venv",
- "downloads": r"C:\Users\Administrator\CodexToolchains\CPLD\downloads",
- "manifests": r"C:\Users\Administrator\CodexToolchains\CPLD\manifests",
- },
- "tools": [{"name": name, "status": "present", "path": data.get("path") or data.get("python")} for name, data in tools.items()],
- "downloads": [],
- "created_paths": [],
- "reused_paths": [],
- "cleanup_plan": {
- "default": "dry_run",
- "requires_owner_marker": True,
- "allowed_root": r"C:\Users\Administrator\CodexToolchains\CPLD",
- },
- "safety": tool_safety,
- },
- "cleanup_policy": {
- "default": "dry_run",
- "requires_owner_marker": True,
- "allowed_root": r"C:\Users\Administrator\CodexToolchains\CPLD",
- "owner_marker_name": ".cpld_toolchain_owner.json",
- "actual_delete_requires_apply": True,
- },
- "safety": tool_safety,
- "authority_boundary": "user-space offline toolchain bootstrap only",
- }
- def valid_offline_layers(self) -> dict:
- coverage_categories = [
- "protocol",
- "uart_bit",
- "control",
- "safety",
- "debug",
- "virtual_driver_lab",
- "thermal",
- "fault_injection",
- "cocotb_virtual_lab",
- "formal",
- "mutation",
- "td_toolchain",
- ]
- shim_names = [
- "pyserial_loopback_url",
- "socket_pipe_transport",
- "bmc_text_driver",
- "host_register_plane",
- "debug_uart_decoder",
- "fault_injection_facade",
- ]
- fault_contracts = [
- "timeout",
- "disconnect",
- "partial_read",
- "partial_write",
- "permission_denied",
- "buffer_overflow",
- "tx_backpressure",
- "rx_overflow",
- ]
- thermal_models = [
- "conservative",
- "optimistic",
- "extreme",
- "random_perturbation",
- "sensor_drift",
- "sensor_delay",
- "crosstalk",
- "fan_degradation",
- "ptc_thermal_inertia",
- ]
- mutants = [
- "invert_fault_condition",
- "remove_force_off",
- "break_channel_compare",
- "drop_debug_event",
- "break_debug_checksum",
- "bad_formal_property",
- ]
- return {
- "static": {"status": "pass", "returncode": 0},
- "model": {"status": "pass", "tests": {"test_pid_model.py": {"returncode": 0}}},
- "replay": {"status": "pass", "sample_count": 1},
- "protocol_fuzz": {"status": "pass", "scenarios": [{"name": "no_echo_bare_hex", "status": "pass"}]},
- "hdl_sim": {
- "status": "pass",
- "tests": [{"name": "uart_rs232_j6_host_sensor_real_fan_ptc_debug921_top_tb", "status": "pass"}],
- },
- "cocotb_virtual_lab": {"status": "pass", "sim": {"status": "pass", "tests": [{"name": "pid_core_smoke_scoreboard", "status": "pass"}]}},
- "virtual_driver_lab": {
- "status": "pass",
- "user_mode_shims": [{"name": name, "status": "pass", "transcript": {"roundtrip": True}} for name in shim_names],
- "fault_contracts": fault_contracts,
- "trace_hash": "a" * 64,
- },
- "formal": {"status": "pass", "targets": [{"name": "fault_implies_ptc_off", "status": "pass"}]},
- "detector_selftest": {"status": "pass", "results": [{"name": "debug_checksum", "status": "pass"}]},
- "mutation": {
- "status": "pass",
- "mutants": [
- {"name": name, "status": "pass", "mutation_status": "killed", "artifact_sha256": "b" * 64}
- for name in mutants
- ],
- },
- "thermal_digital_twin": {
- "status": "pass",
- "models": [{"name": name, "status": "pass", "trace_hash": "c" * 64, "violations": []} for name in thermal_models],
- },
- "coverage_matrix": {
- "status": "pass",
- "items": [{"category": category, "status": "pass", "covered_by": ["contract_evidence"]} for category in coverage_categories],
- },
- "td_build": {"status": "pass", "elaboration": {"status": "pass", "database": {"sha256": "d" * 64}, "plan": {"script_sha256": "e" * 64}}},
- "debug_bundle": {"status": "pass", "path": "tmp/debug_bundle/offline"},
- }
- def valid_offline_receipt(self) -> dict:
- layers = self.valid_offline_layers()
- return {
- "schema": "offline-fidelity-gate-v1-receipt-v1",
- "status": "pass",
- "generated_at": "2026-06-30T00:00:00Z",
- "toolchain": self.valid_offline_toolchain(),
- "layers": layers,
- "coverage_matrix": layers["coverage_matrix"],
- "safety": {
- "opens_com_ports": False,
- "toggles_dtr_rts": False,
- "programs_flash": False,
- "installs_drivers": False,
- "real_ptc_fan_bmc_action_attempted": False,
- },
- "authority_boundary": "offline logic, protocol, safety, debug, and virtual thermal evidence only",
- }
- def write_real_bmc_windows_gate_v2_fixture(
- self,
- root: Path,
- *,
- poll: int = 3,
- valid: int = 3,
- parser_error: int = 0,
- stale: int = 0,
- uerr: int = 0,
- derr: int = 0,
- mode: str = "PROGRAM_SRAM",
- ) -> Path:
- bitstream = root / "uart_rs232_j6_system_debug_primary.bit"
- td_receipt = root / "td_debug.json"
- transcript = root / "j6sys-transcript.txt"
- event_stream = root / "j6sys-event-stream.json"
- register_dump = root / "j6sys-register-dump.json"
- sram_attestation = root / "manual-sram-attestation.json"
- bitstream.write_bytes(b"real bmc j6 windows debug bitstream")
- tx = 3 + 43 * poll
- rx = 300 if poll >= 3 else 1
- tok = 144 if valid >= 3 else 1
- transcript.write_text(
- "\n".join(
- [
- "J6SYS wake=00000003 poll=00000001 tx=0000002E rx=00000001 uerr=00 state=0 tok=00000001 seq=00000001 valid=00000001 perr=0 stale=0 frame=0 duovf=0 dbg=00000001 derr=00000000",
- f"J6SYS wake=00000003 poll={poll:08X} tx={tx:08X} rx={rx:08X} uerr={uerr:02X} state=0 tok={tok:08X} seq={valid:08X} valid={valid:08X} perr={parser_error:X} stale={stale:X} frame=0 duovf=0 dbg=00000002 derr={derr:08X}",
- ]
- )
- + "\n",
- encoding="utf-8",
- )
- event_stream.write_text(
- json.dumps(
- {
- "schema": "j6sys-event-stream-v1",
- "status": "pass",
- "events": [
- {"poll": poll, "valid": valid, "source_id": "BMC_UART_TEXT", "parser_error": bool(parser_error), "stale": bool(stale)}
- ],
- }
- ),
- encoding="utf-8",
- )
- register_dump.write_text(
- json.dumps(
- {
- "schema": "j6sys-register-dump-v1",
- "status": "pass",
- "debug_registers": {"wake": 3, "poll": poll, "rx": rx, "valid": valid, "uerr": uerr, "derr": derr},
- }
- ),
- encoding="utf-8",
- )
- td_receipt.write_text(
- json.dumps(
- {
- "status": "pass",
- "top": "uart_rs232_j6_system_debug_primary",
- "top_module": "uart_rs232_j6_system_debug_top",
- "mode": "implementation",
- "pin_profile": "primary",
- "bitstream": {"path": str(bitstream), "sha256": compute_file_hash(bitstream)},
- "timing_gate": {"status": "pass"},
- }
- ),
- encoding="utf-8",
- )
- sram_attestation.write_text(
- json.dumps(
- {
- "status": "pass",
- "mode": mode,
- "operator": "manual",
- "programmed_at": "2026-07-01T00:00:00Z",
- "bitstream_sha256": compute_file_hash(bitstream),
- "td_receipt_sha256": compute_file_hash(td_receipt),
- "td_log_sha256": "0" * 64,
- }
- ),
- encoding="utf-8",
- )
- receipt = root / "real_bmc_j6_windows_gate_v2.json"
- payload = {
- "schema": "real-bmc-j6-windows-gate-v2-receipt-v1",
- "status": "pass",
- "counterparty": "real_bmc",
- "pin_profile": {"name": "primary", "connector": "J6", "tx_ball": "T4", "rx_ball": "R5", "debug_rx_ball": "P10", "debug_tx_ball": "R10"},
- "programming": {"mode": mode, "manual_programming": True, "bitstream": {"path": str(bitstream), "sha256": compute_file_hash(bitstream)}},
- "layers": {
- "td_bitstream": {"status": "pass", "receipt": {"path": str(td_receipt), "sha256": compute_file_hash(td_receipt)}},
- "manual_sram_programming": {
- "status": "pass",
- "operator": "manual",
- "mode": mode,
- "manual_programming": True,
- "programmed_at": "2026-07-01T00:00:00Z",
- "attestation": {"path": str(sram_attestation), "sha256": compute_file_hash(sram_attestation)},
- },
- "windows_serial_capture": {
- "status": "pass",
- "port": "COM7",
- "baud": 115200,
- "format": "8N1",
- "duration_s": 90,
- "transcript": {"path": str(transcript), "sha256": compute_file_hash(transcript)},
- "event_stream": {"path": str(event_stream), "sha256": compute_file_hash(event_stream)},
- "register_dump": {"path": str(register_dump), "sha256": compute_file_hash(register_dump)},
- },
- "real_bmc_protocol": {"status": "pass", "valid_frame_count": valid, "source_id": "BMC_UART_TEXT"},
- "safety_contract": {"status": "pass", "ptc_fan_pins_exported": False, "real_actuator_action_attempted": False},
- "artifact_hashes": {
- "status": "pass",
- "bitstream_sha256": compute_file_hash(bitstream),
- "td_receipt_sha256": compute_file_hash(td_receipt),
- "manual_sram_attestation_sha256": compute_file_hash(sram_attestation),
- "transcript_sha256": compute_file_hash(transcript),
- "event_stream_sha256": compute_file_hash(event_stream),
- "register_dump_sha256": compute_file_hash(register_dump),
- },
- },
- "safety": {
- "flash_attempted": False,
- "driver_install_attempted": False,
- "programs_flash": False,
- "opens_unknown_com_ports": False,
- "toggles_dtr_rts": False,
- "ptc_fan_pins_exported": False,
- "real_ptc_fan_action_attempted": False,
- "uncontrolled_real_bmc_action_attempted": False,
- },
- "authority_boundary": "real-bmc-j6-windows-gate-v2 proves Windows P10/R10 J6SYS evidence for controlled J6 BMC UART/parser/safety only.",
- }
- receipt.write_text(json.dumps(payload), encoding="utf-8")
- return receipt
- def write_host_sensor_real_fan_ptc_debug921_fixture(
- self,
- root: Path,
- *,
- hardware_status: str = "not_run",
- ) -> Path:
- root.mkdir(parents=True, exist_ok=True)
- bitstream = root / "uart_rs232_j6_host_sensor_real_fan_ptc_temp_uart_ptc_remap_debug921.bit"
- td_receipt = root / "td_host_sensor_real_fan_ptc_debug921.json"
- sram_attestation = root / "manual-sram-attestation.json"
- host_raw = root / "host-port-raw.bin"
- host_escaped = root / "host-port-escaped.txt"
- debug_raw = root / "debug-uart-raw.bin"
- debug_escaped = root / "debug-uart-escaped.txt"
- replay = root / "bmc-raw-replay.bin"
- debug_frame_stream = root / "debug-frame-stream.json"
- host_sensor_report = root / "host-sensor-report.json"
- host_transcript = root / "host-command-transcript.json"
- manifest = root / "j6-host-sensor-real-fan-ptc-capture-manifest.json"
- commands = [
- "SET PTC 01 10",
- "SET PTC 24 20",
- "SET FAN 01 40",
- "SET FAN 04 30",
- "SET PID ENABLE",
- "GET STATUS",
- "GET MAP",
- "GET SENSOR",
- "GET SENSOR",
- "GET SENSOR",
- "SET PID DISABLE",
- "DISABLE",
- ]
- expected_ack_cmds = {
- "SET PTC 01 10": "PTCCH",
- "SET PTC 24 20": "PTCCH",
- "SET FAN 01 40": "FANCH",
- "SET FAN 04 30": "FANCH",
- "SET PID ENABLE": "PID_EN",
- "GET STATUS": "STATUS",
- "GET MAP": "MAP___",
- "GET SENSOR": "SENSOR",
- "SET PID DISABLE": "PID_DI",
- "DISABLE": "DISABL",
- }
- host_lines: list[str] = []
- debug_lines: list[str] = [
- "J6CMD seq=00000001 idx=00 name=raw text=ipmitool raw 0x36 0x6c 0xdf 0xdd 0x00 0x03",
- "J6EVT kind=HCTRL seq=00000006 ok=1 err=00 type=08 all=0 ch=01 pct=010 timeout=0",
- "J6PWM seq=00000006 src=host_manual pid=disabled timeout=0 ptc01=010 ptc24=020 fan01=040 fan04=030",
- "J6MOD seq=00000006 pid=disabled pid_requested=1 pid_active=0 bmc=observe_only host=slave pwm=host_manual timeout_s=5",
- "J6MAP profile=temp-uart-ptc-remap bmc_tx=T4 bmc_rx=R5 host_tx=P7 host_rx=P8 debug_rx=P10 debug_tx=R10 ptc=24 fan=4 fg=8 install=4",
- ]
- dimm_samples: list[dict[str, object]] = []
- replay_bytes = bytearray()
- raw_offset = 0
- for sample_seq in range(1, 4):
- payload_bytes = bytes([0xFF, 0xFF] * 24) if sample_seq == 2 else bytes(
- [value for dimm in range(24) for value in (0x30 + dimm + sample_seq, 0x00)]
- )
- replay_bytes.extend(payload_bytes)
- checksum = sum(payload_bytes) & 0xFFFF
- debug_lines.append(
- f"J6RAW seq={sample_seq:08X} off={raw_offset:08X} len=30 sum={checksum:04X} data={payload_bytes.hex().upper()}"
- )
- raw_offset += len(payload_bytes)
- valid = 0 if sample_seq == 2 else 24
- missing = 24 if sample_seq == 2 else 0
- status = "all_ff" if sample_seq == 2 else "valid"
- host_lines.append(
- f"SENS seq={sample_seq:08X} status={status} valid={valid:02d} missing={missing:02d} fault=0 raw=1 drop=00000000"
- )
- debug_lines.append(
- f"J6TEMP seq={sample_seq:08X} status={status} valid={valid:02d} missing={missing:02d} fault=0 host_report_drop=00000000"
- )
- rows = []
- for dimm in range(24):
- missing_flag = sample_seq == 2
- temp = -1 if missing_flag else 48 + dimm + sample_seq
- raw_pair = "FFFF" if missing_flag else f"{temp:02X}00"
- host_lines.append(
- f"DIMM seq={sample_seq:08X} id={dimm:02X} raw={raw_pair} temp={temp:03d} "
- f"missing={1 if missing_flag else 0} fault=0 status={status}"
- )
- rows.append({"id": dimm, "raw": raw_pair, "temp": temp, "missing": missing_flag, "fault": False})
- dimm_samples.append({"seq": sample_seq, "status": status, "valid": valid, "missing": missing, "dimm_rows": rows})
- host_lines.extend(
- [
- "PWM seq=00000008 src=host_manual timeout=1 ptc01=000 ptc24=000 fan01=030 fan04=030",
- "PID req=1 active=0 src=host_manual",
- "STAT hd=00000000 rd=00000000 he=00000000",
- ]
- )
- debug_lines.extend(
- [
- "J6PWM seq=0000000A src=host_manual pid=disabled timeout=1 ptc01=000 ptc24=000 fan01=030 fan04=030",
- "J6MOD seq=0000000A pid=disabled pid_requested=1 pid_active=0 bmc=observe_only host=slave pwm=host_manual timeout_s=5",
- f"J6STAT raw_in={len(replay_bytes):08X} raw_out={len(replay_bytes):08X} rd=00000000 hd=00000000 be=00000000 he=00000000",
- ]
- )
- host_text = "\r\n".join(host_lines) + "\r\n"
- debug_text = "\r\n".join(debug_lines) + "\r\n"
- bitstream.write_bytes(b"debug921 host sensor real fan ptc bitstream")
- host_raw.write_bytes(host_text.encode("ascii"))
- host_escaped.write_text(host_text, encoding="utf-8", newline="\n")
- debug_raw.write_bytes(debug_text.encode("ascii"))
- debug_escaped.write_text(debug_text, encoding="utf-8", newline="\n")
- replay.write_bytes(bytes(replay_bytes))
- td_receipt.write_text(
- json.dumps(
- {
- "status": "pass",
- "top": "uart_rs232_j6_host_sensor_real_fan_ptc_temp_uart_ptc_remap_debug921",
- "top_module": "uart_rs232_j6_host_sensor_real_fan_ptc_temp_uart_ptc_remap_debug921_top",
- "mode": "implementation",
- "pin_profile": "temp-uart-ptc-remap",
- "bitstream": {"path": str(bitstream), "sha256": compute_file_hash(bitstream)},
- "timing_gate": {"status": "pass"},
- }
- ),
- encoding="utf-8",
- )
- sram_attestation.write_text(
- json.dumps(
- {
- "status": "pass",
- "mode": "PROGRAM_SRAM",
- "operator": "manual",
- "programmed_at": "2026-07-01T00:00:00Z",
- "bitstream_sha256": compute_file_hash(bitstream),
- "td_receipt_sha256": compute_file_hash(td_receipt),
- }
- ),
- encoding="utf-8",
- )
- host_transcript.write_text(
- json.dumps(
- {
- "schema": "j6-host-sensor-real-fan-ptc-debug921-host-command-transcript-v1",
- "status": "pass",
- "host_port": "COM8",
- "baud": 115200,
- "format": "8N1",
- "writes_to_serial": True,
- "write_port_role": "HostPort",
- "debug_port_writes_to_serial": False,
- "commands": [
- {
- "seq": index + 1,
- "command": command,
- "allowed": True,
- "bytes_written": len(command) + 1,
- "expected_ack_cmd": expected_ack_cmds[command],
- "ack_line": f"OK seq={index + 1:08X} cmd={expected_ack_cmds[command]}",
- "ack_offset": index * 32,
- "response_offset": index * 32,
- "response_raw": f"OK seq={index + 1:08X} cmd={expected_ack_cmds[command]}",
- "response_token": f"OK seq={index + 1:08X} cmd={expected_ack_cmds[command]}",
- "response_class": "ok",
- "response_seq": index + 1,
- "response_cmd": expected_ack_cmds[command],
- "seq_match": True,
- "cmd_match": True,
- "response_late": False,
- "stale": False,
- "accepted": True,
- }
- for index, command in enumerate(commands)
- ],
- }
- ),
- encoding="utf-8",
- )
- host_sensor_report.write_text(
- json.dumps(
- {
- "schema": "j6-host-sensor-real-fan-ptc-host-sensor-report-v1",
- "status": "pass",
- "samples": dimm_samples,
- "host_report_drop": 0,
- "bmc_timeout": False,
- "source": "HostPort",
- }
- ),
- encoding="utf-8",
- )
- debug_frame_stream.write_text(
- json.dumps(
- {
- "schema": "j6-host-sensor-real-fan-ptc-debug-frame-stream-v1",
- "status": "pass",
- "frames": debug_lines,
- "raw_drop": 0,
- "host_report_drop": 0,
- "bmc_berr": 0,
- "host_err": 0,
- }
- ),
- encoding="utf-8",
- )
- manifest.write_text(
- json.dumps(
- {
- "schema": "j6-host-sensor-real-fan-ptc-capture-manifest-v1",
- "status": "pass",
- "host_port": "COM8",
- "debug_port": "COM7",
- "host_baud": 115200,
- "debug_baud": 921600,
- "host_port_writes_to_serial": True,
- "debug_port_writes_to_serial": False,
- "enumerates_com_ports": False,
- "opens_unknown_com_ports": False,
- "pin_profile_name": "temp-uart-ptc-remap",
- "pin_profile": {
- "name": "temp-uart-ptc-remap",
- "connector": "J6",
- "tx_ball": "T4",
- "rx_ball": "R5",
- "bmc_tx_ball": "T4",
- "bmc_rx_ball": "R5",
- "host_tx_ball": "P7",
- "host_rx_ball": "P8",
- "debug_rx_ball": "P10",
- "debug_tx_ball": "R10",
- },
- "raw_replay": {"path": "bmc-raw-replay.bin", "sha256": compute_file_hash(replay)},
- }
- ),
- encoding="utf-8",
- )
- payload = {
- "schema": "real-bmc-j6-host-sensor-real-fan-ptc-debug921-v1-receipt-v1",
- "status": hardware_status,
- "counterparty": "real_bmc",
- "diagnostic_scope": "host_sensor_real_fan_ptc_debug921",
- "pin_profile_name": "temp-uart-ptc-remap",
- "pin_profile": {
- "name": "temp-uart-ptc-remap",
- "connector": "J6",
- "tx_ball": "T4",
- "rx_ball": "R5",
- "bmc_tx_ball": "T4",
- "bmc_rx_ball": "R5",
- "host_tx_ball": "P7",
- "host_rx_ball": "P8",
- "debug_rx_ball": "P10",
- "debug_tx_ball": "R10",
- },
- "programming": {"mode": "PROGRAM_SRAM", "manual_programming": True, "bitstream": {"path": str(bitstream), "sha256": compute_file_hash(bitstream)}},
- "collector": {
- "host_port": "COM8",
- "debug_port": "COM7",
- "baud": 115200,
- "debug_baud": 921600,
- "format": "8N1",
- "flow_control": "none",
- "dtr_enable": False,
- "rts_enable": False,
- "writes_to_serial": True,
- "write_port_role": "HostPort",
- "host_port_writes_to_serial": True,
- "debug_port_writes_to_serial": False,
- "opens_unknown_com_ports": False,
- "enumerates_com_ports": False,
- },
- "layers": {
- "td_bitstream": {"status": "pass", "receipt": {"path": str(td_receipt), "sha256": compute_file_hash(td_receipt)}},
- "manual_sram_programming": {
- "status": "pass",
- "operator": "manual",
- "mode": "PROGRAM_SRAM",
- "manual_programming": True,
- "programmed_at": "2026-07-01T00:00:00Z",
- "attestation": {"path": str(sram_attestation), "sha256": compute_file_hash(sram_attestation)},
- },
- "host_command_sequence": {"status": "pass", "commands": commands},
- "host_control_transcript": {
- "status": "pass",
- "host_command_transcript": {"path": str(host_transcript), "sha256": compute_file_hash(host_transcript)},
- },
- "host_sensor_reports": {
- "status": "pass",
- "host_transcript_text": {"path": str(host_escaped), "sha256": compute_file_hash(host_escaped)},
- "host_raw_bin": {"path": str(host_raw), "sha256": compute_file_hash(host_raw)},
- "host_sensor_report": {"path": str(host_sensor_report), "sha256": compute_file_hash(host_sensor_report)},
- },
- "debug_frame_capture": {
- "status": "pass",
- "debug_transcript": {"path": str(debug_escaped), "sha256": compute_file_hash(debug_escaped)},
- "raw_bin": {"path": str(debug_raw), "sha256": compute_file_hash(debug_raw)},
- "raw_replay": {"path": str(replay), "sha256": compute_file_hash(replay)},
- "debug_frame_stream": {"path": str(debug_frame_stream), "sha256": compute_file_hash(debug_frame_stream)},
- "manifest": {"path": str(manifest), "sha256": compute_file_hash(manifest)},
- },
- "bmc_raw_sampling": {"status": "pass", "minimum_completed_samples": 3, "completed_samples": 3, "bmc_timeout": False},
- "pid_boundary": {"status": "pass", "pid_requested": True, "pid_requested_ever": True, "pid_active": False, "pwm_source": "host_manual"},
- "timeout_evidence": {"status": "pass", "timeout_evidence": {"timeout_s": 5, "ptc_all_percent": 0, "fan_all_percent": 30}},
- "pin_map": {
- "status": "pass",
- "profile": "temp-uart-ptc-remap",
- "ptc_count": 24,
- "fan_count": 4,
- "fan_fg_count": 8,
- "fan_install_count": 4,
- "bmc_tx_ball": "T4",
- "bmc_rx_ball": "R5",
- "host_tx_ball": "P7",
- "host_rx_ball": "P8",
- "debug_rx_ball": "P10",
- "debug_tx_ball": "R10",
- },
- "safety_contract": {
- "status": "pass",
- "pid_default_enabled": False,
- "pid_active": False,
- "bmc_controls_pwm": False,
- "debug_port_writes_to_serial": False,
- "host_port_writes_to_serial": True,
- "real_thermal_performance_claimed": False,
- },
- "real_fan_ptc_hardware_status": {"status": hardware_status, "real_fan_ptc_hardware_present": False, "qualifies_final_gate": False},
- "artifact_hashes": {
- "status": "pass",
- "bitstream_sha256": compute_file_hash(bitstream),
- "td_receipt_sha256": compute_file_hash(td_receipt),
- "manual_sram_attestation_sha256": compute_file_hash(sram_attestation),
- "host_transcript_text_sha256": compute_file_hash(host_escaped),
- "host_raw_bin_sha256": compute_file_hash(host_raw),
- "host_sensor_report_sha256": compute_file_hash(host_sensor_report),
- "debug_transcript_sha256": compute_file_hash(debug_escaped),
- "debug_raw_bin_sha256": compute_file_hash(debug_raw),
- "raw_replay_sha256": compute_file_hash(replay),
- "debug_frame_stream_sha256": compute_file_hash(debug_frame_stream),
- "host_command_transcript_sha256": compute_file_hash(host_transcript),
- "manifest_sha256": compute_file_hash(manifest),
- },
- },
- "safety": {
- "flash_attempted": False,
- "driver_install_attempted": False,
- "programs_flash": False,
- "programs_nonvolatile": False,
- "opens_unknown_com_ports": False,
- "enumerates_com_ports": False,
- "toggles_dtr_rts": False,
- "debug_port_writes_to_serial": False,
- "host_port_writes_to_serial": True,
- "uncontrolled_real_bmc_action_attempted": False,
- "real_thermal_performance_claimed": False,
- },
- "authority_boundary": (
- "real-bmc-j6-host-sensor-real-fan-ptc-debug921-v1 validates SRAM-only COM8 host "
- "1-based real FAN/PTC command evidence, COM7 debug921 frame replay, BMC raw DIMM "
- "sampling, HostPort temperature reporting, PID requested-but-inactive boundary, timeout fallback, "
- "and real FAN/PTC hardware status. It does not satisfy final-gate-v2, real-bmc-j6-windows-gate-v2, "
- "flash, thermal performance, production PTC/FAN qualification, or real PID closed-loop pass."
- ),
- }
- receipt = root / "real_bmc_j6_host_sensor_real_fan_ptc_debug921.json"
- receipt.write_text(json.dumps(payload), encoding="utf-8")
- return receipt
- def test_backend_capabilities_report_missing_optional_python_modules(self) -> None:
- caps = backend_capabilities()
- self.assertIn(caps["serial_backend"], {"pyserial", "powershell_dotnet_limited"})
- self.assertIn(caps["schema_backend"], {"jsonschema", "builtin_limited"})
- self.assertIn("strict_gate_requires", caps)
- def test_public_cli_only_exposes_latest_real_fan_ptc_and_retained_gates(self) -> None:
- parser = build_parser()
- subparsers = next(action for action in parser._actions if action.dest == "command")
- commands = set(subparsers.choices)
- expected_commands = {
- "preflight",
- "protocol-offline",
- "validate",
- "final-gate-v2-validate",
- "offline-fidelity-gate-v1-validate",
- "real-bmc-j6-windows-gate-v2-validate",
- "cpld-bmc-acceptance-v1-validate",
- "real-bmc-j6-host-sensor-real-fan-ptc-debug921-v1-validate",
- }
- self.assertEqual(commands, expected_commands)
- for command in [
- "real-bmc-j6-cr-raw-diagnostic-v1-validate",
- "real-bmc-j6-sensor-raw-diagnostic-v1-validate",
- "real-bmc-j6-host-control-pwm-diagnostic-v1-validate",
- "real-bmc-j6-host-control-pwm-debug921-lossless-v1-validate",
- "real-bmc-j6-host-sensor-pwm-debug921-v1-validate",
- "real-bmc-j6-gate-v1-validate",
- ]:
- self.assertNotIn(command, commands)
- def test_real_fan_ptc_validator_does_not_adapt_through_legacy_host_sensor_pwm(self) -> None:
- source = (ROOT / "tools" / "uart_receipts.py").read_text(encoding="utf-8")
- start = source.index("def validate_real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt")
- end = source.index("def validate_cpld_bmc_acceptance_v1_receipt", start)
- body = source[start:end]
- self.assertNotIn("_host_sensor_real_fan_ptc_as_pwm_payload", body)
- self.assertNotIn("validate_real_bmc_j6_host_sensor_pwm_debug921_v1_receipt(", body)
- def test_protocol_offline_receipt_accepts_echo_and_loose_hex(self) -> None:
- receipt = build_protocol_offline_receipt(
- text="ipmitool raw 0x36 0x6c 0xdf 0xdd 0x00 0x03\n"
- + " ".join(["0x23", "0x4b"] * 24),
- scenario="echo_0x_multiline",
- )
- self.assertEqual(receipt["schema"], "bmc-uart-protocol-receipt-v1")
- self.assertEqual(receipt["status"], "pass")
- self.assertEqual(receipt["parser"]["sample_count"], 24)
- self.assertGreaterEqual(receipt["parser"]["rejected_echo_windows"], 1)
- def test_protocol_offline_receipt_validates_itself_strictly(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- receipt = build_protocol_offline_receipt(
- text=" ".join(["23", "4b"] * 24),
- scenario="bare_hex",
- )
- receipt_path = Path(tmp) / "protocol.json"
- receipt_path.write_text(json.dumps(receipt), encoding="utf-8")
- result = validate_uart_receipt(receipt_path, strict=True)
- self.assertEqual(result["status"], "pass")
- def test_loopback_strict_validation_rejects_blocked_and_missing_hashes(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- receipt_path = Path(tmp) / "loopback.json"
- receipt_path.write_text(
- json.dumps(
- {
- "schema": "uart-loopback-receipt-v1",
- "status": "blocked_no_allowlist",
- "counterparty": "pc_emulator",
- "serial": {"port": "COM7", "baud": 115200, "format": "8N1", "allowlisted": False},
- "transcript": {"path": "transcript.txt"},
- "safety": {"flash_attempted": False, "real_ptc_fan_bmc_action_attempted": False, "driver_install_attempted": False},
- }
- ),
- encoding="utf-8",
- )
- result = validate_uart_receipt(receipt_path, strict=True)
- self.assertEqual(result["status"], "blocked_no_allowlist")
- self.assertIn("missing_transcript_hash", result["failures"])
- def test_board_sram_receipt_requires_sram_only_bitstream_and_debug_evidence(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- root = Path(tmp)
- bit = root / "system.bit"
- transcript = root / "uart.log"
- debug = root / "debug.json"
- bit.write_bytes(b"fake bitstream")
- transcript.write_text("tx ipmitool\nrx ok\n", encoding="utf-8")
- debug.write_text(json.dumps({"events": [{"frame_seq": 1}], "register_dump": {"0x00": 1}}), encoding="utf-8")
- receipt = root / "board.json"
- receipt.write_text(
- json.dumps(
- {
- "schema": "uart-board-sram-receipt-v1",
- "status": "pass",
- "counterparty": "pc_emulator",
- "programming": {"mode": "PROGRAM_SRAM", "bitstream": {"path": str(bit), "sha256": compute_file_hash(bit)}},
- "serial": {"port": "COM7", "baud": 115200, "format": "8N1", "allowlisted": True, "dtr": False, "rts": False},
- "transcript": {"path": str(transcript), "sha256": compute_file_hash(transcript)},
- "debug_evidence": {"event_stream": str(debug), "register_dump": str(debug)},
- "safety": {"flash_attempted": False, "real_ptc_fan_bmc_action_attempted": False, "driver_install_attempted": False},
- }
- ),
- encoding="utf-8",
- )
- result = validate_uart_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "pass")
- def test_board_sram_receipt_fails_closed_on_flash_marker(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- receipt = Path(tmp) / "board.json"
- receipt.write_text(
- json.dumps(
- {
- "schema": "uart-board-sram-receipt-v1",
- "status": "pass",
- "counterparty": "pc_emulator",
- "programming": {"mode": "PROGRAM_FLASH", "bitstream": {"path": "x.bit", "sha256": "abc"}},
- "serial": {"port": "COM7", "baud": 115200, "format": "8N1", "allowlisted": True},
- "transcript": {"path": "uart.log", "sha256": "abc"},
- "debug_evidence": {"event_stream": "debug.json", "register_dump": "debug.json"},
- "safety": {"flash_attempted": True, "real_ptc_fan_bmc_action_attempted": False, "driver_install_attempted": False},
- }
- ),
- encoding="utf-8",
- )
- result = validate_uart_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail_forbidden_action")
- def test_uart_soak_receipt_accepts_round_receipts_without_top_level_transcript(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- root = Path(tmp)
- round_receipt = root / "round1.json"
- round_receipt.write_text(
- json.dumps(
- {
- "schema": "uart-loopback-receipt-v1",
- "status": "pass",
- "counterparty": "pc_emulator",
- "serial": {"port": "COM7", "baud": 115200, "format": "8N1", "allowlisted": True},
- "transcript": {"path": "transcript.txt", "sha256": compute_file_hash(root / "transcript.txt") if (root / "transcript.txt").exists() else "placeholder"},
- "safety": {"flash_attempted": False, "real_ptc_fan_bmc_action_attempted": False, "driver_install_attempted": False},
- }
- ),
- encoding="utf-8",
- )
- transcript = root / "transcript.txt"
- transcript.write_text("loopback ok\n", encoding="utf-8")
- payload = json.loads(round_receipt.read_text(encoding="utf-8"))
- payload["transcript"]["sha256"] = compute_file_hash(transcript)
- round_receipt.write_text(json.dumps(payload), encoding="utf-8")
- soak = root / "soak.json"
- soak.write_text(
- json.dumps(
- {
- "schema": "uart-soak-receipt-v1",
- "status": "pass",
- "counterparty": "pc_emulator",
- "duration_hours_requested": 0.1,
- "duration_hours_observed": 0.1,
- "rounds": [{"index": 1, "status": "pass", "receipt": str(round_receipt)}],
- "safety": {"flash_attempted": False, "real_ptc_fan_bmc_action_attempted": False, "driver_install_attempted": False},
- }
- ),
- encoding="utf-8",
- )
- result = validate_uart_receipt(soak, strict=True)
- self.assertEqual(result["status"], "pass")
- def test_final_gate_v2_rejects_chipwatcher_and_blocked_layers(self) -> None:
- receipt = {
- "schema": "final-gate-v2-receipt-v1",
- "status": "pass",
- "layers": {
- "static": {"status": "pass"},
- "model": {"status": "pass"},
- "replay": {"status": "pass"},
- "rtl_sim": {"status": "blocked_missing_tool"},
- "formal": {"status": "pass"},
- "detector_selftest": {"status": "pass"},
- "td_build": {"status": "pass"},
- "uart_strict": {"status": "pass", "schema": "uart-board-sram-validation-v1"},
- "chipwatcher": {"status": "pass"},
- },
- "authority_boundary": "control communication only",
- }
- result = validate_final_gate_v2_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("blocked_layer:rtl_sim", result["failures"])
- self.assertIn("forbidden_chipwatcher_layer", result["failures"])
- def test_final_gate_v2_rejects_blocked_top_level_status_even_when_layers_pass(self) -> None:
- receipt = {
- "schema": "final-gate-v2-receipt-v1",
- "status": "blocked_missing_tool",
- "layers": {
- "static": {"status": "pass"},
- "model": {"status": "pass"},
- "replay": {"status": "pass"},
- "rtl_sim": {"status": "pass"},
- "formal": {"status": "pass"},
- "detector_selftest": {"status": "pass"},
- "td_build": {"status": "pass"},
- "uart_strict": {"status": "pass"},
- },
- "authority_boundary": "control communication only",
- }
- result = validate_final_gate_v2_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("top_status_not_pass:blocked_missing_tool", result["failures"])
- def test_final_gate_v2_rejects_non_final_receipt_schema(self) -> None:
- receipt = {
- "schema": "not-a-final-gate-receipt-v1",
- "status": "pass",
- "layers": {},
- "authority_boundary": "not final gate evidence",
- }
- result = validate_final_gate_v2_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("fail_schema", result["failures"])
- self.assertIn("missing_layer:static", result["failures"])
- self.assertIn("missing_layer:uart_strict", result["failures"])
- def test_offline_fidelity_gate_rejects_hardware_layers_and_blocked_required_layers(self) -> None:
- layers = {name: {"status": "pass"} for name in [
- "static",
- "model",
- "replay",
- "protocol_fuzz",
- "hdl_sim",
- "cocotb_virtual_lab",
- "virtual_driver_lab",
- "formal",
- "detector_selftest",
- "mutation",
- "thermal_digital_twin",
- "coverage_matrix",
- "td_build",
- "debug_bundle",
- ]}
- layers["hdl_sim"] = {"status": "blocked_missing_tool"}
- layers["hardware"] = {"status": "pass"}
- layers["uart_strict"] = {"status": "pass"}
- layers["chipwatcher"] = {"status": "pass"}
- layers["thermal_performance_pass"] = {"status": "pass"}
- receipt = {
- "schema": "offline-fidelity-gate-v1-receipt-v1",
- "status": "pass",
- "generated_at": "2026-06-30T00:00:00Z",
- "toolchain": {
- "status": "pass",
- "safety": {
- "opens_com_ports": False,
- "toggles_dtr_rts": False,
- "installs_drivers": False,
- "programs_flash": False,
- "touches_ptc_fan_bmc": False,
- },
- },
- "layers": layers,
- "coverage_matrix": {"status": "pass"},
- "safety": {
- "opens_com_ports": False,
- "toggles_dtr_rts": False,
- "programs_flash": False,
- "installs_drivers": False,
- "real_ptc_fan_bmc_action_attempted": False,
- },
- "authority_boundary": "offline thermal_performance_pass",
- }
- result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("blocked_layer:hdl_sim", result["failures"])
- self.assertIn("forbidden_layer:hardware", result["failures"])
- self.assertIn("forbidden_layer:uart_strict", result["failures"])
- self.assertIn("forbidden_layer:chipwatcher", result["failures"])
- self.assertIn("forbidden_layer:thermal_performance_pass", result["failures"])
- self.assertIn("authority_overclaim_thermal_performance", result["failures"])
- def test_offline_fidelity_gate_rejects_uart_strict_and_chipwatcher_authority_overclaim(self) -> None:
- layers = {name: {"status": "pass"} for name in [
- "static",
- "model",
- "replay",
- "protocol_fuzz",
- "hdl_sim",
- "cocotb_virtual_lab",
- "virtual_driver_lab",
- "formal",
- "detector_selftest",
- "mutation",
- "thermal_digital_twin",
- "coverage_matrix",
- "td_build",
- "debug_bundle",
- ]}
- receipt = {
- "schema": "offline-fidelity-gate-v1-receipt-v1",
- "status": "pass",
- "generated_at": "2026-06-30T00:00:00Z",
- "toolchain": {
- "status": "pass",
- "safety": {
- "opens_com_ports": False,
- "toggles_dtr_rts": False,
- "installs_drivers": False,
- "programs_flash": False,
- "touches_ptc_fan_bmc": False,
- },
- },
- "layers": layers,
- "coverage_matrix": {"status": "pass"},
- "safety": {
- "opens_com_ports": False,
- "toggles_dtr_rts": False,
- "programs_flash": False,
- "installs_drivers": False,
- "real_ptc_fan_bmc_action_attempted": False,
- },
- "authority_boundary": "offline uart_strict pass and chipwatcher evidence passed",
- }
- result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("authority_overclaim_uart_strict", result["failures"])
- self.assertIn("authority_overclaim_chipwatcher", result["failures"])
- def test_offline_fidelity_gate_rejects_empty_pass_layers(self) -> None:
- layers = {name: {"status": "pass"} for name in [
- "static",
- "model",
- "replay",
- "protocol_fuzz",
- "hdl_sim",
- "cocotb_virtual_lab",
- "virtual_driver_lab",
- "formal",
- "detector_selftest",
- "mutation",
- "thermal_digital_twin",
- "coverage_matrix",
- "td_build",
- "debug_bundle",
- ]}
- receipt = {
- "schema": "offline-fidelity-gate-v1-receipt-v1",
- "status": "pass",
- "generated_at": "2026-06-30T00:00:00Z",
- "toolchain": {
- "status": "pass",
- "safety": {
- "opens_com_ports": False,
- "toggles_dtr_rts": False,
- "installs_drivers": False,
- "programs_flash": False,
- "touches_ptc_fan_bmc": False,
- },
- },
- "layers": layers,
- "coverage_matrix": {"status": "pass"},
- "safety": {
- "opens_com_ports": False,
- "toggles_dtr_rts": False,
- "programs_flash": False,
- "installs_drivers": False,
- "real_ptc_fan_bmc_action_attempted": False,
- },
- "authority_boundary": "offline logic, protocol, safety, debug, and virtual thermal evidence only",
- }
- result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("missing_layer_evidence:protocol_fuzz:scenarios", result["failures"])
- self.assertIn("missing_layer_evidence:virtual_driver_lab:user_mode_shims", result["failures"])
- self.assertIn("missing_layer_evidence:mutation:mutants", result["failures"])
- self.assertIn("missing_layer_evidence:td_build:elaboration", result["failures"])
- def test_offline_fidelity_gate_accepts_required_layers_with_contract_evidence(self) -> None:
- receipt = self.valid_offline_receipt()
- result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "pass")
- def test_offline_fidelity_gate_rejects_default_validation_with_empty_pass_layers(self) -> None:
- receipt = self.valid_offline_receipt()
- receipt["layers"]["virtual_driver_lab"] = {"status": "pass"}
- result = validate_offline_fidelity_gate_v1_receipt(receipt)
- self.assertEqual(result["status"], "fail")
- self.assertIn("missing_layer_evidence:virtual_driver_lab:user_mode_shims", result["failures"])
- def test_offline_fidelity_gate_rejects_incomplete_contract_coverage_matrix(self) -> None:
- receipt = self.valid_offline_receipt()
- receipt["layers"]["coverage_matrix"] = {
- "status": "pass",
- "items": [{"category": "protocol", "status": "pass", "covered_by": ["protocol_fuzz"]}],
- }
- receipt["coverage_matrix"] = receipt["layers"]["coverage_matrix"]
- result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("missing_layer_evidence:coverage_matrix:uart_bit", result["failures"])
- self.assertIn("missing_layer_evidence:coverage_matrix:td_toolchain", result["failures"])
- def test_offline_fidelity_gate_rejects_underspecified_virtual_driver_lab(self) -> None:
- receipt = self.valid_offline_receipt()
- receipt["layers"]["virtual_driver_lab"] = {
- "status": "pass",
- "user_mode_shims": [{"name": "pyserial_loopback_url", "status": "pass", "transcript": {"roundtrip": True}}],
- "fault_contracts": ["timeout"],
- "trace_hash": "a" * 64,
- }
- result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("missing_layer_evidence:virtual_driver_lab:socket_pipe_transport", result["failures"])
- self.assertIn("missing_layer_evidence:virtual_driver_lab:partial_write", result["failures"])
- def test_offline_fidelity_gate_rejects_underspecified_or_failed_thermal_models(self) -> None:
- receipt = self.valid_offline_receipt()
- receipt["layers"]["thermal_digital_twin"] = {
- "status": "pass",
- "models": [{"name": "conservative", "status": "fail", "trace_hash": "c" * 64, "violations": ["ptc_not_fail_closed"]}],
- }
- result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("missing_layer_evidence:thermal_digital_twin:optimistic", result["failures"])
- self.assertIn("missing_layer_evidence:thermal_digital_twin:model_status", result["failures"])
- def test_offline_fidelity_gate_rejects_missing_toolchain_manifest_and_cleanup_policy(self) -> None:
- receipt = self.valid_offline_receipt()
- receipt["toolchain"] = {
- "status": "pass",
- "safety": {
- "opens_com_ports": False,
- "toggles_dtr_rts": False,
- "installs_drivers": False,
- "programs_flash": False,
- "touches_ptc_fan_bmc": False,
- },
- "authority_boundary": "user-space offline toolchain bootstrap only",
- }
- result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("missing_toolchain_manifest", result["failures"])
- self.assertIn("missing_toolchain_cleanup_policy", result["failures"])
- def test_offline_fidelity_gate_requires_virtual_driver_lab(self) -> None:
- layers = {name: {"status": "pass"} for name in [
- "static",
- "model",
- "replay",
- "protocol_fuzz",
- "hdl_sim",
- "cocotb_virtual_lab",
- "formal",
- "detector_selftest",
- "mutation",
- "thermal_digital_twin",
- "coverage_matrix",
- "td_build",
- "debug_bundle",
- ]}
- receipt = {
- "schema": "offline-fidelity-gate-v1-receipt-v1",
- "status": "pass",
- "generated_at": "2026-06-30T00:00:00Z",
- "toolchain": {
- "status": "pass",
- "safety": {
- "opens_com_ports": False,
- "toggles_dtr_rts": False,
- "installs_drivers": False,
- "programs_flash": False,
- "touches_ptc_fan_bmc": False,
- },
- },
- "layers": layers,
- "coverage_matrix": {"status": "pass"},
- "safety": {
- "opens_com_ports": False,
- "toggles_dtr_rts": False,
- "programs_flash": False,
- "installs_drivers": False,
- "real_ptc_fan_bmc_action_attempted": False,
- },
- "authority_boundary": "offline logic, protocol, safety, debug, and virtual thermal evidence only",
- }
- result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("missing_layer:virtual_driver_lab", result["failures"])
- def test_offline_fidelity_gate_rejects_toolchain_and_safety_overclaims(self) -> None:
- layers = {name: {"status": "pass"} for name in [
- "static",
- "model",
- "replay",
- "protocol_fuzz",
- "hdl_sim",
- "cocotb_virtual_lab",
- "virtual_driver_lab",
- "formal",
- "detector_selftest",
- "mutation",
- "thermal_digital_twin",
- "coverage_matrix",
- "td_build",
- "debug_bundle",
- ]}
- receipt = {
- "schema": "offline-fidelity-gate-v1-receipt-v1",
- "status": "pass",
- "generated_at": "2026-06-30T00:00:00Z",
- "toolchain": {
- "status": "blocked_missing_tool",
- "safety": {
- "opens_com_ports": False,
- "toggles_dtr_rts": False,
- "installs_drivers": True,
- "programs_flash": False,
- "touches_ptc_fan_bmc": False,
- },
- },
- "layers": layers,
- "coverage_matrix": {"status": "pass"},
- "safety": {
- "opens_com_ports": True,
- "toggles_dtr_rts": False,
- "programs_flash": False,
- "installs_drivers": False,
- "real_ptc_fan_bmc_action_attempted": False,
- },
- "notes": "DRIVER_INSTALL PROGRAM_FLASH",
- "authority_boundary": "offline logic, protocol, safety, debug, and virtual thermal evidence only",
- }
- result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("toolchain_status_not_pass:blocked_missing_tool", result["failures"])
- self.assertIn("toolchain_safety_not_false:installs_drivers", result["failures"])
- self.assertIn("safety_not_false:opens_com_ports", result["failures"])
- self.assertIn("forbidden_action_marker:DRIVER_INSTALL", result["failures"])
- self.assertIn("forbidden_action_marker:PROGRAM_FLASH", result["failures"])
- def test_offline_fidelity_gate_rejects_offline_forbidden_hardware_markers(self) -> None:
- receipt = self.valid_offline_receipt()
- receipt["notes"] = ["OPEN_COM COM3", "DTR asserted", "PROGRAM_SRAM", "connect_cable -open"]
- result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("forbidden_action_marker:OPEN_COM", result["failures"])
- self.assertIn("forbidden_action_marker:DTR", result["failures"])
- self.assertIn("forbidden_action_marker:PROGRAM_SRAM", result["failures"])
- self.assertIn("forbidden_action_marker:CONNECT_CABLE", result["failures"])
- def test_offline_fidelity_gate_forbidden_marker_scan_avoids_safe_substring_false_positives(self) -> None:
- receipt = self.valid_offline_receipt()
- receipt["toolchain"]["manifest"]["downloads_dir"] = r"C:\Users\Administrator\CodexToolchains\CPLD\downloads"
- receipt["toolchain"]["authority_boundary"] = "Offline probe checks user-space tools and does not enumerate COM ports."
- receipt["td_log_tail"] = "Exported ports\nsafety downloads_to_hardware=false\n"
- receipt["layers"]["td_build"]["authority_boundary"] = "does not generate/download/program a bitstream"
- receipt["coverage_matrix"]["items"][0]["required"] = ["no_download_no_program"]
- result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "pass")
- self.assertNotIn("forbidden_action_marker:DOWNLOAD", result["failures"])
- self.assertNotIn("forbidden_action_marker:RTS", result["failures"])
- def test_offline_fidelity_gate_still_rejects_standalone_download_action(self) -> None:
- receipt = self.valid_offline_receipt()
- receipt["notes"] = "DOWNLOAD bitstream to device"
- result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("forbidden_action_marker:DOWNLOAD", result["failures"])
- def test_host_sensor_text_parser_splits_literal_escaped_cr_without_newlines(self) -> None:
- lines = ["SENS seq=00000001 status=valid valid=24 missing=00 fault=0 raw=1 drop=00000000"]
- lines.extend(
- f"DIMM seq=00000001 id={dimm:02X} raw=1F00 temp=031 missing=0 fault=0 status=valid"
- for dimm in range(24)
- )
- parsed = _parse_host_sensor_report_text("\\r".join(lines) + "\\r")
- self.assertEqual(parsed["sample_count"], 1)
- self.assertEqual(parsed["dimm_rows_per_sample"], [24])
- self.assertEqual(
- sorted(row["id"] for row in parsed["samples"][0]["dimm_rows"]),
- list(range(24)),
- )
- def test_host_sensor_text_parser_accepts_compact_seq_temp_aliases(self) -> None:
- lines = ["SENS s=0003 st=v v=18 m=00"]
- lines.extend(f"DIMM s=0003 id={dimm:02X} tp={0x30 + dimm:02X} m=0 st=v" for dimm in range(24))
- parsed = _parse_host_sensor_report_text("\r\n".join(lines) + "\r\n")
- self.assertEqual(parsed["sample_count"], 1)
- self.assertEqual(parsed["dimm_rows_per_sample"], [24])
- self.assertEqual(parsed["samples"][0]["summary"]["seq"], 3)
- self.assertEqual(parsed["samples"][0]["summary"]["valid"], 24)
- self.assertEqual(parsed["samples"][0]["summary"]["missing"], 0)
- self.assertEqual(parsed["samples"][0]["dimm_rows"][0]["temp"], 0x30)
- def test_real_bmc_j6_host_sensor_real_fan_ptc_debug921_blocks_until_real_hardware_is_present(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- receipt = self.write_host_sensor_real_fan_ptc_debug921_fixture(Path(tmp))
- result = validate_real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt(receipt, strict=True)
- final_result = validate_final_gate_v2_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "blocked_waiting_for_real_fan_ptc_hardware", result["failures"])
- self.assertEqual(result["real_fan_ptc_hardware_status"]["status"], "not_run")
- self.assertIn("real_fan_ptc_hardware_not_run", result["failures"])
- self.assertEqual(result["pin_map"]["fan_count"], 4)
- self.assertFalse(result["real_fan_ptc_hardware_status"]["qualifies_final_gate"])
- self.assertEqual(result["host_commands"][:4], ["SET PTC 01 10", "SET PTC 24 20", "SET FAN 01 40", "SET FAN 04 30"])
- self.assertEqual(final_result["status"], "fail")
- self.assertIn("fail_schema", final_result["failures"])
- def test_real_bmc_j6_host_sensor_real_fan_ptc_debug921_rejects_zero_based_and_out_of_range_fan_commands(self) -> None:
- scenarios = [
- ("SET PTC 00 10", "host_command_not_allowed:SET PTC 00 10"),
- ("SET PTC 25 10", "host_command_not_allowed:SET PTC 25 10"),
- ("SET FAN 00 40", "host_command_not_allowed:SET FAN 00 40"),
- ("SET FAN 05 40", "host_command_not_allowed:SET FAN 05 40"),
- ]
- for bad_command, expected_failure in scenarios:
- with self.subTest(command=bad_command):
- with tempfile.TemporaryDirectory() as tmp:
- receipt = self.write_host_sensor_real_fan_ptc_debug921_fixture(Path(tmp))
- payload = json.loads(receipt.read_text(encoding="utf-8"))
- payload["layers"]["host_command_sequence"]["commands"][0] = bad_command
- transcript = Path(payload["layers"]["host_control_transcript"]["host_command_transcript"]["path"])
- transcript_payload = json.loads(transcript.read_text(encoding="utf-8"))
- transcript_payload["commands"][0]["command"] = bad_command
- transcript.write_text(json.dumps(transcript_payload), encoding="utf-8")
- payload["layers"]["host_control_transcript"]["host_command_transcript"]["sha256"] = compute_file_hash(transcript)
- payload["layers"]["artifact_hashes"]["host_command_transcript_sha256"] = compute_file_hash(transcript)
- receipt.write_text(json.dumps(payload), encoding="utf-8")
- result = validate_real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail_forbidden_action")
- self.assertIn(expected_failure, result["failures"])
- def test_real_bmc_j6_host_sensor_real_fan_ptc_debug921_rejects_wrong_td_top(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- receipt = self.write_host_sensor_real_fan_ptc_debug921_fixture(Path(tmp))
- payload = json.loads(receipt.read_text(encoding="utf-8"))
- td_path = Path(payload["layers"]["td_bitstream"]["receipt"]["path"])
- td_payload = json.loads(td_path.read_text(encoding="utf-8"))
- td_payload["top_module"] = "uart_rs232_j6_host_sensor_pwm_debug921_top"
- td_path.write_text(json.dumps(td_payload), encoding="utf-8")
- payload["layers"]["td_bitstream"]["receipt"]["sha256"] = compute_file_hash(td_path)
- payload["layers"]["artifact_hashes"]["td_receipt_sha256"] = compute_file_hash(td_path)
- attestation_path = Path(payload["layers"]["manual_sram_programming"]["attestation"]["path"])
- attestation = json.loads(attestation_path.read_text(encoding="utf-8"))
- attestation["td_receipt_sha256"] = compute_file_hash(td_path)
- attestation_path.write_text(json.dumps(attestation), encoding="utf-8")
- payload["layers"]["manual_sram_programming"]["attestation"]["sha256"] = compute_file_hash(attestation_path)
- payload["layers"]["artifact_hashes"]["manual_sram_attestation_sha256"] = compute_file_hash(attestation_path)
- receipt.write_text(json.dumps(payload), encoding="utf-8")
- result = validate_real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("td_bitstream_not_host_sensor_real_fan_ptc_top", result["failures"])
- def test_real_bmc_j6_host_sensor_real_fan_ptc_debug921_rejects_old_six_fan_pin_map(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- receipt = self.write_host_sensor_real_fan_ptc_debug921_fixture(Path(tmp))
- payload = json.loads(receipt.read_text(encoding="utf-8"))
- payload["layers"]["pin_map"]["fan_count"] = 6
- receipt.write_text(json.dumps(payload), encoding="utf-8")
- result = validate_real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("pin_map_fan_count_not_4", result["failures"])
- def test_real_bmc_j6_host_sensor_real_fan_ptc_debug921_rejects_legacy_host_sensor_pwm_sidecars(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- receipt = self.write_host_sensor_real_fan_ptc_debug921_fixture(Path(tmp))
- payload = json.loads(receipt.read_text(encoding="utf-8"))
- report_path = Path(payload["layers"]["host_sensor_reports"]["host_sensor_report"]["path"])
- report_payload = json.loads(report_path.read_text(encoding="utf-8"))
- report_payload["schema"] = "j6-host-sensor-pwm-host-sensor-report-v1"
- report_path.write_text(json.dumps(report_payload), encoding="utf-8")
- stream_path = Path(payload["layers"]["debug_frame_capture"]["debug_frame_stream"]["path"])
- stream_payload = json.loads(stream_path.read_text(encoding="utf-8"))
- stream_payload["schema"] = "j6-host-sensor-pwm-debug-frame-stream-v1"
- stream_path.write_text(json.dumps(stream_payload), encoding="utf-8")
- payload["layers"]["host_sensor_reports"]["host_sensor_report"]["sha256"] = compute_file_hash(report_path)
- payload["layers"]["debug_frame_capture"]["debug_frame_stream"]["sha256"] = compute_file_hash(stream_path)
- payload["layers"]["artifact_hashes"]["host_sensor_report_sha256"] = compute_file_hash(report_path)
- payload["layers"]["artifact_hashes"]["debug_frame_stream_sha256"] = compute_file_hash(stream_path)
- receipt.write_text(json.dumps(payload), encoding="utf-8")
- result = validate_real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("host_sensor_report_wrong_schema", result["failures"])
- self.assertIn("debug_frame_stream_wrong_schema", result["failures"])
- def test_real_bmc_j6_windows_required_layers_remain_unchanged(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- receipt = self.write_real_bmc_windows_gate_v2_fixture(Path(tmp))
- result = validate_real_bmc_j6_windows_gate_v2_receipt(receipt, strict=True)
- self.assertEqual(
- result["required_layers"],
- [
- "td_bitstream",
- "manual_sram_programming",
- "windows_serial_capture",
- "real_bmc_protocol",
- "safety_contract",
- "artifact_hashes",
- ],
- )
- def test_real_bmc_j6_windows_gate_v2_accepts_j6sys_strict_evidence(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- receipt = self.write_real_bmc_windows_gate_v2_fixture(Path(tmp))
- result = validate_real_bmc_j6_windows_gate_v2_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "pass")
- self.assertEqual(result["last_j6sys"]["wake"], 3)
- self.assertEqual(result["last_j6sys"]["poll"], 3)
- self.assertEqual(result["last_j6sys"]["valid"], 3)
- def test_real_bmc_j6_windows_gate_v2_rejects_non_sram_and_j6sys_errors(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- receipt = self.write_real_bmc_windows_gate_v2_fixture(
- Path(tmp),
- parser_error=1,
- stale=1,
- uerr=1,
- derr=1,
- mode="PROGRAM_FLASH",
- )
- result = validate_real_bmc_j6_windows_gate_v2_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail_forbidden_action")
- self.assertIn("programming_not_sram", result["failures"])
- self.assertIn("j6sys_parser_error", result["failures"])
- self.assertIn("j6sys_stale", result["failures"])
- self.assertIn("j6sys_uart_error", result["failures"])
- self.assertIn("j6sys_debug_uart_error", result["failures"])
- def test_real_bmc_j6_windows_gate_v2_rejects_short_protocol_and_hash_mismatch(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- receipt = self.write_real_bmc_windows_gate_v2_fixture(Path(tmp), poll=2, valid=2)
- payload = json.loads(receipt.read_text(encoding="utf-8"))
- payload["layers"]["artifact_hashes"]["transcript_sha256"] = "0" * 64
- receipt.write_text(json.dumps(payload), encoding="utf-8")
- result = validate_real_bmc_j6_windows_gate_v2_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("j6sys_poll_lt_3", result["failures"])
- self.assertIn("j6sys_valid_lt_3", result["failures"])
- self.assertIn("artifact_hash_mismatch:transcript_sha256", result["failures"])
- def test_real_bmc_j6_windows_gate_v2_rejects_blocked_sidecar_json_artifacts(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- receipt = self.write_real_bmc_windows_gate_v2_fixture(Path(tmp))
- payload = json.loads(receipt.read_text(encoding="utf-8"))
- capture_layer = payload["layers"]["windows_serial_capture"]
- artifact_layer = payload["layers"]["artifact_hashes"]
- event_stream = Path(capture_layer["event_stream"]["path"])
- register_dump = Path(capture_layer["register_dump"]["path"])
- event_stream.write_text(
- json.dumps({"schema": "j6sys-event-stream-v1", "status": "blocked_missing_debug_capture", "events": []}),
- encoding="utf-8",
- )
- register_dump.write_text(
- json.dumps({"schema": "j6sys-register-dump-v1", "status": "fail_bad_capture", "debug_registers": {}}),
- encoding="utf-8",
- )
- capture_layer["event_stream"]["sha256"] = compute_file_hash(event_stream)
- capture_layer["register_dump"]["sha256"] = compute_file_hash(register_dump)
- artifact_layer["event_stream_sha256"] = compute_file_hash(event_stream)
- artifact_layer["register_dump_sha256"] = compute_file_hash(register_dump)
- receipt.write_text(json.dumps(payload), encoding="utf-8")
- result = validate_real_bmc_j6_windows_gate_v2_receipt(receipt, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("event_stream_status_not_pass:blocked_missing_debug_capture", result["failures"])
- self.assertIn("register_dump_status_not_pass:fail_bad_capture", result["failures"])
- self.assertIn("event_stream_status_not_pass:empty_events", result["failures"])
- self.assertIn("register_dump_status_not_pass:empty_registers", result["failures"])
- def test_cpld_bmc_acceptance_v1_requires_final_and_real_bmc_windows_pass(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- root = Path(tmp)
- real_bmc = self.write_real_bmc_windows_gate_v2_fixture(root)
- final = root / "final.json"
- final.write_text(
- json.dumps(
- {
- "schema": "final-gate-v2-receipt-v1",
- "status": "pass",
- "layers": {name: {"status": "pass"} for name in [
- "static",
- "model",
- "replay",
- "rtl_sim",
- "formal",
- "detector_selftest",
- "td_build",
- "uart_strict",
- ]},
- "authority_boundary": "control communication only",
- }
- ),
- encoding="utf-8",
- )
- acceptance = root / "acceptance.json"
- acceptance.write_text(
- json.dumps(
- {
- "schema": "cpld-bmc-acceptance-v1-receipt-v1",
- "status": "pass",
- "layers": {
- "final_gate_v2": {"status": "pass", "receipt": {"path": str(final), "sha256": compute_file_hash(final)}},
- "real_bmc_j6_windows_gate_v2": {"status": "pass", "receipt": {"path": str(real_bmc), "sha256": compute_file_hash(real_bmc)}},
- },
- "authority_boundary": "composite acceptance for control communication and real J6 BMC Windows evidence only.",
- }
- ),
- encoding="utf-8",
- )
- result = validate_cpld_bmc_acceptance_v1_receipt(acceptance, strict=True)
- self.assertEqual(result["status"], "pass")
- def test_cpld_bmc_acceptance_v1_propagates_child_gate_failures(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- root = Path(tmp)
- real_bmc = self.write_real_bmc_windows_gate_v2_fixture(root, valid=2)
- final = root / "final.json"
- final.write_text(
- json.dumps(
- {
- "schema": "final-gate-v2-receipt-v1",
- "status": "blocked_missing_tool",
- "layers": {},
- "authority_boundary": "control communication only",
- }
- ),
- encoding="utf-8",
- )
- acceptance = root / "acceptance.json"
- acceptance.write_text(
- json.dumps(
- {
- "schema": "cpld-bmc-acceptance-v1-receipt-v1",
- "status": "pass",
- "layers": {
- "final_gate_v2": {"status": "pass", "receipt": {"path": str(final), "sha256": compute_file_hash(final)}},
- "real_bmc_j6_windows_gate_v2": {"status": "pass", "receipt": {"path": str(real_bmc), "sha256": compute_file_hash(real_bmc)}},
- },
- "authority_boundary": "composite acceptance for control communication and real J6 BMC Windows evidence only.",
- }
- ),
- encoding="utf-8",
- )
- result = validate_cpld_bmc_acceptance_v1_receipt(acceptance, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("final_gate_v2_not_pass:fail", result["failures"])
- self.assertIn("real_bmc_j6_windows_gate_v2_not_pass:fail", result["failures"])
- def test_cpld_bmc_acceptance_v1_dict_input_still_validates_child_receipts(self) -> None:
- with tempfile.TemporaryDirectory() as tmp:
- root = Path(tmp)
- real_bmc = self.write_real_bmc_windows_gate_v2_fixture(root, valid=2)
- final = root / "final.json"
- final.write_text(
- json.dumps(
- {
- "schema": "final-gate-v2-receipt-v1",
- "status": "pass",
- "layers": {name: {"status": "pass"} for name in [
- "static",
- "model",
- "replay",
- "rtl_sim",
- "formal",
- "detector_selftest",
- "td_build",
- "uart_strict",
- ]},
- "authority_boundary": "control communication only",
- }
- ),
- encoding="utf-8",
- )
- payload = {
- "schema": "cpld-bmc-acceptance-v1-receipt-v1",
- "status": "pass",
- "layers": {
- "final_gate_v2": {"status": "pass", "receipt": {"path": str(final), "sha256": compute_file_hash(final)}},
- "real_bmc_j6_windows_gate_v2": {"status": "pass", "receipt": {"path": str(real_bmc), "sha256": compute_file_hash(real_bmc)}},
- },
- "authority_boundary": "composite acceptance for control communication and real J6 BMC Windows evidence only.",
- }
- result = validate_cpld_bmc_acceptance_v1_receipt(payload, strict=True)
- self.assertEqual(result["status"], "fail")
- self.assertIn("real_bmc_j6_windows_gate_v2_not_pass:fail", result["failures"])
- def test_legacy_real_bmc_j6_remote_collect_script_is_not_user_entrypoint(self) -> None:
- self.assertFalse((ROOT / "tools" / "remote" / "collect-real-bmc-j6.ps1").exists())
- script = (ROOT / "tools" / "remote" / "collect-j6-host-sensor-real-fan-ptc.ps1").read_text(
- encoding="utf-8"
- )
- self.assertIn("host-command-transcript.json", script)
- self.assertIn("debug-frame-stream.json", script)
- self.assertIn("bmc-raw-replay.bin", script)
- self.assertIn("real-bmc-j6-host-sensor-real-fan-ptc-debug921-v1", script)
- if __name__ == "__main__":
- unittest.main()
|