feat(junction): enforce stage3 geometry validation on save
This commit is contained in:
1 parent
cb55b3ad68
commit
63c6cefce7
9 files changed
+90
No files matched your search
@@ -289,3 +289,12 @@ warning, and blocking/invariant fields; a profile is metadata and rule
|
||||
configuration, not a client-side save decision. Keep the compiler as the sole
|
||||
producer of structure and diagnostics so the client cannot reclassify a
|
||||
junction from node counts.
|
||||
## 15. Save-time geometry validation
|
||||
|
||||
`saveEdits()` must run the same `resolveDirectEditConstraints()` used by
|
||||
`editPreview()` after validating the candidate document and before writing it.
|
||||
Any diagnostic with `severity: 'error'` returns HTTP 400 and leaves the active
|
||||
document byte-identical; warnings remain saveable. This prevents a client from
|
||||
skipping preview and persisting a width, corner radius, crossing offset, or
|
||||
stop-line value that the compiler rejects. Version conflicts are checked first
|
||||
and continue to return HTTP 409 without invoking geometry validation writes.
|
||||
@@ -0,0 +1,2 @@
|
||||
{"file":".trellis/spec/backend/direct-edit-api.md","reason":"Verify 400/no-write behavior for blocking diagnostics."}
|
||||
{"file":".trellis/spec/frontend/quality-guidelines.md","reason":"Run frontend quality gates."}
|
||||
@@ -0,0 +1,5 @@
|
||||
# 技术设计
|
||||
|
||||
保存入口 `workbench/server.js:saveEdits` 在版本检查和文档校验后,调用现有 `resolveDirectEditConstraints`。若返回 `severity=error` 的诊断,返回 400,不调用 `saveEditDocument`;否则保持原子保存流程。preview 路径已经调用同一 solver,因此两者规则一致。
|
||||
|
||||
不改变客户端 `isBlocking`、EditSession 或几何生成器。现有 solver 的约束范围和几何不变量继续作为权威;标准档的推荐范围只产生诊断,不改变保存门禁。
|
||||
@@ -0,0 +1,3 @@
|
||||
{"file":".trellis/spec/backend/direct-edit-api.md","reason":"Save and preview must share solver and blocking invariant semantics."}
|
||||
{"file":".trellis/spec/frontend/direct-edit-client.md","reason":"Client continues to consume server diagnostics and existing reset protocol."}
|
||||
{"file":".trellis/spec/guides/cross-layer-thinking-guide.md","reason":"Trace save validation across API and compiler layers."}
|
||||
@@ -0,0 +1,5 @@
|
||||
# 实施清单
|
||||
|
||||
1. 在保存入口复用 direct-edit solver,阻止 error 诊断并保留版本冲突语义。
|
||||
2. 增加非法路口参数不写入的 API 回归测试。
|
||||
3. 运行 `npm test`、客户端单测、类型检查、格式检查和构建。
|
||||
@@ -0,0 +1,18 @@
|
||||
# JunctionTools Stage 3:几何参数规范校验
|
||||
|
||||
## 目标
|
||||
|
||||
将现有路口几何控制接入标准诊断,并在保存前复用同一求解器阻止明确的几何/参数不变量违规。
|
||||
|
||||
## 范围
|
||||
|
||||
- 校验进口宽度、进口退让、角部圆角、斑马线退让/尺寸和停止线退距。
|
||||
- 保持 `pass/warning/blocking` 语义;warning 可预览和保存,blocking 拒绝保存并返回可定位诊断。
|
||||
- 复用 direct-edit solver,不新增客户端几何计算。
|
||||
|
||||
## 验收标准
|
||||
|
||||
1. 非法路口宽度保存返回 400 且 active document 不变。
|
||||
2. 合法宽度、现有控制线编辑和普通路口回归继续通过。
|
||||
3. preview 与 save 使用同一约束求解结果;诊断包含 rule/message/subject。
|
||||
4. 后端回归、客户端检查、格式检查和构建通过。
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"id": "junctiontools-stage3-geometry-validation",
|
||||
"name": "junctiontools-stage3-geometry-validation",
|
||||
"title": "JunctionTools Stage 3 几何参数规范校验",
|
||||
"description": "",
|
||||
"status": "planning",
|
||||
"dev_type": null,
|
||||
"scope": null,
|
||||
"package": null,
|
||||
"priority": "P2",
|
||||
"creator": "dingkang",
|
||||
"assignee": "dingkang",
|
||||
"createdAt": "2026-09-07",
|
||||
"completedAt": null,
|
||||
"branch": null,
|
||||
"base_branch": "main",
|
||||
"worktree_path": null,
|
||||
"commit": null,
|
||||
"pr_url": null,
|
||||
"subtasks": [],
|
||||
"children": [],
|
||||
"parent": null,
|
||||
"relatedFiles": [],
|
||||
"notes": "",
|
||||
"meta": {}
|
||||
}
|
||||
@@ -154,6 +154,16 @@ const junctionSaved = saveEdits(area, {
|
||||
operations: junctionOperations,
|
||||
});
|
||||
assert.equal(junctionSaved.documentVersion, 3);
|
||||
assert.throws(
|
||||
() =>
|
||||
saveEdits(area, {
|
||||
expectedDocumentVersion: 3,
|
||||
constraints: [{ ...junctionConstraint, value: { widthMeters: 1 } }],
|
||||
operations: [junctionOperation],
|
||||
}),
|
||||
(error) => error.statusCode === 400 && /不能小于/.test(error.message),
|
||||
'blocking junction geometry diagnostics must prevent saving',
|
||||
);
|
||||
const junctionCompiled = compileInput({
|
||||
...input,
|
||||
outDir: path.join(workspace, 'outputs', 'junction-with-edits'),
|
||||
|
||||
@@ -446,6 +446,18 @@ function saveEdits(area, body = {}) {
|
||||
...(Array.isArray(body.operations) ? { operations: body.operations } : {}),
|
||||
documentVersion: current.documentVersion,
|
||||
};
|
||||
const model = compileRoadModel(fs.readFileSync(area.input, 'utf8'), loadOverrides(area.outputs.nativeRoadOverrides));
|
||||
const resolution = resolveDirectEditConstraints(model, candidate, {
|
||||
revisionId: initialized.active.activeRevisionId,
|
||||
compilerGeometryVersion: GEOMETRY_VERSION,
|
||||
});
|
||||
const blockingDiagnostic = resolution.diagnostics.find((item) => item.severity === 'error');
|
||||
if (blockingDiagnostic) {
|
||||
const error = new Error(blockingDiagnostic.message);
|
||||
error.statusCode = 400;
|
||||
error.diagnostic = blockingDiagnostic;
|
||||
throw error;
|
||||
}
|
||||
const saved = saveEditDocument(initialized.paths.activeEdits, candidate);
|
||||
writeJsonAtomic(initialized.paths.activeState, {
|
||||
...initialized.active,
|
||||
|
||||
Reference in new issue
Block a user