nx_director_pipeline_test.nx source
↩ module page · 145 lines · 6254 B
1// nx_director_pipeline_test.nx -- prove the substrate end-to-end.
2
3import "nx_syscalls.nx"
4import "nx_runtime.nx"
5import "nx_tier.nx"
6import "nx_prng.nx"
7import "nx_arc.nx"
8import "nx_directors_note.nx"
9import "nx_moment_resolve.nx"
10import "nx_intent_survival.nx"
11import "nx_director_pipeline.nx"
12
13func main() -> nx_int {
14 // ===== Build a 3-stage "morning routine" arc =================
15 //
16 // Stages: 0 = WAKE_UP (UNAWARE, DOMESTIC, mid arousal)
17 // 1 = STRETCH (AWARE, DOMESTIC, low arousal)
18 // 2 = BREAKFAST (PEEKING, DOMESTIC, mid arousal)
19 //
20 // Pools layout in arc.pools[]:
21 // [0] location: 100 (bedroom)
22 // [1] location: 101 (kitchen)
23 // [2] outfit: 200 (robe)
24 // [3] outfit: 201 (apron)
25 // [4] pose: 300 (sitting)
26 // [5] pose: 301 (standing)
27 // [6] expression: NX_AF_FOCUSED
28 // [7] camera: 500
29 let arc: *Arc = nx_arc_alloc(10, 3, NX_AS_AUTHORED, NX_CD_MUNDANE, 8)
30 nx_arc_pool_set(arc, 0, 100)
31 nx_arc_pool_set(arc, 1, 101)
32 nx_arc_pool_set(arc, 2, 200)
33 nx_arc_pool_set(arc, 3, 201)
34 nx_arc_pool_set(arc, 4, 300)
35 nx_arc_pool_set(arc, 5, 301)
36 nx_arc_pool_set(arc, 6, NX_AF_FOCUSED)
37 nx_arc_pool_set(arc, 7, 500)
38
39 // Stage 0: WAKE_UP
40 nx_arc_stage_set_basic(arc, 0,
41 1, NX_AW_UNAWARE, NX_ET_DOMESTIC,
42 300, 512, 5)
43 nx_arc_stage_set_pool(arc, 0, NX_ARC_POOL_LOCATION, 0, 2)
44 nx_arc_stage_set_pool(arc, 0, NX_ARC_POOL_OUTFIT, 2, 2)
45 nx_arc_stage_set_pool(arc, 0, NX_ARC_POOL_POSE, 4, 2)
46 nx_arc_stage_set_pool(arc, 0, NX_ARC_POOL_EXPRESSION, 6, 1)
47 nx_arc_stage_set_pool(arc, 0, NX_ARC_POOL_CAMERA, 7, 1)
48
49 // Stage 1: STRETCH
50 nx_arc_stage_set_basic(arc, 1,
51 2, NX_AW_AWARE, NX_ET_DOMESTIC,
52 200, 400, 5)
53 nx_arc_stage_set_pool(arc, 1, NX_ARC_POOL_LOCATION, 0, 2)
54 nx_arc_stage_set_pool(arc, 1, NX_ARC_POOL_OUTFIT, 2, 2)
55 nx_arc_stage_set_pool(arc, 1, NX_ARC_POOL_POSE, 4, 2)
56 nx_arc_stage_set_pool(arc, 1, NX_ARC_POOL_EXPRESSION, 6, 1)
57 nx_arc_stage_set_pool(arc, 1, NX_ARC_POOL_CAMERA, 7, 1)
58
59 // Stage 2: BREAKFAST
60 nx_arc_stage_set_basic(arc, 2,
61 3, NX_AW_PEEKING, NX_ET_DOMESTIC,
62 300, 500, 5)
63 nx_arc_stage_set_pool(arc, 2, NX_ARC_POOL_LOCATION, 0, 2)
64 nx_arc_stage_set_pool(arc, 2, NX_ARC_POOL_OUTFIT, 2, 2)
65 nx_arc_stage_set_pool(arc, 2, NX_ARC_POOL_POSE, 4, 2)
66 nx_arc_stage_set_pool(arc, 2, NX_ARC_POOL_EXPRESSION, 6, 1)
67 nx_arc_stage_set_pool(arc, 2, NX_ARC_POOL_CAMERA, 7, 1)
68
69 let prng: *i64 = (sys_mmap(8)) as *i64
70 nx_prng_init(prng, 42)
71
72 let summary: *PipelineSummary = nx_pipe_summary_alloc()
73
74 // ===== Step 0: PERFECT render -> GOOD tier ====================
75 let t0: nx_int = nx_director_pipeline_step(arc, 0, NX_DPS_PERFECT,
76 prng, summary)
77 if t0 != NX_PFT_GOOD { return 1 }
78 if summary.n_stages != 1 { return 2 }
79 if summary.n_good != 1 { return 3 }
80 if summary.n_drift != 0 { return 4 }
81 if summary.n_broken != 0 { return 5 }
82
83 // ===== Step 1: DRIFTED render -> DRIFT tier ===================
84 let t1: nx_int = nx_director_pipeline_step(arc, 1, NX_DPS_DRIFTED,
85 prng, summary)
86 if t1 != NX_PFT_DRIFT { return 6 }
87 if summary.n_stages != 2 { return 7 }
88 if summary.n_good != 1 { return 8 }
89 if summary.n_drift != 1 { return 9 }
90 if summary.n_broken != 0 { return 10 }
91
92 // ===== Step 2: BROKEN render -> BROKEN tier ===================
93 let t2: nx_int = nx_director_pipeline_step(arc, 2, NX_DPS_BROKEN,
94 prng, summary)
95 if t2 != NX_PFT_BROKEN { return 11 }
96 if summary.n_stages != 3 { return 12 }
97 if summary.n_good != 1 { return 13 }
98 if summary.n_drift != 1 { return 14 }
99 if summary.n_broken != 1 { return 15 }
100
101 // ===== Session-wide verdict: BROKEN dominates =================
102 //
103 // Per cardinal: any BROKEN folds the whole session to BROKEN
104 // (the director rejects the take and asks for a regen).
105 let verdict: nx_int = nx_director_pipeline_verdict(summary)
106 if verdict != NX_PFT_BROKEN { return 16 }
107
108 // ===== Sequence numbers chained monotonically =================
109 //
110 // last_seq should be 2 (0 -> 1 -> 2 across the three steps).
111 if summary.last_seq != 2 { return 17 }
112
113 // ===== Idempotency: re-running verdict gives the same answer ==
114 let verdict2: nx_int = nx_director_pipeline_verdict(summary)
115 if verdict2 != verdict { return 18 }
116
117 // ===== All-GOOD second arc -> GOOD session verdict ============
118 //
119 // Same shape, but render PERFECT on every stage. Session verdict
120 // should be GOOD when nothing breaks or drifts.
121 let summary2: *PipelineSummary = nx_pipe_summary_alloc()
122 let prng2: *i64 = (sys_mmap(8)) as *i64
123 nx_prng_init(prng2, 7)
124 nx_director_pipeline_step(arc, 0, NX_DPS_PERFECT, prng2, summary2)
125 nx_director_pipeline_step(arc, 1, NX_DPS_PERFECT, prng2, summary2)
126 nx_director_pipeline_step(arc, 2, NX_DPS_PERFECT, prng2, summary2)
127 if summary2.n_good != 3 { return 20 }
128 if summary2.n_drift != 0 { return 21 }
129 if summary2.n_broken != 0 { return 22 }
130 if nx_director_pipeline_verdict(summary2) != NX_PFT_GOOD { return 23 }
131
132 // ===== All-DRIFTED session -> DRIFT session verdict ===========
133 let summary3: *PipelineSummary = nx_pipe_summary_alloc()
134 let prng3: *i64 = (sys_mmap(8)) as *i64
135 nx_prng_init(prng3, 13)
136 nx_director_pipeline_step(arc, 0, NX_DPS_DRIFTED, prng3, summary3)
137 nx_director_pipeline_step(arc, 1, NX_DPS_DRIFTED, prng3, summary3)
138 nx_director_pipeline_step(arc, 2, NX_DPS_DRIFTED, prng3, summary3)
139 if summary3.n_drift != 3 { return 30 }
140 if summary3.n_broken != 0 { return 31 }
141 if nx_director_pipeline_verdict(summary3) != NX_PFT_DRIFT { return 32 }
142
143 println("nx_director_pipeline: arc -> moment -> note -> survival -> verdict E2E PASS" as *u8)
144 return 0
145}