用途:为 Script Kit GPUI 提供测试基础设施与模式说明,适用于编写测试、运行测试套件或理解测试组织方式。
主要能力与结构:测试分为 tests/smoke/(E2E 测试,通过 stdin JSON 协议运行)与 tests/sdk/(SDK 测试,常用 bun run ...)。测试中可预加载 SDK:import '../../scripts/kit-sdk';,获得 arg()、div()、editor()、fields()、captureScreenshot()、getLayoutInfo() 等全局方法。
输出格式:测试以 JSONL 输出,每行含 test、status、timestamp,状态值为 running | pass | fail | skip(fail/skip 可带 error/reason),pass 可带 result 与 duration_ms。
运行方式:TypeScript SDK 测试用 bun run scripts/test-runner.ts(可指定文件);E2E smoke 测试先 cargo build,再通过 stdin 传入 {"type":"run","path":"..."} 运行;Rust 单元测试用 cargo test;系统测试用 cargo test --features system-tests,交互式测试加 -- --ignored。提交前验证门禁为 cargo check && cargo clippy --all-targets -- -D warnings && cargo test。
限制与注意事项:系统测试需 feature 门控(如 #[cfg(feature = "system-tests")]),平台相关测试需加 target_os/unix 守卫;不要在单元测试中使用 cx.run(),不要依赖测试间全局状态,不要硬编码路径,不要跳过清理(环境变量、临时文件)。