code wiki / (root) / nx_maint_simpage_test.nx

nx_maint_simpage_test.nx source

↩ module page · 75 lines · 3344 B

1// nx_maint_simpage_test.nx -- gate for the in-browser proof page (the capstone). 2// 3// Runs the closed + open simulation, the RUL prognosis, and the business model, 4// renders the single proof page, and asserts: it is fail-closed clean (0 5// <script>, 0 http), valid HTML, and carries every proof (simulation failures, 6// prognosis, business VIABLE + the dollar value), cross-browser by construction. 7// 8// expect_exit: 0 9// 10// license_tier: ORIGINAL 11 12import "nx_syscalls_x86_64.nx" 13import "nx_maint_simpage.nx" 14 15func main() -> i64 { 16 // scratch for the simulation pipeline 17 let t: *i64 = sys_mmap(128) as *i64 18 let indoor: *i64 = sys_mmap(128) as *i64 19 let outdoor: *i64 = sys_mmap(128) as *i64 20 let on: *i64 = sys_mmap(128) as *i64 21 let hout: *HvacEff = sys_mmap(128) as *HvacEff 22 let plan: *ActionPlan = sys_mmap(64) as *ActionPlan 23 24 // ===== run the closed + open simulation ======================== 25 let twc: *TwinThermal = sys_mmap(64) as *TwinThermal 26 nx_twin_init(twc, 400, 100) 27 nx_sim_run(twc, 1, 20, t, indoor, outdoor, on, hout, plan, 60000, 150) 28 let two: *TwinThermal = sys_mmap(64) as *TwinThermal 29 nx_twin_init(two, 400, 100) 30 nx_sim_run(two, 0, 20, t, indoor, outdoor, on, hout, plan, 60000, 150) 31 if twc.failures_seen != 2 { return 10 } 32 if two.failures_seen != 13 { return 11 } 33 34 // ===== run the RUL prognosis =================================== 35 let m: *i64 = sys_mmap(128) as *i64 36 let tr: *i64 = sys_mmap(128) as *i64 37 let rout: *RulEst = sys_mmap(64) as *RulEst 38 let rspec: *RulSpec = sys_mmap(64) as *RulSpec 39 rspec.fail_threshold = 150 40 rspec.imminent_window = 5 41 rspec.soon_window = 15 42 rspec.plan_window = 40 43 m[0]=400; m[1]=360; m[2]=320; m[3]=280 44 tr[0]=0; tr[1]=10; tr[2]=20; tr[3]=30 45 nx_rul_estimate(m, tr, 4, rspec, rout) 46 if rout.verdict != NX_RUL_PLAN { return 20 } 47 48 // ===== run the business model ================================== 49 let bp: *BizParams = sys_mmap(64) as *BizParams 50 let bout: *BizResult = sys_mmap(64) as *BizResult 51 bp.avg_failure_cost_cents = 80000 52 bp.failures_reactive_per_100 = 13 53 bp.failures_proactive_per_100 = 2 54 bp.subscription_cents_yr = 6000 55 bp.platform_cost_cents_yr = 1200 56 bp.n_assets = 10000 57 nx_biz_model(bp, bout) 58 if bout.verdict != NX_BIZ_VIABLE { return 30 } 59 60 // ===== render the in-browser proof page ======================== 61 let buf: *u8 = sys_mmap(4096) 62 let len: i64 = nx_simpage_render(buf, 4096, twc, two, rout, bout) 63 if len <= 0 { return 39 } 64 if nx_maint_render_is_clean(buf, len) != 1 { return 40 } // 0 script, 0 http 65 if mr_contains(buf, len, "<!doctype html" as *u8) != 1 { return 41 } 66 if mr_contains(buf, len, "</html>" as *u8) != 1 { return 42 } 67 if mr_contains(buf, len, "self-fixes" as *u8) != 1 { return 43 } 68 if mr_contains(buf, len, "13 failures" as *u8) != 1 { return 44 } // open-loop stays broken 69 if mr_contains(buf, len, "Plan service" as *u8) != 1 { return 45 } // prognosis 70 if mr_contains(buf, len, "VIABLE" as *u8) != 1 { return 46 } // business verdict 71 if mr_contains(buf, len, "$88" as *u8) != 1 { return 47 } // value created/asset-yr 72 if mr_contains(buf, len, "Chrome/Firefox/Edge" as *u8) != 1 { return 48 } // cross-browser 73 74 return 0 75}