code wiki / (root) / nx_featassert.nx

nx_featassert.nx source

↩ module page · 108 lines · 4494 B

1// nx_featassert.nx -- prove a feature is IN THE BUILT ARTIFACT, not just in the source you meant to edit. 2// 3// WHY THIS EXISTS (operator, 2026-08-07: *"this is a bad bug"*). A whole feature -- writing the 4// gallery's enumerator index -- was never inserted into nx_gen_ingest. A scripted `str.replace` 5// anchor did not match (the source held a LITERAL newline where the pattern had `\n`), and 6// str.replace WITH NO MATCH IS A SILENT NO-OP THAT RETURNS THE ORIGINAL STRING. Then: 7// * the build SUCCEEDED -- absent code has no failure mode, 8// * the run printed 10 NEW / 10 idx:INSERTED -- everything still present worked perfectly, 9// * nothing anywhere in compile-or-test was watching for work that was never emitted. 10// ★★★★★★ A MISSING FEATURE PRODUCES A CLEAN BUILD AND A GREEN RUN. YOU CANNOT TEST FOR THE ABSENCE 11// OF CODE BY RUNNING THE CODE. 12// 13// The doctrine fix ("always assert your anchor matched") is the weak one: it relies on remembering, 14// and forgetting is exactly what happened. THE MECHANICAL FIX IS THAT A FEATURE MUST BE PROVABLE IN 15// THE ARTIFACT. A feature that was never compiled in has no marker string in the binary. So: 16// 17// nx_featassert _build/nx_gen_ingest.sov.elf "view:ADDED" 18// 19// is the one check that would have caught it, and it costs a substring scan. 20// 21// A marker prefixed with '!' must be ABSENT -- which makes this prove a REMOVAL too, and gives the 22// tool its own negative control (a checker that returns PRESENT for everything scores 100%). 23// 24// Usage: nx_featassert <artifact> <marker> [<marker> ...] '!marker' = must NOT be present 25// Exit 0 = every assertion held; 1 = at least one failed; 2 = usage; 3 = unreadable. 26// license_tier: ORIGINAL 27 28import "nx_syscalls.nx" 29import "nx_strconv.nx" 30 31func fa_puts(s: *u8) -> i64 { 32 var n: i64 = 0 33 while s[n] != (0 as u8) { n = n + 1 } 34 return sys_write(1, s, n) 35} 36func fa_len(s: *u8) -> i64 { 37 var n: i64 = 0 38 while s[n] != (0 as u8) { n = n + 1 } 39 return n 40} 41func fa_i(v: i64) -> i64 { 42 let b: *u8 = sys_mmap(32) 43 return sys_write(1, b, nx_strconv_format_i64(v, b)) 44} 45 46// Plain substring search over raw bytes. Deliberately NOT a "contains any of" or fuzzy match: a 47// marker that half-matches is a marker that did not ship. 48func fa_find(hay: *u8, n: i64, needle: *u8, m: i64) -> i64 { 49 if m <= 0 { return 0 - 1 } 50 if m > n { return 0 - 1 } 51 var i: i64 = 0 52 while i <= n - m { 53 var j: i64 = 0 54 var ok: i64 = 1 55 while j < m { 56 if hay[i + j] != needle[j] { ok = 0; j = m } else { j = j + 1 } 57 } 58 if ok == 1 { return i } 59 i = i + 1 60 } 61 return 0 - 1 62} 63 64func main(argc: i64, argv: *i64) -> i64 { 65 if argc < 3 { 66 fa_puts("usage: nx_featassert <artifact> <marker> [<marker> ...] ('!marker' = must be ABSENT)\n" as *u8) 67 return 2 68 } 69 let sp: *i64 = sys_mmap(16) as *i64 70 let buf: *u8 = sys_read_file(argv[1] as *u8, sp) 71 if (buf as i64) == 0 { fa_puts("artifact unreadable\n" as *u8); return 3 } 72 let n: i64 = sp[0] 73 74 fa_puts("artifact_bytes=" as *u8); fa_i(n); fa_puts("\n" as *u8) 75 76 var pass: i64 = 0 77 var fail: i64 = 0 78 var a: i64 = 2 79 while a < argc { 80 var m: *u8 = argv[a] as *u8 81 var want_absent: i64 = 0 82 if m[0] == (0x21 as u8) { want_absent = 1; m = ((m as i64) + 1) as *u8 } 83 let found: i64 = fa_find(buf, n, m, fa_len(m)) 84 85 fa_puts(" " as *u8) 86 if want_absent == 1 { fa_puts("ABSENT? " as *u8) } else { fa_puts("PRESENT? " as *u8) } 87 sys_write(1, m, fa_len(m)) 88 if want_absent == 1 { 89 if found < 0 { fa_puts(" ... ok (absent)\n" as *u8); pass = pass + 1 } 90 else { 91 fa_puts(" ... FAIL -- still present at offset " as *u8); fa_i(found); fa_puts("\n" as *u8) 92 fail = fail + 1 93 } 94 } else { 95 if found >= 0 { fa_puts(" ... ok (offset " as *u8); fa_i(found); fa_puts(")\n" as *u8); pass = pass + 1 } 96 else { 97 // The whole point. This is the line that would have fired. 98 fa_puts(" ... FAIL -- NOT IN THE ARTIFACT (the edit did not apply, or did not compile in)\n" as *u8) 99 fail = fail + 1 100 } 101 } 102 a = a + 1 103 } 104 fa_puts("assertions " as *u8); fa_i(pass); fa_puts("/" as *u8); fa_i(pass + fail) 105 if fail == 0 { fa_puts(" GREEN\n" as *u8); return 0 } 106 fa_puts(" RED\n" as *u8) 107 return 1 108}