Files
apes-sidebar/tests/ui-shadows.spec.ts
T
Menghuan1918 5deb5285da refactor(tasks-ui): align the page with the latest shadcn/ui defaults
The previous round kept a hand-trimmed, shadow-less, 11-13px variant of the
component set. This replaces it with the registry's own defaults and the
registry's own composition primitives, keeping only the adaptations this host
actually requires.

Registry refresh (npx shadcn@latest add --overwrite): the whole vendored set is
back to upstream sources, plus label, field, input-group, item and button-group.
Re-applied adaptations (documented in the design doc):
- cn from ./utils and explicit ./x.tsx specifiers (the registry writes virtual
  aliases this repo has no resolver for);
- host IconXxx instead of lucide (skin contract);
- no dark: variants (the DSH tokens already flip) and no palette literals;
- React.forwardRef on Button (the host is React 18, so radix Slot needs it);
- tw-animate-css animation utilities stripped: installing that dependency would
  inject generic keyframes into a page we do not own.
Restored to stock: the full Button variant/size set, shadow-xs on outline,
transition-all, badge ghost/link.

Recomposition on the newest primitives (per-file, verified here):
- board: full Card composition, Item rows, ToggleGroup filter, dropdown items
  grouped, Empty for the empty state;
- task window: Card composition, FieldGroup/Field with data-invalid validation,
  ToggleGroup owner (default variant: the outline variant's hover and pressed
  states measured identically, hiding the selection), destructive-armed delete,
  FieldError for conflicts;
- popovers: both portal cards use the same Card composition, rows are Item;
- drawer/header: Item rows with ItemActions, Separator bands, Spinner, Empty;
- graph/tree: stock node recipe, outline buttons, cn() for conditional classes.

Two no-preflight traps found by rendering, not by types:
- stock Empty ships border-dashed without a width, so the UA's 3px medium dashed
  frame wrapped the whole page: border-0 on that Empty;
- <Spinner size={12}/> stayed type-clean after the refresh (size is a valid span
  attribute) while the glyph silently rendered at size-4: className="size-3".

Verified: typecheck/lint clean; 136 files / 1515 tests; build with the core and
chunk bundle guards (core 836.3 KiB, chunk 734.7 KiB); mount e2e 7/7; and the
real-host-stylesheet mirror page re-shot for graph, tree, board, task window and
the 77-node stress fixture at 360 and 720.
2026-09-27 22:18:19 +08:00

108 lines
4.6 KiB
TypeScript

/**
* Elevation guard of the task page, shadcn/ui stock edition.
*
* Static panels (cards, rows, the drawer) may carry the stock LIGHT shadows
* only — `shadow-xs` (button-like compact surfaces such as graph node cards)
* and `shadow-sm` (cards / panels); `shadow-none` (a reset) is fine. Anything heavier (`shadow-md|lg|xl|2xl`,
* bare `shadow`, `shadow-inner`, arbitrary `shadow-[…]`) on a static panel is
* the regression: elevation beyond the stock pair reads as a floating layer
* that nothing anchors.
*
* Real floating layers keep their deeper shadows: the `AnchoredPopover` shell
* (the task window / node popover chassis) and the vendored `popover` /
* `dropdown-menu` / `tooltip` primitives, which render into a portal.
*
* The guard is deliberately source-level: a `shadow-*` utility dropped into a
* static panel is exactly the regression, and the class name is the only place
* it is visible (Tailwind generates the CSS at build time).
*/
// @vitest-environment node
import { readFileSync, readdirSync } from 'node:fs'
import { resolve } from 'node:path'
import { describe, expect, it } from 'vitest'
const ROOT = process.cwd()
const VENDORED_UI_DIR = 'src/client/ui'
/** Panels that are laid out IN the page: light stock shadows only. */
const STATIC_PANEL_FILES = [
'src/client/SubagentView.tsx',
'src/client/SubagentView.module.css',
'src/client/TasksGraph.tsx',
'src/client/TasksTree.tsx',
'src/client/TaskWindow.tsx',
'src/client/TeamBoard.tsx',
'src/client/JobsDrawer.tsx',
'src/client/TasksPopovers.tsx',
'src/client/tasks-shared.tsx',
'src/client/tasks-canvas.module.css',
]
/** The only files allowed to paint a deeper elevation shadow (floating layers). */
const FLOATING_FILES = [
'src/client/AnchoredPopover.tsx',
`${VENDORED_UI_DIR}/popover.tsx`,
`${VENDORED_UI_DIR}/dropdown-menu.tsx`,
`${VENDORED_UI_DIR}/tooltip.tsx`,
]
/**
* Every shadow utility a file uses (Tailwind spellings, but NOT `box-shadow`,
* which is how the components spell the focus-ring transition
* (`transition-[color,box-shadow]`) and the ring plumbing (`--tw-shadow`)).
*/
const SHADOW_UTILITY = /(?<![-\w])shadow(?:-(?:2xs|xs|sm|md|lg|xl|2xl|inner|none)|\[|\()?/g
/** The stock pair a static panel may paint. */
// `shadow-none` is not an elevation at all (it clears the ring plumbing), so it
// is allowed anywhere a light shadow is; upstream's input-group uses it to keep
// nested controls flat inside the group's own surface.
const STATIC_ALLOWED = new Set(['shadow-xs', 'shadow-sm', 'shadow-none'])
/** Every non-allowed shadow utility in the source, for a readable failure. */
function offendingShadows(source: string): string[] {
return (source.match(SHADOW_UTILITY) ?? [])
.filter(match => !STATIC_ALLOWED.has(match))
}
/** A literal `box-shadow` declaration is the same defect in stylesheet form. */
const BOX_SHADOW_DECLARATION = /(?:^|;)\s*box-shadow\s*:/
/** Comments are prose about shadows ("no shadow — a node never floats"). */
function stripComments(source: string): string {
return source.replace(/\/\*[\s\S]*?\*\//g, '').replace(/^[ \t]*\/\/.*$/gm, '')
}
const read = (file: string) => stripComments(readFileSync(resolve(ROOT, file), 'utf8'))
describe('task page: static panels keep stock light shadows only', () => {
it.each(STATIC_PANEL_FILES)('%s carries no shadow beyond shadow-xs/shadow-sm', (file) => {
expect(offendingShadows(read(file)), file).toEqual([])
})
it('no migrated stylesheet declares box-shadow', () => {
for (const file of [...STATIC_PANEL_FILES, ...FLOATING_FILES].filter(name => name.endsWith('.css'))) {
expect(read(file), file).not.toMatch(BOX_SHADOW_DECLARATION)
}
})
it('keeps the deep shadows in the floating allowlist only', () => {
const uiFiles = readdirSync(resolve(ROOT, VENDORED_UI_DIR))
.filter(name => /\.(?:tsx|ts|css)$/.test(name))
.map(name => `${VENDORED_UI_DIR}/${name}`)
const surface = [...STATIC_PANEL_FILES, ...FLOATING_FILES, ...uiFiles]
for (const file of new Set(surface)) {
if (FLOATING_FILES.includes(file)) continue
expect(offendingShadows(read(file)), file).toEqual([])
}
})
it('is not a dead allowlist: the floating layers really carry deep shadows', () => {
// If a floating file stops carrying its shadow, the allowlist is hiding a
// regression elsewhere (or the elevation policy drifted back to flat).
expect(read('src/client/AnchoredPopover.tsx')).toMatch(/(?<![-\w])shadow-lg/)
expect(read(`${VENDORED_UI_DIR}/popover.tsx`)).toMatch(/(?<![-\w])shadow-md/)
expect(read(`${VENDORED_UI_DIR}/dropdown-menu.tsx`)).toMatch(/(?<![-\w])shadow-lg/)
})
})