存量清理(首跑 141 errors / 21 warnings → 0 / 0): - 删除孤儿 disable:SideChatView / Sidebar / selection-popup 三处 exhaustive-deps 豁免与 chunk-artifact 的 no-new-func 豁免(多行理由注释把 disable-next-line 顶离了实报行;selection-popup 改为提取 popupOpen 标志真修复) - 死代码:未用导入(Sidebar×7、TextEditor、SideCardSection、config、fs-operations 及 6 个 spec)、sidechat-core 死累加器 total、chunk-loader.spec 死助手 registry、sidechat-seed-validation 死助手 toolResultMessage - 真实小修:agent-opens 三处 throw 补 cause;lazy-chunk any → ComponentType<P>(P extends object);service.ts claimed 初值改定值赋值;chunk-loader task / spec 内 etag / pendingLoad / snapshot 改 const;terminal-links 去掉字符类内多余转义;SubagentView catalogs 空兜底 useMemo 稳定标识;editor-host.spec 组件提出大写 FakeViewer(rules-of-hooks);pty-helpers.spec 内联 require 提升为静态导入;panel-host-css 注释里的零宽空格改为可见写法 - 依赖数组豁免(均带理由):granular scope 字段(EditorHost / PdfView / ChangesTab / GitLens×2)、job.status 粒度(SubagentView×2)、清理期读 ref、mount-only 注册等;ctx(挂载期恒定)直接入 deps(Sidebar×3)、TextEditor previewScroll 补 scope(幂等) - 刻意控制字符正则(conversation-draft / markdown-images)与宿主槽位 any 签名(context-types)以带理由豁免保留 接入: - Makefile:lint 目标(typecheck 旁),check 聚合补 lint 保持「对齐 CI」语义 - ci.yml ci / ci-windows 两 job 与 release.yml 在 Typecheck 后加 Lint 步骤(release 注释同步顺序)
57 lines
2.7 KiB
TypeScript
57 lines
2.7 KiB
TypeScript
/**
|
|
* Built chunk artifact contract: each lib/client-<name>.js must, when
|
|
* executed as a classic script, assign its factory to the plugin-owned
|
|
* global registry (globalThis.__dshChunks__[<name>]), and the factory must
|
|
* be callable with a require that resolves the platform externals — the
|
|
* exact shape the loader (src/client/chunk-loader.ts) depends on. Reads the
|
|
* built lib/ output, so run `pnpm build` first (like manifest-consistency).
|
|
* A missing lib/ (fresh clone before the first build) skips the whole suite
|
|
* instead of crashing on ENOENT.
|
|
*/
|
|
import { existsSync, readFileSync } from 'node:fs'
|
|
import { describe, expect, it } from 'vitest'
|
|
// Browser globals first: chunk bodies probe `self`/`document` at evaluation
|
|
// (xterm's UMD wrapper, CodeMirror's UA probe).
|
|
import './browser-globals.ts'
|
|
import { CHUNK_EXTERNALS } from '../src/client/chunk-loader.ts'
|
|
|
|
const g = globalThis as Record<string, unknown>
|
|
|
|
const CHUNKS = ['terminal', 'editor', 'mermaid']
|
|
|
|
/** All chunk artifacts present (tsdown emits the whole lib/ in one run). */
|
|
const chunksBuilt = CHUNKS.every(name => existsSync(`lib/client-${name}.js`))
|
|
|
|
if (!chunksBuilt) {
|
|
console.warn('[chunk-artifact] lib/ chunk artifacts missing — run `pnpm build` first; skipping this suite')
|
|
}
|
|
|
|
describe.skipIf(!chunksBuilt)('built chunk artifacts', () => {
|
|
it('each chunk assigns its global registry slot when executed as a script', () => {
|
|
g.window = g // classic-script globals
|
|
// mermaid's core hooks window.addEventListener('load') at module scope
|
|
// (its startOnLoad wiring); the Node global lacks the API, so stub it
|
|
// exactly like browser-globals.ts does for its window stub.
|
|
if (typeof g.addEventListener !== 'function') g.addEventListener = () => {}
|
|
if (typeof g.removeEventListener !== 'function') g.removeEventListener = () => {}
|
|
for (const name of CHUNKS) {
|
|
const code = readFileSync(`lib/client-${name}.js`, 'utf8')
|
|
expect(() => new Function(code)(), name).not.toThrow()
|
|
const registry = g.__dshChunks__ as Record<string, unknown>
|
|
expect(typeof registry[name], name).toBe('function')
|
|
}
|
|
})
|
|
|
|
it('each chunk factory materializes through a require over the platform externals', () => {
|
|
const registry = g.__dshChunks__ as Record<string, unknown>
|
|
const table = new Map<string, unknown>(CHUNK_EXTERNALS.map(spec => [spec, { spec }]))
|
|
for (const name of CHUNKS) {
|
|
const factory = registry[name] as (require: (spec: string) => unknown) => Record<string, unknown>
|
|
expect(() => factory((spec) => {
|
|
if (!table.has(spec)) throw new Error(`require("${spec}") missed the module table`)
|
|
return table.get(spec)
|
|
}), name).not.toThrow()
|
|
}
|
|
})
|
|
})
|