code wiki / (root) / nx_substrate_closure_compose_test.nx

nx_substrate_closure_compose_test.nx source

↩ module page · 96 lines · 4549 B

1// nx_substrate_closure_compose_test.nx -- 5 sub-primitives composed. 2// 3// A unified session that exercises: 4// - hunt_evidence captures kill receipts content-addressed 5// - hunt_partition assigns SCOUT/ENGAGER/KILLER across cells 6// - gather_compost recycles prior-arc lessons 7// - twin_key authorizes emergency cellular bypass under SANCTUARY 8// - trace_consent gates cross-host trace share 9 10import "nx_syscalls.nx" 11import "nx_tier.nx" 12import "nx_intent.nx" 13import "nx_hunter.nx" 14import "nx_hunt_evidence.nx" 15import "nx_hunt_partition.nx" 16import "nx_gather_compost.nx" 17import "nx_twin_key.nx" 18import "nx_trace_consent.nx" 19import "nx_transponder_quiescence.nx" 20 21func main() -> i64 { 22 // ===== Step 1: hunt -- 3 cells partition roles on 1 target ====== 23 let part: *NxHuntPartition = nx_hunt_partition_new(8) 24 if nx_hunt_partition_claim(part, 10, 100, NX_HR_SCOUT, 1000) != NX_HP_OK { return 1 } 25 if nx_hunt_partition_claim(part, 20, 100, NX_HR_ENGAGER, 1100) != NX_HP_OK { return 2 } 26 if nx_hunt_partition_claim(part, 30, 100, NX_HR_KILLER, 1200) != NX_HP_OK { return 3 } 27 if nx_hunt_partition_count(part) != 3 { return 4 } 28 29 // Cell 30 delivers the kill on target 100 30 let h: *NxHunter = nx_hunter_new(8) 31 nx_hunter_scout(h, 100, NX_HK_BUG_CLASS, 0xa1, 1000) 32 nx_hunter_kill(h, 100, NX_KP_BUG_FIXED, 1500) 33 if nx_hunter_total_kills(h) != 1 { return 5 } 34 35 // ===== Step 2: evidence captured =============================== 36 let ev: *NxHuntEvidenceLog = nx_hunt_evidence_log_new(8) 37 nx_hunt_evidence_record(ev, 1, 100, NX_EK_COMMIT_HASH, 0xc0ffee, 38 NX_KP_BUG_FIXED, 1600) 39 nx_hunt_evidence_record(ev, 2, 100, NX_EK_TEST_FIXTURE, 0xfeed, 40 NX_KP_BUG_FIXED, 1700) 41 if nx_hunt_evidence_count_for_target(ev, 100) != 2 { return 6 } 42 43 // ===== Step 3: gather_compost recycles prior arc lesson ======== 44 let cp: *NxCompostPile = nx_compost_pile_new(8) 45 nx_compost_deposit(cp, 100, NX_CS_HUNT_EVIDENCE, 100, 0xc0ffee, 2000) 46 if cp.count != 1 { return 7 } 47 // Apply the lesson to current TLS arc 3 times 48 nx_compost_apply(cp, 100, 3000) 49 nx_compost_apply(cp, 100, 3100) 50 nx_compost_apply(cp, 100, 3200) 51 if nx_compost_total_applications(cp) != 3 { return 8 } 52 53 // ===== Step 4: SANCTUARY-mode device + twin-key bypass ========= 54 let decl: *NxTransponderDeclaration = nx_transponder_decl_new( 55 200, NX_QM_SANCTUARY, 4000) 56 // Without twin-key + emergency_override: refused 57 if nx_transponder_check_activation(decl, NX_INTENT_DEFENSIVE, 58 NX_TX_TR_CELLULAR) != NX_TX_REFUSED_QUIESCENCE { return 9 } 59 60 let tk: *NxTwinKeyLedger = nx_twin_key_ledger_new(8) 61 // Family member A=1 proposes emergency cellular for child distress 62 if nx_twin_key_propose(tk, 1, NX_TKP_EMERGENCY_CELLULAR, 1, 2, 5000, 60000) != NX_TK_OK { return 10 } 63 nx_twin_key_sign(tk, 1, 1, 5100) // parent 1 signs 64 let signed_by_two: nx_int = nx_twin_key_sign(tk, 1, 2, 5200) // parent 2 signs 65 if signed_by_two != NX_TK_GRANTED { return 11 } 66 67 // Now operator authorizes emergency on the transponder 68 nx_transponder_authorize_emergency(decl) 69 // CELLULAR now allowed with Defensive intent 70 if nx_transponder_check_activation(decl, NX_INTENT_DEFENSIVE, 71 NX_TX_TR_CELLULAR) != NX_TX_ALLOWED { return 12 } 72 // But still not WiFi 73 if nx_transponder_check_activation(decl, NX_INTENT_DEFENSIVE, 74 NX_TX_TR_WIFI) != NX_TX_REFUSED_QUIESCENCE { return 13 } 75 76 // ===== Step 5: trace_consent for cross-host trace share ======== 77 let tc: *NxConsentLedger = nx_trace_consent_new(8) 78 // Sharer (this host, peer 1) wants to share call_id 9001 to peer 2 79 nx_trace_consent_propose(tc, 1, 9001, 1, 2, NX_CS_MERKLE_ROOT_ONLY, 6000, 10000) 80 // Default-deny before recipient grants 81 if nx_trace_consent_check(tc, 9001, 1, 2, 7000) != NX_CC_PENDING { return 14 } 82 // Recipient grants 83 nx_trace_consent_decide(tc, 1, NX_CC_GRANTED, 7000) 84 if nx_trace_consent_check(tc, 9001, 1, 2, 8000) != NX_CC_GRANTED { return 15 } 85 // After ttl expires 86 if nx_trace_consent_check(tc, 9001, 1, 2, 99999) != NX_CC_EXPIRED { return 16 } 87 88 // ===== Step 6: closure asserts ================================= 89 if nx_hunt_partition_count(part) != 3 { return 17 } 90 if nx_hunt_evidence_count(ev) != 2 { return 18 } 91 if nx_compost_total_applications(cp) != 3 { return 19 } 92 if nx_twin_key_count_by_state(tk, NX_TKS_AUTHORIZED) != 1 { return 20 } 93 if nx_trace_consent_count(tc) != 1 { return 21 } 94 95 return 0 96}