scense_demo/docs/self-test-cases.md
2026-08-29 21:10:23 +08:00

85 lines
6.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# W-07 demo 模块功能点自测(正例 + 反例)
> 依据 feature-granularity-and-testing:每个小功能点至少 1 正例 + 1 反例,期望可判定。
> 执行入口:部署到 /d/scense/scense_app 后,用登录 cookie 请求 `http://<host>:<port>/demo/api/*.dspy`。
> 数据库:宿主库(get_module_dbname('demo')),表 demo_session / demo_session_state / demo_hot_script / demo_presence。
## W-07a 开始演示(进入预览态)— POST /demo/api/start.dspy
- 正例 W-07a-pos:body `{"world_id":"w001","session_name":"产品演示"}` → 期望 `status=200` 且 `data.session_id` 非空、`data.status="preview"`、`data.camera_mode="orbit"`;库 demo_session 新增 1 行 status=preview。
- 反例 W-07a-neg-1(缺参):body `{}` → 期望 `status=400` 且 message 含 "world_id"。
- 反例 W-07a-neg-2(重复):同一 world_id 连续两次 start → 第二次期望 `status=409` 且 message 含 "已有进行中的演示会话"。
- 反例 W-07a-neg-3(世界不存在):`{"world_id":"no_such_world"}` → 期望 `status=404`(world 模块可用时)或 200(world 模块未挂载时跳过校验,防御式)。
## W-07b 结束演示(状态隔离)— POST /demo/api/stop.dspy
- 正例 W-07b-pos:对进行中会话 `{"session_id":"<sid>"}` → 期望 `status=200` 且 `data.overlay_cleared=true`;demo_session.status=ended;demo_session_state/demo_hot_script/demo_presence 中该 session_id 记录数为 0;**正式 entity/world 表无变化**。
- 反例 W-07b-neg-1(缺参):`{}` → `status=400`。
- 反例 W-07b-neg-2(不存在):`{"session_id":"no_such"}` → `status=404`。
- 反例 W-07b-neg-3(重复结束):对已 ended 会话再 stop → `status=400` 且 message 含 "已结束"。
## W-07c 编辑实体实时反映(<1s) — POST /demo/api/entity_edit.dspy
- 正例 W-07c-pos:`{"session_id":"<sid>","entity_id":"e1","fields":{"color":"#22C55E","size":2}}` → `status=200`;随后调 state.dspy,`entities[].state.color="#22C55E"`;前端轮询 500ms → **编辑后 <1s 反映**;demo_session_state.demo_json 更新、base_json 不变。
- 反例 W-07c-neg-1(缺参):缺 entity_id → `status=400`。
- 反例 W-07c-neg-2(fields 非法):fields 传数组/字符串 → `status=400` message 含 "fields 必须是对象"。
- 反例 W-07c-neg-3(会话不存在):`{"session_id":"no_such",...}` → `status=404`。
- 反例 W-07c-neg-4(会话已结束):ended 会话 → `status=400` message 含 "已结束"。
## W-07d 脚本保存热加载 — POST /demo/api/hotload.dspy
- 正例 W-07d-pos:`{"session_id":"<sid>","script_id":"s1","script_type":"python","script_content":"print('hi')"}` → `status=200` 且 `data.status="hot_loaded"`;demo_hot_script 新增 1 行;state.dspy scripts 列表可见。
- 反例 W-07d-neg-1(语法错误):content=`"def f(:"` → `status=400` message 含 "语法错误"。
- 反例 W-07d-neg-2(内容为空):content 空 → `status=400`。
- 反例 W-07d-neg-3(类型非法):script_type=`"sql"` → `status=400` message 含 "非法脚本类型"。
## W-07e 视角切换 — POST /demo/api/camera.dspy
- 正例 W-07e-pos:`{"session_id":"<sid>","camera_mode":"topdown"}` → `status=200` 且 `data.camera_mode="topdown"`;state.dspy 中 camera_mode=topdown。
- 反例 W-07e-neg-1(白名单外):`camera_mode="free"` → `status=400` message 含 "非法视角模式"。
- 反例 W-07e-neg-2(会话不存在):→ `status=404`。
- 反例 W-07e-neg-3(已结束):ended 会话 → `status=400`。
## W-07f 暂停/继续 — POST /demo/api/pause.dspy
- 正例 W-07f-pos-暂停:`{"session_id":"<sid>","paused":true}` → `status=200` 且 `data.status="paused"`。
- 正例 W-07f-pos-继续:再传 `paused:false` → `status=200` 且 `data.status="preview"`。
- 反例 W-07f-neg-1(缺参):缺 paused → `status=400`。
- 反例 W-07f-neg-2(已结束):ended 会话 → `status=400`。
## W-07g 全屏 — POST /demo/api/fullscreen.dspy
- 正例 W-07g-pos:`{"session_id":"<sid>","enabled":true}` → `status=200` 且 `data.fullscreen=true`;demo_session.extra_json 含 `"fullscreen":true`。
- 反例 W-07g-neg-1(缺参):缺 enabled → `status=400`。
- 反例 W-07g-neg-2(会话不存在):→ `status=404`。
## W-07h 状态隔离(演示改动不污染正式数据)— 组合验证
- 正例 W-07h-pos:演示中编辑 e1 后,查询正式 entity 表(entity_id=e1)确认字段未被修改;stop 后 demo_session_state 无残留;再次 query entity 表仍为原值。
- 反例 W-07h-neg(残留污染):stop 后若 demo_session_state 仍查到该 session_id 记录 → 判 FAIL(隔离失效)。
## W-07i 查看实体属性 — POST /demo/api/entity_attrs.dspy
- 正例 W-07i-pos:`{"session_id":"<sid>","entity_id":"e1"}` → `status=200` 且 data 含 base/demo/merged 三对象;merged=base 与 demo 合并。
- 反例 W-07i-neg-1(实体不在会话):`{"session_id":"<sid>","entity_id":"no_such"}` → `status=404` message 含 "实体不存在于演示会话"。
- 反例 W-07i-neg-2(缺参):→ `status=400`。
## W-07j 多人预览 — POST /demo/api/presence.dspy
- 正例 W-07j-pos-加入:`{"session_id":"<sid>","action":"join","user_id":"u1"}` → `status=200` 且 `data.viewer_count=1`;demo_presence 新增 1 行。
- 正例 W-07j-pos-离开:`action:"leave","user_id":"u1"` → `status=200` 且 `data.viewer_count=0`。
- 正例 W-07j-pos-多人在线:u1/u2 都 join → `viewer_count=2`。
- 反例 W-07j-neg-1(action 非法):`action="kick"` → `status=400` message 含 "action 只能为 join/leave"。
- 反例 W-07j-neg-2(会话不存在):→ `status=404`。
## 状态机合法性补充
- W-07a 开始后 → preview;W-07f 暂停 → paused,继续 → preview;W-07b 结束 → ended(唯一出口);ended 后 start/camera/pause/entity_edit/hotload/presence 全部 400。
## 验收汇总表(执行后填写)
| 功能点 | 用例数(正/反) | pass | fail | blocked | 证据 |
|--------|--------------|------|------|---------|------|
| W-07a | 1/3 | | | | |
| W-07b | 1/3 | | | | |
| W-07c | 1/4 | | | | |
| W-07d | 1/3 | | | | |
| W-07e | 1/3 | | | | |
| W-07f | 2/2 | | | | |
| W-07g | 1/2 | | | | |
| W-07h | 1/1 | | | | |
| W-07i | 1/2 | | | | |
| W-07j | 3/2 | | | | |
| 合计 | 13/25=38 | | | | |
> 说明:本工作空间无 /d/scense/scense_app 部署目录与运行库,无法在此实跑;上述用例在部署环境执行,
> actual_result 记录原始响应体(status/message/data),fail 一律落 sd_bugs(关联 task_id)。