nx_tmplstale_gate.nx source
↩ module page · 87 lines · 5487 B
1// nx_tmplstale_gate.nx -- INDEPENDENT GATE for the clerk desk (nx_tmplstale_lib): template registry,
2// document lineage and staleness. Inherits nx_gate_verdict (gv_check per tooth, gv_bite for the
3// non-vacuity cell, gv_verdict carries the verdict in the EXIT CODE). Fixture is assembled at RUNTIME
4// under /tmp (never a production plane): two templates, two client documents, ONE clause revised; the
5// gate asserts the exact stale set (the template and the document that carry the clause) AND that the
6// fresh control (the template and document that do not) stays silent. license_tier: ORIGINAL
7
8import "nx_tmplstale_lib.nx"
9import "nx_gate_verdict.nx"
10const TG_DOCBUF: i64 = 4096
11const TG_WORKBUF: i64 = 8192
12const TG_RECBUF: i64 = 2048
13const TG_EPOCH: i64 = 1787100000
14const TG_TINYCAP: i64 = 8
15
16func tg_has(hay: *u8, needle: *u8) -> i64 {
17 var i: i64 = 0
18 while hay[i] != (0 as u8) {
19 var j: i64 = 0
20 var m: i64 = 1
21 while m == 1 {
22 if needle[j] == (0 as u8) { return 1 }
23 if hay[i + j] != needle[j] { m = 0 }
24 if m == 1 { j = j + 1 }
25 }
26 i = i + 1
27 }
28 return 0
29}
30
31func main() -> i64 {
32 gv_head("NX-TMPLSTALE-GATE -- the clerk desk: template registry, lineage and staleness (runtime fixture under /tmp)" as *u8)
33 let ctr: *i64 = gv_ctr()
34 let p: *u8 = "/tmp/nx_tmplstale_gate-" as *u8
35 dg_clause_put(p, "scope" as *u8, "1. SCOPE. Attorney represents {client} in the matter {matter}." as *u8)
36 dg_clause_put(p, "fee" as *u8, "2. FEES. Client shall pay {fee} for services rendered." as *u8)
37 dg_clause_put(p, "term" as *u8, "3. TERMINATION. Either party may terminate upon written notice." as *u8)
38 dg_clause_put(p, "conf" as *u8, "4. CONFIDENTIALITY. Communications are privileged. Dated {date}." as *u8)
39 let put1: i64 = ts_tmpl_put(p, "engagement" as *u8, "scope,fee,term,conf" as *u8, TG_EPOCH)
40 let put2: i64 = ts_tmpl_put(p, "nda" as *u8, "scope,conf" as *u8, TG_EPOCH)
41 gv_check("templates-put-with-clause-snapshot" as *u8, ((put1 >= 0) as i64) & ((put2 >= 0) as i64), ctr)
42 let putbad: i64 = ts_tmpl_put(p, "ghostly" as *u8, "scope,ghost" as *u8, TG_EPOCH)
43 gv_check("neg-control-unknown-clause-refused-at-put" as *u8, (putbad < 0) as i64, ctr)
44 let listing: *u8 = sys_mmap(TG_WORKBUF)
45 let ntmpl: i64 = dg_tmpl_list(p, listing, TG_WORKBUF)
46 gv_check("registry-lists-exactly-the-two-templates" as *u8, (ntmpl == 2) as i64, ctr)
47 gv_check("registry-row-carries-version-cid-and-epoch" as *u8, ((tg_has(listing, "engagement" as *u8) == 1) as i64) & ((tg_has(listing, "nxc1-" as *u8) == 1) as i64) & ((tg_has(listing, "1787100000" as *u8) == 1) as i64), ctr)
48 let k: *i64 = sys_mmap(8 * 4) as *i64
49 let v: *i64 = sys_mmap(8 * 4) as *i64
50 k[0] = ("client" as *u8) as i64; v[0] = ("Acme Corp" as *u8) as i64
51 k[1] = ("matter" as *u8) as i64; v[1] = ("Acme v. Baker" as *u8) as i64
52 k[2] = ("fee" as *u8) as i64; v[2] = ("$300/hr" as *u8) as i64
53 k[3] = ("date" as *u8) as i64; v[3] = ("2026-08-18" as *u8) as i64
54 let mrec: *u8 = sys_mmap(TG_RECBUF)
55 let mlen: i64 = canon_encode(k, v, 4, mrec)
56 let doc: *u8 = sys_mmap(TG_DOCBUF)
57 let n1: i64 = dg_assemble_lineage(p, "engagement" as *u8, "M-001" as *u8, mrec, mlen, doc)
58 let doc2: *u8 = sys_mmap(TG_DOCBUF)
59 let n2: i64 = dg_assemble_lineage(p, "nda" as *u8, "M-002" as *u8, mrec, mlen, doc2)
60 gv_check("two-documents-assembled-with-lineage" as *u8, ((n1 > 0) as i64) & ((n2 > 0) as i64), ctr)
61 let lpo: *i64 = sys_mmap(16) as *i64
62 let llo: *i64 = sys_mmap(16) as *i64
63 var linok: i64 = 0
64 if reg_get(p, "lineage:" as *u8, "M-001" as *u8, lpo, llo) == 1 {
65 let lin: *u8 = sys_mmap(TG_RECBUF)
66 let lsrc: *u8 = lpo[0] as *u8
67 var z: i64 = 0
68 while z < llo[0] { lin[z] = lsrc[z]; z = z + 1 }
69 lin[z] = 0 as u8
70 if tg_has(lin, "tmpl=engagement" as *u8) == 1 { if tg_has(lin, "fee:nxc1-" as *u8) == 1 { if tg_has(lin, "doc=nxc1-" as *u8) == 1 { linok = 1 } } }
71 }
72 gv_check("lineage-record-names-template-doc-cid-and-clause-cids" as *u8, linok, ctr)
73 let work: *u8 = sys_mmap(TG_WORKBUF)
74 let before: i64 = dg_tmpl_stale(p, work, TG_WORKBUF)
75 gv_check("fresh-desk-reads-zero-stale" as *u8, (before == 0) as i64, ctr)
76 dg_clause_put(p, "fee" as *u8, "2. FEES. Client shall pay {fee} for services rendered, billed monthly in six-minute increments." as *u8)
77 let after: i64 = dg_tmpl_stale(p, work, TG_WORKBUF)
78 gv_check("revised-clause-names-the-template-that-carries-it" as *u8, tg_has(work, "TEMPLATE-STALE engagement clause=fee" as *u8), ctr)
79 gv_check("revised-clause-names-the-document-built-from-it" as *u8, tg_has(work, "DOC-STALE M-001 clause=fee" as *u8), ctr)
80 gv_check("neg-control-fresh-template-and-document-stay-silent" as *u8, ((tg_has(work, "nda" as *u8) == 0) as i64) & ((tg_has(work, "M-002" as *u8) == 0) as i64), ctr)
81 gv_check("stale-set-is-exact-two-rows-not-a-count-guess" as *u8, (after == 2) as i64, ctr)
82 gv_bite("staleness-detector" as *u8, (after > 0) as i64, (before > 0) as i64, ctr)
83 let tiny: *u8 = sys_mmap(TG_RECBUF)
84 let over: i64 = dg_tmpl_stale(p, tiny, TG_TINYCAP)
85 gv_check("worklist-overflow-refuses-never-truncates" as *u8, (over < 0) as i64, ctr)
86 return gv_verdict("TMPLSTALE-GATE" as *u8, ctr, "clerk desk: snapshot at put, lineage at assembly, exact stale set, fresh control silent, overflow refused" as *u8)
87}