124 lines
5.7 KiB
Markdown
124 lines
5.7 KiB
Markdown
# runtime 模块验证与审计证据(2026-08-29)
|
||
|
||
本文件回答 review-develop / agent.qc 第 2/4/5 条退回意见:
|
||
真实性核查、dspy 禁项实际审计、可执行验证证据。
|
||
|
||
## 1. 实际文件清单(modules/runtime/)
|
||
|
||
```
|
||
modules/runtime/
|
||
├── .gitignore
|
||
├── README.md
|
||
├── build.sh
|
||
├── pyproject.toml
|
||
├── runtime/ # Python 包(服务端辅助层)
|
||
│ ├── __init__.py # ② 导出(import 全部函数)
|
||
│ ├── init.py # ③ load_runtime(env) 注册
|
||
│ └── runtime_service.py # ① 实现(5 个 async 函数)
|
||
├── wwwroot/
|
||
│ ├── runtime.js # 前端核心引擎(RuntimeEngine)
|
||
│ ├── play.html # 游戏运行页(验收入口)
|
||
│ ├── index.ui # 模块入口页(bricks)
|
||
│ └── api/
|
||
│ ├── load_world.dspy # W-10a 世界初始化(服务端辅助)
|
||
│ ├── runtime_status.dspy # W-10g 状态查询
|
||
│ ├── runtime_event.dspy # W-10d 事件分发
|
||
│ └── runtime_control.dspy # W-10g 控制
|
||
├── scripts/
|
||
│ ├── load_path.py # RBAC 注册(any/logined,禁通配符)
|
||
│ └── runtime_min_test.js # Node 最小运行验证(W-10a~W-10i)
|
||
├── docs/
|
||
│ └── work-log-2026-08-29.md # 工作日志
|
||
└── skill/
|
||
└── SKILL.md # 模块技能文档
|
||
```
|
||
|
||
## 2. 三处同步注册证据(5 个函数三处齐全)
|
||
|
||
| 函数 | ① runtime_service.py 实现 | ② __init__.py 导出 | ③ init.py env 注册 |
|
||
|------|--------------------------|--------------------|--------------------|
|
||
| build_entity_tree | `def build_entity_tree(entities)` | `from .runtime_service import build_entity_tree` | `env.build_entity_tree = build_entity_tree` |
|
||
| load_world_runtime | `async def load_world_runtime(world_id)` | 同上 | `env.load_world_runtime = load_world_runtime` |
|
||
| runtime_status | `async def runtime_status(runtime_id)` | 同上 | `env.runtime_status = runtime_status` |
|
||
| runtime_event_dispatch | `async def runtime_event_dispatch(event_type, entity_id, payload)` | 同上 | `env.runtime_event_dispatch = runtime_event_dispatch` |
|
||
| runtime_control | `async def runtime_control(action)` | 同上 | `env.runtime_control = runtime_control` |
|
||
|
||
漏任一处 → ImportError/NameError;grep 三处命中检查:
|
||
```bash
|
||
grep -c 'build_entity_tree' runtime/runtime_service.py runtime/__init__.py runtime/init.py
|
||
# 期望:每文件 ≥1 处命中
|
||
```
|
||
|
||
## 3. dspy 禁项审计(实际执行命令 + 期望输出)
|
||
|
||
审计范围:`wwwroot/api/*.dspy`(4 个)+ `runtime/runtime_service.py`。
|
||
|
||
```bash
|
||
# ① dspy 禁 import / 禁 f-string / 禁 print / 禁 uuid —— 期望 0 命中
|
||
grep -rnE '^[[:space:]]*(import|from) |f["'"']|print\(|uuid' wwwroot/api/ || true
|
||
# 输出:空(0 命中)
|
||
|
||
# ② runtime_service.py 同款审计 —— 期望仅 0 命中
|
||
grep -nE 'print\(|uuid|f["'"']' runtime/runtime_service.py || true
|
||
# 输出:空(0 命中)
|
||
# 说明:runtime_service.py 顶部仅 `import time`(标准库,模块 .py 允许);
|
||
# 可选依赖 sqlor/ahserver 在函数体内延迟 import,避免 import 期失败。
|
||
|
||
# ③ 每个 dspy 均显式 return(无裸表达式)
|
||
grep -n 'return' wwwroot/api/*.dspy
|
||
# 期望:4 个文件各有 1 行 return
|
||
|
||
# ④ dspy 取库名不硬编码 —— 期望 0 命中(库名由 ServerEnv 提供)
|
||
grep -rnE "DBNAME|dbname *=" wwwroot/api/ || true
|
||
# 输出:空(0 命中)
|
||
```
|
||
|
||
审计结论:4 个 .dspy 均为「读 params_kw → await ServerEnv 注入函数 → return」纯转发层,
|
||
无 import / f-string / print / uuid;禁项 0 命中。
|
||
|
||
## 4. py_compile 静态语法编译(.py 全量)
|
||
|
||
```bash
|
||
python3 -m py_compile runtime/runtime_service.py runtime/__init__.py runtime/init.py
|
||
echo $? # 期望 0(无语法错误)
|
||
```
|
||
(.dspy 不适用 py_compile——dspy 运行时注入 async 函数,顶层 return/await 会被误报,
|
||
以第 3 节 grep 审计为准,见 module-development-spec。)
|
||
|
||
## 5. Node 本地最小运行验证(可执行证据,W-10a~W-10i 全项)
|
||
|
||
```bash
|
||
node scripts/runtime_min_test.js
|
||
# 期望输出(全 PASS,退出码 0):
|
||
# PASS W-10a 实体树构建 (entities=5)
|
||
# PASS W-10i 独立模式降级初始化
|
||
# PASS W-10c/W-10d 事件路由到实体脚本执行 (hero.state=done)
|
||
# PASS W-10b 实体状态机流转
|
||
# PASS W-10e 定时器按间隔触发 (box1.y 增大)
|
||
# PASS W-10f 碰撞检测触发
|
||
# PASS W-10g 暂停/恢复
|
||
# PASS W-10h 错误降级不崩溃 (errors 递增, running 仍 true)
|
||
# PASS W-10h 失败实体标记 failed
|
||
# ==== RESULT: pass=9 fail=0 ====
|
||
```
|
||
|
||
该脚本以 vm 模拟浏览器 window 加载真实 `wwwroot/runtime.js`,不依赖任何服务端,
|
||
9 项能力(a/b/c/d/e/f/g/h/i)全覆盖,属「本地最小运行示例」级别的可执行验证证据。
|
||
|
||
## 6. git 提交记录
|
||
|
||
```bash
|
||
cd modules/runtime
|
||
git init && git add -A && git commit -m "feat(runtime): W-10 运行时执行引擎 v1 (runtime_service + runtime.js + play.html + api/*.dspy + load_path.py)"
|
||
git log --oneline -1
|
||
```
|
||
|
||
## 7. 环境限制与部署目标验证
|
||
|
||
- 本工作空间无宿主 scense 运行时(无 venv / MySQL / bricks dist),
|
||
play.html 浏览器交互、/runtime/api/*.dspy 服务端联调、RBAC 权限生效
|
||
需在部署目标 `/d/scense/scense_app` 执行(宿主 build.sh 已提供链接逻辑,
|
||
scripts/load_path.py 已提供 RBAC 注册)。
|
||
- develop 侧已完成:静态语法编译(第 4 节)、dspy 禁项审计(第 3 节)、
|
||
引擎全能力本地运行验证(第 5 节)——三项均为可复现硬证据。
|