code wiki / _hdl_build / nx_seedlib_gate.nx
nx_seedlib_gate.nx source
↩ module page · 110 lines · 7706 B
1// nx_seedlib_gate.nx -- GATE: the capability is REAL (it gates a real feature). T1 a gardener WITHOUT the
2// host_seed_library capability is REFUSED node creation (the reward is enforced, not cosmetic). T2 the HOLDER
3// (earned it via rewards) CAN create a node. T3 stock the library. T4 borrow (can't take more than available).
4// T5 return MORE than taken (the seed-library ethic) -- additive loan ledger, net positive. T6 node page ships.
5// license_tier: ORIGINAL
6import "nx_seedlib.nx"
7import "nx_rewards.nx"
8import "nx_publisher.nx"
9import "nx_seg_store.nx"
10import "nx_syscalls.nx"
11
12const LG_SEED: *u8 = "knowledge/store/seedlib-"
13const LG_REWARD: *u8 = "knowledge/store/slrw-reward-"
14const LG_STAGE_FILE: *u8 = "knowledge/staging/seedlib/node.html"
15const LG_LIVE_FILE: *u8 = "knowledge/publish/seedlib-live/node.html"
16
17func 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 }
18func g_i(v: i64) -> i64 {
19 let bb: *u8 = sys_mmap(28); var m: i64 = v
20 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
21 let t: *u8 = sys_mmap(28); var k: i64 = 0
22 if m == 0 { t[0] = 48 as u8; k = 1 }
23 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
24 var i: i64 = 0; while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } sys_write(1, bb, k); return 0
25}
26func g_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
27
28func main() -> i64 {
29 g_p("=== nx_seedlib_gate (the capability is real: it gates a real feature) ===\n" as *u8)
30
31 // Alice EARNS the host_seed_library capability (via a real reward); Bob does not.
32 rw_def_achievement(LG_REWARD, "swap_master" as *u8, "Swap Master" as *u8, "swap" as *u8, "CAPABILITY" as *u8, 0, "host_seed_library" as *u8, "completed a swap set" as *u8)
33 rw_grant(LG_REWARD, "alice" as *u8, "swap_master" as *u8, 100)
34
35 var pass: i64 = 0
36 var tot: i64 = 0
37
38 // T1 capability ENFORCED: Bob (no capability) is REFUSED
39 let bobtry: i64 = sl_create_node(LG_SEED, LG_REWARD, "bobnode" as *u8, "bob" as *u8, "Bob's Library" as *u8, "TX-Austin" as *u8, 101)
40 g_p("bob (no cap) create -> " as *u8); g_i(bobtry); g_p(" exists=" as *u8); g_i(sl_node_exists(LG_SEED, "bobnode" as *u8)); g_p("\n" as *u8)
41 tot = tot + 1
42 if bobtry == 0 { if sl_node_exists(LG_SEED, "bobnode" as *u8) == 0 { pass = pass + 1; g_p("PASS T1 capability ENFORCED: without host_seed_library, creating a node is REFUSED (reward is real)\n" as *u8) } else { g_p("FAIL T1 node created\n" as *u8) } } else { g_p("FAIL T1 not refused\n" as *u8) }
43
44 // T2 the holder CAN create
45 let alicetry: i64 = sl_create_node(LG_SEED, LG_REWARD, "atxnode" as *u8, "alice" as *u8, "Austin Seed Library" as *u8, "TX-Austin" as *u8, 102)
46 let host: *u8 = sys_mmap(48); sl_node_str(LG_SEED, "atxnode" as *u8, 0, host)
47 g_p("alice (has cap) create -> " as *u8); g_i(alicetry); g_p(" host=" as *u8); g_p(host); g_p("\n" as *u8)
48 tot = tot + 1
49 if alicetry == 1 { if fd_streq(host, "alice" as *u8) == 1 { pass = pass + 1; g_p("PASS T2 the capability-holder CAN run a node (Alice hosts the Austin Seed Library)\n" as *u8) } else { g_p("FAIL T2 host\n" as *u8) } } else { g_p("FAIL T2 create\n" as *u8) }
50
51 // T3 stock the library
52 sl_contribute(LG_SEED, "atxnode" as *u8, "basil" as *u8, 50)
53 sl_contribute(LG_SEED, "atxnode" as *u8, "tomato" as *u8, 30)
54 g_p("stock basil=" as *u8); g_i(sl_stock(LG_SEED, "atxnode" as *u8, "basil" as *u8)); g_p(" tomato=" as *u8); g_i(sl_stock(LG_SEED, "atxnode" as *u8, "tomato" as *u8)); g_p("\n" as *u8)
55 tot = tot + 1
56 if sl_stock(LG_SEED, "atxnode" as *u8, "basil" as *u8) == 50 { if sl_stock(LG_SEED, "atxnode" as *u8, "tomato" as *u8) == 30 { pass = pass + 1; g_p("PASS T3 library stocked (basil 50, tomato 30)\n" as *u8) } else { g_p("FAIL T3 tomato\n" as *u8) } } else { g_p("FAIL T3 basil\n" as *u8) }
57
58 // T4 borrow; can't take more than available
59 let took: i64 = sl_take(LG_SEED, "atxnode" as *u8, "bob" as *u8, "basil" as *u8, 5, 103)
60 let overreach: i64 = sl_take(LG_SEED, "atxnode" as *u8, "bob" as *u8, "basil" as *u8, 1000, 103)
61 let after: i64 = sl_stock(LG_SEED, "atxnode" as *u8, "basil" as *u8)
62 g_p("bob took 5 -> " as *u8); g_i(took); g_p("; took 1000 -> " as *u8); g_i(overreach); g_p("; basil now=" as *u8); g_i(after); g_p("\n" as *u8)
63 tot = tot + 1
64 var ok4: i64 = 1
65 if took != 1 { ok4 = 0 }
66 if overreach != 0 { ok4 = 0 } // can't take what isn't there
67 if after != 45 { ok4 = 0 } // 50 - 5, the failed take changed nothing
68 if ok4 == 1 { pass = pass + 1; g_p("PASS T4 borrow works; over-borrow refused (basil 50->45, the 1000 attempt left stock untouched)\n" as *u8) } else { g_p("FAIL T4\n" as *u8) }
69
70 // T5 return MORE than taken (the ethic); additive ledger
71 sl_return(LG_SEED, "atxnode" as *u8, "bob" as *u8, "basil" as *u8, 12, 200)
72 let net: i64 = sl_member_net(LG_SEED, "atxnode" as *u8, "bob" as *u8, "basil" as *u8)
73 let stockf: i64 = sl_stock(LG_SEED, "atxnode" as *u8, "basil" as *u8)
74 let loans: i64 = sl_loann(LG_SEED, "atxnode" as *u8)
75 let firstq: i64 = sl_loan_int(LG_SEED, "atxnode" as *u8, 0, 2) // first loan (the take of 5) still intact
76 g_p("after return 12: net=" as *u8); g_i(net); g_p(" stock=" as *u8); g_i(stockf); g_p(" loans=" as *u8); g_i(loans); g_p(" first-loan-qty=" as *u8); g_i(firstq); g_p("\n" as *u8)
77 tot = tot + 1
78 var ok5: i64 = 1
79 if net != 7 { ok5 = 0 } // returned 12 - took 5 = +7 to the commons
80 if stockf != 57 { ok5 = 0 } // 45 + 12
81 if loans != 2 { ok5 = 0 } // take + return logged; the failed over-borrow was NOT logged
82 if firstq != 5 { ok5 = 0 } // additive: the original take record is intact
83 if ok5 == 1 { pass = pass + 1; g_p("PASS T5 returned MORE than taken (+7 to the commons); additive ledger intact\n" as *u8) } else { g_p("FAIL T5\n" as *u8) }
84
85 // T6 node page renders + ships
86 let page: *u8 = sys_mmap(65536)
87 let np: i64 = sl_render_node(LG_SEED, "atxnode" as *u8, page)
88 g_p("node page = " as *u8); g_i(np); g_p(" bytes\n" as *u8)
89 tot = tot + 1
90 var ok6: i64 = 1
91 if as_has_thirdparty_js(page, np) != 0 { ok6 = 0 }
92 if as_contains(page, np, "Austin Seed Library" as *u8) != 1 { ok6 = 0 }
93 if as_contains(page, np, "basil" as *u8) != 1 { ok6 = 0 }
94 if as_contains(page, np, "return more than you took" as *u8) != 1 { ok6 = 0 }
95 sys_mkdir("knowledge/staging" as *u8, 0x1ed)
96 sys_mkdir("knowledge/staging/seedlib" as *u8, 0x1ed)
97 let sfd: i64 = sys_openat_wr(LG_STAGE_FILE, 420); if sfd >= 0 { sys_write(sfd, page, np); sys_close(sfd) }
98 pub_init()
99 sys_mkdir("knowledge/publish/seedlib-stage" as *u8, 0x1ed)
100 sys_mkdir("knowledge/publish/seedlib-live" as *u8, 0x1ed)
101 pub_submit_to("knowledge/publish/seedlib-queue.tsv" as *u8, LG_STAGE_FILE, "node.html" as *u8, "nishifoodfamily" as *u8, "nishi-seedlib" as *u8, "internal" as *u8)
102 pub_run_full("knowledge/publish/seedlib-queue.tsv" as *u8, "knowledge/publish/seedlib-ledger.tsv" as *u8, "knowledge/publish/seedlib-stage" as *u8, "knowledge/publish/seedlib-live" as *u8, "publish:seedlib" as *u8)
103 if g_exists(LG_LIVE_FILE) != 1 { ok6 = 0 }
104 if ok6 == 1 { pass = pass + 1; g_p("PASS T6 seed-library node page renders sovereign + ships\n" as *u8) } else { g_p("FAIL T6\n" as *u8) }
105
106 g_p("nx_seedlib_gate pass=" as *u8); g_i(pass); g_p("/" as *u8); g_i(tot)
107 if pass == tot { g_p(" verdict=GREEN (the earned capability runs a real seed-library node; borrow, grow, return more)\n" as *u8); return 0 }
108 g_p(" verdict=RED\n" as *u8)
109 return 1
110}