aegis-runtime-mv
Native Rust agent runtime: Axum WebSocket/SSE/REST gateway, heartbeat scheduler, dependency-aware task workflow, SQLite storage. Attachment of AienOS. Pre-alpha.
Brought by drakestapleton
aegis-runtime-mv / tests / stage2_primitives_tests.rs
| 1 | use aegis::{ |
| 2 | ActionId, ActionReceipt, AegisEvent, ApprovalId, DoctrineDecision, EventBus, EventEnvelope, |
| 3 | EventId, Message, MessageId, Role, Run, RunBudget, RunId, RunState, Session, SessionId, |
| 4 | SessionStatus, SystemMessage, TerminationReason, Trigger, UserMessage, |
| 5 | }; |
| 6 | |
| 7 | #[test] |
| 8 | fn test_domain_ids_and_prefixes() { |
| 9 | let sess = SessionId::new(); |
| 10 | assert!(sess.as_str().starts_with("sess_")); |
| 11 | |
| 12 | let run = RunId::new(); |
| 13 | assert!(run.as_str().starts_with("run_")); |
| 14 | |
| 15 | let act = ActionId::new(); |
| 16 | assert!(act.as_str().starts_with("act_")); |
| 17 | |
| 18 | let appr = ApprovalId::new(); |
| 19 | assert!(appr.as_str().starts_with("appr_")); |
| 20 | |
| 21 | let evt = EventId::new(); |
| 22 | assert!(evt.as_str().starts_with("evt_")); |
| 23 | } |
| 24 | |
| 25 | #[test] |
| 26 | fn test_session_lifecycle_and_branching() { |
| 27 | let parent = Session::new(Some("Audit repo history".to_string())); |
| 28 | assert_eq!(parent.status, SessionStatus::Active); |
| 29 | assert_eq!(parent.objective.as_deref(), Some("Audit repo history")); |
| 30 | assert!(parent.parent_session_id.is_none()); |
| 31 | |
| 32 | let branch = parent.branch(); |
| 33 | assert_eq!(branch.parent_session_id, Some(parent.id.clone())); |
| 34 | assert_ne!(branch.id, parent.id); |
| 35 | assert_eq!(branch.objective, parent.objective); |
| 36 | } |
| 37 | |
| 38 | #[test] |
| 39 | fn test_message_roles_and_ids() { |
| 40 | let sys = Message::System(SystemMessage { |
| 41 | id: MessageId::new(), |
| 42 | content: "System instructions".to_string(), |
| 43 | created_at: 1000, |
| 44 | }); |
| 45 | assert_eq!(sys.role(), Role::System); |
| 46 | assert!(sys.id().as_str().starts_with("msg_")); |
| 47 | |
| 48 | let usr = Message::User(UserMessage { |
| 49 | id: MessageId::new(), |
| 50 | content: "Analyze commits".to_string(), |
| 51 | created_at: 1001, |
| 52 | }); |
| 53 | assert_eq!(usr.role(), Role::User); |
| 54 | } |
| 55 | |
| 56 | #[tokio::test] |
| 57 | async fn test_event_bus_publish_and_subscribe() { |
| 58 | let bus = EventBus::new(16); |
| 59 | let mut rx = bus.subscribe(); |
| 60 | |
| 61 | let event = AegisEvent::RunStarted { |
| 62 | run_id: "run_test1".to_string(), |
| 63 | session_id: "sess_test1".to_string(), |
| 64 | trigger: "UserMessage".to_string(), |
| 65 | }; |
| 66 | let envelope = EventEnvelope::new( |
| 67 | event, |
| 68 | Some("sess_test1".to_string()), |
| 69 | Some("run_test1".to_string()), |
| 70 | 1, |
| 71 | ); |
| 72 | |
| 73 | let sent = bus.publish(envelope.clone()).expect("publish must succeed"); |
| 74 | assert_eq!(sent, 1); |
| 75 | |
| 76 | let received = rx.recv().await.expect("recv must succeed"); |
| 77 | assert_eq!(received.sequence, 1); |
| 78 | assert_eq!(received.session_id.as_deref(), Some("sess_test1")); |
| 79 | } |
| 80 | |
| 81 | #[test] |
| 82 | fn test_doctrine_decision_and_action_receipt() { |
| 83 | let decision = DoctrineDecision::AllowRestricted(vec!["network:none".to_string()]); |
| 84 | let receipt = ActionReceipt { |
| 85 | action_id: "act_123".to_string(), |
| 86 | session_id: "sess_123".to_string(), |
| 87 | run_id: "run_123".to_string(), |
| 88 | capability: "shell.execute".to_string(), |
| 89 | target: "cargo test".to_string(), |
| 90 | decision: decision.clone(), |
| 91 | output: "ok".to_string(), |
| 92 | success: true, |
| 93 | duration_ms: 45, |
| 94 | }; |
| 95 | |
| 96 | assert!(receipt.success); |
| 97 | assert_eq!(receipt.decision, decision); |
| 98 | } |
| 99 | |
| 100 | #[test] |
| 101 | fn test_orchestration_run_and_budget() { |
| 102 | let budget = RunBudget { |
| 103 | max_steps: 10, |
| 104 | max_inference_calls: 15, |
| 105 | max_actions: 20, |
| 106 | max_wall_time_secs: 60, |
| 107 | }; |
| 108 | let session_id = SessionId::new(); |
| 109 | let trigger = Trigger::Heartbeat; |
| 110 | let mut run = Run::new(session_id.clone(), trigger, budget); |
| 111 | |
| 112 | assert_eq!(run.state, RunState::Running); |
| 113 | assert_eq!(run.steps_used, 0); |
| 114 | |
| 115 | run.steps_used += 1; |
| 116 | run.state = RunState::Completed; |
| 117 | run.termination = Some(TerminationReason::Completed); |
| 118 | |
| 119 | assert_eq!(run.steps_used, 1); |
| 120 | assert_eq!(run.state, RunState::Completed); |
| 121 | } |