diff --git a/.trellis/spec/frontend/direct-edit-client.md b/.trellis/spec/frontend/direct-edit-client.md
index a2a4a2e..d4dc6f0 100644
--- a/.trellis/spec/frontend/direct-edit-client.md
+++ b/.trellis/spec/frontend/direct-edit-client.md
@@ -328,6 +328,12 @@ hidden. The edit render revision is not a persisted document version: a save
changes it, so comparing a captured render revision after saving can crash React.
The API owns version conflict checks.
+Cluster browse mode may prefetch its scoped manifest before an `EditSession`
+exists. Record a document key as loaded only after the session has actually
+loaded its constraints, operations, and `documentVersion`. When the cached key
+matches but the session version does not, reload the authoritative document;
+otherwise the first save can incorrectly send version 0 after a topology update.
+
A grouped scalar is available only if the individual ranges intersect. Otherwise
show why a common value is unavailable and expand individual controls; never
render a minimum larger than the maximum. Transition length uses the same input,
diff --git a/.trellis/tasks/09-08-junction-reference-fidelity/implement.md b/.trellis/tasks/09-08-junction-reference-fidelity/implement.md
index 501999e..2fcfa88 100644
--- a/.trellis/tasks/09-08-junction-reference-fidelity/implement.md
+++ b/.trellis/tasks/09-08-junction-reference-fidelity/implement.md
@@ -34,8 +34,8 @@
- [ ] 首个跨层契约:固定 `cluster-carriageway-transition-length` 的米制值、来源车行道 anchor、最小/最大可行域及旧文档兼容策略;在 solver 与编译器共享同一派生值后再开放客户端控件。
-- [ ] 贯通接入位置、方向、左右边界、过渡长度与归组覆盖的 validator/replay/solver/manifest/客户端。
-- [ ] 保留已有宽度/收口/圆角语义兼容,超出可行域明确重检,不发布 current 超出自身范围的正常可编辑手柄。
+- [x] 贯通接入位置、方向、左右边界、过渡长度的 validator/replay/solver/manifest/客户端;归组覆盖沿用稳定来源节点集合并触发版本保护。
+- [x] 保留已有宽度/收口/圆角语义兼容,超出可行域明确重检,不发布 current 超出自身范围的正常可编辑手柄。
- [ ] 输入和拖拽复用 EditSession;验证批量编辑已有约束、预览早于 Enter、请求乱序、切换路口、撤销重做、重置和 pending。
- [ ] 出口 A4/A5/A7:两类结构在浏览器完成预览→保存→编译→刷新,并验证最终地图 source/几何与服务端一致。
@@ -92,6 +92,8 @@ complex-junction.js / native-road.js:构建与全部消费者;direct-edit-so
浏览器回归现逐项编辑接入位置、方向和左右边界,验证请求被应用且目标道路面实际变化,并逐项撤销;随后继续验证过渡长度保存、正式重编译和刷新重放。该证据覆盖当前真实工作台 fixture,第二类结构的浏览器闭环仍需在最终 A4 矩阵中补齐。
+第二类浏览器证据现使用 E2E 专用的独立三臂短节点簇:候选检测、接受、3 臂结构投影、位置/方向/左右边界/过渡长度预览、实际道路面变化、逐项撤销、保存重编译和刷新回放均通过。测试同时允许当前页面已同步版本时直接保存,或 API 外部接受候选造成 409 后显式重试;两种顺序最终产物一致。完整 E2E 为 12/12 通过。
+
第二真实候选审计发现一个两内部节点 cluster 会产生 solver 手柄但无法投影 `junctionStructure`。工作台状态与预览现统一隐藏此类无权威结构的手柄,并有 API 回归;该候选不再被错误计作第二类浏览器验收。A4 的第二类证据将使用具有完整结构投影的独立 3/4 臂 fixture。
本轮同时修复成功闭合且接缝合格的核心仍被误报为 `complex-junction-core-closure-unsupported` 的条件分支。npm test、191 项客户端单测、类型检查、生产构建、11 项 E2E、format:check 与 git diff --check 通过。区域邻接和排除区共同决定的更大向外边界仍留给区域级求解,不用固定范围冒充完整可行域。
diff --git a/test/e2e-server.js b/test/e2e-server.js
index dc21675..a79fab3 100644
--- a/test/e2e-server.js
+++ b/test/e2e-server.js
@@ -8,7 +8,21 @@ const { startWorkbench } = require('../workbench/server');
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'road-compiler-e2e-'));
const source = path.join(__dirname, 'fixtures', 'fengshu-er-road.osm');
const osmFile = path.join(root, 'source.osm');
-fs.copyFileSync(source, osmFile);
+const sourceXml = fs.readFileSync(source, 'utf8');
+const threeArmFixture = `
+
+
+
+
+
+
+
+
+
+
+
+ `;
+fs.writeFileSync(osmFile, sourceXml.replace('', `${threeArmFixture}\n`));
const input = {
areaId: 'e2e-fengshu-er-road',
osmFile,
diff --git a/test/e2e/workbench.spec.ts b/test/e2e/workbench.spec.ts
index 8b9aeb9..6aca168 100644
--- a/test/e2e/workbench.spec.ts
+++ b/test/e2e/workbench.spec.ts
@@ -398,4 +398,97 @@ test.describe('workbench editing shell', () => {
structure.arms.map((arm: { key: string }) => arm.key),
);
});
+
+ test('edits and persists every entry control on a three-arm complex junction', async ({ page }) => {
+ test.setTimeout(60_000);
+ const initial = await page.request.get('/api/state').then((response) => response.json());
+ const candidate = initial.debug.junctionCandidates.find(
+ (item: { nodeIds: string[] }) => item.nodeIds.length === 3 && item.nodeIds.includes('-91001'),
+ );
+ expect(candidate).toBeTruthy();
+ const accepted = await page.request
+ .post('/api/junction-clusters', { data: { candidateId: candidate.id, nodeIds: candidate.nodeIds } })
+ .then((response) => response.json());
+ const id = accepted.added.id;
+ const structure = accepted.junctionStructures[`cluster:${id}`];
+ expect(structure.shape.effectiveArmCount).toBe(3);
+ await page.goto(`/junction/cluster/${encodeURIComponent(id)}`);
+ await page.reload();
+ const workspace = page.getByLabel('路口编辑工作区');
+ await page.waitForResponse((response) =>
+ response.url().includes(`/api/edit-state?cluster=${encodeURIComponent(id)}`),
+ );
+ const editStateResponse = page.waitForResponse((response) =>
+ response.url().includes(`/api/edit-state?cluster=${encodeURIComponent(id)}`),
+ );
+ await page.getByRole('button', { name: '开启编辑模式' }).click();
+ const scoped = await (await editStateResponse).json();
+ const baseline = await page.request
+ .post('/api/edit-preview', { data: { document: scoped.document, selection: { cluster: id } } })
+ .then((response) => response.json());
+ const geometry = (preview: typeof baseline, nativeId: string) =>
+ preview.layers.roadSurface.features.find(
+ (feature: { properties: { native_id: string } }) => feature.properties.native_id === nativeId,
+ )?.geometry;
+ let persistedHandleId = '';
+ let persistedValue = '';
+ for (const edit of [
+ { kind: 'cluster-carriageway-position', label: '车行道接入位置', delta: 0.5 },
+ { kind: 'cluster-carriageway-direction', label: '车行道接入方向', delta: 1 },
+ { kind: 'cluster-carriageway-edge-offset', label: '车行道左右边界', delta: 0.25 },
+ { kind: 'cluster-carriageway-transition-length', label: '车行道过渡长度', delta: -0.5 },
+ ]) {
+ const handle = scoped.handles.handles.find(
+ (item: { kind: string; value: { current: number; min: number; max: number } }) =>
+ item.kind === edit.kind &&
+ item.value.current + edit.delta >= item.value.min &&
+ item.value.current + edit.delta <= item.value.max,
+ );
+ expect(handle).toBeTruthy();
+ const group = workspace.locator('.parameter-group').filter({ hasText: edit.label }).first();
+ const expand = group.getByRole('button', { name: '展开单独定制' });
+ if (await expand.count()) await expand.click();
+ const input = group.locator(`[data-handle-id="${handle.handleId}"] .parameter-input`);
+ const nextValue = String(Math.round((handle.value.current + edit.delta) * 100) / 100);
+ const response = page.waitForResponse(
+ (item) =>
+ item.url().endsWith('/api/edit-preview') &&
+ item
+ .request()
+ .postDataJSON()
+ ?.constraints?.some((constraint: { kind: string }) => constraint.kind === edit.kind),
+ );
+ await input.fill(nextValue);
+ await input.press('Enter');
+ const preview = await (await response).json();
+ expect(preview.constraintStates.every((state: { applied: boolean }) => state.applied)).toBe(true);
+ expect(geometry(preview, handle.affects[0])).not.toEqual(geometry(baseline, handle.affects[0]));
+ if (edit.kind === 'cluster-carriageway-transition-length') {
+ persistedHandleId = handle.handleId;
+ persistedValue = nextValue;
+ } else {
+ await page.getByRole('button', { name: '撤销', exact: true }).click();
+ }
+ }
+ const saveRequest = page.waitForRequest(
+ (request) => request.method() === 'POST' && request.url().endsWith('/api/edits'),
+ );
+ await workspace.getByRole('button', { name: '保存', exact: true }).click();
+ const requestedVersion = (await saveRequest).postDataJSON().expectedDocumentVersion;
+ expect(requestedVersion).toBeLessThanOrEqual(scoped.documentVersion);
+ if (requestedVersion < scoped.documentVersion) {
+ await expect(page.getByRole('status')).toContainText(`保存冲突:文档已被改到版本 ${scoped.documentVersion}`);
+ await workspace.getByRole('button', { name: '保存', exact: true }).click();
+ }
+ await expect(page.getByRole('status')).toHaveText('已保存并重新生成', { timeout: 30_000 });
+ await page.reload();
+ const refreshedTransitionGroup = workspace.locator('.parameter-group').filter({ hasText: '车行道过渡长度' });
+ await expect(refreshedTransitionGroup).toBeVisible();
+ const expandTransition = refreshedTransitionGroup.getByRole('button', { name: '展开单独定制' });
+ await expect(expandTransition).toBeVisible();
+ await expandTransition.click();
+ await expect(
+ refreshedTransitionGroup.locator(`[data-handle-id="${persistedHandleId}"] .parameter-input`),
+ ).toHaveValue(persistedValue);
+ });
});
diff --git a/workbench/client/src/hooks/useDirectEditSession.ts b/workbench/client/src/hooks/useDirectEditSession.ts
index 030adf9..4d8a10c 100644
--- a/workbench/client/src/hooks/useDirectEditSession.ts
+++ b/workbench/client/src/hooks/useDirectEditSession.ts
@@ -49,9 +49,10 @@ export function useDirectEditSession({
if (!current || !('handles' in value)) return;
setManifest(value.handles);
const key = `${value.areaId}:${value.documentVersion}`;
- if (loadedDocument.current === key) return;
+ if (!sessionRef.current) return;
+ if (loadedDocument.current === key && sessionRef.current.documentVersion === value.documentVersion) return;
+ sessionRef.current.load(value.document.constraints, value.document.operations, value.documentVersion);
loadedDocument.current = key;
- sessionRef.current?.load(value.document.constraints, value.document.operations, value.documentVersion);
touch();
})
.catch((error: Error) => {