merge sandbox/7975338+28c26c5+cd2cfc4: chg_0004 experiment_platform_frontend — React SPA 4 views + 5 components + Vite proxy + 14 e2e cases (gate PASS)

- docs/dth/experiment-platform/web-design.md: T1 架构设计
- src/frontend/src/main.tsx + App.tsx: 入口 + 路由
- src/frontend/src/api/{auth,operators,runs,client}.ts: 4 文件
- src/frontend/src/components/{AuthContext,ProtectedRoute,OperatorCard,RunResult,Radar}.tsx: 5 组件(Radar SVG 自绘 139 行)
- src/frontend/src/views/{Login,Dashboard,OperatorList,Run}.tsx: 4 页
- src/frontend/src/styles.css: 159 行(< 200 预算,无 UI 库)
- src/frontend/vite.config.ts: proxy /api → :30000
- tests/e2e/dth_frontend.test.sh: 14 case (5 API + 4 routes + 2 static + 3 list)
- openspec/changes/chg_0004_experiment_platform_frontend/{5 工件}
- package-lock.json: +react/react-dom/react-router-dom/axios + vite/typescript

Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
xstudio agentandClaude Opus 4.8 committed 2026-09-28 11:42:47 +08:00
1 parent a94f40e42e
commit 10acc8114d
30 files changed
+3724 -4

No files matched your search

@@ -0,0 +1,50 @@
---
change_id: chg_0004
status: proposed
owner: pm@dth
stakeholders: [pd, dev, qa]
priority: P1
target_release: v0.3
created: 2026-09-28
skip_coverage: false
---
# Change: SP-1 实验台 React 前端 MVP(4 页 + 3 组件)
## Why
chg_0002 落地了后端(NestJS + PGlite,3 个 demo 算子 hello-mpc / pir / vertical-lr,admin 登录,21 条 perm-smoke 全绿)。前端现在只有 package.json + index.html 壳,没法给用户 / 教师 / 学生用。本 chg 落地完整 React 前端。
## Who
- 高校教师:浏览器跑实验、查看可视化结果
- 学生:发起 run、查看 run_id 与结果
- 平台运营:管理界面基础
## Scope
- 4 页:Login / Dashboard / OperatorList / Run
- 3 组件:OperatorCard / RunResult / Radar(能力雷达图,mock 数据)
- 路由:react-router-dom v6
- API 客户端:axios,token 走 localStorage
- Vite proxy:`/api/*` → `http://127.0.0.1:30000`
- e2e:tests/e2e/dth_frontend.test.sh 走 curl + 后端真接口(不需 Playwright)
## Non-Goals
- 不做组件库沉淀
- 不做 E2E 浏览器测试(Playwright 等下次)
- 不做实时 WebSocket / run 进度推送(用 polling / GET 拉结果)
- 不做后端修改(chg_0002 已定)
## Impact
- 新 capability `experiment_platform_web`(独立元能力,不与 backend 共享 S 编号)
## Acceptance
- [ ] `npm run dev` 在 5173 起来,浏览器能登录(admin/123456)
- [ ] Dashboard 显示 3 个统计卡(mock:实验总数 / 算子数 / 学员数)
- [ ] OperatorList 列出 3 个算子卡片(hello-mpc / pir / vertical-lr)
- [ ] 点 hello-mpc 卡片到 Run 页,submit 表单 → 拿 run_id → GET /runs/:id 显示 output_json
- [ ] 能力雷达图 mock 数据按算子类型差异化(hello-mpc=基础;pir=检索;vertical-lr=LR 5 项)
- [ ] 未登录访问 /dashboard 等非 /login 路由 → 跳 /login
- [ ] bad login 显示 401 文案
- [ ] check_spec_coverage.sh gap=0
## Rollout
合并 main;`./run.sh dev` 同启 backend 30000 + frontend 5173。
@@ -0,0 +1,47 @@
---
change_id: chg_0004
owner: pd@dth
status: draft
requires_human_validation: false
---
# Spec: experiment_platform_web
## Requirement
提供 React SPA 前端,承载用户登录 + 实验台 dashboard + 算子运行 + 结果可视化能力。
## ADDED Scenarios
### S1 page_login_form_submit
- **WHEN** 用户访问 `http://127.0.0.1:5173/login` 输入 admin / 123456 后 submit
- **THEN** 调用 `POST /api/ssw/dth/auth/login`,body `{username:"admin",password:"123456"}`
- **AND** 成功后 token 存 localStorage,路由跳 `/dashboard`
### S2 page_login_success_redirect_to_dashboard
- **WHEN** 登录成功
- **THEN** 路由跳 `/dashboard`,dashboard 渲染 3 张统计卡
### S3 page_login_failure_show_401_message
- **WHEN** 登录错误密码
- **THEN** 后端返 `{code:401,msg:"凭据无效"}`(来自 envelope)
- **AND** 前端表单下显示红色错误条 "登录失败:凭据无效"
### S4 page_operator_list_shows_three_cards
- **WHEN** 已登录用户访问 `/operators`
- **THEN** 调 `GET /api/ssw/dth/experiment/operators`(带 Bearer token)
- **AND** 渲染 N 张 OperatorCard,每张含 code / name / version / "运行"按钮
### S5 page_run_form_submit_starts_run_with_run_id
- **WHEN** 用户在 `/operators/hello-mpc/run` 表单填 `{x:42}` submit
- **THEN** 调 `POST /api/ssw/dth/experiment/runs` body `{operator:"hello-mpc",input:{x:42}}`
- **AND** 响应 `data.run_id` 36 位 UUID 渲染在结果区
### S6 page_run_result_shows_output_json_with_real_data
- **WHEN** run 状态 success
- **THEN** 调 `GET /api/ssw/dth/experiment/runs/:id`
- **AND** RunResult 组件渲染 `data.output_json` 真字段(output_json.ok=true + echo.x=42)
- **AND** Radar 组件按算子类型显示 5 项雷达分数(hello_mpc=基础5项;pir=检索5项;vertical-lr=LR 5项)
## UX / Interaction(UI 类变更填写)
- 原型位置:先 MVP,4 页 + 简单样式;不做 design system
- 交互决策:路由跳用 react-router-dom v6 `<Navigate>`;token 校验用 `<Outlet>` 守卫
@@ -0,0 +1,54 @@
# Tasks (DAG)
- id: T1
type: architect
depends_on: []
output: docs/dth/experiment-platform/web-design.md(前端架构 + 路由表 + 状态管理决策)
verification: design.md covers 4 页 + 3 组件 + 6 场景
- id: T2
type: implementer
depends_on: [T1]
output: src/frontend/src/{main.tsx,App.tsx,vite-env.d.ts}
verification: TypeScript compile 0 error
- id: T3
type: implementer
depends_on: [T2]
output: src/frontend/src/api/{auth,operators,runs,client}.ts
verification: 4 文件 + token 走 localStorage + axios interceptor
- id: T4
type: implementer
depends_on: [T3]
output: src/frontend/src/components/{AuthContext,OperatorCard,RunResult,Radar,ProtectedRoute}.tsx
verification: 5 组件 import 0 error
- id: T5
type: implementer
depends_on: [T4]
output: src/frontend/src/views/{Login,Dashboard,OperatorList,Run}.tsx
verification: 4 页含全部 UI 元素
- id: T6
type: implementer
depends_on: [T2]
output: src/frontend/vite.config.ts(含 proxy /api → :30000)
verification: dev server 起来 5173 + proxy 生效
- id: T7
type: implementer
depends_on: [T5, T6]
output: src/frontend/src/styles.css(最小 CSS reset + 4 页简单样式)
verification: 不引入额外 UI 库;总样式 < 200 行
- id: T8
type: tester
depends_on: [T7]
output: tests/e2e/dth_frontend.test.sh(6 case 走 curl + 后端真接口)
verification: 6/6 pass
- id: T9
type: qa
depends_on: [T8]
output: PROJECT_ROOT=. bash openspec/scripts/check_spec_coverage.sh
verification: stdout PASS gap=0
@@ -0,0 +1,26 @@
# spec: experiment_platform_web@chg_0004
scenarios:
- id: S1
cases: [C1_curl_login_success_returns_token]
- id: S2
cases: [C1_curl_login_success_returns_token]
- id: S3
cases: [C2_curl_login_wrong_password_returns_401]
- id: S4
cases: [C3_curl_list_operators_returns_three, C6_static_routes_resolve]
- id: S5
cases: [C4_curl_run_hello_mpc_returns_uuid, C6_static_routes_resolve]
- id: S6
cases: [C5_curl_get_run_returns_real_output, C6_static_routes_resolve]
- id: 全部
cases: [C7_test_runner_passes_all, C8_check_spec_coverage_gap_zero]
gate:
blocking_gap_tolerance: 0
implementation_files:
- src/frontend/src/
- src/frontend/vite.config.ts
- src/frontend/index.html
- tests/e2e/dth_frontend.test.sh
test_files:
- tests/e2e/
@@ -0,0 +1,81 @@
---
change_id: chg_0004
owner: qa@dth
status: draft
spec_ref: spec.md
---
# Testcases
## Cases
### C1_curl_login_success_returns_token
- Scenario: S1, S2
- Type: integration
- Priority: P0
- Given: 后端在 30000 运行(admin seed 已加载)
- When: curl -X POST :30000/api/ssw/dth/auth/login -d '{"username":"admin","password":"123456"}'
- Then: data.token 非空字符串
- Bound Task: T8
### C2_curl_login_wrong_password_returns_401
- Scenario: S3
- Type: integration
- Priority: P0
- Given: 后端运行
- When: curl ... login 错密码
- Then: code=401, msg 含"凭据"
- Bound Task: T8
### C3_curl_list_operators_returns_three
- Scenario: S4
- Type: integration
- Priority: P0
- Given: admin token
- When: GET /api/ssw/dth/experiment/operators
- Then: data 数组长度 ≥ 3,每项含 code/name/version/schema
- Bound Task: T8
### C4_curl_run_hello_mpc_returns_uuid
- Scenario: S5
- Type: integration
- Priority: P0
- Given: admin token
- When: POST /runs body={"operator":"hello-mpc","input":{"x":42}}
- Then: data.run_id 匹配 UUID 正则
- Bound Task: T8
### C5_curl_get_run_returns_real_output
- Scenario: S6
- Type: integration
- Priority: P0
- Given: 已 run 的 run_id
- When: GET /runs/:id
- Then: data.output_json.ok == true AND echo.x == 42
- Bound Task: T8
### C6_static_routes_resolve
- Scenario: S4, S5, S6
- Type: integration
- Priority: P1
- When: 前端 src/frontend/src/App.tsx 加载
- Then: 4 路由 `/login` `/dashboard` `/operators` `/operators/:code/run` 全部有对应 view
- Bound Task: T8
### C7_test_runner_passes_all
- Scenario: 全部
- Type: e2e
- Priority: P0
- Given: 后端 + 前端就位
- When: bash tests/e2e/dth_frontend.test.sh
- Then: exit 0
- Bound Task: T8
### C8_check_spec_coverage_gap_zero
- Scenario: 全部
- Type: e2e
- Priority: P0
- Given: chg 工件齐备
- When: PROJECT_ROOT=. bash openspec/scripts/check_spec_coverage.sh
- Then: stdout PASS gap=0
- Bound Task: T9