nx_tier3_ecology_compose_test.nx source
↩ module page · 112 lines · 5382 B
1// nx_tier3_ecology_compose_test.nx -- ecosystem-tier composition.
2//
3// 4 new ecology primitives exercised end-to-end:
4// - microbiome of 5 diverse cells (HEALTHY by diversity ≥4)
5// - mycorrhizal network of 4 peers linked into a forest
6// - ai_audit catches manipulation pattern proposal
7// - aerobic pile decomposes stale cells with journal report
8
9import "nx_syscalls.nx"
10import "nx_tier.nx"
11import "nx_budget.nx"
12import "nx_attention_class.nx"
13import "nx_intent.nx"
14import "nx_methyl.nx"
15import "nx_cell.nx"
16import "nx_microbiome.nx"
17import "nx_ai_audit.nx"
18import "nx_aerobic.nx"
19import "nx_mycorrhizal.nx"
20
21func main() -> i64 {
22 let sig: *u8 = (sys_mmap(96)) as *u8
23 sig[0] = 1 as u8
24 let mark: *NxMethylMark = nx_methyl_new(7, 0xcafe, 1000, sig, 96)
25 let b: *NxBudget = nx_budget_new(7, 1000, 0, 0, 0, 0)
26
27 // ===== Step 1: build microbiome with diverse cell kinds =========
28 let mb: *NxMicrobiome = nx_microbiome_new(8)
29 let c_game: *NxCell = nx_cell_new(100, NX_AC_INTERACTIVE_FOREGROUND_GAME, 500, mark, b, 1000)
30 let c_video: *NxCell = nx_cell_new(101, NX_AC_VIDEO_CALL, 500, mark, b, 1000)
31 let c_dev: *NxCell = nx_cell_new(102, NX_AC_DEV, 500, mark, b, 1000)
32 let c_infer: *NxCell = nx_cell_new(103, NX_AC_BACKGROUND_INFERENCE, 500, mark, b, 1000)
33 let c_build: *NxCell = nx_cell_new(104, NX_AC_BACKGROUND_BUILD, 500, mark, b, 1000)
34 nx_microbiome_add(mb, c_game, 1000)
35 nx_microbiome_add(mb, c_video, 1100)
36 nx_microbiome_add(mb, c_dev, 1200)
37 nx_microbiome_add(mb, c_infer, 1300)
38 nx_microbiome_add(mb, c_build, 1400)
39 if nx_microbiome_kind_diversity(mb) != 5 { return 1 }
40 if nx_microbiome_health(mb) != NX_MB_HEALTHY { return 2 }
41
42 // ===== Step 2: build mycorrhizal network -- 4 peer hosts ========
43 let net: *NxMycorrhizalNetwork = nx_mycorrhizal_new(8, 16)
44 nx_mycorrhizal_join(net, 1001, 921, 1500) // family laptop
45 nx_mycorrhizal_join(net, 1002, 819, 1600) // homelab
46 nx_mycorrhizal_join(net, 1003, 716, 1700) // sibling node
47 nx_mycorrhizal_join(net, 1004, 410, 1800) // newer peer
48 // Star topology centered on 1001
49 nx_mycorrhizal_link(net, 1001, 1002, 921, 2000)
50 nx_mycorrhizal_link(net, 1001, 1003, 819, 2000)
51 nx_mycorrhizal_link(net, 1001, 1004, 614, 2000)
52 if nx_mycorrhizal_peer_count(net) != 4 { return 3 }
53 if nx_mycorrhizal_edge_count(net) != 3 { return 4 }
54 if nx_mycorrhizal_peer_degree(net, 1001) != 3 { return 5 } // hub
55 if nx_mycorrhizal_count_healthy(net) != 3 { return 6 } // 1004 below threshold
56
57 // ===== Step 3: AI agent proposal -- caught as BLOCKED ==========
58 // proposer claims Defensive intent but proposes AUTONOMOUS_WEAPON
59 // (bit 2). single blocking-pattern bit -> BLOCKED.
60 let p_attack: *NxAiProposal = nx_ai_proposal_new(7777, 99,
61 NX_INTENT_DEFENSIVE, 4, 921, 3000)
62 let r_attack: *NxAiAuditResult = nx_ai_audit(p_attack, 3100)
63 if r_attack.verdict != NX_AIA_BLOCKED { return 7 }
64 if r_attack.operator_required != 1 { return 8 }
65
66 // Same proposer follows up with CAPTURE_ATTEMPT + PERSUASION_LOOP
67 // (bits 0+1 = mask 3) -- two non-blocking patterns = BLOCKED.
68 let p_capture: *NxAiProposal = nx_ai_proposal_new(7778, 99,
69 NX_INTENT_DEFENSIVE, 3, 870, 3200)
70 let r_capture: *NxAiAuditResult = nx_ai_audit(p_capture, 3300)
71 if r_capture.verdict != NX_AIA_BLOCKED { return 9 }
72 if r_capture.pattern_count != 2 { return 10 }
73
74 // Clean proposal passes
75 let p_clean: *NxAiProposal = nx_ai_proposal_new(7779, 99,
76 NX_INTENT_DEFENSIVE, 0, 921, 3400)
77 let r_clean: *NxAiAuditResult = nx_ai_audit(p_clean, 3500)
78 if r_clean.verdict != NX_AIA_CLEAN { return 11 }
79
80 // ===== Step 4: aerobic decomposition of stale cells ============
81 let pile: *NxAerobicPile = nx_aerobic_pile_new(8, 4000)
82 nx_aerobic_add(pile, 200, 0x2000, NX_AR_EXPIRED, 4000)
83 nx_aerobic_add(pile, 201, 0x2001, NX_AR_SUPERSEDED, 4100)
84 nx_aerobic_add(pile, 202, 0x2002, NX_AR_VERSION_RETIRED, 4200)
85 if nx_aerobic_count(pile) != 3 { return 12 }
86 if nx_aerobic_count_by_reason(pile, NX_AR_EXPIRED) != 1 { return 13 }
87 if nx_aerobic_count_by_reason(pile, NX_AR_SUPERSEDED) != 1 { return 14 }
88
89 // Drain all 3
90 let out_id: *i64 = (sys_mmap(8)) as *i64
91 let out_hash: *i64 = (sys_mmap(8)) as *i64
92 nx_aerobic_drain_one(pile, out_id, out_hash, 5000)
93 nx_aerobic_drain_one(pile, out_id, out_hash, 5100)
94 nx_aerobic_drain_one(pile, out_id, out_hash, 5200)
95 if nx_aerobic_total_decomposed(pile) != 3 { return 15 }
96 // Recent activity -> not stagnant
97 if nx_aerobic_is_stagnant(pile, 5300) != 0 { return 16 }
98 // Far-future window -> stagnant
99 if nx_aerobic_is_stagnant(pile, 200000000000) != 1 { return 17 }
100
101 // ===== Step 5: cross-primitive composition asserts =============
102 // Microbiome health preserved across the AI-audit attack attempts
103 if nx_microbiome_health(mb) != NX_MB_HEALTHY { return 18 }
104 // Network healthy peers preserved
105 if nx_mycorrhizal_count_healthy(net) != 3 { return 19 }
106 // Operator was alerted for two AI proposals
107 if r_attack.operator_required != 1 { return 20 }
108 if r_capture.operator_required != 1 { return 21 }
109 if r_clean.operator_required != 0 { return 22 }
110
111 return 0
112}