use super::*;
use tokio::sync::mpsc;
fn ctx() -> ConnectionContext {
let (tx, _rx) = mpsc::unbounded_channel();
ConnectionContext::new(tx)
}
#[tokio::test]
async fn create_without_project_is_projectless() {
let registry = SessionRegistry::new();
let workstreams = crate::workstreams::test_shared_store().await;
let value = create(®istry, &workstreams, json!({"task": "just chat"}), ctx())
.await
.expect("omitting project must be valid");
assert_eq!(value["binding"]["state"], "projectless");
assert!(value["binding"]["root"].is_null());
assert!(
value["project"].is_null(),
"projectless must derive no label"
);
}
#[tokio::test]
async fn create_binds_a_real_directory() {
let registry = SessionRegistry::new();
let workstreams = crate::workstreams::test_shared_store().await;
let dir = tempfile::tempdir().expect("tempdir");
let value = create(
®istry,
&workstreams,
json!({"task": "t", "project": dir.path().to_string_lossy()}),
ctx(),
)
.await
.expect("a real directory must bind");
assert_eq!(value["binding"]["state"], "directory");
assert_eq!(
value["project"], value["binding"]["root"],
"the label must be derived from the binding root, not independent of it"
);
}
#[tokio::test]
async fn create_rejects_a_label_that_is_not_a_directory() {
let registry = SessionRegistry::new();
let workstreams = crate::workstreams::test_shared_store().await;
let err = create(
®istry,
&workstreams,
json!({"task": "t", "project": "my-app"}),
ctx(),
)
.await
.expect_err("a decorative label must no longer be silently accepted");
assert_eq!(err.code, -32003, "expected invalid_argument, got {err:?}");
}