code wiki / _hdl_build / nx_gk_fixture_gate.nx
nx_gk_fixture_gate.nx source
↩ module page · 72 lines · 4128 B
1// nx_gk_fixture_gate.nx -- THE REFEREE FOR gk_fixture_dir, the per-RUN gate fixture directory (2026-09-03).
2//
3// THE DEFECT IT GUARDS, measured the day it shipped. Two runs of nx_bck_elide_gate launched in the same
4// second against two DIFFERENT compilers BOTH returned verdict=SKIP with "the named compiler built none of
5// the fixtures". Neither run was faulty; the pass under test was working (its own log showed
6// BCK-ELIDE sites=4 elided=2 throughout). They had overwritten each other's fixtures in the single
7// directory both had hardcoded. Run sequentially, the same gate on the same box is 13/13 GREEN.
8//
9// The estate already enforced the PER-GATE half of this law (gate scratch in /tmp/<gate>/, never shared
10// with a production beat). The PER-RUN half did not exist, and its absence fails in the ABSTAINING
11// direction -- a false SKIP acquits nothing and alarms nobody, it just deletes the evidence.
12//
13// THE ANTI-VACUITY PROBLEM THIS GATE HAD TO SOLVE. A tooth saying "gk_fixture_dir returned a path" passes
14// for a function that returns a CONSTANT, which is precisely the broken shape. So the load-bearing tooth is
15// that TWO calls differ, and it is paired with a NEGATIVE CONTROL that builds the OLD constant-path shape by
16// hand and asserts it COLLIDES. Without that control a reader cannot tell a working discriminator from a
17// test that could never fail.
18//
19// exit: 0 GREEN . 1 RED license_tier: ORIGINAL No hw writes.
20import "nx_syscalls.nx"
21import "nx_gate_verdict.nx"
22import "nx_gatekit_lib.nx"
23
24const GF_PATH: i64 = 1024
25const GF_SUBJECT: *u8 = "nx_gk_fixture_gate_subject"
26
27func gf_streq(a: *u8, b: *u8) -> i64 {
28 var i: i64 = 0
29 while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 }
30 if b[i] != (0 as u8) { return 0 }
31 return 1
32}
33
34func main(argc: i64, argv: *i64) -> i64 {
35 let ctr: *i64 = gv_ctr()
36 gv_head("NX-GK-FIXTURE-GATE: a gate fixture dir is per-RUN, so two concurrent runs of one gate cannot collide" as *u8)
37
38 let a: *u8 = sys_mmap(GF_PATH)
39 let b: *u8 = sys_mmap(GF_PATH)
40 let na: i64 = gk_fixture_dir(GF_SUBJECT, a)
41 let nb: i64 = gk_fixture_dir(GF_SUBJECT, b)
42
43 gv_puts(" dir_a=" as *u8); gv_puts(a); gv_puts("\n" as *u8)
44 gv_puts(" dir_b=" as *u8); gv_puts(b); gv_puts("\n" as *u8)
45
46 // the fixture must actually have reached its condition before any outcome is asserted
47 gv_check("fixture-reached-the-condition-both-dirs-were-created-on-disk" as *u8, (gk_exists(a) as i64) & (gk_exists(b) as i64), ctr)
48 gv_check_eq("both-calls-returned-a-nonempty-path" as *u8, ((na > 0) as i64) + ((nb > 0) as i64), 2, ctr)
49 gv_check("the-dir-is-named-for-its-gate-so-an-operator-can-find-it" as *u8, gk_has(a, GF_SUBJECT), ctr)
50 gv_check("the-dir-is-under-tmp-never-in-the-knowledge-tree" as *u8, gk_has(a, "/tmp/" as *u8), ctr)
51
52 // THE LOAD-BEARING TOOTH: a discriminator that returns the same thing twice is the bug, not the fix
53 let differ: i64 = 1 - gf_streq(a, b)
54 gv_check_eq("TWO-CALLS-IN-ONE-PROCESS-YIELD-DIFFERENT-DIRS-the-whole-point" as *u8, differ, 1, ctr)
55
56 // NEGATIVE CONTROL: reconstruct the OLD constant-path shape and prove it collides. Without this a
57 // reader cannot distinguish a working discriminator from a tooth that could never fire.
58 let c1: *u8 = sys_mmap(GF_PATH)
59 let c2: *u8 = sys_mmap(GF_PATH)
60 gk_cat(c1, 0, "/tmp/" as *u8); gk_cat(c1, gk_len(c1), GF_SUBJECT)
61 gk_cat(c2, 0, "/tmp/" as *u8); gk_cat(c2, gk_len(c2), GF_SUBJECT)
62 let collides: i64 = gf_streq(c1, c2)
63 gv_check_eq("neg-control-the-OLD-constant-path-shape-DOES-collide-so-this-suite-can-fail" as *u8, collides, 1, ctr)
64 gv_bite("bite-the-per-run-dir-separates-two-runs-while-the-constant-path-does-not" as *u8, collides, 1 - differ, ctr)
65
66 gv_kv("dir_len_a" as *u8, na)
67 gv_kv("dir_len_b" as *u8, nb)
68 gv_kv("dirs_differ" as *u8, differ)
69 gv_kv("constant_shape_collides" as *u8, collides)
70
71 return gv_verdict("nx_gk_fixture_gate" as *u8, ctr, "two calls in one process yield distinct created dirs, and the constant-path shape it replaces is proven to collide" as *u8)
72}