Files
apes-sidebar/tests/primitives-exports.spec.ts
T
Menghuan1918 6586e3e2d3 feat: adapt to DSH 0.1.7-alpha.1 and yield the read-only previews
DSH 0.1.7-alpha.1 is 1299 commits past 0.1.6-alpha.2 and rewrites four
contracts this plugin was built on. The peer floor moves to
^0.1.7-alpha.1 (semver's prerelease rule means ^0.1.6-alpha.2 can never
match a 0.1.7 prerelease); 0.1.6-alpha.2 and earlier stay on v0.19.1.
Released as 0.21.0-alpha.1 (dist-tag alpha).

Hard breaks:
- dsh-settings was rewritten: register(ns, schema) is gone, a form is
  addressed by the plugin row's Loader entry id and read from the
  module's exported Config. The preferences are merged into Config and
  marked volatile — which requires DSH's own schemastery, because only
  that build wraps a volatile field in the cosmokit reference the
  loader's volatile commit walks. With the public package a settings
  write reports success and revision 1 while the effective value never
  changes.
- ui-primitives renamed its whole icon family (IconXxx14/16 ->
  IconXxxRegular/Medium): 26 imported symbols, 17 files. The failing
  mode is render-time, not load-time. Five call sites that relied on the
  old 14px default now pass size={14} explicitly.
- Session format v4 rejects source.kind === 'plugin'; the side-chat
  boundary injection now writes plugin:dsh-better-sidebar, the same kind
  DSH's own v3->v4 migration produces, so historical threads survive.
  Tool results moved to role 'tool' with top-level content/isError; all
  four parsers accept both shapes.
- The client session snapshot dropped subagentsByParent/jobsBySession
  and the on-demand subagent-catalog observation API. The Tasks page
  reads projectionsBySession and a new jobs.list route.

Yields and convergence:
- The read-only previews go to DSH's documentpreview (Office->PDF, a
  spreadsheet worker, zoom, per-directory refresh); editor.canOpen
  refuses those 26 extensions. Markdown, HTML (with its sandbox
  switches) and the editable code buffer stay.
- The host browser kind is desktop-profile-only now, so the web e2e
  lanes expect no browser entry and assert its absence.
- Link takeover claims only urlTarget links and passes the rest to the
  host, fixing a regression from the 0.1.6 round: the fallback pointed
  at a 'browser' type the plugin no longer registers, so http links in
  its own markdown did nothing.

Also fixed, found along the way:
- The file tree refreshes live (new directory watch over the plugin's
  own socket), since the plugin owns the `files` kind.
- ctx.sessions.list has no `current` field at either tag; the three
  readers were dead. They now use ctx.sidebarRight.mounted.
- package.json.files was missing lib/client-locale.js.
- Two genuinely dead call sites: sessions.openSubagent/open/
  refreshSubagents do not exist on the current baseline, so the
  topology click, the jump-back and the retry were all no-ops.
- The test harness window shim lacked addEventListener, which the 0.1.7
  primitives call at module-evaluation time; and the e2e token exchange
  needs Playwright's request stack, not Node's fetch.
2026-09-22 17:09:08 +08:00

83 lines
3.7 KiB
TypeScript

/**
* Icon-export guard: DSH 0.1.7 renamed the whole `ui-primitives` icon family
* from size-suffixed names (`IconCloseFill14`) to weight-suffixed ones
* (`IconCloseFillRegular` / `…Medium`), deleting the old names outright.
*
* Missing exports do not fail at load time here — the client bundle is CJS
* with `ui-primitives` external, so a missing named export reads as
* `undefined` and React throws "Element type is invalid" at RENDER time. That
* is a failure mode no other spec in this repository observes, so this one
* pins the contract directly: every icon symbol the plugin imports from the
* package must actually be exported by the installed version.
*
* `pnpm typecheck` catches the same thing from the type side; this stays as
* the runtime-side witness, and as a guard for the symbols that reach the
* bundle through a re-export rather than a direct import.
*/
import { describe, expect, it } from 'vitest'
import { readFileSync } from 'node:fs'
import { execFileSync } from 'node:child_process'
import * as primitives from '@deepseek-ai/dsh-client-ui-primitives'
/** The specifier whose named exports the plugin depends on. */
const PACKAGE = '@deepseek-ai/dsh-client-ui-primitives'
/**
* Every value symbol the repository imports from the primitives package.
* Type-only imports are ignored: they are erased before the bundle is built
* and therefore cannot become a missing runtime export.
* @returns the imported symbol names, deduplicated.
*/
function importedSymbols(): string[] {
const files = execFileSync('rg', ['-l', PACKAGE, 'src', 'tests'], { encoding: 'utf8' })
.trim().split('\n').filter(Boolean)
const names = new Set<string>()
for (const file of files) {
const source = readFileSync(file, 'utf8')
for (const match of source.matchAll(
new RegExp(`import\\s+(type\\s+)?\\{([^}]*)\\}\\s+from\\s+['"]${PACKAGE}['"]`, 'g'),
)) {
// `import type { … }` imports nothing at runtime.
if (match[1] !== undefined) continue
for (const raw of match[2]!.split(',')) {
const name = raw.trim().replace(/^type\s+/, '')
if (name === '' || name.startsWith('type ')) continue
// A per-specifier `type` marker has no runtime counterpart either.
if (/^type\s/.test(raw.trim())) continue
names.add(name)
}
}
}
return [...names].sort()
}
describe('ui-primitives exports', () => {
const imported = importedSymbols()
const exported = new Set(Object.keys(primitives as Record<string, unknown>))
it('finds the plugin\'s import surface at all', () => {
// A guard on the guard: a regex that silently stopped matching would make
// the assertion below vacuously true.
expect(imported.length).toBeGreaterThan(20)
expect(imported).toContain('FileTypeIcon')
expect(imported).toContain('MarkdownText')
})
it('still exports every icon symbol the plugin imports', () => {
const missing = imported.filter(name => name.startsWith('Icon') && !exported.has(name))
expect(missing, `these symbols are imported but not exported by ${PACKAGE}: ${missing.join(', ')}`).toEqual([])
})
it('still exports every other value symbol the plugin imports', () => {
const missing = imported.filter(name => !name.startsWith('Icon') && !exported.has(name))
expect(missing, `these symbols are imported but not exported by ${PACKAGE}: ${missing.join(', ')}`).toEqual([])
})
it('ships no icon whose name still carries the retired size suffix', () => {
// The rename was wholesale: a `…14` / `…16` name reappearing would mean
// upstream re-introduced the old scheme and the migration above is stale.
const sized = [...exported].filter(name => /^Icon[A-Za-z]+(10|12|14|16|20|24)$/.test(name))
expect(sized).toEqual([])
})
})