code wiki / _hdl_build / nx_cms_lms_gate.nx
nx_cms_lms_gate.nx source
↩ module page · 89 lines · 5126 B
1// nx_cms_lms_gate.nx -- CMS LMS/MEMBERSHIP gate: land the missing LearnDash/MemberPress class HONESTLY by
2// proving the sovereign sequential-progress engine over a 3-lesson course -- enrollment gates access,
3// lessons drip in order, skip-ahead is refused, progress can't double-count, course completion + cert
4// eligibility require enrollment AND full completion. Positive AND negative controls throughout. Appends
5// "CMSGATE row=nx_cms_lms lms-membership ... verdict=PASS" to knowledge/status/cms_gate.log ONLY if every
6// assertion holds. Exit 0 iff all pass. license_tier: ORIGINAL
7import "nx_cms_lms.nx"
8import "nx_syscalls.nx"
9
10func lg_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
11func lg_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 }
12func lg_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 }
13func lg_catnum(dst: *u8, off: i64, v: i64) -> i64 {
14 var o: i64=off; let t: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; var k: i64=0
15 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}
16 var i: i64=0; while i<k {dst[o]=t[k-1-i]; o=o+1; i=i+1} return o
17}
18
19func lg_row(id: i64, ok: i64, what: *u8) -> i64 {
20 lg_w("LMSROW " as *u8); lg_num(id); lg_w(" " as *u8)
21 if ok==1 { lg_w("PASS " as *u8) } else { lg_w("FAIL " as *u8) }
22 lg_w(what); lg_w("\n" as *u8)
23 return ok
24}
25
26func main() -> i64 {
27 var pass: i64 = 0
28 var rows: i64 = 0
29 var ok: i64 = 0
30 let total: i64 = 3 // a 3-lesson course
31
32 // R0 (neg control): a non-enrolled visitor has NO access
33 ok = 0; if lms_can_access(0) == 0 { ok = 1 }
34 rows=rows+1; pass=pass+lg_row(0, ok, "not enrolled -> no access (membership gate, neg control)" as *u8)
35
36 // R1: an enrolled learner has access
37 ok = 0; if lms_can_access(1) == 1 { ok = 1 }
38 rows=rows+1; pass=pass+lg_row(1, ok, "enrolled -> access granted" as *u8)
39
40 // R2: at 0 completed, lesson 0 is unlocked but lesson 1 is LOCKED (sequential drip)
41 ok = 0
42 if lms_lesson_unlocked(1, 0, 0) == 1 { if lms_lesson_unlocked(1, 1, 0) == 0 { ok = 1 } }
43 rows=rows+1; pass=pass+lg_row(2, ok, "drip: lesson0 unlocked, lesson1 locked until lesson0 done" as *u8)
44
45 // R3: completing lesson 0 advances progress and unlocks lesson 1
46 let c1: i64 = lms_complete_lesson(0, 0, total)
47 ok = 0; if c1 == 1 { if lms_lesson_unlocked(1, 1, c1) == 1 { ok = 1 } }
48 rows=rows+1; pass=pass+lg_row(3, ok, "complete lesson0 -> progress=1, lesson1 now unlocked" as *u8)
49
50 // R4 (neg control): cannot SKIP -- completing lesson 2 while at progress 1 leaves progress unchanged
51 let c_skip: i64 = lms_complete_lesson(1, 2, total)
52 ok = 0; if c_skip == 1 { ok = 1 }
53 rows=rows+1; pass=pass+lg_row(4, ok, "no skip-ahead: completing a later lesson leaves progress=1 (neg)" as *u8)
54
55 // R5 (neg control): enrollment dominates -- even with 'completed' lessons, no access when not enrolled
56 ok = 0; if lms_lesson_unlocked(0, 0, total) == 0 { ok = 1 }
57 rows=rows+1; pass=pass+lg_row(5, ok, "enrollment dominates: not-enrolled locked even with progress (neg)" as *u8)
58
59 // R6: sequential completion of all lessons -> course complete + cert eligible (enrolled)
60 var c: i64 = 0
61 c = lms_complete_lesson(c, 0, total)
62 c = lms_complete_lesson(c, 1, total)
63 c = lms_complete_lesson(c, 2, total)
64 let c_again: i64 = lms_complete_lesson(c, 3, total) // no double-count past total
65 ok = 0
66 if c == total { if c_again == total { if lms_course_complete(c, total) == 1 { if lms_cert_eligible(1, c, total) == 1 { ok = 1 } } } }
67 rows=rows+1; pass=pass+lg_row(6, ok, "all lessons in order -> complete + cert eligible; no double-count" as *u8)
68
69 // R7 (neg controls): cert NOT eligible if not enrolled, or not fully complete
70 ok = 0
71 if lms_cert_eligible(0, total, total) == 0 { if lms_cert_eligible(1, total - 1, total) == 0 { ok = 1 } }
72 rows=rows+1; pass=pass+lg_row(7, ok, "cert denied if unenrolled OR incomplete (two neg controls)" as *u8)
73
74 lg_w("CMS-LMS-GATE rows=" as *u8); lg_num(rows); lg_w(" pass=" as *u8); lg_num(pass); lg_w("\n" as *u8)
75
76 if pass == rows {
77 let line: *u8 = sys_mmap(256)
78 var off: i64 = lg_cat(line, 0, "CMSGATE row=nx_cms_lms lms-membership rows=" as *u8)
79 off = lg_catnum(line, off, rows)
80 off = lg_cat(line, off, " pass=" as *u8); off = lg_catnum(line, off, pass)
81 off = lg_cat(line, off, " verdict=PASS\n" as *u8)
82 let gf: i64 = sys_openat_append("knowledge/status/cms_gate.log" as *u8, 0x1a4)
83 if gf >= 0 { sys_write(gf, line, off); sys_close(gf) }
84 lg_w("CMS-LMS-GATE verdict=PASS -- lms-membership recorded in cms_gate.log\n" as *u8)
85 sys_exit(0); return 0
86 }
87 lg_w("CMS-LMS-GATE verdict=FAIL -- NOT recorded (no fake-green)\n" as *u8)
88 sys_exit(1); return 1
89}