code wiki / _hdl_build / nx_cms_forum_gate.nx
nx_cms_forum_gate.nx source
↩ module page · 102 lines · 5994 B
1// nx_cms_forum_gate.nx -- CMS COMMUNITY-FORUMS gate: land the missing bbPress/BuddyPress class HONESTLY by
2// proving the sovereign threaded-discussion layer that COMPOSES nx_cms_comments (DRY moderation reuse) and
3// adds thread-state gating + deterministic pinned ordering. Positive AND negative controls (a locked thread
4// REFUSES replies; a spam reply is withheld via the reused engine; pinned outranks newer-unpinned). Appends
5// "CMSGATE row=nx_cms_forum community-forums ... verdict=PASS" to knowledge/status/cms_gate.log ONLY if every
6// assertion holds (no fake-green). Exit 0 iff all pass. license_tier: ORIGINAL
7import "nx_cms_forum.nx"
8import "nx_cms_comments.nx"
9import "nx_syscalls.nx"
10
11func fg_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
12func fg_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=48+(m%10);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 }
13func fg_cat(dst: *u8, off: i64, s: *u8) -> i64 { var o: i64=off; var k: i64=0; while s[k]!=(0 as u8){dst[o]=s[k];o=o+1;k=k+1} return o }
14func fg_catnum(dst: *u8, off: i64, v: i64) -> i64 {
15 var o: i64=off; let t: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; var k: i64=0
16 if m==0 {t[0]=48 as u8;k=1}; while m>0 {t[k]=(48+(m%10)) as u8; m=m/10; k=k+1}
17 var i: i64=0; while i<k {dst[o]=t[k-1-i]; o=o+1; i=i+1} return o
18}
19
20func fg_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
21
22func fg_row(id: i64, ok: i64, what: *u8) -> i64 {
23 fg_w("FORUMROW " as *u8); fg_num(id); fg_w(" " as *u8)
24 if ok==1 { fg_w("PASS " as *u8) } else { fg_w("FAIL " as *u8) }
25 fg_w(what); fg_w("\n" as *u8)
26 return ok
27}
28
29func main() -> i64 {
30 var pass: i64 = 0
31 var rows: i64 = 0
32 var ok: i64 = 0
33
34 let clean: *u8 = "Thanks for starting this thread, very helpful." as *u8
35 let spammy: *u8 = "visit http://spam.example casino loan http://more.example" as *u8
36 let cleanN: i64 = fg_slen(clean)
37 let spamN: i64 = fg_slen(spammy)
38
39 // R0: an OPEN thread accepts a clean reply -> moderated to PENDING (queued, composes the engine)
40 let s0: i64 = forum_post_reply(NX_FORUM_OPEN, clean, cleanN)
41 ok = 0; if forum_can_reply(NX_FORUM_OPEN) == 1 { if s0 == NX_CMT_PENDING { ok = 1 } }
42 rows=rows+1; pass=pass+fg_row(0, ok, "open thread accepts clean reply -> PENDING (moderation reused)" as *u8)
43
44 // R1 (neg control): a LOCKED thread REFUSES new replies
45 let s1: i64 = forum_post_reply(NX_FORUM_LOCKED, clean, cleanN)
46 ok = 0; if forum_can_reply(NX_FORUM_LOCKED) == 0 { if s1 == NX_FORUM_REFUSED { ok = 1 } }
47 rows=rows+1; pass=pass+fg_row(1, ok, "locked thread REFUSES reply (negative control)" as *u8)
48
49 // R2: a spam reply to an open thread is classified SPAM and withheld from public (engine reuse)
50 let s2: i64 = forum_post_reply(NX_FORUM_OPEN, spammy, spamN)
51 ok = 0; if s2 == NX_CMT_SPAM { if forum_reply_visible(NX_CMT_SPAM) == 0 { ok = 1 } }
52 rows=rows+1; pass=pass+fg_row(2, ok, "spam reply -> SPAM, withheld from public (composed moderation)" as *u8)
53
54 // R3: pinned/sticky thread outranks a much NEWER unpinned thread (deterministic sticky ordering)
55 let rp: i64 = forum_thread_rank(1, 5) // pinned, ancient
56 let ru: i64 = forum_thread_rank(0, 999999) // unpinned, brand new
57 ok = 0; if rp < ru { ok = 1 }
58 rows=rows+1; pass=pass+fg_row(3, ok, "pinned thread outranks newer unpinned (sticky ordering)" as *u8)
59
60 // R4: within the same band, more-recent activity ranks higher (smaller rank)
61 let rn: i64 = forum_thread_rank(0, 100)
62 let ro: i64 = forum_thread_rank(0, 50)
63 ok = 0; if rn < ro { ok = 1 }
64 rows=rows+1; pass=pass+fg_row(4, ok, "same band: more-recent activity ranks higher" as *u8)
65
66 // R5: a reply becomes public only AFTER moderation approves it (reused FSM + visibility)
67 ok = 0
68 if cmt_can_moderate(NX_CMT_PENDING, NX_CMT_APPROVED) == 1 { if forum_reply_visible(NX_CMT_APPROVED) == 1 { ok = 1 } }
69 rows=rows+1; pass=pass+fg_row(5, ok, "reply public only after approve (pending->approved then visible)" as *u8)
70
71 // R6: thread state machine -- a LOCKED thread that is reopened accepts replies again
72 ok = 0
73 if forum_can_reply(NX_FORUM_LOCKED) == 0 { if forum_can_reply(NX_FORUM_OPEN) == 1 { ok = 1 } }
74 rows=rows+1; pass=pass+fg_row(6, ok, "state machine: locked refuses, reopened accepts" as *u8)
75
76 // R7 (DRY proof): forum visibility == comment visibility for every status (delegation, not a copy)
77 ok = 0
78 if forum_reply_visible(NX_CMT_APPROVED) == cmt_visible_public(NX_CMT_APPROVED) {
79 if forum_reply_visible(NX_CMT_PENDING) == cmt_visible_public(NX_CMT_PENDING) {
80 if forum_reply_visible(NX_CMT_SPAM) == cmt_visible_public(NX_CMT_SPAM) {
81 if forum_reply_visible(NX_CMT_TRASH) == cmt_visible_public(NX_CMT_TRASH) { ok = 1 }
82 }
83 }
84 }
85 rows=rows+1; pass=pass+fg_row(7, ok, "DRY: forum visibility delegates to the comment engine for all states" as *u8)
86
87 fg_w("CMS-FORUM-GATE rows=" as *u8); fg_num(rows); fg_w(" pass=" as *u8); fg_num(pass); fg_w("\n" as *u8)
88
89 if pass == rows {
90 let line: *u8 = sys_mmap(256)
91 var off: i64 = fg_cat(line, 0, "CMSGATE row=nx_cms_forum community-forums rows=" as *u8)
92 off = fg_catnum(line, off, rows)
93 off = fg_cat(line, off, " pass=" as *u8); off = fg_catnum(line, off, pass)
94 off = fg_cat(line, off, " verdict=PASS\n" as *u8)
95 let gf: i64 = sys_openat_append("knowledge/status/cms_gate.log" as *u8, 0x1a4)
96 if gf >= 0 { sys_write(gf, line, off); sys_close(gf) }
97 fg_w("CMS-FORUM-GATE verdict=PASS -- community-forums recorded in cms_gate.log\n" as *u8)
98 sys_exit(0); return 0
99 }
100 fg_w("CMS-FORUM-GATE verdict=FAIL -- NOT recorded (no fake-green)\n" as *u8)
101 sys_exit(1); return 1
102}