nx_dupname_gate.nx source
↩ module page · 124 lines · 6686 B
1// nx_dupname_gate.nx -- THE ENTRY POINT nx_janitor_dupname NEVER HAD.
2//
3// nx_janitor_dupname.nx carries a complete, careful shadow-collision census (jdn_scan / jdn_collisions /
4// jdn_pair_differs) and NO `func main`, so nothing in the ecosystem could ever run it: building it standalone
5// answers nxasm rc=102 "UNDEFINED label: main". A capability with no entry point is indistinguishable from a
6// capability that does not exist -- it greps as present, it reviews as done, and it can never fire.
7// LAW: A LIB WITH NO IMPORTER IS AN UNRUNNABLE CAPABILITY THAT SCORES AS A BUILT ONE.
8//
9// TWO THINGS THIS DRIVER MUST SUPPLY, both of which the lib legitimately leaves to its caller:
10// 1. CWD. jdn_scan opens the literal paths "runtime/_hdl_build" and "runtime", which only resolve with
11// cwd=buildroot -- the working directory nx_sov_build_run uses. /api/gate_run executes from the nishihost
12// root, so without the chdir both opens fail, jdn_collect returns 0, and the census would report ZERO
13// collisions: a VACUOUS GREEN produced by looking at nothing.
14// 2. A NON-VACUITY REFUSAL. So this gate REFUSES unless it sees files in BOTH dirs. An instrument that
15// cannot find its corpus must say so, never report zero (the rule nx_routeguard and nx_gatebuilt_gate
16// already follow).
17//
18// WHY THE COLLISION SET IS SPLIT BY CONTENT, not just counted: nx_sov_build_run probes _hdl_build FIRST, so a
19// duplicated basename means the runtime copy NEVER COMPILES. If the two files are byte-identical that is
20// merely redundant (COPY); if they DIFFER, you edit one and build the other, which is the bug that shipped
21// TWO nx_sovereignty_audit.nx. Only DIFFERING pairs are a defect, so only they set the verdict.
22// I NEEDED THIS MEASUREMENT AND GOT IT WRONG TWICE BY HAND FIRST (2026-08-07): nx_shelltool glob RECURSES, so
23// intersecting buildroot/runtime against runtime/_hdl_build compared a set with its own superset (97pc, absurd);
24// and the second attempt read a list the tool had honestly marked NX-TRUNCATED at capture_cap=163840 while my
25// own filter discarded the warning line. ★A DECLARED TRUNCATION YOU FILTER OUT OF YOUR VIEW IS A SILENT ONE.
26// license_tier: ORIGINAL Read-only: getdents + reads, writes nothing. (Rule 26) expect_exit: 0
27import "nx_syscalls.nx"
28import "_hdl_build/nx_janitor_dupname.nx"
29import "nx_gate_verdict.nx"
30
31const DG_BUILDROOT: *u8 = "/volume1/homes/elderwesto/nishihost/buildroot"
32const DG_FN_BYTES: i64 = 2097152
33const DG_FN_MAX: i64 = 30000
34const DG_RDCAP: i64 = 262144
35const DG_MAXSHOW: i64 = 20 // capped list of DIFFERING pairs; the cap is printed
36const DG_CMP_CAP: i64 = 600 // max content comparisons; declared, never silent
37
38func main(argc: i64, argv: *i64) -> i64 {
39 let ctr: *i64 = gv_ctr()
40 gv_head("nx_dupname_gate -- shadowed organ names (_hdl_build wins, runtime copy never compiles)" as *u8)
41
42 if sys_chdir(DG_BUILDROOT) != 0 {
43 gv_puts("REFUSED: cannot chdir to the buildroot -- the census paths are relative to it.\n" as *u8)
44 gv_check("corpus-reachable" as *u8, 0, ctr)
45 return gv_verdict("DUPNAME-GATE" as *u8, ctr, "could not reach the corpus" as *u8)
46 }
47
48 let fnames: *u8 = sys_mmap(DG_FN_BYTES)
49 let fnoff: *i64 = sys_mmap(8 * (DG_FN_MAX + 2)) as *i64
50 let hc: *i64 = sys_mmap(16) as *i64
51 hc[0] = 0
52 let nf: i64 = jdn_scan(fnames, fnoff, hc)
53 let hcount: i64 = hc[0]
54
55 // NON-VACUITY, asserted as a tooth so it cannot be skipped: both dirs must have yielded files.
56 var seen_both: i64 = 0
57 if hcount > 0 { if nf > hcount { seen_both = 1 } }
58 gv_puts(" _hdl_build=" as *u8); gv_num(hcount)
59 gv_puts(" runtime=" as *u8); gv_num(nf - hcount)
60 gv_puts(" total=" as *u8); gv_num(nf)
61 gv_puts("\n" as *u8)
62 gv_check("corpus-reachable (files found in BOTH dirs)" as *u8, seen_both, ctr)
63 if seen_both == 0 {
64 gv_puts(" REFUSING to report a collision count computed from an empty dir listing.\n" as *u8)
65 return gv_verdict("DUPNAME-GATE" as *u8, ctr, "corpus unreachable -- zero is not a measurement here" as *u8)
66 }
67
68 let coll: i64 = jdn_collisions(fnames, fnoff, hcount, nf)
69 gv_puts(" collisions=" as *u8); gv_num(coll)
70 gv_puts(" (basenames present in BOTH dirs; the runtime copy is unreachable by name)\n" as *u8)
71
72 // CLASSIFY: differing pairs are the defect, identical pairs are redundancy.
73 let br: *u8 = sys_mmap(DG_RDCAP + 1)
74 let bh: *u8 = sys_mmap(DG_RDCAP + 1)
75 var differ: i64 = 0
76 var same: i64 = 0
77 var unread: i64 = 0
78 var shown: i64 = 0
79 var cmp: i64 = 0
80 var i: i64 = hcount
81 while i < nf {
82 if cmp < DG_CMP_CAP {
83 if jdn_is_shadowed(fnames, fnoff, i, hcount) == 1 {
84 let nm: *u8 = ((fnames as i64) + fnoff[i]) as *u8
85 let d: i64 = jdn_pair_differs(nm, br, bh, DG_RDCAP)
86 cmp = cmp + 1
87 if d == 1 {
88 differ = differ + 1
89 if shown < DG_MAXSHOW {
90 gv_puts(" SHADOW-DIFFERS " as *u8); gv_puts(nm)
91 gv_puts(" (you edit one, the build takes the other)\n" as *u8)
92 shown = shown + 1
93 }
94 }
95 if d == 0 { same = same + 1 }
96 if d < 0 { unread = unread + 1 }
97 }
98 }
99 i = i + 1
100 }
101 if differ > DG_MAXSHOW {
102 gv_puts(" ... " as *u8); gv_num(differ - DG_MAXSHOW)
103 gv_puts(" more SHADOW-DIFFERS not shown (cap " as *u8); gv_num(DG_MAXSHOW)
104 gv_puts(", declared not silent)\n" as *u8)
105 }
106 gv_puts(" compared=" as *u8); gv_num(cmp)
107 gv_puts(" differ=" as *u8); gv_num(differ)
108 gv_puts(" identical=" as *u8); gv_num(same)
109 gv_puts(" unreadable=" as *u8); gv_num(unread)
110 if coll > cmp {
111 gv_puts("\n ENVELOPE: content comparison CAPPED at " as *u8); gv_num(DG_CMP_CAP)
112 gv_puts(" of " as *u8); gv_num(coll)
113 gv_puts(" collisions -- the rest are UNCLASSIFIED, not clean.\n" as *u8)
114 }
115 gv_puts(" scope: FLAT listing of the two source dirs, basename equality, first " as *u8)
116 gv_num(DG_RDCAP)
117 gv_puts(" bytes compared per file.\n" as *u8)
118
119 // Only DIFFERING pairs are a defect. Identical duplicates are redundancy and must not turn this RED,
120 // or the gate becomes noise nobody can act on.
121 var no_diff: i64 = 0
122 if differ == 0 { no_diff = 1 }
123 gv_check("no differing shadowed pair" as *u8, no_diff, ctr)
124 return gv_verdict("DUPNAME-GATE" as *u8, ctr, "shadow collisions classified by CONTENT; identical copies are redundancy, differing pairs are the defect" as *u8)
125}