fix(desktop): preserve keyless plugin row identity
This commit is contained in:
parent
6e19c20d0a
commit
03a9c69dc6
|
|
@ -40,6 +40,7 @@ beforeEach(() => {
|
|||
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
describe('PluginsSettings', () => {
|
||||
|
|
@ -68,6 +69,27 @@ describe('PluginsSettings', () => {
|
|||
)
|
||||
})
|
||||
|
||||
it('keeps duplicate-named legacy rows distinct after a name-addressed toggle', async () => {
|
||||
const sibling = {
|
||||
...legacyRow,
|
||||
description: 'A second plugin category with the same legacy name'
|
||||
}
|
||||
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => undefined)
|
||||
|
||||
$agentPlugins.set([legacyRow, sibling])
|
||||
requestGateway.mockResolvedValue({ ok: true, plugin: { ...legacyRow, status: 'enabled' } })
|
||||
|
||||
render(<PluginsSettings />)
|
||||
fireEvent.click(screen.getAllByRole('switch', { name: 'Enable Legacy plugin' })[0])
|
||||
|
||||
await waitFor(() =>
|
||||
expect(screen.getAllByRole('switch', { name: 'Disable Legacy plugin' })).toHaveLength(2)
|
||||
)
|
||||
|
||||
expect(screen.getByText(sibling.description)).toBeTruthy()
|
||||
expect(consoleError.mock.calls.flat().join(' ')).not.toContain('same key')
|
||||
})
|
||||
|
||||
it('keeps using the canonical key when the backend provides one', async () => {
|
||||
const keyedRow = { ...legacyRow, key: 'image_gen/legacy' }
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,9 @@ const isDesktopRelevant = (row: AgentPluginRow) => {
|
|||
return !key || !HIDDEN_KEY_PREFIXES.some(prefix => key.startsWith(prefix))
|
||||
}
|
||||
|
||||
const agentPluginRowKey = (row: AgentPluginRow) =>
|
||||
row.key ?? [row.name, row.source, row.version, row.description].join('\0')
|
||||
|
||||
function reveal(file: string) {
|
||||
void window.hermesDesktop?.revealPath?.(file)?.catch(() => undefined)
|
||||
}
|
||||
|
|
@ -240,7 +243,7 @@ function AgentPluginsSection() {
|
|||
) : (
|
||||
<div>
|
||||
{sorted.map(row => (
|
||||
<AgentPluginRowView key={row.key || row.name} row={row} />
|
||||
<AgentPluginRowView key={agentPluginRowKey(row)} row={row} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -96,10 +96,14 @@ export async function toggleAgentPlugin(
|
|||
const refreshed = result.plugin
|
||||
|
||||
if (refreshed) {
|
||||
const currentRows = $agentPlugins.get()
|
||||
|
||||
$agentPlugins.set(
|
||||
$agentPlugins
|
||||
.get()
|
||||
.map(current => ((current.key ?? current.name) === address ? { ...current, ...refreshed } : current))
|
||||
row.key
|
||||
? currentRows.map(current => (current.key === row.key ? { ...current, ...refreshed } : current))
|
||||
: currentRows.map(current =>
|
||||
current.name === row.name ? { ...current, status: refreshed.status } : current
|
||||
)
|
||||
)
|
||||
} else {
|
||||
await loadAgentPlugins(request)
|
||||
|
|
|
|||
Loading…
Reference in New Issue