Files
deepseek-harness/packages/client/ui-settings/tests/plugin.client.spec.ts
T
Yichen Jiang 1570eeeaee feat(web): manage plugins and per-preset settings from the browser
Add the Manage plugins tab (ui-settings-plugin-manager): package cards
with enable/disable switches, retry and uninstall, an install dialog
streaming pnpm output, and the selected preset's composition with per-row
switches and removal; the read-only list gains provenance facts.

Settings cards edit one scope at a time: ui-settings keeps one describe
mirror per settings scope (SettingsMirrorRegistry) and binds
{ namespace, scope }; ui-settings-plugins stages forms per scope, marks
inherited fields, and adds the skill-filesystem roots card.

Fixes surfaced by driving the browser end to end: the client gateway now
lets a call omit trailing parameters that accept undefined (PR3's
optional scope arguments failed the strict arity check), the plugins
install verb is `add` because the client namespace service reserves
`install`/`remove` (guarded by remote-method-names.host.spec), a plugin
module offers its main export as an addable `.`, and describing a settings
scope no owner registered resolves over the global instance's base and
never throws.

The web e2e scaffold can mount a profile runtime over fixture packages;
plugin-manager.e2e drives the tab and writes one field under a preset
scope; plugin-config and settings-chrome goldens are refreshed.
2026-09-04 04:32:31 +08:00

76 lines
3.6 KiB
TypeScript

import { Context } from '@deepseek-ai/cordis'
import { describe, expect, it, vi } from 'vitest'
import { TestRemote } from '@deepseek-ai/dsh-client-test-runtime'
import { apply, inject } from '../src/client/index.ts'
import { SettingsSchemaService } from '../src/client/schema.ts'
import { SettingsScopeBinder } from '../src/client/settings-scope.ts'
import { apply as hostApply } from '../src/index.ts'
function bench() {
const describeCall = vi.fn((scope?: string) => Promise.resolve({
ok: true,
value: { writable: true, hasDocument: true, namespaces: [], ...scope === undefined ? { scopes: [] } : { scope, scopes: [scope] } },
}))
const ctx = new Context()
const remote = new TestRemote(ctx, { settings: { describe: describeCall } })
return { ctx, describeCall, remote, fiber: ctx.plugin({ inject: [...inject], apply }) }
}
describe('settings domain base plugin', () => {
it('keeps the host Loader entry inert', () => {
expect(hostApply).not.toThrow()
})
it('mounts the scope service under settingsScope and reads once eagerly', async () => {
const { ctx, describeCall, fiber } = bench()
await fiber.await()
expect(ctx.get('settingsScope')).toBeInstanceOf(SettingsScopeBinder)
expect(ctx.get('settingsSchema')).toBeInstanceOf(SettingsSchemaService)
await vi.waitFor(() => { expect(describeCall).toHaveBeenCalledTimes(1) })
})
it('refreshes the mirror on document commits and connection resets, once each', async () => {
const { ctx, describeCall, remote, fiber } = bench()
await fiber.await()
await vi.waitFor(() => { expect(describeCall).toHaveBeenCalledTimes(1) })
remote.emit('settings/document-updated', ['ui-test', 0])
await vi.waitFor(() => { expect(describeCall).toHaveBeenCalledTimes(2) })
ctx.emit('connection/reset')
await vi.waitFor(() => { expect(describeCall).toHaveBeenCalledTimes(3) })
})
it('routes a scoped commit to the scope\'s mirror and a global commit to every mirror', async () => {
const { ctx, describeCall, remote, fiber } = bench()
await fiber.await()
await vi.waitFor(() => { expect(describeCall).toHaveBeenCalledTimes(1) })
// A scoped commit before any scoped bind touches nothing: no mirror exists for it.
remote.emit('settings/document-updated', ['ui-test', 0, 'preset/research'])
await Promise.resolve()
expect(describeCall).toHaveBeenCalledTimes(1)
ctx.settingsScope.describe('preset/research')
remote.emit('settings/document-updated', ['ui-test', 1, 'preset/research'])
await vi.waitFor(() => { expect(describeCall).toHaveBeenCalledTimes(2) })
expect(describeCall.mock.calls[1]).toEqual(['preset/research'])
// A global commit reaches the scoped instance too: it inherits the global section.
remote.emit('settings/document-updated', ['ui-test', 2])
await vi.waitFor(() => { expect(describeCall).toHaveBeenCalledTimes(4) })
expect(describeCall.mock.calls.slice(2).map(call => call[0])).toEqual([undefined, 'preset/research'])
ctx.emit('connection/reset')
await vi.waitFor(() => { expect(describeCall).toHaveBeenCalledTimes(6) })
await fiber.dispose()
})
it('fiber disposal retires the service and its invalidation subscriptions', async () => {
const { ctx, describeCall, remote, fiber } = bench()
await fiber.await()
await vi.waitFor(() => { expect(describeCall).toHaveBeenCalledTimes(1) })
await fiber.dispose()
expect(ctx.get('settingsScope')).toBeUndefined()
expect(ctx.get('settingsSchema')).toBeUndefined()
remote.emit('settings/document-updated', ['ui-test', 0])
ctx.emit('connection/reset')
await Promise.resolve()
expect(describeCall).toHaveBeenCalledTimes(1)
})
})