🐛 fix(vscode): 提交代码改调 generate-git-commit-message 写说明
This commit is contained in:
1 parent
5e9bf44710
commit
d10c29a260
7 files changed
+130
-3
No files matched your search
@@ -0,0 +1,74 @@
|
||||
import type { KanbanWebviewPanel } from '../KanbanPanel'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { COMMIT_PROMPT } from '../../cc/commitPrompt'
|
||||
import { handleCommitRun } from './toolbar'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
spawnClaude: vi.fn(),
|
||||
getEffectiveCommitProfilePath: vi.fn(),
|
||||
resolveCommitProfileForRun: vi.fn(),
|
||||
readGitIdentity: vi.fn(),
|
||||
toast: vi.fn(),
|
||||
dismiss: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('vscode', () => ({
|
||||
workspace: { workspaceFolders: [{ uri: { fsPath: '/repo' } }] },
|
||||
}))
|
||||
vi.mock('../../cc/commitProfile', () => ({
|
||||
resolveCommitProfileForRun: (...args: unknown[]) => mocks.resolveCommitProfileForRun(...args),
|
||||
}))
|
||||
vi.mock('../../cc/profiles', () => ({ resolveProfilePath: (p: string) => p }))
|
||||
vi.mock('../../cc/spawnClaude', () => ({ spawnClaude: (...args: unknown[]) => mocks.spawnClaude(...args) }))
|
||||
vi.mock('../../git/identity', () => ({
|
||||
missingGitIdentityKeys: (identity: { name: string, email: string }) => {
|
||||
const missing: string[] = []
|
||||
if (!identity.name.trim())
|
||||
missing.push('user.name')
|
||||
if (!identity.email.trim())
|
||||
missing.push('user.email')
|
||||
return missing
|
||||
},
|
||||
readGitIdentity: (...args: unknown[]) => mocks.readGitIdentity(...args),
|
||||
}))
|
||||
vi.mock('../../settings/store', () => ({
|
||||
getEffectiveCommitProfilePath: (...args: unknown[]) => mocks.getEffectiveCommitProfilePath(...args),
|
||||
}))
|
||||
vi.mock('../../webview/html', () => ({ makeNonce: () => 'n1' }))
|
||||
vi.mock('./handoffFlow', () => ({
|
||||
toast: (...args: unknown[]) => mocks.toast(...args),
|
||||
dismiss: (...args: unknown[]) => mocks.dismiss(...args),
|
||||
}))
|
||||
vi.mock('../../logging/logger', () => ({ logger: { add: vi.fn() } }))
|
||||
vi.mock('../../files/envLock', () => ({ findEnvFiles: vi.fn(), lockEnvFiles: vi.fn(), unlockEnvFiles: vi.fn() }))
|
||||
vi.mock('../../git/gitExtension', () => ({ loadGitApi: vi.fn() }))
|
||||
|
||||
function panel(): KanbanWebviewPanel {
|
||||
return {
|
||||
commitRunning: false,
|
||||
context: {},
|
||||
postMessage: vi.fn(),
|
||||
} as unknown as KanbanWebviewPanel
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mocks.getEffectiveCommitProfilePath.mockResolvedValue('/p/deepseek-v4-pro.json')
|
||||
mocks.resolveCommitProfileForRun.mockReturnValue({ ok: true, profilePath: '/p/deepseek-v4-pro.json' })
|
||||
mocks.readGitIdentity.mockResolvedValue({ name: 'me', email: 'me@example.com' })
|
||||
mocks.spawnClaude.mockResolvedValue({ resultText: 'committed', sessionId: 's', rawJson: '{}' })
|
||||
mocks.toast.mockReturnValue('toast-id')
|
||||
})
|
||||
|
||||
describe('handleCommitRun', () => {
|
||||
it('把写提交说明的指令交给 claude,不用「提交下代码」', async () => {
|
||||
const p = panel()
|
||||
await handleCommitRun(p)
|
||||
expect(mocks.spawnClaude).toHaveBeenCalledOnce()
|
||||
const args = mocks.spawnClaude.mock.calls[0][0] as { prompt: string, cwd: string, profilePath: string }
|
||||
expect(args.prompt).toBe(COMMIT_PROMPT)
|
||||
expect(args.prompt).not.toBe('提交下代码')
|
||||
expect(args.cwd).toBe('/repo')
|
||||
expect(args.profilePath).toBe('/p/deepseek-v4-pro.json')
|
||||
})
|
||||
})
|
||||
@@ -4,6 +4,7 @@ import { accessSync, constants } from 'node:fs'
|
||||
import * as path from 'node:path'
|
||||
import { workspace } from 'vscode'
|
||||
import { resolveCommitProfileForRun } from '../../cc/commitProfile'
|
||||
import { COMMIT_PROMPT } from '../../cc/commitPrompt'
|
||||
import { resolveProfilePath } from '../../cc/profiles'
|
||||
import { spawnClaude } from '../../cc/spawnClaude'
|
||||
import { findEnvFiles, lockEnvFiles, unlockEnvFiles } from '../../files/envLock'
|
||||
@@ -84,7 +85,7 @@ export async function handleCommitRun(panel: KanbanWebviewPanel): Promise<void>
|
||||
// claude -p 提交流程可能跑得比较久(要 git add / 编 commit message / git
|
||||
// commit),所以给一个比较宽松的超时(30 min)。
|
||||
const { resultText } = await spawnClaude({
|
||||
prompt: '提交下代码',
|
||||
prompt: COMMIT_PROMPT,
|
||||
cwd: workspaceRoot,
|
||||
profilePath: resolution.profilePath,
|
||||
timeoutMs: 30 * 60 * 1000,
|
||||
|
||||
Reference in new issue
Block a user