test_uart_receipts.py 101 KB

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