26382a7ac6
CI / Clippy (push) Failing after 15m13s
CI / Test (ubuntu-latest) (push) Failing after 16m1s
CI / Test (macos-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Build (no embeddings / no ORT) (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / Cookbook (Node) (push) Has been cancelled
CI / Pi Extension (Node) (push) Has been cancelled
CI / Rust SDK (lean-ctx-client) (push) Has been cancelled
CI / Embed SDK (lean-ctx-sdk) (push) Has been cancelled
CI / Python SDK (leanctx) (push) Has been cancelled
CI / Hermes Plugin (Python) (push) Has been cancelled
CI / SDK Conformance Matrix (push) Has been cancelled
CI / Coverage (push) Has been cancelled
CI / cargo-deny (push) Has been cancelled
CI / Adversarial Safety (push) Has been cancelled
CI / Benchmarks (push) Has been cancelled
CI / Output-Quality Gate (eval A/B) (push) Has been cancelled
CI / Documentation (push) Has been cancelled
CI / CI Green (push) Has been cancelled
JetBrains Plugin / Actionlint (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (rust) (push) Has been cancelled
JetBrains Plugin / Validation (push) Has been cancelled
JetBrains Plugin / Build (push) Has been cancelled
JetBrains Plugin / Test (push) Has been cancelled
Security Check / Security Scan (push) Has been cancelled
50 lines
1.8 KiB
Rust
50 lines
1.8 KiB
Rust
use serde_json::json;
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
|
#[allow(clippy::await_holding_lock)]
|
|
async fn ctx_prefetch_warms_cache_for_full_read() {
|
|
let _g = lean_ctx::core::data_dir::test_env_lock();
|
|
let dir = tempfile::tempdir().expect("tempdir");
|
|
let data_dir = dir.path().join("data");
|
|
std::fs::create_dir_all(&data_dir).expect("create data dir");
|
|
// TODO: Audit that the environment access only happens in single-threaded code.
|
|
unsafe { std::env::set_var("LEAN_CTX_DATA_DIR", &data_dir) };
|
|
|
|
let project = tempfile::tempdir().expect("project");
|
|
let file_a = project.path().join("a.rs");
|
|
let file_b = project.path().join("b.rs");
|
|
std::fs::write(&file_a, "mod b;\npub fn a() { b::b(); }\n").expect("write a");
|
|
std::fs::write(&file_b, "pub fn b() {}\n").expect("write b");
|
|
|
|
let engine = lean_ctx::engine::ContextEngine::with_project_root(project.path());
|
|
|
|
let out = engine
|
|
.call_tool_text(
|
|
"ctx_prefetch",
|
|
Some(json!({
|
|
"root": project.path().to_string_lossy().to_string(),
|
|
"changed_files": [file_a.to_string_lossy().to_string()],
|
|
"budget_tokens": 500,
|
|
"max_files": 2
|
|
})),
|
|
)
|
|
.await
|
|
.expect("prefetch");
|
|
assert!(out.contains("prefetched"), "prefetch out: {out}");
|
|
|
|
let full = engine
|
|
.call_tool_text(
|
|
"ctx_read",
|
|
Some(json!({"path": file_a.to_string_lossy().to_string(), "mode":"full"})),
|
|
)
|
|
.await
|
|
.expect("read full");
|
|
assert!(
|
|
full.contains("unchanged") || full.contains("cached") || full.is_empty(),
|
|
"expected cache hit, got: {full}"
|
|
);
|
|
|
|
// TODO: Audit that the environment access only happens in single-threaded code.
|
|
unsafe { std::env::remove_var("LEAN_CTX_DATA_DIR") };
|
|
}
|