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