code wiki / _hdl_build / nx_estate_gate.nx
nx_estate_gate.nx source
↩ module page · 115 lines · 7319 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"
9
10const EG_INV: *u8 = "knowledge/store/inv-"
11const EG_DOM: *u8 = "estate"
12const EG_Q: *u8 = "knowledge/publish/estate-queue.tsv"
13const EG_LED: *u8 = "knowledge/publish/estate-ledger.tsv"
14const EG_STG: *u8 = "knowledge/publish/estate-stage"
15const EG_LIVE: *u8 = "knowledge/publish/estate-live"
16const EG_STAGE_FILE: *u8 = "knowledge/staging/estate/schedule.html"
17const EG_LIVE_FILE: *u8 = "knowledge/publish/estate-live/estate-schedule.html"
18
19func 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 }
20func g_i(v: i64) -> i64 {
21 let bb: *u8 = sys_mmap(28); var m: i64 = v
22 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
23 let t: *u8 = sys_mmap(28); var k: i64 = 0
24 if m == 0 { t[0] = 48 as u8; k = 1 }
25 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
26 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
27}
28func 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 }
29func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
30
31func main() -> i64 {
32 g_p("=== nx_estate_gate (R-ESTATE: a will's Schedule of Assets from the inventory) ===\n" as *u8)
33
34 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)
35 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)
36 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)
37 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)
38 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)
39 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)
40 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)
41 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)
42
43 let doc: *u8 = sys_mmap(131072)
44 let nd: i64 = er_render_schedule(EG_INV, EG_DOM, "Robert A. Family" as *u8, doc)
45 g_p("rendered Schedule of Assets = " as *u8); g_i(nd); g_p(" bytes\n" as *u8)
46 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
47 sys_mkdir("knowledge/staging/estate" as *u8, 0x1ed)
48
49 var pass: i64 = 0
50 var tot: i64 = 0
51
52 // T1 every asset present
53 tot = tot + 1
54 var ok1: i64 = 1
55 if as_contains(doc, nd, "Grandfather clock" as *u8) != 1 { ok1 = 0 }
56 if as_contains(doc, nd, "Steinway piano" as *u8) != 1 { ok1 = 0 }
57 if as_contains(doc, nd, "Coin collection" as *u8) != 1 { ok1 = 0 }
58 if as_contains(doc, nd, "Book collection" as *u8) != 1 { ok1 = 0 }
59 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) }
60
61 // T2 net worth exact
62 let total: i64 = iv_value_total(EG_INV, EG_DOM)
63 g_p("estate net worth = " as *u8); g_money(total); g_p("\n" as *u8)
64 tot = tot + 1
65 var ok2: i64 = 1
66 if total != 8035000 { ok2 = 0 }
67 if as_contains(doc, nd, "$80350.00" as *u8) != 1 { ok2 = 0 }
68 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) }
69
70 // T3 per-beneficiary + residuary
71 tot = tot + 1
72 var ok3: i64 = 1
73 if as_contains(doc, nd, "Bequeathed to Emma" as *u8) != 1 { ok3 = 0 }
74 if as_contains(doc, nd, "$50000.00" as *u8) != 1 { ok3 = 0 } // Emma subtotal (ring+piano)
75 if as_contains(doc, nd, "Residuary estate" as *u8) != 1 { ok3 = 0 } // unassigned books
76 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) }
77
78 // T4 CONSERVATION: subtotals across all distribution groups sum to the grand total
79 let owners: *i64 = sys_mmap(8 * 64) as *i64
80 let no: i64 = er_distinct_owners(EG_INV, EG_DOM, owners)
81 var sumsub: i64 = 0
82 var i: i64 = 0
83 while i < no { sumsub = sumsub + er_owner_total(EG_INV, EG_DOM, owners[i] as *u8); i = i + 1 }
84 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)
85 tot = tot + 1
86 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) }
87
88 // T5 sovereign + boundary-escaped (injected estate name cannot inject script)
89 let doc2: *u8 = sys_mmap(131072)
90 let nd2: i64 = er_render_schedule(EG_INV, EG_DOM, "<script>steal()</script>" as *u8, doc2)
91 tot = tot + 1
92 var ok5: i64 = 1
93 if as_has_thirdparty_js(doc, nd) != 0 { ok5 = 0 }
94 if as_contains(doc2, nd2, "<script" as *u8) != 0 { ok5 = 0 }
95 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) }
96
97 // T6 SHIP via the publisher
98 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
99 sys_mkdir("knowledge/staging/estate" as *u8, 0x1ed)
100 let sfd: i64 = sys_openat_wr(EG_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, doc, nd); sys_close(sfd) }
101 pub_init()
102 sys_mkdir(EG_STG, 0x1ed)
103 sys_mkdir(EG_LIVE, 0x1ed)
104 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)
105 g_p(" pub_submit schedule -> " as *u8); g_i(s1); g_p("\n" as *u8)
106 let pubd: i64 = pub_run_full(EG_Q, EG_LED, EG_STG, EG_LIVE, "publish:estate" as *u8)
107 g_p(" pub_run_full -> published_this_pass=" as *u8); g_i(pubd); g_p("\n" as *u8)
108 tot = tot + 1
109 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) }
110
111 g_p("nx_estate_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
112 if pass == tot { g_p(" verdict=GREEN (the will's Schedule of Assets: catalogued -> conserved -> shipped)\n" as *u8); return 0 }
113 g_p(" verdict=RED\n" as *u8)
114 return 1
115}