fix(compile): validate direct edit constraint ranges

This commit is contained in:
que01 committed 2026-09-01 14:28:24 +08:00
1 parent bb108267e3
commit 0318876e6a
7 files changed
+238 -11

No files matched your search

+85 -1
View File
@@ -184,6 +184,90 @@ const anchoredHandle = anchoredResolution.handles.handles.find(
);
assert.equal(anchoredHandle.constraintId, 'edge-on-road-a');
// The published edge extrema are solver extrema, not the segment's combined
// directional width. Submitting either endpoint must be accepted by the same
// resolver that published it.
for (const side of ['left', 'right']) {
const handle = junctionResolution.handles.handles.find(
(item) => item.kind === 'road-edge-offset' && item.anchor.roadId === 'road:a' && item.anchor.side === side,
);
assert.ok(handle);
const endpoint = resolveDirectEditConstraints(
junctionModel,
document([
constraint({
id: `edge-endpoint-${side}`,
anchor: { ...handle.anchor },
value: { offsetMeters: handle.value.min, transition: 'smoothstep' },
}),
]),
);
assert.equal(endpoint.constraintStates[0].applied, true, `${side} min must be solver-accepted`);
assert.deepEqual(endpoint.diagnostics, []);
const maxEndpoint = resolveDirectEditConstraints(
junctionModel,
document([
constraint({
id: `edge-endpoint-max-${side}`,
anchor: { ...handle.anchor },
value: { offsetMeters: handle.value.max, transition: 'smoothstep' },
}),
]),
);
assert.equal(maxEndpoint.constraintStates[0].applied, true, `${side} max must be solver-accepted`);
assert.deepEqual(maxEndpoint.diagnostics, []);
}
// A value that was legal on the original road becomes stale when a reimport
// narrows that road's feasible range. It must not be replayed into geometry.
const savedEdge = constraint({
id: 'saved-edge',
anchor: { type: 'road-interval', roadId: 'road:a', startStation: 0.2, endStation: 0.8, side: 'left' },
value: { offsetMeters: 2.5, transition: 'smoothstep' },
});
const widenedModel = { ...junctionModel, roads: junctionModel.roads.map((road) => ({ ...road, widthMeters: 6 })) };
const narrowedModel = { ...junctionModel, roads: junctionModel.roads.map((road) => ({ ...road, widthMeters: 4 })) };
assert.equal(resolveDirectEditConstraints(widenedModel, document([savedEdge])).constraintStates[0].status, 'exact');
const narrowed = resolveDirectEditConstraints(narrowedModel, document([savedEdge]), { replay: true });
assert.deepEqual(narrowed.constraintStates[0], {
constraintId: 'saved-edge',
kind: 'road-edge-offset',
status: 'stale',
applied: false,
reason: 'range-out-of-bounds',
});
assert.equal(narrowed.roadProfiles.size, 0);
assert.deepEqual(narrowed.diagnostics, []);
// A new preview draft is invalid, not stale: the server must expose a blocking
// diagnostic when a client bypasses the manifest and submits an out-of-range value.
const previewInvalid = resolveDirectEditConstraints(
junctionModel,
document([
constraint({
id: 'preview-invalid-edge',
anchor: savedEdge.anchor,
value: { offsetMeters: 99, transition: 'smoothstep' },
}),
]),
);
assert.equal(previewInvalid.constraintStates[0].status, 'exact');
assert.equal(previewInvalid.constraintStates[0].applied, false);
assert.ok(previewInvalid.diagnostics.some((item) => item.rule === 'direct-edit-edge-offset-out-of-range'));
const bothEdges = resolveDirectEditConstraints(
junctionModel,
document([
constraint({
id: 'both-edges',
anchor: { type: 'road-interval', roadId: 'road:a', startStation: 0.2, endStation: 0.8 },
value: { offsetMeters: 0.5, transition: 'smoothstep' },
}),
]),
);
assert.equal(bothEdges.constraintStates[0].applied, true);
assert.deepEqual(bothEdges.diagnostics, []);
const allKinds = [
anchored,
constraint({
@@ -295,7 +379,7 @@ for (const status of ['exact', 'recheck']) {
kind: 'road-edge-offset',
status: 'stale',
applied: false,
reason: 'status-stale',
reason: 'anchor-missing',
},
]);
assert.deepEqual(resolution.diagnostics, []);