test_uart_receipts.py 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699
  1. #!/usr/bin/env python3
  2. """Tests for non-ChipWatcher UART/RS232 receipt validation."""
  3. from __future__ import annotations
  4. import json
  5. import hashlib
  6. import re
  7. import sys
  8. import tempfile
  9. import unittest
  10. from pathlib import Path
  11. sys.dont_write_bytecode = True
  12. ROOT = Path(__file__).resolve().parents[2]
  13. sys.path.insert(0, str(ROOT / "tools"))
  14. from uart_receipts import ( # noqa: E402
  15. _parse_host_sensor_report_text,
  16. backend_capabilities,
  17. build_parser,
  18. build_protocol_offline_receipt,
  19. compute_file_hash,
  20. validate_cpld_bmc_acceptance_v1_receipt,
  21. validate_real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt,
  22. validate_real_bmc_j6_windows_gate_v2_receipt,
  23. validate_offline_fidelity_gate_v1_receipt,
  24. validate_final_gate_v2_receipt,
  25. validate_uart_receipt,
  26. )
  27. class UartReceiptsTests(unittest.TestCase):
  28. def valid_offline_toolchain(self) -> dict:
  29. tool_safety = {
  30. "opens_com_ports": False,
  31. "toggles_dtr_rts": False,
  32. "installs_drivers": False,
  33. "programs_flash": False,
  34. "touches_ptc_fan_bmc": False,
  35. }
  36. tools = {
  37. "python": {"name": "python", "status": "present", "path": r"C:\Python\python.exe"},
  38. "iverilog": {"name": "iverilog", "status": "present", "path": r"C:\tools\iverilog.exe"},
  39. "vvp": {"name": "vvp", "status": "present", "path": r"C:\tools\vvp.exe"},
  40. "verilator": {"name": "verilator", "status": "present", "path": r"C:\tools\verilator_bin.exe"},
  41. "yosys": {"name": "yosys", "status": "present", "path": r"C:\tools\yosys.exe"},
  42. "sby": {"name": "sby", "status": "present", "path": r"C:\tools\sby.exe"},
  43. "cocotb": {"name": "python_module:cocotb", "status": "present", "python": r"C:\venv\Scripts\python.exe"},
  44. "td_cli": {"name": "td_commands_prompt", "status": "present", "path": r"C:\TD\bin\td_commands_prompt.exe"},
  45. }
  46. return {
  47. "status": "pass",
  48. "toolchain": {"status": "pass", "tools": tools},
  49. "manifest": {
  50. "install_roots": {
  51. "oss_cad_suite": r"C:\Users\Administrator\CodexToolchains\CPLD\oss-cad-suite\latest",
  52. "cocotb_venv": r"C:\Users\Administrator\CodexToolchains\CPLD\venvs\pid-study-cocotb-venv",
  53. "downloads": r"C:\Users\Administrator\CodexToolchains\CPLD\downloads",
  54. "manifests": r"C:\Users\Administrator\CodexToolchains\CPLD\manifests",
  55. },
  56. "tools": [{"name": name, "status": "present", "path": data.get("path") or data.get("python")} for name, data in tools.items()],
  57. "downloads": [],
  58. "created_paths": [],
  59. "reused_paths": [],
  60. "cleanup_plan": {
  61. "default": "dry_run",
  62. "requires_owner_marker": True,
  63. "allowed_root": r"C:\Users\Administrator\CodexToolchains\CPLD",
  64. },
  65. "safety": tool_safety,
  66. },
  67. "cleanup_policy": {
  68. "default": "dry_run",
  69. "requires_owner_marker": True,
  70. "allowed_root": r"C:\Users\Administrator\CodexToolchains\CPLD",
  71. "owner_marker_name": ".cpld_toolchain_owner.json",
  72. "actual_delete_requires_apply": True,
  73. },
  74. "safety": tool_safety,
  75. "authority_boundary": "user-space offline toolchain bootstrap only",
  76. }
  77. def valid_offline_layers(self) -> dict:
  78. coverage_categories = [
  79. "protocol",
  80. "uart_bit",
  81. "control",
  82. "safety",
  83. "debug",
  84. "virtual_driver_lab",
  85. "thermal",
  86. "fault_injection",
  87. "cocotb_virtual_lab",
  88. "formal",
  89. "mutation",
  90. "td_toolchain",
  91. ]
  92. shim_names = [
  93. "pyserial_loopback_url",
  94. "socket_pipe_transport",
  95. "bmc_text_driver",
  96. "host_register_plane",
  97. "debug_uart_decoder",
  98. "fault_injection_facade",
  99. ]
  100. fault_contracts = [
  101. "timeout",
  102. "disconnect",
  103. "partial_read",
  104. "partial_write",
  105. "permission_denied",
  106. "buffer_overflow",
  107. "tx_backpressure",
  108. "rx_overflow",
  109. ]
  110. thermal_models = [
  111. "conservative",
  112. "optimistic",
  113. "extreme",
  114. "random_perturbation",
  115. "sensor_drift",
  116. "sensor_delay",
  117. "crosstalk",
  118. "fan_degradation",
  119. "ptc_thermal_inertia",
  120. ]
  121. mutants = [
  122. "invert_fault_condition",
  123. "remove_force_off",
  124. "break_channel_compare",
  125. "drop_debug_event",
  126. "break_debug_checksum",
  127. "bad_formal_property",
  128. ]
  129. return {
  130. "static": {"status": "pass", "returncode": 0},
  131. "model": {"status": "pass", "tests": {"test_pid_model.py": {"returncode": 0}}},
  132. "replay": {"status": "pass", "sample_count": 1},
  133. "protocol_fuzz": {"status": "pass", "scenarios": [{"name": "no_echo_bare_hex", "status": "pass"}]},
  134. "hdl_sim": {
  135. "status": "pass",
  136. "tests": [{"name": "uart_rs232_j6_host_sensor_real_fan_ptc_debug921_top_tb", "status": "pass"}],
  137. },
  138. "cocotb_virtual_lab": {"status": "pass", "sim": {"status": "pass", "tests": [{"name": "pid_core_smoke_scoreboard", "status": "pass"}]}},
  139. "virtual_driver_lab": {
  140. "status": "pass",
  141. "user_mode_shims": [{"name": name, "status": "pass", "transcript": {"roundtrip": True}} for name in shim_names],
  142. "fault_contracts": fault_contracts,
  143. "trace_hash": "a" * 64,
  144. },
  145. "formal": {"status": "pass", "targets": [{"name": "fault_implies_ptc_off", "status": "pass"}]},
  146. "detector_selftest": {"status": "pass", "results": [{"name": "debug_checksum", "status": "pass"}]},
  147. "mutation": {
  148. "status": "pass",
  149. "mutants": [
  150. {"name": name, "status": "pass", "mutation_status": "killed", "artifact_sha256": "b" * 64}
  151. for name in mutants
  152. ],
  153. },
  154. "thermal_digital_twin": {
  155. "status": "pass",
  156. "models": [{"name": name, "status": "pass", "trace_hash": "c" * 64, "violations": []} for name in thermal_models],
  157. },
  158. "coverage_matrix": {
  159. "status": "pass",
  160. "items": [{"category": category, "status": "pass", "covered_by": ["contract_evidence"]} for category in coverage_categories],
  161. },
  162. "td_build": {"status": "pass", "elaboration": {"status": "pass", "database": {"sha256": "d" * 64}, "plan": {"script_sha256": "e" * 64}}},
  163. "debug_bundle": {"status": "pass", "path": "tmp/debug_bundle/offline"},
  164. }
  165. def valid_offline_receipt(self) -> dict:
  166. layers = self.valid_offline_layers()
  167. return {
  168. "schema": "offline-fidelity-gate-v1-receipt-v1",
  169. "status": "pass",
  170. "generated_at": "2026-06-30T00:00:00Z",
  171. "toolchain": self.valid_offline_toolchain(),
  172. "layers": layers,
  173. "coverage_matrix": layers["coverage_matrix"],
  174. "safety": {
  175. "opens_com_ports": False,
  176. "toggles_dtr_rts": False,
  177. "programs_flash": False,
  178. "installs_drivers": False,
  179. "real_ptc_fan_bmc_action_attempted": False,
  180. },
  181. "authority_boundary": "offline logic, protocol, safety, debug, and virtual thermal evidence only",
  182. }
  183. def write_real_bmc_windows_gate_v2_fixture(
  184. self,
  185. root: Path,
  186. *,
  187. poll: int = 3,
  188. valid: int = 3,
  189. parser_error: int = 0,
  190. stale: int = 0,
  191. uerr: int = 0,
  192. derr: int = 0,
  193. mode: str = "PROGRAM_SRAM",
  194. ) -> Path:
  195. bitstream = root / "uart_rs232_j6_system_debug_primary.bit"
  196. td_receipt = root / "td_debug.json"
  197. transcript = root / "j6sys-transcript.txt"
  198. event_stream = root / "j6sys-event-stream.json"
  199. register_dump = root / "j6sys-register-dump.json"
  200. sram_attestation = root / "manual-sram-attestation.json"
  201. bitstream.write_bytes(b"real bmc j6 windows debug bitstream")
  202. tx = 3 + 43 * poll
  203. rx = 300 if poll >= 3 else 1
  204. tok = 144 if valid >= 3 else 1
  205. transcript.write_text(
  206. "\n".join(
  207. [
  208. "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",
  209. 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}",
  210. ]
  211. )
  212. + "\n",
  213. encoding="utf-8",
  214. )
  215. event_stream.write_text(
  216. json.dumps(
  217. {
  218. "schema": "j6sys-event-stream-v1",
  219. "status": "pass",
  220. "events": [
  221. {"poll": poll, "valid": valid, "source_id": "BMC_UART_TEXT", "parser_error": bool(parser_error), "stale": bool(stale)}
  222. ],
  223. }
  224. ),
  225. encoding="utf-8",
  226. )
  227. register_dump.write_text(
  228. json.dumps(
  229. {
  230. "schema": "j6sys-register-dump-v1",
  231. "status": "pass",
  232. "debug_registers": {"wake": 3, "poll": poll, "rx": rx, "valid": valid, "uerr": uerr, "derr": derr},
  233. }
  234. ),
  235. encoding="utf-8",
  236. )
  237. td_receipt.write_text(
  238. json.dumps(
  239. {
  240. "status": "pass",
  241. "top": "uart_rs232_j6_system_debug_primary",
  242. "top_module": "uart_rs232_j6_system_debug_top",
  243. "mode": "implementation",
  244. "pin_profile": "primary",
  245. "bitstream": {"path": str(bitstream), "sha256": compute_file_hash(bitstream)},
  246. "timing_gate": {"status": "pass"},
  247. }
  248. ),
  249. encoding="utf-8",
  250. )
  251. sram_attestation.write_text(
  252. json.dumps(
  253. {
  254. "status": "pass",
  255. "mode": mode,
  256. "operator": "manual",
  257. "programmed_at": "2026-07-01T00:00:00Z",
  258. "bitstream_sha256": compute_file_hash(bitstream),
  259. "td_receipt_sha256": compute_file_hash(td_receipt),
  260. "td_log_sha256": "0" * 64,
  261. }
  262. ),
  263. encoding="utf-8",
  264. )
  265. receipt = root / "real_bmc_j6_windows_gate_v2.json"
  266. payload = {
  267. "schema": "real-bmc-j6-windows-gate-v2-receipt-v1",
  268. "status": "pass",
  269. "counterparty": "real_bmc",
  270. "pin_profile": {"name": "primary", "connector": "J6", "tx_ball": "T4", "rx_ball": "R5", "debug_rx_ball": "P10", "debug_tx_ball": "R10"},
  271. "programming": {"mode": mode, "manual_programming": True, "bitstream": {"path": str(bitstream), "sha256": compute_file_hash(bitstream)}},
  272. "layers": {
  273. "td_bitstream": {"status": "pass", "receipt": {"path": str(td_receipt), "sha256": compute_file_hash(td_receipt)}},
  274. "manual_sram_programming": {
  275. "status": "pass",
  276. "operator": "manual",
  277. "mode": mode,
  278. "manual_programming": True,
  279. "programmed_at": "2026-07-01T00:00:00Z",
  280. "attestation": {"path": str(sram_attestation), "sha256": compute_file_hash(sram_attestation)},
  281. },
  282. "windows_serial_capture": {
  283. "status": "pass",
  284. "port": "COM7",
  285. "baud": 115200,
  286. "format": "8N1",
  287. "duration_s": 90,
  288. "transcript": {"path": str(transcript), "sha256": compute_file_hash(transcript)},
  289. "event_stream": {"path": str(event_stream), "sha256": compute_file_hash(event_stream)},
  290. "register_dump": {"path": str(register_dump), "sha256": compute_file_hash(register_dump)},
  291. },
  292. "real_bmc_protocol": {"status": "pass", "valid_frame_count": valid, "source_id": "BMC_UART_TEXT"},
  293. "safety_contract": {"status": "pass", "ptc_fan_pins_exported": False, "real_actuator_action_attempted": False},
  294. "artifact_hashes": {
  295. "status": "pass",
  296. "bitstream_sha256": compute_file_hash(bitstream),
  297. "td_receipt_sha256": compute_file_hash(td_receipt),
  298. "manual_sram_attestation_sha256": compute_file_hash(sram_attestation),
  299. "transcript_sha256": compute_file_hash(transcript),
  300. "event_stream_sha256": compute_file_hash(event_stream),
  301. "register_dump_sha256": compute_file_hash(register_dump),
  302. },
  303. },
  304. "safety": {
  305. "flash_attempted": False,
  306. "driver_install_attempted": False,
  307. "programs_flash": False,
  308. "opens_unknown_com_ports": False,
  309. "toggles_dtr_rts": False,
  310. "ptc_fan_pins_exported": False,
  311. "real_ptc_fan_action_attempted": False,
  312. "uncontrolled_real_bmc_action_attempted": False,
  313. },
  314. "authority_boundary": "real-bmc-j6-windows-gate-v2 proves Windows P10/R10 J6SYS evidence for controlled J6 BMC UART/parser/safety only.",
  315. }
  316. receipt.write_text(json.dumps(payload), encoding="utf-8")
  317. return receipt
  318. def write_host_sensor_real_fan_ptc_debug921_fixture(
  319. self,
  320. root: Path,
  321. *,
  322. hardware_status: str = "not_run",
  323. ) -> Path:
  324. root.mkdir(parents=True, exist_ok=True)
  325. bitstream = root / "uart_rs232_j6_host_sensor_real_fan_ptc_temp_uart_ptc_remap_debug921.bit"
  326. td_receipt = root / "td_host_sensor_real_fan_ptc_debug921.json"
  327. sram_attestation = root / "manual-sram-attestation.json"
  328. host_raw = root / "host-port-raw.bin"
  329. host_escaped = root / "host-port-escaped.txt"
  330. debug_raw = root / "debug-uart-raw.bin"
  331. debug_escaped = root / "debug-uart-escaped.txt"
  332. replay = root / "bmc-raw-replay.bin"
  333. debug_frame_stream = root / "debug-frame-stream.json"
  334. host_sensor_report = root / "host-sensor-report.json"
  335. host_transcript = root / "host-command-transcript.json"
  336. manifest = root / "j6-host-sensor-real-fan-ptc-capture-manifest.json"
  337. commands = [
  338. "SET PTC 01 10",
  339. "SET PTC 24 20",
  340. "SET FAN 01 40",
  341. "SET FAN 04 30",
  342. "SET PID ENABLE",
  343. "GET STATUS",
  344. "GET MAP",
  345. "GET SENSOR",
  346. "GET SENSOR",
  347. "GET SENSOR",
  348. "SET PID DISABLE",
  349. "DISABLE",
  350. ]
  351. expected_ack_cmds = {
  352. "SET PTC 01 10": "PTCCH",
  353. "SET PTC 24 20": "PTCCH",
  354. "SET FAN 01 40": "FANCH",
  355. "SET FAN 04 30": "FANCH",
  356. "SET PID ENABLE": "PID_EN",
  357. "GET STATUS": "STATUS",
  358. "GET MAP": "MAP___",
  359. "GET SENSOR": "SENSOR",
  360. "SET PID DISABLE": "PID_DI",
  361. "DISABLE": "DISABL",
  362. }
  363. host_lines: list[str] = []
  364. debug_lines: list[str] = [
  365. "J6CMD seq=00000001 idx=00 name=raw text=ipmitool raw 0x36 0x6c 0xdf 0xdd 0x00 0x03",
  366. "J6EVT kind=HCTRL seq=00000006 ok=1 err=00 type=08 all=0 ch=01 pct=010 timeout=0",
  367. "J6PWM seq=00000006 src=host_manual pid=disabled timeout=0 ptc01=010 ptc24=020 fan01=040 fan04=030",
  368. "J6MOD seq=00000006 pid=disabled pid_requested=1 pid_active=0 bmc=observe_only host=slave pwm=host_manual timeout_s=5",
  369. "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",
  370. ]
  371. dimm_samples: list[dict[str, object]] = []
  372. replay_bytes = bytearray()
  373. raw_offset = 0
  374. for sample_seq in range(1, 4):
  375. payload_bytes = bytes([0xFF, 0xFF] * 24) if sample_seq == 2 else bytes(
  376. [value for dimm in range(24) for value in (0x30 + dimm + sample_seq, 0x00)]
  377. )
  378. replay_bytes.extend(payload_bytes)
  379. checksum = sum(payload_bytes) & 0xFFFF
  380. debug_lines.append(
  381. f"J6RAW seq={sample_seq:08X} off={raw_offset:08X} len=30 sum={checksum:04X} data={payload_bytes.hex().upper()}"
  382. )
  383. raw_offset += len(payload_bytes)
  384. valid = 0 if sample_seq == 2 else 24
  385. missing = 24 if sample_seq == 2 else 0
  386. status = "all_ff" if sample_seq == 2 else "valid"
  387. host_lines.append(
  388. f"SENS seq={sample_seq:08X} status={status} valid={valid:02d} missing={missing:02d} fault=0 raw=1 drop=00000000"
  389. )
  390. debug_lines.append(
  391. f"J6TEMP seq={sample_seq:08X} status={status} valid={valid:02d} missing={missing:02d} fault=0 host_report_drop=00000000"
  392. )
  393. rows = []
  394. for dimm in range(24):
  395. missing_flag = sample_seq == 2
  396. temp = -1 if missing_flag else 48 + dimm + sample_seq
  397. raw_pair = "FFFF" if missing_flag else f"{temp:02X}00"
  398. host_lines.append(
  399. f"DIMM seq={sample_seq:08X} id={dimm:02X} raw={raw_pair} temp={temp:03d} "
  400. f"missing={1 if missing_flag else 0} fault=0 status={status}"
  401. )
  402. rows.append({"id": dimm, "raw": raw_pair, "temp": temp, "missing": missing_flag, "fault": False})
  403. dimm_samples.append({"seq": sample_seq, "status": status, "valid": valid, "missing": missing, "dimm_rows": rows})
  404. host_lines.extend(
  405. [
  406. "PWM seq=00000008 src=host_manual timeout=1 ptc01=000 ptc24=000 fan01=030 fan04=030",
  407. "PID req=1 active=0 src=host_manual",
  408. "STAT hd=00000000 rd=00000000 he=00000000",
  409. ]
  410. )
  411. debug_lines.extend(
  412. [
  413. "J6PWM seq=0000000A src=host_manual pid=disabled timeout=1 ptc01=000 ptc24=000 fan01=030 fan04=030",
  414. "J6MOD seq=0000000A pid=disabled pid_requested=1 pid_active=0 bmc=observe_only host=slave pwm=host_manual timeout_s=5",
  415. f"J6STAT raw_in={len(replay_bytes):08X} raw_out={len(replay_bytes):08X} rd=00000000 hd=00000000 be=00000000 he=00000000",
  416. ]
  417. )
  418. host_text = "\r\n".join(host_lines) + "\r\n"
  419. debug_text = "\r\n".join(debug_lines) + "\r\n"
  420. bitstream.write_bytes(b"debug921 host sensor real fan ptc bitstream")
  421. host_raw.write_bytes(host_text.encode("ascii"))
  422. host_escaped.write_text(host_text, encoding="utf-8", newline="\n")
  423. debug_raw.write_bytes(debug_text.encode("ascii"))
  424. debug_escaped.write_text(debug_text, encoding="utf-8", newline="\n")
  425. replay.write_bytes(bytes(replay_bytes))
  426. td_receipt.write_text(
  427. json.dumps(
  428. {
  429. "status": "pass",
  430. "top": "uart_rs232_j6_host_sensor_real_fan_ptc_temp_uart_ptc_remap_debug921",
  431. "top_module": "uart_rs232_j6_host_sensor_real_fan_ptc_temp_uart_ptc_remap_debug921_top",
  432. "mode": "implementation",
  433. "pin_profile": "temp-uart-ptc-remap",
  434. "bitstream": {"path": str(bitstream), "sha256": compute_file_hash(bitstream)},
  435. "timing_gate": {"status": "pass"},
  436. }
  437. ),
  438. encoding="utf-8",
  439. )
  440. sram_attestation.write_text(
  441. json.dumps(
  442. {
  443. "status": "pass",
  444. "mode": "PROGRAM_SRAM",
  445. "operator": "manual",
  446. "programmed_at": "2026-07-01T00:00:00Z",
  447. "bitstream_sha256": compute_file_hash(bitstream),
  448. "td_receipt_sha256": compute_file_hash(td_receipt),
  449. }
  450. ),
  451. encoding="utf-8",
  452. )
  453. host_transcript.write_text(
  454. json.dumps(
  455. {
  456. "schema": "j6-host-sensor-real-fan-ptc-debug921-host-command-transcript-v1",
  457. "status": "pass",
  458. "host_port": "COM8",
  459. "baud": 115200,
  460. "format": "8N1",
  461. "writes_to_serial": True,
  462. "write_port_role": "HostPort",
  463. "debug_port_writes_to_serial": False,
  464. "commands": [
  465. {
  466. "seq": index + 1,
  467. "command": command,
  468. "allowed": True,
  469. "bytes_written": len(command) + 1,
  470. "expected_ack_cmd": expected_ack_cmds[command],
  471. "ack_line": f"OK seq={index + 1:08X} cmd={expected_ack_cmds[command]}",
  472. "ack_offset": index * 32,
  473. "response_offset": index * 32,
  474. "response_raw": f"OK seq={index + 1:08X} cmd={expected_ack_cmds[command]}",
  475. "response_token": f"OK seq={index + 1:08X} cmd={expected_ack_cmds[command]}",
  476. "response_class": "ok",
  477. "response_seq": index + 1,
  478. "response_cmd": expected_ack_cmds[command],
  479. "seq_match": True,
  480. "cmd_match": True,
  481. "response_late": False,
  482. "stale": False,
  483. "accepted": True,
  484. }
  485. for index, command in enumerate(commands)
  486. ],
  487. }
  488. ),
  489. encoding="utf-8",
  490. )
  491. host_sensor_report.write_text(
  492. json.dumps(
  493. {
  494. "schema": "j6-host-sensor-real-fan-ptc-host-sensor-report-v1",
  495. "status": "pass",
  496. "samples": dimm_samples,
  497. "host_report_drop": 0,
  498. "bmc_timeout": False,
  499. "source": "HostPort",
  500. }
  501. ),
  502. encoding="utf-8",
  503. )
  504. debug_frame_stream.write_text(
  505. json.dumps(
  506. {
  507. "schema": "j6-host-sensor-real-fan-ptc-debug-frame-stream-v1",
  508. "status": "pass",
  509. "frames": debug_lines,
  510. "raw_drop": 0,
  511. "host_report_drop": 0,
  512. "bmc_berr": 0,
  513. "host_err": 0,
  514. }
  515. ),
  516. encoding="utf-8",
  517. )
  518. manifest.write_text(
  519. json.dumps(
  520. {
  521. "schema": "j6-host-sensor-real-fan-ptc-capture-manifest-v1",
  522. "status": "pass",
  523. "host_port": "COM8",
  524. "debug_port": "COM7",
  525. "host_baud": 115200,
  526. "debug_baud": 921600,
  527. "host_port_writes_to_serial": True,
  528. "debug_port_writes_to_serial": False,
  529. "enumerates_com_ports": False,
  530. "opens_unknown_com_ports": False,
  531. "pin_profile_name": "temp-uart-ptc-remap",
  532. "pin_profile": {
  533. "name": "temp-uart-ptc-remap",
  534. "connector": "J6",
  535. "tx_ball": "T4",
  536. "rx_ball": "R5",
  537. "bmc_tx_ball": "T4",
  538. "bmc_rx_ball": "R5",
  539. "host_tx_ball": "P7",
  540. "host_rx_ball": "P8",
  541. "debug_rx_ball": "P10",
  542. "debug_tx_ball": "R10",
  543. },
  544. "raw_replay": {"path": "bmc-raw-replay.bin", "sha256": compute_file_hash(replay)},
  545. }
  546. ),
  547. encoding="utf-8",
  548. )
  549. payload = {
  550. "schema": "real-bmc-j6-host-sensor-real-fan-ptc-debug921-v1-receipt-v1",
  551. "status": hardware_status,
  552. "counterparty": "real_bmc",
  553. "diagnostic_scope": "host_sensor_real_fan_ptc_debug921",
  554. "pin_profile_name": "temp-uart-ptc-remap",
  555. "pin_profile": {
  556. "name": "temp-uart-ptc-remap",
  557. "connector": "J6",
  558. "tx_ball": "T4",
  559. "rx_ball": "R5",
  560. "bmc_tx_ball": "T4",
  561. "bmc_rx_ball": "R5",
  562. "host_tx_ball": "P7",
  563. "host_rx_ball": "P8",
  564. "debug_rx_ball": "P10",
  565. "debug_tx_ball": "R10",
  566. },
  567. "programming": {"mode": "PROGRAM_SRAM", "manual_programming": True, "bitstream": {"path": str(bitstream), "sha256": compute_file_hash(bitstream)}},
  568. "collector": {
  569. "host_port": "COM8",
  570. "debug_port": "COM7",
  571. "baud": 115200,
  572. "debug_baud": 921600,
  573. "format": "8N1",
  574. "flow_control": "none",
  575. "dtr_enable": False,
  576. "rts_enable": False,
  577. "writes_to_serial": True,
  578. "write_port_role": "HostPort",
  579. "host_port_writes_to_serial": True,
  580. "debug_port_writes_to_serial": False,
  581. "opens_unknown_com_ports": False,
  582. "enumerates_com_ports": False,
  583. },
  584. "layers": {
  585. "td_bitstream": {"status": "pass", "receipt": {"path": str(td_receipt), "sha256": compute_file_hash(td_receipt)}},
  586. "manual_sram_programming": {
  587. "status": "pass",
  588. "operator": "manual",
  589. "mode": "PROGRAM_SRAM",
  590. "manual_programming": True,
  591. "programmed_at": "2026-07-01T00:00:00Z",
  592. "attestation": {"path": str(sram_attestation), "sha256": compute_file_hash(sram_attestation)},
  593. },
  594. "host_command_sequence": {"status": "pass", "commands": commands},
  595. "host_control_transcript": {
  596. "status": "pass",
  597. "host_command_transcript": {"path": str(host_transcript), "sha256": compute_file_hash(host_transcript)},
  598. },
  599. "host_sensor_reports": {
  600. "status": "pass",
  601. "host_transcript_text": {"path": str(host_escaped), "sha256": compute_file_hash(host_escaped)},
  602. "host_raw_bin": {"path": str(host_raw), "sha256": compute_file_hash(host_raw)},
  603. "host_sensor_report": {"path": str(host_sensor_report), "sha256": compute_file_hash(host_sensor_report)},
  604. },
  605. "debug_frame_capture": {
  606. "status": "pass",
  607. "debug_transcript": {"path": str(debug_escaped), "sha256": compute_file_hash(debug_escaped)},
  608. "raw_bin": {"path": str(debug_raw), "sha256": compute_file_hash(debug_raw)},
  609. "raw_replay": {"path": str(replay), "sha256": compute_file_hash(replay)},
  610. "debug_frame_stream": {"path": str(debug_frame_stream), "sha256": compute_file_hash(debug_frame_stream)},
  611. "manifest": {"path": str(manifest), "sha256": compute_file_hash(manifest)},
  612. },
  613. "bmc_raw_sampling": {"status": "pass", "minimum_completed_samples": 3, "completed_samples": 3, "bmc_timeout": False},
  614. "pid_boundary": {"status": "pass", "pid_requested": True, "pid_requested_ever": True, "pid_active": False, "pwm_source": "host_manual"},
  615. "timeout_evidence": {"status": "pass", "timeout_evidence": {"timeout_s": 5, "ptc_all_percent": 0, "fan_all_percent": 30}},
  616. "pin_map": {
  617. "status": "pass",
  618. "profile": "temp-uart-ptc-remap",
  619. "ptc_count": 24,
  620. "fan_count": 4,
  621. "fan_fg_count": 8,
  622. "fan_install_count": 4,
  623. "bmc_tx_ball": "T4",
  624. "bmc_rx_ball": "R5",
  625. "host_tx_ball": "P7",
  626. "host_rx_ball": "P8",
  627. "debug_rx_ball": "P10",
  628. "debug_tx_ball": "R10",
  629. },
  630. "safety_contract": {
  631. "status": "pass",
  632. "pid_default_enabled": False,
  633. "pid_active": False,
  634. "bmc_controls_pwm": False,
  635. "debug_port_writes_to_serial": False,
  636. "host_port_writes_to_serial": True,
  637. "real_thermal_performance_claimed": False,
  638. },
  639. "real_fan_ptc_hardware_status": {"status": hardware_status, "real_fan_ptc_hardware_present": False, "qualifies_final_gate": False},
  640. "artifact_hashes": {
  641. "status": "pass",
  642. "bitstream_sha256": compute_file_hash(bitstream),
  643. "td_receipt_sha256": compute_file_hash(td_receipt),
  644. "manual_sram_attestation_sha256": compute_file_hash(sram_attestation),
  645. "host_transcript_text_sha256": compute_file_hash(host_escaped),
  646. "host_raw_bin_sha256": compute_file_hash(host_raw),
  647. "host_sensor_report_sha256": compute_file_hash(host_sensor_report),
  648. "debug_transcript_sha256": compute_file_hash(debug_escaped),
  649. "debug_raw_bin_sha256": compute_file_hash(debug_raw),
  650. "raw_replay_sha256": compute_file_hash(replay),
  651. "debug_frame_stream_sha256": compute_file_hash(debug_frame_stream),
  652. "host_command_transcript_sha256": compute_file_hash(host_transcript),
  653. "manifest_sha256": compute_file_hash(manifest),
  654. },
  655. },
  656. "safety": {
  657. "flash_attempted": False,
  658. "driver_install_attempted": False,
  659. "programs_flash": False,
  660. "programs_nonvolatile": False,
  661. "opens_unknown_com_ports": False,
  662. "enumerates_com_ports": False,
  663. "toggles_dtr_rts": False,
  664. "debug_port_writes_to_serial": False,
  665. "host_port_writes_to_serial": True,
  666. "uncontrolled_real_bmc_action_attempted": False,
  667. "real_thermal_performance_claimed": False,
  668. },
  669. "authority_boundary": (
  670. "real-bmc-j6-host-sensor-real-fan-ptc-debug921-v1 validates SRAM-only COM8 host "
  671. "1-based real FAN/PTC command evidence, COM7 debug921 frame replay, BMC raw DIMM "
  672. "sampling, HostPort temperature reporting, PID requested-but-inactive boundary, timeout fallback, "
  673. "and real FAN/PTC hardware status. It does not satisfy final-gate-v2, real-bmc-j6-windows-gate-v2, "
  674. "flash, thermal performance, production PTC/FAN qualification, or real PID closed-loop pass."
  675. ),
  676. }
  677. receipt = root / "real_bmc_j6_host_sensor_real_fan_ptc_debug921.json"
  678. receipt.write_text(json.dumps(payload), encoding="utf-8")
  679. return receipt
  680. def test_backend_capabilities_report_missing_optional_python_modules(self) -> None:
  681. caps = backend_capabilities()
  682. self.assertIn(caps["serial_backend"], {"pyserial", "powershell_dotnet_limited"})
  683. self.assertIn(caps["schema_backend"], {"jsonschema", "builtin_limited"})
  684. self.assertIn("strict_gate_requires", caps)
  685. def test_public_cli_only_exposes_latest_real_fan_ptc_and_retained_gates(self) -> None:
  686. parser = build_parser()
  687. subparsers = next(action for action in parser._actions if action.dest == "command")
  688. commands = set(subparsers.choices)
  689. expected_commands = {
  690. "preflight",
  691. "protocol-offline",
  692. "validate",
  693. "final-gate-v2-validate",
  694. "offline-fidelity-gate-v1-validate",
  695. "real-bmc-j6-windows-gate-v2-validate",
  696. "cpld-bmc-acceptance-v1-validate",
  697. "real-bmc-j6-host-sensor-real-fan-ptc-debug921-v1-validate",
  698. }
  699. self.assertEqual(commands, expected_commands)
  700. for command in [
  701. "real-bmc-j6-cr-raw-diagnostic-v1-validate",
  702. "real-bmc-j6-sensor-raw-diagnostic-v1-validate",
  703. "real-bmc-j6-host-control-pwm-diagnostic-v1-validate",
  704. "real-bmc-j6-host-control-pwm-debug921-lossless-v1-validate",
  705. "real-bmc-j6-host-sensor-pwm-debug921-v1-validate",
  706. "real-bmc-j6-gate-v1-validate",
  707. ]:
  708. self.assertNotIn(command, commands)
  709. def test_real_fan_ptc_validator_does_not_adapt_through_legacy_host_sensor_pwm(self) -> None:
  710. source = (ROOT / "tools" / "uart_receipts.py").read_text(encoding="utf-8")
  711. start = source.index("def validate_real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt")
  712. end = source.index("def validate_cpld_bmc_acceptance_v1_receipt", start)
  713. body = source[start:end]
  714. self.assertNotIn("_host_sensor_real_fan_ptc_as_pwm_payload", body)
  715. self.assertNotIn("validate_real_bmc_j6_host_sensor_pwm_debug921_v1_receipt(", body)
  716. def test_protocol_offline_receipt_accepts_echo_and_loose_hex(self) -> None:
  717. receipt = build_protocol_offline_receipt(
  718. text="ipmitool raw 0x36 0x6c 0xdf 0xdd 0x00 0x03\n"
  719. + " ".join(["0x23", "0x4b"] * 24),
  720. scenario="echo_0x_multiline",
  721. )
  722. self.assertEqual(receipt["schema"], "bmc-uart-protocol-receipt-v1")
  723. self.assertEqual(receipt["status"], "pass")
  724. self.assertEqual(receipt["parser"]["sample_count"], 24)
  725. self.assertGreaterEqual(receipt["parser"]["rejected_echo_windows"], 1)
  726. def test_protocol_offline_receipt_validates_itself_strictly(self) -> None:
  727. with tempfile.TemporaryDirectory() as tmp:
  728. receipt = build_protocol_offline_receipt(
  729. text=" ".join(["23", "4b"] * 24),
  730. scenario="bare_hex",
  731. )
  732. receipt_path = Path(tmp) / "protocol.json"
  733. receipt_path.write_text(json.dumps(receipt), encoding="utf-8")
  734. result = validate_uart_receipt(receipt_path, strict=True)
  735. self.assertEqual(result["status"], "pass")
  736. def test_loopback_strict_validation_rejects_blocked_and_missing_hashes(self) -> None:
  737. with tempfile.TemporaryDirectory() as tmp:
  738. receipt_path = Path(tmp) / "loopback.json"
  739. receipt_path.write_text(
  740. json.dumps(
  741. {
  742. "schema": "uart-loopback-receipt-v1",
  743. "status": "blocked_no_allowlist",
  744. "counterparty": "pc_emulator",
  745. "serial": {"port": "COM7", "baud": 115200, "format": "8N1", "allowlisted": False},
  746. "transcript": {"path": "transcript.txt"},
  747. "safety": {"flash_attempted": False, "real_ptc_fan_bmc_action_attempted": False, "driver_install_attempted": False},
  748. }
  749. ),
  750. encoding="utf-8",
  751. )
  752. result = validate_uart_receipt(receipt_path, strict=True)
  753. self.assertEqual(result["status"], "blocked_no_allowlist")
  754. self.assertIn("missing_transcript_hash", result["failures"])
  755. def test_board_sram_receipt_requires_sram_only_bitstream_and_debug_evidence(self) -> None:
  756. with tempfile.TemporaryDirectory() as tmp:
  757. root = Path(tmp)
  758. bit = root / "system.bit"
  759. transcript = root / "uart.log"
  760. debug = root / "debug.json"
  761. bit.write_bytes(b"fake bitstream")
  762. transcript.write_text("tx ipmitool\nrx ok\n", encoding="utf-8")
  763. debug.write_text(json.dumps({"events": [{"frame_seq": 1}], "register_dump": {"0x00": 1}}), encoding="utf-8")
  764. receipt = root / "board.json"
  765. receipt.write_text(
  766. json.dumps(
  767. {
  768. "schema": "uart-board-sram-receipt-v1",
  769. "status": "pass",
  770. "counterparty": "pc_emulator",
  771. "programming": {"mode": "PROGRAM_SRAM", "bitstream": {"path": str(bit), "sha256": compute_file_hash(bit)}},
  772. "serial": {"port": "COM7", "baud": 115200, "format": "8N1", "allowlisted": True, "dtr": False, "rts": False},
  773. "transcript": {"path": str(transcript), "sha256": compute_file_hash(transcript)},
  774. "debug_evidence": {"event_stream": str(debug), "register_dump": str(debug)},
  775. "safety": {"flash_attempted": False, "real_ptc_fan_bmc_action_attempted": False, "driver_install_attempted": False},
  776. }
  777. ),
  778. encoding="utf-8",
  779. )
  780. result = validate_uart_receipt(receipt, strict=True)
  781. self.assertEqual(result["status"], "pass")
  782. def test_board_sram_receipt_fails_closed_on_flash_marker(self) -> None:
  783. with tempfile.TemporaryDirectory() as tmp:
  784. receipt = Path(tmp) / "board.json"
  785. receipt.write_text(
  786. json.dumps(
  787. {
  788. "schema": "uart-board-sram-receipt-v1",
  789. "status": "pass",
  790. "counterparty": "pc_emulator",
  791. "programming": {"mode": "PROGRAM_FLASH", "bitstream": {"path": "x.bit", "sha256": "abc"}},
  792. "serial": {"port": "COM7", "baud": 115200, "format": "8N1", "allowlisted": True},
  793. "transcript": {"path": "uart.log", "sha256": "abc"},
  794. "debug_evidence": {"event_stream": "debug.json", "register_dump": "debug.json"},
  795. "safety": {"flash_attempted": True, "real_ptc_fan_bmc_action_attempted": False, "driver_install_attempted": False},
  796. }
  797. ),
  798. encoding="utf-8",
  799. )
  800. result = validate_uart_receipt(receipt, strict=True)
  801. self.assertEqual(result["status"], "fail_forbidden_action")
  802. def test_uart_soak_receipt_accepts_round_receipts_without_top_level_transcript(self) -> None:
  803. with tempfile.TemporaryDirectory() as tmp:
  804. root = Path(tmp)
  805. round_receipt = root / "round1.json"
  806. round_receipt.write_text(
  807. json.dumps(
  808. {
  809. "schema": "uart-loopback-receipt-v1",
  810. "status": "pass",
  811. "counterparty": "pc_emulator",
  812. "serial": {"port": "COM7", "baud": 115200, "format": "8N1", "allowlisted": True},
  813. "transcript": {"path": "transcript.txt", "sha256": compute_file_hash(root / "transcript.txt") if (root / "transcript.txt").exists() else "placeholder"},
  814. "safety": {"flash_attempted": False, "real_ptc_fan_bmc_action_attempted": False, "driver_install_attempted": False},
  815. }
  816. ),
  817. encoding="utf-8",
  818. )
  819. transcript = root / "transcript.txt"
  820. transcript.write_text("loopback ok\n", encoding="utf-8")
  821. payload = json.loads(round_receipt.read_text(encoding="utf-8"))
  822. payload["transcript"]["sha256"] = compute_file_hash(transcript)
  823. round_receipt.write_text(json.dumps(payload), encoding="utf-8")
  824. soak = root / "soak.json"
  825. soak.write_text(
  826. json.dumps(
  827. {
  828. "schema": "uart-soak-receipt-v1",
  829. "status": "pass",
  830. "counterparty": "pc_emulator",
  831. "duration_hours_requested": 0.1,
  832. "duration_hours_observed": 0.1,
  833. "rounds": [{"index": 1, "status": "pass", "receipt": str(round_receipt)}],
  834. "safety": {"flash_attempted": False, "real_ptc_fan_bmc_action_attempted": False, "driver_install_attempted": False},
  835. }
  836. ),
  837. encoding="utf-8",
  838. )
  839. result = validate_uart_receipt(soak, strict=True)
  840. self.assertEqual(result["status"], "pass")
  841. def test_final_gate_v2_rejects_chipwatcher_and_blocked_layers(self) -> None:
  842. receipt = {
  843. "schema": "final-gate-v2-receipt-v1",
  844. "status": "pass",
  845. "layers": {
  846. "static": {"status": "pass"},
  847. "model": {"status": "pass"},
  848. "replay": {"status": "pass"},
  849. "rtl_sim": {"status": "blocked_missing_tool"},
  850. "formal": {"status": "pass"},
  851. "detector_selftest": {"status": "pass"},
  852. "td_build": {"status": "pass"},
  853. "uart_strict": {"status": "pass", "schema": "uart-board-sram-validation-v1"},
  854. "chipwatcher": {"status": "pass"},
  855. },
  856. "authority_boundary": "control communication only",
  857. }
  858. result = validate_final_gate_v2_receipt(receipt, strict=True)
  859. self.assertEqual(result["status"], "fail")
  860. self.assertIn("blocked_layer:rtl_sim", result["failures"])
  861. self.assertIn("forbidden_chipwatcher_layer", result["failures"])
  862. def test_final_gate_v2_rejects_blocked_top_level_status_even_when_layers_pass(self) -> None:
  863. receipt = {
  864. "schema": "final-gate-v2-receipt-v1",
  865. "status": "blocked_missing_tool",
  866. "layers": {
  867. "static": {"status": "pass"},
  868. "model": {"status": "pass"},
  869. "replay": {"status": "pass"},
  870. "rtl_sim": {"status": "pass"},
  871. "formal": {"status": "pass"},
  872. "detector_selftest": {"status": "pass"},
  873. "td_build": {"status": "pass"},
  874. "uart_strict": {"status": "pass"},
  875. },
  876. "authority_boundary": "control communication only",
  877. }
  878. result = validate_final_gate_v2_receipt(receipt, strict=True)
  879. self.assertEqual(result["status"], "fail")
  880. self.assertIn("top_status_not_pass:blocked_missing_tool", result["failures"])
  881. def test_final_gate_v2_rejects_non_final_receipt_schema(self) -> None:
  882. receipt = {
  883. "schema": "not-a-final-gate-receipt-v1",
  884. "status": "pass",
  885. "layers": {},
  886. "authority_boundary": "not final gate evidence",
  887. }
  888. result = validate_final_gate_v2_receipt(receipt, strict=True)
  889. self.assertEqual(result["status"], "fail")
  890. self.assertIn("fail_schema", result["failures"])
  891. self.assertIn("missing_layer:static", result["failures"])
  892. self.assertIn("missing_layer:uart_strict", result["failures"])
  893. def test_offline_fidelity_gate_rejects_hardware_layers_and_blocked_required_layers(self) -> None:
  894. layers = {name: {"status": "pass"} for name in [
  895. "static",
  896. "model",
  897. "replay",
  898. "protocol_fuzz",
  899. "hdl_sim",
  900. "cocotb_virtual_lab",
  901. "virtual_driver_lab",
  902. "formal",
  903. "detector_selftest",
  904. "mutation",
  905. "thermal_digital_twin",
  906. "coverage_matrix",
  907. "td_build",
  908. "debug_bundle",
  909. ]}
  910. layers["hdl_sim"] = {"status": "blocked_missing_tool"}
  911. layers["hardware"] = {"status": "pass"}
  912. layers["uart_strict"] = {"status": "pass"}
  913. layers["chipwatcher"] = {"status": "pass"}
  914. layers["thermal_performance_pass"] = {"status": "pass"}
  915. receipt = {
  916. "schema": "offline-fidelity-gate-v1-receipt-v1",
  917. "status": "pass",
  918. "generated_at": "2026-06-30T00:00:00Z",
  919. "toolchain": {
  920. "status": "pass",
  921. "safety": {
  922. "opens_com_ports": False,
  923. "toggles_dtr_rts": False,
  924. "installs_drivers": False,
  925. "programs_flash": False,
  926. "touches_ptc_fan_bmc": False,
  927. },
  928. },
  929. "layers": layers,
  930. "coverage_matrix": {"status": "pass"},
  931. "safety": {
  932. "opens_com_ports": False,
  933. "toggles_dtr_rts": False,
  934. "programs_flash": False,
  935. "installs_drivers": False,
  936. "real_ptc_fan_bmc_action_attempted": False,
  937. },
  938. "authority_boundary": "offline thermal_performance_pass",
  939. }
  940. result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
  941. self.assertEqual(result["status"], "fail")
  942. self.assertIn("blocked_layer:hdl_sim", result["failures"])
  943. self.assertIn("forbidden_layer:hardware", result["failures"])
  944. self.assertIn("forbidden_layer:uart_strict", result["failures"])
  945. self.assertIn("forbidden_layer:chipwatcher", result["failures"])
  946. self.assertIn("forbidden_layer:thermal_performance_pass", result["failures"])
  947. self.assertIn("authority_overclaim_thermal_performance", result["failures"])
  948. def test_offline_fidelity_gate_rejects_uart_strict_and_chipwatcher_authority_overclaim(self) -> None:
  949. layers = {name: {"status": "pass"} for name in [
  950. "static",
  951. "model",
  952. "replay",
  953. "protocol_fuzz",
  954. "hdl_sim",
  955. "cocotb_virtual_lab",
  956. "virtual_driver_lab",
  957. "formal",
  958. "detector_selftest",
  959. "mutation",
  960. "thermal_digital_twin",
  961. "coverage_matrix",
  962. "td_build",
  963. "debug_bundle",
  964. ]}
  965. receipt = {
  966. "schema": "offline-fidelity-gate-v1-receipt-v1",
  967. "status": "pass",
  968. "generated_at": "2026-06-30T00:00:00Z",
  969. "toolchain": {
  970. "status": "pass",
  971. "safety": {
  972. "opens_com_ports": False,
  973. "toggles_dtr_rts": False,
  974. "installs_drivers": False,
  975. "programs_flash": False,
  976. "touches_ptc_fan_bmc": False,
  977. },
  978. },
  979. "layers": layers,
  980. "coverage_matrix": {"status": "pass"},
  981. "safety": {
  982. "opens_com_ports": False,
  983. "toggles_dtr_rts": False,
  984. "programs_flash": False,
  985. "installs_drivers": False,
  986. "real_ptc_fan_bmc_action_attempted": False,
  987. },
  988. "authority_boundary": "offline uart_strict pass and chipwatcher evidence passed",
  989. }
  990. result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
  991. self.assertEqual(result["status"], "fail")
  992. self.assertIn("authority_overclaim_uart_strict", result["failures"])
  993. self.assertIn("authority_overclaim_chipwatcher", result["failures"])
  994. def test_offline_fidelity_gate_rejects_empty_pass_layers(self) -> None:
  995. layers = {name: {"status": "pass"} for name in [
  996. "static",
  997. "model",
  998. "replay",
  999. "protocol_fuzz",
  1000. "hdl_sim",
  1001. "cocotb_virtual_lab",
  1002. "virtual_driver_lab",
  1003. "formal",
  1004. "detector_selftest",
  1005. "mutation",
  1006. "thermal_digital_twin",
  1007. "coverage_matrix",
  1008. "td_build",
  1009. "debug_bundle",
  1010. ]}
  1011. receipt = {
  1012. "schema": "offline-fidelity-gate-v1-receipt-v1",
  1013. "status": "pass",
  1014. "generated_at": "2026-06-30T00:00:00Z",
  1015. "toolchain": {
  1016. "status": "pass",
  1017. "safety": {
  1018. "opens_com_ports": False,
  1019. "toggles_dtr_rts": False,
  1020. "installs_drivers": False,
  1021. "programs_flash": False,
  1022. "touches_ptc_fan_bmc": False,
  1023. },
  1024. },
  1025. "layers": layers,
  1026. "coverage_matrix": {"status": "pass"},
  1027. "safety": {
  1028. "opens_com_ports": False,
  1029. "toggles_dtr_rts": False,
  1030. "programs_flash": False,
  1031. "installs_drivers": False,
  1032. "real_ptc_fan_bmc_action_attempted": False,
  1033. },
  1034. "authority_boundary": "offline logic, protocol, safety, debug, and virtual thermal evidence only",
  1035. }
  1036. result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
  1037. self.assertEqual(result["status"], "fail")
  1038. self.assertIn("missing_layer_evidence:protocol_fuzz:scenarios", result["failures"])
  1039. self.assertIn("missing_layer_evidence:virtual_driver_lab:user_mode_shims", result["failures"])
  1040. self.assertIn("missing_layer_evidence:mutation:mutants", result["failures"])
  1041. self.assertIn("missing_layer_evidence:td_build:elaboration", result["failures"])
  1042. def test_offline_fidelity_gate_accepts_required_layers_with_contract_evidence(self) -> None:
  1043. receipt = self.valid_offline_receipt()
  1044. result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
  1045. self.assertEqual(result["status"], "pass")
  1046. def test_offline_fidelity_gate_rejects_default_validation_with_empty_pass_layers(self) -> None:
  1047. receipt = self.valid_offline_receipt()
  1048. receipt["layers"]["virtual_driver_lab"] = {"status": "pass"}
  1049. result = validate_offline_fidelity_gate_v1_receipt(receipt)
  1050. self.assertEqual(result["status"], "fail")
  1051. self.assertIn("missing_layer_evidence:virtual_driver_lab:user_mode_shims", result["failures"])
  1052. def test_offline_fidelity_gate_rejects_incomplete_contract_coverage_matrix(self) -> None:
  1053. receipt = self.valid_offline_receipt()
  1054. receipt["layers"]["coverage_matrix"] = {
  1055. "status": "pass",
  1056. "items": [{"category": "protocol", "status": "pass", "covered_by": ["protocol_fuzz"]}],
  1057. }
  1058. receipt["coverage_matrix"] = receipt["layers"]["coverage_matrix"]
  1059. result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
  1060. self.assertEqual(result["status"], "fail")
  1061. self.assertIn("missing_layer_evidence:coverage_matrix:uart_bit", result["failures"])
  1062. self.assertIn("missing_layer_evidence:coverage_matrix:td_toolchain", result["failures"])
  1063. def test_offline_fidelity_gate_rejects_underspecified_virtual_driver_lab(self) -> None:
  1064. receipt = self.valid_offline_receipt()
  1065. receipt["layers"]["virtual_driver_lab"] = {
  1066. "status": "pass",
  1067. "user_mode_shims": [{"name": "pyserial_loopback_url", "status": "pass", "transcript": {"roundtrip": True}}],
  1068. "fault_contracts": ["timeout"],
  1069. "trace_hash": "a" * 64,
  1070. }
  1071. result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
  1072. self.assertEqual(result["status"], "fail")
  1073. self.assertIn("missing_layer_evidence:virtual_driver_lab:socket_pipe_transport", result["failures"])
  1074. self.assertIn("missing_layer_evidence:virtual_driver_lab:partial_write", result["failures"])
  1075. def test_offline_fidelity_gate_rejects_underspecified_or_failed_thermal_models(self) -> None:
  1076. receipt = self.valid_offline_receipt()
  1077. receipt["layers"]["thermal_digital_twin"] = {
  1078. "status": "pass",
  1079. "models": [{"name": "conservative", "status": "fail", "trace_hash": "c" * 64, "violations": ["ptc_not_fail_closed"]}],
  1080. }
  1081. result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
  1082. self.assertEqual(result["status"], "fail")
  1083. self.assertIn("missing_layer_evidence:thermal_digital_twin:optimistic", result["failures"])
  1084. self.assertIn("missing_layer_evidence:thermal_digital_twin:model_status", result["failures"])
  1085. def test_offline_fidelity_gate_rejects_missing_toolchain_manifest_and_cleanup_policy(self) -> None:
  1086. receipt = self.valid_offline_receipt()
  1087. receipt["toolchain"] = {
  1088. "status": "pass",
  1089. "safety": {
  1090. "opens_com_ports": False,
  1091. "toggles_dtr_rts": False,
  1092. "installs_drivers": False,
  1093. "programs_flash": False,
  1094. "touches_ptc_fan_bmc": False,
  1095. },
  1096. "authority_boundary": "user-space offline toolchain bootstrap only",
  1097. }
  1098. result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
  1099. self.assertEqual(result["status"], "fail")
  1100. self.assertIn("missing_toolchain_manifest", result["failures"])
  1101. self.assertIn("missing_toolchain_cleanup_policy", result["failures"])
  1102. def test_offline_fidelity_gate_requires_virtual_driver_lab(self) -> None:
  1103. layers = {name: {"status": "pass"} for name in [
  1104. "static",
  1105. "model",
  1106. "replay",
  1107. "protocol_fuzz",
  1108. "hdl_sim",
  1109. "cocotb_virtual_lab",
  1110. "formal",
  1111. "detector_selftest",
  1112. "mutation",
  1113. "thermal_digital_twin",
  1114. "coverage_matrix",
  1115. "td_build",
  1116. "debug_bundle",
  1117. ]}
  1118. receipt = {
  1119. "schema": "offline-fidelity-gate-v1-receipt-v1",
  1120. "status": "pass",
  1121. "generated_at": "2026-06-30T00:00:00Z",
  1122. "toolchain": {
  1123. "status": "pass",
  1124. "safety": {
  1125. "opens_com_ports": False,
  1126. "toggles_dtr_rts": False,
  1127. "installs_drivers": False,
  1128. "programs_flash": False,
  1129. "touches_ptc_fan_bmc": False,
  1130. },
  1131. },
  1132. "layers": layers,
  1133. "coverage_matrix": {"status": "pass"},
  1134. "safety": {
  1135. "opens_com_ports": False,
  1136. "toggles_dtr_rts": False,
  1137. "programs_flash": False,
  1138. "installs_drivers": False,
  1139. "real_ptc_fan_bmc_action_attempted": False,
  1140. },
  1141. "authority_boundary": "offline logic, protocol, safety, debug, and virtual thermal evidence only",
  1142. }
  1143. result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
  1144. self.assertEqual(result["status"], "fail")
  1145. self.assertIn("missing_layer:virtual_driver_lab", result["failures"])
  1146. def test_offline_fidelity_gate_rejects_toolchain_and_safety_overclaims(self) -> None:
  1147. layers = {name: {"status": "pass"} for name in [
  1148. "static",
  1149. "model",
  1150. "replay",
  1151. "protocol_fuzz",
  1152. "hdl_sim",
  1153. "cocotb_virtual_lab",
  1154. "virtual_driver_lab",
  1155. "formal",
  1156. "detector_selftest",
  1157. "mutation",
  1158. "thermal_digital_twin",
  1159. "coverage_matrix",
  1160. "td_build",
  1161. "debug_bundle",
  1162. ]}
  1163. receipt = {
  1164. "schema": "offline-fidelity-gate-v1-receipt-v1",
  1165. "status": "pass",
  1166. "generated_at": "2026-06-30T00:00:00Z",
  1167. "toolchain": {
  1168. "status": "blocked_missing_tool",
  1169. "safety": {
  1170. "opens_com_ports": False,
  1171. "toggles_dtr_rts": False,
  1172. "installs_drivers": True,
  1173. "programs_flash": False,
  1174. "touches_ptc_fan_bmc": False,
  1175. },
  1176. },
  1177. "layers": layers,
  1178. "coverage_matrix": {"status": "pass"},
  1179. "safety": {
  1180. "opens_com_ports": True,
  1181. "toggles_dtr_rts": False,
  1182. "programs_flash": False,
  1183. "installs_drivers": False,
  1184. "real_ptc_fan_bmc_action_attempted": False,
  1185. },
  1186. "notes": "DRIVER_INSTALL PROGRAM_FLASH",
  1187. "authority_boundary": "offline logic, protocol, safety, debug, and virtual thermal evidence only",
  1188. }
  1189. result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
  1190. self.assertEqual(result["status"], "fail")
  1191. self.assertIn("toolchain_status_not_pass:blocked_missing_tool", result["failures"])
  1192. self.assertIn("toolchain_safety_not_false:installs_drivers", result["failures"])
  1193. self.assertIn("safety_not_false:opens_com_ports", result["failures"])
  1194. self.assertIn("forbidden_action_marker:DRIVER_INSTALL", result["failures"])
  1195. self.assertIn("forbidden_action_marker:PROGRAM_FLASH", result["failures"])
  1196. def test_offline_fidelity_gate_rejects_offline_forbidden_hardware_markers(self) -> None:
  1197. receipt = self.valid_offline_receipt()
  1198. receipt["notes"] = ["OPEN_COM COM3", "DTR asserted", "PROGRAM_SRAM", "connect_cable -open"]
  1199. result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
  1200. self.assertEqual(result["status"], "fail")
  1201. self.assertIn("forbidden_action_marker:OPEN_COM", result["failures"])
  1202. self.assertIn("forbidden_action_marker:DTR", result["failures"])
  1203. self.assertIn("forbidden_action_marker:PROGRAM_SRAM", result["failures"])
  1204. self.assertIn("forbidden_action_marker:CONNECT_CABLE", result["failures"])
  1205. def test_offline_fidelity_gate_forbidden_marker_scan_avoids_safe_substring_false_positives(self) -> None:
  1206. receipt = self.valid_offline_receipt()
  1207. receipt["toolchain"]["manifest"]["downloads_dir"] = r"C:\Users\Administrator\CodexToolchains\CPLD\downloads"
  1208. receipt["toolchain"]["authority_boundary"] = "Offline probe checks user-space tools and does not enumerate COM ports."
  1209. receipt["td_log_tail"] = "Exported ports\nsafety downloads_to_hardware=false\n"
  1210. receipt["layers"]["td_build"]["authority_boundary"] = "does not generate/download/program a bitstream"
  1211. receipt["coverage_matrix"]["items"][0]["required"] = ["no_download_no_program"]
  1212. result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
  1213. self.assertEqual(result["status"], "pass")
  1214. self.assertNotIn("forbidden_action_marker:DOWNLOAD", result["failures"])
  1215. self.assertNotIn("forbidden_action_marker:RTS", result["failures"])
  1216. def test_offline_fidelity_gate_still_rejects_standalone_download_action(self) -> None:
  1217. receipt = self.valid_offline_receipt()
  1218. receipt["notes"] = "DOWNLOAD bitstream to device"
  1219. result = validate_offline_fidelity_gate_v1_receipt(receipt, strict=True)
  1220. self.assertEqual(result["status"], "fail")
  1221. self.assertIn("forbidden_action_marker:DOWNLOAD", result["failures"])
  1222. def test_host_sensor_text_parser_splits_literal_escaped_cr_without_newlines(self) -> None:
  1223. lines = ["SENS seq=00000001 status=valid valid=24 missing=00 fault=0 raw=1 drop=00000000"]
  1224. lines.extend(
  1225. f"DIMM seq=00000001 id={dimm:02X} raw=1F00 temp=031 missing=0 fault=0 status=valid"
  1226. for dimm in range(24)
  1227. )
  1228. parsed = _parse_host_sensor_report_text("\\r".join(lines) + "\\r")
  1229. self.assertEqual(parsed["sample_count"], 1)
  1230. self.assertEqual(parsed["dimm_rows_per_sample"], [24])
  1231. self.assertEqual(
  1232. sorted(row["id"] for row in parsed["samples"][0]["dimm_rows"]),
  1233. list(range(24)),
  1234. )
  1235. def test_host_sensor_text_parser_accepts_compact_seq_temp_aliases(self) -> None:
  1236. lines = ["SENS s=0003 st=v v=18 m=00"]
  1237. lines.extend(f"DIMM s=0003 id={dimm:02X} tp={0x30 + dimm:02X} m=0 st=v" for dimm in range(24))
  1238. parsed = _parse_host_sensor_report_text("\r\n".join(lines) + "\r\n")
  1239. self.assertEqual(parsed["sample_count"], 1)
  1240. self.assertEqual(parsed["dimm_rows_per_sample"], [24])
  1241. self.assertEqual(parsed["samples"][0]["summary"]["seq"], 3)
  1242. self.assertEqual(parsed["samples"][0]["summary"]["valid"], 24)
  1243. self.assertEqual(parsed["samples"][0]["summary"]["missing"], 0)
  1244. self.assertEqual(parsed["samples"][0]["dimm_rows"][0]["temp"], 0x30)
  1245. def test_real_bmc_j6_host_sensor_real_fan_ptc_debug921_blocks_until_real_hardware_is_present(self) -> None:
  1246. with tempfile.TemporaryDirectory() as tmp:
  1247. receipt = self.write_host_sensor_real_fan_ptc_debug921_fixture(Path(tmp))
  1248. result = validate_real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt(receipt, strict=True)
  1249. final_result = validate_final_gate_v2_receipt(receipt, strict=True)
  1250. self.assertEqual(result["status"], "blocked_waiting_for_real_fan_ptc_hardware", result["failures"])
  1251. self.assertEqual(result["real_fan_ptc_hardware_status"]["status"], "not_run")
  1252. self.assertIn("real_fan_ptc_hardware_not_run", result["failures"])
  1253. self.assertEqual(result["pin_map"]["fan_count"], 4)
  1254. self.assertFalse(result["real_fan_ptc_hardware_status"]["qualifies_final_gate"])
  1255. self.assertEqual(result["host_commands"][:4], ["SET PTC 01 10", "SET PTC 24 20", "SET FAN 01 40", "SET FAN 04 30"])
  1256. self.assertEqual(final_result["status"], "fail")
  1257. self.assertIn("fail_schema", final_result["failures"])
  1258. def test_real_bmc_j6_host_sensor_real_fan_ptc_debug921_rejects_zero_based_and_out_of_range_fan_commands(self) -> None:
  1259. scenarios = [
  1260. ("SET PTC 00 10", "host_command_not_allowed:SET PTC 00 10"),
  1261. ("SET PTC 25 10", "host_command_not_allowed:SET PTC 25 10"),
  1262. ("SET FAN 00 40", "host_command_not_allowed:SET FAN 00 40"),
  1263. ("SET FAN 05 40", "host_command_not_allowed:SET FAN 05 40"),
  1264. ]
  1265. for bad_command, expected_failure in scenarios:
  1266. with self.subTest(command=bad_command):
  1267. with tempfile.TemporaryDirectory() as tmp:
  1268. receipt = self.write_host_sensor_real_fan_ptc_debug921_fixture(Path(tmp))
  1269. payload = json.loads(receipt.read_text(encoding="utf-8"))
  1270. payload["layers"]["host_command_sequence"]["commands"][0] = bad_command
  1271. transcript = Path(payload["layers"]["host_control_transcript"]["host_command_transcript"]["path"])
  1272. transcript_payload = json.loads(transcript.read_text(encoding="utf-8"))
  1273. transcript_payload["commands"][0]["command"] = bad_command
  1274. transcript.write_text(json.dumps(transcript_payload), encoding="utf-8")
  1275. payload["layers"]["host_control_transcript"]["host_command_transcript"]["sha256"] = compute_file_hash(transcript)
  1276. payload["layers"]["artifact_hashes"]["host_command_transcript_sha256"] = compute_file_hash(transcript)
  1277. receipt.write_text(json.dumps(payload), encoding="utf-8")
  1278. result = validate_real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt(receipt, strict=True)
  1279. self.assertEqual(result["status"], "fail_forbidden_action")
  1280. self.assertIn(expected_failure, result["failures"])
  1281. def test_real_bmc_j6_host_sensor_real_fan_ptc_debug921_rejects_wrong_td_top(self) -> None:
  1282. with tempfile.TemporaryDirectory() as tmp:
  1283. receipt = self.write_host_sensor_real_fan_ptc_debug921_fixture(Path(tmp))
  1284. payload = json.loads(receipt.read_text(encoding="utf-8"))
  1285. td_path = Path(payload["layers"]["td_bitstream"]["receipt"]["path"])
  1286. td_payload = json.loads(td_path.read_text(encoding="utf-8"))
  1287. td_payload["top_module"] = "uart_rs232_j6_host_sensor_pwm_debug921_top"
  1288. td_path.write_text(json.dumps(td_payload), encoding="utf-8")
  1289. payload["layers"]["td_bitstream"]["receipt"]["sha256"] = compute_file_hash(td_path)
  1290. payload["layers"]["artifact_hashes"]["td_receipt_sha256"] = compute_file_hash(td_path)
  1291. attestation_path = Path(payload["layers"]["manual_sram_programming"]["attestation"]["path"])
  1292. attestation = json.loads(attestation_path.read_text(encoding="utf-8"))
  1293. attestation["td_receipt_sha256"] = compute_file_hash(td_path)
  1294. attestation_path.write_text(json.dumps(attestation), encoding="utf-8")
  1295. payload["layers"]["manual_sram_programming"]["attestation"]["sha256"] = compute_file_hash(attestation_path)
  1296. payload["layers"]["artifact_hashes"]["manual_sram_attestation_sha256"] = compute_file_hash(attestation_path)
  1297. receipt.write_text(json.dumps(payload), encoding="utf-8")
  1298. result = validate_real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt(receipt, strict=True)
  1299. self.assertEqual(result["status"], "fail")
  1300. self.assertIn("td_bitstream_not_host_sensor_real_fan_ptc_top", result["failures"])
  1301. def test_real_bmc_j6_host_sensor_real_fan_ptc_debug921_rejects_old_six_fan_pin_map(self) -> None:
  1302. with tempfile.TemporaryDirectory() as tmp:
  1303. receipt = self.write_host_sensor_real_fan_ptc_debug921_fixture(Path(tmp))
  1304. payload = json.loads(receipt.read_text(encoding="utf-8"))
  1305. payload["layers"]["pin_map"]["fan_count"] = 6
  1306. receipt.write_text(json.dumps(payload), encoding="utf-8")
  1307. result = validate_real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt(receipt, strict=True)
  1308. self.assertEqual(result["status"], "fail")
  1309. self.assertIn("pin_map_fan_count_not_4", result["failures"])
  1310. def test_real_bmc_j6_host_sensor_real_fan_ptc_debug921_rejects_legacy_host_sensor_pwm_sidecars(self) -> None:
  1311. with tempfile.TemporaryDirectory() as tmp:
  1312. receipt = self.write_host_sensor_real_fan_ptc_debug921_fixture(Path(tmp))
  1313. payload = json.loads(receipt.read_text(encoding="utf-8"))
  1314. report_path = Path(payload["layers"]["host_sensor_reports"]["host_sensor_report"]["path"])
  1315. report_payload = json.loads(report_path.read_text(encoding="utf-8"))
  1316. report_payload["schema"] = "j6-host-sensor-pwm-host-sensor-report-v1"
  1317. report_path.write_text(json.dumps(report_payload), encoding="utf-8")
  1318. stream_path = Path(payload["layers"]["debug_frame_capture"]["debug_frame_stream"]["path"])
  1319. stream_payload = json.loads(stream_path.read_text(encoding="utf-8"))
  1320. stream_payload["schema"] = "j6-host-sensor-pwm-debug-frame-stream-v1"
  1321. stream_path.write_text(json.dumps(stream_payload), encoding="utf-8")
  1322. payload["layers"]["host_sensor_reports"]["host_sensor_report"]["sha256"] = compute_file_hash(report_path)
  1323. payload["layers"]["debug_frame_capture"]["debug_frame_stream"]["sha256"] = compute_file_hash(stream_path)
  1324. payload["layers"]["artifact_hashes"]["host_sensor_report_sha256"] = compute_file_hash(report_path)
  1325. payload["layers"]["artifact_hashes"]["debug_frame_stream_sha256"] = compute_file_hash(stream_path)
  1326. receipt.write_text(json.dumps(payload), encoding="utf-8")
  1327. result = validate_real_bmc_j6_host_sensor_real_fan_ptc_debug921_v1_receipt(receipt, strict=True)
  1328. self.assertEqual(result["status"], "fail")
  1329. self.assertIn("host_sensor_report_wrong_schema", result["failures"])
  1330. self.assertIn("debug_frame_stream_wrong_schema", result["failures"])
  1331. def test_real_bmc_j6_windows_required_layers_remain_unchanged(self) -> None:
  1332. with tempfile.TemporaryDirectory() as tmp:
  1333. receipt = self.write_real_bmc_windows_gate_v2_fixture(Path(tmp))
  1334. result = validate_real_bmc_j6_windows_gate_v2_receipt(receipt, strict=True)
  1335. self.assertEqual(
  1336. result["required_layers"],
  1337. [
  1338. "td_bitstream",
  1339. "manual_sram_programming",
  1340. "windows_serial_capture",
  1341. "real_bmc_protocol",
  1342. "safety_contract",
  1343. "artifact_hashes",
  1344. ],
  1345. )
  1346. def test_real_bmc_j6_windows_gate_v2_accepts_j6sys_strict_evidence(self) -> None:
  1347. with tempfile.TemporaryDirectory() as tmp:
  1348. receipt = self.write_real_bmc_windows_gate_v2_fixture(Path(tmp))
  1349. result = validate_real_bmc_j6_windows_gate_v2_receipt(receipt, strict=True)
  1350. self.assertEqual(result["status"], "pass")
  1351. self.assertEqual(result["last_j6sys"]["wake"], 3)
  1352. self.assertEqual(result["last_j6sys"]["poll"], 3)
  1353. self.assertEqual(result["last_j6sys"]["valid"], 3)
  1354. def test_real_bmc_j6_windows_gate_v2_rejects_non_sram_and_j6sys_errors(self) -> None:
  1355. with tempfile.TemporaryDirectory() as tmp:
  1356. receipt = self.write_real_bmc_windows_gate_v2_fixture(
  1357. Path(tmp),
  1358. parser_error=1,
  1359. stale=1,
  1360. uerr=1,
  1361. derr=1,
  1362. mode="PROGRAM_FLASH",
  1363. )
  1364. result = validate_real_bmc_j6_windows_gate_v2_receipt(receipt, strict=True)
  1365. self.assertEqual(result["status"], "fail_forbidden_action")
  1366. self.assertIn("programming_not_sram", result["failures"])
  1367. self.assertIn("j6sys_parser_error", result["failures"])
  1368. self.assertIn("j6sys_stale", result["failures"])
  1369. self.assertIn("j6sys_uart_error", result["failures"])
  1370. self.assertIn("j6sys_debug_uart_error", result["failures"])
  1371. def test_real_bmc_j6_windows_gate_v2_rejects_short_protocol_and_hash_mismatch(self) -> None:
  1372. with tempfile.TemporaryDirectory() as tmp:
  1373. receipt = self.write_real_bmc_windows_gate_v2_fixture(Path(tmp), poll=2, valid=2)
  1374. payload = json.loads(receipt.read_text(encoding="utf-8"))
  1375. payload["layers"]["artifact_hashes"]["transcript_sha256"] = "0" * 64
  1376. receipt.write_text(json.dumps(payload), encoding="utf-8")
  1377. result = validate_real_bmc_j6_windows_gate_v2_receipt(receipt, strict=True)
  1378. self.assertEqual(result["status"], "fail")
  1379. self.assertIn("j6sys_poll_lt_3", result["failures"])
  1380. self.assertIn("j6sys_valid_lt_3", result["failures"])
  1381. self.assertIn("artifact_hash_mismatch:transcript_sha256", result["failures"])
  1382. def test_real_bmc_j6_windows_gate_v2_rejects_blocked_sidecar_json_artifacts(self) -> None:
  1383. with tempfile.TemporaryDirectory() as tmp:
  1384. receipt = self.write_real_bmc_windows_gate_v2_fixture(Path(tmp))
  1385. payload = json.loads(receipt.read_text(encoding="utf-8"))
  1386. capture_layer = payload["layers"]["windows_serial_capture"]
  1387. artifact_layer = payload["layers"]["artifact_hashes"]
  1388. event_stream = Path(capture_layer["event_stream"]["path"])
  1389. register_dump = Path(capture_layer["register_dump"]["path"])
  1390. event_stream.write_text(
  1391. json.dumps({"schema": "j6sys-event-stream-v1", "status": "blocked_missing_debug_capture", "events": []}),
  1392. encoding="utf-8",
  1393. )
  1394. register_dump.write_text(
  1395. json.dumps({"schema": "j6sys-register-dump-v1", "status": "fail_bad_capture", "debug_registers": {}}),
  1396. encoding="utf-8",
  1397. )
  1398. capture_layer["event_stream"]["sha256"] = compute_file_hash(event_stream)
  1399. capture_layer["register_dump"]["sha256"] = compute_file_hash(register_dump)
  1400. artifact_layer["event_stream_sha256"] = compute_file_hash(event_stream)
  1401. artifact_layer["register_dump_sha256"] = compute_file_hash(register_dump)
  1402. receipt.write_text(json.dumps(payload), encoding="utf-8")
  1403. result = validate_real_bmc_j6_windows_gate_v2_receipt(receipt, strict=True)
  1404. self.assertEqual(result["status"], "fail")
  1405. self.assertIn("event_stream_status_not_pass:blocked_missing_debug_capture", result["failures"])
  1406. self.assertIn("register_dump_status_not_pass:fail_bad_capture", result["failures"])
  1407. self.assertIn("event_stream_status_not_pass:empty_events", result["failures"])
  1408. self.assertIn("register_dump_status_not_pass:empty_registers", result["failures"])
  1409. def test_cpld_bmc_acceptance_v1_requires_final_and_real_bmc_windows_pass(self) -> None:
  1410. with tempfile.TemporaryDirectory() as tmp:
  1411. root = Path(tmp)
  1412. real_bmc = self.write_real_bmc_windows_gate_v2_fixture(root)
  1413. final = root / "final.json"
  1414. final.write_text(
  1415. json.dumps(
  1416. {
  1417. "schema": "final-gate-v2-receipt-v1",
  1418. "status": "pass",
  1419. "layers": {name: {"status": "pass"} for name in [
  1420. "static",
  1421. "model",
  1422. "replay",
  1423. "rtl_sim",
  1424. "formal",
  1425. "detector_selftest",
  1426. "td_build",
  1427. "uart_strict",
  1428. ]},
  1429. "authority_boundary": "control communication only",
  1430. }
  1431. ),
  1432. encoding="utf-8",
  1433. )
  1434. acceptance = root / "acceptance.json"
  1435. acceptance.write_text(
  1436. json.dumps(
  1437. {
  1438. "schema": "cpld-bmc-acceptance-v1-receipt-v1",
  1439. "status": "pass",
  1440. "layers": {
  1441. "final_gate_v2": {"status": "pass", "receipt": {"path": str(final), "sha256": compute_file_hash(final)}},
  1442. "real_bmc_j6_windows_gate_v2": {"status": "pass", "receipt": {"path": str(real_bmc), "sha256": compute_file_hash(real_bmc)}},
  1443. },
  1444. "authority_boundary": "composite acceptance for control communication and real J6 BMC Windows evidence only.",
  1445. }
  1446. ),
  1447. encoding="utf-8",
  1448. )
  1449. result = validate_cpld_bmc_acceptance_v1_receipt(acceptance, strict=True)
  1450. self.assertEqual(result["status"], "pass")
  1451. def test_cpld_bmc_acceptance_v1_propagates_child_gate_failures(self) -> None:
  1452. with tempfile.TemporaryDirectory() as tmp:
  1453. root = Path(tmp)
  1454. real_bmc = self.write_real_bmc_windows_gate_v2_fixture(root, valid=2)
  1455. final = root / "final.json"
  1456. final.write_text(
  1457. json.dumps(
  1458. {
  1459. "schema": "final-gate-v2-receipt-v1",
  1460. "status": "blocked_missing_tool",
  1461. "layers": {},
  1462. "authority_boundary": "control communication only",
  1463. }
  1464. ),
  1465. encoding="utf-8",
  1466. )
  1467. acceptance = root / "acceptance.json"
  1468. acceptance.write_text(
  1469. json.dumps(
  1470. {
  1471. "schema": "cpld-bmc-acceptance-v1-receipt-v1",
  1472. "status": "pass",
  1473. "layers": {
  1474. "final_gate_v2": {"status": "pass", "receipt": {"path": str(final), "sha256": compute_file_hash(final)}},
  1475. "real_bmc_j6_windows_gate_v2": {"status": "pass", "receipt": {"path": str(real_bmc), "sha256": compute_file_hash(real_bmc)}},
  1476. },
  1477. "authority_boundary": "composite acceptance for control communication and real J6 BMC Windows evidence only.",
  1478. }
  1479. ),
  1480. encoding="utf-8",
  1481. )
  1482. result = validate_cpld_bmc_acceptance_v1_receipt(acceptance, strict=True)
  1483. self.assertEqual(result["status"], "fail")
  1484. self.assertIn("final_gate_v2_not_pass:fail", result["failures"])
  1485. self.assertIn("real_bmc_j6_windows_gate_v2_not_pass:fail", result["failures"])
  1486. def test_cpld_bmc_acceptance_v1_dict_input_still_validates_child_receipts(self) -> None:
  1487. with tempfile.TemporaryDirectory() as tmp:
  1488. root = Path(tmp)
  1489. real_bmc = self.write_real_bmc_windows_gate_v2_fixture(root, valid=2)
  1490. final = root / "final.json"
  1491. final.write_text(
  1492. json.dumps(
  1493. {
  1494. "schema": "final-gate-v2-receipt-v1",
  1495. "status": "pass",
  1496. "layers": {name: {"status": "pass"} for name in [
  1497. "static",
  1498. "model",
  1499. "replay",
  1500. "rtl_sim",
  1501. "formal",
  1502. "detector_selftest",
  1503. "td_build",
  1504. "uart_strict",
  1505. ]},
  1506. "authority_boundary": "control communication only",
  1507. }
  1508. ),
  1509. encoding="utf-8",
  1510. )
  1511. payload = {
  1512. "schema": "cpld-bmc-acceptance-v1-receipt-v1",
  1513. "status": "pass",
  1514. "layers": {
  1515. "final_gate_v2": {"status": "pass", "receipt": {"path": str(final), "sha256": compute_file_hash(final)}},
  1516. "real_bmc_j6_windows_gate_v2": {"status": "pass", "receipt": {"path": str(real_bmc), "sha256": compute_file_hash(real_bmc)}},
  1517. },
  1518. "authority_boundary": "composite acceptance for control communication and real J6 BMC Windows evidence only.",
  1519. }
  1520. result = validate_cpld_bmc_acceptance_v1_receipt(payload, strict=True)
  1521. self.assertEqual(result["status"], "fail")
  1522. self.assertIn("real_bmc_j6_windows_gate_v2_not_pass:fail", result["failures"])
  1523. def test_legacy_real_bmc_j6_remote_collect_script_is_not_user_entrypoint(self) -> None:
  1524. self.assertFalse((ROOT / "tools" / "remote" / "collect-real-bmc-j6.ps1").exists())
  1525. script = (ROOT / "tools" / "remote" / "collect-j6-host-sensor-real-fan-ptc.ps1").read_text(
  1526. encoding="utf-8"
  1527. )
  1528. self.assertIn("host-command-transcript.json", script)
  1529. self.assertIn("debug-frame-stream.json", script)
  1530. self.assertIn("bmc-raw-replay.bin", script)
  1531. self.assertIn("real-bmc-j6-host-sensor-real-fan-ptc-debug921-v1", script)
  1532. if __name__ == "__main__":
  1533. unittest.main()