✨ feat(vscode): 重写注释排成一队,整个扩展一次只跑一段
OpenPencil 同一时间只能开一个画板,两段同时画会互相掐断。所有预览、所有文件的重写(第一轮和接着说)排成一队,前一段写成、出错、被叫停后按先后自动开始下一段;问 AI 照旧最多同时 3 个。 排着的那一轮记在扩展端(rewriteCurrent 的 queued),块下面写「排队中」、能取消排队,切标签页、页面重新加载后照样显示。
This commit is contained in:
1 parent
b7c29c60e1
commit
aecc4d1ab5
15 files changed
+329
-114
No files matched your search
@@ -182,7 +182,10 @@ describe('重写注释的记录', () => {
|
||||
expect(rewriter.mock.calls[1][0].followUp).toEqual({ sessionId: 'r1', prompt: 'a.ts:1-5\n\n短一点' })
|
||||
expect((await second).end).toEqual({ status: 'done', body: '短的。', error: '编辑器没接受这次修改,没有写回。' })
|
||||
expect(writeBack).toHaveBeenCalledWith('短的。')
|
||||
expect(rewritesOf(qa)[0].entries.map(entry => [entry.question, entry.answer, entry.error])).toEqual([[SKILL, '按名字找。', undefined], ['短一点', '短的。', '编辑器没接受这次修改,没有写回。']])
|
||||
// 两条可能记在同一毫秒,不比先后
|
||||
const entries = rewritesOf(qa)[0].entries.map(entry => [entry.question, entry.answer, entry.error])
|
||||
expect(entries).toHaveLength(2)
|
||||
expect(entries).toEqual(expect.arrayContaining([[SKILL, '按名字找。', undefined], ['短一点', '短的。', '编辑器没接受这次修改,没有写回。']]))
|
||||
|
||||
await qa.ask(uri, { askId: '3', anchor: 'function f', question: '为什么', prompt: '完整的', followUp: '短的', images: [] })
|
||||
expect(runner.mock.calls[0][0]).not.toHaveProperty('followUp')
|
||||
@@ -199,8 +202,10 @@ describe('重写注释的记录', () => {
|
||||
const second = ended(qa, '2')
|
||||
await qa.rewrite(uri, request('2', { writeBack: async body => body === undefined ? '模型没有按要求交回注释正文,没有改文件。' : undefined }))
|
||||
expect(rewriter.mock.calls[1][0]).not.toHaveProperty('followUp')
|
||||
expect((await second).end).toEqual({ status: 'done', error: '模型没有按要求交回注释正文,没有改文件。' })
|
||||
expect(rewritesOf(qa)[0].entries.at(-1)).toMatchObject({ answer: '', error: '模型没有按要求交回注释正文,没有改文件。' })
|
||||
const { end, entryId } = await second
|
||||
expect(end).toEqual({ status: 'done', error: '模型没有按要求交回注释正文,没有改文件。' })
|
||||
// 两条可能记在同一毫秒,按 id 找这一条
|
||||
expect(rewritesOf(qa)[0].entries.find(entry => entry.id === entryId)).toMatchObject({ answer: '', error: '模型没有按要求交回注释正文,没有改文件。' })
|
||||
})
|
||||
|
||||
it('出错、被叫停的不记,也不写文件;进行中的、没记下留着的那一轮在 rewriteCurrent 里,页面重新加载能再画出来,收起这块时去掉', async () => {
|
||||
@@ -227,4 +232,33 @@ describe('重写注释的记录', () => {
|
||||
qa.forgetRewrite(uri, 'function f')
|
||||
expect(qa.view(uri, file => file.fsPath, 'file').rewriteCurrent).toEqual([])
|
||||
})
|
||||
|
||||
it('整个扩展一次只重写一段:别的文件的排在后面、报排队中,记在 rewriteCurrent 里;前一段写完自动开始;问 AI 照旧同时问', async () => {
|
||||
const ctx = context()
|
||||
const { qa, runner, rewriter } = service(ctx)
|
||||
let finishFirst: (answer: CommentAnswer) => void = () => {}
|
||||
rewriter.mockImplementationOnce(() => new Promise((resolve) => {
|
||||
finishFirst = resolve
|
||||
}))
|
||||
rewriter.mockResolvedValueOnce({ body: '第二段。', sessionId: 'r2' })
|
||||
const other = { fsPath: '/workspace/b.ts', toString: () => 'file:///workspace/b.ts' } as Uri
|
||||
const events: RewriteEvent[] = []
|
||||
qa.onDidRewrite(event => events.push(event))
|
||||
const writeBack = vi.fn(async () => undefined)
|
||||
expect(await qa.rewrite(uri, request('1'))).toBeUndefined()
|
||||
expect(await qa.rewrite(other, request('2', { anchor: 'function g', writeBack }))).toBeUndefined()
|
||||
expect(rewriter).toHaveBeenCalledTimes(1)
|
||||
expect(events).toContainEqual({ owner: 'file:///workspace/b.ts', kind: 'update', ask: { askId: '2', anchor: 'function g', question: SKILL, text: '', queued: true } })
|
||||
expect(qa.view(other, file => file.fsPath, 'file').rewriteCurrent).toEqual([{ askId: '2', anchor: 'function g', question: SKILL, text: '', status: 'queued' }])
|
||||
|
||||
await qa.ask(uri, { askId: '3', anchor: 'function f', question: '为什么', prompt: '完整的', followUp: '短的', images: [] })
|
||||
await qa.ask(other, { askId: '4', anchor: 'function g', question: '为什么', prompt: '完整的', followUp: '短的', images: [] })
|
||||
expect(runner).toHaveBeenCalledTimes(2)
|
||||
|
||||
const second = ended(qa, '2')
|
||||
finishFirst({ body: '第一段。', sessionId: 'r1' })
|
||||
expect((await second).end).toEqual({ status: 'done', body: '第二段。' })
|
||||
expect(rewriter).toHaveBeenCalledTimes(2)
|
||||
expect(writeBack).toHaveBeenCalledWith('第二段。')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user