Files
lucioandClaude Fable 5.1 acf20f7e62 Extract module: dataflow-inferred ports, a new file where the client can create one, and a verifier ledger that follows the move
TODO §53.1 (docs/features/extract-inline-module), the fourth §8
refactoring; §53.2 inline module is unstarted and runs as its own lane.

`vlog_refactor::extract` (region, flow, boundary, render): a selection
of whole module items becomes a new module — a name declared outside
and read inside is an `input`, written inside an `output` (assign and
procedural LHS, for init/step, ++/--, force/release/deassign, `-> ev`,
an initialiser, an output/inout connection through the index), written
on both sides refused; parameters passed through `#(.P(P))`, used
imports copied, the port's type taken from the declaration's own text;
the selection replaced by an instantiation rendered from the new
module's text. Forty-three refusal sentences. `RefactorEdit::created`;
the server emits `CreateFile` document changes when the client reads
both halves of the capability, else writes the module below its source;
`refactor.extract` action carrying `lucisv.extractModule [uri, range,
name]`, and a name prompt in the VS Code extension through the language
client's middleware.

The verifier's never-dropped ledger follows the move (review rework of
QA's two HIGHs): `verify_move(moving: &[(file, region)])` — a piece
deleted inside the moved region must land exactly once in the file the
move names, a deletion outside the region stays an ordinary deletion,
four equations, twelve attack pairs through the production entry;
`check.rs` split (pure move) into `check/{mod,ledger}.rs`. `interface`
and `program` bodies are refused (one AST node, gated on `kw`). QA's
re-attack: PASS; its MEDIUM (a same-file relocation as two edits) is
filed as topo §2.9-32.

Trials: corpus 5 extracted / 6 refused, opentitan `hw/ip/{aes,uart,
spi_host,hmac}` 5 / 5, the unresolved-name census held for every
accepted extraction. 0 of 820 corpus files differ from 0.46.0.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
2026-09-05 23:04:14 -05:00

138 lines
5.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Checks for `extract.js`: the input box that names the module the server is
// about to extract, and what it does when the user does not name one.
//
// node extract_test.js
//
// Exits 0 on success, 1 on any failure. Plain node, no dependencies and no
// test runner — the same style as `restart_test.js` next to it.
//
// The fakes below script only what `extract.js` is allowed to depend on: an
// input box that resolves to a string or to `undefined`, and a `next` that
// records what it was handed. Nothing here re-implements VS Code.
// See docs/features/extract-inline-module/README.md.
const { EXTRACT_MODULE, executeCommand, validateModuleName } = require('./extract');
let checks = 0;
function ok(condition, what) {
checks += 1;
if (!condition) fail(what);
}
function equal(got, want, what) {
checks += 1;
const a = JSON.stringify(got);
const b = JSON.stringify(want);
if (a !== b) fail(`${what}: got ${a}, want ${b}`);
}
function fail(message) {
console.error(`extract: FAIL — ${message}`);
process.exit(1);
}
/** A `next` that records every call and answers with a marker. */
function recorder() {
const calls = [];
const next = (command, args) => {
calls.push({ command, args });
return Promise.resolve('applied');
};
return { calls, next };
}
/** An input box that answers `answer` and records the options it was given. */
function box(answer) {
const seen = [];
const showInputBox = (options) => {
seen.push(options);
return Promise.resolve(answer);
};
return { seen, showInputBox };
}
const ARGS = ['file:///rtl/m.sv', { start: { line: 6 }, end: { line: 6 } }, 'm_extracted'];
async function aNameTypedIntoTheBoxReachesTheServer() {
const { calls, next } = recorder();
const { seen, showInputBox } = box('adder');
const result = await executeCommand({ showInputBox }, EXTRACT_MODULE, ARGS, next);
equal(result, 'applied', 'the server’s answer comes back to the client');
equal(calls.length, 1, 'the command is sent once');
equal(calls[0].command, EXTRACT_MODULE, 'under its own name');
equal(calls[0].args[0], ARGS[0], 'the uri is passed through');
equal(calls[0].args[1], ARGS[1], 'and so is the range');
equal(calls[0].args[2], 'adder', 'the typed name replaces the default');
equal(seen.length, 1, 'one box is shown');
equal(seen[0].value, 'm_extracted', 'prefilled with the default the server proposed');
}
async function surroundingWhitespaceIsTrimmedOffTheName() {
const { calls, next } = recorder();
const { showInputBox } = box(' adder\t');
await executeCommand({ showInputBox }, EXTRACT_MODULE, ARGS, next);
equal(calls[0].args[2], 'adder', 'a name is what is left after the spaces');
}
async function anEscapedBoxSendsNothingAtAll() {
const { calls, next } = recorder();
const { showInputBox } = box(undefined);
const result = await executeCommand({ showInputBox }, EXTRACT_MODULE, ARGS, next);
equal(result, undefined, 'a cancelled extraction answers nothing');
equal(calls.length, 0, 'and reaches the server not at all');
}
async function aNameTheEngineWouldRefuseIsNotSentEither() {
// The box's own validator should stop this, but a client that ignores
// `validateInput` must not get a file called `2fast.sv` out of it.
for (const typed of ['', ' ', '2fast', 'with space', '\\odd-name']) {
const { calls, next } = recorder();
const { showInputBox } = box(typed);
const result = await executeCommand({ showInputBox }, EXTRACT_MODULE, ARGS, next);
equal(result, undefined, `\`${typed}\` is not a module name`);
equal(calls.length, 0, `\`${typed}\` never reaches the server`);
}
}
async function everyOtherCommandGoesStraightThrough() {
const { calls, next } = recorder();
let shown = 0;
const showInputBox = () => {
shown += 1;
return Promise.resolve('never');
};
const args = ['file:///rtl/m.sv', { line: 3, character: 0 }];
const result = await executeCommand({ showInputBox }, 'lucisv.organizeImports', args, next);
equal(result, 'applied', 'the other commands answer as they always did');
equal(shown, 0, 'and no box is shown for them');
equal(calls, [{ command: 'lucisv.organizeImports', args }], 'passed through unchanged');
}
function theValidatorSaysWhatTheEngineWouldSay() {
equal(validateModuleName('adder'), undefined, 'a plain identifier is fine');
equal(validateModuleName('_adder$2'), undefined, 'so are `_`, digits and `$` after the first');
ok(validateModuleName('').includes('needs a name'), 'an empty box says so');
ok(validateModuleName(' ').includes('needs a name'), 'and so does a blank one');
ok(validateModuleName('2fast').includes('plain SystemVerilog identifier'), 'a leading digit');
ok(validateModuleName('a b').includes('plain SystemVerilog identifier'), 'a space');
ok(validateModuleName('\\odd-name').includes('plain SystemVerilog identifier'), 'an escaped name');
}
async function main() {
const watchdog = setTimeout(
() => fail('timed out after 5s — a promise this test waits on never settled'),
5000,
);
theValidatorSaysWhatTheEngineWouldSay();
await aNameTypedIntoTheBoxReachesTheServer();
await surroundingWhitespaceIsTrimmedOffTheName();
await anEscapedBoxSendsNothingAtAll();
await aNameTheEngineWouldRefuseIsNotSentEither();
await everyOtherCommandGoesStraightThrough();
clearTimeout(watchdog);
console.log(`extract: OK — ${checks} checks over the extract input box`);
}
main().catch((error) => fail(error.stack || String(error)));