test(junction): verify preview and compile parity

This commit is contained in:
que01 committed 2026-09-03 13:32:37 +08:00
1 parent 3811790dc8
commit a78f5257fc
13 files changed
+71 -8

No files matched your search

+65 -2
View File
@@ -5,6 +5,7 @@ const fs = require('fs');
const os = require('os');
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 { snapshot: outputSnapshot } = require('./fixture-baseline');
@@ -110,12 +111,74 @@ const clientSaved = saveEdits(area, {
});
assert.equal(clientSaved.documentVersion, 2);
// JunctionTools uses the same preview and compile solver. Exercise a real
// junction approach handle so a geometry edit cannot be preview-only: the
// published intersection layer must be byte-equivalent after a save/recompile.
const junctionHandle = state.handles.handles.find((handle) => handle.kind === 'junction-approach-width');
assert.ok(junctionHandle, 'the fixture must publish a junction approach width handle');
const junctionModel = compileRoadModel(fs.readFileSync(input.osmFile, 'utf8'), loadOverrides(input.overridesFile));
const approach = junctionModel.roads.find((road) => road.segmentId === junctionHandle.anchor.segmentId);
assert.ok(approach, 'the junction handle must resolve to a model road');
const junctionConstraint = {
id: `constraint:${junctionHandle.handleId}`,
kind: 'junction-approach-width',
anchor: junctionHandle.anchor,
anchorSnapshot: {
coordinate: junctionHandle.position,
tangentAzimuth: junctionHandle.axisAzimuth,
roadLengthMeters: 120,
osmNodeIds: approach.sourceNodeIds,
},
value: { widthMeters: junctionHandle.value.current + 0.25 },
enabled: true,
status: 'exact',
provenance: { operationId: 'operation:client:junction-1', createdAt: '2026-08-27T00:00:01.000Z' },
};
const junctionOperation = {
id: junctionConstraint.provenance.operationId,
createdAt: junctionConstraint.provenance.createdAt,
constraintIds: [junctionConstraint.id],
};
const junctionConstraints = [clientConstraint, junctionConstraint];
const junctionOperations = [clientOperation, junctionOperation];
const junctionPreview = editPreview(area, {
previewSeq: 23,
constraints: junctionConstraints,
operations: junctionOperations,
});
assert.equal(junctionPreview.ok, true);
assert.ok(junctionPreview.layers.intersectionSurface);
const junctionSaved = saveEdits(area, {
expectedDocumentVersion: 2,
constraints: junctionConstraints,
operations: junctionOperations,
});
assert.equal(junctionSaved.documentVersion, 3);
const junctionCompiled = compileInput({
...input,
outDir: path.join(workspace, 'outputs', 'junction-with-edits'),
stagingDir: path.join(workspace, 'outputs', '_junction-with-edits'),
areaConfigSnapshotFile: initialized.paths.activeAreaConfig,
editsFile: initialized.paths.activeEdits,
});
const publishedJunction = JSON.parse(
fs.readFileSync(
path.join(junctionCompiled.area.outputs.nativeRoadDir, 'layers', 'intersection_surface.geojson'),
'utf8',
),
);
assert.deepEqual(
publishedJunction,
junctionPreview.layers.intersectionSurface,
'formal compile must publish the same junction geometry returned by preview',
);
// A save that does not survive a reload as `exact` was cosmetic.
const reloaded = editState(area);
assert.equal(reloaded.documentVersion, 2);
assert.equal(reloaded.documentVersion, 3);
assert.deepEqual(
reloaded.document.constraints.map((item) => item.id),
[clientConstraint.id],
[clientConstraint.id, junctionConstraint.id],
);
assert.equal(reloaded.constraintStates[0].status, 'exact');
assert.equal(reloaded.constraintStates[0].applied, true);