-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathCommitMessageGeneration.integration.spec.ts
More file actions
80 lines (71 loc) · 2.49 KB
/
Copy pathCommitMessageGeneration.integration.spec.ts
File metadata and controls
80 lines (71 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import * as os from "os"
import * as path from "path"
import { execFile } from "child_process"
import { promisify } from "util"
import { promises as fs } from "fs"
import type { ProviderSettings } from "@roo-code/types"
import { GitContextCollector } from "../../git-context"
import { CommitMessageGenerator } from "../CommitMessageGenerator"
const execFileAsync = promisify(execFile)
async function runGit(cwd: string, args: string[]) {
await execFileAsync("git", args, { cwd })
}
describe("commit message generation flow", () => {
const defaultConfig: ProviderSettings = { apiProvider: "openai", openAiApiKey: "default-key" }
const providerSettingsManager = {
initialize: vi.fn(),
getProfile: vi.fn(),
}
const contextProxy = {
isInitialized: true,
getProviderSettings: vi.fn(() => defaultConfig),
getValue: vi.fn((key: string) => {
switch (key) {
case "listApiConfigMeta":
return []
case "customSupportPrompts":
return {}
default:
return undefined
}
}),
}
beforeEach(() => {
vi.clearAllMocks()
})
it("passes collected git context with untracked file diff to the LLM", async () => {
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "zoo-commit-generation-"))
try {
await runGit(tempRoot, ["init"])
const filePath = path.join(tempRoot, "src", "new.ts")
await fs.mkdir(path.dirname(filePath), { recursive: true })
await fs.writeFile(filePath, "export const value = 1\n")
const gitContext = await new GitContextCollector(tempRoot).collect({
staged: false,
includeBranch: false,
recentCommits: { include: false },
})
const completePrompt = vi.fn().mockResolvedValue("feat(src): add new module")
const generator = new CommitMessageGenerator(providerSettingsManager as any, {
getContextProxy: () => contextProxy,
completePrompt,
addCustomInstructions: vi.fn().mockResolvedValue(""),
captureGenerated: vi.fn(),
})
const message = await generator.generateMessage({
workspacePath: tempRoot,
selectedFiles: gitContext.changes.map((change) => change.filePath),
gitContext: gitContext.context,
})
expect(message).toBe("feat(src): add new module")
expect(gitContext.context).toContain("diff --git a/src/new.ts b/src/new.ts")
expect(gitContext.context).toContain("+export const value = 1")
expect(completePrompt).toHaveBeenCalledWith(
defaultConfig,
expect.stringContaining("+export const value = 1"),
)
} finally {
await fs.rm(tempRoot, { recursive: true, force: true })
}
})
})