mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-18 07:01:34 +00:00
56 lines
1.6 KiB
Rust
56 lines
1.6 KiB
Rust
#[path = "../common/mod.rs"]
|
|
mod common;
|
|
|
|
use axum::http::Method;
|
|
use common::*;
|
|
use sandbox_agent_agent_management::testing::test_agents_from_env;
|
|
use serde_json::json;
|
|
use std::time::Duration;
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
async fn agent_termination() {
|
|
let configs = test_agents_from_env().expect("configure SANDBOX_TEST_AGENTS or install agents");
|
|
let app = TestApp::new();
|
|
|
|
for config in &configs {
|
|
let _guard = apply_credentials(&config.credentials);
|
|
install_agent(&app.app, config.agent).await;
|
|
|
|
let session_id = format!("terminate-{}", config.agent.as_str());
|
|
create_session(&app.app, config.agent, &session_id, "default").await;
|
|
|
|
let status = send_status(
|
|
&app.app,
|
|
Method::POST,
|
|
&format!("/v1/sessions/{session_id}/terminate"),
|
|
None,
|
|
)
|
|
.await;
|
|
assert_eq!(
|
|
status,
|
|
axum::http::StatusCode::NO_CONTENT,
|
|
"terminate session"
|
|
);
|
|
|
|
let events = poll_events_until(&app.app, &session_id, Duration::from_secs(30), |events| {
|
|
has_event_type(events, "session.ended")
|
|
})
|
|
.await;
|
|
assert!(
|
|
has_event_type(&events, "session.ended"),
|
|
"missing session.ended"
|
|
);
|
|
|
|
let status = send_status(
|
|
&app.app,
|
|
Method::POST,
|
|
&format!("/v1/sessions/{session_id}/messages"),
|
|
Some(json!({ "message": PROMPT })),
|
|
)
|
|
.await;
|
|
assert!(
|
|
!status.is_success(),
|
|
"terminated session should reject messages"
|
|
);
|
|
}
|
|
}
|