dsh-test-generator

September 13, 2026 · View on GitHub

DeepSeek Harness 插件:从调用方提供的源码文本生成测试脚手架。三个工具都是纯文本函数——不读文件、不起子进程、不联网,因此同样的输入永远得到同样的输出,单元测试完全离线。

包名:@qingshanjiluo/dsh-test-generator

安装

npx -y @deepseek-ai/dsh plugin --profile web add @qingshanjiluo/dsh-test-generator

加载后插件只声明 inject = ['tools'],向工具注册表注册下面三个工具。

工具

工具参数输出
scan_testablecode(必填,源码全文)、language?auto/typescript/javascript/pythonlanguagecountsymbolskind:name 标签,方法为 method:Class.member)、truncatednotes
generate_testscode(必填)、framework?vitest/jest)、language?module?(import 路径)framework(Python 为 unittest)、languagecountsymbolscontent(完整测试文件文本)、notes
generate_from_specspec(必填,{ fn, args, expected, matcher? } 数组;所有取值都是源码文本)、framework?module?frameworkcountcontentnotes

识别规则(正则子集,非 AST)

  • JavaScript / TypeScript:export functionexport async functionexport class(含一层公有方法,跳过 constructor)、export const x = () =>export const/let/varexport defaultexport { a as b }type/interface 等纯类型导出不算可测符号。
  • Python:顶层 def / async def、顶层 name = lambdaclass 及其缩进方法。
  • 注释与字符串内的伪代码会被剥离后再匹配;_ 前缀成员与导出默认按私有处理,可用 includePrivate 打开。

generate_from_spec 约定

argsexpected 按原样作为字面量写进生成的代码:{ fn: "add", args: ["1", "2"], expected: "3" }expect(result).toEqual(3)matcher 可为 toEqual(默认)、toBetoThrow(此时 expected 是抛错消息字面量)。fn 支持点号方法(utils.parse),import 会取根标识符。

配置

配置项类型默认值说明
defaultFrameworkstringvitest调用未传 framework 时使用;非 vitest/jest 会回退到 vitest 并在 notes 中说明
defaultModulestring./subject调用未传 module 时写入生成文件的 import 路径
maxSymbolsnumber40单次调用输出的符号数 / spec 行数上限,超出即截断并置 truncated 或写入 notes
includePrivatebooleanfalse是否把 _ 前缀的成员、值导出与 Python 名称视为可测

cordis.patch.yml 中的示例配置只包含上述四个真实字段。

运行与测试说明

  • 本插件是纯主机工具插件:没有浏览器 UI,也没有 settings/commands 注册。
  • 它是纯函数实现,运行期不需要任何外部服务、网络或子进程;若同类插件需要网络或命令执行,必须通过配置注入 fetchFn/runCommand 一类的接缝,测试里喂假实现,因此测试始终离线。
  • 生成的代码是脚手架:import 路径与 TODO 断言需由调用方(或模型)补全后再落盘运行。
npm install --no-audit --no-fund
npx tsc --noEmit
npm run build          # 产出 lib/index.js 与 lib/index.d.ts
npx vitest run         # 离线单元测试
node scripts/load-smoke.mjs   # 校验构建产物的导出面与注册的工具

License

MIT