包装 ctx.workspaces.openPath(聊天区文件打开的唯一漏斗),接管时 经 openSidebarFile 开进 sidebar 编辑器而非系统默认应用;由 interceptOpenPath pref(默认开)与 editor tab 启用态双重门控, 拒接时原样放行,dispose 还原原始方法引用(HMR 安全)。 - prefs-shared/config/prefs: 新增 interceptOpenPath 字段(默认 true) - openpath-intercept.ts: 零依赖包装器,纯插件层面实现,不改 DSH - intercept.tsx: registerOpenPathInterception 接线(当前会话 scope) - SideCardSection: 常规区新增开关卡片(zh/en 文案) - 测试: 包装器单测 6 个 + 接线集成测试 + pref 解析/设置页断言更新
63 lines
3.0 KiB
TypeScript
63 lines
3.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import Loader from '@cordisjs/plugin-loader'
|
|
import * as sidebar from '../src/index.ts'
|
|
|
|
/**
|
|
* Run the real namespace export through `Loader.unwrapExports`; a stray
|
|
* default would discard `name`, `inject`, `Config`, and `apply`. Same guard
|
|
* the official plugin repos ship (dsh-external/turtle-ui,
|
|
* packages/ui/jsonrpc).
|
|
*/
|
|
describe('dsh-better-sidebar plugin export shape', () => {
|
|
it('has the namespace-plugin export shape (no stray default) so the Loader keeps name/inject/Config/apply', () => {
|
|
expect('default' in sidebar).toBe(false)
|
|
expect(typeof sidebar.apply).toBe('function')
|
|
|
|
const loader = Object.create(Loader.prototype) as Loader
|
|
const unwrapped = loader.unwrapExports(sidebar) as Record<string, unknown>
|
|
expect(unwrapped).toBe(sidebar)
|
|
expect(unwrapped.name).toBe('dsh-better-sidebar')
|
|
expect(unwrapped.inject).toEqual(['httpServer', 'sessions', 'loader', 'tools'])
|
|
expect(unwrapped.Config).toBeDefined()
|
|
expect(typeof unwrapped.apply).toBe('function')
|
|
})
|
|
|
|
it('exports the schemastery Config with the documented tunable fields', () => {
|
|
const schema = sidebar.Config
|
|
expect(schema).toBeDefined()
|
|
// The resolved defaults mirror the pre-config constants.
|
|
const resolved = (schema as unknown as {
|
|
(input: Record<string, unknown> | undefined): Record<string, unknown>
|
|
})(undefined)
|
|
expect(resolved.readLimit).toBe(512 * 1024)
|
|
expect(resolved.mediaLimit).toBe(20 * 1024 * 1024)
|
|
expect(resolved.listLimit).toBe(1000)
|
|
expect(resolved.terminalsPerSession).toBe(3)
|
|
expect(resolved.reconnectGraceMs).toBe(30_000)
|
|
})
|
|
|
|
it('registers the side card preferences schema with the documented defaults', async () => {
|
|
const { PrefsSchema, SIDEBAR_PREFS_NS } = await import('../src/config.ts')
|
|
expect(SIDEBAR_PREFS_NS).toBe('dsh-better-sidebar')
|
|
const resolved = (PrefsSchema as unknown as {
|
|
(input: Record<string, unknown> | undefined): Record<string, unknown>
|
|
})(undefined)
|
|
expect(resolved.openByDefault).toBe(true)
|
|
expect(resolved.defaultWidthPercent).toBe(30)
|
|
expect(resolved.autoOpenSubagent).toBe(true)
|
|
// The terminal tools default OFF (the feature is dormant until the user
|
|
// enables it in the side card settings).
|
|
expect(resolved.agentTerminalTools).toBe(false)
|
|
// The enable-switch maps resolve to {} (everything on) for old documents.
|
|
expect(resolved.tabsEnabled).toEqual({})
|
|
expect(resolved.viewersEnabled).toEqual({})
|
|
// A stored overridden value resolves through (the range contract is
|
|
// enforced by the settings service on write); the new pref keeps its
|
|
// default when the stored document predates it.
|
|
const overridden = (PrefsSchema as unknown as {
|
|
(input: Record<string, unknown> | undefined): Record<string, unknown>
|
|
})({ openByDefault: false, defaultWidthPercent: 45 })
|
|
expect(overridden).toEqual({ openByDefault: false, defaultWidthPercent: 45, autoOpenSubagent: true, agentTerminalTools: false, interceptOpenPath: true, tabsEnabled: {}, viewersEnabled: {} })
|
|
})
|
|
})
|