refactor: resolve critical concurrency, data loss, schema, and search audit passes
This commit is contained in:
1 parent
e4a0fe72df
commit
d80915635f
7 files changed
+846
-450
No files matched your search
+79
-46
@@ -34,7 +34,7 @@ pub fn create_router(app_state: Arc<AppState>) -> Router {
|
||||
let entity_count = graph.entities.len();
|
||||
let relation_count = graph.relations.len();
|
||||
let tasks = state_clone.project.tasks.cache.read().unwrap();
|
||||
let active_tasks = tasks.iter().filter(|t| t.status != "completed" && t.status != "done").count();
|
||||
let active_tasks = tasks.iter().filter(|t| t.is_active()).count();
|
||||
let adrs = state_clone.code.adrs.cache.read().unwrap();
|
||||
let adr_count = adrs.len();
|
||||
let tech_debts = state_clone.code.tech_debts.cache.read().unwrap();
|
||||
@@ -464,10 +464,7 @@ mod tests {
|
||||
async fn test_ping_endpoint() {
|
||||
let (app, _, _dir) = setup_app().await;
|
||||
|
||||
let request = Request::builder()
|
||||
.uri("/ping")
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let request = Request::builder().uri("/ping").body(Body::empty()).unwrap();
|
||||
|
||||
let response = app.oneshot(request).await.unwrap();
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
@@ -611,12 +608,15 @@ mod tests {
|
||||
.method("POST")
|
||||
.uri("/gate/set")
|
||||
.header("content-type", "application/json")
|
||||
.body(Body::from(serde_json::json!({
|
||||
"action": "deploy",
|
||||
"target": "prod",
|
||||
"authorize": true,
|
||||
"reason": "Tests passed"
|
||||
}).to_string()))
|
||||
.body(Body::from(
|
||||
serde_json::json!({
|
||||
"action": "deploy",
|
||||
"target": "prod",
|
||||
"authorize": true,
|
||||
"reason": "Tests passed"
|
||||
})
|
||||
.to_string(),
|
||||
))
|
||||
.unwrap();
|
||||
|
||||
let response = app.oneshot(set_req).await.unwrap();
|
||||
@@ -655,10 +655,7 @@ mod tests {
|
||||
|
||||
for ep in endpoints {
|
||||
let app_inst = create_router(app_state.clone());
|
||||
let req = Request::builder()
|
||||
.uri(ep)
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let req = Request::builder().uri(ep).body(Body::empty()).unwrap();
|
||||
let resp = app_inst.oneshot(req).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::OK, "Failed endpoint: {}", ep);
|
||||
}
|
||||
@@ -693,22 +690,39 @@ mod tests {
|
||||
let req_html = Request::builder().uri("/").body(Body::empty()).unwrap();
|
||||
let resp_html = app_html.oneshot(req_html).await.unwrap();
|
||||
assert_eq!(resp_html.status(), StatusCode::OK);
|
||||
let content_type = resp_html.headers().get(axum::http::header::CONTENT_TYPE).unwrap().to_str().unwrap();
|
||||
let content_type = resp_html
|
||||
.headers()
|
||||
.get(axum::http::header::CONTENT_TYPE)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap();
|
||||
assert!(content_type.contains("text/html"));
|
||||
|
||||
let body_bytes = axum::body::to_bytes(resp_html.into_body(), usize::MAX).await.unwrap();
|
||||
let body_bytes = axum::body::to_bytes(resp_html.into_body(), usize::MAX)
|
||||
.await
|
||||
.unwrap();
|
||||
let html_str = String::from_utf8(body_bytes.to_vec()).unwrap();
|
||||
assert!(html_str.contains("<script src=\"/dashboard.js\"></script>"));
|
||||
|
||||
// Test GET /dashboard.js
|
||||
let app_js = create_router(app_state.clone());
|
||||
let req_js = Request::builder().uri("/dashboard.js").body(Body::empty()).unwrap();
|
||||
let req_js = Request::builder()
|
||||
.uri("/dashboard.js")
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let resp_js = app_js.oneshot(req_js).await.unwrap();
|
||||
assert_eq!(resp_js.status(), StatusCode::OK);
|
||||
let content_type_js = resp_js.headers().get(axum::http::header::CONTENT_TYPE).unwrap().to_str().unwrap();
|
||||
let content_type_js = resp_js
|
||||
.headers()
|
||||
.get(axum::http::header::CONTENT_TYPE)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap();
|
||||
assert!(content_type_js.contains("application/javascript"));
|
||||
|
||||
let js_bytes = axum::body::to_bytes(resp_js.into_body(), usize::MAX).await.unwrap();
|
||||
let js_bytes = axum::body::to_bytes(resp_js.into_body(), usize::MAX)
|
||||
.await
|
||||
.unwrap();
|
||||
let js_str = String::from_utf8(js_bytes.to_vec()).unwrap();
|
||||
assert!(js_str.contains("escapeHtml"));
|
||||
assert!(js_str.contains("setupWS"));
|
||||
@@ -722,15 +736,24 @@ mod tests {
|
||||
|
||||
// 1. Initial GET /api/activity should return empty array []
|
||||
let app_act = create_router(app_state.clone());
|
||||
let req_act = Request::builder().uri("/api/activity").body(Body::empty()).unwrap();
|
||||
let req_act = Request::builder()
|
||||
.uri("/api/activity")
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let resp_act = app_act.oneshot(req_act).await.unwrap();
|
||||
assert_eq!(resp_act.status(), StatusCode::OK);
|
||||
let body_bytes = axum::body::to_bytes(resp_act.into_body(), usize::MAX).await.unwrap();
|
||||
let body_bytes = axum::body::to_bytes(resp_act.into_body(), usize::MAX)
|
||||
.await
|
||||
.unwrap();
|
||||
let json_str = String::from_utf8(body_bytes.to_vec()).unwrap();
|
||||
assert_eq!(json_str.trim(), "[]");
|
||||
|
||||
// 2. Record a direct activity
|
||||
app_state.handler.state.record_activity("code_change", "Refactored live activity UI", Some("Added empty state placeholder"));
|
||||
app_state.handler.state.record_activity(
|
||||
"code_change",
|
||||
"Refactored live activity UI",
|
||||
Some("Added empty state placeholder"),
|
||||
);
|
||||
|
||||
// 3. Post terminal telemetry activity
|
||||
let app_term = create_router(app_state.clone());
|
||||
@@ -738,13 +761,16 @@ mod tests {
|
||||
.method("POST")
|
||||
.uri("/terminal/telemetry")
|
||||
.header("content-type", "application/json")
|
||||
.body(Body::from(serde_json::json!({
|
||||
"command": "cargo test --workspace",
|
||||
"exit_code": 0,
|
||||
"cwd": "C:\\workspace\\mcp-memory",
|
||||
"os": "windows",
|
||||
"timestamp": 1728130000000u64
|
||||
}).to_string()))
|
||||
.body(Body::from(
|
||||
serde_json::json!({
|
||||
"command": "cargo test --workspace",
|
||||
"exit_code": 0,
|
||||
"cwd": "C:\\workspace\\mcp-memory",
|
||||
"os": "windows",
|
||||
"timestamp": 1728130000000u64
|
||||
})
|
||||
.to_string(),
|
||||
))
|
||||
.unwrap();
|
||||
let term_resp = app_term.oneshot(term_req).await.unwrap();
|
||||
assert_eq!(term_resp.status(), StatusCode::OK);
|
||||
@@ -755,23 +781,31 @@ mod tests {
|
||||
.method("POST")
|
||||
.uri("/nvim/telemetry")
|
||||
.header("content-type", "application/json")
|
||||
.body(Body::from(serde_json::json!({
|
||||
"session_id": "test_session_1",
|
||||
"event": "BufWritePost",
|
||||
"file": "server/src/dashboard.ts"
|
||||
}).to_string()))
|
||||
.body(Body::from(
|
||||
serde_json::json!({
|
||||
"session_id": "test_session_1",
|
||||
"event": "BufWritePost",
|
||||
"file": "server/src/dashboard.ts"
|
||||
})
|
||||
.to_string(),
|
||||
))
|
||||
.unwrap();
|
||||
let nvim_resp = app_nvim.oneshot(nvim_req).await.unwrap();
|
||||
assert_eq!(nvim_resp.status(), StatusCode::OK);
|
||||
|
||||
// 5. GET /api/activity should return all recorded items
|
||||
let app_act2 = create_router(app_state.clone());
|
||||
let req_act2 = Request::builder().uri("/api/activity").body(Body::empty()).unwrap();
|
||||
let req_act2 = Request::builder()
|
||||
.uri("/api/activity")
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let resp_act2 = app_act2.oneshot(req_act2).await.unwrap();
|
||||
assert_eq!(resp_act2.status(), StatusCode::OK);
|
||||
let body_bytes2 = axum::body::to_bytes(resp_act2.into_body(), usize::MAX).await.unwrap();
|
||||
let body_bytes2 = axum::body::to_bytes(resp_act2.into_body(), usize::MAX)
|
||||
.await
|
||||
.unwrap();
|
||||
let json_str2 = String::from_utf8(body_bytes2.to_vec()).unwrap();
|
||||
|
||||
|
||||
assert!(json_str2.contains("CODE_CHANGE"));
|
||||
assert!(json_str2.contains("Refactored live activity UI"));
|
||||
assert!(json_str2.contains("TERMINAL"));
|
||||
@@ -781,19 +815,18 @@ mod tests {
|
||||
|
||||
// 6. Verify /dashboard.js contains empty state text and stream logic
|
||||
let app_js = create_router(app_state.clone());
|
||||
let req_js = Request::builder().uri("/dashboard.js").body(Body::empty()).unwrap();
|
||||
let req_js = Request::builder()
|
||||
.uri("/dashboard.js")
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
let resp_js = app_js.oneshot(req_js).await.unwrap();
|
||||
assert_eq!(resp_js.status(), StatusCode::OK);
|
||||
let js_bytes = axum::body::to_bytes(resp_js.into_body(), usize::MAX).await.unwrap();
|
||||
let js_bytes = axum::body::to_bytes(resp_js.into_body(), usize::MAX)
|
||||
.await
|
||||
.unwrap();
|
||||
let js_str = String::from_utf8(js_bytes.to_vec()).unwrap();
|
||||
assert!(js_str.contains("No recent activity recorded yet."));
|
||||
assert!(js_str.contains("/api/activity/stream"));
|
||||
assert!(js_str.contains("parseActivityPayload"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user