test: 完善防回归测试体系 - #31
Merged
Merged
Conversation
为 proxy-errors 模块添加 extractApiErrorMessage 和 formatProxyRequestError 函数的测试用例,覆盖 JSON 错误解析、非 JSON 回退以及特定错误码转换等场景。 为 proxy-env 模块添加 resolveProxyConfig 函数的测试用例,验证其能正确读取 http_proxy、https_proxy、ALL_PROXY 和 no_proxy 等环境变量,并处理大小写和优先级逻辑。
移除 proxy-env-compat.test.js 文件,因为其测试功能已被其他测试覆盖。 在 plugin-loader 中注释掉控制台错误输出,以减少测试时的日志噪音。 修复 plugin-loader.test.js 中空 catch 块的格式一致性。
- 将 interceptor.js 中的工具函数(如 isMainAgentRequest、assembleStreamMessage 等)提取到 lib/interceptor-core.js 模块,提高代码可维护性和复用性 - 更新 interceptor.js 和测试文件以导入新模块,减少重复代码 - 在测试中添加新的测试用例以覆盖边界情况和增强逻辑验证 - 移除 interceptor.js 中未使用的 readdirSync 导入 - 恢复 plugin-loader.js 中的调试日志输出,便于插件加载过程调试 - 在 updater.test.js 中移除 ANSI 颜色代码,确保测试输出纯净
添加针对服务器日志端点(/api/local-logs, /api/download-log)和插件端点(/api/plugins, /api/plugins/upload 等)的集成测试,验证其功能与安全性。同时为插件加载器补充语法错误处理测试,并为流消息组装函数增加非对象事件处理测试。
- 修改 package.json 中的测试命令,添加 --test-concurrency=1 确保测试串行执行 - 重构测试文件,移除临时目录创建逻辑,使用统一的日志目录管理 - 在 findcc.js 中实现 resolveLogDir 函数,支持测试环境下的独立日志目录 - 为 pty-manager.js 添加测试注入机制,使单元测试不依赖真实 claude 二进制 - 在 workspace-registry.js 中添加文件锁机制,防止并发写入冲突 - 更新测试用例,专注于逻辑验证而非文件系统操作
添加 options 参数以允许注入自定义的 fetch、exec 实现和启用 dry-run 模式,这提高了代码的可测试性,使得在单元测试中能够模拟网络请求和命令执行,避免实际安装操作。
修复测试时可能出现的日志目录锁竞争条件问题。当 CCV_LOG_DIR 环境变量设为 "tmp" 或 "temp" 时,现在会使用进程特定的临时目录,避免多个测试进程间的冲突。同时改进锁机制,增加陈旧锁检测(超过5秒未更新视为死锁),防止因进程崩溃导致的锁永久持有问题。
添加注释说明允许通过环境变量中的 'tmp' 或 'temp' 关键字使用系统临时目录,这通常用于测试场景。
移除测试命令的并发限制以提升测试执行速度 更新README文档,添加环境变量说明 修复workspace-registry中临时文件重命名在Windows上的竞争条件 添加过时锁文件的恢复机制
Owner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

变更概述
本 PR 以“防回归 + 可维护”为目标,完善测试体系并减少环境/网络/并发带来的不稳定因素,重点覆盖:
主要改动
CCV_LOG_DIR,测试默认落到临时目录,避免污染用户目录_setPtyImportForTests,测试改为 mock spawn,不再依赖本机 claude/pty 环境checkAndUpdate支持注入fetchImpl/execImpl与dryRun;测试完全 mock fetchnpm test串行(--test-concurrency=1),降低端口/环境共享导致的偶发失败验证
npm test(node --test --test-concurrency=1)全量通过:pass 220 / fail 0兼容性/风险
CCV_LOG_DIR或测试运行时才切换 LOG_DIR 到隔离路径