🐛 fix(vscode): 修复新建工单后会话关联丢失

This commit is contained in:
cruldra committed 2026-10-10 01:33:18 -04:00
1 parent 172e6ba77d
commit 9345b6a16e
12 files changed
+836 -435

No files matched your search

+14
View File
@@ -36,3 +36,17 @@ describe('buildCcArgv', () => {
])
})
})
describe('new session identity', () => {
const sessionId = '5a749776-d1c8-4cf0-8f85-3b8d7b804498'
it('passes the allocated identity before the prompt', () => {
expect(buildCcArgv({ profilePath: '/p.json', sessionId, prompt: 'create issue' }))
.toEqual([...BASE, '--session-id', sessionId, 'create issue'])
})
it('rejects a new identity combined with resuming another session', () => {
expect(() => buildCcArgv({ profilePath: '/p.json', sessionId, resumeSessionId: 'existing' }))
.toThrow('sessionId')
})
})
+37
View File
@@ -216,6 +216,43 @@ describe('state JSON 尾部普通评论不丢状态', () => {
})
})
describe('state defaults', () => {
beforeEach(() => {
listIssueComments.mockReset()
postIssueComment.mockReset()
})
it.each([
[{}, { column: 'todo', color: 'blue', pr: '5' }],
[{ column: 'review', color: 'red' }, { column: 'review', color: 'red', pr: '5' }],
])('fills missing defaults without replacing existing values: %j', async (existing, expected) => {
const { mergeStateJsonComment } = await import('../../src/gitea/stateJson.js')
const comments = [{ body: JSON.stringify(existing) }]
listIssueComments.mockImplementation(async () => [...comments])
postIssueComment.mockImplementation(async ({ body }: { body: string }) => comments.push({ body }))
await mergeStateJsonComment({ host: 'host', owner: 'owner', repo: 'repo', token: 'token', issueNumber: 5, defaults: { column: 'todo', color: 'blue' }, extra: { pr: '5' } })
expect(JSON.parse(postIssueComment.mock.calls[0][0].body)).toEqual(expected)
expect(postIssueComment).toHaveBeenCalledOnce()
})
it('explicit changes override defaults and existing state', async () => {
const { mergeStateJsonComment } = await import('../../src/gitea/stateJson.js')
const comments = [{ body: JSON.stringify({ column: 'review' }) }]
listIssueComments.mockImplementation(async () => [...comments])
postIssueComment.mockImplementation(async ({ body }: { body: string }) => comments.push({ body }))
await mergeStateJsonComment({ host: 'host', owner: 'owner', repo: 'repo', token: 'token', issueNumber: 5, defaults: { column: 'todo', color: 'blue' }, extra: { column: 'done' } })
expect(JSON.parse(postIssueComment.mock.calls[0][0].body)).toEqual({ column: 'done', color: 'blue' })
})
it('read-back does not force defaults over a concurrent update', async () => {
const { mergeStateJsonComment } = await import('../../src/gitea/stateJson.js')
listIssueComments.mockResolvedValueOnce([]).mockResolvedValue([{ body: JSON.stringify({ column: 'review', color: 'red' }) }])
await mergeStateJsonComment({ host: 'host', owner: 'owner', repo: 'repo', token: 'token', issueNumber: 5, defaults: { column: 'todo', color: 'blue' }, extra: {} })
expect(postIssueComment).toHaveBeenCalledOnce()
expect(JSON.parse(postIssueComment.mock.calls[0][0].body)).toEqual({ column: 'todo', color: 'blue' })
})
})
describe('spawnClaude', () => {
beforeEach(() => {
execFile.mockReset()