TODO §56 (docs/features/dut-hierarchy), the owner's request of 2026-09-06.
Client-only, over the flat `lucisv/moduleHierarchy` snapshot the server
already sends. `hierarchySections.js`: per starred DUT, in starred
order, the DUT's forward subtree (the DUT at the top) and an upward tree
from the DUT through every module that instantiates it (labelled `via
<instance>`, cycles cut with one `recursive` row), then one section for
every module in no DUT's subtree or ancestor closure, re-rooted where
its only parents are DUT ancestors (the review ruling — a monitor beside
the DUT under the same bench stays on screen); a module both below one
DUT and above another appears in both DUT sections; a starred name the
index lacks keeps its sections with a "not in the index" row. Star and
unstar from the webview row menu (the pane is a WebviewView, so the
menu is the renderer's, driven by a `menuTable()` per render), the
`lucisv.hierarchy.{starDut,unstarDut,clearDuts}` commands and title
actions, persistence in `workspaceState` in starred order, and the
`lucisv.hierarchy.duts` setting whose entries show locked. With nothing
starred the pane is byte-identical to before (pinned).
opentitan `hw/ip` (847 modules): `aes` → 3 sections with `tb` in its
parents and 5 modules under `aes_tb` re-rooted into others; `aes` +
`hmac` → 5 sections; every module reachable in both configurations; QA's
200-trial fuzz found no overlap and no gap. `extract_test.js` added to
`.vscodeignore`.
(Committed after the 0.48.0 version commit: the release chain broke at a
test-output grep and cut the tag one commit early; the tag is moved here.)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
623 lines
25 KiB
JavaScript
623 lines
25 KiB
JavaScript
const assert = require('assert/strict');
|
||
const fs = require('fs');
|
||
const path = require('path');
|
||
const { buildHierarchy, treeRows } = require('./hierarchyModel');
|
||
const {
|
||
LOCKED,
|
||
decorate,
|
||
defaultOpenIds,
|
||
menuTable,
|
||
sectionPrefixes,
|
||
sectionRows,
|
||
sections,
|
||
} = require('./hierarchySections');
|
||
|
||
// The same schema-2 wire the model tests use: a file table, four-number ranges,
|
||
// no ids and no per-instance `definitions`.
|
||
function site(file, line, start, end) {
|
||
return { file, range: [line, 0, line, end + 3], selectionRange: [line, start, line, end] };
|
||
}
|
||
|
||
/** A DV bench above a DUT above three leaves, plus two unrelated modules. */
|
||
function fixture() {
|
||
const files = [
|
||
'file:///tb.sv', 'file:///dut.sv', 'file:///l1.sv', 'file:///l2.sv',
|
||
'file:///l3.sv', 'file:///lonely.sv', 'file:///other.sv',
|
||
];
|
||
return {
|
||
schemaVersion: 2,
|
||
revision: 7,
|
||
complete: true,
|
||
files,
|
||
modules: [
|
||
{ moduleName: 'tb', definition: site(0, 0, 7, 9), instances: [
|
||
{ instanceName: 'u_dut', moduleName: 'dut', site: site(0, 1, 4, 9) },
|
||
] },
|
||
{ moduleName: 'dut', definition: site(1, 0, 7, 10), instances: [
|
||
{ instanceName: 'u_l1', moduleName: 'leaf1', site: site(1, 1, 6, 10) },
|
||
{ instanceName: 'u_l2', moduleName: 'leaf2', site: site(1, 2, 6, 10) },
|
||
{ instanceName: 'u_l3', moduleName: 'leaf3', site: site(1, 3, 6, 10) },
|
||
] },
|
||
{ moduleName: 'leaf1', definition: site(2, 0, 7, 12), instances: [] },
|
||
{ moduleName: 'leaf2', definition: site(3, 0, 7, 12), instances: [] },
|
||
{ moduleName: 'leaf3', definition: site(4, 0, 7, 12), instances: [] },
|
||
{ moduleName: 'lonely', definition: site(5, 0, 7, 13), instances: [] },
|
||
{ moduleName: 'other_top', definition: site(6, 0, 7, 16), instances: [] },
|
||
],
|
||
};
|
||
}
|
||
|
||
/** A snapshot from `{ module: [instantiated type, …] }`: one file and one
|
||
* declaration per module, and one instance `u_<type>` per named type. */
|
||
function graph(spec) {
|
||
const names = Object.keys(spec);
|
||
return {
|
||
schemaVersion: 2,
|
||
revision: 1,
|
||
complete: true,
|
||
files: names.map((name) => `file:///${name}.sv`),
|
||
modules: names.map((name, at) => ({
|
||
moduleName: name,
|
||
definition: site(at, 0, 7, 7 + name.length),
|
||
instances: spec[name].map((type, index) => ({
|
||
instanceName: `u_${type}`,
|
||
moduleName: type,
|
||
site: site(at, index + 1, 4, 9),
|
||
})),
|
||
})),
|
||
};
|
||
}
|
||
|
||
/** Every id in a section list, opened all the way down. */
|
||
function openEverything(model, list) {
|
||
const expanded = new Set();
|
||
for (let pass = 0; pass < 12; pass += 1) {
|
||
const { rows } = sectionRows(model, list, expanded, '');
|
||
const before = expanded.size;
|
||
for (const row of rows) if (row.hasChildren) expanded.add(row.id);
|
||
if (expanded.size === before) break;
|
||
}
|
||
return sectionRows(model, list, expanded, '');
|
||
}
|
||
|
||
function shape(model, list) {
|
||
return openEverything(model, list).rows.map((row) => `${' '.repeat(row.depth)}${row.label}`);
|
||
}
|
||
|
||
function noDutIsOneSectionAndThePlainRoots() {
|
||
const model = buildHierarchy(fixture());
|
||
const list = sections(model, []);
|
||
assert.equal(list.length, 1, 'zero DUTs is the others section on its own');
|
||
assert.equal(list[0].kind, 'others');
|
||
assert.deepEqual(
|
||
list[0].roots.map(({ module }) => module.moduleName),
|
||
model.roots.map(({ module }) => module.moduleName),
|
||
'and it holds exactly today’s roots',
|
||
);
|
||
}
|
||
|
||
function oneDutIsThreeSectionsAndTwoAreFive() {
|
||
const model = buildHierarchy(fixture());
|
||
const one = sections(model, ['dut']);
|
||
assert.deepEqual(one.map((section) => section.kind), ['dut', 'parents', 'others']);
|
||
const two = sections(model, ['dut', 'other_top']);
|
||
assert.deepEqual(
|
||
two.map((section) => `${section.kind}:${section.name || ''}`),
|
||
['dut:dut', 'parents:dut', 'dut:other_top', 'parents:other_top', 'others:'],
|
||
'per DUT its own two sections, in starred order, then one others',
|
||
);
|
||
}
|
||
|
||
function theDutSectionIsTheForwardSubtreeAndTheParentsSectionIsTheUpwardTree() {
|
||
const model = buildHierarchy(fixture());
|
||
const list = sections(model, ['dut']);
|
||
assert.deepEqual(shape(model, list), [
|
||
'DUT: dut',
|
||
' dut',
|
||
' u_l1 (leaf1)',
|
||
' u_l2 (leaf2)',
|
||
' u_l3 (leaf3)',
|
||
'Parents of dut',
|
||
' dut',
|
||
' tb',
|
||
'Other modules',
|
||
' lonely',
|
||
' other_top',
|
||
]);
|
||
|
||
// The upward row says which instance reaches the DUT, and points at the
|
||
// instantiating module's own declaration.
|
||
const { rows, nodes } = openEverything(model, list);
|
||
const upward = rows.find((row) => row.label === 'tb' && row.depth === 2);
|
||
assert.equal(upward.detail, 'via u_dut');
|
||
const node = nodes.get(upward.id);
|
||
assert.equal(node.definition.uri, 'file:///tb.sv', 'the parent module’s declaration');
|
||
assert.equal(node.site.uri, 'file:///tb.sv');
|
||
assert.equal(node.kind, 'module');
|
||
|
||
// The DUT's own subtree is the node the plain view shows for it: same
|
||
// children, same order, same labels.
|
||
const plainDut = treeRows(model, new Set(), '').rows;
|
||
assert(!plainDut.some((row) => row.label === 'dut'), 'dut is not a root of the plain view');
|
||
const dutRows = rows.filter((row) => row.depth >= 2 && row.id.startsWith('dut:dut/'));
|
||
assert.deepEqual(dutRows.map((row) => row.label), ['u_l1 (leaf1)', 'u_l2 (leaf2)', 'u_l3 (leaf3)']);
|
||
}
|
||
|
||
function othersHoldsEveryModuleOutsideEveryDut() {
|
||
const model = buildHierarchy(fixture());
|
||
const [, , others] = sections(model, ['dut']);
|
||
assert.deepEqual(
|
||
others.roots.map(({ module }) => module.moduleName),
|
||
['lonely', 'other_top'],
|
||
'tb is above the DUT and is gone; the two unrelated roots stay',
|
||
);
|
||
// A leaf is below the DUT and was never a root, so nothing changed for it;
|
||
// what the exclusion actually removes is the ancestor root.
|
||
const plainRoots = model.roots.map(({ module }) => module.moduleName);
|
||
assert.deepEqual(plainRoots, ['lonely', 'other_top', 'tb']);
|
||
|
||
// Starring a leaf takes `tb` (an ancestor) and `dut` (an ancestor) out, which
|
||
// leaves the two *other* leaves with no parent on screen: they are not below
|
||
// the DUT, so others re-roots them, in the model's alphabetical order.
|
||
const [, , leafOthers] = sections(model, ['leaf2']);
|
||
assert.deepEqual(
|
||
leafOthers.roots.map(({ module }) => module.moduleName),
|
||
['leaf1', 'leaf3', 'lonely', 'other_top'],
|
||
);
|
||
}
|
||
|
||
/** The bench beside the DUT: `monitor` is not a child of the DUT, so it is in
|
||
* others — re-rooted, because the exclusion took its only parent. */
|
||
function aModuleUnderAnExcludedBenchIsReRootedInOthers() {
|
||
const model = buildHierarchy(graph({
|
||
bench: ['dut', 'monitor'], dut: ['leaf'], monitor: ['probe'], leaf: [], probe: [], spare: [],
|
||
}));
|
||
const list = sections(model, ['dut']);
|
||
const [, , others] = list;
|
||
assert.deepEqual(others.roots.map(({ module }) => module.moduleName), ['monitor', 'spare']);
|
||
assert.deepEqual(shape(model, list), [
|
||
'DUT: dut',
|
||
' dut',
|
||
' u_leaf (leaf)',
|
||
'Parents of dut',
|
||
' dut',
|
||
' bench',
|
||
'Other modules',
|
||
' monitor',
|
||
' u_probe (probe)',
|
||
' spare',
|
||
]);
|
||
// Nothing the snapshot holds is off screen while the DUT is starred.
|
||
const shown = new Set(shape(model, list).map((line) => line.trim().replace(/^.*\((.*)\)$/, '$1')));
|
||
for (const module of model.modules) {
|
||
assert(shown.has(module.moduleName), `${module.moduleName} is in no section`);
|
||
}
|
||
}
|
||
|
||
/** Two benches instantiate one module and both are excluded: it is re-rooted
|
||
* once, not once per bench. */
|
||
function aModuleUnderTwoExcludedBenchesIsReRootedOnce() {
|
||
const model = buildHierarchy(graph({
|
||
bench_a: ['dut', 'shared'], bench_b: ['dut', 'shared'], dut: [], shared: [],
|
||
}));
|
||
const [, , others] = sections(model, ['dut']);
|
||
assert.deepEqual(others.roots.map(({ module }) => module.moduleName), ['shared']);
|
||
assert.equal(others.roots.length, 1);
|
||
}
|
||
|
||
/** One excluded parent and one ordinary one: the module keeps its place under
|
||
* the ordinary parent and is not re-rooted beside it. */
|
||
function aModuleWithOneOrdinaryParentIsNotReRooted() {
|
||
const model = buildHierarchy(graph({
|
||
bench: ['dut', 'util'], top: ['util'], dut: [], util: [],
|
||
}));
|
||
const list = sections(model, ['dut']);
|
||
const [, , others] = list;
|
||
assert.deepEqual(others.roots.map(({ module }) => module.moduleName), ['top']);
|
||
assert.deepEqual(shape(model, list), [
|
||
'DUT: dut',
|
||
' dut',
|
||
'Parents of dut',
|
||
' dut',
|
||
' bench',
|
||
'Other modules',
|
||
' top',
|
||
' u_util (util)',
|
||
]);
|
||
const util = shape(model, list).filter((line) => line.includes('util'));
|
||
assert.equal(util.length, 1, 'shown once, under the parent it always had');
|
||
}
|
||
|
||
/** DUT2's bench is a sibling of DUT1 under one top bench: both are excluded,
|
||
* and the monitor beside DUT2 is the only thing others re-roots. */
|
||
function twoDutsSharingABenchLeaveOthersCorrect() {
|
||
const model = buildHierarchy(graph({
|
||
bench: ['dut1', 'sub_bench'], sub_bench: ['dut2', 'monitor'],
|
||
dut1: [], dut2: [], monitor: [], spare: [],
|
||
}));
|
||
const list = sections(model, ['dut1', 'dut2']);
|
||
assert.equal(list.length, 5);
|
||
assert.deepEqual(shape(model, list), [
|
||
'DUT: dut1',
|
||
' dut1',
|
||
'Parents of dut1',
|
||
' dut1',
|
||
' bench',
|
||
'DUT: dut2',
|
||
' dut2',
|
||
'Parents of dut2',
|
||
' dut2',
|
||
' sub_bench',
|
||
' bench',
|
||
'Other modules',
|
||
' monitor',
|
||
' spare',
|
||
]);
|
||
}
|
||
|
||
/** A cycle whose only way in is an excluded bench: no member has a parent
|
||
* outside it, so others opens it at the model's own fallback root. */
|
||
function aCycleReachableOnlyThroughAnExcludedBenchStillHasARoot() {
|
||
const model = buildHierarchy(graph({
|
||
bench: ['dut', 'a'], a: ['b'], b: ['a'], dut: [],
|
||
}));
|
||
const list = sections(model, ['dut']);
|
||
const [, , others] = list;
|
||
assert.deepEqual(others.roots.map(({ module }) => module.moduleName), ['a']);
|
||
assert.equal(others.roots[0].fallback, true, 'marked recursive, as the plain view marks it');
|
||
assert.deepEqual(shape(model, list), [
|
||
'DUT: dut',
|
||
' dut',
|
||
'Parents of dut',
|
||
' dut',
|
||
' bench',
|
||
'Other modules',
|
||
' a',
|
||
' u_b (b)',
|
||
' u_a (a)',
|
||
]);
|
||
}
|
||
|
||
/** `mid` is below DUT1 and above DUT2: it belongs to both DUT sections and to
|
||
* neither others. */
|
||
function aModuleBothBelowOneDutAndAboveAnotherIsInBothSections() {
|
||
const model = buildHierarchy({
|
||
schemaVersion: 2,
|
||
revision: 1,
|
||
complete: true,
|
||
files: ['file:///top.sv', 'file:///mid.sv', 'file:///low.sv', 'file:///spare.sv'],
|
||
modules: [
|
||
{ moduleName: 'top', definition: site(0, 0, 7, 10), instances: [
|
||
{ instanceName: 'u_mid', moduleName: 'mid', site: site(0, 1, 4, 9) },
|
||
] },
|
||
{ moduleName: 'mid', definition: site(1, 0, 7, 10), instances: [
|
||
{ instanceName: 'u_low', moduleName: 'low', site: site(1, 1, 4, 9) },
|
||
] },
|
||
{ moduleName: 'low', definition: site(2, 0, 7, 10), instances: [] },
|
||
{ moduleName: 'spare', definition: site(3, 0, 7, 12), instances: [] },
|
||
],
|
||
});
|
||
const list = sections(model, ['top', 'low']);
|
||
assert.deepEqual(shape(model, list), [
|
||
'DUT: top',
|
||
' top',
|
||
' u_mid (mid)',
|
||
' u_low (low)',
|
||
'Parents of top',
|
||
' top',
|
||
'DUT: low',
|
||
' low',
|
||
'Parents of low',
|
||
' low',
|
||
' mid',
|
||
' top',
|
||
'Other modules',
|
||
' spare',
|
||
]);
|
||
const [, , , , others] = list;
|
||
assert.deepEqual(others.roots.map(({ module }) => module.moduleName), ['spare']);
|
||
|
||
// The same module in two sections is two rows with two ids, so opening one
|
||
// never opens the other.
|
||
const { rows } = openEverything(model, list);
|
||
const midRows = rows.filter((row) => row.label.includes('mid'));
|
||
assert.equal(midRows.length, 2);
|
||
assert.equal(new Set(midRows.map((row) => row.id)).size, 2);
|
||
assert(midRows.some((row) => row.id.startsWith('dut:top/')));
|
||
assert(midRows.some((row) => row.id.startsWith('parents:low/')));
|
||
}
|
||
|
||
/** `a` instantiates `b` instantiates `a`: the upward walk cuts the cycle with
|
||
* its visited set, exactly as the forward walk does. */
|
||
function theParentsWalkCutsACycle() {
|
||
const model = buildHierarchy({
|
||
schemaVersion: 2,
|
||
revision: 1,
|
||
complete: true,
|
||
files: ['file:///a.sv', 'file:///b.sv'],
|
||
modules: [
|
||
{ moduleName: 'a', definition: site(0, 0, 7, 8), instances: [
|
||
{ instanceName: 'u_b', moduleName: 'b', site: site(0, 1, 4, 7) },
|
||
] },
|
||
{ moduleName: 'b', definition: site(1, 0, 7, 8), instances: [
|
||
{ instanceName: 'u_a', moduleName: 'a', site: site(1, 1, 4, 7) },
|
||
] },
|
||
],
|
||
});
|
||
const list = sections(model, ['a']);
|
||
assert.deepEqual(shape(model, list), [
|
||
'DUT: a',
|
||
' a',
|
||
' u_b (b)',
|
||
' u_a (a)',
|
||
'Parents of a',
|
||
' a',
|
||
' b',
|
||
' a',
|
||
'Other modules',
|
||
]);
|
||
const { rows } = openEverything(model, list);
|
||
const cut = rows.filter((row) => row.id.startsWith('parents:a/') && row.detail === 'recursive');
|
||
assert.equal(cut.length, 1, 'the edge that closes the cycle is marked once');
|
||
assert.equal(cut[0].label, 'a');
|
||
assert.equal(cut[0].hasChildren, false, 'and does not open again');
|
||
assert.equal(cut[0].warning, true);
|
||
}
|
||
|
||
function aStarredNameTheSnapshotLacksKeepsItsSections() {
|
||
const model = buildHierarchy(fixture());
|
||
const list = sections(model, ['renamed_away']);
|
||
assert.equal(list.length, 3, 'a missing DUT still costs three sections');
|
||
assert.equal(list[0].root, undefined);
|
||
assert.deepEqual(shape(model, list), [
|
||
'DUT: renamed_away',
|
||
' renamed_away is not in the index',
|
||
'Parents of renamed_away',
|
||
' renamed_away is not in the index',
|
||
'Other modules',
|
||
' lonely',
|
||
' other_top',
|
||
' tb',
|
||
' u_dut (dut)',
|
||
' u_l1 (leaf1)',
|
||
' u_l2 (leaf2)',
|
||
' u_l3 (leaf3)',
|
||
]);
|
||
const notice = openEverything(model, list).rows.find((row) => row.kind === 'notice');
|
||
assert.equal(notice.hasChildren, false);
|
||
assert.equal(notice.warning, true);
|
||
}
|
||
|
||
function twoDeclarationsOfOneNameAreMarkedAmbiguous() {
|
||
const raw = fixture();
|
||
raw.files.push('file:///dut-again.sv');
|
||
raw.modules.push({ moduleName: 'dut', definition: site(7, 0, 7, 10), instances: [] });
|
||
const model = buildHierarchy(raw);
|
||
const [dut, parents] = sections(model, ['dut']);
|
||
assert.equal(dut.ambiguous, true);
|
||
assert.equal(parents.ambiguous, true);
|
||
assert(dut.root, 'the first declaration in the model’s order is what is shown');
|
||
const header = sectionRows(model, [dut], new Set(), '').rows[0];
|
||
assert.equal(header.detail, 'ambiguous');
|
||
}
|
||
|
||
function sectionsAreCollapsedUntilOpenedAndOnlyTheDutOnesOpenByDefault() {
|
||
const model = buildHierarchy(fixture());
|
||
const list = sections(model, ['dut']);
|
||
const closed = sectionRows(model, list, new Set(), '');
|
||
assert.deepEqual(
|
||
closed.rows.map((row) => row.label),
|
||
['DUT: dut', 'Parents of dut', 'Other modules'],
|
||
'a closed section builds none of its tree',
|
||
);
|
||
assert(closed.rows.every((row) => row.kind === 'section' && row.hasChildren && !row.expanded));
|
||
|
||
const seeded = new Set(defaultOpenIds(list));
|
||
assert.deepEqual([...seeded], ['sec:dut:dut', 'dut:dut/root:file:///dut.sv#0:7',
|
||
'sec:parents:dut', 'parents:dut/up:file:///dut.sv#0:7']);
|
||
assert(!seeded.has('sec:others'), 'others is not opened for the user');
|
||
assert.deepEqual(
|
||
sectionRows(model, list, seeded, '').rows.map((row) => row.label),
|
||
['DUT: dut', 'dut', 'u_l1 (leaf1)', 'u_l2 (leaf2)', 'u_l3 (leaf3)',
|
||
'Parents of dut', 'dut', 'tb', 'Other modules'],
|
||
'starring opens the two sections and the DUT row inside each, one level',
|
||
);
|
||
}
|
||
|
||
function sectionRowsMatchTheShapeTheViewAlreadyRenders() {
|
||
const model = buildHierarchy(fixture());
|
||
const list = sections(model, ['dut']);
|
||
const { rows } = openEverything(model, list);
|
||
const keys = ['id', 'kind', 'label', 'detail', 'depth', 'hasChildren', 'expanded',
|
||
'warning', 'bookmarked'];
|
||
for (const row of rows) {
|
||
for (const key of keys) assert(key in row, `${key} is missing from ${row.label}`);
|
||
assert.equal(typeof row.depth, 'number');
|
||
}
|
||
// Depth 0 is the header; everything under it is one level deeper than the
|
||
// plain tree would put it.
|
||
assert.equal(rows.filter((row) => row.depth === 0).length, 3);
|
||
}
|
||
|
||
/** A bookmark is a path, and it is painted wherever that path is on screen —
|
||
* behind the section prefix as readily as at the top level. */
|
||
function aBookmarkIsPaintedWhereverItsPathIsShown() {
|
||
const model = buildHierarchy(fixture());
|
||
const openAll = (list) => {
|
||
const expanded = new Set();
|
||
for (let pass = 0; pass < 12; pass += 1) {
|
||
for (const row of sectionRows(model, list, expanded, '').rows) {
|
||
if (row.hasChildren) expanded.add(row.id);
|
||
}
|
||
}
|
||
return expanded;
|
||
};
|
||
|
||
// Bookmarked from inside the DUT section, the path is DUT-relative
|
||
// (`dut.u_l2`) — which resolves only because `bookmarkChain` retries over
|
||
// every module — and it is found behind the section's prefix.
|
||
const starred = sections(model, ['dut']);
|
||
const inDut = sectionRows(model, starred, openAll(starred), 'dut.u_l2').rows
|
||
.filter((row) => row.bookmarked);
|
||
assert.equal(inDut.length, 1);
|
||
assert.equal(inDut[0].label, 'u_l2 (leaf2)');
|
||
assert(inDut[0].id.startsWith('dut:dut/'));
|
||
assert.deepEqual(sectionPrefixes(['dut']), ['dut:dut/', 'parents:dut/']);
|
||
|
||
// Bookmarked from the others section, the path is the ordinary one and the
|
||
// ordinary id matches.
|
||
const elsewhere = sections(model, ['other_top']);
|
||
const inOthers = sectionRows(model, elsewhere, openAll(elsewhere), 'tb.u_dut.u_l2').rows
|
||
.filter((row) => row.bookmarked);
|
||
assert.equal(inOthers.length, 1);
|
||
assert.equal(inOthers[0].label, 'u_l2 (leaf2)');
|
||
|
||
// The documented consequence: a path whose root the exclusion removed is not
|
||
// on screen, so nothing is painted. The bookmark is not dropped — the model
|
||
// still resolves it — and unstarring brings it back.
|
||
const hidden = sectionRows(model, starred, openAll(starred), 'tb.u_dut.u_l2').rows
|
||
.filter((row) => row.bookmarked);
|
||
assert.equal(hidden.length, 0, 'tb is above the DUT, so that path has no rows');
|
||
assert(idForPathStillResolves(model, 'tb.u_dut.u_l2'), 'and the bookmark survives');
|
||
}
|
||
|
||
function idForPathStillResolves(model, path) {
|
||
return Boolean(require('./hierarchyModel').idForPath(model, path));
|
||
}
|
||
|
||
function contextValuesAndMenusSayWhatEachRowOffers() {
|
||
const model = buildHierarchy(fixture());
|
||
const list = sections(model, ['dut']);
|
||
const { rows } = openEverything(model, list);
|
||
const decorated = decorate(rows, ['dut'], []);
|
||
const byLabel = (label) => decorated.find((row) => row.label === label);
|
||
assert.equal(byLabel('DUT: dut').contextValue, 'section');
|
||
assert.equal(byLabel('dut').contextValue, 'module.dut', 'the starred module offers Unstar');
|
||
assert.equal(byLabel('tb').contextValue, 'module', 'any other module offers Star');
|
||
assert.equal(byLabel('u_l1 (leaf1)').contextValue, 'instance');
|
||
|
||
// An instance row is starred by its type, not by its instance name — checked
|
||
// on the plain rows, where `u_dut` is on screen (with `dut` starred its own
|
||
// root is above the DUT and excluded).
|
||
const plain = decorate(treeRows(model, new Set(openEverything(model, sections(model, []))
|
||
.rows.map((row) => row.id)), '').rows, ['dut'], []);
|
||
assert.equal(plain.find((row) => row.label === 'u_dut (dut)').contextValue, 'instance.dut');
|
||
assert.equal(plain.find((row) => row.label === 'tb').contextValue, 'module');
|
||
|
||
const table = menuTable();
|
||
assert.deepEqual(table.section, []);
|
||
assert.deepEqual(table.module.map((item) => item.action), ['starDut']);
|
||
assert.deepEqual(table['module.dut'].map((item) => item.action), ['unstarDut']);
|
||
assert.deepEqual(table.instance.map((item) => item.action),
|
||
['copyPath', 'definition', 'instance', 'bookmark', 'openRight', 'starDut']);
|
||
assert.deepEqual(table['instance.dut'].map((item) => item.action),
|
||
['copyPath', 'definition', 'instance', 'bookmark', 'openRight', 'unstarDut']);
|
||
// Every contextValue `decorate` can produce must have a menu, or a row would
|
||
// silently offer nothing.
|
||
for (const kind of ['section', 'notice', 'module', 'instance']) {
|
||
for (const suffix of ['', '.dut', '.dut.locked']) {
|
||
if ((kind === 'section' || kind === 'notice') && suffix !== '') continue;
|
||
assert(Array.isArray(table[`${kind}${suffix}`]), `no menu for ${kind}${suffix}`);
|
||
}
|
||
}
|
||
}
|
||
|
||
function aDutFromTheSettingsIsLockedAndSaysWhy() {
|
||
const model = buildHierarchy(fixture());
|
||
const list = sections(model, ['dut']);
|
||
const decorated = decorate(openEverything(model, list).rows, ['dut'], ['dut']);
|
||
const row = decorated.find((candidate) => candidate.label === 'dut');
|
||
assert.equal(row.contextValue, 'module.dut.locked');
|
||
assert.match(row.title, /lucisv\.hierarchy\.duts/, 'the tooltip names the setting');
|
||
const [item] = menuTable()['module.dut.locked'];
|
||
assert.equal(item.disabled, true);
|
||
assert.equal(item.action, 'lockedDut');
|
||
assert.equal(item.title, LOCKED.title);
|
||
}
|
||
|
||
/** The pane with no DUT starred is the pane as it was: `sections()` is not on
|
||
* the path at all, and the rows the view sends are `treeRows`' own. */
|
||
function thePlainViewIsUntouched() {
|
||
const model = buildHierarchy(fixture());
|
||
const open = new Set(treeRows(model, new Set(), '').rows.map((row) => row.id));
|
||
const plain = treeRows(model, open, '');
|
||
const decorated = decorate(plain.rows, [], []);
|
||
const visible = ['id', 'kind', 'label', 'detail', 'depth', 'hasChildren', 'expanded',
|
||
'warning', 'bookmarked'];
|
||
for (let at = 0; at < plain.rows.length; at += 1) {
|
||
for (const key of visible) {
|
||
assert.deepEqual(decorated[at][key], plain.rows[at][key], `${key} changed on ${plain.rows[at].label}`);
|
||
}
|
||
assert.equal(decorated[at].contextValue, plain.rows[at].kind, 'nothing is a DUT');
|
||
assert.equal(decorated[at].title, undefined);
|
||
}
|
||
assert.deepEqual(plain.rows.map((row) => row.label),
|
||
['lonely', 'other_top', 'tb', 'u_dut (dut)']);
|
||
}
|
||
|
||
/** The commands the menus and the pane's own rows fire have to exist, and the
|
||
* view's title entries have to be gated on this view. */
|
||
function packageJsonContributesTheCommandsMenusAndSetting() {
|
||
const manifest = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
|
||
const commands = manifest.contributes.commands.map((command) => command.command);
|
||
for (const name of ['lucisv.hierarchy.starDut', 'lucisv.hierarchy.unstarDut',
|
||
'lucisv.hierarchy.clearDuts']) {
|
||
assert(commands.includes(name), `${name} is not contributed`);
|
||
}
|
||
const title = manifest.contributes.menus['view/title'];
|
||
for (const name of ['lucisv.hierarchy.starDut', 'lucisv.hierarchy.unstarDut',
|
||
'lucisv.hierarchy.clearDuts', 'lucisv.hierarchy.refresh',
|
||
'lucisv.hierarchy.clearBookmark']) {
|
||
const entry = title.find((item) => item.command === name);
|
||
assert(entry, `${name} has no view/title entry`);
|
||
assert.equal(entry.when, 'view == lucisv.hierarchy', `${name}'s when clause`);
|
||
}
|
||
const setting = manifest.contributes.configuration.properties['lucisv.hierarchy.duts'];
|
||
assert.equal(setting.type, 'array');
|
||
assert.equal(setting.items.type, 'string');
|
||
assert.deepEqual(setting.default, []);
|
||
// Every action the menu table can post must be one the view answers; the
|
||
// view's own test covers the answering, this pins the vocabulary.
|
||
const actions = new Set(Object.values(menuTable()).flat().map((item) => item.action));
|
||
assert.deepEqual([...actions].sort(), ['bookmark', 'copyPath', 'definition', 'instance',
|
||
'lockedDut', 'openRight', 'starDut', 'unstarDut']);
|
||
}
|
||
|
||
/** The upward walk must not cost a pass over the design per opened row: the
|
||
* reverse index is built once and reused. */
|
||
function theReverseIndexIsBuiltOncePerSnapshot() {
|
||
const model = buildHierarchy(fixture());
|
||
const list = sections(model, ['dut']);
|
||
assert(model.parentsByTarget instanceof Map, 'memoized on the model');
|
||
const first = model.parentsByTarget;
|
||
openEverything(model, list);
|
||
sections(model, ['leaf1']);
|
||
assert.equal(model.parentsByTarget, first, 'and never rebuilt for the same snapshot');
|
||
}
|
||
|
||
for (const test of [
|
||
noDutIsOneSectionAndThePlainRoots,
|
||
oneDutIsThreeSectionsAndTwoAreFive,
|
||
theDutSectionIsTheForwardSubtreeAndTheParentsSectionIsTheUpwardTree,
|
||
othersHoldsEveryModuleOutsideEveryDut,
|
||
aModuleUnderAnExcludedBenchIsReRootedInOthers,
|
||
aModuleUnderTwoExcludedBenchesIsReRootedOnce,
|
||
aModuleWithOneOrdinaryParentIsNotReRooted,
|
||
twoDutsSharingABenchLeaveOthersCorrect,
|
||
aCycleReachableOnlyThroughAnExcludedBenchStillHasARoot,
|
||
aModuleBothBelowOneDutAndAboveAnotherIsInBothSections,
|
||
theParentsWalkCutsACycle,
|
||
aStarredNameTheSnapshotLacksKeepsItsSections,
|
||
twoDeclarationsOfOneNameAreMarkedAmbiguous,
|
||
sectionsAreCollapsedUntilOpenedAndOnlyTheDutOnesOpenByDefault,
|
||
sectionRowsMatchTheShapeTheViewAlreadyRenders,
|
||
aBookmarkIsPaintedWhereverItsPathIsShown,
|
||
contextValuesAndMenusSayWhatEachRowOffers,
|
||
aDutFromTheSettingsIsLockedAndSaysWhy,
|
||
thePlainViewIsUntouched,
|
||
packageJsonContributesTheCommandsMenusAndSetting,
|
||
theReverseIndexIsBuiltOncePerSnapshot,
|
||
]) test();
|
||
|
||
console.log('hierarchy sections: OK — three sections per DUT, five for two, the upward tree, cycles cut, missing names, others holding and re-rooting everything outside every DUT, menus, the setting lock, and the plain view untouched');
|