use super::*;
#[tokio::test(flavor = "current_thread")]
async fn session_new_refuses_an_omitted_environment_policy_and_names_its_values() {
harn_vm::reset_thread_local_state();
let (tx, mut rx) = mpsc::unbounded_channel();
let mut server = AcpServer::new_with_output(AcpServerConfig::new(None), AcpOutput::Channel(tx));
server
.handle_incoming_message(serde_json::json!({
"jsonrpc": "2.0",
"id": 1,
"method": "session/new",
"params": {"cwd": "."},
}))
.await;
let refused = recv_json(&mut rx).await;
assert!(
refused["result"].is_null(),
"an omitted policy must not open a session, got {refused}"
);
assert_eq!(refused["error"]["code"], serde_json::json!(-32602));
let data = &refused["error"]["data"];
assert_eq!(
data["code"],
serde_json::json!("environment_policy.missing")
);
assert_eq!(data["field"], serde_json::json!("environmentPolicy"));
assert_eq!(
data["accepted"],
serde_json::json!(["inherited", "isolated", "granted"]),
"the refusal must name every value the field accepts"
);
let message = refused["error"]["message"].as_str().expect("message");
for kind in ["inherited", "isolated", "granted"] {
assert!(
message.contains(kind),
"message must name {kind}: {message}"
);
}
server
.handle_incoming_message(serde_json::json!({
"jsonrpc": "2.0",
"id": 2,
"method": "session/new",
"params": {"cwd": ".", "environmentPolicy": {"kind": "isolated", "grants": []}},
}))
.await;
let created = recv_json(&mut rx).await;
assert!(
created["result"]["sessionId"].as_str().is_some(),
"a stated policy must still open a session, got {created}"
);
}