storkit: merge 444_refactor_extract_shared_test_helpers_test_ctx_write_story_file_make_api

This commit is contained in:
dave
2026-03-28 19:47:59 +00:00
parent d216f3c267
commit ddc4a57cd2
27 changed files with 188 additions and 187 deletions
+2
View File
@@ -5,3 +5,5 @@ pub mod shell;
pub mod story_metadata;
pub mod watcher;
pub mod wizard;
#[cfg(test)]
pub(crate) mod test_helpers;
+1 -8
View File
@@ -74,17 +74,10 @@ fn needs_project_toml(story_kit: &Path) -> bool {
#[cfg(test)]
mod tests {
use super::*;
use crate::io::test_helpers::setup_project;
use std::fs;
use tempfile::TempDir;
fn setup_project(dir: &TempDir) -> std::path::PathBuf {
let root = dir.path().to_path_buf();
let sk = root.join(".storkit");
fs::create_dir_all(sk.join("specs").join("tech")).unwrap();
fs::create_dir_all(root.join("script")).unwrap();
root
}
// ── needs_onboarding ──────────────────────────────────────────
#[test]
+2 -8
View File
@@ -64,18 +64,12 @@ pub async fn search_files_impl(query: String, root: PathBuf) -> Result<Vec<Searc
#[cfg(test)]
mod tests {
use super::*;
use std::fs;
use crate::io::test_helpers::create_test_files;
use tempfile::TempDir;
fn setup_project(files: &[(&str, &str)]) -> TempDir {
let dir = TempDir::new().unwrap();
for (path, content) in files {
let full = dir.path().join(path);
if let Some(parent) = full.parent() {
fs::create_dir_all(parent).unwrap();
}
fs::write(full, content).unwrap();
}
create_test_files(&dir, files);
dir
}
+32
View File
@@ -0,0 +1,32 @@
//! Shared test utilities for I/O module tests.
//!
//! Import with `use crate::io::test_helpers::{create_test_files, setup_project};`
use std::fs;
use std::path::PathBuf;
use tempfile::TempDir;
/// Create a minimal storkit project directory structure under `dir`.
///
/// Creates `.storkit/specs/tech/` and `script/`, then returns the root path.
/// Used by onboarding and wizard tests.
pub(crate) fn setup_project(dir: &TempDir) -> PathBuf {
let root = dir.path().to_path_buf();
let sk = root.join(".storkit");
fs::create_dir_all(sk.join("specs").join("tech")).unwrap();
fs::create_dir_all(root.join("script")).unwrap();
root
}
/// Write a set of files into `dir` at the given relative paths.
///
/// Parent directories are created automatically. Used by search tests.
pub(crate) fn create_test_files(dir: &TempDir, files: &[(&str, &str)]) {
for (path, content) in files {
let full = dir.path().join(path);
if let Some(parent) = full.parent() {
fs::create_dir_all(parent).unwrap();
}
fs::write(full, content).unwrap();
}
}
+1 -7
View File
@@ -255,15 +255,9 @@ pub fn format_wizard_state(state: &WizardState) -> String {
#[cfg(test)]
mod tests {
use super::*;
use crate::io::test_helpers::setup_project;
use tempfile::TempDir;
fn setup_project(dir: &TempDir) -> std::path::PathBuf {
let root = dir.path().to_path_buf();
let sk = root.join(".storkit");
std::fs::create_dir_all(&sk).unwrap();
root
}
#[test]
fn default_state_has_all_steps_pending() {
let state = WizardState::default();