Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions packages/build/src/__tests__/types.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// npx vitest run src/__tests__/types.test.ts

import { contributesSchema } from "../types.js"

describe("contributes commands schema", () => {
// Reached through `.shape` so this stays focused on the icon field, without needing a whole
// valid `contributes` object around it.
const commandsSchema = contributesSchema.shape.commands

const command = (icon: unknown) => [
{ command: "zoo-code.generateCommitMessage", title: "%command.generateCommitMessage.title%", icon },
]

it("accepts a codicon reference", () => {
expect(commandsSchema.safeParse(command("$(edit)")).success).toBe(true)
})

// The Source Control button ships a PNG per theme rather than a codicon. This field used to
// allow only a string, which rejected the manifest outright when generating the nightly build.
it("accepts a pair of theme-specific icon paths", () => {
const icon = { light: "assets/icons/panel_light.png", dark: "assets/icons/panel_dark.png" }

expect(commandsSchema.safeParse(command(icon)).success).toBe(true)
})

it("rejects an icon pair that is missing a theme", () => {
expect(commandsSchema.safeParse(command({ light: "assets/icons/panel_light.png" })).success).toBe(false)
})
})

describe("contributes menus schema", () => {
const menusSchema = contributesSchema.shape.menus

it("accepts a grouped menu item", () => {
const menus = {
"scm/title": [
{
command: "zoo-code.generateCommitMessage",
group: "navigation",
when: "scmProvider == git && !zoo-code.generatingCommitMessage",
},
],
}

expect(menusSchema.safeParse(menus).success).toBe(true)
})

// `commandPalette` items have no group. This field used to be required, which rejected the
// manifest outright when generating the nightly build.
it("accepts a menu item with no group", () => {
const menus = {
commandPalette: [
{ command: "zoo-code.stopGeneratingCommitMessage", when: "zoo-code.generatingCommitMessage" },
],
}

expect(menusSchema.safeParse(menus).success).toBe(true)
})
})
6 changes: 4 additions & 2 deletions packages/build/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ const commandsSchema = z.array(
command: z.string(),
title: z.string(),
category: z.string().optional(),
Comment thread
Rafael-Silva-Oliveira marked this conversation as resolved.
icon: z.string().optional(),
// Either a codicon reference (e.g. `$(edit)`) or a pair of theme-specific image paths.
icon: z.union([z.string(), z.object({ light: z.string(), dark: z.string() })]).optional(),
}),
)

export type Commands = z.infer<typeof commandsSchema>

const menuItemSchema = z.object({
group: z.string(),
// Absent on menus that do not group their items, such as `commandPalette`.
group: z.string().optional(),
command: z.string().optional(),
submenu: z.string().optional(),
when: z.string().optional(),
Expand Down
7 changes: 7 additions & 0 deletions packages/types/src/global-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ export const globalSettingsSchema = z.object({
customSupportPrompts: customSupportPromptsSchema.optional(),
enhancementApiConfigId: z.string().optional(),
includeTaskHistoryInEnhance: z.boolean().optional(),
commitMessageApiConfigId: z.string().optional(),
/**
* Seconds to wait for a commit message before giving up. Most providers ignore the abort
* signal, so without a bound a request that never answers leaves the indicator up until the
* window is reloaded.
*/
commitMessageTimeout: z.number().int().min(10).max(600).optional(),
Comment thread
Rafael-Silva-Oliveira marked this conversation as resolved.
historyPreviewCollapsed: z.boolean().optional(),
reasoningBlockCollapsed: z.boolean().optional(),
/**
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/vscode-extension-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ export type ExtensionState = Pick<
| "customModePrompts"
| "customSupportPrompts"
| "enhancementApiConfigId"
| "commitMessageApiConfigId"
| "commitMessageTimeout"
| "customCondensingPrompt"
| "codebaseIndexConfig"
| "codebaseIndexModels"
Expand Down
3 changes: 3 additions & 0 deletions packages/types/src/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export const commandIds = [
"focusPanel",
"toggleAutoApprove",

"generateCommitMessage",
"stopGeneratingCommitMessage",

"showRipgrepDiagnostic",
] as const

Expand Down
26 changes: 26 additions & 0 deletions src/activate/__tests__/registerCommands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ vi.mock("../../i18n", () => ({
t: (key: string) => key,
}))

vi.mock("../../services/commit-message", () => ({
generateCommitMessage: vi.fn().mockResolvedValue(undefined),
stopGeneratingCommitMessage: vi.fn().mockResolvedValue(undefined),
}))

vi.mock("../../services/ripgrep/diagnostic", () => ({
registerRipgrepDiagnosticCommand: vi.fn().mockReturnValue({ dispose: vi.fn() }),
}))
Expand Down Expand Up @@ -192,6 +197,27 @@ describe("registerCommands handlers", () => {
expect(mockContext.subscriptions).toContain(disposable)
})

it("generateCommitMessage forwards the clicked source control to the generator", async () => {
const { generateCommitMessage } = await import("../../services/commit-message")
const sourceControl = { rootUri: { fsPath: "/repo" } }

await handlers["zoo-code.generateCommitMessage"](sourceControl)

// Uses the registered provider rather than the visible one, so the Source Control button
// still works while the Zoo Code sidebar is closed.
expect(vi.mocked(generateCommitMessage)).toHaveBeenCalledWith(mockProvider, sourceControl)
})

it("stopGeneratingCommitMessage forwards the clicked source control", async () => {
const { stopGeneratingCommitMessage } = await import("../../services/commit-message")
const sourceControl = { rootUri: { fsPath: "/repo" } }

await handlers["zoo-code.stopGeneratingCommitMessage"](sourceControl)

// No provider: it only aborts the request the button above it started.
expect(vi.mocked(stopGeneratingCommitMessage)).toHaveBeenCalledWith(sourceControl)
})

it("settingsButtonClicked posts both settingsButtonClicked and didBecomeVisible actions", () => {
handlers["zoo-code.settingsButtonClicked"]()

Expand Down
7 changes: 7 additions & 0 deletions src/activate/registerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { CodeIndexManager } from "../services/code-index/manager"
import { importSettingsWithFeedback } from "../core/config/importExport"
import { MdmService } from "../services/mdm/MdmService"
import { registerRipgrepDiagnosticCommand } from "../services/ripgrep/diagnostic"
import { generateCommitMessage, stopGeneratingCommitMessage } from "../services/commit-message"
import { t } from "../i18n"

/**
Expand Down Expand Up @@ -219,6 +220,12 @@ const getCommandsMap = ({
outputChannel.appendLine(`[toggleAutoApprove] postMessageToWebview failed: ${error}`)
}
},
// Uses `provider` rather than the visible instance so the Source Control button still works
// while the Zoo Code sidebar is closed.
generateCommitMessage: (sourceControl?: vscode.SourceControl) => generateCommitMessage(provider, sourceControl),
// Replaces the button above while a message is generating, so it needs no provider - it only
// aborts the request that button started.
stopGeneratingCommitMessage: (sourceControl?: vscode.SourceControl) => stopGeneratingCommitMessage(sourceControl),
})

export const openClineInNewTab = async ({ context, outputChannel }: Omit<RegisterCommandOptions, "provider">) => {
Expand Down
6 changes: 6 additions & 0 deletions src/core/webview/ClineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2461,6 +2461,8 @@ export class ClineProvider
customModePrompts,
customSupportPrompts,
enhancementApiConfigId,
commitMessageApiConfigId,
commitMessageTimeout,
autoApprovalEnabled,
customModes,
experiments,
Expand Down Expand Up @@ -2619,6 +2621,8 @@ export class ClineProvider
customModePrompts: customModePrompts ?? {},
customSupportPrompts: customSupportPrompts ?? {},
enhancementApiConfigId,
commitMessageApiConfigId,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
commitMessageTimeout,
autoApprovalEnabled: autoApprovalEnabled ?? false,
customModes,
experiments: experiments ?? experimentDefault,
Expand Down Expand Up @@ -2852,6 +2856,8 @@ export class ClineProvider
customModePrompts: stateValues.customModePrompts ?? {},
customSupportPrompts: stateValues.customSupportPrompts ?? {},
enhancementApiConfigId: stateValues.enhancementApiConfigId,
commitMessageApiConfigId: stateValues.commitMessageApiConfigId,
Comment thread
Rafael-Silva-Oliveira marked this conversation as resolved.
commitMessageTimeout: stateValues.commitMessageTimeout,
experiments: stateValues.experiments ?? experimentDefault,
autoApprovalEnabled: stateValues.autoApprovalEnabled ?? false,
customModes,
Expand Down
79 changes: 79 additions & 0 deletions src/core/webview/__tests__/ClineProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,85 @@ describe("ClineProvider", () => {
})
})

describe("commit message model selection is included in state", () => {
// Both paths matter: the webview reads the posted state to show the current selection, and
// the generator reads getState() to pick a profile. Dropping either one makes a saved
// selection look like it reverted.
it("getStateToPostToWebview returns the saved commitMessageApiConfigId", async () => {
await provider.resolveWebviewView(mockWebviewView)
await provider.contextProxy.setValue("commitMessageApiConfigId", "config-2")

const state = await provider.getStateToPostToWebview()

expect(state.commitMessageApiConfigId).toBe("config-2")
})

it("getStateToPostToWebview leaves commitMessageApiConfigId unset when no profile is chosen", async () => {
await provider.resolveWebviewView(mockWebviewView)
await provider.contextProxy.setValue("commitMessageApiConfigId", undefined)

const state = await provider.getStateToPostToWebview()

expect(state.commitMessageApiConfigId).toBeUndefined()
})

it("getState returns the saved commitMessageApiConfigId", async () => {
await provider.resolveWebviewView(mockWebviewView)
await provider.contextProxy.setValue("commitMessageApiConfigId", "config-2")

const state = await provider.getState()

expect(state.commitMessageApiConfigId).toBe("config-2")
})

it("getState leaves commitMessageApiConfigId unset when no profile is chosen", async () => {
await provider.resolveWebviewView(mockWebviewView)
await provider.contextProxy.setValue("commitMessageApiConfigId", undefined)

const state = await provider.getState()

expect(state.commitMessageApiConfigId).toBeUndefined()
})

// The timeout is read from getState() to bound the request. Omitted from the returned state
// it reads as unset, so a configured value silently became the default instead.
it("getState returns the saved commitMessageTimeout", async () => {
await provider.resolveWebviewView(mockWebviewView)
await provider.contextProxy.setValue("commitMessageTimeout", 120)

const state = await provider.getState()

expect(state.commitMessageTimeout).toBe(120)
})

it("getState leaves commitMessageTimeout unset when no timeout is configured", async () => {
await provider.resolveWebviewView(mockWebviewView)
await provider.contextProxy.setValue("commitMessageTimeout", undefined)

const state = await provider.getState()

expect(state.commitMessageTimeout).toBeUndefined()
})

it("getStateToPostToWebview returns the saved commitMessageTimeout", async () => {
await provider.resolveWebviewView(mockWebviewView)
await provider.contextProxy.setValue("commitMessageTimeout", 120)

const state = await provider.getStateToPostToWebview()

expect(state.commitMessageTimeout).toBe(120)
})

it("getStateToPostToWebview leaves commitMessageTimeout unset when no timeout is configured", async () => {
await provider.resolveWebviewView(mockWebviewView)
await provider.contextProxy.setValue("commitMessageTimeout", undefined)

const state = await provider.getStateToPostToWebview()

expect(state.commitMessageTimeout).toBeUndefined()
})
})

it("getStateToPostToWebview passes through defined diffFuzzyThreshold value", async () => {
await provider.resolveWebviewView(mockWebviewView)
await provider.contextProxy.setValue("diffFuzzyThreshold", 0.5)
Expand Down
8 changes: 8 additions & 0 deletions src/i18n/locales/ca/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/i18n/locales/de/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
"update_support_prompt": "Failed to update support prompt",
"reset_support_prompt": "Failed to reset support prompt",
"enhance_prompt": "Failed to enhance prompt",
"commit_message_empty_response": "The model returned an empty commit message.",
"commit_message_no_repository": "No Git repository found in the Source Control panel.",
"commit_message_failed": "Failed to generate commit message: {{error}}",
"commit_message_ambiguous_repository": "Several Git repositories are open. Use the Zoo Code button in the Source Control panel of the repository you want.",
"commit_message_timeout": "No commit message after {{seconds}} seconds. The provider did not respond - try again, or raise the timeout in Settings.",
"get_system_prompt": "Failed to get system prompt",
"search_commits": "Failed to search commits",
"save_api_config": "Failed to save api configuration",
Expand Down Expand Up @@ -160,6 +165,9 @@
},
"info": {
"no_changes": "No changes found.",
"commit_message_no_changes": "No changes to commit.",
"commit_message_box_not_empty": "Kept your commit message. Clear the box to generate a new one.",
"commit_message_already_generating": "Already generating a commit message.",
"clipboard_copy": "System prompt successfully copied to clipboard",
"history_cleanup": "Cleaned up {{count}} task(s) with missing files from history.",
"custom_storage_path_set": "Custom storage path set: {{path}}",
Expand Down
8 changes: 8 additions & 0 deletions src/i18n/locales/es/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/i18n/locales/fr/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading