code wiki / _hdl_build / nx_estate_gate.nx
nx_estate_gate.nx source
↩ module page · 124 lines · 7934 B
1// nx_estate_gate.nx -- GATE: R-ESTATE. Renders a will's Schedule of Assets from the inventory's `estate`
2// domain and proves: T1 every catalogued asset appears, T2 net worth exact, T3 per-beneficiary bequests +
3// residuary, T4 CONSERVATION (every asset accounted to a distribution group -> subtotals sum to the total),
4// T5 sovereign + boundary-escaped, T6 SHIPPED via the publisher. license_tier: ORIGINAL
5import "nx_estate.nx"
6import "nx_inventory.nx"
7import "nx_publisher.nx"
8import "nx_syscalls.nx"
9import "nx_gate_verdict.nx"
10
11const EG_INV: *u8 = "knowledge/store/inv-"
12const EG_DOM: *u8 = "estate"
13const EG_Q: *u8 = "knowledge/publish/estate-queue.tsv"
14const EG_LED: *u8 = "knowledge/publish/estate-ledger.tsv"
15const EG_STG: *u8 = "knowledge/publish/estate-stage"
16const EG_LIVE: *u8 = "knowledge/publish/estate-live"
17const EG_STAGE_FILE: *u8 = "knowledge/staging/estate/schedule.html"
18const EG_LIVE_FILE: *u8 = "knowledge/publish/estate-live/estate-schedule.html"
19
20func g_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
21func g_i(v: i64) -> i64 {
22 let bb: *u8 = sys_mmap(28); var m: i64 = v
23 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
24 let t: *u8 = sys_mmap(28); var k: i64 = 0
25 if m == 0 { t[0] = 48 as u8; k = 1 }
26 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
27 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
28}
29func g_money(cents: i64) -> i64 { let b: *u8 = sys_mmap(32); let o: i64 = iv_money(b, 0, cents); sys_write(1, b, o); return 0 }
30func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
31
32func main() -> i64 {
33 g_p("=== nx_estate_gate (R-ESTATE: a will's Schedule of Assets from the inventory) ===\n" as *u8)
34
35 iv_add(EG_INV, EG_DOM, "clock" as *u8, "Grandfather clock" as *u8, "heirloom" as *u8, 1, "ea" as *u8, "living room" as *u8, 250000, 0, "Sarah" as *u8)
36 iv_add(EG_INV, EG_DOM, "ring" as *u8, "Wedding ring" as *u8, "jewelry" as *u8, 1, "ea" as *u8, "safe" as *u8, 800000, 0, "Emma" as *u8)
37 iv_add(EG_INV, EG_DOM, "truck" as *u8, "Ford F-150" as *u8, "vehicle" as *u8, 1, "ea" as *u8, "garage" as *u8, 1850000, 0, "Sam" as *u8)
38 iv_add(EG_INV, EG_DOM, "piano" as *u8, "Steinway piano" as *u8, "instrument" as *u8, 1, "ea" as *u8, "study" as *u8, 4200000, 0, "Emma" as *u8)
39 iv_add(EG_INV, EG_DOM, "coins" as *u8, "Coin collection" as *u8, "collectible" as *u8, 1, "set" as *u8, "safe" as *u8, 575000, 0, "Sarah" as *u8)
40 iv_add(EG_INV, EG_DOM, "tools" as *u8, "Tool collection" as *u8, "equipment" as *u8, 1, "lot" as *u8, "garage" as *u8, 150000, 0, "Sam" as *u8)
41 iv_add(EG_INV, EG_DOM, "china" as *u8, "China dinner set" as *u8, "houseware" as *u8, 1, "set" as *u8, "dining room" as *u8, 90000, 0, "Sarah" as *u8)
42 iv_add(EG_INV, EG_DOM, "books" as *u8, "Book collection" as *u8, "houseware" as *u8, 1, "lot" as *u8, "study" as *u8, 120000, 0, "(residuary)" as *u8)
43
44 let doc: *u8 = sys_mmap(131072)
45 let nd: i64 = er_render_schedule(EG_INV, EG_DOM, "Robert A. Family" as *u8, doc)
46 g_p("rendered Schedule of Assets = " as *u8); g_i(nd); g_p(" bytes\n" as *u8)
47 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
48 sys_mkdir("knowledge/staging/estate" as *u8, 0x1ed)
49
50 var pass: i64 = 0
51 var tot: i64 = 0
52
53 // T1 every asset present
54 tot = tot + 1
55 var ok1: i64 = 1
56 if as_contains(doc, nd, "Grandfather clock" as *u8) != 1 { ok1 = 0 }
57 if as_contains(doc, nd, "Steinway piano" as *u8) != 1 { ok1 = 0 }
58 if as_contains(doc, nd, "Coin collection" as *u8) != 1 { ok1 = 0 }
59 if as_contains(doc, nd, "Book collection" as *u8) != 1 { ok1 = 0 }
60 if ok1 == 1 { pass = pass + 1; g_p("PASS T1 all catalogued assets appear on the schedule\n" as *u8) } else { g_p("FAIL T1\n" as *u8) }
61
62 // T2 net worth exact
63 let total: i64 = iv_value_total(EG_INV, EG_DOM)
64 g_p("estate net worth = " as *u8); g_money(total); g_p("\n" as *u8)
65 tot = tot + 1
66 var ok2: i64 = 1
67 if total != 8035000 { ok2 = 0 }
68 if as_contains(doc, nd, "$80350.00" as *u8) != 1 { ok2 = 0 }
69 if ok2 == 1 { pass = pass + 1; g_p("PASS T2 net worth exact + on the document ($80350.00, integer cents)\n" as *u8) } else { g_p("FAIL T2 total=" as *u8); g_i(total); g_p("\n" as *u8) }
70
71 // T3 per-beneficiary + residuary
72 tot = tot + 1
73 var ok3: i64 = 1
74 if as_contains(doc, nd, "Bequeathed to Emma" as *u8) != 1 { ok3 = 0 }
75 if as_contains(doc, nd, "$50000.00" as *u8) != 1 { ok3 = 0 } // Emma subtotal (ring+piano)
76 if as_contains(doc, nd, "Residuary estate" as *u8) != 1 { ok3 = 0 } // unassigned books
77 if ok3 == 1 { pass = pass + 1; g_p("PASS T3 per-beneficiary bequests + residuary (Emma $50000.00, residuary section present)\n" as *u8) } else { g_p("FAIL T3\n" as *u8) }
78
79 // T4 CONSERVATION: subtotals across all distribution groups sum to the grand total
80 // ER_OWNCAP (nx_estate) sizes this array and is passed as the bound -- one name, no drift, and the
81 // gate exercises the SAME capped path the renderer uses rather than a looser one of its own.
82 let owners: *i64 = sys_mmap(8 * ER_OWNCAP) as *i64
83 let no: i64 = er_distinct_owners(EG_INV, EG_DOM, owners, ER_OWNCAP)
84 var sumsub: i64 = 0
85 var i: i64 = 0
86 while i < no { sumsub = sumsub + er_owner_total(EG_INV, EG_DOM, owners[i] as *u8); i = i + 1 }
87 g_p("distribution groups=" as *u8); g_i(no); g_p(" sum of subtotals=" as *u8); g_money(sumsub); g_p(" total=" as *u8); g_money(total); g_p("\n" as *u8)
88 tot = tot + 1
89 if sumsub == total { pass = pass + 1; g_p("PASS T4 conservation: every asset accounted for (subtotals sum to the estate total)\n" as *u8) } else { g_p("FAIL T4 sum=" as *u8); g_i(sumsub); g_p("\n" as *u8) }
90
91 // T5 sovereign + boundary-escaped (injected estate name cannot inject script)
92 let doc2: *u8 = sys_mmap(131072)
93 let nd2: i64 = er_render_schedule(EG_INV, EG_DOM, "<script>steal()</script>" as *u8, doc2)
94 tot = tot + 1
95 var ok5: i64 = 1
96 if as_has_thirdparty_js(doc, nd) != 0 { ok5 = 0 }
97 if as_contains(doc2, nd2, "<script" as *u8) != 0 { ok5 = 0 }
98 if ok5 == 1 { pass = pass + 1; g_p("PASS T5 sovereign (0 JS) + boundary-escaped (injected estate name neutralised)\n" as *u8) } else { g_p("FAIL T5\n" as *u8) }
99
100 // T6 SHIP via the publisher
101 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
102 sys_mkdir("knowledge/staging/estate" as *u8, 0x1ed)
103 let sfd: i64 = sys_openat_wr(EG_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, doc, nd); sys_close(sfd) }
104 pub_init()
105 sys_mkdir(EG_STG, 0x1ed)
106 sys_mkdir(EG_LIVE, 0x1ed)
107 let s1: i64 = pub_submit_to(EG_Q, EG_STAGE_FILE, "estate-schedule.html" as *u8, "andelinwest" as *u8, "nishi-estate" as *u8, "internal" as *u8)
108 g_p(" pub_submit schedule -> " as *u8); g_i(s1); g_p("\n" as *u8)
109 let pubd: i64 = pub_run_full(EG_Q, EG_LED, EG_STG, EG_LIVE, "publish:estate" as *u8)
110 g_p(" pub_run_full -> published_this_pass=" as *u8); g_i(pubd); g_p("\n" as *u8)
111 tot = tot + 1
112 if g_exists(EG_LIVE_FILE) == 1 { pass = pass + 1; g_p("PASS T6 SHIPPED the Schedule of Assets to liveroot (sha-verified, ledgered)\n" as *u8) } else { g_p("FAIL T6\n" as *u8) }
113
114 g_p("nx_estate_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
115 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
116 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
117 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
118 let ctr__dry: *i64 = gv_ctr()
119 ctr__dry[0] = pass
120 ctr__dry[1] = tot
121 let rc__dry: i64 = gv_verdict("ESTATE-GATE" as *u8, ctr__dry, "the will's Schedule of Assets: catalogued -> conserved -> shipped)" as *u8)
122 sys_exit(rc__dry)
123 return rc__dry
124}