Files
apes-sidebar/tests/css-composition.spec.ts
T
Menghuan1918 5ee81fb073 feat(clues): collect resources from files, Feishu and GitHub, adapted to DSH 0.2.2-rc.2
This lands the clue collection line on top of origin/dev (v0.32.1, DSH
0.2.2-rc.2). The 14 commits that carried it are squashed into this one
because every one of them overlapped upstream's own changes (version,
19 dictionaries, CHANGELOG), and each intermediate commit would have
failed to compile against rc.2's menu API. The pre-integration head is
kept at backup/clues-uiux-refresh-pre-rebase.

What the feature is:
- a Clues tab that reads local files, Feishu tasks/docs and GitHub
  issues/pulls through one source registry, with a scope row, shared
  search, filters, paging and stable [[dsh-clue:...]] references;
- one window host for detail, pack management, source configuration,
  new pack and sharing (preview and edit are separate paths: a read is
  never saved over);
- .cluepack export/import with per-row resolvability previews;
- a source runtime that owns dependency installs and connection
  authorization (gh, lark-cli device code) and only probes on an
  explicit read;
- the public betterSidebarClues service and the windows capability
  (features gains clues / windowHost).

Merged with upstream rather than over it:
- the settings section keeps upstream's start-page takeover group and
  this branch's clue sources group; navigation is now six groups;
- the dictionaries keep both sides' new keys (1211 each, verified equal
  across all 19), the external-plugin guide and CHANGELOG keep both
  histories, and service features list both capability sets.

Adapted to 0.2.2-rc.2:
- menu call sites use anchorPoint instead of getAnchorRect;
- the shared SelectMenu mounts the host menu only while open, because
  rc.2's Menu reads the DOM during render and broke server-rendered
  settings surfaces;
- the submenu flip workaround stays deleted (the host positions
  submenus now), pinned by an updated layout-css assertion.

Version 0.33.0 (three synced spots) with a new 未发布 / Unreleased
changelog section; package.json regains the ./clues export, lib/clues.js
and the uqr dependency that upstream never had.

Gates: typecheck, lint, 5410 unit tests, build, check:consumer-types and
the full mount lane (35 passed) against dsh 0.2.2-rc.2 in Chromium.
2026-11-24 16:43:26 +08:00

47 lines
3.0 KiB
TypeScript

/** Build through the actual client CSS plugin: composition must survive emission, resolution and style injection. */
import { mkdtemp, writeFile, readFile, readdir, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { runInNewContext } from 'node:vm'
import { expect, it } from 'vitest'
import { build } from 'tsdown'
import { createRequire } from 'node:module'
const { JSDOM } = createRequire(import.meta.url)('jsdom') as { JSDOM: new (html: string) => { window: Window } }
import configs from '../tsdown.config.ts'
it('emits local, global and transitive cross-file composition with dependency styles', async () => {
const directory = await mkdtemp(join(tmpdir(), 'sidebar-css-composition-'))
const dom = new JSDOM('<!doctype html><html><head></head><body></body></html>')
const document = dom.window.document
try {
await writeFile(join(directory, 'base.module.css'), '.base { border: 1px solid; padding: 4px; } .primary { composes: base; background: rgb(12, 34, 56); }')
await writeFile(join(directory, 'middle.module.css'), '.middle { composes: primary from "./base.module.css"; min-height: 32px; }')
await writeFile(join(directory, 'action.module.css'), '.action { composes: middle from "./middle.module.css"; composes: shared from global; border-radius: 6px; }')
await writeFile(join(directory, 'entry.ts'), 'import classes from "./action.module.css"; export { classes };')
const client = configs.find(config => config.entry && typeof config.entry === 'object' && 'client' in config.entry)!
await build({ config: false, entry: join(directory, 'entry.ts'), outDir: join(directory, 'dist'), format: 'iife', platform: 'browser', target: 'es2023', dts: false, sourcemap: false, clean: false, plugins: client.plugins, outputOptions: { name: 'fixture' } })
const output = (await readdir(join(directory, 'dist'))).find(name => name.endsWith('.js'))!
const context: { document: Document; fixture?: { classes: Record<string, string> } } = { document }
runInNewContext(await readFile(join(directory, 'dist', output), 'utf8'), context)
const classes = context.fixture!.classes.action!
expect(classes.split(' ')).toHaveLength(5)
expect(classes.split(' ')).toContain('shared')
const button = document.createElement('button')
button.className = classes
document.body.append(button)
const style = dom.window.getComputedStyle(button)
expect(style.borderTopWidth).toBe('1px')
expect(style.paddingTop).toBe('4px')
expect(style.minHeight).toBe('32px')
expect(style.borderRadius).toBe('6px')
expect(style.backgroundColor).toBe('rgb(12, 34, 56)')
const injected = [...document.querySelectorAll<HTMLStyleElement>('style[data-plugin]')]
expect(injected.map(node => node.dataset.pluginCss?.split('/').at(-1))).toEqual(['base.module.css', 'middle.module.css', 'action.module.css'])
button.remove()
injected.forEach(node => { node.remove() })
} finally {
dom.window.close()
await rm(directory, { recursive: true, force: true })
}
})