🐛 fix(vscode): 重写注释直接调用 /ecc:writing-code-comments,不再自己读技能文件

This commit is contained in:
cruldra committed 2026-10-03 03:22:20 +08:00
1 parent f2490b0505
commit 5f1352df86
3 files changed
+10 -72

No files matched your search

+3 -18
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { commentProse, commentRewritePrompt, commentSource, isModuleComment, loadCommentSkill, modelCommentBody, refillComment, skillBody } from './commentRewrite'
import { COMMENT_SKILL, commentProse, commentRewritePrompt, commentSource, isModuleComment, modelCommentBody, refillComment } from './commentRewrite'
import { commonIndent, replaceLines } from './editText'
/** 和预览写回同一条路:正文套回壳,再按原来的缩进替换这几行。 */
@@ -116,15 +116,14 @@ describe('重写注释的提示', () => {
it('文件顶上的三引号:上下文是去掉这段之后的文件,太长会截掉并说明', () => {
const rest = Array.from({ length: 130 }, (_, index) => `line ${index}`).join('\n')
const prompt = commentRewritePrompt({
skill: '技能正文',
comment: '"""旧"""',
source: `"""旧"""\n${rest}`,
startLine: 0,
endLine: 0,
earlierKinds: [],
})
expect(prompt).toContain('技能正文')
expect(prompt).toContain('只按上面的技能重写这一段注释')
expect(prompt?.startsWith(`${COMMENT_SKILL}\n`)).toBe(true)
expect(prompt).toContain('只按这个技能重写这一段注释')
expect(prompt).toContain('这段注释现在的正文:\n旧')
expect(prompt).not.toContain('"""')
expect(prompt).toContain('截断了')
@@ -134,7 +133,6 @@ describe('重写注释的提示', () => {
it('普通注释只带后面紧挨着的那一块,不带整份文件', () => {
const prompt = commentRewritePrompt({
skill: '技能正文',
comment: '# 旧',
source: '整份文件不该出现',
startLine: 4,
@@ -149,19 +147,6 @@ describe('重写注释的提示', () => {
expect(isModuleComment('"""旧"""', ['function'])).toBe(false)
})
it('技能按给出的顺序找,用到第一份;都没有就是没有', async () => {
const read = async (path: string): Promise<string> => {
if (path.includes('/marketplaces/ecc/'))
throw Object.assign(new Error('no'), { code: 'ENOENT' })
return '---\nname: writing-code-comments\n---\n规范正文\n'
}
expect(await loadCommentSkill(read)).toBe('规范正文')
expect(await loadCommentSkill(async () => {
throw Object.assign(new Error('no'), { code: 'ENOENT' })
})).toBeUndefined()
expect(skillBody('没有头的正文')).toBe('没有头的正文')
})
it('模型套了代码围栏时只留里面的正文', () => {
expect(modelCommentBody('```\n新说明\n```')).toBe('新说明')
expect(modelCommentBody(' ')).toBeUndefined()