nx_build_canon_input_gate.nx source
↩ module page · 69 lines · 5867 B
1// Parser and resource-verdict fixtures only; does not prove runner integration.
2// license_tier: ORIGINAL. No hardware writes; no production input mutation.
3import "nx_gate_verdict.nx"
4import "nx_build_canon_input_lib.nx"
5func bcig_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
6func bcig_conf(name: *u8, input: *u8, bound: i64, expected: i64, ctr: *i64) -> i64 {
7 return gv_check_eq(name, bci_conf_rows(input, bcig_len(input), bound), expected, ctr)
8}
9func bcig_hash(name: *u8, input: *u8, expected: i64, ctr: *i64) -> i64 {
10 return gv_check_eq(name, bci_hash_row(input, 0, bcig_len(input)), expected, ctr)
11}
12func main() -> i64 {
13 let ctr: *i64 = gv_ctr()
14 gv_head("build canon input gate -- pure parser and resource exit decisions" as *u8)
15 bcig_conf("conf valid frozen and scoped" as *u8, "!nx_syscalls.nx\n_hdl_build/a.nx\n" as *u8, 64, 2, ctr)
16 bcig_conf("conf valid CRLF comments" as *u8, "# canon\r\n\r\n!nx_syscalls.nx\r\na.nx\r\n" as *u8, 64, 2, ctr)
17 bcig_conf("conf empty" as *u8, "" as *u8, 64, BCI_INVALID, ctr)
18 bcig_conf("conf comments only" as *u8, "# canon\n\n" as *u8, 64, BCI_INVALID, ctr)
19 bcig_conf("conf bare freeze" as *u8, "!\n" as *u8, 64, BCI_INVALID, ctr)
20 bcig_conf("conf traversal" as *u8, "a/../b.nx\n" as *u8, 64, BCI_INVALID, ctr)
21 bcig_conf("conf absolute" as *u8, "/a.nx" as *u8, 64, BCI_INVALID, ctr)
22 bcig_conf("conf empty component" as *u8, "a//b.nx" as *u8, 64, BCI_INVALID, ctr)
23 bcig_conf("conf trailing slash" as *u8, "a/" as *u8, 64, BCI_INVALID, ctr)
24 bcig_conf("conf dot component" as *u8, "a/./b.nx" as *u8, 64, BCI_INVALID, ctr)
25 bcig_conf("conf space path" as *u8, "a b.nx" as *u8, 64, BCI_INVALID, ctr)
26 bcig_conf("conf backslash" as *u8, "a\\b.nx" as *u8, 64, BCI_INVALID, ctr)
27 bcig_conf("conf exact path bound" as *u8, "a.nx" as *u8, 4, 1, ctr)
28 bcig_conf("conf over path bound" as *u8, "a.nx" as *u8, 3, BCI_INVALID, ctr)
29 bcig_conf("conf invalid bound" as *u8, "a.nx" as *u8, 0, BCI_INVALID, ctr)
30 bcig_conf("conf malformed after good" as *u8, "a.nx\n!\n" as *u8, 64, BCI_INVALID, ctr)
31 bcig_conf("conf embedded CR" as *u8, "a\rb.nx" as *u8, 64, BCI_INVALID, ctr)
32 bcig_hash("hash valid" as *u8, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef 71 a.nx" as *u8, 1, ctr)
33 bcig_hash("hash valid CRLF" as *u8, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef 71 a.nx\r\n" as *u8, 1, ctr)
34 bcig_hash("hash max signed size" as *u8, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef 9223372036854775807 a.nx" as *u8, 1, ctr)
35 bcig_hash("hash overflow size" as *u8, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef 9223372036854775808 a.nx" as *u8, 0, ctr)
36 bcig_hash("hash zero size" as *u8, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef 0 a.nx" as *u8, 0, ctr)
37 bcig_hash("hash negative size" as *u8, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef -1 a.nx" as *u8, 0, ctr)
38 bcig_hash("hash empty size" as *u8, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef a.nx" as *u8, 0, ctr)
39 bcig_hash("hash malformed size" as *u8, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef 1x a.nx" as *u8, 0, ctr)
40 bcig_hash("hash invalid hex" as *u8, "g123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef 71 a.nx" as *u8, 0, ctr)
41 bcig_hash("hash uppercase hex" as *u8, "A123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef 71 a.nx" as *u8, 0, ctr)
42 bcig_hash("hash missing separator" as *u8, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef:71 a.nx" as *u8, 0, ctr)
43 bcig_hash("hash missing path" as *u8, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef 71 " as *u8, 0, ctr)
44 bcig_hash("hash traversal path" as *u8, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef 71 ../a.nx" as *u8, 0, ctr)
45 bcig_hash("hash trailing bytes" as *u8, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef 71 a.nx bad" as *u8, 0, ctr)
46 bcig_hash("hash empty row" as *u8, "" as *u8, 0, ctr)
47 bcig_hash("hash truncated digest" as *u8, "123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" as *u8, 0, ctr)
48 bcig_hash("hash double newline" as *u8, "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef 71 a.nx\n\n" as *u8, 0, ctr)
49 gv_check_eq("resource rc 0" as *u8, bci_resource_allowed(0), 1, ctr)
50 gv_check_eq("resource rc 3" as *u8, bci_resource_allowed(3), 0, ctr)
51 gv_check_eq("resource rc 4" as *u8, bci_resource_allowed(4), 0, ctr)
52 gv_check_eq("resource rc 5" as *u8, bci_resource_allowed(5), 0, ctr)
53 gv_check_eq("resource rc 127" as *u8, bci_resource_allowed(127), 0, ctr)
54 gv_check_eq("resource rc 2" as *u8, bci_resource_allowed(2), 0, ctr)
55 gv_check_eq("resource rc 42" as *u8, bci_resource_allowed(42), 0, ctr)
56 gv_check_eq("resource rc 139" as *u8, bci_resource_allowed(139), 0, ctr)
57 gv_check_eq("resource rc -9" as *u8, bci_resource_allowed(0 - 9), 0, ctr)
58 gv_check_eq("null conf" as *u8, bci_conf_rows(0 as *u8, 1, 64), BCI_INVALID, ctr)
59 gv_check_eq("null hash" as *u8, bci_hash_row(0 as *u8, 0, 100), 0, ctr)
60 gv_check_eq("negative hash offset" as *u8, bci_hash_row("x" as *u8, 0 - 1, 100), 0, ctr)
61 gv_check_eq("overflow hash range" as *u8, bci_hash_row("x" as *u8, BCI_I64_MAX, 100), 0, ctr)
62 let offset_row: *u8 = "xx0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef 71 a.nx" as *u8
63 gv_check_eq("valid nonzero row offset" as *u8, bci_hash_row(offset_row, 2, bcig_len(offset_row)-2), 1, ctr)
64 let rc: i64 = gv_verdict("BUILD-CANON-INPUT", ctr, "pure input fixtures; runner integration requires a separate live witness" as *u8)
65 sys_exit(rc)
66 return rc
67}
68
69