code wiki / (root) / nx_ai_audit_test.nx

nx_ai_audit_test.nx source

↩ module page · 64 lines · 2818 B

1// nx_ai_audit_test.nx -- smoke for nx_ai_audit. 2 3import "nx_syscalls.nx" 4import "nx_intent.nx" 5import "nx_ai_audit.nx" 6 7func main() -> i64 { 8 if NX_AIP_N_KINDS != 6 { return 1 } 9 if nx_aip_is_valid(NX_AIP_CAPTURE_ATTEMPT) != 1 { return 2 } 10 if nx_aip_is_valid(NX_AIP_COLLATERAL_ACCEPTANCE) != 1 { return 3 } 11 if nx_aip_is_valid(6) != 0 { return 4 } 12 13 // Blocking-pattern predicates 14 if nx_aip_is_blocking_pattern(NX_AIP_AUTONOMOUS_WEAPON) != 1 { return 5 } 15 if nx_aip_is_blocking_pattern(NX_AIP_SECRET_KEY_EXFIL) != 1 { return 6 } 16 if nx_aip_is_blocking_pattern(NX_AIP_CAPTURE_ATTEMPT) != 0 { return 7 } 17 if nx_aip_is_blocking_pattern(NX_AIP_PERSUASION_LOOP) != 0 { return 8 } 18 19 // Clean proposal: no patterns + Defensive intent -> CLEAN 20 let p_clean: *NxAiProposal = nx_ai_proposal_new(1, 7, 21 NX_INTENT_DEFENSIVE, 0, 1024, 1000) 22 let r_clean: *NxAiAuditResult = nx_ai_audit(p_clean, 1100) 23 if r_clean.verdict != NX_AIA_CLEAN { return 9 } 24 if r_clean.operator_required != 0 { return 10 } 25 26 // Single non-blocking pattern -> OPERATOR_REVIEW 27 let p_one: *NxAiProposal = nx_ai_proposal_new(2, 7, 28 NX_INTENT_DEFENSIVE, 1, 921, 1200) // CAPTURE_ATTEMPT bit set 29 let r_one: *NxAiAuditResult = nx_ai_audit(p_one, 1300) 30 if r_one.verdict != NX_AIA_OPERATOR_REVIEW { return 11 } 31 if r_one.pattern_count != 1 { return 12 } 32 if r_one.operator_required != 1 { return 13 } 33 34 // Two non-blocking patterns -> BLOCKED 35 let p_two: *NxAiProposal = nx_ai_proposal_new(3, 7, 36 NX_INTENT_DEFENSIVE, 3, 870, 1400) // bits 0+1 set 37 let r_two: *NxAiAuditResult = nx_ai_audit(p_two, 1500) 38 if r_two.verdict != NX_AIA_BLOCKED { return 14 } 39 if r_two.pattern_count != 2 { return 15 } 40 41 // Single blocking pattern (AUTONOMOUS_WEAPON bit 2) -> BLOCKED 42 let p_block: *NxAiProposal = nx_ai_proposal_new(4, 7, 43 NX_INTENT_DEFENSIVE, 4, 921, 1600) 44 let r_block: *NxAiAuditResult = nx_ai_audit(p_block, 1700) 45 if r_block.verdict != NX_AIA_BLOCKED { return 16 } 46 if r_block.blocked_patterns != 4 { return 17 } 47 48 // SECRET_KEY_EXFIL alone -> BLOCKED 49 let p_exfil: *NxAiProposal = nx_ai_proposal_new(5, 7, 50 NX_INTENT_DEFENSIVE, 8, 921, 1800) // bit 3 = SECRET_KEY_EXFIL 51 let r_exfil: *NxAiAuditResult = nx_ai_audit(p_exfil, 1900) 52 if r_exfil.verdict != NX_AIA_BLOCKED { return 18 } 53 54 // Bad intent 55 let p_bad: *NxAiProposal = nx_ai_proposal_new(6, 7, 99, 0, 921, 2000) 56 let r_bad: *NxAiAuditResult = nx_ai_audit(p_bad, 2100) 57 if r_bad.verdict != NX_AIA_ERR_BAD_INTENT { return 19 } 58 59 // has_pattern predicate 60 if nx_ai_proposal_has_pattern(p_one, NX_AIP_CAPTURE_ATTEMPT) != 1 { return 20 } 61 if nx_ai_proposal_has_pattern(p_one, NX_AIP_AUTONOMOUS_WEAPON) != 0 { return 21 } 62 63 return 0 64}