tools/release.sh builds -p lucisv_mcp for the host and every cross triple, stages lucisv-mcp[.exe] beside the two binaries (three per platform package, fifteen in the all-platforms one; the universal package still carries none), smoke-tests it (editors/vscode/mcp_smoke.js: initialize, tools/list ≥ 26, project_overview) loose and unzipped from the host and all-platforms packages; tools/audit_artifacts.sh audits the third name and rejects any other; prune_release_assets.sh unchanged (seven vsix names). editors/vscode/mcp.js: the three-rung binary ladder (lucisv.mcp.path → bundled → PATH), one McpStdioServerDefinition per workspace folder — the constructor is POSITIONAL (label, command, args, env, version) with cwd set afterwards; the plan's object form was wrong and is corrected — with `--root <folder> --index-cache <storage>`, refreshed on folder and setting changes, guarded so VS Code < 1.101 registers nothing but the command; a missing binary refused at resolve time with one output-channel line; the `lucisv.mcp.copyConfig` command puts the Claude Code / Cursor / VS Code snippet on the clipboard. package.json: contributes.mcpServerDefinitionProviders, lucisv.mcp.enabled/path, the command; engine stays ^1.82.0 (vsce 4 accepts). ci.yml runs node --test over the extension's unit tests. Docs: docs/site guides/agents.md with the tool table generated from the binary (site rebuilt), README paragraph, RELEASING.md, extension README/CHANGELOG (Unreleased), manual-acceptance rows 18–25 for the live-VS Code checks. QA (Opus): API signature confirmed against VS Code 1.138's vscode.d.ts; 8 mutation checks caught by mcp_test.js; release.sh run end to end, vsix contents listed (three binaries, mcp.js, no test files), SHA256SUMS verified, the embedded binary smoke-tested, the vsix installed into an isolated profile. Gates: node --test 6/6, fmt clean. Co-Authored-By: Claude Fable 5.1 <[email protected]>
160 lines
6.3 KiB
JavaScript
160 lines
6.3 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 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 fewest tools a build of this block may advertise (TODO-MCP M1–M4). */
|
||
const MIN_TOOLS = 26;
|
||
|
||
/** 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: 'project_overview', 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) || [];
|
||
if (tools.length < MIN_TOOLS) fail(`tools/list has ${tools.length} tools, expected at least ${MIN_TOOLS}`);
|
||
const overview = byId.get(3);
|
||
if (!overview) fail('no project_overview answer');
|
||
if (overview.isError) fail(`project_overview is an error: ${JSON.stringify(overview.content)}`);
|
||
const text = (overview.content || []).map((part) => part.text || '').join('');
|
||
if (text.trim() === '') fail('project_overview answered no text');
|
||
if (!text.includes('top')) fail(`project_overview 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, project_overview`,
|
||
);
|
||
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;
|
||
});
|