@tbox.cn/app-template-agent 1.0.0-alpha.8 → 1.0.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitignore +7 -0
- package/.tbox/app.json +1 -1
- package/.tbox/default-modules.json +1 -1
- package/.tbox/factory/chat.json +9 -0
- package/.tbox/miniapp-containers.json +1 -1
- package/AGENTS.md +4 -2
- package/apps/client/package.json +1 -0
- package/apps/client/scripts/._color-scan.test.mjs +0 -0
- package/apps/client/scripts/._experience-checks.mjs +0 -0
- package/apps/client/scripts/._geometry-kernel.test.mjs +0 -0
- package/apps/client/scripts/._in-process-checks.mjs +0 -0
- package/apps/client/scripts/._probe-checks.mjs +0 -0
- package/apps/client/scripts/._sample-entries.test.mjs +0 -0
- package/apps/client/scripts/._storyboard.test.mjs +0 -0
- package/apps/client/scripts/._theme-kernel.mjs +0 -0
- package/apps/client/scripts/._theme-kernel.test.mjs +0 -0
- package/apps/client/scripts/acceptance-changes.test.mjs +97 -0
- package/apps/client/scripts/check-evidence.mjs +361 -94
- package/apps/client/scripts/color-scan.mjs +66 -0
- package/apps/client/scripts/color-scan.test.mjs +25 -0
- package/apps/client/scripts/evidence-gate.mjs +248 -46
- package/apps/client/scripts/evidence-gate.test.mjs +63 -5
- package/apps/client/scripts/experience-checks.mjs +163 -0
- package/apps/client/scripts/geometry-kernel.test.mjs +92 -0
- package/apps/client/scripts/in-process-checks.mjs +51 -0
- package/apps/client/scripts/lib/._card-registry.mjs +0 -0
- package/apps/client/scripts/lib/._card-registry.test.mjs +0 -0
- package/apps/client/scripts/lib/._evidence-inputs.mjs +0 -0
- package/apps/client/scripts/lib/._evidence-inputs.test.mjs +0 -0
- package/apps/client/scripts/lib/._static-render.mjs +0 -0
- package/apps/client/scripts/lib/._static-render.test.mjs +0 -0
- package/apps/client/scripts/lib/card-registry.mjs +81 -0
- package/apps/client/scripts/lib/card-registry.test.mjs +59 -0
- package/apps/client/scripts/lib/evidence-inputs.mjs +91 -0
- package/apps/client/scripts/lib/evidence-inputs.test.mjs +27 -0
- package/apps/client/scripts/lib/static-render.mjs +35 -0
- package/apps/client/scripts/lib/static-render.test.mjs +21 -0
- package/apps/client/scripts/probe-checks.mjs +85 -0
- package/apps/client/scripts/render-card.mjs +76 -60
- package/apps/client/scripts/sample-entries.test.mjs +31 -0
- package/apps/client/scripts/storyboard.test.mjs +149 -0
- package/apps/client/scripts/surface-css.mjs +5 -2
- package/apps/client/scripts/theme-kernel.mjs +236 -0
- package/apps/client/scripts/theme-kernel.test.mjs +136 -0
- package/apps/client/src/styles/brand.css +11 -11
- package/apps/client/src/styles/tailwind.css +3 -4
- package/apps/client/vite.config.ts +2 -1
- package/apps/server/scripts/probe.mjs +6 -1
- package/apps/server/scripts/scenario-lib.mjs +54 -7
- package/apps/server/scripts/scenario.mjs +41 -7
- package/config/AGENTS.md +1 -0
- package/config/chat.json +21 -9
- package/docs/agent/card.md +1 -0
- package/docs/agent/kit.md +1 -1
- package/docs/agent/shell.md +1 -0
- package/docs/agent/style.md +3 -1
- package/docs/agent/verify.md +37 -8
- package/package.json +9 -6
- package/packages/agent-ui-kit/README.md +21 -1
- package/packages/agent-ui-kit/catalog.json +1 -1
- package/packages/agent-ui-kit/package.json +9 -1
- package/packages/agent-ui-kit/src/ChatPage.tsx +30 -1
- package/packages/agent-ui-kit/src/card/primitives.test.tsx +10 -0
- package/packages/agent-ui-kit/src/card/primitives.tsx +14 -10
- package/packages/agent-ui-kit/src/card/view-card.tsx +6 -1
- package/packages/agent-ui-kit/src/chat-config.ts +11 -7
- package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.test.tsx +3 -0
- package/packages/agent-ui-kit/src/components/ActionBar/DebugButton.tsx +2 -7
- package/packages/agent-ui-kit/src/components/BottomSheet/._index.test.tsx +0 -0
- package/packages/agent-ui-kit/src/components/BottomSheet/._index.tsx +0 -0
- package/packages/agent-ui-kit/src/components/BottomSheet/index.test.tsx +90 -0
- package/packages/agent-ui-kit/src/components/BottomSheet/index.tsx +129 -0
- package/packages/agent-ui-kit/src/components/ChatInput/index.test.tsx +2 -2
- package/packages/agent-ui-kit/src/components/ChatInput/index.tsx +21 -16
- package/packages/agent-ui-kit/src/components/HistoryEntry/index.tsx +1 -0
- package/packages/agent-ui-kit/src/components/QuickCommands/index.tsx +2 -2
- package/packages/agent-ui-kit/src/components/ScrollToBottomButton/index.tsx +7 -3
- package/packages/agent-ui-kit/src/components/ToolCallBlock/index.tsx +4 -2
- package/packages/agent-ui-kit/src/index.ts +4 -0
- package/packages/agent-ui-kit/src/shell.contract.json +9 -0
- package/packages/agent-ui-kit/src/shell.test.ts +10 -0
- package/packages/agent-ui-kit/src/shell.ts +15 -0
- package/packages/agent-ui-kit/src/theme/contract.json +78 -1
- package/packages/agent-ui-kit/src/theme/theme-contract.test.ts +16 -0
- package/packages/agent-ui-kit/src/theme/tokens.css +1 -1
- package/pnpm-lock.template.yaml +97 -91
- package/pnpm-workspace.template.yaml +10 -10
- package/profiles/mall/._chat.overrides.json +0 -0
- package/profiles/mall/chat.overrides.json +12 -0
- package/profiles/mall/config/chat.json +14 -6
- package/profiles/mall.json +1 -1
- package/scripts/._deliver.mjs +0 -0
- package/scripts/._shell-probe.mjs +0 -0
- package/scripts/._storyboard.mjs +0 -0
- package/scripts/check-fast.mjs +1 -0
- package/scripts/checks.json +294 -17
- package/scripts/deliver.mjs +183 -0
- package/scripts/lib/._chrome-pipe.mjs +0 -0
- package/scripts/lib/._geometry-kernel.mjs +0 -0
- package/scripts/lib/chrome-pipe.mjs +95 -0
- package/scripts/lib/geometry-kernel.mjs +137 -0
- package/scripts/shell-probe.mjs +283 -0
- package/scripts/storyboard.mjs +350 -0
- package/profiles/mall/config/llm_provider.json +0 -5
- package/profiles/mall/config/plugins.json +0 -3
- package/scripts/gen-tailwind-sources.mjs +0 -55
- /package/{profiles/mall/config/._llm_provider.json → .tbox/factory/._chat.json} +0 -0
- /package/{profiles/mall/config/._plugins.json → apps/client/scripts/._acceptance-changes.test.mjs} +0 -0
- /package/{scripts/._gen-tailwind-sources.mjs → apps/client/scripts/._color-scan.mjs} +0 -0
|
@@ -19,9 +19,12 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { createRequire } from 'node:module';
|
|
21
21
|
import { copyFileSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
22
|
+
import { createServer as createHttpServer } from 'node:http';
|
|
22
23
|
import { buildSurfaceCss, SURFACE_CSS_SENTINELS } from './surface-css.mjs';
|
|
24
|
+
import { geometryFunctionSource } from '../../../scripts/lib/geometry-kernel.mjs';
|
|
23
25
|
import { execFileSync } from 'node:child_process';
|
|
24
26
|
import path from 'node:path';
|
|
27
|
+
import { fileURLToPath } from 'node:url';
|
|
25
28
|
import process from 'node:process';
|
|
26
29
|
|
|
27
30
|
const appDir = path.resolve(import.meta.dirname, '..', '..', '..');
|
|
@@ -99,7 +102,7 @@ function usageError(message) {
|
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
// ── 1. 启动 Vite(与 check-evidence 同一条加载路径) ─────────────────
|
|
102
|
-
async function loadVite() {
|
|
105
|
+
export async function loadVite() {
|
|
103
106
|
let createServer;
|
|
104
107
|
let react;
|
|
105
108
|
let tailwindcss;
|
|
@@ -123,15 +126,21 @@ async function loadVite() {
|
|
|
123
126
|
'@config': path.join(appDir, 'config'),
|
|
124
127
|
},
|
|
125
128
|
},
|
|
126
|
-
|
|
129
|
+
// 零 socket:给 Vite 一个永不 listen 的 http server 承载 HMR 升级,避免自建 24678 监听。
|
|
130
|
+
server: { middlewareMode: true, hmr: { server: createHttpServer() }, fs: { allow: [appDir] } },
|
|
127
131
|
optimizeDeps: { noDiscovery: true, include: [] },
|
|
132
|
+
// SSR 加载客户端 registry 时,依赖里带 CSS 的包必须交给 Vite 内联处理:
|
|
133
|
+
// Node 直连 antd-mobile 的 CJS 入口会 require 它自己的 global.css,直接 SyntaxError。
|
|
134
|
+
// 新增同类运行时依赖(带 CSS 副作用)时补进这张名单,否则 registry 步骤会在
|
|
135
|
+
// 模块客户端代码 import 到它时报「Unexpected token ':'」。
|
|
136
|
+
ssr: { noExternal: ['antd-mobile'] },
|
|
128
137
|
});
|
|
129
138
|
} catch (error) {
|
|
130
139
|
throw new Error(`Vite 启动失败:${error?.message ?? error}\n 修复:检查依赖安装与 apps/client/.tbox-gen(pnpm generate)`);
|
|
131
140
|
}
|
|
132
141
|
}
|
|
133
142
|
|
|
134
|
-
async function loadRegistry(vite) {
|
|
143
|
+
export async function loadRegistry(vite) {
|
|
135
144
|
let client;
|
|
136
145
|
let server;
|
|
137
146
|
try {
|
|
@@ -148,7 +157,7 @@ async function loadRegistry(vite) {
|
|
|
148
157
|
}
|
|
149
158
|
|
|
150
159
|
// ── 2. 样式:与 dev/build 同一条 Vite + Tailwind 管线 ────────────────
|
|
151
|
-
async function buildStyleSheet(vite) {
|
|
160
|
+
export async function buildStyleSheet(vite) {
|
|
152
161
|
const { cssText, bytes, missing } = await buildSurfaceCss(vite, { clientDir, appDir });
|
|
153
162
|
return { css: cssText, bytes, missing };
|
|
154
163
|
}
|
|
@@ -369,21 +378,37 @@ function buildOutline(cardType, label, cardHtml) {
|
|
|
369
378
|
}
|
|
370
379
|
|
|
371
380
|
// ── 4. 渲染 ──────────────────────────────────────────────────────────
|
|
372
|
-
function sampleEntries(meta) {
|
|
381
|
+
export function sampleEntries(meta, { includeHidden = true } = {}) {
|
|
373
382
|
const samples = [];
|
|
374
|
-
if (meta.sampleData !== undefined) samples.push({ label: 'sampleData', note: undefined, data: meta.sampleData });
|
|
383
|
+
if (meta.sampleData !== undefined) samples.push({ label: 'sampleData', note: undefined, data: meta.sampleData, isHistory: false, noTokens: false, hidden: false });
|
|
375
384
|
if (Array.isArray(meta.samples)) {
|
|
376
385
|
meta.samples.forEach((entry, index) => {
|
|
386
|
+
if (entry?.hidden === true && !includeHidden) return;
|
|
377
387
|
samples.push({
|
|
378
388
|
label: typeof entry?.label === 'string' ? entry.label : `samples[${index}]`,
|
|
379
389
|
note: typeof entry?.note === 'string' ? entry.note : undefined,
|
|
390
|
+
group: typeof entry?.group === 'string' ? entry.group : undefined,
|
|
380
391
|
data: entry?.data,
|
|
392
|
+
isHistory: entry?.isHistory === true,
|
|
393
|
+
noTokens: entry?.noTokens === true,
|
|
394
|
+
hidden: entry?.hidden === true,
|
|
381
395
|
});
|
|
382
396
|
});
|
|
383
397
|
}
|
|
384
398
|
return samples;
|
|
385
399
|
}
|
|
386
400
|
|
|
401
|
+
/** 同卡样例 label 重复检测:label 是故事板帧键与渲染文件名的一部分,重复会静默覆盖证据。 */
|
|
402
|
+
export function duplicateSampleLabels(meta, { includeHidden = true } = {}) {
|
|
403
|
+
const seen = new Set();
|
|
404
|
+
const duplicates = new Set();
|
|
405
|
+
for (const sample of sampleEntries(meta, { includeHidden })) {
|
|
406
|
+
if (seen.has(sample.label)) duplicates.add(sample.label);
|
|
407
|
+
seen.add(sample.label);
|
|
408
|
+
}
|
|
409
|
+
return [...duplicates];
|
|
410
|
+
}
|
|
411
|
+
|
|
387
412
|
function selectSamples(samples, args) {
|
|
388
413
|
if (samples.length === 0) return [];
|
|
389
414
|
if (args.all) return samples;
|
|
@@ -400,7 +425,7 @@ function selectSamples(samples, args) {
|
|
|
400
425
|
|
|
401
426
|
const slug = (label) => label.replace(/[^\p{L}\p{N}._-]+/gu, '-').replace(/^-+|-+$/g, '') || 'sample';
|
|
402
427
|
|
|
403
|
-
async function renderSamples(vite, registries, cardType, samples) {
|
|
428
|
+
export async function renderSamples(vite, registries, cardType, samples) {
|
|
404
429
|
const meta = registries.server?.cards?.[cardType];
|
|
405
430
|
const components = registries.client?.cards ?? {};
|
|
406
431
|
const Component = components[cardType];
|
|
@@ -412,6 +437,8 @@ async function renderSamples(vite, registries, cardType, samples) {
|
|
|
412
437
|
}
|
|
413
438
|
const React = (await import('react')).default;
|
|
414
439
|
const { renderToStaticMarkup } = await import('react-dom/server');
|
|
440
|
+
const { createStaticRenderer } = await import('./lib/static-render.mjs');
|
|
441
|
+
const staticRender = createStaticRenderer(renderToStaticMarkup);
|
|
415
442
|
const kit = await vite.ssrLoadModule('@tbox.cn/app-agent-ui-kit');
|
|
416
443
|
|
|
417
444
|
// 与 check:fast / 预览同一条装配(SurfaceHarness):动作不落库、isGenerating=false。
|
|
@@ -423,9 +450,9 @@ async function renderSamples(vite, registries, cardType, samples) {
|
|
|
423
450
|
const schemaValid = parsed ? parsed.success : true;
|
|
424
451
|
let html;
|
|
425
452
|
try {
|
|
426
|
-
html =
|
|
453
|
+
html = staticRender.render(
|
|
427
454
|
harness.wrap(
|
|
428
|
-
React.createElement(Component, { data: parsed?.success ? parsed.data : sample.data, cardId: `render-${cardType}`, isHistory:
|
|
455
|
+
React.createElement(Component, { data: parsed?.success ? parsed.data : sample.data, cardId: `render-${cardType}`, isHistory: sample.isHistory === true, actionTokens: {} }),
|
|
429
456
|
),
|
|
430
457
|
);
|
|
431
458
|
} catch (error) {
|
|
@@ -447,6 +474,9 @@ async function renderSamples(vite, registries, cardType, samples) {
|
|
|
447
474
|
// ── 视觉体检(F12,可选层:需要无头浏览器) ──────────────────────
|
|
448
475
|
const CHROME_CANDIDATES = [
|
|
449
476
|
process.env.TBOX_CHROME,
|
|
477
|
+
// 平台沙箱:Chrome for Testing 由镜像安装,路径只在 AGENT_BROWSER_EXECUTABLE_PATH 暴露。
|
|
478
|
+
process.env.AGENT_BROWSER_EXECUTABLE_PATH,
|
|
479
|
+
'/home/admin/.agent-browser/chrome/chrome-linux64/chrome',
|
|
450
480
|
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
451
481
|
'/Applications/Chromium.app/Contents/MacOS/Chromium',
|
|
452
482
|
'/usr/bin/google-chrome',
|
|
@@ -455,6 +485,7 @@ const CHROME_CANDIDATES = [
|
|
|
455
485
|
'/usr/bin/chromium-browser',
|
|
456
486
|
].filter(Boolean);
|
|
457
487
|
|
|
488
|
+
let chromeLookupError = '';
|
|
458
489
|
function findChrome() {
|
|
459
490
|
for (const candidate of CHROME_CANDIDATES) if (existsSync(candidate)) return candidate;
|
|
460
491
|
for (const name of ['chromium', 'google-chrome', 'chrome']) {
|
|
@@ -465,48 +496,27 @@ function findChrome() {
|
|
|
465
496
|
// 继续找
|
|
466
497
|
}
|
|
467
498
|
}
|
|
499
|
+
chromeLookupError = '已尝试:' + CHROME_CANDIDATES.join('、') + ' 与 PATH 中的 chromium/google-chrome/chrome';
|
|
468
500
|
return undefined;
|
|
469
501
|
}
|
|
470
502
|
|
|
471
|
-
const auditScript = (
|
|
503
|
+
const auditScript = () => `
|
|
472
504
|
<script>
|
|
473
505
|
(function () {
|
|
474
|
-
//
|
|
475
|
-
//
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
var
|
|
479
|
-
var
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
var size = parseFloat(getComputedStyle(el).fontSize);
|
|
489
|
-
if (size > 0) {
|
|
490
|
-
minFont = Math.min(minFont, size);
|
|
491
|
-
var key = Math.round(size * 10) / 10;
|
|
492
|
-
fontCounts[key] = (fontCounts[key] || 0) + 1;
|
|
493
|
-
if (!fontSamples[key]) fontSamples[key] = (el.textContent || '').trim().slice(0, 20);
|
|
494
|
-
}
|
|
495
|
-
if (el.scrollWidth > el.clientWidth + 1) out.truncated += 1;
|
|
496
|
-
}
|
|
497
|
-
if ((el.tagName === 'BUTTON' || el.tagName === 'A') && rect.width > 0) {
|
|
498
|
-
if (rect.width < 44 || rect.height < 44) out.smallTargets.push({ tag: el.tagName, w: Math.round(rect.width), h: Math.round(rect.height), text: (el.textContent || '').trim().slice(0, 16) });
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
out.overflow = Math.max(0, document.documentElement.scrollWidth - W);
|
|
502
|
-
out.minFontPx = minFont === 1e9 ? null : Math.round(minFont * 10) / 10;
|
|
503
|
-
var ALLOWED = [12, 14, 16, 18, 20];
|
|
504
|
-
var offScale = Object.keys(fontCounts)
|
|
505
|
-
.map(Number)
|
|
506
|
-
.filter(function (px) { return ALLOWED.indexOf(px) < 0; })
|
|
507
|
-
.map(function (px) { return { px: px, count: fontCounts[px], sample: fontSamples[px] }; });
|
|
508
|
-
out.typeScale = { allowed: ALLOWED, counts: fontCounts, offScale: offScale };
|
|
509
|
-
out.smallTargets = out.smallTargets.slice(0, 5);
|
|
506
|
+
// 量法统一在 scripts/lib/geometry-kernel.mjs(与壳探针、故事板同一份);
|
|
507
|
+
// 这里只把内核输出映射回体检原有的字段名,报告与命令行输出不变。
|
|
508
|
+
// 无头浏览器有最小窗口宽(macOS 上约 500),这里按实际视口量并把宽度写进结果。
|
|
509
|
+
${geometryFunctionSource()}
|
|
510
|
+
var g = tboxGeometry({ targets: 'button, a', thresholds: { minTarget: 44, minFontPx: 12 } });
|
|
511
|
+
var out = {
|
|
512
|
+
viewport: g.viewport.w,
|
|
513
|
+
overflow: g.overflowX,
|
|
514
|
+
overflowRight: g.overflowRight,
|
|
515
|
+
minFontPx: g.minFontPx,
|
|
516
|
+
truncated: g.clipped.length,
|
|
517
|
+
smallTargets: g.smallTargets,
|
|
518
|
+
typeScale: g.typeScale,
|
|
519
|
+
};
|
|
510
520
|
var pre = document.createElement('pre');
|
|
511
521
|
pre.id = '__tbox_audit';
|
|
512
522
|
pre.textContent = JSON.stringify(out);
|
|
@@ -517,7 +527,7 @@ const auditScript = (width) => `
|
|
|
517
527
|
/** 用无头浏览器量一张卡在 390 宽下的布局风险;找不到浏览器时返回 skipped。 */
|
|
518
528
|
function auditFile(file, width = 390) {
|
|
519
529
|
const chrome = findChrome();
|
|
520
|
-
if (!chrome) return { skipped: true, reason: '未找到无头浏览器(可设 TBOX_CHROME 指向 Chrome/Chromium)' };
|
|
530
|
+
if (!chrome) return { skipped: true, reason: '未找到无头浏览器(可设 TBOX_CHROME 指向 Chrome/Chromium)' + (chromeLookupError ? ';' + chromeLookupError : '') };
|
|
521
531
|
const html = readFileSync(file, 'utf8').replace('</body>', `${auditScript(width)}\n</body>`);
|
|
522
532
|
const probe = file.replace(/\.html$/, '.audit.html');
|
|
523
533
|
writeFileSync(probe, html, 'utf8');
|
|
@@ -548,7 +558,7 @@ function auditLines(audit) {
|
|
|
548
558
|
|
|
549
559
|
function captureScreenshot(file, outDir, base) {
|
|
550
560
|
const chrome = findChrome();
|
|
551
|
-
if (!chrome) return { skipped: true, reason: '未找到无头浏览器(可设 TBOX_CHROME 指向 Chrome/Chromium)' };
|
|
561
|
+
if (!chrome) return { skipped: true, reason: '未找到无头浏览器(可设 TBOX_CHROME 指向 Chrome/Chromium)' + (chromeLookupError ? ';' + chromeLookupError : '') };
|
|
552
562
|
const png = path.join(outDir, `${base}.png`);
|
|
553
563
|
try {
|
|
554
564
|
execFileSync(
|
|
@@ -603,7 +613,7 @@ function compareScreenshot(current, baselineDir, base) {
|
|
|
603
613
|
}
|
|
604
614
|
|
|
605
615
|
// ── 5. 输出 ──────────────────────────────────────────────────────────
|
|
606
|
-
function writeSample(outDir, cardType, sample, css) {
|
|
616
|
+
export function writeSample(outDir, cardType, sample, css) {
|
|
607
617
|
mkdirSync(outDir, { recursive: true });
|
|
608
618
|
const base = sample.label === 'sampleData' ? cardType : `${cardType}-${slug(sample.label)}`;
|
|
609
619
|
const file = path.join(outDir, `${base}.html`);
|
|
@@ -624,8 +634,10 @@ async function main() {
|
|
|
624
634
|
const vite = await loadVite();
|
|
625
635
|
try {
|
|
626
636
|
const registries = await loadRegistry(vite);
|
|
627
|
-
const
|
|
628
|
-
const
|
|
637
|
+
const view = (await import('./lib/card-registry.mjs')).collectCards({ server: registries.server, client: registries.client });
|
|
638
|
+
const resolved = { ...registries, server: { ...registries.server, cards: view.metas }, client: { ...registries.client, cards: view.components } };
|
|
639
|
+
const knownCards = Object.keys(view.metas);
|
|
640
|
+
const meta = view.metas[args.type];
|
|
629
641
|
if (!meta) {
|
|
630
642
|
throw new Error(
|
|
631
643
|
`未找到卡片类型 "${args.type}"(已注册:${knownCards.join('、') || '无'})\n` +
|
|
@@ -636,18 +648,18 @@ async function main() {
|
|
|
636
648
|
if (samples.length === 0) {
|
|
637
649
|
throw new Error(
|
|
638
650
|
`卡片 ${args.type} 没有样例。\n` +
|
|
639
|
-
` 修复:在 apps/server/src/cards/${args.type}.card.ts 的 sampleData 或 samples 里补一条静态字面量(card render 依赖它)`,
|
|
651
|
+
` 修复:在 ${view.provenance?.[args.type]?.kind === 'module' ? `modules/${view.provenance[args.type].moduleId}/src/server/cards/${args.type}/meta.ts` : `apps/server/src/cards/${args.type}.card.ts`} 的 sampleData 或 samples 里补一条静态字面量(card render 依赖它)`,
|
|
640
652
|
);
|
|
641
653
|
}
|
|
642
654
|
const selected = selectSamples(samples, args);
|
|
643
|
-
const rendered = await renderSamples(vite,
|
|
655
|
+
const rendered = await renderSamples(vite, resolved, args.type, selected);
|
|
644
656
|
const surface = await buildStyleSheet(vite);
|
|
645
657
|
const css = surface.css;
|
|
646
658
|
// 证据自校验:CSS 为空或哨兵缺失时,截图/HTML 只会说谎——直接失败,不产出「无样式证据」。
|
|
647
659
|
if (surface.missing.length > 0 || surface.bytes < 20000) {
|
|
648
660
|
throw new Error(
|
|
649
661
|
`表面 CSS 不可信:${surface.bytes} 字节,缺哨兵 ${surface.missing.join('、') || '无'}。\n` +
|
|
650
|
-
` 修复:确认 apps/client/
|
|
662
|
+
` 修复:确认 apps/client/vite.config.ts 的 tboxModuleSourcesPlugin 在 tailwindcss() 之前;本命令与 check:fast 同一管线(surface-css.mjs)。`,
|
|
651
663
|
);
|
|
652
664
|
}
|
|
653
665
|
const outDir = path.resolve(args.out ?? path.join(appDir, '.tbox/card-render'));
|
|
@@ -687,10 +699,14 @@ async function main() {
|
|
|
687
699
|
}
|
|
688
700
|
}
|
|
689
701
|
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
702
|
+
// 直接运行才走 CLI;被 scripts/storyboard.mjs 导入时只提供渲染函数(同进程复用一次 vite)。
|
|
703
|
+
const invokedDirectly = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
704
|
+
if (invokedDirectly) {
|
|
705
|
+
try {
|
|
706
|
+
await main();
|
|
707
|
+
} catch (error) {
|
|
708
|
+
if (process.argv.includes('--json')) console.log(JSON.stringify({ ok: false, error: error?.message ?? String(error) }));
|
|
709
|
+
else console.error(`❌ ${error?.message ?? error}`);
|
|
710
|
+
process.exitCode = 1;
|
|
711
|
+
}
|
|
696
712
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { duplicateSampleLabels, sampleEntries } from './render-card.mjs';
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
sampleData: { title: '基准' },
|
|
6
|
+
samples: [
|
|
7
|
+
{ label: '历史', data: { title: '历史' }, isHistory: true },
|
|
8
|
+
{ label: '隐藏', data: { title: '隐藏' }, hidden: true },
|
|
9
|
+
{ label: '无令牌', data: { title: '无令牌' }, noTokens: true },
|
|
10
|
+
],
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
describe('样例条目', () => {
|
|
14
|
+
it('贯通 isHistory/noTokens/hidden/group/note,隐藏样例可按需过滤', () => {
|
|
15
|
+
const all = sampleEntries(meta);
|
|
16
|
+
expect(all.map((sample) => sample.label)).toEqual(['sampleData', '历史', '隐藏', '无令牌']);
|
|
17
|
+
expect(all.find((sample) => sample.label === '历史')?.isHistory).toBe(true);
|
|
18
|
+
expect(all.find((sample) => sample.label === '无令牌')?.noTokens).toBe(true);
|
|
19
|
+
expect(all.find((sample) => sample.label === '隐藏')?.hidden).toBe(true);
|
|
20
|
+
expect(sampleEntries(meta, { includeHidden: false }).map((sample) => sample.label)).toEqual(['sampleData', '历史', '无令牌']);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('同卡 label 重复可被检测(帧键/文件名冲突防线)', () => {
|
|
24
|
+
expect(duplicateSampleLabels(meta)).toEqual([]);
|
|
25
|
+
const duplicated = { ...meta, samples: [...meta.samples, { label: '历史', data: {} }] };
|
|
26
|
+
expect(duplicateSampleLabels(duplicated)).toEqual(['历史']);
|
|
27
|
+
// hidden-only 重复不进帧:故事板用 includeHidden:false 检查,不应误伤。
|
|
28
|
+
const hiddenDuplicate = { ...meta, samples: [...meta.samples, { label: '隐藏', data: {}, hidden: true }] };
|
|
29
|
+
expect(duplicateSampleLabels(hiddenDuplicate, { includeHidden: false })).toEqual([]);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { chunkPages, expandFrames, geometryProblems, sourceCacheKey } from '../../../scripts/storyboard.mjs';
|
|
3
|
+
import { matchFrame, storyboardCoverage } from './evidence-gate.mjs';
|
|
4
|
+
import { mergeStoryboardChecks } from './probe-checks.mjs';
|
|
5
|
+
|
|
6
|
+
const cards = [
|
|
7
|
+
{ cardType: 'parking', samples: [{ label: 'sampleData' }, { label: '已缴费' }, { label: '无记录' }, { label: '第四个' }] },
|
|
8
|
+
{ cardType: 'member', samples: [{ label: 'sampleData' }] },
|
|
9
|
+
];
|
|
10
|
+
const specs = [
|
|
11
|
+
{ id: 'shell.empty', source: 'shell', widths: [390, 320] },
|
|
12
|
+
{ id: 'card', source: 'card-samples', widths: [390, 320], maxSamplesPerCard: 3 },
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
describe('故事板帧展开', () => {
|
|
16
|
+
it('宽档笛卡尔积;最宽档看全部样例,窄档只看第一个', () => {
|
|
17
|
+
const frames = expandFrames(specs, cards);
|
|
18
|
+
expect(frames.filter((frame) => frame.source === 'shell').map((frame) => frame.id)).toEqual(['shell.empty@390', 'shell.empty@320']);
|
|
19
|
+
const cardFrames = frames.filter((frame) => frame.source === 'card-samples');
|
|
20
|
+
// parking:390 三个样例 + 320 一个;member:390 一个 + 320 一个
|
|
21
|
+
expect(cardFrames.filter((frame) => frame.width === 390)).toHaveLength(4);
|
|
22
|
+
expect(cardFrames.filter((frame) => frame.width === 320)).toHaveLength(2);
|
|
23
|
+
expect(cardFrames[0].id).toBe('card:parking:sampleData@390');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('hidden 卡只取基准态(最宽档 1 份 + 窄档 1 份)', () => {
|
|
27
|
+
const hidden = [{ cardType: 'hidden-card', hidden: true, samples: [{ label: 'sampleData' }, { label: '状态一' }, { label: '状态二' }] }];
|
|
28
|
+
const frames = expandFrames(specs, hidden).filter((frame) => frame.source === 'card-samples');
|
|
29
|
+
expect(frames.map((frame) => frame.id)).toEqual(['card:hidden-card:sampleData@390', 'card:hidden-card:sampleData@320']);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('没有样例的卡片不产生帧', () => {
|
|
33
|
+
const frames = expandFrames(specs, [{ cardType: 'empty', samples: [] }]);
|
|
34
|
+
expect(frames.filter((frame) => frame.source === 'card-samples')).toHaveLength(0);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('分页', () => {
|
|
39
|
+
it('按帧高累加切页,超过上限换页,最多三页', () => {
|
|
40
|
+
const frames = Array.from({ length: 10 }, (_, index) => ({ id: 'f' + index, geometry: { height: 4000 } }));
|
|
41
|
+
const pages = chunkPages(frames, 12000, 3);
|
|
42
|
+
expect(pages.length).toBe(3);
|
|
43
|
+
expect(pages.every((page) => page.length > 0)).toBe(true);
|
|
44
|
+
expect(pages.flat().length).toBeLessThanOrEqual(10);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('单页放得下就只出一页', () => {
|
|
48
|
+
const pages = chunkPages([{ id: 'a', geometry: { height: 500 } }, { id: 'b', geometry: { height: 500 } }], 12000, 3);
|
|
49
|
+
expect(pages).toHaveLength(1);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('帧级几何判定', () => {
|
|
54
|
+
const limits = { minTarget: 44, minFontPx: 12, overflowTolerancePx: 1 };
|
|
55
|
+
it('卡片帧:溢出、截断、点击区与字号各出一条', () => {
|
|
56
|
+
const problems = geometryProblems({
|
|
57
|
+
id: 'card:parking:x@320', source: 'card-samples',
|
|
58
|
+
geometry: { overflowX: 12, clipped: [{ text: '很长的文字', ellipsis: false }], smallTargets: [{ tag: 'BUTTON', w: 20, h: 20, text: '领券' }], minFontPx: 10 },
|
|
59
|
+
}, limits);
|
|
60
|
+
expect(problems.map((item) => item.id)).toEqual(['card.overflow-x', 'card.text-clip', 'card.tap-target', 'card.min-font']);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('有省略号的截断不算问题;壳帧不判卡片项(壳有自己的检查)', () => {
|
|
64
|
+
expect(geometryProblems({ id: 'x', source: 'card-samples', geometry: { clipped: [{ text: 'a', ellipsis: true }], minFontPx: 14, overflowX: 0, smallTargets: [] } }, limits)).toEqual([]);
|
|
65
|
+
expect(geometryProblems({ id: 'shell.empty@390', source: 'shell', geometry: { overflowX: 40, minFontPx: 9 } }, limits)).toEqual([]);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('故事板覆盖(D1)', () => {
|
|
70
|
+
const items = [
|
|
71
|
+
{ id: 'ui.mobile', by: 'storyboard', frames: ['card:*@320', 'shell.empty@320'] },
|
|
72
|
+
{ id: 'ui.brand', by: 'storyboard' },
|
|
73
|
+
{ id: 'logic', by: 'scenario' },
|
|
74
|
+
];
|
|
75
|
+
const storyboard = {
|
|
76
|
+
status: 'ok',
|
|
77
|
+
frames: [
|
|
78
|
+
{ id: 'card:parking:sampleData@320', source: 'card-samples', problems: [] },
|
|
79
|
+
{ id: 'shell.empty@320', source: 'shell', problems: [] },
|
|
80
|
+
{ id: 'card:parking:sampleData@390', source: 'card-samples', problems: [] },
|
|
81
|
+
],
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
it('匹配帧全部无错 → 覆盖;与场景覆盖分列', () => {
|
|
85
|
+
const board = storyboardCoverage(items, storyboard, 'visual');
|
|
86
|
+
expect([...board.covered]).toEqual(['ui.mobile', 'ui.brand']);
|
|
87
|
+
expect(board.handoff.size).toBe(0);
|
|
88
|
+
expect(board.failed.size).toBe(0);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('任一帧有 error 级几何 → 该项不升格,按未覆盖', () => {
|
|
92
|
+
const broken = { ...storyboard, frames: storyboard.frames.map((frame) => frame.id === 'card:parking:sampleData@320' ? { ...frame, problems: [{ id: 'card.overflow-x', detail: '溢出 12px' }] } : frame) };
|
|
93
|
+
const board = storyboardCoverage(items, broken, 'visual');
|
|
94
|
+
expect(board.covered.has('ui.mobile')).toBe(false);
|
|
95
|
+
expect(board.failed.has('ui.mobile')).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('static 档位或故事板未运行 → 回落 handoff 并写理由', () => {
|
|
99
|
+
expect(storyboardCoverage(items, storyboard, 'static').handoff.get('ui.mobile')).toContain('static');
|
|
100
|
+
expect(storyboardCoverage(items, { status: 'not-run', reason: '无 Chrome' }, 'visual').handoff.get('ui.mobile')).toContain('未运行');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('没有匹配帧 → handoff,理由带 frames 表达式', () => {
|
|
104
|
+
const board = storyboardCoverage([{ id: 'ui.x', by: 'storyboard', frames: ['card:nope@320'] }], storyboard, 'visual');
|
|
105
|
+
expect(board.handoff.get('ui.x')).toContain('card:nope@320');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('帧 id 通配只认位置', () => {
|
|
109
|
+
expect(matchFrame('*', 'anything')).toBe(true);
|
|
110
|
+
expect(matchFrame('card:*@320', 'card:parking:x@320')).toBe(true);
|
|
111
|
+
expect(matchFrame('card:*@320', 'card:parking:x@390')).toBe(false);
|
|
112
|
+
expect(matchFrame('card', 'card:parking:x@390')).toBe(false);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe('故事板检查合并', () => {
|
|
117
|
+
const ids = ['storyboard.render', 'card.overflow-x', 'card.min-font'];
|
|
118
|
+
it('没有卡片时卡片项 deferred,渲染项照常', () => {
|
|
119
|
+
const merged = mergeStoryboardChecks({ storyboard: { status: 'ok', frames: [{ id: 'shell.empty@390', source: 'shell', problems: [] }] }, ids, policy: 'visual', cardCount: 0 });
|
|
120
|
+
expect(merged.find((item) => item.id === 'storyboard.render').status).toBe('pass');
|
|
121
|
+
expect(merged.find((item) => item.id === 'card.overflow-x').status).toBe('deferred');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('帧错误 → 渲染项 fail;几何问题聚合到对应 id', () => {
|
|
125
|
+
const merged = mergeStoryboardChecks({
|
|
126
|
+
storyboard: { status: 'partial', frames: [
|
|
127
|
+
{ id: 'card:a:x@390', source: 'card-samples', error: '帧未加载几何内核' },
|
|
128
|
+
{ id: 'card:b:x@390', source: 'card-samples', problems: [{ id: 'card.min-font', detail: '9px' }] },
|
|
129
|
+
] },
|
|
130
|
+
ids, policy: 'visual', cardCount: 2,
|
|
131
|
+
});
|
|
132
|
+
expect(merged.find((item) => item.id === 'storyboard.render').status).toBe('fail');
|
|
133
|
+
expect(merged.find((item) => item.id === 'card.min-font').status).toBe('fail');
|
|
134
|
+
expect(merged.find((item) => item.id === 'card.overflow-x').status).toBe('pass');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('static 档位全部 deferred', () => {
|
|
138
|
+
const merged = mergeStoryboardChecks({ storyboard: { status: 'ok', frames: [{ id: 'x', problems: [] }] }, ids, policy: 'static', cardCount: 1 });
|
|
139
|
+
expect(merged.every((item) => item.status === 'deferred')).toBe(true);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe('缓存键', () => {
|
|
144
|
+
it('读源文件即可算出,重复调用稳定', () => {
|
|
145
|
+
const first = sourceCacheKey();
|
|
146
|
+
expect(first).toMatch(/^[0-9a-f]{16}$/);
|
|
147
|
+
expect(sourceCacheKey()).toBe(first);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
12
12
|
import { createRequire } from 'node:module';
|
|
13
13
|
import path from 'node:path';
|
|
14
|
+
import { collectModuleSourceDirs, renderModuleSources } from '@tbox.cn/app-build/tailwind-sources';
|
|
14
15
|
|
|
15
16
|
/** 必须出现在产物里的哨兵:少了任何一个,说明样式管线断了,证据不可信。 */
|
|
16
17
|
export const SURFACE_CSS_SENTINELS = ['--tbox-primary', '.tbox-card', '.bg-card'];
|
|
@@ -42,10 +43,12 @@ export async function buildSurfaceCss(vite, { clientDir, appDir }) {
|
|
|
42
43
|
const imports = files
|
|
43
44
|
.map((file) => `@import "${path.relative(entryDir, file).split(path.sep).join('/')}";`)
|
|
44
45
|
.join('\n');
|
|
45
|
-
|
|
46
|
+
// 模块源码与 dev/build 共用同一发现函数:证据包不依赖 tailwind.css 的生成标记块。
|
|
47
|
+
const moduleSources = collectModuleSourceDirs(appDir);
|
|
48
|
+
writeFileSync(entry, `/* 由 surface-css.mjs 生成:证据/截图共用的样式入口 */\n${imports}\n${renderModuleSources(moduleSources)}\n`);
|
|
46
49
|
|
|
47
50
|
const result = await vite.transformRequest(`/@fs${entry}?direct`);
|
|
48
51
|
const cssText = typeof result === 'string' ? result : (result?.code ?? '');
|
|
49
52
|
const missing = SURFACE_CSS_SENTINELS.filter((sentinel) => !cssText.includes(sentinel));
|
|
50
|
-
return { cssText, bytes: Buffer.byteLength(cssText), missing, entry };
|
|
53
|
+
return { cssText, bytes: Buffer.byteLength(cssText), missing, entry, moduleSources };
|
|
51
54
|
}
|