The great storkit name conversion

This commit is contained in:
Dave
2026-03-20 12:26:02 +00:00
parent 51d878e117
commit c4e45b2841
25 changed files with 1522 additions and 1333 deletions

View File

@@ -5,7 +5,7 @@ use std::path::Path;
use super::{find_story_file, replace_or_append_section};
const TEST_RESULTS_MARKER: &str = "<!-- story-kit-test-results:";
const TEST_RESULTS_MARKER: &str = "<!-- storkit-test-results:";
/// Write (or overwrite) the `## Test Results` section in a story file.
///
@@ -27,8 +27,7 @@ pub fn write_test_results_to_story_file(
let section = build_test_results_section(&json, results);
let new_contents = replace_or_append_section(&contents, "## Test Results", &section);
fs::write(&path, &new_contents)
.map_err(|e| format!("Failed to write story file: {e}"))?;
fs::write(&path, &new_contents).map_err(|e| format!("Failed to write story file: {e}"))?;
Ok(())
}
@@ -95,12 +94,19 @@ fn build_test_results_section(json: &str, results: &StoryTestResults) -> String
}
fn count_pass_fail(tests: &[TestCaseResult]) -> (usize, usize) {
let pass = tests.iter().filter(|t| t.status == TestStatus::Pass).count();
let pass = tests
.iter()
.filter(|t| t.status == TestStatus::Pass)
.count();
(pass, tests.len() - pass)
}
fn format_test_line(t: &TestCaseResult) -> String {
let icon = if t.status == TestStatus::Pass { "" } else { "" };
let icon = if t.status == TestStatus::Pass {
""
} else {
""
};
match &t.details {
Some(d) if !d.is_empty() => format!("- {icon} {}{d}\n", t.name),
_ => format!("- {icon} {}\n", t.name),
@@ -132,12 +138,22 @@ mod tests {
fn make_results() -> StoryTestResults {
StoryTestResults {
unit: vec![
TestCaseResult { name: "unit-pass".to_string(), status: TestStatus::Pass, details: None },
TestCaseResult { name: "unit-fail".to_string(), status: TestStatus::Fail, details: Some("assertion failed".to_string()) },
],
integration: vec![
TestCaseResult { name: "int-pass".to_string(), status: TestStatus::Pass, details: None },
TestCaseResult {
name: "unit-pass".to_string(),
status: TestStatus::Pass,
details: None,
},
TestCaseResult {
name: "unit-fail".to_string(),
status: TestStatus::Fail,
details: Some("assertion failed".to_string()),
},
],
integration: vec![TestCaseResult {
name: "int-pass".to_string(),
status: TestStatus::Pass,
details: None,
}],
}
}
@@ -146,7 +162,11 @@ mod tests {
let tmp = tempfile::tempdir().unwrap();
let current = tmp.path().join(".storkit/work/2_current");
fs::create_dir_all(&current).unwrap();
fs::write(current.join("1_story_test.md"), "---\nname: Test\n---\n# Story\n").unwrap();
fs::write(
current.join("1_story_test.md"),
"---\nname: Test\n---\n# Story\n",
)
.unwrap();
let results = make_results();
write_test_results_to_story_file(tmp.path(), "1_story_test", &results).unwrap();
@@ -157,7 +177,10 @@ mod tests {
assert_eq!(read_back.integration.len(), 1);
assert_eq!(read_back.unit[0].name, "unit-pass");
assert_eq!(read_back.unit[1].status, TestStatus::Fail);
assert_eq!(read_back.unit[1].details.as_deref(), Some("assertion failed"));
assert_eq!(
read_back.unit[1].details.as_deref(),
Some("assertion failed")
);
}
#[test]
@@ -166,7 +189,11 @@ mod tests {
let current = tmp.path().join(".storkit/work/2_current");
fs::create_dir_all(&current).unwrap();
let story_path = current.join("2_story_check.md");
fs::write(&story_path, "---\nname: Check\n---\n# Story\n\n## Acceptance Criteria\n\n- [ ] AC1\n").unwrap();
fs::write(
&story_path,
"---\nname: Check\n---\n# Story\n\n## Acceptance Criteria\n\n- [ ] AC1\n",
)
.unwrap();
let results = make_results();
write_test_results_to_story_file(tmp.path(), "2_story_check", &results).unwrap();
@@ -176,7 +203,7 @@ mod tests {
assert!(contents.contains("✅ unit-pass"));
assert!(contents.contains("❌ unit-fail"));
assert!(contents.contains("assertion failed"));
assert!(contents.contains("story-kit-test-results:"));
assert!(contents.contains("storkit-test-results:"));
// Original content still present
assert!(contents.contains("## Acceptance Criteria"));
}
@@ -189,7 +216,7 @@ mod tests {
let story_path = current.join("3_story_overwrite.md");
fs::write(
&story_path,
"---\nname: Overwrite\n---\n# Story\n\n## Test Results\n\n<!-- story-kit-test-results: {} -->\n\n### Unit Tests (0 passed, 0 failed)\n\n*No unit tests recorded.*\n",
"---\nname: Overwrite\n---\n# Story\n\n## Test Results\n\n<!-- storkit-test-results: {} -->\n\n### Unit Tests (0 passed, 0 failed)\n\n*No unit tests recorded.*\n",
)
.unwrap();
@@ -208,7 +235,11 @@ mod tests {
let tmp = tempfile::tempdir().unwrap();
let current = tmp.path().join(".storkit/work/2_current");
fs::create_dir_all(&current).unwrap();
fs::write(current.join("4_story_empty.md"), "---\nname: Empty\n---\n# Story\n").unwrap();
fs::write(
current.join("4_story_empty.md"),
"---\nname: Empty\n---\n# Story\n",
)
.unwrap();
let result = read_test_results_from_story_file(tmp.path(), "4_story_empty");
assert!(result.is_none());
@@ -226,10 +257,18 @@ mod tests {
let tmp = tempfile::tempdir().unwrap();
let qa_dir = tmp.path().join(".storkit/work/3_qa");
fs::create_dir_all(&qa_dir).unwrap();
fs::write(qa_dir.join("5_story_qa.md"), "---\nname: QA Story\n---\n# Story\n").unwrap();
fs::write(
qa_dir.join("5_story_qa.md"),
"---\nname: QA Story\n---\n# Story\n",
)
.unwrap();
let results = StoryTestResults {
unit: vec![TestCaseResult { name: "u1".to_string(), status: TestStatus::Pass, details: None }],
unit: vec![TestCaseResult {
name: "u1".to_string(),
status: TestStatus::Pass,
details: None,
}],
integration: vec![],
};
write_test_results_to_story_file(tmp.path(), "5_story_qa", &results).unwrap();
@@ -243,12 +282,19 @@ mod tests {
let tmp = tempfile::tempdir().unwrap();
let current = tmp.path().join(".storkit/work/2_current");
fs::create_dir_all(&current).unwrap();
fs::write(current.join("6_story_cov.md"), "---\nname: Cov Story\n---\n# Story\n").unwrap();
fs::write(
current.join("6_story_cov.md"),
"---\nname: Cov Story\n---\n# Story\n",
)
.unwrap();
write_coverage_baseline_to_story_file(tmp.path(), "6_story_cov", 75.4).unwrap();
let contents = fs::read_to_string(current.join("6_story_cov.md")).unwrap();
assert!(contents.contains("coverage_baseline: 75.4%"), "got: {contents}");
assert!(
contents.contains("coverage_baseline: 75.4%"),
"got: {contents}"
);
}
#[test]