@@ -2551,6 +2551,53 @@ TEST(tool_trace_call_path_not_found) {
25512551 PASS ();
25522552}
25532553
2554+ /* Regression for #1425: a project name that fails validation must produce a
2555+ * clean "not found" error and NOTHING else. project_db_path() yields "" for
2556+ * such names; SQLite opens "" as an anonymous temp db, its integrity check
2557+ * fails, and quarantine rendered "".corrupt.<hex> - a RELATIVE path dropped
2558+ * into the daemon's cwd on every such query. */
2559+ TEST (tool_call_invalid_project_name_leaves_no_corrupt_litter_issue1425 ) {
2560+ char tmpdir [256 ];
2561+ snprintf (tmpdir , sizeof (tmpdir ), "/tmp/mcp-litter-XXXXXX" );
2562+ if (!cbm_mkdtemp (tmpdir ))
2563+ FAIL ("cbm_mkdtemp failed" );
2564+ char oldcwd [CBM_SZ_1K ];
2565+ if (!cbm_getcwd (oldcwd , sizeof (oldcwd )))
2566+ FAIL ("getcwd failed" );
2567+ if (cbm_chdir (tmpdir ) != 0 )
2568+ FAIL ("chdir failed" );
2569+
2570+ cbm_mcp_server_t * srv = cbm_mcp_server_new (NULL );
2571+ char * resp =
2572+ cbm_mcp_server_handle (srv , "{\"jsonrpc\":\"2.0\",\"id\":30,\"method\":\"tools/call\","
2573+ "\"params\":{\"name\":\"search_graph\","
2574+ "\"arguments\":{\"name_pattern\":\"x\","
2575+ "\"project\":\"bad name\"}}}" );
2576+ bool clean_error = resp && strstr (resp , "not found" ) != NULL ;
2577+ free (resp );
2578+ cbm_mcp_server_free (srv );
2579+
2580+ int litter = 0 ;
2581+ cbm_dir_t * dir = cbm_opendir (tmpdir );
2582+ if (dir ) {
2583+ cbm_dirent_t * entry ;
2584+ while ((entry = cbm_readdir (dir )) != NULL ) {
2585+ if (strstr (entry -> name , ".corrupt." )) {
2586+ litter ++ ;
2587+ }
2588+ }
2589+ cbm_closedir (dir );
2590+ }
2591+ if (cbm_chdir (oldcwd ) != 0 )
2592+ FAIL ("chdir back failed" );
2593+ th_rmtree (tmpdir );
2594+ if (!clean_error )
2595+ FAIL ("invalid project name must produce a clean not-found error" );
2596+ if (litter != 0 )
2597+ FAIL ("invalid project name must not quarantine an anonymous temp db into cwd (#1425)" );
2598+ PASS ();
2599+ }
2600+
25542601TEST (tool_trace_missing_function_name ) {
25552602 cbm_mcp_server_t * srv = cbm_mcp_server_new (NULL );
25562603
@@ -10352,6 +10399,7 @@ SUITE(mcp) {
1035210399
1035310400 /* Tool handlers with validation */
1035410401 RUN_TEST (tool_trace_call_path_not_found );
10402+ RUN_TEST (tool_call_invalid_project_name_leaves_no_corrupt_litter_issue1425 );
1035510403 RUN_TEST (tool_trace_missing_function_name );
1035610404 RUN_TEST (tool_trace_call_path_ambiguous );
1035710405 RUN_TEST (tool_trace_union_records_min_hop_across_seeds );
0 commit comments