From 901f7a65d30043ced50f5092481919632c6f6941 Mon Sep 17 00:00:00 2001 From: Dave Date: Tue, 17 Mar 2026 18:09:28 +0000 Subject: [PATCH] story-kit: merge 270_bug_qa_test_server_overwrites_root_mcp_json_with_wrong_port --- server/src/agents/pool.rs | 5 ----- server/src/http/project.rs | 1 - server/src/io/fs.rs | 23 +++++++---------------- server/src/main.rs | 2 -- 4 files changed, 7 insertions(+), 24 deletions(-) diff --git a/server/src/agents/pool.rs b/server/src/agents/pool.rs index b2cc192..60e0e82 100644 --- a/server/src/agents/pool.rs +++ b/server/src/agents/pool.rs @@ -1293,11 +1293,6 @@ impl AgentPool { .and_then(|jobs| jobs.get(story_id).cloned()) } - /// Return the port this server is running on. - pub fn port(&self) -> u16 { - self.port - } - /// Get project root helper. pub fn get_project_root( &self, diff --git a/server/src/http/project.rs b/server/src/http/project.rs index 37a48ab..ac07b18 100644 --- a/server/src/http/project.rs +++ b/server/src/http/project.rs @@ -39,7 +39,6 @@ impl ProjectApi { payload.0.path, &self.ctx.state, self.ctx.store.as_ref(), - self.ctx.agents.port(), ) .await .map_err(bad_request)?; diff --git a/server/src/io/fs.rs b/server/src/io/fs.rs index c214b9a..e49c4a9 100644 --- a/server/src/io/fs.rs +++ b/server/src/io/fs.rs @@ -1,6 +1,5 @@ use crate::state::SessionState; use crate::store::StoreOps; -use crate::worktree::write_mcp_json as worktree_write_mcp_json; use serde::Serialize; use serde_json::json; use std::fs; @@ -515,17 +514,12 @@ pub async fn open_project( path: String, state: &SessionState, store: &dyn StoreOps, - port: u16, ) -> Result { let p = PathBuf::from(&path); ensure_project_root_with_story_kit(p.clone()).await?; validate_project_path(p.clone()).await?; - // Write .mcp.json so that claude-code can connect to the MCP server. - // Best-effort: failure should not prevent the project from opening. - let _ = worktree_write_mcp_json(&p, port); - { // TRACE:MERGE-DEBUG — remove once root cause is found crate::slog!("[MERGE-DEBUG] open_project: setting project_root to {:?}", p); @@ -813,7 +807,6 @@ mod tests { project_dir.to_string_lossy().to_string(), &state, &store, - 3001, ) .await; @@ -823,7 +816,11 @@ mod tests { } #[tokio::test] - async fn open_project_writes_mcp_json_to_project_root() { + async fn open_project_does_not_write_mcp_json() { + // open_project must NOT overwrite .mcp.json — test servers started by QA + // agents share the real project root, so writing here would clobber the + // root .mcp.json with the wrong port. .mcp.json is written once during + // worktree creation (worktree.rs) and should not be touched again. let dir = tempdir().unwrap(); let project_dir = dir.path().join("myproject"); fs::create_dir_all(&project_dir).unwrap(); @@ -834,17 +831,14 @@ mod tests { project_dir.to_string_lossy().to_string(), &state, &store, - 4242, ) .await .unwrap(); let mcp_path = project_dir.join(".mcp.json"); - assert!(mcp_path.exists(), ".mcp.json should be written to project root"); - let content = fs::read_to_string(&mcp_path).unwrap(); assert!( - content.contains("http://localhost:4242/mcp"), - ".mcp.json should contain the correct port" + !mcp_path.exists(), + "open_project must not write .mcp.json — that would overwrite the root with the wrong port" ); } @@ -904,7 +898,6 @@ mod tests { project_dir.to_string_lossy().to_string(), &state, &store, - 3001, ) .await .unwrap(); @@ -1365,7 +1358,6 @@ mod tests { project_dir.to_string_lossy().to_string(), &state, &store, - 0, ) .await .unwrap(); @@ -1389,7 +1381,6 @@ mod tests { project_dir.to_string_lossy().to_string(), &state, &store, - 0, ) .await .unwrap(); diff --git a/server/src/main.rs b/server/src/main.rs index a412399..de026bf 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -58,7 +58,6 @@ async fn main() -> Result<(), std::io::Error> { explicit_root.to_string_lossy().to_string(), &app_state, store.as_ref(), - port, ) .await { @@ -81,7 +80,6 @@ async fn main() -> Result<(), std::io::Error> { project_root.to_string_lossy().to_string(), &app_state, store.as_ref(), - port, ) .await .unwrap_or_else(|e| {