Files
openclaw/src/cli/attach-cli.test.ts
anagnorisis2peripeteia 6df7db9f9e feat(cli): add attach launcher (#96454)
* feat(cli): openclaw attach — launch Claude Code bound to a gateway session with scoped MCP tools
* fix(cli): use token-only MCP config for attach

---------

Co-authored-by: Ayaan Zaidi <hi@obviy.us>
2026-07-01 15:52:39 -07:00

35 lines
1014 B
TypeScript

import { readFileSync } from "node:fs";
import { describe, expect, it } from "vitest";
import { writeClaudeMcpConfig } from "./attach-cli.js";
const MCP_CONFIG = {
mcpServers: {
openclaw: {
type: "http",
url: "http://127.0.0.1:54321/mcp",
headers: {
Authorization: "Bearer ${OPENCLAW_MCP_TOKEN}",
"x-session-key": "${OPENCLAW_MCP_SESSION_KEY}",
},
},
},
};
describe("writeClaudeMcpConfig", () => {
it("writes the gateway mcpConfig verbatim to a .mcp.json (placeholders preserved for Claude env substitution)", () => {
const { path, cleanup } = writeClaudeMcpConfig(MCP_CONFIG);
try {
expect(path.endsWith(".mcp.json")).toBe(true);
expect(JSON.parse(readFileSync(path, "utf8"))).toEqual(MCP_CONFIG);
} finally {
cleanup();
}
});
it("cleanup removes the temp config", () => {
const { path, cleanup } = writeClaudeMcpConfig(MCP_CONFIG);
cleanup();
expect(() => readFileSync(path, "utf8")).toThrow();
});
});