Files
lucioandClaude Fable 5.2 ea586d29bc
ci / checks (push) Successful in 1m54s
ci / corpus (push) Successful in 36s
release / build-and-publish (push) Successful in 7m18s
Release smoke: the ranges probe expects a block laid out at its own indentation (TODO §66.2)
The v0.63.0 release build failed at tools/release.sh's server smoke test:
smoke.js still expected rangesFormatting to re-indent a named line to the
configured depth. Selection formatting keeps a block's written leading
whitespace, so the probe now checks that the named fork is re-laid from
its own two spaces, the named wire stays put and the unnamed block keeps
its bytes. Checked against a local release lucisv-server (smoke: OK).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
2026-11-09 19:50:52 -08:00

410 lines
20 KiB
JavaScript

// Pre-publish smoke test: spawn the server exactly the way extension.js does
// and drive a whole LSP session at it over stdio. Plain node, no dependencies,
// hand-rolled framing — a check that reused a client library could not catch a
// framing or startup bug. Mirrors crates/lucisv_server/tests/e2e.rs.
//
// node smoke.js [path-to-lucisv-server] # default: `lucisv-server` on PATH
//
// Exits 0 on success, 1 on any failure.
const { spawn } = require('child_process');
const serverPath = process.argv[2] || 'lucisv-server';
/** Frame one JSON payload the way LSP wants it. */
function frame(payload) {
const body = Buffer.from(JSON.stringify(payload), 'utf8');
return Buffer.concat([Buffer.from(`Content-Length: ${body.length}\r\n\r\n`, 'ascii'), body]);
}
/** Split a stdout dump into its JSON payloads. */
function unframe(buffer) {
const messages = [];
let at = 0;
while (at < buffer.length) {
const headerEnd = buffer.indexOf('\r\n\r\n', at, 'ascii');
if (headerEnd < 0) break;
const headers = buffer.toString('ascii', at, headerEnd);
const match = /Content-Length: *(\d+)/i.exec(headers);
if (!match) break;
const start = headerEnd + 4;
const end = start + Number(match[1]);
if (end > buffer.length) break;
messages.push(JSON.parse(buffer.toString('utf8', start, end)));
at = end;
}
return messages;
}
function fail(message) {
console.error(`smoke: FAIL — ${message}`);
process.exit(1);
}
// The same spawn contract extension.js uses by default: no arguments,
// inherited env, the workspace directory as cwd, LSP on stdin/stdout. The one
// argument the extension can add — `--verbose`, when the user turns on
// `lucisv.verbose` — only adds log lines, and is driven by
// crates/lucisv_server/tests/e2e.rs; this check stays on the spawn everybody
// gets (docs/features/verbose-timing/README.md).
// `--stdio` is what `vscode-languageclient` really appends for
// TransportKind.stdio, so the smoke spawn matches the extension's actual
// spawn — the shape whose absence from this check let strict argument
// parsing ship a server no real VS Code session could start (2026-08-29).
const server = spawn(serverPath, ['--stdio'], { cwd: process.cwd(), env: process.env, stdio: 'pipe' });
server.on('error', (error) => fail(`could not spawn "${serverPath}": ${error.message}`));
const chunks = [];
server.stdout.on('data', (chunk) => chunks.push(chunk));
server.stderr.on('data', (chunk) => process.stderr.write(chunk));
// Every message is written before anything is read: the server handles them in
// order and exits on `exit`, so stdout closes on its own and this can never
// deadlock waiting for a message that is not coming.
const uri = `file://${process.cwd()}/smoke_scratch.sv`;
// Nested blocks plus a sibling fork: enough for the rainbow's whole contract —
// which pairs are reported, and what depth each one carries.
const RAINBOW = [
'module top;',
' wire a;',
' initial begin',
' if (a) begin',
' b = 1;',
' end',
' end',
' initial fork',
' c = 1;',
' join',
'endmodule',
'',
].join('\n');
// A module worth instantiating, in the same buffer because **this** buffer is
// the one the index reads: a `didOpen` for a URI with no file behind it is the
// only kind of source a plain-node session can offer, and the first one opened
// is what the initial scan sweeps up. Appended after the rainbow so every line
// number the checks below name stays put. The name is deliberately unlike
// anything a real project declares: the ghost wants exactly *one* definition
// of it, and a second one in scope would (correctly) silence it.
const SOURCE = RAINBOW + [
'module smoke_ghost_sub #(',
' parameter int WIDTH = 8',
') (',
' input logic clk,',
' output logic q',
');',
'endmodule',
'',
].join('\n');
// The rainbow with the outer `end` taken away: the half-pair the extension
// paints in its error colour, which is the other half of that contract. The
// instantiable module is left out on purpose — two declarations of it would be
// one too many.
const BROKEN = RAINBOW.replace(' end\n end\n', ' end\n');
const brokenUri = `file://${process.cwd()}/smoke_scratch_broken.sv`;
// A buffer that has just finished typing that module's name **and the space
// that arms the ghost** — `smoke_ghost_sub` alone offers nothing, because a
// longer name may still be coming (owner ruling, 2026-08-30).
const GHOST_TOP = ['module smoke_ghost_top;', ' logic clk;', ' smoke_ghost_sub ', 'endmodule', ''].join('\n');
const ghostTopUri = `file://${process.cwd()}/smoke_scratch_inst.sv`;
server.stdin.end(
Buffer.concat([
// `rangeFormatting.rangesSupport` is what vscode-languageclient 9.0.1
// itself sends (lib/common/formatting.js), and the server only widens
// `documentRangeFormattingProvider` for a client that sent it — so the
// capability this asserts below is the one the real extension sees.
frame({
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: {
processId: process.pid,
rootUri: null,
initializationOptions: { hierarchyView: true },
capabilities: { textDocument: { rangeFormatting: { dynamicRegistration: true, rangesSupport: true } } },
},
}),
frame({ jsonrpc: '2.0', method: 'initialized', params: {} }),
frame({
jsonrpc: '2.0',
method: 'textDocument/didOpen',
params: { textDocument: { uri, languageId: 'systemverilog', version: 1, text: SOURCE } },
}),
frame({ jsonrpc: '2.0', id: 3, method: 'lucisv/scopePairs', params: { textDocument: { uri } } }),
frame({
jsonrpc: '2.0',
method: 'textDocument/didOpen',
params: { textDocument: { uri: brokenUri, languageId: 'systemverilog', version: 1, text: BROKEN } },
}),
frame({ jsonrpc: '2.0', id: 5, method: 'lucisv/scopePairs', params: { textDocument: { uri: brokenUri } } }),
// The custom sidebar snapshot. The opened source contributes one module;
// this catches a server/extension method-name or response-shape mismatch.
frame({ jsonrpc: '2.0', id: 8, method: 'lucisv/moduleHierarchy', params: {} }),
// Ghost text, just after the `begin` on line 2 of the buffer that lost its
// `end`. The extension only ever sends this after opting into
// `ProposedFeatures`, so an "unhandled method" here is the same kind of
// mismatch the scopePairs check above exists to catch.
frame({
jsonrpc: '2.0',
id: 6,
method: 'textDocument/inlineCompletion',
params: { textDocument: { uri: brokenUri }, position: { line: 2, character: 15 }, context: { triggerKind: 2 } },
}),
// The other ghost: a module's whole name, typed where an instantiation may
// be written, is finished with its parameters and ports. A buffer of its
// own, so the definition really is looked up through the index rather than
// read out of the file being typed in.
frame({
jsonrpc: '2.0',
method: 'textDocument/didOpen',
params: { textDocument: { uri: ghostTopUri, languageId: 'systemverilog', version: 1, text: GHOST_TOP } },
}),
frame({
jsonrpc: '2.0',
id: 10,
method: 'textDocument/inlineCompletion',
params: { textDocument: { uri: ghostTopUri }, position: { line: 2, character: 18 }, context: { triggerKind: 2 } },
}),
// The same buffer at the end of the name itself, one character back: the
// byte before the cursor is not a space, so the answer is `null`.
frame({
jsonrpc: '2.0',
id: 11,
method: 'textDocument/inlineCompletion',
params: { textDocument: { uri: ghostTopUri }, position: { line: 2, character: 17 }, context: { triggerKind: 2 } },
}),
// The settings push, in exactly the shape `synchronize.configurationSection:
// 'lucisv'` produces — the whole section, defaults included.
frame({
jsonrpc: '2.0',
method: 'workspace/didChangeConfiguration',
params: {
settings: {
lucisv: { serverPath: 'lucisv-server', rainbowBeginEnd: true, inlineTemplates: true, lineLength: null, indent: 4, exclude: [] },
},
},
}),
// Formatting asks for a 2-space tab: the pushed `indent` must win, which
// is rung 2 of the precedence ladder beating rung 3, over the wire.
frame({
jsonrpc: '2.0',
id: 4,
method: 'textDocument/formatting',
params: { textDocument: { uri }, options: { tabSize: 2, insertSpaces: true } },
}),
// Multi-range formatting (LSP 3.18): two ranges, one round trip. Lines 2
// and 8 of SOURCE (0-based 1 and 7) are `wire a;` and `initial fork`. Each
// named block is laid out where it stands (selection formatting keeps a
// block's own leading whitespace): the wire is already laid out, the fork
// is re-laid under `indent = 4` from its two written spaces, and the
// `initial begin` between them keeps its bytes.
frame({
jsonrpc: '2.0',
id: 7,
method: 'textDocument/rangesFormatting',
params: {
textDocument: { uri },
ranges: [
{ start: { line: 7, character: 0 }, end: { line: 8, character: 0 } },
{ start: { line: 1, character: 0 }, end: { line: 2, character: 0 } },
],
options: { tabSize: 2, insertSpaces: true },
},
}),
frame({ jsonrpc: '2.0', id: 2, method: 'shutdown', params: null }),
frame({ jsonrpc: '2.0', method: 'exit', params: null }),
]),
);
server.on('close', (code) => {
if (code !== 0) fail(`server exited with code ${code}`);
const messages = unframe(Buffer.concat(chunks));
const initialize = messages.find((m) => m.id === 1);
if (!initialize) fail('no initialize response');
if (initialize.error) fail(`initialize failed: ${JSON.stringify(initialize.error)}`);
const capabilities = initialize.result && initialize.result.capabilities;
if (!capabilities) fail('initialize response carries no capabilities');
for (const capability of ['documentFormattingProvider', 'definitionProvider', 'hoverProvider', 'semanticTokensProvider']) {
if (!capabilities[capability]) fail(`capability missing: ${capability}`);
}
if (!capabilities.documentHighlightProvider) fail('capability missing: documentHighlightProvider');
if (!capabilities.inlineCompletionProvider) fail('capability missing: inlineCompletionProvider');
// A member list has no identifier of its own to be asked for, so the two
// separators that start one are advertised as triggers. If VS Code does not
// see them here it never asks after a `.` at all, and the whole feature is
// invisible in the editor while every test still passes.
// docs/features/member-completion/README.md
const completionTriggers = (capabilities.completionProvider || {}).triggerCharacters || [];
for (const trigger of ['.', ':']) {
if (!completionTriggers.includes(trigger)) {
fail(`completion trigger missing: ${trigger} (got ${JSON.stringify(completionTriggers)})`);
}
}
const hierarchy = messages.find((m) => m.id === 8);
if (!hierarchy || hierarchy.error) fail(`hierarchy snapshot failed: ${JSON.stringify(hierarchy)}`);
if (!hierarchy.result || hierarchy.result.schemaVersion !== 2) fail('hierarchy snapshot has the wrong schema');
if (!Array.isArray(hierarchy.result.files)) fail('hierarchy snapshot has no file table');
const hierarchyNames = (hierarchy.result.modules || []).map((module) => module.moduleName);
if (!hierarchyNames.includes('top')) fail(`hierarchy snapshot missing top: ${JSON.stringify(hierarchyNames)}`);
// A location names its file by index and its ranges as four numbers — the
// narrow wire the sidebar's cost fix introduced.
const definition = (hierarchy.result.modules.find((m) => m.moduleName === 'top') || {}).definition;
if (!definition || typeof definition.file !== 'number'
|| !Array.isArray(definition.range) || definition.range.length !== 4) {
fail(`hierarchy definition is not the narrow shape: ${JSON.stringify(definition)}`);
}
const diagnostics = messages.find((m) => m.method === 'textDocument/publishDiagnostics');
if (!diagnostics) fail('the server pushed no diagnostics for the opened document');
// The rainbow's data source. Custom method, so nothing advertises it — an
// "unhandled method" error here is exactly the mismatch this test exists to
// catch, and it is what an extension paired with an older server would hit.
const scopePairs = messages.find((m) => m.id === 3);
if (!scopePairs) fail('no lucisv/scopePairs response');
if (scopePairs.error) fail(`lucisv/scopePairs failed: ${JSON.stringify(scopePairs.error)}`);
const pairs = scopePairs.result && scopePairs.result.pairs;
if (!Array.isArray(pairs)) fail(`lucisv/scopePairs result has no pairs array: ${JSON.stringify(scopePairs.result)}`);
// Depth counts only the scopes the rainbow draws, so the enclosing module
// does not count: the outer begin is 0, the begin inside it is 1, and the
// fork is the outer begin's sibling at 0.
const depths = pairs.map((p) => p.depth);
if (JSON.stringify(depths) !== JSON.stringify([0, 1, 0])) {
fail(`expected depths [0,1,0] (outer begin, inner begin, fork), got ${JSON.stringify(depths)}`);
}
// Opener lines, 0-based: `initial begin`, `if (a) begin`, `initial fork`.
const openLines = pairs.map((p) => p.open.start.line);
if (JSON.stringify(openLines) !== JSON.stringify([2, 3, 7])) {
fail(`expected openers on lines [2,3,7], got ${JSON.stringify(openLines)}`);
}
const closeLines = pairs.map((p) => p.close.start.line);
if (JSON.stringify(closeLines) !== JSON.stringify([6, 5, 9])) {
fail(`expected closers on lines [6,5,9], got ${JSON.stringify(closeLines)}`);
}
for (const pair of pairs) {
for (const half of [pair.open, pair.close]) {
if (half.end.character <= half.start.character) fail(`empty range in ${JSON.stringify(pair)}`);
}
}
// A balanced buffer still carries the field, empty: that is what clears the
// error decoration once the user finishes typing the missing `end`.
if (!Array.isArray(scopePairs.result.unmatched) || scopePairs.result.unmatched.length !== 0) {
fail(`a balanced buffer must report no unmatched keywords, got ${JSON.stringify(scopePairs.result.unmatched)}`);
}
// ... and the buffer missing its outer `end` reports that `begin`, so the
// extension can paint it rather than leave it undecorated.
const broken = messages.find((m) => m.id === 5);
if (!broken) fail('no lucisv/scopePairs response for the broken buffer');
if (broken.error) fail(`lucisv/scopePairs failed: ${JSON.stringify(broken.error)}`);
const unmatched = broken.result && broken.result.unmatched;
if (!Array.isArray(unmatched) || unmatched.length !== 1) {
fail(`expected one unmatched keyword, got ${JSON.stringify(unmatched)}`);
}
if (unmatched[0].start.line !== 2 || unmatched[0].start.character !== 10) {
fail(`expected the unclosed begin at 2:10, got ${JSON.stringify(unmatched[0])}`);
}
// Ghost text: the `begin` that lost its `end` gets one offered, spelled the
// one way the language client turns into a working snippet. A bare-string
// `insertText` would be inserted as plain text, tabstops and all.
const ghost = messages.find((m) => m.id === 6);
if (!ghost) fail('no textDocument/inlineCompletion response');
if (ghost.error) fail(`textDocument/inlineCompletion failed: ${JSON.stringify(ghost.error)}`);
const suggestion = ghost.result && ghost.result.items && ghost.result.items[0];
if (!suggestion) fail(`expected one inline completion, got ${JSON.stringify(ghost.result)}`);
if (!suggestion.insertText || suggestion.insertText.kind !== 'snippet') {
fail(`insertText must be a {kind:"snippet"} object, got ${JSON.stringify(suggestion.insertText)}`);
}
// The body is indented *relative* to the trigger line — one tab per step,
// no trace of where in the file it goes — because VS Code's snippet session
// prepends the insertion line's own leading whitespace to every line after
// the first and re-spells the result in the editor's tabs-or-spaces. Sending
// the absolute layout, as 0.6.0 did, indented it twice.
if (suggestion.insertText.value !== '\n\t$0\nend') {
fail(`unexpected ghost text: ${JSON.stringify(suggestion.insertText.value)}`);
}
// The instantiation ghost: the module's name and the arming space are
// already typed, so the ghost is everything after both — the parameter list,
// the instance name, and one line per port, all relative to the trigger
// line. `clk` is declared in the buffer, so it connects itself rather than
// becoming a tabstop.
const instantiation = messages.find((m) => m.id === 10);
if (!instantiation) fail('no textDocument/inlineCompletion response for the module name');
if (instantiation.error) fail(`instantiation ghost failed: ${JSON.stringify(instantiation.error)}`);
const skeleton = instantiation.result && instantiation.result.items && instantiation.result.items[0];
if (!skeleton) fail(`expected an instantiation ghost, got ${JSON.stringify(instantiation.result)}`);
if (!skeleton.insertText || skeleton.insertText.kind !== 'snippet') {
fail(`insertText must be a {kind:"snippet"} object, got ${JSON.stringify(skeleton.insertText)}`);
}
const expected = '#(\n\t.WIDTH(${1:8})\n) ${2:u_smoke_ghost_sub} (\n\t.clk(clk),\n\t.q(${3:q})\n);';
if (skeleton.insertText.value !== expected) {
fail(`unexpected instantiation ghost: ${JSON.stringify(skeleton.insertText.value)}`);
}
// …and the other half of the same rule: the name with no space after the
// cursor is not an offer at all.
const unarmed = messages.find((m) => m.id === 11);
if (!unarmed) fail('no textDocument/inlineCompletion response for the unarmed module name');
if (unarmed.error) fail(`unarmed instantiation probe failed: ${JSON.stringify(unarmed.error)}`);
if (unarmed.result !== null) {
fail(`a module name with no space after it must ghost nothing, got ${JSON.stringify(unarmed.result)}`);
}
// The settings the extension pushes actually reach the formatter.
const formatting = messages.find((m) => m.id === 4);
if (!formatting) fail('no textDocument/formatting response');
if (formatting.error) fail(`formatting failed: ${JSON.stringify(formatting.error)}`);
const edits = formatting.result;
if (!Array.isArray(edits) || edits.length !== 1) {
fail(`expected one edit re-indenting the buffer, got ${JSON.stringify(edits)}`);
}
const indented = edits[0].newText;
if (!indented.includes('\n wire a;')) {
fail(`pushed lucisv.indent=4 was not honoured over tabSize=2:\n${indented}`);
}
if (indented.includes('\n wire a;')) {
fail(`the editor tab size won over the pushed setting:\n${indented}`);
}
// Multi-range formatting, and the capability shape that unlocks it. A client
// library registers its multi-range provider only when the server answers
// with the options object; a bare `true` here means the feature is dark.
const ranges = capabilities.documentRangeFormattingProvider;
if (!ranges || ranges.rangesSupport !== true) {
fail(`a client advertising rangesSupport must get the options object back, got ${JSON.stringify(ranges)}`);
}
const ranged = messages.find((m) => m.id === 7);
if (!ranged) fail('no textDocument/rangesFormatting response');
if (ranged.error) fail(`rangesFormatting failed: ${JSON.stringify(ranged.error)}`);
if (!Array.isArray(ranged.result) || ranged.result.length !== 1) {
fail(`expected one edit from rangesFormatting, got ${JSON.stringify(ranged.result)}`);
}
const partial = ranged.result[0].newText;
if (!partial.includes('\n initial\n fork\n c = 1;\n join\n')) {
fail(`the named block was not laid out at its own indentation:\n${partial}`);
}
if (!partial.includes('\n wire a;')) {
fail(`a named line must keep the indentation it was written at:\n${partial}`);
}
if (!partial.includes('\n initial begin')) {
fail(`a line no range named must keep its own bytes:\n${partial}`);
}
const shutdown = messages.find((m) => m.id === 2);
if (!shutdown) fail('no shutdown response');
if (shutdown.error) fail(`shutdown failed: ${JSON.stringify(shutdown.error)}`);
console.log(`smoke: OK — "${serverPath}" completed initialize/didOpen/shutdown/exit (${messages.length} messages)`);
});