Skip to content

test(install): 斜杠命令测试覆盖 + 回归防护#6

Merged
telagod merged 3 commits intotelagod:mainfrom
zhang0281:test/slash-command-coverage
Feb 18, 2026
Merged

test(install): 斜杠命令测试覆盖 + 回归防护#6
telagod merged 3 commits intotelagod:mainfrom
zhang0281:test/slash-command-coverage

Conversation

@zhang0281
Copy link
Contributor

⚠️ 依赖: 请先合并 PR #5 (fix/command-wrapper-no-stall) 再合并本 PR。
本分支已 rebase 到 PR#5 之上,包含其「一气呵成指令流」的代码变更。

Summary

  • 补全斜杠命令核心函数(parseFrontmatter, scanInvocableSkills, generateCommandContent, installGeneratedCommands)的单元测试覆盖
  • 新增 6 条回归防护测试,防止 skills 目录重组后路径失效(0eb9f45 事件复发防线)

回归防护测试详情

测试 防护目标
至少存在 6 个 user-invocable skill 防止 skill 意外丢失
所有 SKILL.md 路径必须真实存在 端到端验证 generateCommandContent() 路径映射
有脚本 skill 包含正确 run_skill.js 调用 防脚本引用断裂
无脚本 skill 不引用 run_skill.js 防误注入脚本调用
name 符合 /^[a-z][a-z0-9-]*$/ 防非法文件名
name 无重复 防 command 文件冲突

Test plan

  • npx jest test/install.test.js --verbose — 46 条全部通过
  • 模拟回归验证:篡改 skill name → 命名规范测试爆红 → 还原后通过

将 generateCommandContent() 的「先读取 SKILL.md…然后执行」
两步分离模式改为一气呵成指令流:

- 保留读取 SKILL.md(保留行为上下文如骨架填充指引)
- 保留执行 run_skill.js(保留脚本功能)
- 合并为有序步骤列表 + 「全程不要停顿」约束
- 消除 Claude 在 Read/Bash 工具调用间的停顿等待
- allowed-tools 恢复使用 SKILL.md 中定义的工具集
为 4 个零覆盖的斜杠命令核心函数添加 22 条测试:
- parseFrontmatter: 6 条 (标准解析/空输入/引号/连字符/无效行/CRLF)
- scanInvocableSkills: 6 条 (过滤/hasScripts/relPath/空目录/无name/真实目录)
- generateCommandContent: 6 条 (脚本模式/知识库模式/可选字段/默认值/转义)
- installGeneratedCommands: 4 条 (生成/备份/空结果/内容格式)

测试总数: 66 → 88 (全部通过)
新增 describe('斜杠命令回归防护') 包含 6 条回归测试:
- SKILL.md 路径有效性烟雾测试(2条)
- 脚本引用完整性(2条)
- command 文件名合法性(2条)

防止 skills 目录重组后路径失效的问题再次发生。
@telagod telagod merged commit 4a1be51 into telagod:main Feb 18, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants