From aa1a5ddde1a310af51eadd46c1ffee3c419fc6fd Mon Sep 17 00:00:00 2001 From: Willie Date: Thu, 1 Oct 2026 21:22:08 +0800 Subject: [PATCH] fix(hooks): keep account bindings when editing from a target tab TargetHooks opened HookDialog without the account map, so the dialog's picker only knew built-in Agents and saving dropped bindings such as codex-2 from the source. The next sync would then remove that account's hook without warning. --- ui/src/components/targets/TargetHooks.test.tsx | 15 ++++++++++++++- ui/src/components/targets/TargetHooks.tsx | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ui/src/components/targets/TargetHooks.test.tsx b/ui/src/components/targets/TargetHooks.test.tsx index 14fc6a7df..da91adfd3 100644 --- a/ui/src/components/targets/TargetHooks.test.tsx +++ b/ui/src/components/targets/TargetHooks.test.tsx @@ -10,7 +10,7 @@ import { hookAgents } from '../../api/hooks'; import { ToastProvider } from '../Toast'; import TargetHooks from './TargetHooks'; -vi.mock('../../api/hooks', async (load) => ({ ...await load(), hooksApi: { syncProject: vi.fn().mockResolvedValue({ applied: [], backupIds: [] }), configure: vi.fn().mockResolvedValue({ applied: [], backupIds: [] }), preview: vi.fn(), save: vi.fn() } })); +vi.mock('../../api/hooks', async (load) => ({ ...await load(), hooksApi: { syncProject: vi.fn().mockResolvedValue({ applied: [], backupIds: [] }), configure: vi.fn().mockResolvedValue({ applied: [], backupIds: [] }), preview: vi.fn(), save: vi.fn(), catalog: vi.fn().mockResolvedValue({}) } })); const codex = { bindings: { codex: { events: { Stop: [{ hooks: [{ type: 'command', command: 'true' }] }] } } } }; const data = { @@ -71,6 +71,19 @@ describe('Target hooks tab', () => { }); }); +describe('Target hooks editing', () => { + it("keeps the hook's account bindings when it is saved from an Agent's tab", async () => { + vi.mocked(hooksApi.save).mockResolvedValue({ applied: [], backupIds: [] }); + const both = { bindings: { codex: codex.bindings.codex, 'codex-2': codex.bindings.codex } }; + const inventory = { ...data, source: { ...data.source, entries: { 'global-lint': both } }, targets: [{ name: 'codex', kind: 'command' }, { name: 'codex-2', agent: 'codex', kind: 'command' }] } as unknown as HookInventory; + const user = userEvent.setup(); + render(); + await user.click(screen.getByRole('button', { name: 'Edit global-lint' })); + await user.click(await screen.findByRole('button', { name: 'Save' })); + await waitFor(() => expect(hooksApi.save).toHaveBeenCalledWith({ name: 'global-lint', entry: both })); + }); +}); + describe('Target hooks conflicts', () => { const blocked = (changes: object[]) => ({ ...data, plan: { revision: 'r1', fingerprint: 'fp', sourcePath: '', blocked: true, changes } }) as unknown as HookInventory; const show = (inventory: HookInventory) => render( diff --git a/ui/src/components/targets/TargetHooks.tsx b/ui/src/components/targets/TargetHooks.tsx index 6eb736ea2..200b55f10 100644 --- a/ui/src/components/targets/TargetHooks.tsx +++ b/ui/src/components/targets/TargetHooks.tsx @@ -8,7 +8,7 @@ import EmptyState from '../EmptyState'; import { useToast } from '../Toast'; import HookDialog from '../hooks/HookDialog'; import { HooksSyncDialog } from '../hooks/HooksSyncBox'; -import { blockedHint, boundAgents, hookLabel, hookMessage, hookNote, isCodeAgent, scopeEntries, scopePlan, syncState, writes } from '../hooks/hooksView'; +import { blockedHint, boundAgents, hookAccounts, hookLabel, hookMessage, hookNote, isCodeAgent, scopeEntries, scopePlan, syncState, writes } from '../hooks/hooksView'; import { useT } from '../../i18n'; import { queryKeys } from '../../lib/queryKeys'; @@ -98,6 +98,7 @@ export default function TargetHooks({ agent, data, project }: { agent: string; d {syncing && setSyncing(false)} />} {editing && (