根因:trustedHostsOf 按 entry.options.name === 'connection' 查找 connection 行,但该行 name 是模块标识符(@deepseek-ai/dsh-client-connection,id 才是 connection),查找永远落空 → trustedHosts 为空 → 栅栏只放行回环 Host → 通过 域名或局域网 IP 访问时 /sidebar/bundle chunk 加载失败、资源管理器/代码管理器 全部 403 forbidden(/api 不受影响,它读的是 apply 时已求值的配置)。 修复(按 review 建议):host half 直接注入 webRuntime 服务,栅栏每请求实时 读取 ctx.webRuntime.trustedHosts —— 与 /api 网关同一信任列表(启动时采样的 LAN IP 字面量 + --trusted-host 权威),不再依赖 Loader entry / fiber / !!js 节点求值;自定义信任域名由 dsh web --trusted-host 提供。 新增 tests/trusted-hosts.spec.ts 回归:域名/局域网放行、空列表仅回环、 跨站标记拒绝、每请求实时读取;plugin-shape 断言同步更新。
69 lines
3.6 KiB
TypeScript
69 lines
3.6 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(['webServer', 'sessions', 'webRuntime', '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)
|
|
// A new background job auto-opens the Jobs page too.
|
|
expect(resolved.autoOpenJobs).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 terminal font customizations default to the theme (empty family)
|
|
// and 13px.
|
|
expect(resolved.terminalFontFamily).toBe('')
|
|
expect(resolved.terminalFontSize).toBe(13)
|
|
// 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, autoOpenJobs: true, agentTerminalTools: false, bottomPanelAutoTerminal: true, terminalFontFamily: '', terminalFontSize: 13, interceptOpenPath: true, htmlViewerNoSandbox: false, htmlViewerDefaultUnsafe: false, browserNoSandbox: false, browserInterceptLinks: true, tabsEnabled: {}, viewersEnabled: {}, pluginSettings: {} })
|
|
})
|
|
})
|