Feat: Add bulk actions for case analysis and deletion
Introduces a new `/web/cases/bulk` endpoint to handle multiple case actions simultaneously. This change adds the following: - A new `bulk` module for handling bulk operations. - The `handle_bulk_action` function in `bulk.rs` to dispatch to specific actions. - `bulk_analyze` and `bulk_delete` functions to process the actions. - Updates `Cargo.toml` and `Cargo.lock` to include necessary dependencies: `form_urlencoded`, `serde_core`, `serde_html_form`, and `serde_path_to_error`. - Modified `axum-extra` features to include `form`. - Adds checks for deleted cases in `collect_pending` for both analysis and transcription recovery. - Renames and modifies `handle_close_case` to `handle_analyze_case` in `case_actions.rs` to better reflect its functionality. - Adds a new `handle_delete_case` and `handle_undo_delete` to `case_actions.rs`. - Updates `my_cases.html` and `case_detail.html` to support bulk actions, including checkboxes, a bulk action bar, and an "Undo last delete" feature. - Modifies `handle_audio` and `scan_cases` in `web.rs` to respect delete markers. - Updates `analyze_test.rs` with new request builders for analyze and delete actions.
This commit is contained in:
@@ -54,16 +54,6 @@ fn config_with_llm_users(data_path: PathBuf, llm_url: String, users: Vec<User>)
|
||||
})
|
||||
}
|
||||
|
||||
fn make_admin(slug: &str) -> User {
|
||||
User {
|
||||
slug: slug.into(),
|
||||
api_key: format!("key-{slug}"),
|
||||
web_password: bcrypt::hash("s", 4).unwrap(),
|
||||
role: "admin".into(),
|
||||
whisper: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
fn config_without_llm(data_path: PathBuf) -> Arc<Config> {
|
||||
let users = vec![make_user("dr_a")];
|
||||
let api_keys: HashMap<String, String> = users
|
||||
@@ -117,10 +107,19 @@ async fn login(app: axum::Router, slug: &str) -> String {
|
||||
panic!("no session cookie after login");
|
||||
}
|
||||
|
||||
fn close_request(case_id: &str, cookie: &str) -> Request<Body> {
|
||||
fn analyze_request(case_id: &str, cookie: &str) -> Request<Body> {
|
||||
Request::builder()
|
||||
.method("POST")
|
||||
.uri(format!("/web/cases/{case_id}/close"))
|
||||
.uri(format!("/web/cases/{case_id}/analyze"))
|
||||
.header(header::COOKIE, cookie)
|
||||
.body(Body::empty())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn delete_request(case_id: &str, cookie: &str) -> Request<Body> {
|
||||
Request::builder()
|
||||
.method("POST")
|
||||
.uri(format!("/web/cases/{case_id}/delete"))
|
||||
.header(header::COOKIE, cookie)
|
||||
.body(Body::empty())
|
||||
.unwrap()
|
||||
@@ -131,7 +130,7 @@ fn close_request(case_id: &str, cookie: &str) -> Request<Body> {
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#[tokio::test]
|
||||
async fn close_without_cookie_redirects_to_login() {
|
||||
async fn analyze_without_cookie_redirects_to_login() {
|
||||
let config = config_with_llm(unique_tmp("a"), "http://unused".into());
|
||||
let app = doctate_server::create_router(config);
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
@@ -139,7 +138,7 @@ async fn close_without_cookie_redirects_to_login() {
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method("POST")
|
||||
.uri(format!("/web/cases/{case_id}/close"))
|
||||
.uri(format!("/web/cases/{case_id}/analyze"))
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
)
|
||||
@@ -149,33 +148,33 @@ async fn close_without_cookie_redirects_to_login() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn close_foreign_case_returns_404() {
|
||||
async fn analyze_foreign_case_returns_404() {
|
||||
let config = config_with_llm(unique_tmp("b"), "http://unused".into());
|
||||
// Seed a case owned by someone else.
|
||||
let foreign_case = "22222222-2222-2222-2222-222222222222";
|
||||
let foreign_dir = config.data_path.join("dr_other/open").join(foreign_case);
|
||||
let foreign_dir = config.data_path.join("dr_other").join(foreign_case);
|
||||
std::fs::create_dir_all(&foreign_dir).unwrap();
|
||||
seed_recording(&foreign_dir, "10-00-00", Some("text"));
|
||||
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let resp = app.oneshot(close_request(foreign_case, &cookie)).await.unwrap();
|
||||
let resp = app.oneshot(analyze_request(foreign_case, &cookie)).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn close_invalid_uuid_returns_400() {
|
||||
async fn analyze_invalid_uuid_returns_400() {
|
||||
let config = config_with_llm(unique_tmp("c"), "http://unused".into());
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let resp = app.oneshot(close_request("not-a-uuid", &cookie)).await.unwrap();
|
||||
let resp = app.oneshot(analyze_request("not-a-uuid", &cookie)).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn close_case_without_recordings_returns_400() {
|
||||
async fn analyze_case_without_recordings_returns_400() {
|
||||
let config = config_with_llm(unique_tmp("d"), "http://unused".into());
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
seed_case(&config.data_path, "dr_a", case_id);
|
||||
@@ -184,12 +183,12 @@ async fn close_case_without_recordings_returns_400() {
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let resp = app.oneshot(close_request(case_id, &cookie)).await.unwrap();
|
||||
let resp = app.oneshot(analyze_request(case_id, &cookie)).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn close_case_with_missing_transcript_returns_400() {
|
||||
async fn analyze_case_with_missing_transcript_returns_400() {
|
||||
let config = config_with_llm(unique_tmp("e"), "http://unused".into());
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&config.data_path, "dr_a", case_id);
|
||||
@@ -199,12 +198,12 @@ async fn close_case_with_missing_transcript_returns_400() {
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let resp = app.oneshot(close_request(case_id, &cookie)).await.unwrap();
|
||||
let resp = app.oneshot(analyze_request(case_id, &cookie)).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn close_case_without_llm_returns_503() {
|
||||
async fn analyze_case_without_llm_returns_503() {
|
||||
let config = config_without_llm(unique_tmp("f"));
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&config.data_path, "dr_a", case_id);
|
||||
@@ -213,7 +212,7 @@ async fn close_case_without_llm_returns_503() {
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let resp = app.oneshot(close_request(case_id, &cookie)).await.unwrap();
|
||||
let resp = app.oneshot(analyze_request(case_id, &cookie)).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::SERVICE_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@@ -222,7 +221,7 @@ async fn close_case_without_llm_returns_503() {
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#[tokio::test]
|
||||
async fn close_case_happy_path_writes_input_and_redirects() {
|
||||
async fn analyze_case_happy_path_writes_input_and_redirects() {
|
||||
let config = config_with_llm(unique_tmp("g"), "http://unused".into());
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&config.data_path, "dr_a", case_id);
|
||||
@@ -232,7 +231,7 @@ async fn close_case_happy_path_writes_input_and_redirects() {
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let resp = app.oneshot(close_request(case_id, &cookie)).await.unwrap();
|
||||
let resp = app.oneshot(analyze_request(case_id, &cookie)).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::SEE_OTHER);
|
||||
assert_eq!(
|
||||
resp.headers().get(header::LOCATION).unwrap().to_str().unwrap(),
|
||||
@@ -254,7 +253,7 @@ async fn close_case_happy_path_writes_input_and_redirects() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn close_case_second_time_returns_409() {
|
||||
async fn analyze_case_second_time_returns_409() {
|
||||
let config = config_with_llm(unique_tmp("h"), "http://unused".into());
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&config.data_path, "dr_a", case_id);
|
||||
@@ -263,15 +262,15 @@ async fn close_case_second_time_returns_409() {
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let first = app.clone().oneshot(close_request(case_id, &cookie)).await.unwrap();
|
||||
let first = app.clone().oneshot(analyze_request(case_id, &cookie)).await.unwrap();
|
||||
assert_eq!(first.status(), StatusCode::SEE_OTHER);
|
||||
|
||||
let second = app.oneshot(close_request(case_id, &cookie)).await.unwrap();
|
||||
let second = app.oneshot(analyze_request(case_id, &cookie)).await.unwrap();
|
||||
assert_eq!(second.status(), StatusCode::CONFLICT);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn close_case_skips_blank_transcript_from_recordings() {
|
||||
async fn analyze_case_skips_blank_transcript_from_recordings() {
|
||||
let config = config_with_llm(unique_tmp("i"), "http://unused".into());
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&config.data_path, "dr_a", case_id);
|
||||
@@ -282,7 +281,7 @@ async fn close_case_skips_blank_transcript_from_recordings() {
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let resp = app.oneshot(close_request(case_id, &cookie)).await.unwrap();
|
||||
let resp = app.oneshot(analyze_request(case_id, &cookie)).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::SEE_OTHER);
|
||||
|
||||
let raw = std::fs::read_to_string(case_dir.join("analysis_input_v1.json")).unwrap();
|
||||
@@ -424,102 +423,12 @@ async fn document_view_picks_highest_version() {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Reanalyze (admin-only)
|
||||
// Re-analysis path: same handler, version derived from existing documents
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
fn reanalyze_request(case_id: &str, cookie: &str) -> Request<Body> {
|
||||
Request::builder()
|
||||
.method("POST")
|
||||
.uri(format!("/web/cases/{case_id}/reanalyze"))
|
||||
.header(header::COOKIE, cookie)
|
||||
.body(Body::empty())
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reanalyze_by_non_admin_returns_403() {
|
||||
let config = config_with_llm(unique_tmp("rn-1"), "http://unused".into());
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&config.data_path, "dr_a", case_id);
|
||||
std::fs::write(case_dir.join("document_v1.md"), "v1").unwrap();
|
||||
seed_recording(&case_dir, "10-00-00", Some("ok"));
|
||||
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let resp = app.oneshot(reanalyze_request(case_id, &cookie)).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::FORBIDDEN);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reanalyze_without_document_returns_400() {
|
||||
let config = config_with_llm_users(
|
||||
unique_tmp("rn-2"),
|
||||
"http://unused".into(),
|
||||
vec![make_admin("dr_a")],
|
||||
);
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&config.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "10-00-00", Some("ok"));
|
||||
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let resp = app.oneshot(reanalyze_request(case_id, &cookie)).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reanalyze_foreign_case_returns_404() {
|
||||
let config = config_with_llm_users(
|
||||
unique_tmp("rn-3"),
|
||||
"http://unused".into(),
|
||||
vec![make_admin("dr_a")],
|
||||
);
|
||||
let foreign_case = "22222222-2222-2222-2222-222222222222";
|
||||
let foreign_dir = config.data_path.join("dr_other/open").join(foreign_case);
|
||||
std::fs::create_dir_all(&foreign_dir).unwrap();
|
||||
std::fs::write(foreign_dir.join("document_v1.md"), "v1").unwrap();
|
||||
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let resp = app.oneshot(reanalyze_request(foreign_case, &cookie)).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reanalyze_without_llm_returns_503() {
|
||||
let users = vec![make_admin("dr_a")];
|
||||
let api_keys: HashMap<String, String> = users
|
||||
.iter()
|
||||
.map(|u| (u.api_key.clone(), u.slug.clone()))
|
||||
.collect();
|
||||
let config = Arc::new(Config {
|
||||
data_path: unique_tmp("rn-4"),
|
||||
users,
|
||||
api_keys,
|
||||
..Config::test_default()
|
||||
});
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&config.data_path, "dr_a", case_id);
|
||||
std::fs::write(case_dir.join("document_v1.md"), "v1").unwrap();
|
||||
seed_recording(&case_dir, "10-00-00", Some("ok"));
|
||||
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let resp = app.oneshot(reanalyze_request(case_id, &cookie)).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::SERVICE_UNAVAILABLE);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reanalyze_happy_path_writes_v2_input() {
|
||||
let config = config_with_llm_users(
|
||||
unique_tmp("rn-5"),
|
||||
"http://unused".into(),
|
||||
vec![make_admin("dr_a")],
|
||||
);
|
||||
async fn analyze_writes_v2_when_document_exists() {
|
||||
let config = config_with_llm(unique_tmp("rn-5"), "http://unused".into());
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&config.data_path, "dr_a", case_id);
|
||||
std::fs::write(case_dir.join("document_v1.md"), "altes Dokument").unwrap();
|
||||
@@ -529,7 +438,7 @@ async fn reanalyze_happy_path_writes_v2_input() {
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let resp = app.oneshot(reanalyze_request(case_id, &cookie)).await.unwrap();
|
||||
let resp = app.oneshot(analyze_request(case_id, &cookie)).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::SEE_OTHER);
|
||||
|
||||
let input_path = case_dir.join("analysis_input_v2.json");
|
||||
@@ -537,34 +446,11 @@ async fn reanalyze_happy_path_writes_v2_input() {
|
||||
let parsed: Value = serde_json::from_str(&std::fs::read_to_string(&input_path).unwrap()).unwrap();
|
||||
assert_eq!(parsed["version"], 2);
|
||||
assert_eq!(parsed["recordings"].as_array().unwrap().len(), 2);
|
||||
// v1 document is still there until worker writes v2.
|
||||
assert!(case_dir.join("document_v1.md").exists());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reanalyze_second_time_returns_409() {
|
||||
let config = config_with_llm_users(
|
||||
unique_tmp("rn-6"),
|
||||
"http://unused".into(),
|
||||
vec![make_admin("dr_a")],
|
||||
);
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&config.data_path, "dr_a", case_id);
|
||||
std::fs::write(case_dir.join("document_v1.md"), "v1").unwrap();
|
||||
seed_recording(&case_dir, "10-00-00", Some("ok"));
|
||||
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let first = app.clone().oneshot(reanalyze_request(case_id, &cookie)).await.unwrap();
|
||||
assert_eq!(first.status(), StatusCode::SEE_OTHER);
|
||||
|
||||
let second = app.oneshot(reanalyze_request(case_id, &cookie)).await.unwrap();
|
||||
assert_eq!(second.status(), StatusCode::CONFLICT);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reanalyze_worker_writes_document_v2_via_wiremock() {
|
||||
async fn analyze_v2_worker_writes_document_v2_via_wiremock() {
|
||||
let tmp = unique_tmp("rn-w");
|
||||
let case_dir = tmp.join("dr_a/11111111-1111-1111-1111-111111111111");
|
||||
std::fs::create_dir_all(&case_dir).unwrap();
|
||||
@@ -592,7 +478,7 @@ async fn reanalyze_worker_writes_document_v2_via_wiremock() {
|
||||
.mount(&mock)
|
||||
.await;
|
||||
|
||||
let config = config_with_llm_users(tmp.clone(), mock.uri(), vec![make_admin("dr_a")]);
|
||||
let config = config_with_llm(tmp.clone(), mock.uri());
|
||||
let (tx, rx) = analyze::channel();
|
||||
let handle = tokio::spawn(analyze::worker::run(rx, config, reqwest::Client::new()));
|
||||
|
||||
@@ -613,7 +499,6 @@ async fn reanalyze_worker_writes_document_v2_via_wiremock() {
|
||||
|
||||
let content = std::fs::read_to_string(&doc_v2).unwrap();
|
||||
assert!(content.contains("neue Fassung"));
|
||||
// v1 untouched.
|
||||
assert_eq!(
|
||||
std::fs::read_to_string(case_dir.join("document_v1.md")).unwrap(),
|
||||
"alte Version"
|
||||
@@ -623,6 +508,182 @@ async fn reanalyze_worker_writes_document_v2_via_wiremock() {
|
||||
let _ = tokio::time::timeout(Duration::from_secs(2), handle).await;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Soft-delete + Undo
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
#[tokio::test]
|
||||
async fn delete_writes_marker_and_redirects() {
|
||||
let config = config_with_llm(unique_tmp("del-1"), "http://unused".into());
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&config.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "10-00-00", Some("ok"));
|
||||
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let resp = app.oneshot(delete_request(case_id, &cookie)).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::SEE_OTHER);
|
||||
assert_eq!(
|
||||
resp.headers().get(header::LOCATION).unwrap().to_str().unwrap(),
|
||||
"/web/cases"
|
||||
);
|
||||
let marker = case_dir.join(".deleted");
|
||||
assert!(marker.exists(), ".deleted marker missing");
|
||||
let raw = std::fs::read_to_string(&marker).unwrap();
|
||||
let parsed: Value = serde_json::from_str(&raw).unwrap();
|
||||
assert!(parsed["batch"].is_string(), "batch must be a UUID string");
|
||||
assert!(parsed["deleted_at"].is_string(), "deleted_at must be a string");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn deleted_case_returns_404_on_detail() {
|
||||
let config = config_with_llm(unique_tmp("del-2"), "http://unused".into());
|
||||
let case_id = "11111111-1111-1111-1111-111111111111";
|
||||
let case_dir = seed_case(&config.data_path, "dr_a", case_id);
|
||||
seed_recording(&case_dir, "10-00-00", Some("ok"));
|
||||
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let resp = app.clone().oneshot(delete_request(case_id, &cookie)).await.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::SEE_OTHER);
|
||||
|
||||
let resp = app
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.uri(format!("/web/cases/{case_id}"))
|
||||
.header(header::COOKIE, &cookie)
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn undo_delete_restores_latest_batch_only() {
|
||||
let config = config_with_llm(unique_tmp("undo-1"), "http://unused".into());
|
||||
let case_a = "11111111-1111-1111-1111-111111111111";
|
||||
let case_b = "22222222-2222-2222-2222-222222222222";
|
||||
let dir_a = seed_case(&config.data_path, "dr_a", case_a);
|
||||
let dir_b = seed_case(&config.data_path, "dr_a", case_b);
|
||||
seed_recording(&dir_a, "10-00-00", Some("a"));
|
||||
seed_recording(&dir_b, "10-05-00", Some("b"));
|
||||
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
// Two separate delete clicks → two distinct batches.
|
||||
let _ = app.clone().oneshot(delete_request(case_a, &cookie)).await.unwrap();
|
||||
// Ensure timestamps differ at sub-second resolution (RFC3339 includes
|
||||
// fractional seconds via the Rfc3339 well-known format).
|
||||
tokio::time::sleep(Duration::from_millis(20)).await;
|
||||
let _ = app.clone().oneshot(delete_request(case_b, &cookie)).await.unwrap();
|
||||
|
||||
let undo = app
|
||||
.clone()
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method("POST")
|
||||
.uri("/web/cases/undo-delete")
|
||||
.header(header::COOKIE, &cookie)
|
||||
.body(Body::empty())
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(undo.status(), StatusCode::SEE_OTHER);
|
||||
|
||||
// case_b (latest delete) restored, case_a still deleted.
|
||||
assert!(!dir_b.join(".deleted").exists(), "case_b marker should be gone");
|
||||
assert!(dir_a.join(".deleted").exists(), "case_a marker must remain");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn bulk_delete_shares_one_batch_uuid() {
|
||||
let config = config_with_llm(unique_tmp("bulk-d"), "http://unused".into());
|
||||
let case_a = "11111111-1111-1111-1111-111111111111";
|
||||
let case_b = "22222222-2222-2222-2222-222222222222";
|
||||
let dir_a = seed_case(&config.data_path, "dr_a", case_a);
|
||||
let dir_b = seed_case(&config.data_path, "dr_a", case_b);
|
||||
seed_recording(&dir_a, "10-00-00", Some("a"));
|
||||
seed_recording(&dir_b, "10-05-00", Some("b"));
|
||||
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let body = format!("action=delete&case_id={case_a}&case_id={case_b}");
|
||||
let resp = app
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method("POST")
|
||||
.uri("/web/cases/bulk")
|
||||
.header(header::COOKIE, &cookie)
|
||||
.header(header::CONTENT_TYPE, "application/x-www-form-urlencoded")
|
||||
.body(Body::from(body))
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::SEE_OTHER);
|
||||
|
||||
let m_a: Value = serde_json::from_str(&std::fs::read_to_string(dir_a.join(".deleted")).unwrap()).unwrap();
|
||||
let m_b: Value = serde_json::from_str(&std::fs::read_to_string(dir_b.join(".deleted")).unwrap()).unwrap();
|
||||
assert_eq!(m_a["batch"], m_b["batch"], "bulk-delete must share batch UUID");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn bulk_analyze_processes_each_selected_case() {
|
||||
let config = config_with_llm(unique_tmp("bulk-a"), "http://unused".into());
|
||||
let case_a = "11111111-1111-1111-1111-111111111111";
|
||||
let case_b = "22222222-2222-2222-2222-222222222222";
|
||||
let dir_a = seed_case(&config.data_path, "dr_a", case_a);
|
||||
let dir_b = seed_case(&config.data_path, "dr_a", case_b);
|
||||
seed_recording(&dir_a, "10-00-00", Some("a"));
|
||||
seed_recording(&dir_b, "10-05-00", Some("b"));
|
||||
|
||||
let app = doctate_server::create_router(config);
|
||||
let cookie = login(app.clone(), "dr_a").await;
|
||||
|
||||
let body = format!("action=analyze&case_id={case_a}&case_id={case_b}");
|
||||
let resp = app
|
||||
.oneshot(
|
||||
Request::builder()
|
||||
.method("POST")
|
||||
.uri("/web/cases/bulk")
|
||||
.header(header::COOKIE, &cookie)
|
||||
.header(header::CONTENT_TYPE, "application/x-www-form-urlencoded")
|
||||
.body(Body::from(body))
|
||||
.unwrap(),
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(resp.status(), StatusCode::SEE_OTHER);
|
||||
|
||||
assert!(dir_a.join("analysis_input_v1.json").exists());
|
||||
assert!(dir_b.join("analysis_input_v1.json").exists());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn recovery_skips_deleted_cases() {
|
||||
let tmp = unique_tmp("rec-del");
|
||||
let case_dir = tmp.join("dr_a/11111111-1111-1111-1111-111111111111");
|
||||
std::fs::create_dir_all(&case_dir).unwrap();
|
||||
std::fs::write(case_dir.join("analysis_input_v1.json"), "{}").unwrap();
|
||||
std::fs::write(
|
||||
case_dir.join(".deleted"),
|
||||
r#"{"batch":"00000000-0000-0000-0000-000000000000","deleted_at":"2026-04-15T10:00:00Z"}"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let (tx, mut rx) = analyze::channel();
|
||||
analyze::recovery::scan_and_enqueue(&tmp, &tx).await;
|
||||
|
||||
assert!(rx.try_recv().is_err(), "deleted case must not be enqueued");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn document_view_without_document_returns_404() {
|
||||
let config = config_with_llm(unique_tmp("dv2"), "http://unused".into());
|
||||
Reference in New Issue
Block a user