test: dedupe mcp cli mock reads

This commit is contained in:
Peter Steinberger
2026-05-13 03:25:53 +01:00
parent 91bae4baa5
commit d1ddb68d37

View File

@@ -51,7 +51,16 @@ async function runMcpCommand(args: string[]) {
}
function lastLogLine(): string {
return String(mockLog.mock.calls.at(-1)?.[0] ?? "");
return lastRuntimeLine(mockLog);
}
function lastErrorLine(): string {
return lastRuntimeLine(mockError);
}
function lastRuntimeLine(mock: typeof mockLog): string {
const call = mock.mock.calls[mock.mock.calls.length - 1];
return String(call?.[0] ?? "");
}
describe("mcp cli", () => {
@@ -94,8 +103,7 @@ describe("mcp cli", () => {
vi.spyOn(process, "cwd").mockReturnValue(workspaceDir);
await expect(runMcpCommand(["mcp", "unset", "missing"])).rejects.toThrow("__exit__:1");
const errorLine = String(mockError.mock.calls.at(-1)?.[0] ?? "");
expect(errorLine).toBe(
expect(lastErrorLine()).toBe(
`No MCP server named "missing" in ${configPath}. Run openclaw mcp list to see configured servers.`,
);
});