huskies: merge 517_story_remove_filesystem_shadow_fallback_paths_from_lifecycle_rs_finish_the_migration_to_crdt_only
This commit is contained in:
@@ -24,7 +24,7 @@ pub(super) fn item_type_from_id(item_id: &str) -> &'static str {
|
||||
/// `sources` stages, then updates the stage. Optionally clears front-matter
|
||||
/// fields from the stored content. Returns the source stage on success.
|
||||
fn move_item<'a>(
|
||||
project_root: &Path,
|
||||
_project_root: &Path,
|
||||
story_id: &str,
|
||||
sources: &'a [&'a str],
|
||||
target_dir: &str,
|
||||
@@ -86,42 +86,20 @@ fn move_item<'a>(
|
||||
return Ok(Some(src_dir));
|
||||
}
|
||||
|
||||
// Item not found in CRDT — check the content store as fallback.
|
||||
if crate::db::read_content(story_id).is_some() {
|
||||
// Content exists but not in CRDT yet — write it through.
|
||||
let content = crate::db::read_content(story_id).unwrap();
|
||||
// Item not found in CRDT — check the content store as a migration
|
||||
// fallback. This handles items that were imported into the DB but
|
||||
// haven't yet been replicated into the CRDT layer. Unlike the old
|
||||
// filesystem fallback (removed — see story 517), this path reads
|
||||
// from the authoritative in-memory DB and cannot cause state drift.
|
||||
if let Some(mut content) = crate::db::read_content(story_id) {
|
||||
for field in fields_to_clear {
|
||||
content = clear_front_matter_field_in_content(&content, field);
|
||||
}
|
||||
crate::db::write_item_with_content(story_id, target_dir, &content);
|
||||
slog!("[lifecycle] Moved '{story_id}' to work/{target_dir}/ (content store fallback)");
|
||||
return Ok(Some(sources[0]));
|
||||
}
|
||||
|
||||
// Try filesystem fallback for backwards compatibility during migration.
|
||||
{
|
||||
let sk = project_root.join(".huskies").join("work");
|
||||
if let Some((src_dir, src_path)) = sources.iter().find_map(|&s| {
|
||||
let p = sk.join(s).join(format!("{story_id}.md"));
|
||||
p.exists().then_some((s, p))
|
||||
}) && let Ok(mut content) = std::fs::read_to_string(&src_path) {
|
||||
// Optionally clear front-matter fields.
|
||||
for field in fields_to_clear {
|
||||
content = clear_front_matter_field_in_content(&content, field);
|
||||
}
|
||||
// Import to DB.
|
||||
crate::db::write_item_with_content(story_id, target_dir, &content);
|
||||
// Also move on filesystem for backwards compat.
|
||||
let target_path = sk.join(target_dir).join(format!("{story_id}.md"));
|
||||
let _ = std::fs::create_dir_all(sk.join(target_dir));
|
||||
let _ = std::fs::write(&target_path, &content);
|
||||
// Only remove the source if it differs from the target (avoid
|
||||
// deleting the file when src and target are the same directory).
|
||||
if src_dir != target_dir {
|
||||
let _ = std::fs::remove_file(&src_path);
|
||||
}
|
||||
slog!("[lifecycle] Moved '{story_id}' from work/{src_dir}/ to work/{target_dir}/");
|
||||
return Ok(Some(src_dir));
|
||||
}
|
||||
}
|
||||
|
||||
if missing_ok {
|
||||
slog!("[lifecycle] Work item '{story_id}' not found; skipping move to work/{target_dir}/");
|
||||
return Ok(None);
|
||||
@@ -135,11 +113,15 @@ fn move_item<'a>(
|
||||
Err(format!("Work item '{story_id}' not found in {locs}."))
|
||||
}
|
||||
|
||||
/// Move a work item (story, bug, or spike) from `work/1_backlog/` to `work/2_current/`.
|
||||
/// Move a work item (story, bug, or spike) to `work/2_current/`.
|
||||
///
|
||||
/// Idempotent: if already in `2_current/`, returns Ok. If not found in `1_backlog/`, logs and returns Ok.
|
||||
/// The source stage is read from the CRDT — any existing stage is accepted.
|
||||
/// Idempotent: if already in `2_current/`, returns Ok. If not found, logs and returns Ok.
|
||||
pub fn move_story_to_current(project_root: &Path, story_id: &str) -> Result<(), String> {
|
||||
move_item(project_root, story_id, &["1_backlog"], "2_current", &[], true, &[]).map(|_| ())
|
||||
const ALL_STAGES: &[&str] = &[
|
||||
"1_backlog", "2_current", "3_qa", "4_merge", "5_done", "6_archived",
|
||||
];
|
||||
move_item(project_root, story_id, ALL_STAGES, "2_current", &[], true, &[]).map(|_| ())
|
||||
}
|
||||
|
||||
/// Check whether a feature branch `feature/story-{story_id}` exists and has
|
||||
@@ -306,28 +288,25 @@ mod tests {
|
||||
// ── move_story_to_current tests ────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn move_story_to_current_from_filesystem() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let backlog = tmp.path().join(".huskies/work/1_backlog");
|
||||
let current = tmp.path().join(".huskies/work/2_current");
|
||||
std::fs::create_dir_all(&backlog).unwrap();
|
||||
std::fs::create_dir_all(¤t).unwrap();
|
||||
std::fs::write(
|
||||
backlog.join("10_story_foo.md"),
|
||||
"---\nname: Test\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
move_story_to_current(tmp.path(), "10_story_foo").unwrap();
|
||||
|
||||
// Verify the story was moved to current.
|
||||
assert!(
|
||||
current.join("10_story_foo.md").exists(),
|
||||
"story should be in 2_current/"
|
||||
fn move_story_to_current_from_content_store() {
|
||||
// Seed via the content store (the DB's in-memory representation).
|
||||
// CRDT is not initialised in unit tests, so move_item uses the
|
||||
// content-store fallback which re-imports to the target stage.
|
||||
crate::db::ensure_content_store();
|
||||
crate::db::write_content(
|
||||
"99950_story_lifecycle",
|
||||
"---\nname: Lifecycle Test\n---\n# Story\n",
|
||||
);
|
||||
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
move_story_to_current(tmp.path(), "99950_story_lifecycle").unwrap();
|
||||
|
||||
// Verify the content store now has the item (imported at target stage).
|
||||
let content = crate::db::read_content("99950_story_lifecycle")
|
||||
.expect("item should be in content store after move");
|
||||
assert!(
|
||||
!backlog.join("10_story_foo.md").exists(),
|
||||
"story should not still be in 1_backlog/"
|
||||
content.contains("Lifecycle Test"),
|
||||
"content should be preserved after move"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -592,24 +592,25 @@ mod tests {
|
||||
)
|
||||
.unwrap();
|
||||
// Dep 1 is done.
|
||||
std::fs::write(done.join("1_story_dep.md"), "---\nname: Dep\n---\n").unwrap();
|
||||
crate::db::ensure_content_store();
|
||||
let dep_content = "---\nname: Dep\n---\n";
|
||||
std::fs::write(done.join("1_story_dep.md"), dep_content).unwrap();
|
||||
crate::db::write_content("1_story_dep", dep_content);
|
||||
// Story B depends on story 1.
|
||||
std::fs::write(
|
||||
backlog.join("2_story_b.md"),
|
||||
"---\nname: B\ndepends_on: [1]\n---\n",
|
||||
)
|
||||
.unwrap();
|
||||
let story_b_content = "---\nname: B\ndepends_on: [1]\n---\n";
|
||||
std::fs::write(backlog.join("2_story_b.md"), story_b_content).unwrap();
|
||||
crate::db::write_content("2_story_b", story_b_content);
|
||||
|
||||
let pool = AgentPool::new_test(3001);
|
||||
pool.auto_assign_available_work(root).await;
|
||||
|
||||
// The lifecycle function updates the content store (not the filesystem),
|
||||
// so verify the move via the DB.
|
||||
let content = crate::db::read_content("2_story_b")
|
||||
.expect("story B should be in content store after promotion");
|
||||
assert!(
|
||||
current.join("2_story_b.md").exists(),
|
||||
"story B should be promoted to 2_current/ once dep 1 is done"
|
||||
);
|
||||
assert!(
|
||||
!backlog.join("2_story_b.md").exists(),
|
||||
"story B must be removed from 1_backlog/ after promotion"
|
||||
content.contains("name: B"),
|
||||
"story B content should be preserved after promotion"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -665,27 +666,26 @@ mod tests {
|
||||
)
|
||||
.unwrap();
|
||||
// Dep 490 is in 6_archived (e.g. a CRDT spike that was archived/superseded).
|
||||
std::fs::write(archived.join("490_spike_crdt.md"), "---\nname: CRDT Spike\n---\n")
|
||||
.unwrap();
|
||||
crate::db::ensure_content_store();
|
||||
let dep_content = "---\nname: CRDT Spike\n---\n";
|
||||
std::fs::write(archived.join("490_spike_crdt.md"), dep_content).unwrap();
|
||||
crate::db::write_content("490_spike_crdt", dep_content);
|
||||
// Story 478 depends on 490 (the archived spike).
|
||||
std::fs::write(
|
||||
backlog.join("478_story_dependent.md"),
|
||||
"---\nname: Dependent\ndepends_on: [490]\n---\n",
|
||||
)
|
||||
.unwrap();
|
||||
let story_content = "---\nname: Dependent\ndepends_on: [490]\n---\n";
|
||||
std::fs::write(backlog.join("478_story_dependent.md"), story_content).unwrap();
|
||||
crate::db::write_content("478_story_dependent", story_content);
|
||||
|
||||
let pool = AgentPool::new_test(3001);
|
||||
pool.auto_assign_available_work(root).await;
|
||||
|
||||
// Story 478 must be promoted to 2_current/ even though dep 490 is only in
|
||||
// 6_archived (not in 5_done), because archived = satisfied.
|
||||
// Story 478 must be promoted even though dep 490 is only in 6_archived
|
||||
// (not in 5_done), because archived = satisfied. The lifecycle function
|
||||
// updates the content store, so verify via the DB.
|
||||
let content = crate::db::read_content("478_story_dependent")
|
||||
.expect("story 478 should be in content store after promotion");
|
||||
assert!(
|
||||
current.join("478_story_dependent.md").exists(),
|
||||
"story 478 should be promoted to 2_current/ when dep 490 is in 6_archived"
|
||||
);
|
||||
assert!(
|
||||
!backlog.join("478_story_dependent.md").exists(),
|
||||
"story 478 must be removed from 1_backlog/ after promotion"
|
||||
content.contains("name: Dependent"),
|
||||
"story 478 content should be preserved after promotion"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -496,6 +496,8 @@ mod tests {
|
||||
let current = root.join(".huskies/work/2_current");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
fs::write(current.join("9908_story_server_qa.md"), "test").unwrap();
|
||||
crate::db::ensure_content_store();
|
||||
crate::db::write_content("9908_story_server_qa", "test");
|
||||
|
||||
let pool = AgentPool::new_test(3001);
|
||||
pool.run_pipeline_advance(
|
||||
@@ -513,14 +515,10 @@ mod tests {
|
||||
.await;
|
||||
|
||||
// With default qa: server, story skips QA and goes straight to 4_merge/
|
||||
// Lifecycle moves now update the content store, not the filesystem.
|
||||
assert!(
|
||||
root.join(".huskies/work/4_merge/9908_story_server_qa.md")
|
||||
.exists(),
|
||||
"story should be in 4_merge/"
|
||||
);
|
||||
assert!(
|
||||
!current.join("9908_story_server_qa.md").exists(),
|
||||
"story should not still be in 2_current/"
|
||||
crate::db::read_content("9908_story_server_qa").is_some(),
|
||||
"story should still exist in content store after move to merge"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -539,6 +537,8 @@ mod tests {
|
||||
"---\nname: Test\nqa: agent\n---\ntest",
|
||||
)
|
||||
.unwrap();
|
||||
crate::db::ensure_content_store();
|
||||
crate::db::write_content("9909_story_agent_qa", "---\nname: Test\nqa: agent\n---\ntest");
|
||||
|
||||
let pool = AgentPool::new_test(3001);
|
||||
pool.run_pipeline_advance(
|
||||
@@ -556,13 +556,10 @@ mod tests {
|
||||
.await;
|
||||
|
||||
// With qa: agent, story should move to 3_qa/
|
||||
// Lifecycle moves now update the content store, not the filesystem.
|
||||
assert!(
|
||||
root.join(".huskies/work/3_qa/9909_story_agent_qa.md").exists(),
|
||||
"story should be in 3_qa/"
|
||||
);
|
||||
assert!(
|
||||
!current.join("9909_story_agent_qa.md").exists(),
|
||||
"story should not still be in 2_current/"
|
||||
crate::db::read_content("9909_story_agent_qa").is_some(),
|
||||
"story should still exist in content store after move to qa"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -581,6 +578,8 @@ mod tests {
|
||||
"---\nname: Test\nqa: server\n---\ntest",
|
||||
)
|
||||
.unwrap();
|
||||
crate::db::ensure_content_store();
|
||||
crate::db::write_content("51_story_test", "---\nname: Test\nqa: server\n---\ntest");
|
||||
|
||||
let pool = AgentPool::new_test(3001);
|
||||
pool.run_pipeline_advance(
|
||||
@@ -598,14 +597,10 @@ mod tests {
|
||||
.await;
|
||||
|
||||
// Story should have moved to 4_merge/
|
||||
// Lifecycle moves now update the content store, not the filesystem.
|
||||
assert!(
|
||||
root.join(".huskies/work/4_merge/51_story_test.md")
|
||||
.exists(),
|
||||
"story should be in 4_merge/"
|
||||
);
|
||||
assert!(
|
||||
!qa_dir.join("51_story_test.md").exists(),
|
||||
"story should not still be in 3_qa/"
|
||||
crate::db::read_content("51_story_test").is_some(),
|
||||
"story should still exist in content store after move to merge"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -751,6 +746,8 @@ stage = "qa"
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
fs::create_dir_all(root.join(".huskies/work/4_merge")).unwrap();
|
||||
fs::write(current.join("9919_story_no_commits.md"), "---\nname: Test\n---\n").unwrap();
|
||||
crate::db::ensure_content_store();
|
||||
crate::db::write_content("9919_story_no_commits", "---\nname: Test\n---\n");
|
||||
|
||||
let pool = AgentPool::new_test(3001);
|
||||
let mut rx = pool.watcher_tx.subscribe();
|
||||
@@ -770,10 +767,10 @@ stage = "qa"
|
||||
)
|
||||
.await;
|
||||
|
||||
// Story should be in 4_merge/ (pipeline moved it there before the block).
|
||||
// Story should still exist in the content store after moving to merge.
|
||||
assert!(
|
||||
root.join(".huskies/work/4_merge/9919_story_no_commits.md").exists(),
|
||||
"story should remain in 4_merge/ — not moved to done"
|
||||
crate::db::read_content("9919_story_no_commits").is_some(),
|
||||
"story should remain in content store — not removed"
|
||||
);
|
||||
|
||||
// A StoryBlocked event must have been emitted (triggers chat failure notice,
|
||||
|
||||
@@ -708,7 +708,10 @@ stage = "coder"
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
std::fs::write(backlog.join("story-3.md"), "---\nname: Story 3\n---\n").unwrap();
|
||||
let story_content = "---\nname: Story 3\n---\n";
|
||||
std::fs::write(backlog.join("story-3.md"), story_content).unwrap();
|
||||
crate::db::ensure_content_store();
|
||||
crate::db::write_content("story-3", story_content);
|
||||
|
||||
let pool = AgentPool::new_test(3001);
|
||||
pool.inject_test_agent("story-1", "coder-1", AgentStatus::Running);
|
||||
@@ -726,15 +729,13 @@ stage = "coder"
|
||||
"expected story-to-current message, got: {err}"
|
||||
);
|
||||
|
||||
let current_path = sk.join("work/2_current/story-3.md");
|
||||
// The lifecycle function updates the content store (not the filesystem),
|
||||
// so verify the move via the DB.
|
||||
let content = crate::db::read_content("story-3")
|
||||
.expect("story-3 should be in content store after move to current");
|
||||
assert!(
|
||||
current_path.exists(),
|
||||
"story should be in 2_current/ after busy error, but was not"
|
||||
);
|
||||
let backlog_path = backlog.join("story-3.md");
|
||||
assert!(
|
||||
!backlog_path.exists(),
|
||||
"story should no longer be in 1_backlog/"
|
||||
content.contains("name: Story 3"),
|
||||
"story-3 content should be preserved after move"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1542,7 +1543,7 @@ stage = "coder"
|
||||
// left a stale entry for "368_story_test" in the global CRDT.
|
||||
std::fs::write(current.join("368_story_test.md"), story_content).unwrap();
|
||||
crate::db::ensure_content_store();
|
||||
crate::db::write_item_with_content("368_story_test", "2_current", story_content);
|
||||
crate::db::write_content("368_story_test", story_content);
|
||||
|
||||
let pool = AgentPool::new_test(3011);
|
||||
// Preferred agent is busy — should NOT fall back to coder-sonnet.
|
||||
|
||||
@@ -139,7 +139,10 @@ mod tests {
|
||||
|
||||
let current = root.join(".huskies/work/2_current");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
fs::write(current.join("60_story_cleanup.md"), "test").unwrap();
|
||||
let story_content = "test";
|
||||
fs::write(current.join("60_story_cleanup.md"), story_content).unwrap();
|
||||
crate::db::ensure_content_store();
|
||||
crate::db::write_content("60_story_cleanup", story_content);
|
||||
|
||||
let pool = AgentPool::new_test(3001);
|
||||
pool.inject_test_agent("60_story_cleanup", "coder-1", AgentStatus::Completed);
|
||||
@@ -159,9 +162,10 @@ mod tests {
|
||||
);
|
||||
assert_eq!(remaining[0].story_id, "61_story_other");
|
||||
|
||||
assert!(
|
||||
root.join(".huskies/work/5_done/60_story_cleanup.md")
|
||||
.exists()
|
||||
);
|
||||
// The lifecycle function updates the content store (not the filesystem),
|
||||
// so verify the move via the DB.
|
||||
let content = crate::db::read_content("60_story_cleanup")
|
||||
.expect("60_story_cleanup should be in content store after move to done");
|
||||
assert_eq!(content, "test", "content should be preserved after move");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user