- 1
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)] - 2
- 3
use std::path::Path; - 4
use std::sync::Arc; - 5
- 6
use vak_core::Core; - 7
use vak_llm::stream; - 8
use vak_llm::types::ChatRequest; - 9
use vak_llm::{EventStream, LlmError, Provider}; - 10
use vak_session::types::{FrozenContract, SessionHeader}; - 11
use vak_session::{SessionLog, SessionPath}; - 12
- 13
struct Empty; - 14
- 15
#[async_trait::async_trait] - 16
impl Provider for Empty { - 17
fn name(&self) -> &str { - 18
"empty" - 19
} - 20
- 21
async fn stream( - 22
&self, - 23
_request: ChatRequest, - 24
_cancel: tokio_util::sync::CancellationToken, - 25
) -> Result<EventStream, LlmError> { - 26
let (mut sink, rx) = stream::channel(8); - 27
sink.close_error(LlmError::Parse("unused".into())).await; - 28
Ok(rx) - 29
} - 30
} - 31
- 32
fn header_for(id: &str, cwd: &Path) -> SessionHeader { - 33
SessionHeader { - 34
agent: None, - 35
session_id: id.to_string(), - 36
created_at: chrono::Utc::now(), - 37
cwd: cwd.to_path_buf(), - 38
parent_session_id: None, - 39
contract_id: None, - 40
work_item_id: None, - 41
conversation: None, - 42
contract: FrozenContract { - 43
app_version: "test".into(), - 44
provider: "scripted".into(), - 45
model: "m".into(), - 46
route_ladder: Vec::new(), - 47
route_objective: String::new(), - 48
route_annotations: Vec::new(), - 49
system_prompt: String::new(), - 50
permission_mode: "workspace-write".into(), - 51
capabilities: Vec::new(), - 52
prompt_layers: Vec::new(), - 53
}, - 54
} - 55
} - 56
- 57
#[tokio::test(flavor = "multi_thread", worker_threads = 4)] - 58
async fn search_endpoint_returns_ranked_hits() { - 59
let dir = tempfile::tempdir().unwrap(); - 60
let home = dir.path().join("home"); - 61
let cwd = dir.path().to_path_buf(); - 62
- 63
let path = SessionPath::new_session_file(&home, &cwd, "11111111-past"); - 64
let mut log = SessionLog::create(path, header_for("11111111-past", &cwd)).unwrap(); - 65
log.append_message(vak_session::types::MessageRecord { - 66
message: vak_llm::Message { - 67
role: vak_llm::Role::User, - 68
content: vec![vak_llm::types::ContentBlock::text( - 69
"the rollout checklist lives in ops/handbook.md", - 70
)], - 71
}, - 72
meta: None, - 73
}) - 74
.unwrap(); - 75
drop(log); - 76
- 77
vak_config::paths::isolate_home_for_tests(); - 78
let core = Core::new(cwd.clone()).unwrap(); - 79
core.set_sessions_home(home.clone()); - 80
core.set_provider_instance(Arc::new(Empty)); - 81
std::mem::forget(dir); - 82
- 83
let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap(); - 84
let addr = listener.local_addr().unwrap(); - 85
tokio::spawn(async move { - 86
axum::serve(listener, vak_server::router(core)) - 87
.await - 88
.unwrap(); - 89
}); - 90
let base = format!("http://{addr}"); - 91
let client = reqwest::Client::new(); - 92
- 93
let res = client - 94
.get(format!("{base}/search")) - 95
.query(&[("q", "rollout checklist")]) - 96
.send() - 97
.await - 98
.unwrap(); - 99
assert_eq!(res.status(), 200); - 100
let body: serde_json::Value = res.json().await.unwrap(); - 101
let hits = body["hits"].as_array().unwrap(); - 102
assert_eq!(hits.len(), 1); - 103
assert_eq!(hits[0]["session_id"], "11111111-past"); - 104
assert!( - 105
hits[0]["snippet"].as_str().unwrap().contains("rollout"), - 106
"snippet: {}", - 107
hits[0]["snippet"] - 108
); - 109
- 110
// Garbage queries answer empty, not error. - 111
let res = client - 112
.get(format!("{base}/search")) - 113
.query(&[("q", "")]) - 114
.send() - 115
.await - 116
.unwrap(); - 117
assert_eq!(res.status(), 200); - 118
} - 119
Indexing the workspace…
Vakyartha documentation is discovering safe artifacts, anchors, and source references.