1
0
Files
DiAL/openspec/changes/refactor-checker-cohesion/tasks.md
lanyuanxiaoyao bb6b2bc20b refactor: checker 模块内聚化 — 每个 checker 自包含于独立目录
将 checker 架构重构为完全内聚模式:每个 checker 目录包含自身的
types、schema、validate、execute、expect 和 index,新增 checker
只需创建一个目录并在 runner/index.ts 添加一行注册。

主要变更:
- runner/shared/ 拆分:断言基础设施迁入 checker/expect/,
  body.ts 迁入 http/,text.ts 迁入 command/
- config-contract/ 重命名为 schema/,schema.ts → builder.ts
- size.ts + parseDuration 合并为 utils.ts
- 顶层 types.ts 改为 base interface + index signature,
  checker 专属类型下沉到各自 types.ts
- runner/index.ts 改为显式数组注册模式
- 更新 DEVELOPMENT.md 项目结构和开发新 Checker 指南
2026-05-13 14:38:21 +08:00

57 lines
3.9 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.
## 1. 基础设施搭建
- [x] 1.1 创建 `src/server/checker/utils.ts`,将 `size.ts``parseSize``config-loader.ts``parseDuration``DURATION_REGEX` 迁入
- [x] 1.2 创建 `src/server/checker/expect/` 目录,创建 `expect/types.ts` 放置 `ExpectResult` 等共享类型
- [x] 1.3 将 `runner/shared/operator.ts` 迁入为 `expect/operator.ts`
- [x] 1.4 将 `runner/shared/failure.ts` 迁入为 `expect/failure.ts`
- [x] 1.5 将 `runner/shared/duration.ts` 迁入为 `expect/duration.ts``ExpectResult` 类型提取到 `expect/types.ts`
- [x] 1.6 从 `runner/shared/validate.ts` 中提取 `validateOperatorObject``isJsonValue``validateOperatorValue``isPlainRecord``expect/validate-operator.ts`
## 2. Schema 目录重组
- [x] 2.1 将 `config-contract/` 目录重命名为 `schema/`
- [x] 2.2 将 `schema/schema.ts` 重命名为 `schema/builder.ts`
- [x] 2.3 更新 `schema/` 内部文件的相互引用路径
- [x] 2.4 更新外部对 `config-contract/` 的所有 import 路径config-loader.ts、runner/shared/validate.ts 等)
## 3. 类型系统重构
- [x] 3.1 在顶层 `types.ts` 中创建 `ResolvedTargetBase``RawTargetConfig` base interface
- [x] 3.2 将 HTTP 专属类型(`HttpTargetConfig``ResolvedHttpTarget``HttpExpectConfig``HttpDefaultsConfig``ResolvedHttpConfig``BodyRule``CssRule``JsonRule``XpathRule``HeaderExpect`)迁入 `runner/http/types.ts`
- [x] 3.3 将 Command 专属类型(`CommandTargetConfig``ResolvedCommandTarget``CommandExpectConfig``CommandDefaultsConfig``ResolvedCommandConfig`)迁入 `runner/command/types.ts`
- [x] 3.4 删除顶层 `types.ts` 中的 `ResolvedTarget` 联合类型和 `TargetConfig` 联合类型,将 `TextRule` 迁入 command/types.ts
- [x] 3.5 将 `DefaultsConfig` 改为宽松 base 形式(仅保留 `interval?``timeout?` + index signature`CommandDefaultsConfig` 迁入 command/types.ts`HttpDefaultsConfig` 迁入 http/types.ts
- [x] 3.6 更新 `runner/types.ts``CheckerDefinition` 接口签名,使用 `RawTargetConfig``ResolvedTargetBase`
- [x] 3.7 更新 `engine.ts``store.ts``config-loader.ts` 的类型引用为 `ResolvedTargetBase``RawTargetConfig`
## 4. HTTP Checker 内聚化
- [x] 4.1 将 `runner/http/runner.ts` 重命名为 `runner/http/execute.ts`
- [x] 4.2 将 `runner/http/contract.ts` 重命名为 `runner/http/schema.ts`
- [x] 4.3 将 `runner/shared/body.ts` 迁入 `runner/http/body.ts`
- [x] 4.4 将 `runner/shared/validate.ts` 中的 `validateBodyRules``validateCssRule``validateJsonRule``validateXpathRule``validateRegexRule``validateSingleBodyRule``validateJsonPath` 合并到 `runner/http/validate.ts`
- [x] 4.5 创建 `runner/http/index.ts`re-export `HttpChecker`
- [x] 4.6 更新 `runner/http/` 内所有文件的 import 路径
## 5. Command Checker 内聚化
- [x] 5.1 将 `runner/command/runner.ts` 重命名为 `runner/command/execute.ts`
- [x] 5.2 将 `runner/command/contract.ts` 重命名为 `runner/command/schema.ts`
- [x] 5.3 将 `runner/shared/text.ts` 迁入 `runner/command/text.ts`
- [x] 5.4 将 `runner/shared/validate.ts` 中的 `validateTextRules` 合并到 `runner/command/validate.ts`
- [x] 5.5 创建 `runner/command/index.ts`re-export `CommandChecker`
- [x] 5.6 更新 `runner/command/` 内所有文件的 import 路径
## 6. 注册入口改造
- [x] 6.1 重写 `runner/index.ts` 为显式列表注册模式import 列表 + checker 数组 + 循环注册)
- [x] 6.2 删除 `runner/shared/` 目录(确认所有内容已迁移完毕)
- [x] 6.3 删除 `src/server/checker/size.ts`(已迁入 utils.ts
## 7. 测试与质量保障
- [x] 7.1 更新所有测试文件的 import 路径
- [x] 7.2 执行完整测试套件,确保所有测试通过
- [x] 7.3 执行 lint 和格式检查,确保代码质量
- [x] 7.4 确认新增 checker 只需一个目录 + 一行注册