Files
Guoliang ChenandClaude Mythos 5.2 71d13b5fbe
ci / checks (push) Successful in 1m0s
ci / corpus (push) Successful in 18s
ci / linux (push) Successful in 6m4s
release / build-and-publish (push) Successful in 5m31s
Release 0.66.2: every source file names its author
Every tracked file that can carry a comment (880 of them) now opens with
"Author: Guoliang Chen, a Senior Digital Design Engineer" and closes with
"Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love,
luciochen.com", in the file's own comment syntax. No behaviour change: the
diff outside the version bump and changelogs is comment lines only.

- tools/stamp_author.py: writes the lines; idempotent, `--check` lists
  what is missing. Headers go under a shebang and under Markdown front
  matter.
- Left alone: test fixtures, cases and snapshots (byte-exact inputs), JSON
  and JSONL, logs, images, lockfiles, docs/site/dist (regenerated) and the
  LICENSE files (already carry the copyright line).
- tools/linux_check.sh: --help reads its header from line 3, now that the
  author line sits under the shebang.
- tools/gates.sh green on this tree: 5 545 tests, corpus 814/6 as before.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
2026-11-24 12:11:09 -08:00

142 lines
5.5 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.
// Author: Guoliang Chen, a Senior Digital Design Engineer
// 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)));
// Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com