- 1
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] - 2
- 3
//! `/search` reads exactly one Agent's memory (AGENTS.md invariant 37), - 4
//! resolved the way `/memory` resolves it: `?agent=`, defaulting to `vak`. - 5
- 6
use axum::{ - 7
Router, - 8
body::Body, - 9
http::{Request, StatusCode}, - 10
}; - 11
use http_body_util::BodyExt; - 12
use serde_json::{Value, json}; - 13
use tower::ServiceExt; - 14
- 15
async fn call(app: &Router, method: &str, path: &str, body: Value) -> (StatusCode, Value) { - 16
let response = app - 17
.clone() - 18
.oneshot( - 19
Request::builder() - 20
.method(method) - 21
.uri(path) - 22
.header("content-type", "application/json") - 23
.body(Body::from(body.to_string())) - 24
.unwrap(), - 25
) - 26
.await - 27
.unwrap(); - 28
let status = response.status(); - 29
let bytes = response.into_body().collect().await.unwrap().to_bytes(); - 30
( - 31
status, - 32
serde_json::from_slice(&bytes).unwrap_or(Value::Null), - 33
) - 34
} - 35
- 36
#[tokio::test] - 37
async fn search_reads_the_resolved_agents_own_memory() { - 38
vak_config::paths::isolate_home_for_tests(); - 39
let temp = tempfile::tempdir().unwrap(); - 40
let cwd = temp.path().join("workspace"); - 41
std::fs::create_dir_all(&cwd).unwrap(); - 42
let core = vak_core::Core::new_with_trust(cwd, true).unwrap(); - 43
core.set_sessions_home(temp.path().join("sessions-home")); - 44
let app = vak_server::router(core); - 45
- 46
let (status, body) = call( - 47
&app, - 48
"POST", - 49
"/memory", - 50
json!({"text": "the rollback window opens at noon", "kind": "fact", "tag": "rollback"}), - 51
) - 52
.await; - 53
assert_eq!(status, StatusCode::CREATED, "{body}"); - 54
- 55
let (status, found) = call(&app, "GET", "/search?q=rollback%20window", json!({})).await; - 56
assert_eq!(status, StatusCode::OK, "{found}"); - 57
assert!( - 58
found.to_string().contains("rollback window opens at noon"), - 59
"the default Agent finds its own note: {found}" - 60
); - 61
- 62
let (status, scoped) = call( - 63
&app, - 64
"GET", - 65
"/search?q=rollback%20window&agent=vak", - 66
json!({}), - 67
) - 68
.await; - 69
assert_eq!(status, StatusCode::OK); - 70
assert_eq!(found, scoped, "no agent means `vak`, exactly like /memory"); - 71
} - 72
Indexing the workspace…
Vakyartha documentation is discovering safe artifacts, anchors, and source references.