76bf65be1a
This commit replaces the disk-based `analysis_input.json` marker for in-progress analysis jobs with an in-memory `Arc<RwLock<HashSet<PathBuf>>>`. Previously, the existence of `analysis_input.json` was used as a signal that a case was queued or being analyzed. This led to stale "Queued" states after server restarts, as the disk file would persist while the server process tracking it had vanished. The new `InFlight` struct, held in `AppState`, provides a process-local marker. This ensures that: - Server restarts correctly reset the state, as the `HashSet` is cleared. - Race conditions for triggering analysis are handled by the `try_claim` method, replacing the previous reliance on file system `O_EXCL` flags. - The `AnalyzeJob` payload now travels with the job over the channel, eliminating the need for workers to re-read `analysis_input.json` from disk. This change simplifies state management and improves the reliability of analysis job tracking.
38 lines
1.7 KiB
Rust
38 lines
1.7 KiB
Rust
//! Re-exports of case-directory artefact filenames from their
|
|
//! canonical source-of-truth locations.
|
|
//!
|
|
//! Tests that need to read, write, or assert the absence of per-case
|
|
//! artefacts (`oneliner.json`, `.closed`, `document.json`,
|
|
//! `analysis_input.json`) pull these names from here instead of
|
|
//! inlining string literals. If the server renames a sidecar in the
|
|
//! future, test call-sites fail to compile instead of silently
|
|
//! asserting against the old name.
|
|
|
|
use std::path::Path;
|
|
|
|
pub use doctate_common::ONELINER_FILENAME;
|
|
pub use doctate_server::analyze::{DOCUMENT_FILE, Document};
|
|
pub use doctate_server::paths::CLOSE_MARKER;
|
|
|
|
/// Legacy filename of the per-case analysis input. The server no
|
|
/// longer writes or reads it — the in-flight marker lives in `InFlight`
|
|
/// and the payload travels with the `AnalyzeJob`. This constant is
|
|
/// retained only for tests that simulate an orphan file from a
|
|
/// pre-refactor server. New tests should not seed this file.
|
|
pub const ANALYSIS_INPUT_FILE: &str = "analysis_input.json";
|
|
|
|
/// Seed a `document.json` for tests. `covered_mtime` is the RFC3339
|
|
/// snapshot mtime the document is supposed to "cover" — for tests that
|
|
/// don't care about the auto-trigger state machine, pass any RFC3339
|
|
/// string (e.g. `"1970-01-01T00:00:00Z"`).
|
|
pub fn write_document_for_test(case_dir: &Path, content_md: &str, covered_mtime: &str) {
|
|
let doc = Document {
|
|
covered_mtime: covered_mtime.to_owned(),
|
|
written_at: doctate_common::timestamp::now_rfc3339(),
|
|
backend_id: "test".to_owned(),
|
|
content_md: content_md.to_owned(),
|
|
};
|
|
let bytes = serde_json::to_vec_pretty(&doc).expect("serialize test Document");
|
|
std::fs::write(case_dir.join(DOCUMENT_FILE), bytes).expect("write test document.json");
|
|
}
|