Files
lucisv/editors/vscode/mcp_smoke.js
T
lucioandClaude Fable 5.1 bfa8e98eb5
ci / checks (push) Successful in 1m43s
ci / corpus (push) Successful in 36s
MCP M7: the lean catalogue — nine tools, 3 440 model-visible bytes, no dry_run/paging, short answers
hierarchy (file:line per instance, peek), find (every declaration by
name, refs + unresolved mentions), outline, read, check, rename, port,
edit_item, format. Name lookup reaches every declaration the symbol
tables hold (tools/declared.rs); rename of a generate-block label is
refused (engine gap filed as topo §2.9 MCP-14). Text-only results,
engine sentences made root-relative. Tests ported or deleted per the
README; QA lane in tests/qa_m7.rs. Docs, smoke gate, release notes
(0.58.0 unreleased) updated.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-09-24 01:40:53 -07:00

162 lines
6.5 KiB
JavaScript

// Pre-release smoke test for `lucisv-mcp`: spawn it the way the extension's
// provider does (`--root <folder> --index-cache <dir>`, the folder as cwd) over
// a tiny temporary project and drive one MCP session at it over stdio —
// initialize, notifications/initialized, tools/list, one `hierarchy` without a
// root (the project overview).
// Plain node, no dependencies, hand-rolled newline-delimited JSON-RPC, like
// `smoke.js` does for the language server.
//
// node mcp_smoke.js [path-to-lucisv-mcp] [--tool-table]
//
// `--tool-table` also prints the tools as the Markdown table checked into
// docs/site/src/content/docs/guides/agents.md, so that page is regenerated
// from the binary rather than typed. Exits 0 on success, 1 on any failure.
const { spawn } = require('child_process');
const fs = require('fs');
const os = require('os');
const path = require('path');
const args = process.argv.slice(2);
const toolTable = args.includes('--tool-table');
const named = args.find((arg) => arg !== '--tool-table') || 'lucisv-mcp';
// Resolved now: the server runs with the temporary project as its cwd, where a
// relative path would no longer point at the binary. A bare name stays a PATH lookup.
const binary = /[\\/]/.test(named) ? path.resolve(named) : named;
/** The lean catalogue, in order (PLAN §10.1, TODO-MCP M7). */
const TOOLS = ['hierarchy', 'find', 'outline', 'read', 'check', 'rename', 'port', 'edit_item', 'format'];
/** Give up on a server that has not answered and exited by then. */
const TIMEOUT_MS = 30000;
/** Thrown, not exited on, so the temporary project is always removed. */
function fail(message) {
throw new Error(message);
}
/** Two files, one instantiating the other: enough for a non-trivial overview. */
function makeProject() {
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'lucisv-mcp-smoke-'));
fs.writeFileSync(
path.join(root, 'top.sv'),
'module top (input logic clk);\n sub u_sub (.clk(clk));\nendmodule\n',
);
fs.writeFileSync(path.join(root, 'sub.sv'), 'module sub (input logic clk);\nendmodule\n');
fs.mkdirSync(path.join(root, '.cache'));
return root;
}
const REQUESTS = [
{
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: {
protocolVersion: '2025-06-18',
capabilities: {},
clientInfo: { name: 'lucisv-mcp-smoke', version: '0' },
},
},
{ jsonrpc: '2.0', method: 'notifications/initialized' },
{ jsonrpc: '2.0', id: 2, method: 'tools/list' },
{ jsonrpc: '2.0', id: 3, method: 'tools/call', params: { name: 'hierarchy', arguments: {} } },
];
/** Every request is written up front and stdin closed: the server answers in order and exits on EOF. */
function session(root) {
return new Promise((resolve, reject) => {
const server = spawn(binary, ['--root', root, '--index-cache', path.join(root, '.cache')], {
cwd: root,
stdio: 'pipe',
});
const timer = setTimeout(() => {
server.kill();
reject(new Error(`no answer from "${binary}" within ${TIMEOUT_MS / 1000} s`));
}, TIMEOUT_MS);
const chunks = [];
server.on('error', (error) => {
clearTimeout(timer);
reject(new Error(`could not spawn "${binary}": ${error.message}`));
});
// A server that died before reading everything must not crash this script.
server.stdin.on('error', () => {});
server.stdout.on('data', (chunk) => chunks.push(chunk));
server.stderr.on('data', (chunk) => process.stderr.write(chunk));
server.on('close', (code) => {
clearTimeout(timer);
resolve({ code, stdout: Buffer.concat(chunks).toString('utf8') });
});
server.stdin.end(REQUESTS.map((request) => `${JSON.stringify(request)}\n`).join(''));
});
}
/** Parse stdout, which must be JSON-RPC lines and nothing else. */
function answers(stdout) {
const byId = new Map();
for (const line of stdout.split('\n').filter((l) => l.trim() !== '')) {
let message;
try {
message = JSON.parse(line);
} catch {
fail(`stdout carried a line that is not JSON: ${line.slice(0, 200)}`);
}
if (message.error) fail(`request ${message.id} failed: ${JSON.stringify(message.error)}`);
byId.set(message.id, message.result);
}
return byId;
}
function check(byId) {
const init = byId.get(1);
if (!init) fail('no initialize answer');
if (!init.serverInfo || init.serverInfo.name !== 'lucisv-mcp') {
fail(`serverInfo.name is not lucisv-mcp: ${JSON.stringify(init.serverInfo)}`);
}
const listed = byId.get(2);
const tools = (listed && listed.tools) || [];
const names = tools.map((tool) => tool.name).join(', ');
if (names !== TOOLS.join(', ')) fail(`tools/list is [${names}], expected [${TOOLS.join(', ')}]`);
const overview = byId.get(3);
if (!overview) fail('no hierarchy answer');
if (overview.isError) fail(`hierarchy is an error: ${JSON.stringify(overview.content)}`);
const text = (overview.content || []).map((part) => part.text || '').join('');
if (text.trim() === '') fail('hierarchy answered no text');
if (!text.includes('top top.sv:1')) fail(`hierarchy does not name the top module:\n${text}`);
return { init, tools };
}
/** One row per tool: name, whether it writes, and the description's first sentence. */
function markdownTable(tools) {
const firstSentence = (text) => text.split(/(?<!e\.g\.)(?<=\.)\s+(?=[A-Z`])/)[0];
// A lone literal backtick (`define) would open a code span that swallows
// the row: with an odd count, the first one is escaped.
const balanced = (text) => ((text.match(/`/g) || []).length % 2 ? text.replace('`', '\\`') : text);
const cell = (text) => balanced(text).replace(/\|/g, '\\|');
const rows = tools.map((tool) => {
const writes = tool.annotations && tool.annotations.readOnlyHint === false ? 'yes' : '';
return `| \`${tool.name}\` | ${writes} | ${cell(firstSentence(tool.description))} |`;
});
return ['| tool | writes | what it answers |', '|---|---|---|', ...rows].join('\n');
}
async function main() {
const root = makeProject();
try {
const { code, stdout } = await session(root);
const { init, tools } = check(answers(stdout));
if (code !== 0) fail(`the server exited with status ${code} after stdin closed`);
console.log(
`mcp smoke: OK — "${binary}" ${init.serverInfo.version}: initialize, ${tools.length} tools, hierarchy`,
);
if (toolTable) console.log(markdownTable(tools));
} finally {
fs.rmSync(root, { recursive: true, force: true });
}
}
main().catch((error) => {
console.error(`mcp smoke: FAIL — ${error.message}`);
process.exitCode = 1;
});