@@ -12,7 +12,7 @@ import {
1212import { tmpdir } from "node:os" ;
1313import { dirname , join } from "node:path" ;
1414import { DatabaseSync } from "node:sqlite" ;
15- import { afterEach , describe , expect , it } from "vitest" ;
15+ import { afterEach , describe , expect , it , vi } from "vitest" ;
1616import type { McpServerConfig } from "../config/types.mcp.js" ;
1717import type { OpenClawConfig } from "../config/types.openclaw.js" ;
1818import { closeOpenClawStateDatabaseForTest } from "../state/openclaw-state-db.js" ;
@@ -298,6 +298,51 @@ describe("collectClawStateHealthFindings", () => {
298298 ) . resolves . toEqual ( [ ] ) ;
299299 } ) ;
300300
301+ it ( "does not load MCP config when no Claw owns an MCP server" , async ( ) => {
302+ const current = await installFixture ( { withFile : true } ) ;
303+ await writeFile ( join ( current . plan . agent . workspace , "SOUL.md" ) , "local edit\n" , "utf8" ) ;
304+ const listMcpServers = vi . fn ( async ( ) => {
305+ throw new Error ( "MCP config unavailable" ) ;
306+ } ) ;
307+
308+ await expect (
309+ collectClawStateHealthFindings ( {
310+ env : current . env ,
311+ cfg : current . getConfig ( ) ,
312+ listMcpServers,
313+ } ) ,
314+ ) . resolves . toEqual ( [
315+ expect . objectContaining ( {
316+ message : expect . stringContaining ( "workspace file changed" ) ,
317+ path : "claws.worker.workspace.SOUL.md" ,
318+ } ) ,
319+ ] ) ;
320+ expect ( listMcpServers ) . not . toHaveBeenCalled ( ) ;
321+ } ) ;
322+
323+ it ( "reports MCP config failure when a Claw owns an MCP server" , async ( ) => {
324+ const current = await installFixture ( { withMcp : true } ) ;
325+ const listMcpServers = vi . fn ( async ( ) => ( {
326+ ok : false as const ,
327+ path : "/tmp/openclaw.json" ,
328+ error : "MCP config unavailable" ,
329+ } ) ) ;
330+
331+ await expect (
332+ collectClawStateHealthFindings ( {
333+ env : current . env ,
334+ cfg : current . getConfig ( ) ,
335+ listMcpServers,
336+ } ) ,
337+ ) . resolves . toEqual ( [
338+ expect . objectContaining ( {
339+ severity : "error" ,
340+ message : expect . stringContaining ( "MCP config unavailable" ) ,
341+ } ) ,
342+ ] ) ;
343+ expect ( listMcpServers ) . toHaveBeenCalledOnce ( ) ;
344+ } ) ;
345+
301346 it ( "uses source MCP placeholders instead of resolved secret values" , async ( ) => {
302347 const current = await installFixture ( { withMcp : true } ) ;
303348 const sourceMcpServers = structuredClone ( current . getConfig ( ) . mcp ?. servers ?? { } ) ;
0 commit comments