//! 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. /// /// Creates `.huskies/work/{stage}/{filename}` under `root`, creating any /// 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. pub(crate) fn write_story_file(root: &Path, stage: &str, filename: &str, content: &str) { let dir = root.join(".huskies/work").join(stage); std::fs::create_dir_all(&dir).unwrap(); std::fs::write(dir.join(filename), content).unwrap(); // 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); }