Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ describe('registerFilesystemHandlers', () => {
handlers.get('git:generateCommitMessage')!(null, {
worktreePath: WORKTREE_FEATURE_PATH
})
).resolves.toEqual({
).resolves.toMatchObject({
success: false,
error: 'Failed to prepare the selected agent account for commit message generation.'
})
Expand Down Expand Up @@ -454,7 +454,7 @@ describe('registerFilesystemHandlers', () => {
worktreePath: '/remote/repo',
connectionId: 'conn-1'
})
).resolves.toEqual({ success: false, error: SSH_HOST_NOT_SERVED_MESSAGE })
).resolves.toMatchObject({ success: false, error: SSH_HOST_NOT_SERVED_MESSAGE })
expect(getStagedCommitContextMock).not.toHaveBeenCalled()
expect(generateCommitMessageFromContextMock).not.toHaveBeenCalled()
})
Expand Down Expand Up @@ -488,7 +488,7 @@ describe('registerFilesystemHandlers', () => {
handlers.get('git:generateCommitMessage')!(null, {
worktreePath: WORKTREE_FEATURE_PATH
})
).resolves.toEqual({ success: false, error: 'No staged changes to summarize.' })
).resolves.toMatchObject({ success: false, error: 'No staged changes to summarize.' })

expect(generateCommitMessageFromContextMock).not.toHaveBeenCalled()
})
Expand All @@ -506,7 +506,7 @@ describe('registerFilesystemHandlers', () => {
handlers.get('git:generateCommitMessage')!(null, {
worktreePath: WORKTREE_FEATURE_PATH
})
).resolves.toEqual({ success: false, error: 'Failed to read staged changes.' })
).resolves.toMatchObject({ success: false, error: 'Failed to read staged changes.' })

expect(generateCommitMessageFromContextMock).not.toHaveBeenCalled()
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { textGenerationFailure } from '../../../shared/text-generation-failure-copy'
import { ipcMain } from 'electron'
import type { GlobalSettings } from '../../../shared/global-settings-types'
import type { ResolvedSourceControlAiGenerationParams } from '../../../shared/source-control-ai'
Expand Down Expand Up @@ -80,11 +81,11 @@ export function registerFilesystemGitCommitGenerationHandlers(
console.error('[filesystem] Failed to read staged commit context:', error)
return {
success: false,
error: 'Failed to read staged changes.'
...textGenerationFailure('stagedChangesReadFailed')
}
}
if (!context) {
return { success: false, error: 'No staged changes to summarize.' }
return { success: false, ...textGenerationFailure('noStagedChanges') }
}
context = withLinkedIssueDraftContext(
context,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { textGenerationFailure } from '../../../shared/text-generation-failure-copy'
import { ipcMain } from 'electron'
import type { GlobalSettings } from '../../../shared/global-settings-types'
import type { ResolvedSourceControlAiGenerationParams } from '../../../shared/source-control-ai'
Expand Down Expand Up @@ -122,7 +123,7 @@ export function registerFilesystemGitPullRequestGenerationHandlers(
}
}
if (!context) {
return { success: false, error: 'No branch changes to summarize.' }
return { success: false, ...textGenerationFailure('noBranchChanges') }
}
const linkedIssueDetails = await linkedIssueDetailsPromise
context = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('PR linked-issue lifetime on a local worktree', () => {
try {
await expect(
handlers.get('git:generatePullRequestFields')!(null, request)
).resolves.toEqual({
).resolves.toMatchObject({
success: false,
error:
outcome === 'no changes' ? 'No branch changes to summarize.' : preparationError.message
Expand Down
4 changes: 2 additions & 2 deletions src/main/runtime/runtime-git-generation-admission.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('RuntimeGitGenerationCommands admission', () => {
{ base: 'main', title: '', body: '', draft: false },
settingsOverride
)
).resolves.toEqual({ success: false, error: SSH_HOST_NOT_SERVED_MESSAGE })
).resolves.toMatchObject({ success: false, error: SSH_HOST_NOT_SERVED_MESSAGE })
expect(mocks.getPullRequestDraftContext).not.toHaveBeenCalled()
expect(mocks.gitExecFileAsync).not.toHaveBeenCalled()
expect(mocks.loadPullRequestLinkedIssue).not.toHaveBeenCalled()
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('RuntimeGitGenerationCommands admission', () => {
try {
await expect(
commands().generateRuntimePullRequestFields('id:wt-1', input, settingsOverride)
).resolves.toEqual({
).resolves.toMatchObject({
success: false,
error:
outcome === 'no changes'
Expand Down
25 changes: 19 additions & 6 deletions src/main/runtime/runtime-git-generation-commands.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { textGenerationFailure } from '../../shared/text-generation-failure-copy'
import type { CommitMessageDraftContext } from '../../shared/commit-message-generation'
import { getCommitMessageModelDiscoveryHostKey } from '../../shared/commit-message-host-key'
import type { HostedReviewProvider } from '../../shared/hosted-review'
Expand Down Expand Up @@ -48,7 +49,10 @@ export class RuntimeGitGenerationCommands {
settingsOverride?.commitMessageDiscoveryHostKey ??
getCommitMessageModelDiscoveryHostKey(route.kind === 'ssh' ? route.connectionId : null)
const resolvedSettings = settingsOverride?.sourceControlAiResolvedParams
? { ok: true as const, params: settingsOverride.sourceControlAiResolvedParams }
? {
ok: true as const,
params: settingsOverride.sourceControlAiResolvedParams
}
: resolveCommitMessageSettings(
getRuntimeGitGenerationSettings(
this.host.getRuntimeSettings(),
Expand All @@ -75,10 +79,13 @@ export class RuntimeGitGenerationCommands {
})
} catch (error) {
console.error('[runtime-git] Failed to read staged commit context:', error)
return { success: false, error: 'Failed to read staged changes.' }
return {
success: false,
...textGenerationFailure('stagedChangesReadFailed')
}
}
if (!context) {
return { success: false, error: 'No staged changes to summarize.' }
return { success: false, ...textGenerationFailure('noStagedChanges') }
}
context = withLinkedIssueDraftContext(context, linkedIssueForTarget(this.host, target))
const localEnv = await prepareLocalCommitMessageAgentEnv(
Expand Down Expand Up @@ -125,7 +132,10 @@ export class RuntimeGitGenerationCommands {
settingsOverride?.commitMessageDiscoveryHostKey ??
getCommitMessageModelDiscoveryHostKey(route.kind === 'ssh' ? route.connectionId : null)
const resolvedSettings = settingsOverride?.sourceControlAiResolvedParams
? { ok: true as const, params: settingsOverride.sourceControlAiResolvedParams }
? {
ok: true as const,
params: settingsOverride.sourceControlAiResolvedParams
}
: resolveCommitMessageSettings(
getRuntimeGitGenerationSettings(
this.host.getRuntimeSettings(),
Expand Down Expand Up @@ -175,7 +185,7 @@ export class RuntimeGitGenerationCommands {
}
}
if (!context) {
return { success: false, error: 'No branch changes to summarize.' }
return { success: false, ...textGenerationFailure('noBranchChanges') }
}
const linkedIssueDetails = await linkedIssueDetailsPromise
context = {
Expand Down Expand Up @@ -221,7 +231,10 @@ export class RuntimeGitGenerationCommands {
this.host.getRuntimeSettings().agentCmdOverrides?.[typedAgentId]
const route = runtimeGitRouteForTarget(target)
if (route.kind === 'ssh') {
return { success: false, error: `No git provider for connection "${route.connectionId}"` }
return {
success: false,
error: `No git provider for connection "${route.connectionId}"`
}
}
const localEnv = await prepareLocalCommitMessageAgentEnv(
typedAgentId,
Expand Down
15 changes: 9 additions & 6 deletions src/main/text-generation/agent-generation-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import type { ResolvedSourceControlAiGenerationParams } from '../../shared/source-control-ai'
import { openCodeVariantRetryPlan } from '../../shared/opencode-generation-command'
import { runLocalPlanForAgent } from './source-control-local-generation'
import { emptyResultFailure } from './source-control-agent-failure'
import { runRemoteSourceControlPlan } from './source-control-remote-generation'
import type {
CommitMessageGenerationTarget,
Expand All @@ -33,12 +34,14 @@ export async function runGenerationRequest(input: {
params: GenerateParams
prompt: string
target: CommitMessageGenerationTarget
emptyResultName: string
operation: TextGenerationOperation
spawnAgent: SpawnSourceControlAgent
shouldExecute?: () => boolean
}): Promise<InternalTextGenerationResult> {
const params = { ...input.params, backslash: commandBackslashMode(input.target) }
const params = {
...input.params,
backslash: commandBackslashMode(input.target)
}
const planned = planCommitMessageGeneration(params, input.prompt)
if (!planned.ok) {
return { success: false, error: planned.error }
Expand All @@ -49,14 +52,12 @@ export async function runGenerationRequest(input: {
? runRemoteSourceControlPlan({
plan,
target: input.target,
emptyResultName: input.emptyResultName,
operation: input.operation
})
: runLocalPlanForAgent({
agentId: input.params.agentId,
plan,
target: input.target,
emptyResultName: input.emptyResultName,
operation: input.operation,
spawnAgent: input.spawnAgent,
shouldExecute: input.shouldExecute
Expand All @@ -67,7 +68,9 @@ export async function runGenerationRequest(input: {
if (strictMcp) {
return execute(plan)
}
const retry = planCommitMessageGeneration(params, input.prompt, { strictMcp })
const retry = planCommitMessageGeneration(params, input.prompt, {
strictMcp
})
return retry.ok
? execute(retry.plan)
: Promise.resolve({ success: false, error: retry.error })
Expand Down Expand Up @@ -100,5 +103,5 @@ export async function runGenerationRequest(input: {
const rawOutput = cleanGeneratedCommitMessage(answer)
return rawOutput
? { ...result, rawOutput }
: { success: false, error: `${plan.label} returned an empty ${input.emptyResultName}.` }
: { success: false, ...emptyResultFailure(input.operation, plan.label) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('generateBranchNameFromContext', () => {
}
)

expect(result).toEqual({
expect(result).toMatchObject({
success: false,
error: 'Generated branch name was empty after sanitization.',
failureOutput: { label: 'agent', exitCode: 0, stdout: '!!! ___', stderr: '' }
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('generateBranchNameFromContext', () => {
}
)

expect(result).toEqual({
expect(result).toMatchObject({
success: false,
error: 'agent CLI command failed with code 1.',
failureOutput: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('generateCommitMessageFromContext', () => {
}
)

expect(result).toEqual({
expect(result).toMatchObject({
success: false,
error: 'agent CLI command failed with code 1: raw failure output with [path]'
})
Expand Down Expand Up @@ -58,7 +58,7 @@ describe('generateCommitMessageFromContext', () => {
}
)

expect(result).toEqual({
expect(result).toMatchObject({
success: false,
error: 'agent CLI command failed with code 1: ERROR: fatal: [path] failed'
})
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('generateCommitMessageFromContext', () => {
}
)

expect(result).toEqual({
expect(result).toMatchObject({
success: false,
error: 'agent CLI command failed with code 1: ERROR: failed at [path]'
})
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('generateCommitMessageFromContext', () => {
}
)

expect(result).toEqual({
expect(result).toMatchObject({
success: false,
error: 'agent returned an empty message. CLI output: Error: No payment method'
})
Expand Down Expand Up @@ -156,7 +156,7 @@ describe('generateCommitMessageFromContext', () => {
}
)

expect(result).toEqual({
expect(result).toMatchObject({
success: false,
error:
'Pi CLI command failed with code 1: No API key found for github-copilot. Use /login to log into a provider via OAuth or API key. See: … [path]'
Expand Down Expand Up @@ -188,7 +188,7 @@ describe('generateCommitMessageFromContext', () => {
}
)

expect(result).toEqual({
expect(result).toMatchObject({
success: false,
error: 'agent CLI command failed with code 1: ERROR: run /login then check [path]'
})
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('generateCommitMessageFromContext', () => {
}
)

expect(result).toEqual({
expect(result).toMatchObject({
success: false,
error: 'Pi CLI command failed with code 1: 401: {"message":"Invalid key loaded from [path]"}'
})
Expand Down Expand Up @@ -248,7 +248,7 @@ describe('generateCommitMessageFromContext', () => {
}
)

expect(result).toEqual({
expect(result).toMatchObject({
success: false,
error: 'Pi CLI command failed with code 1: 401: {"message":"Invalid key loaded from [path]"}'
})
Expand Down Expand Up @@ -279,7 +279,7 @@ describe('generateCommitMessageFromContext', () => {
}
)

expect(result).toEqual({
expect(result).toMatchObject({
success: false,
error:
'Pi CLI command failed with code 1: 401: Visit https://console.anthropic.com/settings/keys then check [path]'
Expand Down Expand Up @@ -310,7 +310,7 @@ describe('generateCommitMessageFromContext', () => {
}
)

expect(result).toEqual({
expect(result).toMatchObject({
success: false,
error: 'Pi CLI command failed with code 1: 401: {"message":"rejected credential_path=[path]"}'
})
Expand Down Expand Up @@ -351,7 +351,7 @@ describe('generateCommitMessageFromContext', () => {
}
)

expect(result).toEqual({ success: false, error: expected })
expect(result).toMatchObject({ success: false, error: expected })
})

it('passes the live colonless 400 gateway payload through the sanitizer unmangled', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('generateCommitMessageFromContext', () => {
}
)

expect(result).toEqual({ success: false, error: 'agent returned an empty message.' })
expect(result).toMatchObject({ success: false, error: 'agent returned an empty message.' })
})

it('reports empty remote commit-message output as an empty message', async () => {
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('generateCommitMessageFromContext', () => {
)

expect(operation).toBe('commit-message')
expect(result).toEqual({
expect(result).toMatchObject({
success: false,
error: 'agent returned an empty message.'
})
Expand Down Expand Up @@ -238,7 +238,7 @@ describe('generateCommitMessageFromContext', () => {
)

expect(operation).toBe('pull-request-fields')
expect(result).toEqual({
expect(result).toMatchObject({
success: false,
error: 'agent returned an empty details.',
branchChangedByPreparation: false
Expand Down Expand Up @@ -282,7 +282,7 @@ describe('generateCommitMessageFromContext', () => {
listeners.get('stdout:data')?.(Buffer.from('not json'))
listeners.get('close')?.(0)

await expect(pullRequest).resolves.toEqual({
await expect(pullRequest).resolves.toMatchObject({
success: false,
error:
agentId === 'kimi'
Expand Down Expand Up @@ -318,7 +318,7 @@ it.each([
stderr: '',
code: 0,
label,
emptyResultName: 'message',
operation: 'commit-message',
outputFormat
})
expect(result).toMatchObject({ success: true, rawOutput: literal })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('generateCommitMessageFromContext on the Windows direct-child path', ()
listeners.get('stdout:data')?.(Buffer.alloc(4 * 1024 * 1024 + 1))
listeners.get('close')?.(null)

await expect(pending).resolves.toEqual({
await expect(pending).resolves.toMatchObject({
success: false,
error:
'agent CLI command produced too much output. Check the agent CLI configuration and try again.'
Expand Down Expand Up @@ -271,7 +271,7 @@ describe('generateCommitMessageFromContext on the Windows direct-child path', ()
}
)

expect(result).toEqual({
expect(result).toMatchObject({
success: false,
error:
"C:/tools/agent.cmd runs through a Windows batch script that cannot take the multi-line prompt as an argument. Point Settings at the agent's executable, or use a custom command without {prompt} so Orca sends the prompt on stdin."
Expand Down
Loading
Loading