The great storkit name conversion
This commit is contained in:
+38
-39
@@ -1,5 +1,5 @@
|
||||
use crate::slog;
|
||||
use crate::config::ProjectConfig;
|
||||
use crate::slog;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
|
||||
@@ -7,7 +7,7 @@ use std::process::Command;
|
||||
/// at the given port.
|
||||
pub fn write_mcp_json(dir: &Path, port: u16) -> Result<(), String> {
|
||||
let content = format!(
|
||||
"{{\n \"mcpServers\": {{\n \"story-kit\": {{\n \"type\": \"http\",\n \"url\": \"http://localhost:{port}/mcp\"\n }}\n }}\n}}\n"
|
||||
"{{\n \"mcpServers\": {{\n \"storkit\": {{\n \"type\": \"http\",\n \"url\": \"http://localhost:{port}/mcp\"\n }}\n }}\n}}\n"
|
||||
);
|
||||
std::fs::write(dir.join(".mcp.json"), content).map_err(|e| format!("Write .mcp.json: {e}"))
|
||||
}
|
||||
@@ -104,15 +104,10 @@ pub async fn create_worktree(
|
||||
})
|
||||
}
|
||||
|
||||
fn create_worktree_sync(
|
||||
project_root: &Path,
|
||||
wt_path: &Path,
|
||||
branch: &str,
|
||||
) -> Result<(), String> {
|
||||
fn create_worktree_sync(project_root: &Path, wt_path: &Path, branch: &str) -> Result<(), String> {
|
||||
// Ensure the parent directory exists
|
||||
if let Some(parent) = wt_path.parent() {
|
||||
std::fs::create_dir_all(parent)
|
||||
.map_err(|e| format!("Create worktree dir: {e}"))?;
|
||||
std::fs::create_dir_all(parent).map_err(|e| format!("Create worktree dir: {e}"))?;
|
||||
}
|
||||
|
||||
// Prune stale worktree references (e.g. directories deleted externally)
|
||||
@@ -129,12 +124,7 @@ fn create_worktree_sync(
|
||||
|
||||
// Create worktree
|
||||
let output = Command::new("git")
|
||||
.args([
|
||||
"worktree",
|
||||
"add",
|
||||
&wt_path.to_string_lossy(),
|
||||
branch,
|
||||
])
|
||||
.args(["worktree", "add", &wt_path.to_string_lossy(), branch])
|
||||
.current_dir(project_root)
|
||||
.output()
|
||||
.map_err(|e| format!("git worktree add: {e}"))?;
|
||||
@@ -238,9 +228,7 @@ pub fn list_worktrees(project_root: &Path) -> Result<Vec<WorktreeListEntry>, Str
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
let mut entries = Vec::new();
|
||||
for entry in
|
||||
std::fs::read_dir(&worktrees_dir).map_err(|e| format!("list worktrees: {e}"))?
|
||||
{
|
||||
for entry in std::fs::read_dir(&worktrees_dir).map_err(|e| format!("list worktrees: {e}"))? {
|
||||
let entry = entry.map_err(|e| format!("list worktrees entry: {e}"))?;
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
@@ -255,19 +243,10 @@ pub fn list_worktrees(project_root: &Path) -> Result<Vec<WorktreeListEntry>, Str
|
||||
Ok(entries)
|
||||
}
|
||||
|
||||
fn remove_worktree_sync(
|
||||
project_root: &Path,
|
||||
wt_path: &Path,
|
||||
branch: &str,
|
||||
) -> Result<(), String> {
|
||||
fn remove_worktree_sync(project_root: &Path, wt_path: &Path, branch: &str) -> Result<(), String> {
|
||||
// Remove worktree
|
||||
let output = Command::new("git")
|
||||
.args([
|
||||
"worktree",
|
||||
"remove",
|
||||
"--force",
|
||||
&wt_path.to_string_lossy(),
|
||||
])
|
||||
.args(["worktree", "remove", "--force", &wt_path.to_string_lossy()])
|
||||
.current_dir(project_root)
|
||||
.output()
|
||||
.map_err(|e| format!("git worktree remove: {e}"))?;
|
||||
@@ -645,7 +624,10 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
let mcp = fs::read_to_string(info2.path.join(".mcp.json")).unwrap();
|
||||
assert!(mcp.contains("3002"), "MCP json should be updated to new port");
|
||||
assert!(
|
||||
mcp.contains("3002"),
|
||||
"MCP json should be updated to new port"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -708,9 +690,12 @@ mod tests {
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let result =
|
||||
remove_worktree_by_story_id(&project_root, "88_remove_by_id", &config).await;
|
||||
assert!(result.is_ok(), "Expected removal to succeed: {:?}", result.err());
|
||||
let result = remove_worktree_by_story_id(&project_root, "88_remove_by_id", &config).await;
|
||||
assert!(
|
||||
result.is_ok(),
|
||||
"Expected removal to succeed: {:?}",
|
||||
result.err()
|
||||
);
|
||||
}
|
||||
|
||||
// ── prune_worktree_sync ──────────────────────────────────────────────────
|
||||
@@ -720,7 +705,11 @@ mod tests {
|
||||
let tmp = TempDir::new().unwrap();
|
||||
// No worktree directory exists — must return Ok without touching git.
|
||||
let result = prune_worktree_sync(tmp.path(), "42_story_nonexistent");
|
||||
assert!(result.is_ok(), "Expected Ok when worktree dir absent: {:?}", result.err());
|
||||
assert!(
|
||||
result.is_ok(),
|
||||
"Expected Ok when worktree dir absent: {:?}",
|
||||
result.err()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -732,11 +721,20 @@ mod tests {
|
||||
|
||||
let story_id = "55_story_prune_test";
|
||||
let wt_path = worktree_path(&project_root, story_id);
|
||||
create_worktree_sync(&project_root, &wt_path, &format!("feature/story-{story_id}")).unwrap();
|
||||
create_worktree_sync(
|
||||
&project_root,
|
||||
&wt_path,
|
||||
&format!("feature/story-{story_id}"),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(wt_path.exists(), "worktree dir should exist before prune");
|
||||
|
||||
let result = prune_worktree_sync(&project_root, story_id);
|
||||
assert!(result.is_ok(), "prune_worktree_sync must return Ok: {:?}", result.err());
|
||||
assert!(
|
||||
result.is_ok(),
|
||||
"prune_worktree_sync must return Ok: {:?}",
|
||||
result.err()
|
||||
);
|
||||
assert!(!wt_path.exists(), "worktree dir should be gone after prune");
|
||||
}
|
||||
|
||||
@@ -810,8 +808,7 @@ mod tests {
|
||||
max_retries: 2,
|
||||
};
|
||||
// Second call — worktree exists, setup commands fail, must still succeed
|
||||
let result =
|
||||
create_worktree(&project_root, "173_reuse_fail", &failing_config, 3002).await;
|
||||
let result = create_worktree(&project_root, "173_reuse_fail", &failing_config, 3002).await;
|
||||
assert!(
|
||||
result.is_ok(),
|
||||
"create_worktree reuse must succeed even if setup commands fail: {:?}",
|
||||
@@ -841,7 +838,9 @@ mod tests {
|
||||
|
||||
let path = info.path.clone();
|
||||
assert!(path.exists());
|
||||
remove_worktree(&project_root, &info, &config).await.unwrap();
|
||||
remove_worktree(&project_root, &info, &config)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(!path.exists());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user