huskies: merge 530_story_eliminate_filesystem_markdown_shadows_entirely_crdt_db_is_the_only_story_store

This commit is contained in:
dave
2026-04-10 14:56:13 +00:00
parent 1dd675796b
commit 11d19d8902
26 changed files with 966 additions and 1668 deletions
+33 -11
View File
@@ -167,25 +167,47 @@ mod tests {
#[test]
fn scan_stage_items_returns_empty_for_missing_dir() {
// Use a unique stage name that no other test writes to, so
// the global CRDT store won't contribute stale items.
let tmp = tempfile::tempdir().unwrap();
let items = scan_stage_items(tmp.path(), "2_current");
let items = scan_stage_items(tmp.path(), "9_nonexistent");
assert!(items.is_empty());
}
#[test]
fn scan_stage_items_returns_sorted_story_ids() {
use std::fs;
let tmp = tempfile::tempdir().unwrap();
let stage_dir = tmp.path().join(".huskies").join("work").join("2_current");
fs::create_dir_all(&stage_dir).unwrap();
fs::write(stage_dir.join("42_story_foo.md"), "---\nname: foo\n---").unwrap();
fs::write(stage_dir.join("10_story_bar.md"), "---\nname: bar\n---").unwrap();
fs::write(stage_dir.join("5_story_baz.md"), "---\nname: baz\n---").unwrap();
// non-md file should be ignored
fs::write(stage_dir.join("README.txt"), "ignore me").unwrap();
// Write items via the CRDT store (the primary source of truth).
crate::db::ensure_content_store();
crate::db::write_item_with_content("9942_story_foo", "2_current", "---\nname: foo\n---");
crate::db::write_item_with_content("9940_story_bar", "2_current", "---\nname: bar\n---");
crate::db::write_item_with_content("9935_story_baz", "2_current", "---\nname: baz\n---");
let tmp = tempfile::tempdir().unwrap();
let items = scan_stage_items(tmp.path(), "2_current");
assert_eq!(items, vec!["10_story_bar", "42_story_foo", "5_story_baz"]);
// The global CRDT may contain items from other tests, so check
// that our three items are present and appear in sorted order.
assert!(
items.iter().any(|id| id == "9935_story_baz"),
"9935_story_baz should be in results"
);
assert!(
items.iter().any(|id| id == "9940_story_bar"),
"9940_story_bar should be in results"
);
assert!(
items.iter().any(|id| id == "9942_story_foo"),
"9942_story_foo should be in results"
);
// Verify sorted order: BTreeSet produces lexicographic order.
let positions: Vec<usize> = ["9935_story_baz", "9940_story_bar", "9942_story_foo"]
.iter()
.filter_map(|id| items.iter().position(|x| x == id))
.collect();
assert_eq!(positions.len(), 3, "all three items must be found");
assert!(
positions[0] < positions[1] && positions[1] < positions[2],
"items should appear in sorted order: positions = {positions:?}"
);
}
#[test]