Files
deepseek-harness/packages/client/ui-sidebar-documentpreview/tests/config.host.spec.ts
T
imccyu 09899f3a0f feat(remote-access): 插件注册跟随访问状态(whenAccess),index 按 Peer 注入访问快照
- remote-access 新增 whenAccess / whenResourceAccess,ui-session、ui-workspace 各自提供 whenAccess
- schedule、plugin-manager、settings-general、settings-account、directory-picker-native 的入口包进 global whenAccess;消息反馈按钮按会话 useAccess 渲染
- webserver/index-inject 带 Peer,renderIndex / collectIndexInjections 需要 Peer,remote-access 注入 snapshotFor(peer.principal)
- client-test-runtime 新增 StaticRemoteAccess、staticAccessPlugin 与 TestClientOptions.access
- implemented Agent Note 2026-10-21-when-access 与升级指南 webserver-index-peer

Refs #2940
2026-10-21 17:57:51 +08:00

35 lines
1.8 KiB
TypeScript

/** Host configuration supplies bounded Office reuse settings to browser pages. */
import { Context } from '@deepseek-ai/cordis'
import type { IndexInjection, WebServer } from '@deepseek-ai/dsh-host-webserver'
import { expect, it, onTestFinished } from 'vitest'
import { Config } from '../src/config.ts'
import * as host from '../src/index.ts'
/** The Peer an index render speaks for; this listener reads no field of it. */
const PAGE_PEER = { principal: { kind: 'owner' } } as Parameters<WebServer['renderIndex']>[1]
it('exposes Client cache and spreadsheet limits on the Host entry', () => {
expect(host.Config).toBe(Config)
expect(Config({})).toEqual({ office: {
maxCachedEntries: 8, maxCachedBytes: 64 * 1024 * 1024, maxPending: 8, maxReaders: 32,
}, excel: { maxBytes: 16 * 1024 * 1024, maxCells: 250_000, timeoutMs: 15_000 } })
for (const key of ['maxCachedEntries', 'maxCachedBytes']) expect(() => Config({ office: { [key]: 0 } })).toThrow()
for (const key of ['maxBytes', 'maxCells', 'timeoutMs']) expect(() => Config({ excel: { [key]: 0 } })).toThrow()
expect(() => Config({ excel: { timeoutMs: 2_147_483_648 } })).toThrow()
})
it('embeds YAML cache settings in browser pages and withdraws them on disposal', async () => {
const ctx = new Context()
onTestFinished(async () => { await ctx.fiber.dispose() })
const config = Config({ office: { maxCachedEntries: 2 } })
const fiber = ctx.plugin(host, config)
await fiber.await()
const rows: IndexInjection[] = []
ctx.emit('webserver/index-inject', rows, PAGE_PEER)
expect(rows).toEqual([{ kind: 'global', name: '__DSH_DOCUMENT_PREVIEW_CONFIG__', value: config }])
await fiber.dispose()
const after: IndexInjection[] = []
ctx.emit('webserver/index-inject', after, PAGE_PEER)
expect(after).toEqual([])
})