插件自 v0.19.0 起不再自绘顶部 chrome:`223b254` 把那三条读 strip 的规则
(`top: calc(var(--dsh-title-bar-strip, 40px) + 3px)` / 右面板
`padding-top: var(--dsh-title-bar-strip, 40px)` / 折叠态 `+14px`)连同自绘
chrome 一起删掉了。此后「位置兼容模式」四方案仍在写
`--dsh-title-bar-strip` + `body[data-dsh-title-bar-compat]`,但**没有任何
消费者**:`src/**/*.css` 零命中,宿主也不读这条契约(DSH 核心整树 grep
`windowControlsOverlay|dsh-desktop-titlebar-inset|titlebarInset|
title-bar-strip|title-bar-compat` 与 `desktopWindow` 全部零命中)。结果是
用户改设置只写变量、什么都不动,而设置项描述(「标题栏条带高度:侧边栏
按钮与内容下移的像素数」)与现实不符。整套删除,不留兼容层。
删除范围(先做了完整消费者普查,见新增的设计文档):
- 计算与写入:`src/client/titlebar-strip.ts`、`src/client/wco.ts`、
`src/client/shell-presets.ts` 三个文件整体删除;`Sidebar.tsx` 里的 strip
计算 + 写 `--dsh-title-bar-strip` / `body[data-dsh-title-bar-compat]` 的
effect 与 `titleBarCompat` 局部量一并清理。
- 壳信号:`desktop-env.ts` 的 `parseDesktopEnv` / `DesktopEnv` /
`probeDesktopWindow` 与 `context-types.ts` 的 `SidebarDesktopWindowService`
(含 Insets / DragRegion)删除。#864 新增的 `desktopWindow` 优先读取随之
消失。**`desktop-env.ts` 文件保留**:同文件的 `hostTransportBase()` 另有
3 个消费者(`host-route-url.ts` / `TextEditor.tsx` / `changes/DiffPane.tsx`),
是反向代理前缀与 `dsh-app://` 自定义 scheme 的解析基准,与本机制无关。
- 配置:`titleBarScheme` / `titleBarPresetId` / `titleBarCompat` /
`titleBarStripPx` 及 `TITLE_BAR_STRIP_{MIN,MAX,DEFAULT}` / `TITLE_BAR_SCHEMES`
/ `TitleBarScheme` / `clampTitleBarStrip`(`prefs-shared.ts` 的字段与默认值、
`config.ts` 的 schema 字段、`client/prefs.ts` 的读迁移逻辑)。
- 设置界面:常规行的方案下拉 + 「自定义方案」齿轮弹窗 + `titleBarSchemeValue`
/ `onSchemeSelect` / `detectedEnv` / `stripSettingsOpen` 全部删除;
**自定义 CSS 逃生口保留**,搬到独立的「自定义 CSS」分组,并去掉 scheme
门控(非空即生效)。`SideCardSection.module.css` 的死样式 `.rowGear` 同步删。
- 词典:21 份(`locales.ts` 的 zh + en 与 19 个 `locales-*.ts`)同步删除 12 个
只服务这些设置的 key(`settingsTitleBar*` / `settingsScheme*` /
`presetDshDesktopDesc`);`settingsCustomCssPlaceholder` 的示例改为
`[data-dsh-bottom-panel]` + `--dsw-font-mono`,不再引用已删变量。
- 文档:指南 §12.1 重写(删四方案 / strip 取值链 / 壳信号 / 迁移,保留用户
空间 CSS 与两条拖拽区退出)、§7 的 `toggles` 键清单、AGENTS §5 皮肤契约与
「契约反向引用」;新增 `docs/plans/2026-10-05-remove-titlebar-compat-strip.md`
记录普查结论与去留理由。`docs/plans/` 的历史文档未改。
迁移安全(旧偏好数据被安全忽略):四个已删键在 OPEN 的宿主 schema 里是未知键,
解析不报错、不写回(`plugin-shape.spec.ts`);客户端 `parsePrefs` 只按声明字段
构造结果,旧键不进入 UI(`prefs.spec.ts`);一次性 `settings.yaml` 回迁按
`Config.dict` 的声明字段过滤,已删键被丢弃而非转发(`smoke.spec.ts`)。
三条新断言都做过变异证伪:让 `parsePrefs` 透传原记录 / 让 schema 重新声明
`titleBarCompat` / 去掉回迁的声明字段过滤,对应用例分别红在
「不要带上已删键」「解析结果不得含该字段」「回迁不得保留该键」。
测试:删除 `tests/titlebar-strip.spec.ts` / `wco.spec.ts` /
`shell-presets.spec.ts` / `desktop-window-strip.spec.tsx` /
`desktop-env.spec.ts`(五个文件断言的行为已整体移除,不留断言已删行为的测试);
`prefs.spec.ts` / `plugin-shape.spec.ts` / `smoke.spec.ts` /
`side-card-section{,-rows}.spec.tsx` 的夹具与断言改写;`mount.e2e.ts` 删掉 WCO
与壳预设两个场景,URL 戳记场景保留挂载与拖拽区断言、只删 strip 断言,
自定义 CSS 场景改为只写 `customCss`。
门禁:`pnpm typecheck`(0 错误)/ `pnpm lint`(0 问题)/
`pnpm exec vitest run --maxWorkers=3` —— 179 文件 / 2075 passed + 13 skipped
(删除前基线 184 文件 / 2117 passed + 13 skipped;差额 = 5 个被删 spec 的
41 条 + `prefs.spec.ts` 净减 1 条)。词典 parity(`locales.spec.ts`)与皮肤
契约(`theme.spec.ts`)均绿。
118 lines
6.0 KiB
TypeScript
118 lines
6.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(['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)
|
|
const configured = (schema as unknown as {
|
|
(input: Record<string, unknown> | undefined): Record<string, unknown>
|
|
})({ readLimit: 1024 })
|
|
expect(configured.readLimit).toBe(1024)
|
|
})
|
|
|
|
it('registers the side card preferences schema with the documented defaults', async () => {
|
|
const { PrefsSchema, SIDEBAR_PREFS_NS, SIDEBAR_PREFS_DEFAULTS } = 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).toBeUndefined()
|
|
expect(resolved.defaultWidthPercent).toBeUndefined()
|
|
expect(resolved.changesDiffFloat).toBeUndefined()
|
|
expect(resolved.autoOpenSubagent).toBe(true)
|
|
// A new background job auto-opens the Jobs page too.
|
|
expect(resolved.autoOpenJobs).toBe(true)
|
|
// The sidebar-open tool defaults OFF (dormant until the user enables it
|
|
// in the side card settings).
|
|
expect(resolved.agentOpenTools).toBe(false)
|
|
// customCss (the user-space escape hatch) is declared WITHOUT a schema
|
|
// default — the client's parsePrefs supplies '' — so a document that
|
|
// never stored it resolves without the field.
|
|
expect(resolved.customCss).toBeUndefined()
|
|
// The title-bar compatibility keys are GONE (the whole strip mechanism
|
|
// was removed): a resolved document no longer declares them, so the
|
|
// settings form stops offering them.
|
|
expect(resolved.titleBarScheme).toBeUndefined()
|
|
expect(resolved.titleBarPresetId).toBeUndefined()
|
|
expect(resolved.titleBarCompat).toBeUndefined()
|
|
expect(resolved.titleBarStripPx).toBeUndefined()
|
|
// The enable-switch maps resolve to {} (everything on) for old documents.
|
|
expect(resolved.tabsEnabled).toEqual({})
|
|
expect(resolved.viewersEnabled).toEqual({})
|
|
// The separate file-window mode is the default (each file opens its own
|
|
// tab; the merged editor-explorer is opt-in).
|
|
expect(resolved.editorExplorer).toBe(false)
|
|
// The workspace fence is GONE: `workspaceFence` is no longer a declared
|
|
// schema field, so a resolved document does not carry it. A legacy stored
|
|
// value passes through the OPEN object schema untouched (and is inert).
|
|
expect(resolved.workspaceFence).toBeUndefined()
|
|
const legacy = (PrefsSchema as unknown as {
|
|
(input: Record<string, unknown> | undefined): Record<string, unknown>
|
|
})({ workspaceFence: true })
|
|
expect(legacy.workspaceFence).toBe(true)
|
|
// Same contract for the retired title-bar keys: a settings document
|
|
// written before the removal still carries them, and resolving it must
|
|
// neither throw nor drop the rest of the document — the values pass
|
|
// through untouched and are inert (the client's parsePrefs drops them;
|
|
// tests/prefs.spec.ts). This is the "old preference data is ignored
|
|
// safely" nail for the removal.
|
|
const retired = {
|
|
titleBarScheme: 'preset',
|
|
titleBarPresetId: 'dsh-desktop',
|
|
titleBarCompat: true,
|
|
titleBarStripPx: 56,
|
|
}
|
|
const withRetired = (PrefsSchema as unknown as {
|
|
(input: Record<string, unknown> | undefined): Record<string, unknown>
|
|
})({ ...retired, agentOpenTools: true })
|
|
expect(withRetired).toMatchObject({ ...retired, agentOpenTools: true })
|
|
expect(withRetired.autoOpenSubagent).toBe(true)
|
|
expect(withRetired.explorerExclude).toEqual(['.DS_Store', 'Thumbs.db'])
|
|
// 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, changesDiffFloat: true })
|
|
// Schemastery's object schema is OPEN: a document written by an older
|
|
// plugin version still carrying the retired keys resolves them through
|
|
// verbatim. They are inert — the typed value the client consumes
|
|
// (parsePrefs) drops them (tests/prefs.spec.ts) — and the defaults no
|
|
// longer declare them.
|
|
// customCss is declared WITHOUT a schema default (the client's parsePrefs
|
|
// supplies it), so it is absent from a resolved document that never
|
|
// stored it.
|
|
const { customCss, ...schemaDefaults } = SIDEBAR_PREFS_DEFAULTS
|
|
void customCss
|
|
expect(overridden).toEqual({ ...schemaDefaults, openByDefault: false, defaultWidthPercent: 45, changesDiffFloat: true })
|
|
})
|
|
})
|