test_uart_receipts.py 93 KB

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