# Test Infrastructure — Dungeon Sweeper **Engine**: Godot 4.7.2-stable(GDScript 单语言) **Test Framework**: 双载体(ADR-0004)——`--headless --script` 逻辑冒烟 + headless 场景探针;gdUnit4 **deferred**(D2 OQ1 关闭形态,正式 CI 期再议) **CI**: `.github/workflows/tests.yml`(首次 push 到 GitHub 后自动生效;仓库 2026-09-12 尚未初始化 git) **Setup date**: 2026-09-12 **参考实现**: `prototypes/dungeon-sweeper-vertical-slice/smoke/`(冒烟 96/96 + 三 UI 探针——正式工程的活样板) ## Directory Layout ``` tests/ unit/ # 隔离单元测试(公式/状态机/纯逻辑)——extends SceneTree + quit(code) integration/ # 跨系统测试(Core-Core 集成、回放确定性、存档往返) smoke/ # critical-paths.md——人工 gate 清单(/smoke-check 读取) evidence/ # 截图与人工签核记录 run_all.gd # CI 冒烟统一入口(套件 manifest 协议,D2 AC-2b) static_scan.sh # ADR-0004 静态扫描域 S1–S8 可执行子集 ``` ## Running Tests ```bash # 逻辑冒烟(双载体之一)——Windows 须用 console 版 exe 取 stdout godot --headless --script tests/run_all.gd # 统一入口(CI 调用点) godot --headless --script tests/unit/example_test.gd # 场景探针(双载体之二)——以探针场景为运行目标,走完整项目引导(autoload 在位) godot --headless --path . res://tests/probes/.tscn # CI 旁必须配外部 wall-clock 超时(ADR-0004:引擎无死锁探测) timeout 120s godot --headless --script tests/run_all.gd ``` **协议要点**(D2 冒烟协议 + ADR-0004): - 冒烟脚本 `extends SceneTree` 以获得 `quit(code)`;成功 `quit(0)`、失败 `quit(1)` - `--script` 模式**不加载 autoload 且不注册全局标识符**(裸引用 `ConfigDB` = parse error)——ConfigDB/RngService 由脚本显式实例化,core 一律构造注入 - 致命类用例独立进程,runner manifest 登记"调用 → 期望退出码" - 每用例先 `reset_diagnostics()`(诊断收集器协议) - 期望值由表读值推导,不写死玩法数值 ## Test Naming - **Files**: `[system]_[feature]_test.gd`(领域命名,禁 ID 前缀——docs/code-conventions.md) - **Functions**: `test_[scenario]_[expected]` - **Example**: `reward_roll_test.gd` → `test_power_interval_rolls_within_bounds()` ## Story Type → Test Evidence | Story Type | Required Evidence | Location | |---|---|---| | Logic | Automated unit test — must pass | `tests/unit/[system]/` | | Integration | Integration test OR playtest doc | `tests/integration/[system]/` | | Visual/Feel | Screenshot + lead sign-off | `tests/evidence/` | | UI | Manual walkthrough OR interaction test(场景探针为首选) | `tests/evidence/` | | Config/Data | Smoke check pass | `production/qa/smoke-*.md` | ## Static Scan(提交前双跑:本地 + CI) `tests/static_scan.sh` 实现 ADR-0004 扫描域 S1–S8 的可执行子集;规则全集与动机见 `docs/architecture/adr-0004-test-carrier-and-ci.md`。新违规案例必须**先补扫描规则再修码**。 ## CI Tests run automatically on every push to `main` and on every pull request. A failed test suite blocks merging. **gdUnit4 安装说明(deferred,届时启用)**: AssetLib → GdUnit4 → Install → Project Settings → Plugins 勾选 → 重启编辑器 → 确认 `res://addons/gdunit4/`。