2026-03-28 19:47:59 +00:00
|
|
|
//! Shared test utilities for chat handler tests.
|
|
|
|
|
//!
|
|
|
|
|
//! Import with `use crate::chat::test_helpers::write_story_file;`
|
|
|
|
|
|
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
|
|
/// Write a work-item file into the standard pipeline directory structure.
|
|
|
|
|
///
|
2026-04-03 16:12:52 +01:00
|
|
|
/// Creates `.huskies/work/{stage}/{filename}` under `root`, creating any
|
2026-04-08 03:03:59 +00:00
|
|
|
/// missing parent directories. Also writes to the global content store so
|
|
|
|
|
/// that code paths that prefer the content store over the filesystem (e.g.
|
|
|
|
|
/// `unblock_by_number`) see this test's content rather than a stale entry
|
|
|
|
|
/// left by a parallel test with the same numeric prefix.
|
2026-03-28 19:47:59 +00:00
|
|
|
pub(crate) fn write_story_file(root: &Path, stage: &str, filename: &str, content: &str) {
|
2026-04-03 16:12:52 +01:00
|
|
|
let dir = root.join(".huskies/work").join(stage);
|
2026-03-28 19:47:59 +00:00
|
|
|
std::fs::create_dir_all(&dir).unwrap();
|
|
|
|
|
std::fs::write(dir.join(filename), content).unwrap();
|
2026-04-10 12:56:16 +00:00
|
|
|
|
|
|
|
|
// Seed the in-memory content store so lifecycle functions that read from
|
|
|
|
|
// the content store (instead of the filesystem) see this entry. Use
|
|
|
|
|
// write_content (not write_item_with_content) to avoid writing to the
|
|
|
|
|
// CRDT — tests must not initialise the global CRDT OnceLock because that
|
|
|
|
|
// would pollute every subsequent test in the same process.
|
|
|
|
|
let story_id = filename.trim_end_matches(".md");
|
|
|
|
|
crate::db::ensure_content_store();
|
|
|
|
|
crate::db::write_content(story_id, content);
|
2026-03-28 19:47:59 +00:00
|
|
|
}
|