feat(junction): establish stable complex junction structure
This commit is contained in:
1 parent
bd8b55e58b
commit
0a5a229ce3
22 files changed
+1386
-125
No files matched your search
+103
-1
@@ -7,7 +7,14 @@ const path = require('path');
|
||||
const { compileInput } = require('../src/compile/compiler');
|
||||
const { compileRoadModel, loadOverrides } = require('../src/compile/native-road');
|
||||
const { ensureRevisionStore } = require('../src/compile/road-revisions');
|
||||
const { editPreview, editState, rebaseEdits, saveEdits } = require('../workbench/server');
|
||||
const {
|
||||
editPreview,
|
||||
editState,
|
||||
rebaseEdits,
|
||||
saveEdits,
|
||||
state: browseState,
|
||||
selectionFrom,
|
||||
} = require('../workbench/server');
|
||||
const { snapshot: outputSnapshot } = require('./fixture-baseline');
|
||||
|
||||
const workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'workbench-edit-api-'));
|
||||
@@ -219,5 +226,100 @@ assert.notDeepEqual(
|
||||
'a saved constraint must change the compiled output, or saving cannot survive a refresh',
|
||||
);
|
||||
|
||||
// Typed scope must survive parsing and cannot silently choose the first key.
|
||||
assert.deepEqual(selectionFrom(new URLSearchParams('cluster=fixture-five-arm')), {
|
||||
type: 'cluster',
|
||||
id: 'fixture-five-arm',
|
||||
});
|
||||
assert.deepEqual(selectionFrom({ junction: '8005332807' }), { type: 'junction', id: '8005332807' });
|
||||
for (const invalid of [
|
||||
{ cluster: 'one', junction: 'two' },
|
||||
{ cluster: '' },
|
||||
{ cluster: {} },
|
||||
new URLSearchParams('cluster=one&cluster=two'),
|
||||
]) {
|
||||
assert.throws(() => selectionFrom(invalid), /selection/);
|
||||
}
|
||||
assert.throws(() => editPreview(area, { selection: { cluster: 'one', segment: 'two' } }), /selection/);
|
||||
|
||||
const cluster = {
|
||||
id: 'fixture-five-arm',
|
||||
template: 'complex-junction-v1',
|
||||
nodeIds: ['8005332807', '8024512135', '8024512145', '8024512147', '8613058676'],
|
||||
coreRadiusMeters: 24,
|
||||
};
|
||||
const complexInput = {
|
||||
...input,
|
||||
outDir: path.join(workspace, 'outputs', 'complex'),
|
||||
stagingDir: path.join(workspace, 'outputs', '_complex'),
|
||||
options: { edgeLines: false, junctionTemplates: { enabled: true, clusters: [cluster] } },
|
||||
};
|
||||
const complexArea = compileInput(complexInput).area;
|
||||
const clusterState = editState(complexArea, selectionFrom({ cluster: cluster.id }));
|
||||
assert.deepEqual(clusterState.handles.handles, [], 'cluster selection must never fall through to node handles');
|
||||
assert.deepEqual(clusterState.junctionStructure.junctionRef, { type: 'cluster', id: cluster.id });
|
||||
assert.equal(clusterState.junctionStructure.shape.effectiveArmCount, 5);
|
||||
assert.equal(clusterState.junctionStructure.capability.editable, false);
|
||||
const complexTracked = trackedFiles.map(({ file }) => ({
|
||||
file,
|
||||
bytes: fs.readFileSync(file),
|
||||
mtimeMs: fs.statSync(file).mtimeMs,
|
||||
}));
|
||||
const emptyDocument = { ...clusterState.document, constraints: [], operations: [] };
|
||||
const clusterPreview = editPreview(complexArea, { document: emptyDocument, selection: { cluster: cluster.id } });
|
||||
assert.deepEqual(clusterPreview.handles.handles, []);
|
||||
assert.deepEqual(
|
||||
clusterPreview.junctionStructure,
|
||||
clusterState.junctionStructure,
|
||||
'preview and persisted compiler structure agree',
|
||||
);
|
||||
const browsing = browseState(complexArea);
|
||||
const unavailableStructureState = browseState({
|
||||
...complexArea,
|
||||
nativeRoad: {
|
||||
...complexArea.nativeRoad,
|
||||
junctionTemplates: {
|
||||
...complexArea.nativeRoad.junctionTemplates,
|
||||
clusters: [
|
||||
...complexArea.nativeRoad.junctionTemplates.clusters,
|
||||
{ id: 'not-compiled', template: 'complex-junction-v1', nodeIds: ['missing-1', 'missing-2'] },
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
assert.equal(unavailableStructureState.junctionStructures['cluster:not-compiled'], undefined);
|
||||
assert.ok(browsing.standardsDiagnostics.length, 'browse state retains structure diagnostics');
|
||||
assert.equal(new Set(browsing.standardsDiagnostics.map((item) => item.id)).size, browsing.standardsDiagnostics.length);
|
||||
assert.ok(
|
||||
Object.values(browsing.junctionStructures).every(Boolean),
|
||||
'the structure index contains only available structures',
|
||||
);
|
||||
assert.deepEqual(browsing.junctionStructures[`cluster:${cluster.id}`], clusterState.junctionStructure);
|
||||
const simpleKey = Object.keys(browsing.junctionStructures).find(
|
||||
(key) => key.startsWith('node:') && !cluster.nodeIds.includes(key.slice(5)),
|
||||
);
|
||||
assert.ok(simpleKey, 'fixture includes a simple junction outside the cluster');
|
||||
const simpleState = editState(complexArea, selectionFrom({ junction: simpleKey.slice(5) }));
|
||||
assert.deepEqual(simpleState.junctionStructure, browsing.junctionStructures[simpleKey]);
|
||||
assert.equal(simpleState.junctionStructure.junctionRef.type, 'node');
|
||||
for (const item of clusterState.standardsDiagnostics) {
|
||||
assert.ok(browsing.standardsDiagnostics.some((candidate) => candidate.id === item.id));
|
||||
}
|
||||
assert.ok(simpleState.handles.handles.length);
|
||||
for (const type of ['cluster', 'junction']) {
|
||||
const missing = editState(complexArea, selectionFrom({ [type]: 'missing-junction' }));
|
||||
assert.equal(missing.junctionStructure, null);
|
||||
assert.deepEqual(missing.handles.handles, []);
|
||||
assert.deepEqual(missing.standardsDiagnostics, []);
|
||||
assert.equal(
|
||||
editPreview(complexArea, { document: emptyDocument, selection: { [type]: 'missing-junction' } }).junctionStructure,
|
||||
null,
|
||||
);
|
||||
}
|
||||
for (const tracked of complexTracked) {
|
||||
assert.deepEqual(fs.readFileSync(tracked.file), tracked.bytes, 'scoped reads and previews preserve active files');
|
||||
assert.equal(fs.statSync(tracked.file).mtimeMs, tracked.mtimeMs);
|
||||
}
|
||||
|
||||
fs.rmSync(workspace, { recursive: true, force: true });
|
||||
console.log('workbench edit API tests passed');
|
||||
Reference in new issue
Block a user