Fix 25 tests for work/ directory restructure (story 60)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1220,15 +1220,15 @@ mod tests {
|
||||
#[test]
|
||||
fn load_upcoming_parses_metadata() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let upcoming = tmp.path().join(".story_kit/stories/upcoming");
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::write(
|
||||
upcoming.join("31_view_upcoming.md"),
|
||||
upcoming.join("31_story_view_upcoming.md"),
|
||||
"---\nname: View Upcoming\ntest_plan: pending\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
upcoming.join("32_worktree.md"),
|
||||
upcoming.join("32_story_worktree.md"),
|
||||
"---\nname: Worktree Orchestration\ntest_plan: pending\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
@@ -1236,20 +1236,20 @@ mod tests {
|
||||
let ctx = crate::http::context::AppContext::new_test(tmp.path().to_path_buf());
|
||||
let stories = load_upcoming_stories(&ctx).unwrap();
|
||||
assert_eq!(stories.len(), 2);
|
||||
assert_eq!(stories[0].story_id, "31_view_upcoming");
|
||||
assert_eq!(stories[0].story_id, "31_story_view_upcoming");
|
||||
assert_eq!(stories[0].name.as_deref(), Some("View Upcoming"));
|
||||
assert_eq!(stories[1].story_id, "32_worktree");
|
||||
assert_eq!(stories[1].story_id, "32_story_worktree");
|
||||
assert_eq!(stories[1].name.as_deref(), Some("Worktree Orchestration"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_upcoming_skips_non_md_files() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let upcoming = tmp.path().join(".story_kit/stories/upcoming");
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::write(upcoming.join(".gitkeep"), "").unwrap();
|
||||
fs::write(
|
||||
upcoming.join("31_story.md"),
|
||||
upcoming.join("31_story_example.md"),
|
||||
"---\nname: A Story\ntest_plan: pending\n---\n",
|
||||
)
|
||||
.unwrap();
|
||||
@@ -1257,23 +1257,23 @@ mod tests {
|
||||
let ctx = crate::http::context::AppContext::new_test(tmp.path().to_path_buf());
|
||||
let stories = load_upcoming_stories(&ctx).unwrap();
|
||||
assert_eq!(stories.len(), 1);
|
||||
assert_eq!(stories[0].story_id, "31_story");
|
||||
assert_eq!(stories[0].story_id, "31_story_example");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_story_dirs_valid_files() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let current = tmp.path().join(".story_kit/current");
|
||||
let upcoming = tmp.path().join(".story_kit/stories/upcoming");
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::write(
|
||||
current.join("28_todos.md"),
|
||||
current.join("28_story_todos.md"),
|
||||
"---\nname: Show TODOs\ntest_plan: approved\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(
|
||||
upcoming.join("36_front_matter.md"),
|
||||
upcoming.join("36_story_front_matter.md"),
|
||||
"---\nname: Enforce Front Matter\ntest_plan: pending\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
@@ -1287,9 +1287,9 @@ mod tests {
|
||||
#[test]
|
||||
fn validate_story_dirs_missing_front_matter() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let current = tmp.path().join(".story_kit/current");
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
fs::write(current.join("28_todos.md"), "# No front matter\n").unwrap();
|
||||
fs::write(current.join("28_story_todos.md"), "# No front matter\n").unwrap();
|
||||
|
||||
let results = validate_story_dirs(tmp.path()).unwrap();
|
||||
assert_eq!(results.len(), 1);
|
||||
@@ -1300,9 +1300,9 @@ mod tests {
|
||||
#[test]
|
||||
fn validate_story_dirs_missing_required_fields() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let current = tmp.path().join(".story_kit/current");
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
fs::write(current.join("28_todos.md"), "---\n---\n# Story\n").unwrap();
|
||||
fs::write(current.join("28_story_todos.md"), "---\n---\n# Story\n").unwrap();
|
||||
|
||||
let results = validate_story_dirs(tmp.path()).unwrap();
|
||||
assert_eq!(results.len(), 1);
|
||||
@@ -1315,10 +1315,10 @@ mod tests {
|
||||
#[test]
|
||||
fn validate_story_dirs_missing_test_plan_only() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let current = tmp.path().join(".story_kit/current");
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
fs::write(
|
||||
current.join("28_todos.md"),
|
||||
current.join("28_story_todos.md"),
|
||||
"---\nname: A Story\n---\n# Story\n",
|
||||
)
|
||||
.unwrap();
|
||||
@@ -1373,36 +1373,36 @@ mod tests {
|
||||
assert_eq!(slugify_name("my_story_name"), "my_story_name");
|
||||
}
|
||||
|
||||
// --- next_story_number tests ---
|
||||
// --- next_item_number tests ---
|
||||
|
||||
#[test]
|
||||
fn next_story_number_empty_dirs() {
|
||||
fn next_item_number_empty_dirs() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let base = tmp.path().join(".story_kit/stories/upcoming");
|
||||
let base = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(&base).unwrap();
|
||||
assert_eq!(next_story_number(tmp.path()).unwrap(), 1);
|
||||
assert_eq!(next_item_number(tmp.path()).unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_story_number_scans_all_dirs() {
|
||||
fn next_item_number_scans_all_dirs() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let upcoming = tmp.path().join(".story_kit/stories/upcoming");
|
||||
let current = tmp.path().join(".story_kit/current");
|
||||
let archived = tmp.path().join(".story_kit/stories/archived");
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
let archived = tmp.path().join(".story_kit/work/5_archived");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
fs::create_dir_all(&archived).unwrap();
|
||||
fs::write(upcoming.join("10_foo.md"), "").unwrap();
|
||||
fs::write(current.join("20_bar.md"), "").unwrap();
|
||||
fs::write(archived.join("15_baz.md"), "").unwrap();
|
||||
assert_eq!(next_story_number(tmp.path()).unwrap(), 21);
|
||||
fs::write(upcoming.join("10_story_foo.md"), "").unwrap();
|
||||
fs::write(current.join("20_story_bar.md"), "").unwrap();
|
||||
fs::write(archived.join("15_story_baz.md"), "").unwrap();
|
||||
assert_eq!(next_item_number(tmp.path()).unwrap(), 21);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_story_number_no_story_dirs() {
|
||||
fn next_item_number_no_work_dirs() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
// No .story_kit at all
|
||||
assert_eq!(next_story_number(tmp.path()).unwrap(), 1);
|
||||
assert_eq!(next_item_number(tmp.path()).unwrap(), 1);
|
||||
}
|
||||
|
||||
// --- create_story integration tests ---
|
||||
@@ -1410,11 +1410,11 @@ mod tests {
|
||||
#[test]
|
||||
fn create_story_writes_correct_content() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let upcoming = tmp.path().join(".story_kit/stories/upcoming");
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::write(upcoming.join("36_existing.md"), "").unwrap();
|
||||
fs::write(upcoming.join("36_story_existing.md"), "").unwrap();
|
||||
|
||||
let number = next_story_number(tmp.path()).unwrap();
|
||||
let number = next_item_number(tmp.path()).unwrap();
|
||||
assert_eq!(number, 37);
|
||||
|
||||
let slug = slugify_name("My New Feature");
|
||||
@@ -1450,10 +1450,10 @@ mod tests {
|
||||
#[test]
|
||||
fn create_story_rejects_duplicate() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let upcoming = tmp.path().join(".story_kit/stories/upcoming");
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
|
||||
let filepath = upcoming.join("1_my_feature.md");
|
||||
let filepath = upcoming.join("1_story_my_feature.md");
|
||||
fs::write(&filepath, "existing").unwrap();
|
||||
|
||||
// Simulate the check
|
||||
@@ -1497,7 +1497,7 @@ mod tests {
|
||||
fn check_criterion_marks_first_unchecked() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
setup_git_repo(tmp.path());
|
||||
let current = tmp.path().join(".story_kit/current");
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
let filepath = current.join("1_test.md");
|
||||
fs::write(&filepath, story_with_criteria(3)).unwrap();
|
||||
@@ -1524,7 +1524,7 @@ mod tests {
|
||||
fn check_criterion_marks_second_unchecked() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
setup_git_repo(tmp.path());
|
||||
let current = tmp.path().join(".story_kit/current");
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
let filepath = current.join("2_test.md");
|
||||
fs::write(&filepath, story_with_criteria(3)).unwrap();
|
||||
@@ -1551,7 +1551,7 @@ mod tests {
|
||||
fn check_criterion_out_of_range_returns_error() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
setup_git_repo(tmp.path());
|
||||
let current = tmp.path().join(".story_kit/current");
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
let filepath = current.join("3_test.md");
|
||||
fs::write(&filepath, story_with_criteria(2)).unwrap();
|
||||
@@ -1577,7 +1577,7 @@ mod tests {
|
||||
fn set_test_plan_updates_pending_to_approved() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
setup_git_repo(tmp.path());
|
||||
let current = tmp.path().join(".story_kit/current");
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
let filepath = current.join("4_test.md");
|
||||
fs::write(
|
||||
@@ -1607,7 +1607,7 @@ mod tests {
|
||||
fn set_test_plan_missing_field_returns_error() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
setup_git_repo(tmp.path());
|
||||
let current = tmp.path().join(".story_kit/current");
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
let filepath = current.join("5_test.md");
|
||||
fs::write(
|
||||
@@ -1634,20 +1634,20 @@ mod tests {
|
||||
#[test]
|
||||
fn find_story_file_searches_current_then_upcoming() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let current = tmp.path().join(".story_kit/current");
|
||||
let upcoming = tmp.path().join(".story_kit/stories/upcoming");
|
||||
let current = tmp.path().join(".story_kit/work/2_current");
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(¤t).unwrap();
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
|
||||
// Only in upcoming
|
||||
fs::write(upcoming.join("6_test.md"), "").unwrap();
|
||||
let found = find_story_file(tmp.path(), "6_test").unwrap();
|
||||
assert!(found.ends_with("upcoming/6_test.md") || found.ends_with("upcoming\\6_test.md"));
|
||||
assert!(found.ends_with("1_upcoming/6_test.md") || found.ends_with("1_upcoming\\6_test.md"));
|
||||
|
||||
// Also in current — current should win
|
||||
fs::write(current.join("6_test.md"), "").unwrap();
|
||||
let found = find_story_file(tmp.path(), "6_test").unwrap();
|
||||
assert!(found.ends_with("current/6_test.md") || found.ends_with("current\\6_test.md"));
|
||||
assert!(found.ends_with("2_current/6_test.md") || found.ends_with("2_current\\6_test.md"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1661,30 +1661,30 @@ mod tests {
|
||||
// ── Bug file helper tests ──────────────────────────────────────────────────
|
||||
|
||||
#[test]
|
||||
fn next_bug_number_starts_at_1_when_empty() {
|
||||
fn next_item_number_starts_at_1_when_empty_bugs() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
assert_eq!(next_bug_number(tmp.path()).unwrap(), 1);
|
||||
assert_eq!(next_item_number(tmp.path()).unwrap(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_bug_number_increments_from_existing() {
|
||||
fn next_item_number_increments_from_existing_bugs() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let bugs_dir = tmp.path().join(".story_kit/bugs");
|
||||
fs::create_dir_all(&bugs_dir).unwrap();
|
||||
fs::write(bugs_dir.join("bug-1-crash.md"), "").unwrap();
|
||||
fs::write(bugs_dir.join("bug-3-another.md"), "").unwrap();
|
||||
assert_eq!(next_bug_number(tmp.path()).unwrap(), 4);
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::write(upcoming.join("1_bug_crash.md"), "").unwrap();
|
||||
fs::write(upcoming.join("3_bug_another.md"), "").unwrap();
|
||||
assert_eq!(next_item_number(tmp.path()).unwrap(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn next_bug_number_scans_archive_too() {
|
||||
fn next_item_number_scans_archived_too() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let bugs_dir = tmp.path().join(".story_kit/bugs");
|
||||
let archive_dir = bugs_dir.join("archive");
|
||||
fs::create_dir_all(&bugs_dir).unwrap();
|
||||
fs::create_dir_all(&archive_dir).unwrap();
|
||||
fs::write(archive_dir.join("bug-5-old.md"), "").unwrap();
|
||||
assert_eq!(next_bug_number(tmp.path()).unwrap(), 6);
|
||||
let upcoming = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
let archived = tmp.path().join(".story_kit/work/5_archived");
|
||||
fs::create_dir_all(&upcoming).unwrap();
|
||||
fs::create_dir_all(&archived).unwrap();
|
||||
fs::write(archived.join("5_bug_old.md"), "").unwrap();
|
||||
assert_eq!(next_item_number(tmp.path()).unwrap(), 6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1697,33 +1697,33 @@ mod tests {
|
||||
#[test]
|
||||
fn list_bug_files_excludes_archive_subdir() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let bugs_dir = tmp.path().join(".story_kit/bugs");
|
||||
let archive_dir = bugs_dir.join("archive");
|
||||
fs::create_dir_all(&bugs_dir).unwrap();
|
||||
fs::create_dir_all(&archive_dir).unwrap();
|
||||
fs::write(bugs_dir.join("bug-1-open.md"), "# Bug 1: Open Bug\n").unwrap();
|
||||
fs::write(archive_dir.join("bug-2-closed.md"), "# Bug 2: Closed Bug\n").unwrap();
|
||||
let upcoming_dir = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
let archived_dir = tmp.path().join(".story_kit/work/5_archived");
|
||||
fs::create_dir_all(&upcoming_dir).unwrap();
|
||||
fs::create_dir_all(&archived_dir).unwrap();
|
||||
fs::write(upcoming_dir.join("1_bug_open.md"), "# Bug 1: Open Bug\n").unwrap();
|
||||
fs::write(archived_dir.join("2_bug_closed.md"), "# Bug 2: Closed Bug\n").unwrap();
|
||||
|
||||
let result = list_bug_files(tmp.path()).unwrap();
|
||||
assert_eq!(result.len(), 1);
|
||||
assert_eq!(result[0].0, "bug-1-open");
|
||||
assert_eq!(result[0].0, "1_bug_open");
|
||||
assert_eq!(result[0].1, "Open Bug");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_bug_files_sorted_by_id() {
|
||||
let tmp = tempfile::tempdir().unwrap();
|
||||
let bugs_dir = tmp.path().join(".story_kit/bugs");
|
||||
fs::create_dir_all(&bugs_dir).unwrap();
|
||||
fs::write(bugs_dir.join("bug-3-third.md"), "# Bug 3: Third\n").unwrap();
|
||||
fs::write(bugs_dir.join("bug-1-first.md"), "# Bug 1: First\n").unwrap();
|
||||
fs::write(bugs_dir.join("bug-2-second.md"), "# Bug 2: Second\n").unwrap();
|
||||
let upcoming_dir = tmp.path().join(".story_kit/work/1_upcoming");
|
||||
fs::create_dir_all(&upcoming_dir).unwrap();
|
||||
fs::write(upcoming_dir.join("3_bug_third.md"), "# Bug 3: Third\n").unwrap();
|
||||
fs::write(upcoming_dir.join("1_bug_first.md"), "# Bug 1: First\n").unwrap();
|
||||
fs::write(upcoming_dir.join("2_bug_second.md"), "# Bug 2: Second\n").unwrap();
|
||||
|
||||
let result = list_bug_files(tmp.path()).unwrap();
|
||||
assert_eq!(result.len(), 3);
|
||||
assert_eq!(result[0].0, "bug-1-first");
|
||||
assert_eq!(result[1].0, "bug-2-second");
|
||||
assert_eq!(result[2].0, "bug-3-third");
|
||||
assert_eq!(result[0].0, "1_bug_first");
|
||||
assert_eq!(result[1].0, "2_bug_second");
|
||||
assert_eq!(result[2].0, "3_bug_third");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -1751,11 +1751,11 @@ mod tests {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(bug_id, "bug-1-login_crash");
|
||||
assert_eq!(bug_id, "1_bug_login_crash");
|
||||
|
||||
let filepath = tmp
|
||||
.path()
|
||||
.join(".story_kit/bugs/bug-1-login_crash.md");
|
||||
.join(".story_kit/work/1_upcoming/1_bug_login_crash.md");
|
||||
assert!(filepath.exists());
|
||||
let contents = fs::read_to_string(&filepath).unwrap();
|
||||
assert!(contents.contains("# Bug 1: Login Crash"));
|
||||
@@ -1795,7 +1795,7 @@ mod tests {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let filepath = tmp.path().join(".story_kit/bugs/bug-1-some_bug.md");
|
||||
let filepath = tmp.path().join(".story_kit/work/1_upcoming/1_bug_some_bug.md");
|
||||
let contents = fs::read_to_string(&filepath).unwrap();
|
||||
assert!(contents.contains("- [ ] Bug is fixed and verified"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user