code wiki / (root) / nx_intent_test.nx

nx_intent_test.nx source

↩ module page · 53 lines · 2829 B

1// nx_intent_test.nx -- smoke for nx_intent. 2 3import "nx_syscalls.nx" 4import "nx_intent.nx" 5 6func main() -> i64 { 7 if NX_INTENT_N_KINDS != 4 { return 1 } 8 if nx_intent_is_valid(NX_INTENT_DEFENSIVE) != 1 { return 2 } 9 if nx_intent_is_valid(NX_INTENT_CREATIVE) != 1 { return 3 } 10 if nx_intent_is_valid(4) != 0 { return 4 } 11 12 // Defensive composes with anything 13 if nx_intent_compatible(NX_INTENT_DEFENSIVE, NX_INTENT_CREATIVE) != 1 { return 5 } 14 if nx_intent_compatible(NX_INTENT_DEFENSIVE, NX_INTENT_EDUCATIONAL) != 1 { return 6 } 15 if nx_intent_compatible(NX_INTENT_DEFENSIVE, NX_INTENT_DEFENSIVE) != 1 { return 7 } 16 17 // Educational only composes with itself 18 if nx_intent_compatible(NX_INTENT_EDUCATIONAL, NX_INTENT_EDUCATIONAL) != 1 { return 8 } 19 if nx_intent_compatible(NX_INTENT_EDUCATIONAL, NX_INTENT_DEFENSIVE) != 0 { return 9 } 20 if nx_intent_compatible(NX_INTENT_EDUCATIONAL, NX_INTENT_CREATIVE) != 0 { return 10 } 21 22 // Creative refuses Defensive callees 23 if nx_intent_compatible(NX_INTENT_CREATIVE, NX_INTENT_DEFENSIVE) != 0 { return 11 } 24 if nx_intent_compatible(NX_INTENT_CREATIVE, NX_INTENT_CREATIVE) != 1 { return 12 } 25 26 // Diagnostic refuses Creative downstream 27 if nx_intent_compatible(NX_INTENT_DIAGNOSTIC, NX_INTENT_CREATIVE) != 0 { return 13 } 28 if nx_intent_compatible(NX_INTENT_DIAGNOSTIC, NX_INTENT_DEFENSIVE) != 1 { return 14 } 29 30 // Operation check: offensive-pattern op requires Defensive 31 if nx_intent_check_operation(NX_INTENT_DEFENSIVE, NX_OPK_COMMAND_BATTERY) != NX_IN_OK { return 15 } 32 if nx_intent_check_operation(NX_INTENT_CREATIVE, NX_OPK_COMMAND_BATTERY) != NX_IN_REFUSED_OFFENSIVE { return 16 } 33 if nx_intent_check_operation(NX_INTENT_DIAGNOSTIC, NX_OPK_ACTUATE_DRONE) != NX_IN_REFUSED_OFFENSIVE { return 17 } 34 if nx_intent_check_operation(NX_INTENT_EDUCATIONAL, NX_OPK_ACTIVATE_TRANSPONDER) != NX_IN_REFUSED_OFFENSIVE { return 18 } 35 36 // Non-offensive ops admitted under any intent 37 if nx_intent_check_operation(NX_INTENT_CREATIVE, NX_OPK_READ_OWN_STATE) != NX_IN_OK { return 19 } 38 if nx_intent_check_operation(NX_INTENT_EDUCATIONAL, NX_OPK_NETWORK_RECV) != NX_IN_OK { return 20 } 39 40 // Invocation check propagates compatibility 41 if nx_intent_check_invocation(NX_INTENT_DEFENSIVE, NX_INTENT_CREATIVE) != NX_IN_OK { return 21 } 42 if nx_intent_check_invocation(NX_INTENT_CREATIVE, NX_INTENT_DEFENSIVE) != NX_IN_REFUSED_INCONSISTENT { return 22 } 43 44 // String shorts for logging 45 if nx_intent_string_short(NX_INTENT_DEFENSIVE) != 68 { return 23 } 46 if nx_intent_string_short(99) != 63 { return 24 } 47 48 // is_offensive_pattern predicates 49 if nx_opk_is_offensive_pattern(NX_OPK_COMMAND_BATTERY) != 1 { return 25 } 50 if nx_opk_is_offensive_pattern(NX_OPK_READ_OWN_STATE) != 0 { return 26 } 51 52 return 0 53}