-
Notifications
You must be signed in to change notification settings - Fork 229
[2/4] feat(commit-message): add prompt template and generator service #1228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import type { ProviderSettings } from "@roo-code/types" | ||
|
|
||
| import { getCommitMessageSettings } from "../config" | ||
| import type { ClineProvider } from "../../../core/webview/ClineProvider" | ||
|
|
||
| describe("getCommitMessageSettings", () => { | ||
| const apiConfiguration: ProviderSettings = { apiProvider: "openai", apiKey: "key", apiModelId: "gpt-4" } | ||
|
|
||
| const listApiConfigMeta = [ | ||
| { id: "config1", name: "Config 1" }, | ||
| { id: "config2", name: "Config 2" }, | ||
| ] | ||
|
|
||
| const commitProfile = { | ||
| name: "Commit Config", | ||
| apiProvider: "anthropic" as const, | ||
| apiKey: "commit-key", | ||
| apiModelId: "claude-3", | ||
| } | ||
|
|
||
| let getProfile: ReturnType<typeof vi.fn> | ||
|
|
||
| // `ClineProvider` is a large concrete class, and constructing one would drag in the extension | ||
| // host. This reads the two members the function actually touches, so the double assertion is | ||
| // the narrowest way to stand in for it - widening to `unknown` first because the stub is not | ||
| // structurally assignable to the full class. | ||
| const makeProvider = (commitMessageApiConfigId?: string) => | ||
| ({ | ||
| getState: vi.fn().mockResolvedValue({ | ||
| apiConfiguration, | ||
| listApiConfigMeta, | ||
| customSupportPrompts: { COMMIT_MESSAGE: "custom" }, | ||
| commitMessageApiConfigId, | ||
| }), | ||
| providerSettingsManager: { getProfile }, | ||
| }) as unknown as ClineProvider | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| getProfile = vi.fn().mockResolvedValue(commitProfile) | ||
| }) | ||
|
|
||
| it("uses the active configuration when no dedicated profile is chosen", async () => { | ||
| const settings = await getCommitMessageSettings(makeProvider()) | ||
|
|
||
| expect(settings.apiConfiguration).toBe(apiConfiguration) | ||
| expect(getProfile).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it("uses the dedicated profile when one is configured", async () => { | ||
| const settings = await getCommitMessageSettings(makeProvider("config2")) | ||
|
|
||
| expect(getProfile).toHaveBeenCalledWith({ id: "config2" }) | ||
| expect(settings.apiConfiguration).toEqual({ | ||
| apiProvider: "anthropic", | ||
| apiKey: "commit-key", | ||
| apiModelId: "claude-3", | ||
| }) | ||
| }) | ||
|
|
||
| it("carries the customized prompt through", async () => { | ||
| const settings = await getCommitMessageSettings(makeProvider()) | ||
|
|
||
| expect(settings.customSupportPrompts).toEqual({ COMMIT_MESSAGE: "custom" }) | ||
| }) | ||
|
|
||
| it("falls back when the saved id is not in the known profiles", async () => { | ||
| const settings = await getCommitMessageSettings(makeProvider("deleted-config")) | ||
|
|
||
| expect(getProfile).not.toHaveBeenCalled() | ||
| expect(settings.apiConfiguration).toBe(apiConfiguration) | ||
| }) | ||
|
|
||
| // The metadata check is not enough on its own: a profile can be deleted between reading the | ||
| // state and looking it up, and stale metadata points at profiles that are already gone. | ||
| it("falls back when the profile disappears between the state read and the lookup", async () => { | ||
| getProfile = vi.fn().mockRejectedValue(new Error("Profile not found")) | ||
|
|
||
| const settings = await getCommitMessageSettings(makeProvider("config2")) | ||
|
|
||
| expect(getProfile).toHaveBeenCalledWith({ id: "config2" }) | ||
| expect(settings.apiConfiguration).toBe(apiConfiguration) | ||
| }) | ||
|
|
||
| it("falls back when the saved profile has no provider configured", async () => { | ||
| getProfile = vi.fn().mockResolvedValue({ name: "Empty Config" }) | ||
|
|
||
| const settings = await getCommitMessageSettings(makeProvider("config2")) | ||
|
|
||
| expect(settings.apiConfiguration).toBe(apiConfiguration) | ||
| }) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we cover set and unset
commitMessageApiConfigIdvalues through both state-return paths? This would catch a future omission that makes the saved selector revert after a webview refresh.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
four tests covering set and unset across both getState() and getStateToPostToWebview(), in the ClineProvider spec next to the existing state coverage