deepseek-harness/packages/client/ui-settings/tests/plugin.client.spec.ts

54 lines
2.3 KiB
TypeScript
Raw Normal View History

2026-08-11 15:31:13 +08:00
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'
2026-08-11 15:31:13 +08:00
function bench() {
const describeCall = vi.fn().mockResolvedValue({
rpcId: 'plugin-bench' as never,
result: { ok: true, value: { writable: true, hasDocument: true, namespaces: [] } },
})
2026-08-11 15:31:13 +08:00
const ctx = new Context()
ctx.provide('connection', {
api: { settings: { describe: describeCall } },
isLoopback: true,
} as never)
const remote = new TestRemote(ctx)
return { ctx, describeCall, remote, fiber: ctx.plugin({ inject: [...inject], apply }) }
2026-08-11 15:31:13 +08:00
}
describe('settings domain base plugin', () => {
it('mounts the scope service under settingsScope and reads once eagerly', async () => {
const { ctx, describeCall, fiber } = bench()
2026-08-11 15:31:13 +08:00
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) })
2026-08-11 15:31:13 +08:00
})
it('fiber disposal retires the service and its invalidation subscriptions', async () => {
const { ctx, describeCall, remote, fiber } = bench()
2026-08-11 15:31:13 +08:00
await fiber.await()
await vi.waitFor(() => { expect(describeCall).toHaveBeenCalledTimes(1) })
2026-08-11 15:31:13 +08:00
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)
2026-08-11 15:31:13 +08:00
})
})