chore: archive web OSM import task

This commit is contained in:
2026-08-26 14:06:27 +08:00
parent 181e575e1e
commit f15e69c868
6 changed files with 2 additions and 2 deletions

View File

@@ -0,0 +1,2 @@
{"file":".trellis/spec/guides/cross-layer-thinking-guide.md","reason":"Verify upload-to-compile data flow and session boundary."}
{"file":".trellis/spec/guides/code-reuse-thinking-guide.md","reason":"Verify no duplicate compiler or parser logic was introduced."}

View File

@@ -0,0 +1,39 @@
# Technical Design
## Boundaries
- `bin/road-workbench.js` owns process startup and creates an import session/workspace.
- `workbench/server.js` owns HTTP routes and session-local files; it continues to call `compileInput()` for compilation.
- `workbench/client/index.html` and `workbench/client/app.js` add the upload/bootstrap state only; existing editing panels remain unchanged.
- `src/compile/compiler.js` and `src/osm.js` remain the source of truth for input validation and OSM processing.
## Data Flow
1. CLI starts a workbench with an optional existing `--input` for compatibility, or with no input for the new import-first flow.
2. The browser submits multipart OSM content (bounded by a server upload limit) to a new session/import endpoint.
3. The server validates the filename/content, creates a unique workspace directory under a configured workbench data root, and writes:
- `source.osm`
- `native-road-overrides.json` with the existing empty schema
- `native-traffic-signals.json` with the existing empty schema
- `RoadCompilerInput.json` using conservative defaults and workspace-relative output paths
4. The server calls `compileInput()` and swaps the active session from the import screen to the existing state/map view.
5. Existing routes operate against the active session's `area` object. A failed import/compile removes only the new staging directory and leaves any prior active session untouched.
## Defaults and Compatibility
- Area id is derived from a sanitized user-provided name or uploaded basename, with a unique suffix when necessary.
- `options.edgeLines` and `options.junctionTemplates` use the same shape required by `validateInput()`; no new compiler options are introduced.
- Existing `--input RoadCompilerInput.json` startup remains supported by adapting it into the same active-session context.
- The server binds to localhost as it does today and does not add authentication or remote persistence.
## Error and Recovery
- Reject empty/non-XML uploads, oversized bodies, malformed OSM, and compile failures with JSON errors suitable for the browser.
- Stage all files before switching the active session; cleanup on failure.
- Keep workspace directories recoverable on disk; do not delete an existing user workspace during a new import.
## Testing Strategy
- Unit/integration tests for workspace initialization, default input generation, upload size/content validation, and failed-import cleanup.
- HTTP smoke test for import -> state -> compile/export using the existing fixture OSM.
- Existing compiler and fixture tests remain the regression gate.

View File

@@ -0,0 +1,2 @@
{"file":".trellis/spec/guides/cross-layer-thinking-guide.md","reason":"Import spans CLI, HTTP server, filesystem workspace, compiler, and browser state."}
{"file":".trellis/spec/guides/code-reuse-thinking-guide.md","reason":"Reuse existing compiler input validation, atomic JSON writes, and workbench state routes."}

View File

@@ -0,0 +1,19 @@
# Implementation Plan
1. Read frontend/backend project specs and map the current workbench startup contract.
2. Extract small, testable helpers for session workspace creation, default `RoadCompilerInput`, and bounded OSM request handling.
3. Repair `bin/road-workbench.js` to support import-first startup while adapting legacy `--input` files.
4. Add server endpoints for upload/bootstrap and active-session state, preserving all existing edit routes.
5. Add a minimal import screen and transition in the existing client; keep the map/editor UI intact.
6. Add tests for helper validation and an HTTP import smoke path using `test/fixtures/fengshu-er-road.osm`.
7. Run `npm test`, targeted workbench tests, and manual localhost smoke checks; fix issues found.
8. Run Trellis quality check, update relevant specs if a durable convention is discovered, then commit.
Validation commands:
- `npm test`
- `node --check bin/road-workbench.js`
- `node --check workbench/server.js`
- targeted workbench test command added by this task
Rollback points: CLI/server changes can be reverted independently of compiler sources; workspace staging ensures an import failure does not alter an existing session.

View File

@@ -0,0 +1,40 @@
# Web OSM 导入工作流
## Goal
让用户无需预先编写 `RoadCompilerInput.json` 或宿主区域配置,即可通过 Web 工作台上传一个 `.osm` 文件,创建一次可编译的工作区并开始查看、调整和导出道路结果。
## Confirmed Facts
- `src/compile/compiler.js` 已提供完整的 `compileInput()`,负责读取 OSM、加载 overrides、生成原生道路图层、诊断和交通信号运行时资产。
- `src/osm.js` 已提供 OSM XML 解析;`src/compile/native-road.js` 已提供道路模型、几何编译和 overrides 校验。
- `workbench/server.js` 已提供地图状态、覆盖项保存、交通信号编辑/生成、重新编译和 ZIP 导出接口,但入口假定已有 `area`、配置加载器和编译回调。
- `workbench/client/` 已有完整的 OpenLayers 编辑界面,当前通过 `/api/state` 加载既有编译结果。
- `bin/road-workbench.js` 当前要求 `--input <RoadCompilerInput.json>`,却把 `{ input, inputFile, port }` 传给期待另一种上下文的 `startWorkbench()`,无法独立启动现有工作台。
## Requirements
1. 工作台启动后提供 OSM 文件导入入口;成功导入后自动建立编译所需的工作区文件和默认参数。
2. 导入流程复用现有 `compileInput()` 与已有编辑 API不复制道路解析或几何编译逻辑。
3. 导入后自动执行首次编译,并让现有地图、诊断、覆盖项、交通信号编辑和 ZIP 导出继续可用。
4. 导入失败时返回可理解的错误,不破坏当前已加载的工作区。
5. 保留通过现有 `RoadCompilerInput.json` 启动工作台的兼容路径(若当前入口契约可修复则继续支持)。
6. 默认参数应明确、可追溯,并允许用户在首次编译后通过已有工作台控件调整;本任务不重新设计道路算法或参数模型。
## Acceptance Criteria
- 用户运行工作台命令并打开页面,可以选择 `.osm` 文件并提交。
- 服务端保存上传内容,生成有效的 overrides、traffic-signals、输出目录和 `options`,然后完成一次 `compileInput()`;页面显示道路图层和编译诊断。
- `/api/state``/api/overrides``/api/traffic-signals``/api/compile``/api/export.zip` 在导入工作区中均正常工作。
- 非法文件、空文件、超过限制的上传或编译错误不会留下半成品工作区,并在页面显示错误。
- 现有测试继续通过,并新增覆盖入口/上传/初始化链路的自动化测试。
## Out Of Scope
- 修改 OSM 解析规则、道路几何算法、交通信号生成算法或导出包格式。
- 多用户认证、远程持久化、数据库、云端 OSM 下载和在线协作。
- 重新设计现有工作台地图编辑 UI。
## Key Decision
每次导入创建独立的本地工作区目录并在当前工作台会话中使用,避免覆盖已有区域配置。工作区保留在磁盘上,后续可通过兼容的 `--input` 方式恢复。

View File

@@ -0,0 +1,26 @@
{
"id": "web-osm-import",
"name": "web-osm-import",
"title": "Web OSM 导入工作流",
"description": "",
"status": "completed",
"dev_type": null,
"scope": null,
"package": null,
"priority": "P2",
"creator": "dingkang",
"assignee": "dingkang",
"createdAt": "2026-08-26",
"completedAt": "2026-08-26",
"branch": null,
"base_branch": "main",
"worktree_path": null,
"commit": null,
"pr_url": null,
"subtasks": [],
"children": [],
"parent": null,
"relatedFiles": [],
"notes": "",
"meta": {}
}