code wiki / (root) / nx_goalmap_record_gate.nx

nx_goalmap_record_gate.nx source

↩ module page · 154 lines · 12124 B

1// nx_goalmap_record_gate.nx -- EC38 RECORD GAPS proven on a PLANTED compare tree: two boards, one invoked-tool document, one 2// queue callout. The boarded set (matrix organ + symbol, plan rung symbol, gates organ) is DERIVED, ORGAN candidates come 3// from the invoked set, DIRECTIVE candidates from the queue row only (a lesson row's prose is never a directive), the 4// partition sums, the plane is rewritten whole (a second run yields the same rows), a boarded organ is never filed 5// (neg-control) and removing it from its board makes it appear (bite). Drives the LIB in-process on a /tmp fixture; the 6// production conf, plane and journal are never touched. 7// exit: 0 GREEN . 1 RED . 3 SKIP license_tier: ORIGINAL No hw writes. 8import "nx_syscalls.nx" 9import "nx_gate_verdict.nx" 10import "nx_goalmap_lib.nx" 11import "nx_gauge_lib.nx" // ga_judge + GA_* for the stamp teeth (the lib imports it too; stated here so the gate's closure is explicit) 12 13const RG_SPAN: i64 = 16 14const RG_CADENCE: i64 = 86400 // the fixture conf declares no cadence row, so the lib's default is what its stamp carries 15const RG_EXP_TOTAL: i64 = 3 16const RG_EXP_FEED_LINES: i64 = 4 // one header line + three rows 17const RG_ROWS: *u8 = "/tmp/nx_goalmap_record_gate/rg.conf.rows" 18const RG_STAMP: *u8 = "/tmp/nx_goalmap_record_gate/rg.conf.stamp" 19const RG_ROOT: *u8 = "/tmp/nx_goalmap_record_gate" 20const RG_STORE: *u8 = "/tmp/nx_goalmap_record_gate/store" 21const RG_PLANS: *u8 = "/tmp/nx_goalmap_record_gate/plans/" 22const RG_PLANS2: *u8 = "/tmp/nx_goalmap_record_gate/plans2/" 23const RG_GATES: *u8 = "/tmp/nx_goalmap_record_gate/gates/" 24const RG_FREQ: *u8 = "/tmp/nx_goalmap_record_gate/freq.json" 25const RG_CONF: *u8 = "/tmp/nx_goalmap_record_gate/rg.conf" 26const RG_CONF2: *u8 = "/tmp/nx_goalmap_record_gate/rg2.conf" 27const RG_CONF_ABSENT: *u8 = "/tmp/nx_goalmap_record_gate/absent.conf" 28const RG_PLANE: *u8 = "/tmp/nx_goalmap_record_gate/store/comparegaps-" 29const RG_PLANE2: *u8 = "/tmp/nx_goalmap_record_gate/store/comparegaps2-" 30const RG_MODE_RWX: i64 = 493 31const RG_MODE_RW: i64 = 420 32const RG_PATHB: i64 = 512 33const RG_LOADCAP: i64 = 65536 34const RG_NL: i64 = 10 35 36func rg_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 37func rg_path(out: *u8, dir: *u8, name: *u8) -> i64 { var o: i64 = sj_cat(out, 0, dir); o = sj_cat(out, o, name); out[o] = 0 as u8; return o } 38func rg_put(path: *u8, body: *u8) -> i64 { 39 sys_unlinkat(path) 40 let fd: i64 = sys_openat_wr(path, RG_MODE_RW) 41 if fd < 0 { return 0 - 1 } 42 let w: i64 = sys_write(fd, body, rg_slen(body)) 43 sys_close(fd) 44 return w 45} 46func rg_put_in(dir: *u8, name: *u8, body: *u8) -> i64 { let p: *u8 = sys_mmap(RG_PATHB); rg_path(p, dir, name); return rg_put(p, body) } 47func rg_find(buf: *u8, n: i64, needle: *u8) -> i64 { 48 let m: i64 = rg_slen(needle) 49 if m == 0 { return 0 } 50 var i: i64 = 0 51 while i + m <= n { var j: i64 = 0; var ok: i64 = 1; while j < m { if buf[i + j] != needle[j] { ok = 0 } j = j + 1 } if ok == 1 { return 1 } i = i + 1 } 52 return 0 53} 54func rg_lines(buf: *u8, n: i64) -> i64 { var c: i64 = 0; var i: i64 = 0; while i < n { if buf[i] == (RG_NL as u8) { c = c + 1 } i = i + 1 } return c } 55// the planted boards: domain a carries nx_bx (unless with_bx=0), a watch on qq_watch, rung foo_sym, a queue callout naming 56// nx_unboarded_z and _ABSENT_:qq_sym and nx_bx and qq_watch, and a LESSON row naming nx_never_mind; domain b carries nx_bz 57func rg_plant(plans: *u8, with_bx: i64) -> i64 { 58 sys_mkdir(plans, RG_MODE_RWX) 59 rg_put_in(plans, "regen.list" as *u8, "a\nb\n" as *u8) 60 if with_bx == 1 { 61 rg_put_in(plans, "a.matrix" as *u8, "# planted\nROW BX|runtime/nx_bx.nx|bx_sym|1|0|0|0|0|note\nWATCH|runtime/nx_w.nx|_ABSENT_:qq_watch|1|0|0|0|0|note\n" as *u8) 62 } else { 63 rg_put_in(plans, "a.matrix" as *u8, "# planted\nWATCH|runtime/nx_w.nx|_ABSENT_:qq_watch|1|0|0|0|0|note\n" as *u8) 64 } 65 rg_put_in(plans, "a.plan" as *u8, "rung|A1|title|foo_sym|note|Organ|1|-\nlog|1|A1|queue|owed: nx_unboarded_z and _ABSENT_:qq_sym then nx_bx again and qq_watch\nlog|2|A1|lesson|nx_never_mind is prose in a lesson row and never a directive\n" as *u8) 66 rg_put_in(plans, "b.matrix" as *u8, "ROW BZ|runtime/nx_bz.nx|bz_sym|1|0|0|0|0|note\n" as *u8) 67 rg_put_in(plans, "b.plan" as *u8, "rung|B1|t|bz_sym|note|Organ|1|-\n" as *u8) 68 return 0 69} 70func rg_conf(path: *u8, plans: *u8, plane: *u8) -> i64 { 71 let b: *u8 = sys_mmap(4096) 72 var o: i64 = sj_cat(b, 0, "# planted\nsource|invoked|" as *u8) 73 o = sj_cat(b, o, RG_FREQ) 74 o = sj_cat(b, o, "\nsource|plans|" as *u8) 75 o = sj_cat(b, o, plans) 76 o = sj_cat(b, o, "\nsource|gates|" as *u8) 77 o = sj_cat(b, o, RG_GATES) 78 o = sj_cat(b, o, "\nsource|debt|/tmp/none\nsource|weird|x\nplane|" as *u8) 79 o = sj_cat(b, o, plane) 80 o = sj_cat(b, o, "\n" as *u8) 81 b[o] = 0 as u8 82 return rg_put(path, b) 83} 84 85func main(argc: i64, argv: *i64) -> i64 { 86 let ctr: *i64 = gv_ctr() 87 gv_head("NX-GOALMAP-RECORD-GATE: EC38 record gaps on a planted tree -- boarded set derived, organ and directive candidates, partition sums, plane idempotent, a boarded organ never filed until its board drops it" as *u8) 88 sys_mkdir(RG_ROOT, RG_MODE_RWX) 89 sys_mkdir(RG_STORE, RG_MODE_RWX) 90 sys_mkdir(RG_GATES, RG_MODE_RWX) 91 sys_unlinkat(RG_CONF_ABSENT) 92 rg_plant(RG_PLANS, 1) 93 rg_plant(RG_PLANS2, 0) 94 rg_put_in(RG_GATES, "a.gates" as *u8, "# planted\nnx_gz.elf|x y|note|runtime/nx_gz.nx\n" as *u8) 95 rg_put(RG_FREQ, "{\"v\":1,\"tool\":\"nx_actlog\",\"averb\":\"freq\",\"distinct\":5,\"freq\":[{\"tv\":\"nx_bx:call\",\"count\":5},{\"tv\":\"nx_orphan_q:call\",\"count\":3},{\"tv\":\"Bash:-\",\"count\":9},{\"tv\":\"mcp__nishi__nx_bz:-\",\"count\":2},{\"tv\":\"/vol/x/nx_gz.sov.elf:run\",\"count\":4}],\"shown\":5}\n" as *u8) 96 rg_conf(RG_CONF, RG_PLANS, RG_PLANE) 97 rg_conf(RG_CONF2, RG_PLANS2, RG_PLANE2) 98 let out: *u8 = sys_mmap(GR_OUTB) 99 let n: i64 = gm_record_gaps(RG_CONF, out) 100 if gv_need("record verb ran over the planted conf and printed a document" as *u8, (n > 0) as i64, ctr) == 0 { return gv_verdict("nx_goalmap_record_gate" as *u8, ctr, "the verb produced nothing on the fixture" as *u8) } 101 // ---- the declared source set ---- 102 gv_check("conf-rows-counted-and-the-unknown-kind-named-not-dropped" as *u8, rg_find(out, n, "\"conf_rows\":6,\"conf_unknown_kinds\":1" as *u8), ctr) 103 gv_check("sources-read-unimplemented-and-undeclared-are-three-different-words" as *u8, rg_find(out, n, "\"invoked\":\"READ\"" as *u8) * rg_find(out, n, "\"debt\":\"UNIMPLEMENTED\"" as *u8) * rg_find(out, n, "\"memory\":\"UNDECLARED\"" as *u8), ctr) 104 // ---- the boarded set: 8 names across two boards (matrix organ+symbol, rung symbol, gates organ; bz_sym once) ---- 105 gv_check("two-domains-from-regen-list" as *u8, rg_find(out, n, "\"domains\":2,\"matrices_read\":2,\"plans_read\":2,\"gates_read\":1" as *u8), ctr) 106 gv_check("boarded-names-eight-deduped-across-matrix-plan-gates" as *u8, rg_find(out, n, "\"boarded_names\":8,\"boarded_floor\":0" as *u8), ctr) 107 // ---- invoked: five distinct, one harness frame skipped and counted, one un-boarded organ ---- 108 gv_check("invoked-distinct-five-harness-skipped-one" as *u8, rg_find(out, n, "\"invoked_distinct\":5,\"harness_skipped\":1" as *u8), ctr) 109 gv_check("organ-candidate-is-the-one-invoked-tool-no-board-carries" as *u8, rg_find(out, n, "\"organ\":1" as *u8) * rg_find(out, n, "\"name\":\"nx_orphan_q\"" as *u8), ctr) 110 gv_check("mcp-prefix-and-elf-path-both-resolve-to-boarded-organs" as *u8, ((rg_find(out, n, "\"name\":\"nx_bz\"" as *u8) == 0) as i64) * ((rg_find(out, n, "\"name\":\"nx_gz\"" as *u8) == 0) as i64), ctr) 111 // ---- directives: the queue row names two un-boarded things; the boarded nx_bx and the lesson row are never filed ---- 112 gv_check("one-queue-row-read" as *u8, rg_find(out, n, "\"queue_rows\":1" as *u8), ctr) 113 gv_check("directive-candidates-two-from-the-queue-row" as *u8, rg_find(out, n, "\"directive\":2" as *u8) * rg_find(out, n, "\"name\":\"nx_unboarded_z\"" as *u8) * rg_find(out, n, "\"name\":\"qq_sym\"" as *u8), ctr) 114 gv_check("neg-control-lesson-row-prose-is-never-a-directive" as *u8, (rg_find(out, n, "nx_never_mind" as *u8) == 0) as i64, ctr) 115 gv_check("directive-row-carries-board-and-rung-evidence" as *u8, rg_find(out, n, "\"board_source_evidence\":\"a|plan-queue|rung=A1\"" as *u8), ctr) 116 // ---- partition sums; declared-unread classes read zero with a named status ---- 117 gv_check("partition-organ-plus-directive-is-total-three-and-sums" as *u8, rg_find(out, n, "\"symbol\":0,\"defect\":0,\"total\":3,\"partition_sums\":1" as *u8), ctr) 118 gv_check("unread-classes-say-unimplemented-never-silent-zero" as *u8, rg_find(out, n, "\"symbol_status\":\"UNIMPLEMENTED\",\"defect_status\":\"UNIMPLEMENTED\"" as *u8), ctr) 119 // ---- the plane: three rows, rewritten whole -- a second run yields the same three ---- 120 gv_check("plane-rows-three" as *u8, rg_find(out, n, "\"plane_rows\":3" as *u8), ctr) 121 let out2: *u8 = sys_mmap(GR_OUTB) 122 let n2: i64 = gm_record_gaps(RG_CONF, out2) 123 gv_check("second-run-plane-rows-still-three-idempotent" as *u8, rg_find(out2, n2, "\"plane_rows\":3" as *u8), ctr) 124 let lb: *u8 = sys_mmap(RG_LOADCAP) 125 let ln: i64 = sts_load(RG_PLANE, lb, RG_LOADCAP) 126 gv_check_eq("plane-loaded-back-carries-three-rows" as *u8, rg_lines(lb, ln), 3, ctr) 127 gv_check("plane-row-shape-kind-name-board-source-evidence" as *u8, rg_find(lb, ln, "organ|nx_orphan_q|UNASSIGNED|invoked|count=3" as *u8) * rg_find(lb, ln, "directive|qq_sym|a|plan-queue|rung=A1" as *u8), ctr) 128 // ---- neg-control and bite: nx_bx is boarded in plans/ and never filed; drop its row (plans2/) and it appears ---- 129 let bx1: i64 = rg_find(out, n, "\"name\":\"nx_bx\"" as *u8) 130 let out3: *u8 = sys_mmap(GR_OUTB) 131 let n3: i64 = gm_record_gaps(RG_CONF2, out3) 132 let bx3: i64 = rg_find(out3, n3, "\"name\":\"nx_bx\"" as *u8) 133 gv_bite("boarded-organ-never-filed-until-its-board-drops-it" as *u8, bx3, bx1, ctr) 134 // a gap is a NAME: nx_bx is filed ONCE under its first witness (the invoked set), never again as a directive 135 gv_check("unboarding-nx_bx-files-it-once-under-its-first-witness-organ-two-directive-two-total-four" as *u8, rg_find(out3, n3, "\"organ\":2" as *u8) * rg_find(out3, n3, "\"directive\":2" as *u8) * rg_find(out3, n3, "\"total\":4" as *u8), ctr) 136 // ---- an absent conf is UNOBSERVABLE, not zero ---- 137 let out4: *u8 = sys_mmap(GR_OUTB) 138 let n4: i64 = gm_record_gaps(RG_CONF_ABSENT, out4) 139 gv_check_eq("absent-conf-returns-minus-one-writes-nothing" as *u8, n4, 0 - 1, ctr) 140 // ---- the render feed and the heartbeat sit BESIDE THE CONF (derived from its path, so this fixture can never stamp production) ---- 141 let rb2: *u8 = sys_mmap(RG_LOADCAP) 142 let rszp: *i64 = sys_mmap(RG_SPAN) as *i64 143 let rn: i64 = gm_read(RG_ROWS, rb2, RG_LOADCAP, rszp) 144 gv_check("rows-artifact-beside-the-conf-carries-its-header-counts-and-the-three-rows" as *u8, rg_find(rb2, rn, "# comparegaps rows ts=" as *u8) * rg_find(rb2, rn, " total=3 organ=1 directive=2 sources_read=3 sources_declared=4" as *u8) * ((rg_lines(rb2, rn) == RG_EXP_FEED_LINES) as i64), ctr) 145 let gf: *i64 = sys_mmap(GA_F_SLOTS * GA_WORD) as *i64 146 let gst: i64 = ga_judge(RG_STAMP, sys_now_realtime_sec(), RG_CADENCE, gf) 147 gv_check_eq("stamp-beside-the-conf-judges-BLIND-three-of-four-declared-sources-read" as *u8, gst, GA_BLIND, ctr) 148 gv_check_eq("stamp-gauge-is-the-candidate-total" as *u8, gf[GA_F_GAUGE], RG_EXP_TOTAL, ctr) 149 gv_values_head() 150 gv_kv("doc_bytes" as *u8, n) 151 gv_kv("plane_loaded_bytes" as *u8, ln) 152 gv_kv("doc_bytes_unboarded" as *u8, n3) 153 return gv_verdict("nx_goalmap_record_gate" as *u8, ctr, "EC38 record gaps: the boarded set is derived from the boards, an invoked organ no board carries is filed, a queue callout's un-boarded names are filed, a lesson row never is, the partition sums, the plane is rewritten whole, and a boarded organ is filed only when its board drops it" as *u8) 154}