mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-18 13:23:33 +08:00
The desktop app could read plugin-produced skills and agents, but it had no plugin control plane of its own. This adds a dedicated Settings tab backed by server-side plugin APIs so installed plugins can be inspected, enabled, disabled, updated, reloaded, and uninstalled from the WebUI. The implementation also teaches browser-based desktop dev sessions to honor a custom backend URL, which made it possible to run isolated worktree ports for real UI automation. During verification, the long-lived desktop server kept a stale installed-plugin snapshot after external CLI mutations, so cache clearing now resets that session-level plugin installation state as well. Constraint: Desktop WebUI needed an isolated backend URL instead of the hard-coded 127.0.0.1:3456 fallback Constraint: Reuse existing plugin operations and loaders instead of rebuilding plugin lifecycle logic in the desktop layer Rejected: Fold plugin management into Skills or Adapters | mixed unrelated lifecycles and hid plugin-specific health/actions Rejected: Expose only read-only plugin status in desktop | did not satisfy enable-disable-reload-uninstall verification needs Confidence: high Scope-risk: moderate Reversibility: clean Directive: Keep desktop plugin actions routed through the shared plugin operation layer and clear installed-plugin session caches when plugin state changes externally Tested: cd desktop && bun run lint Tested: cd desktop && bun run test -- src/__tests__/pluginsSettings.test.tsx Tested: bun test src/server/__tests__/plugins.test.ts src/server/__tests__/skills.test.ts Tested: Browser automation against isolated ports 15120/38456 covering discord plugin list/detail/disable/apply/enable/update/uninstall flows Not-tested: Full desktop session runtime parity with CLI /reload-plugins AppState refresh beyond the new desktop API path
228 lines
6.4 KiB
TypeScript
228 lines
6.4 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { fireEvent, render, screen } from '@testing-library/react'
|
|
import '@testing-library/jest-dom'
|
|
|
|
import { Settings } from '../pages/Settings'
|
|
import { usePluginStore } from '../stores/pluginStore'
|
|
import { useSettingsStore } from '../stores/settingsStore'
|
|
import { useSessionStore } from '../stores/sessionStore'
|
|
|
|
vi.mock('../api/agents', () => ({
|
|
agentsApi: {
|
|
list: vi.fn().mockResolvedValue({ activeAgents: [], allAgents: [] }),
|
|
},
|
|
}))
|
|
|
|
vi.mock('../stores/providerStore', () => ({
|
|
useProviderStore: () => ({
|
|
providers: [],
|
|
activeId: null,
|
|
isLoading: false,
|
|
fetchProviders: vi.fn(),
|
|
deleteProvider: vi.fn(),
|
|
activateProvider: vi.fn(),
|
|
activateOfficial: vi.fn(),
|
|
testProvider: vi.fn(),
|
|
createProvider: vi.fn(),
|
|
updateProvider: vi.fn(),
|
|
testConfig: vi.fn(),
|
|
}),
|
|
}))
|
|
|
|
vi.mock('../pages/AdapterSettings', () => ({
|
|
AdapterSettings: () => <div>Adapter Settings Mock</div>,
|
|
}))
|
|
|
|
vi.mock('../stores/agentStore', () => ({
|
|
useAgentStore: () => ({
|
|
activeAgents: [],
|
|
allAgents: [],
|
|
isLoading: false,
|
|
error: null,
|
|
selectedAgent: null,
|
|
fetchAgents: vi.fn(),
|
|
selectAgent: vi.fn(),
|
|
}),
|
|
}))
|
|
|
|
vi.mock('../stores/skillStore', () => ({
|
|
useSkillStore: () => ({
|
|
skills: [],
|
|
selectedSkill: null,
|
|
isLoading: false,
|
|
isDetailLoading: false,
|
|
error: null,
|
|
fetchSkills: vi.fn(),
|
|
fetchSkillDetail: vi.fn(),
|
|
clearSelection: vi.fn(),
|
|
}),
|
|
}))
|
|
|
|
const noop = vi.fn()
|
|
|
|
function switchToPluginsTab() {
|
|
fireEvent.click(screen.getByText('Plugins'))
|
|
}
|
|
|
|
describe('Settings > Plugins tab', () => {
|
|
beforeEach(() => {
|
|
useSettingsStore.setState({ locale: 'en' })
|
|
useSessionStore.setState({
|
|
sessions: [
|
|
{
|
|
id: 'session-1',
|
|
title: 'Active session',
|
|
createdAt: '2026-04-20T00:00:00.000Z',
|
|
modifiedAt: '2026-04-20T00:00:00.000Z',
|
|
messageCount: 1,
|
|
projectPath: '/workspace/project',
|
|
workDir: '/workspace/project',
|
|
workDirExists: true,
|
|
},
|
|
],
|
|
activeSessionId: 'session-1',
|
|
isLoading: false,
|
|
error: null,
|
|
})
|
|
usePluginStore.setState({
|
|
plugins: [],
|
|
marketplaces: [],
|
|
summary: { total: 0, enabled: 0, errorCount: 0, marketplaceCount: 0 },
|
|
selectedPlugin: null,
|
|
lastReloadSummary: null,
|
|
isLoading: false,
|
|
isDetailLoading: false,
|
|
isApplying: false,
|
|
error: null,
|
|
fetchPlugins: noop,
|
|
fetchPluginDetail: noop,
|
|
reloadPlugins: vi.fn().mockResolvedValue({
|
|
enabled: 1,
|
|
disabled: 0,
|
|
skills: 2,
|
|
agents: 1,
|
|
hooks: 0,
|
|
mcpServers: 1,
|
|
lspServers: 0,
|
|
errors: 0,
|
|
}),
|
|
enablePlugin: vi.fn().mockResolvedValue('enabled'),
|
|
disablePlugin: vi.fn().mockResolvedValue('disabled'),
|
|
updatePlugin: vi.fn().mockResolvedValue('updated'),
|
|
uninstallPlugin: vi.fn().mockResolvedValue('uninstalled'),
|
|
clearSelection: vi.fn(),
|
|
})
|
|
})
|
|
|
|
it('renders plugin browser summary and grouped cards', () => {
|
|
usePluginStore.setState({
|
|
plugins: [
|
|
{
|
|
id: 'github@claude-plugins-official',
|
|
name: 'github',
|
|
marketplace: 'claude-plugins-official',
|
|
scope: 'user',
|
|
enabled: true,
|
|
hasErrors: false,
|
|
isBuiltin: false,
|
|
version: '1.2.3',
|
|
description: 'GitHub integration',
|
|
authorName: 'Anthropic',
|
|
componentCounts: {
|
|
commands: 1,
|
|
agents: 1,
|
|
skills: 2,
|
|
hooks: 0,
|
|
mcpServers: 1,
|
|
lspServers: 0,
|
|
},
|
|
errors: [],
|
|
},
|
|
{
|
|
id: 'pyright-lsp@claude-plugins-official',
|
|
name: 'pyright-lsp',
|
|
marketplace: 'claude-plugins-official',
|
|
scope: 'project',
|
|
enabled: false,
|
|
hasErrors: true,
|
|
isBuiltin: false,
|
|
description: 'Python language tooling',
|
|
componentCounts: {
|
|
commands: 0,
|
|
agents: 0,
|
|
skills: 0,
|
|
hooks: 0,
|
|
mcpServers: 0,
|
|
lspServers: 1,
|
|
},
|
|
errors: ['Executable not found in $PATH'],
|
|
},
|
|
],
|
|
marketplaces: [
|
|
{
|
|
name: 'claude-plugins-official',
|
|
source: 'github:anthropics/claude-plugins-official',
|
|
autoUpdate: true,
|
|
installedCount: 2,
|
|
},
|
|
],
|
|
summary: { total: 2, enabled: 1, errorCount: 1, marketplaceCount: 1 },
|
|
})
|
|
|
|
render(<Settings />)
|
|
switchToPluginsTab()
|
|
|
|
expect(screen.getByText('Browse installed plugins')).toBeInTheDocument()
|
|
expect(screen.getByText('Plugin Manager')).toBeInTheDocument()
|
|
expect(screen.getAllByText('Needs attention').length).toBeGreaterThan(0)
|
|
expect(screen.getByText('github')).toBeInTheDocument()
|
|
expect(screen.getByText('Python language tooling')).toBeInTheDocument()
|
|
expect(screen.getByText('Known marketplaces')).toBeInTheDocument()
|
|
})
|
|
|
|
it('renders plugin detail with bundled capability sections', () => {
|
|
usePluginStore.setState({
|
|
selectedPlugin: {
|
|
id: 'github@claude-plugins-official',
|
|
name: 'github',
|
|
marketplace: 'claude-plugins-official',
|
|
scope: 'user',
|
|
enabled: true,
|
|
hasErrors: false,
|
|
isBuiltin: false,
|
|
version: '1.2.3',
|
|
description: 'GitHub integration',
|
|
authorName: 'Anthropic',
|
|
installPath: '/Users/test/.claude/plugins/cache/github',
|
|
componentCounts: {
|
|
commands: 1,
|
|
agents: 1,
|
|
skills: 2,
|
|
hooks: 1,
|
|
mcpServers: 1,
|
|
lspServers: 0,
|
|
},
|
|
capabilities: {
|
|
commands: ['review-pr'],
|
|
agents: ['pr-reviewer'],
|
|
skills: ['commit', 'create-pr'],
|
|
hooks: ['SessionStart'],
|
|
mcpServers: ['github-api'],
|
|
lspServers: [],
|
|
},
|
|
errors: [],
|
|
},
|
|
})
|
|
|
|
render(<Settings />)
|
|
switchToPluginsTab()
|
|
|
|
expect(screen.getByText('Plugin Detail')).toBeInTheDocument()
|
|
expect(screen.getByText('GitHub integration')).toBeInTheDocument()
|
|
expect(screen.getByText('Bundled capabilities')).toBeInTheDocument()
|
|
expect(screen.getByText('review-pr')).toBeInTheDocument()
|
|
expect(screen.getByText('Apply changes')).toBeInTheDocument()
|
|
expect(screen.getByText('Uninstall')).toBeInTheDocument()
|
|
})
|
|
})
|