mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 16:02:32 +00:00
fix: address review findings (#5040)
This commit is contained in:
@@ -1,11 +1,29 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { buildCommitMessageGenerationParams } from './SourceControlTextGenerationDialog'
|
||||
import { getDefaultSourceControlTextGenerationSaveTargetKey } from './SourceControlTextGenerationDialogForm'
|
||||
import {
|
||||
applyCommitMessageGenerationDefaults,
|
||||
applySourceControlTextGenerationDefaults
|
||||
} from './SourceControlTextGenerationDefaults'
|
||||
|
||||
describe('buildCommitMessageGenerationParams', () => {
|
||||
it('defaults saved text-generation recipes to the global target when repo and global are available', () => {
|
||||
expect(
|
||||
getDefaultSourceControlTextGenerationSaveTargetKey([
|
||||
{
|
||||
target: { type: 'repo', repoId: 'repo-1' },
|
||||
label: 'Save for this repository only',
|
||||
successMessage: ''
|
||||
},
|
||||
{
|
||||
target: { type: 'global' },
|
||||
label: 'Save as default for all repositories',
|
||||
successMessage: ''
|
||||
}
|
||||
])
|
||||
).toBe('global')
|
||||
})
|
||||
|
||||
it('preserves the resolved model and thinking level for the selected agent', () => {
|
||||
expect(
|
||||
buildCommitMessageGenerationParams({
|
||||
|
||||
+12
-4
@@ -54,10 +54,20 @@ type SourceControlTextGenerationDialogFormProps = {
|
||||
) => Promise<void> | void
|
||||
}
|
||||
|
||||
function sourceControlTextGenerationSaveTargetKey(target: SourceControlAiWriteTarget): string {
|
||||
export function sourceControlTextGenerationSaveTargetKey(
|
||||
target: SourceControlAiWriteTarget
|
||||
): string {
|
||||
return target.type === 'repo' ? `repo:${target.repoId}` : 'global'
|
||||
}
|
||||
|
||||
export function getDefaultSourceControlTextGenerationSaveTargetKey(
|
||||
saveTargets: SourceControlTextGenerationSaveTarget[]
|
||||
): string {
|
||||
const defaultTarget =
|
||||
saveTargets.find((saveTarget) => saveTarget.target.type === 'global') ?? saveTargets[0]
|
||||
return defaultTarget ? sourceControlTextGenerationSaveTargetKey(defaultTarget.target) : 'global'
|
||||
}
|
||||
|
||||
function agentLabel(agentId: TuiAgent): string {
|
||||
return getAgentCatalog().find((agent) => agent.id === agentId)?.label ?? agentId
|
||||
}
|
||||
@@ -86,9 +96,7 @@ export function SourceControlTextGenerationDialogForm({
|
||||
const [agentArgs, setAgentArgs] = useState(baseParams?.agentArgs ?? '')
|
||||
const [generationError, setGenerationError] = useState<string | null>(null)
|
||||
const [savingTargetKey, setSavingTargetKey] = useState<string | null>(null)
|
||||
const defaultSaveTargetKey = saveTargets[0]
|
||||
? sourceControlTextGenerationSaveTargetKey(saveTargets[0].target)
|
||||
: 'global'
|
||||
const defaultSaveTargetKey = getDefaultSourceControlTextGenerationSaveTargetKey(saveTargets)
|
||||
const [saveTargetKey, setSaveTargetKey] = useState(defaultSaveTargetKey)
|
||||
const commandTemplateId = `source-control-${actionId}-command-template`
|
||||
const selectedSaveTarget =
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import type { getAgentCatalog } from '@/lib/agent-catalog'
|
||||
import type { useAppStore } from '@/store'
|
||||
import type { useRepoById } from '@/store/selectors'
|
||||
import type { TuiAgent } from '../../../../shared/types'
|
||||
import type { SourceControlAgentActionDeliveryPlanState } from './SourceControlAgentActionDialogForm'
|
||||
|
||||
export type UseSourceControlAgentActionDialogResult = {
|
||||
handleOpenChange: (nextOpen: boolean) => void
|
||||
agentOptions: ReturnType<typeof getAgentCatalog>
|
||||
selectedAgent: TuiAgent | null
|
||||
hasEnabledAgents: boolean
|
||||
detecting: boolean
|
||||
statusCopy: string | null
|
||||
agentArgs: string
|
||||
commandTemplate: string
|
||||
saveTargetValue: string
|
||||
saveTargets: { value: string; label: string }[]
|
||||
settings: ReturnType<typeof useAppStore.getState>['settings']
|
||||
repo: ReturnType<typeof useRepoById>
|
||||
deliveryPlan: SourceControlAgentActionDeliveryPlanState
|
||||
canStart: boolean
|
||||
isStarting: boolean
|
||||
onSelectedAgentChange: (agent: TuiAgent | null) => void
|
||||
onAgentArgsChange: (value: string) => void
|
||||
onCommandTemplateChange: (value: string) => void
|
||||
onSaveAgentDefaultChange: (value: string) => void
|
||||
handleStart: () => Promise<void>
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
buildSourceControlAgentSaveTargets,
|
||||
getDefaultSourceControlAgentSaveTargetValue
|
||||
} from './source-control-agent-action-dialog-support'
|
||||
|
||||
describe('source control agent action dialog save targets', () => {
|
||||
it('defaults saved launch recipes to the global target even when a repo target exists', () => {
|
||||
expect(buildSourceControlAgentSaveTargets('repo-1').map((target) => target.value)).toEqual([
|
||||
'none',
|
||||
'repo',
|
||||
'global'
|
||||
])
|
||||
expect(getDefaultSourceControlAgentSaveTargetValue()).toBe('global')
|
||||
})
|
||||
})
|
||||
+4
@@ -44,6 +44,10 @@ export function buildSourceControlAgentSaveTargets(repoId?: string | null): {
|
||||
return targets
|
||||
}
|
||||
|
||||
export function getDefaultSourceControlAgentSaveTargetValue(): string {
|
||||
return 'global'
|
||||
}
|
||||
|
||||
export function buildSourceControlAgentConnectionErrorPlan(): SourceControlAgentActionDeliveryPlanState {
|
||||
return {
|
||||
status: 'error',
|
||||
|
||||
@@ -9,6 +9,7 @@ import { isTuiAgentEnabled } from '../../../../shared/tui-agent-selection'
|
||||
import type { TuiAgent } from '../../../../shared/types'
|
||||
import { type SourceControlAgentActionDeliveryPlanState } from './SourceControlAgentActionDialogForm'
|
||||
import type { SourceControlAgentActionDialogProps } from './SourceControlAgentActionDialog'
|
||||
import type { UseSourceControlAgentActionDialogResult } from './source-control-agent-action-dialog-result'
|
||||
import {
|
||||
buildSourceControlAgentConnectionErrorPlan,
|
||||
buildSourceControlAgentSaveTargets,
|
||||
@@ -17,28 +18,7 @@ import {
|
||||
} from './source-control-agent-action-dialog-support'
|
||||
import { runSourceControlAgentActionStart } from './runSourceControlAgentActionStart'
|
||||
|
||||
export type UseSourceControlAgentActionDialogResult = {
|
||||
handleOpenChange: (nextOpen: boolean) => void
|
||||
agentOptions: ReturnType<typeof getAgentCatalog>
|
||||
selectedAgent: TuiAgent | null
|
||||
hasEnabledAgents: boolean
|
||||
detecting: boolean
|
||||
statusCopy: string | null
|
||||
agentArgs: string
|
||||
commandTemplate: string
|
||||
saveTargetValue: string
|
||||
saveTargets: { value: string; label: string }[]
|
||||
settings: ReturnType<typeof useAppStore.getState>['settings']
|
||||
repo: ReturnType<typeof useRepoById>
|
||||
deliveryPlan: SourceControlAgentActionDeliveryPlanState
|
||||
canStart: boolean
|
||||
isStarting: boolean
|
||||
onSelectedAgentChange: (agent: TuiAgent | null) => void
|
||||
onAgentArgsChange: (value: string) => void
|
||||
onCommandTemplateChange: (value: string) => void
|
||||
onSaveAgentDefaultChange: (value: string) => void
|
||||
handleStart: () => Promise<void>
|
||||
}
|
||||
const DEFAULT_SAVE_TARGET_VALUE = 'global'
|
||||
|
||||
export function useSourceControlAgentActionDialog({
|
||||
open,
|
||||
@@ -75,7 +55,7 @@ export function useSourceControlAgentActionDialog({
|
||||
})
|
||||
const [isStarting, setIsStarting] = useState(false)
|
||||
const saveTargets = useMemo(() => buildSourceControlAgentSaveTargets(repoId), [repoId])
|
||||
const [saveTargetValue, setSaveTargetValue] = useState(repoId ? 'repo' : 'global')
|
||||
const [saveTargetValue, setSaveTargetValue] = useState(DEFAULT_SAVE_TARGET_VALUE)
|
||||
|
||||
const disabledAgents = settings?.disabledTuiAgents
|
||||
const connectionUnavailable = Boolean(worktreeId && connectionId === undefined)
|
||||
@@ -106,7 +86,7 @@ export function useSourceControlAgentActionDialog({
|
||||
setCommandTemplate(savedCommandInputTemplate ?? '{basePrompt}')
|
||||
setAgentArgs(savedAgentArgs ?? '')
|
||||
setSelectedAgent(savedAgentId ?? null)
|
||||
setSaveTargetValue(repoId ? 'repo' : 'global')
|
||||
setSaveTargetValue(DEFAULT_SAVE_TARGET_VALUE)
|
||||
let stale = false
|
||||
void refreshDetectedAgents().then((nextAgents) => {
|
||||
if (stale) {
|
||||
@@ -141,11 +121,11 @@ export function useSourceControlAgentActionDialog({
|
||||
(nextOpen: boolean) => {
|
||||
if (!nextOpen) {
|
||||
setDeliveryPlan({ status: 'idle' })
|
||||
setSaveTargetValue(repoId ? 'repo' : 'global')
|
||||
setSaveTargetValue(DEFAULT_SAVE_TARGET_VALUE)
|
||||
}
|
||||
onOpenChange(nextOpen)
|
||||
},
|
||||
[onOpenChange, repoId]
|
||||
[onOpenChange]
|
||||
)
|
||||
|
||||
const enabledDetectedAgents = useMemo(
|
||||
|
||||
Reference in New Issue
Block a user