@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
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { existsSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { execFileSync } from 'node:child_process';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_TARGETS,
|
|
8
|
+
GEOMETRY_DEFAULTS,
|
|
9
|
+
geometryAuditScript,
|
|
10
|
+
geometryExpression,
|
|
11
|
+
geometryFunctionSource,
|
|
12
|
+
loadThresholds,
|
|
13
|
+
} from '../../../scripts/lib/geometry-kernel.mjs';
|
|
14
|
+
|
|
15
|
+
const chrome = [
|
|
16
|
+
process.env.TBOX_CHROME,
|
|
17
|
+
process.env.AGENT_BROWSER_EXECUTABLE_PATH,
|
|
18
|
+
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
19
|
+
'/Applications/Chromium.app/Contents/MacOS/Chromium',
|
|
20
|
+
'/usr/bin/google-chrome',
|
|
21
|
+
'/usr/bin/chromium',
|
|
22
|
+
].filter(Boolean).find((candidate) => existsSync(candidate));
|
|
23
|
+
|
|
24
|
+
describe('几何内核', () => {
|
|
25
|
+
it('函数源码可解析,且只依赖 DOM', () => {
|
|
26
|
+
const source = geometryFunctionSource();
|
|
27
|
+
expect(() => new Function(source + '\nreturn tboxGeometry;')).not.toThrow();
|
|
28
|
+
expect(source).not.toMatch(/require\(|import\s|fetch\(/);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('表达式把内核拼成一条可执行语句', () => {
|
|
32
|
+
const expression = geometryExpression({ blankSelectors: ['.chat-page__welcome'] });
|
|
33
|
+
expect(() => new Function('return ' + expression)).not.toThrow();
|
|
34
|
+
expect(expression).toContain('tboxGeometry');
|
|
35
|
+
expect(expression).toContain('.chat-page__welcome');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('审计脚本在页面里写回 <pre id="__tbox_audit">', () => {
|
|
39
|
+
const script = geometryAuditScript({ targets: 'button, a' });
|
|
40
|
+
expect(script.startsWith('<script>')).toBe(true);
|
|
41
|
+
expect(script).toContain('__tbox_audit');
|
|
42
|
+
expect(script).toContain('tboxGeometry');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('阈值可被 checks.json 覆盖,缺省值不变', () => {
|
|
46
|
+
expect(loadThresholds(undefined)).toEqual(GEOMETRY_DEFAULTS);
|
|
47
|
+
const checks = { checks: [{ id: 'card.tap-target', threshold: { minTarget: 40 } }] };
|
|
48
|
+
expect(loadThresholds(checks, ['card.tap-target']).minTarget).toBe(40);
|
|
49
|
+
expect(loadThresholds(checks, ['card.min-font']).minTarget).toBe(GEOMETRY_DEFAULTS.minTarget);
|
|
50
|
+
expect(DEFAULT_TARGETS).toContain('button');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it.runIf(chrome)('真实页面测量:溢出、小目标、字号与块间空白', () => {
|
|
54
|
+
const dir = mkdtempSync(path.join(tmpdir(), 'tbox-geometry-'));
|
|
55
|
+
const file = path.join(dir, 'probe.html');
|
|
56
|
+
const html = [
|
|
57
|
+
'<!doctype html><html><head><meta name="viewport" content="width=device-width, initial-scale=1"><style>',
|
|
58
|
+
'body{margin:0;font-family:sans-serif}',
|
|
59
|
+
'.wide{width:600px;height:20px;background:#eee}',
|
|
60
|
+
'.tiny{font-size:10px}',
|
|
61
|
+
'.gap{height:40px}',
|
|
62
|
+
'</style></head><body>',
|
|
63
|
+
'<div class="block">上块</div>',
|
|
64
|
+
'<div class="wide"></div>',
|
|
65
|
+
'<button style="width:20px;height:20px">x</button>',
|
|
66
|
+
'<span class="tiny">小字</span>',
|
|
67
|
+
'<div class="gap"></div>',
|
|
68
|
+
'<div class="block">下块</div>',
|
|
69
|
+
'</body></html>',
|
|
70
|
+
].join('');
|
|
71
|
+
writeFileSync(file, html.replace('</body>', geometryAuditScript({ blankSelectors: ['.block'] }) + '</body>'), 'utf8');
|
|
72
|
+
const dom = execFileSync(chrome, ['--headless=new', '--disable-gpu', '--no-sandbox', '--hide-scrollbars', '--window-size=500,900', '--virtual-time-budget=1500', '--dump-dom', 'file://' + file], { encoding: 'utf8', timeout: 30000, maxBuffer: 20 * 1024 * 1024 });
|
|
73
|
+
const match = /<pre id="__tbox_audit">([\s\S]*?)<\/pre>/.exec(dom);
|
|
74
|
+
expect(match).toBeTruthy();
|
|
75
|
+
const geometry = JSON.parse(match[1].replaceAll('"', '"').replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>'));
|
|
76
|
+
expect(geometry.overflowX).toBeGreaterThan(0);
|
|
77
|
+
expect(geometry.overflowRight).toBeGreaterThan(0);
|
|
78
|
+
expect(geometry.minFontPx).toBe(10);
|
|
79
|
+
expect(geometry.smallTargets.length).toBeGreaterThan(0);
|
|
80
|
+
expect(geometry.blankGap.blocks).toBe(2);
|
|
81
|
+
expect(geometry.blankGap.maxGap).toBeGreaterThan(40);
|
|
82
|
+
expect(geometry.height).toBeGreaterThan(0);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('迁移一致性:模板实跑结果与迁移前逐项相同', () => {
|
|
86
|
+
const file = path.join(import.meta.dirname, '..', '..', '..', '.tbox/evidence/shell.json');
|
|
87
|
+
if (!existsSync(file)) return;
|
|
88
|
+
const result = JSON.parse(readFileSync(file, 'utf8'));
|
|
89
|
+
const blank = result.items.find((item) => item.id === 'shell.blank');
|
|
90
|
+
expect(blank.status === 'pass' || blank.status === 'fail').toBe(true);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 进程内体验检查执行器(checks.json 的 source=experience + phase=in-process)。
|
|
3
|
+
*
|
|
4
|
+
* 上下文由门禁提供(CSS 字节数、registry、渲染计数、对比度/密度函数),执行器只按 id 分发。
|
|
5
|
+
* 新增检查 = checks.json 一行 + IN_PROCESS_CHECKS 一段。
|
|
6
|
+
*/
|
|
7
|
+
export const IN_PROCESS_CHECKS = {
|
|
8
|
+
'shell.contrast': (ctx) => ctx.checkContrast(),
|
|
9
|
+
|
|
10
|
+
'css.sentinel': (ctx) => ({
|
|
11
|
+
status: ctx.cssBytes >= 20000 ? 'pass' : 'fail',
|
|
12
|
+
detail: ctx.cssBytes + ' 字节',
|
|
13
|
+
}),
|
|
14
|
+
|
|
15
|
+
'card.states': (ctx) => {
|
|
16
|
+
const cardCount = Object.keys(ctx.registryServer?.cards ?? {}).length;
|
|
17
|
+
return {
|
|
18
|
+
status: cardCount === 0 ? 'deferred' : ctx.historyRendered >= cardCount ? 'pass' : 'fail',
|
|
19
|
+
detail: cardCount === 0 ? '没有卡片' : '历史态 ' + ctx.historyRendered + '/' + cardCount,
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
'card.height': async (ctx) => {
|
|
24
|
+
const cardCount = Object.keys(ctx.registryServer?.cards ?? {}).length;
|
|
25
|
+
if (cardCount === 0) return { status: 'deferred', detail: '没有卡片' };
|
|
26
|
+
const density = await ctx.checkCardDensity();
|
|
27
|
+
if (!density.available) return { status: 'deferred', detail: '视图卡密度未检查:' + density.reason };
|
|
28
|
+
const viewCards = Object.values(ctx.registryServer?.cards ?? {}).filter((meta) => meta && meta.view).length;
|
|
29
|
+
if (viewCards === 0) return { status: 'pass', detail: '没有视图卡(三件套不估算)' };
|
|
30
|
+
if (density.worst > 506 && density.worst <= 633) {
|
|
31
|
+
ctx.warn('card-height-warn', '视图卡最高 ' + density.worst + 'px(超过一屏 60% 的 506px)', { fix: '优先减积木或拆卡;>633px 会阻断', recipe: 'card' });
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
status: density.violations.length > 0 ? 'fail' : 'pass',
|
|
35
|
+
detail: '最高 ' + density.worst + 'px' + (density.violations.length > 0 ? ';超限:' + density.violations.join('、') : ''),
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export async function runInProcessChecks(context, ids) {
|
|
41
|
+
const items = [];
|
|
42
|
+
for (const id of ids) {
|
|
43
|
+
const run = IN_PROCESS_CHECKS[id];
|
|
44
|
+
if (!run) {
|
|
45
|
+
items.push({ id, status: 'fail', detail: '进程内执行器没有实现(检查登记与 experience-checks.mjs 不一致)' });
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
items.push({ id, ...(await run(context)) });
|
|
49
|
+
}
|
|
50
|
+
return items;
|
|
51
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* card-registry.mjs — 证据面的卡片合并视图。
|
|
3
|
+
*
|
|
4
|
+
* 运行时装配顺序:`registerAppPrimitives` 先注册应用卡(`registry.cards`),随后
|
|
5
|
+
* `registerServerModules` 逐模块注册;`CardRegistry.register` 对重复 cardType **告警并覆盖**
|
|
6
|
+
* (后注册胜出)。证据面必须同序同语义,否则展示的组件/契约与线上不一致。
|
|
7
|
+
*
|
|
8
|
+
* 返回:
|
|
9
|
+
* - metas:cardType → 服务端 CardMeta(后者胜出)
|
|
10
|
+
* - components:cardType → 客户端组件(后者胜出)
|
|
11
|
+
* - provenance:cardType → { kind: 'app' } | { kind: 'module', moduleId }
|
|
12
|
+
* - warnings:重复/键不一致等装配歧义(不阻断,由调用方写入 warnings)
|
|
13
|
+
*/
|
|
14
|
+
export function collectCards({ server, client } = {}) {
|
|
15
|
+
const metas = {};
|
|
16
|
+
const components = {};
|
|
17
|
+
const provenance = {};
|
|
18
|
+
const warnings = [];
|
|
19
|
+
|
|
20
|
+
const warn = (id, message, detail = {}) => warnings.push({ id, message, ...detail });
|
|
21
|
+
|
|
22
|
+
const registerServer = (cards, source) => {
|
|
23
|
+
for (const [key, meta] of Object.entries(cards ?? {})) {
|
|
24
|
+
if (!meta) continue;
|
|
25
|
+
const cardType = typeof meta.cardType === 'string' && meta.cardType ? meta.cardType : key;
|
|
26
|
+
if (key !== cardType) {
|
|
27
|
+
warn('card-type-key-mismatch', `卡片注册键 "${key}" 与 meta.cardType "${cardType}" 不一致(按 cardType 注册)`, { cardType, source: source.kind, moduleId: source.moduleId });
|
|
28
|
+
}
|
|
29
|
+
const previous = provenance[cardType];
|
|
30
|
+
if (previous) {
|
|
31
|
+
warn('card-type-duplicate', `卡片类型 "${cardType}" 重复声明:${describe(previous)} → ${describe(source)}(后者胜出)`, {
|
|
32
|
+
cardType,
|
|
33
|
+
previous: describe(previous),
|
|
34
|
+
next: describe(source),
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
metas[cardType] = meta;
|
|
38
|
+
provenance[cardType] = source;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const registerClient = (cards, source) => {
|
|
43
|
+
for (const [key, component] of Object.entries(cards ?? {})) {
|
|
44
|
+
if (!component) continue;
|
|
45
|
+
const cardType = typeof component?.cardType === 'string' && component.cardType ? component.cardType : key;
|
|
46
|
+
if (components[cardType]) {
|
|
47
|
+
warn('card-client-duplicate', `客户端卡片 "${cardType}" 在 ${describe(source)} 重复注册(后者胜出)`, { cardType, source: source.kind, moduleId: source.moduleId });
|
|
48
|
+
}
|
|
49
|
+
components[cardType] = component;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
registerServer(server?.cards, { kind: 'app' });
|
|
54
|
+
registerClient(client?.cards, { kind: 'app' });
|
|
55
|
+
for (const module of server?.modules ?? []) {
|
|
56
|
+
registerServer(module?.cards, { kind: 'module', moduleId: module?.declaration?.moduleId ?? 'anonymous' });
|
|
57
|
+
}
|
|
58
|
+
for (const module of client?.modules ?? []) {
|
|
59
|
+
registerClient(module?.cards, { kind: 'module', moduleId: module?.declaration?.moduleId ?? 'anonymous' });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return { metas, components, provenance, warnings };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function describe(source) {
|
|
66
|
+
return source?.kind === 'module' ? `模块 ${source.moduleId ?? 'anonymous'}` : '应用';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 错误/修复文案里的来源提示(app 卡保持历史路径;模块卡指到模块目录)。 */
|
|
70
|
+
export function cardSourceHint(provenance, cardType) {
|
|
71
|
+
const source = provenance?.[cardType];
|
|
72
|
+
if (source?.kind === 'module') return `modules/${source.moduleId}/src/client/cards/${cardType}`;
|
|
73
|
+
return `apps/client/src/cards/${cardType}.card.tsx`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** 服务端卡片的来源提示(样例/schema 修复用)。 */
|
|
77
|
+
export function cardMetaSourceHint(provenance, cardType) {
|
|
78
|
+
const source = provenance?.[cardType];
|
|
79
|
+
if (source?.kind === 'module') return `modules/${source.moduleId}/src/server/cards/${cardType}/meta.ts`;
|
|
80
|
+
return `apps/server/src/cards/${cardType}.card.ts`;
|
|
81
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { collectCards } from './card-registry.mjs';
|
|
3
|
+
|
|
4
|
+
const meta = (cardType, extra = {}) => ({ cardType, dataSchema: { safeParse: () => ({ success: true }) }, ...extra });
|
|
5
|
+
|
|
6
|
+
describe('证据面卡片合并', () => {
|
|
7
|
+
it('app 卡先注册,模块卡后注册并胜出(与运行时覆盖语义一致)', () => {
|
|
8
|
+
const appMeta = meta('demo');
|
|
9
|
+
const moduleMeta = meta('demo', { displayName: '模块版' });
|
|
10
|
+
const view = collectCards({
|
|
11
|
+
server: { cards: { demo: appMeta }, modules: [{ declaration: { moduleId: 'm1' }, cards: { demo: moduleMeta } }] },
|
|
12
|
+
client: { cards: { demo: () => null }, modules: [{ cards: { demo: () => null } }] },
|
|
13
|
+
});
|
|
14
|
+
expect(view.metas.demo).toBe(moduleMeta);
|
|
15
|
+
expect(view.provenance.demo).toEqual({ kind: 'module', moduleId: 'm1' });
|
|
16
|
+
expect(view.warnings.map((item) => item.id)).toContain('card-type-duplicate');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('模块间重复同样后者胜出并告警', () => {
|
|
20
|
+
const first = meta('demo');
|
|
21
|
+
const second = meta('demo');
|
|
22
|
+
const view = collectCards({
|
|
23
|
+
server: { modules: [
|
|
24
|
+
{ declaration: { moduleId: 'a' }, cards: { demo: first } },
|
|
25
|
+
{ declaration: { moduleId: 'b' }, cards: { demo: second } },
|
|
26
|
+
] },
|
|
27
|
+
client: { modules: [] },
|
|
28
|
+
});
|
|
29
|
+
expect(view.metas.demo).toBe(second);
|
|
30
|
+
expect(view.provenance.demo).toEqual({ kind: 'module', moduleId: 'b' });
|
|
31
|
+
expect(view.warnings.some((item) => item.id === 'card-type-duplicate')).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('键与 meta.cardType 不一致时按 cardType 注册并告警', () => {
|
|
35
|
+
const view = collectCards({
|
|
36
|
+
server: { modules: [{ declaration: { moduleId: 'm' }, cards: { key: meta('actual') } }] },
|
|
37
|
+
client: {},
|
|
38
|
+
});
|
|
39
|
+
expect(view.metas.actual).toBeTruthy();
|
|
40
|
+
expect(view.warnings.map((item) => item.id)).toContain('card-type-key-mismatch');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('客户端组件重复注册同样告警(模块间/应用与模块)', () => {
|
|
44
|
+
const component = () => null;
|
|
45
|
+
const view = collectCards({
|
|
46
|
+
server: { cards: { demo: meta('demo') }, modules: [{ declaration: { moduleId: 'm' }, cards: { demo: meta('demo') } }] },
|
|
47
|
+
client: { cards: { demo: component }, modules: [{ declaration: { moduleId: 'm' }, cards: { demo: component } }] },
|
|
48
|
+
});
|
|
49
|
+
expect(view.warnings.map((item) => item.id)).toContain('card-client-duplicate');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('缺 declaration 的模块记为 anonymous,不阻断合并', () => {
|
|
53
|
+
const view = collectCards({
|
|
54
|
+
server: { modules: [{ cards: { demo: meta('demo') } }] },
|
|
55
|
+
client: { modules: [] },
|
|
56
|
+
});
|
|
57
|
+
expect(view.provenance.demo).toEqual({ kind: 'module', moduleId: 'anonymous' });
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* evidence-inputs.mjs — 故事板/门禁共用的证据输入清单。
|
|
3
|
+
*
|
|
4
|
+
* 单一真源:storyboard 的缓存键(内容哈希)与 check-evidence 的旧结果过期判定(newest mtime)
|
|
5
|
+
* 必须看同一批文件,否则"缓存键变了但旧图被判新鲜"或反之。
|
|
6
|
+
*
|
|
7
|
+
* 覆盖:应用卡片与壳源、品牌/主题接线、kit 源码、配置、模块卡片(含注册入口)、证据脚本自身。
|
|
8
|
+
*/
|
|
9
|
+
import { existsSync, readdirSync, statSync } from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
|
|
12
|
+
const FILE_EXTS = new Set(['.ts', '.tsx', '.js', '.mjs', '.cjs', '.css', '.json', '.jsonc', '.html']);
|
|
13
|
+
const MODULE_FILE_EXTS = new Set(['.ts', '.tsx', '.json']);
|
|
14
|
+
|
|
15
|
+
/** 应用内固定输入(相对 appDir)。 */
|
|
16
|
+
export const EVIDENCE_INPUT_PATHS = [
|
|
17
|
+
'apps/client/index.html',
|
|
18
|
+
'apps/client/package.json',
|
|
19
|
+
'apps/client/src',
|
|
20
|
+
'apps/client/scripts/lib',
|
|
21
|
+
'apps/client/scripts/render-card.mjs',
|
|
22
|
+
'apps/client/scripts/surface-css.mjs',
|
|
23
|
+
'apps/client/scripts/theme-kernel.mjs',
|
|
24
|
+
'apps/server/src/cards',
|
|
25
|
+
'packages/agent-ui-kit/package.json',
|
|
26
|
+
'packages/agent-ui-kit/src',
|
|
27
|
+
'config',
|
|
28
|
+
'scripts/checks.json',
|
|
29
|
+
'scripts/shell-probe.mjs',
|
|
30
|
+
'scripts/storyboard.mjs',
|
|
31
|
+
'scripts/lib',
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
/** 模块卡片相关输入:只看影响渲染/契约的文件,避免无关模块代码把缓存打穿。 */
|
|
35
|
+
export const MODULE_INPUT_PATHS = [
|
|
36
|
+
'tbox.module.json',
|
|
37
|
+
'src/server/cards',
|
|
38
|
+
'src/client/cards',
|
|
39
|
+
'src/client/index.ts',
|
|
40
|
+
'src/server/index.ts',
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
function walk(dir, out, exts) {
|
|
44
|
+
if (!existsSync(dir)) return;
|
|
45
|
+
for (const entry of readdirSync(dir, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name))) {
|
|
46
|
+
const full = path.join(dir, entry.name);
|
|
47
|
+
if (entry.isDirectory()) walk(full, out, exts);
|
|
48
|
+
else if (exts.has(path.extname(entry.name)) && !/\.(test|spec)\./.test(entry.name)) out.push(full);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {string} appDir 生成应用根
|
|
54
|
+
* @returns {string[]} 排序去重后的绝对文件路径(缺文件自动跳过)
|
|
55
|
+
*/
|
|
56
|
+
export function evidenceInputFiles(appDir) {
|
|
57
|
+
const files = [];
|
|
58
|
+
for (const rel of EVIDENCE_INPUT_PATHS) {
|
|
59
|
+
const full = path.join(appDir, rel);
|
|
60
|
+
if (!existsSync(full)) continue;
|
|
61
|
+
if (statSync(full).isDirectory()) walk(full, files, FILE_EXTS);
|
|
62
|
+
else files.push(full);
|
|
63
|
+
}
|
|
64
|
+
const modulesDir = path.join(appDir, 'modules');
|
|
65
|
+
if (existsSync(modulesDir)) {
|
|
66
|
+
for (const entry of readdirSync(modulesDir, { withFileTypes: true }).sort((left, right) => left.name.localeCompare(right.name))) {
|
|
67
|
+
if (!entry.isDirectory()) continue;
|
|
68
|
+
const moduleDir = path.join(modulesDir, entry.name);
|
|
69
|
+
for (const rel of MODULE_INPUT_PATHS) {
|
|
70
|
+
const full = path.join(moduleDir, rel);
|
|
71
|
+
if (!existsSync(full)) continue;
|
|
72
|
+
if (statSync(full).isDirectory()) walk(full, files, MODULE_FILE_EXTS);
|
|
73
|
+
else files.push(full);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return [...new Set(files)].sort();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** 清单里最新的 mtime(目录清单已展开为文件;缺文件返回 0)。 */
|
|
81
|
+
export function newestEvidenceMtime(appDir) {
|
|
82
|
+
let newest = 0;
|
|
83
|
+
for (const file of evidenceInputFiles(appDir)) {
|
|
84
|
+
try {
|
|
85
|
+
newest = Math.max(newest, statSync(file).mtimeMs);
|
|
86
|
+
} catch {
|
|
87
|
+
/* 竞态删除不影响其它文件 */
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return newest;
|
|
91
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { evidenceInputFiles } from './evidence-inputs.mjs';
|
|
4
|
+
|
|
5
|
+
const appDir = path.resolve(import.meta.dirname, '..', '..', '..', '..');
|
|
6
|
+
|
|
7
|
+
describe('证据输入清单', () => {
|
|
8
|
+
it('覆盖模块卡、kit、应用壳源与证据脚本自身', () => {
|
|
9
|
+
const files = evidenceInputFiles(appDir).map((file) => path.relative(appDir, file));
|
|
10
|
+
expect(files).toContain('scripts/checks.json');
|
|
11
|
+
expect(files).toContain('scripts/storyboard.mjs');
|
|
12
|
+
expect(files).toContain('apps/client/scripts/render-card.mjs');
|
|
13
|
+
expect(files).toContain('apps/client/src/styles/brand.css');
|
|
14
|
+
expect(files).toContain('packages/agent-ui-kit/src/index.ts');
|
|
15
|
+
// 几何/缓存代码自身也是输入:改内核必须让旧图失效(曾因 .mjs 不在扩展名白名单而漏掉)。
|
|
16
|
+
expect(files).toContain('scripts/lib/geometry-kernel.mjs');
|
|
17
|
+
expect(files).toContain('scripts/lib/chrome-pipe.mjs');
|
|
18
|
+
expect(files).toContain('apps/client/scripts/lib/card-registry.mjs');
|
|
19
|
+
expect(files.some((file) => /\.(test|spec)\./.test(file))).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('清单稳定排序且不重复', () => {
|
|
23
|
+
const files = evidenceInputFiles(appDir);
|
|
24
|
+
expect([...files].sort()).toEqual(files);
|
|
25
|
+
expect(new Set(files).size).toBe(files.length);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* static-render.mjs — React 静态渲染的窄噪声过滤。
|
|
3
|
+
*
|
|
4
|
+
* 客户端卡片(如 promotion 的 useLayoutEffect 滚动定位)在 SSR 下会打印
|
|
5
|
+
* "useLayoutEffect does nothing on the server"——这是预期形态,不是缺陷;但 154 份样例
|
|
6
|
+
* 会把门禁/deliver 的 stderr 淹没。这里只过滤这一条前缀,其余 console.error 原样透出,
|
|
7
|
+
* 并统计抑制条数供步骤摘要使用。
|
|
8
|
+
*/
|
|
9
|
+
const SSR_LAYOUT_EFFECT_WARNING = 'useLayoutEffect does nothing on the server';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {(node: unknown) => string} renderToStaticMarkup
|
|
13
|
+
* @returns {{ render: (node: unknown) => string, suppressed: () => number }}
|
|
14
|
+
*/
|
|
15
|
+
export function createStaticRenderer(renderToStaticMarkup) {
|
|
16
|
+
let suppressed = 0;
|
|
17
|
+
return {
|
|
18
|
+
render(node) {
|
|
19
|
+
const original = console.error;
|
|
20
|
+
console.error = (...args) => {
|
|
21
|
+
if (typeof args[0] === 'string' && args[0].includes(SSR_LAYOUT_EFFECT_WARNING)) {
|
|
22
|
+
suppressed += 1;
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
original(...args);
|
|
26
|
+
};
|
|
27
|
+
try {
|
|
28
|
+
return renderToStaticMarkup(node);
|
|
29
|
+
} finally {
|
|
30
|
+
console.error = original;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
suppressed: () => suppressed,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { createStaticRenderer } from './static-render.mjs';
|
|
3
|
+
|
|
4
|
+
describe('静态渲染噪声过滤', () => {
|
|
5
|
+
it('只吞 useLayoutEffect SSR 警告,其余 console.error 原样透出', () => {
|
|
6
|
+
const rest = vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
7
|
+
try {
|
|
8
|
+
const renderer = createStaticRenderer((node) => {
|
|
9
|
+
console.error('useLayoutEffect does nothing on the server, because its effect cannot be encoded');
|
|
10
|
+
console.error('真正的问题');
|
|
11
|
+
return String(node);
|
|
12
|
+
});
|
|
13
|
+
expect(renderer.render('card')).toBe('card');
|
|
14
|
+
expect(renderer.suppressed()).toBe(1);
|
|
15
|
+
expect(rest).toHaveBeenCalledTimes(1);
|
|
16
|
+
expect(rest).toHaveBeenCalledWith('真正的问题');
|
|
17
|
+
} finally {
|
|
18
|
+
rest.mockRestore();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 布局 / 运行时探针结果合并器(checks.json 的 source=experience + phase=probe)。
|
|
3
|
+
*
|
|
4
|
+
* 探针本身在 scripts/shell-probe.mjs;这里只按 checks.json 的 id 取结果、处理档位/过期/协议。
|
|
5
|
+
* 新增探针检查 = checks.json 一行 + PROBE_CHECKS 一段 + shell-probe 一条断言。
|
|
6
|
+
*/
|
|
7
|
+
export const PROBE_CHECKS = {
|
|
8
|
+
'shell.hit-target': { lane: 'layout', title: '命中区 ≥44×44' },
|
|
9
|
+
'shell.quick-visible': { lane: 'layout', title: '空态快捷问题可见' },
|
|
10
|
+
'shell.icon-render': { lane: 'layout', title: '快捷问题图标可见' },
|
|
11
|
+
'shell.controls-semantic': { lane: 'layout', title: '控件为语义按钮' },
|
|
12
|
+
'shell.control-present': { lane: 'layout', title: '能力开启时控件在场' },
|
|
13
|
+
'shell.a11y-name': { lane: 'layout', title: '控件有可访问名' },
|
|
14
|
+
'shell.blank': { lane: 'layout', title: '首屏块间空白 ≤35%' },
|
|
15
|
+
'shell.turn-visible': { lane: 'runtime', title: '新回合问题在视口内' },
|
|
16
|
+
'shell.console-clean': { lane: 'runtime', title: '控制台无告警' },
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 故事板检查(storyboard.json):帧级几何问题的聚合。
|
|
21
|
+
*
|
|
22
|
+
* 与探针的区别:探针的每条检查在浏览器里各自判定;故事板的判定在渲染时就写进帧的 problems,
|
|
23
|
+
* 这里只按 id 取第一条即可——判据留在内核一处,门禁不重算几何。
|
|
24
|
+
*/
|
|
25
|
+
export const STORYBOARD_CHECKS = {
|
|
26
|
+
'storyboard.render': { lane: 'layout', title: '故事板渲染完成' },
|
|
27
|
+
'card.overflow-x': { lane: 'layout', title: '卡片无横向溢出' },
|
|
28
|
+
'card.text-clip': { lane: 'layout', title: '文本截断带省略号' },
|
|
29
|
+
'card.tap-target': { lane: 'layout', title: '卡片点击区 ≥44px' },
|
|
30
|
+
'card.min-font': { lane: 'layout', title: '卡片最小字号 ≥12px' },
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export function mergeStoryboardChecks({ storyboard, ids, policy, stale = '', cardCount = 0 }) {
|
|
34
|
+
const frames = Array.isArray(storyboard?.frames) ? storyboard.frames : [];
|
|
35
|
+
const notRun = (meta, reason) => ({ status: 'deferred', detail: '未运行 ' + meta.title + ':' + reason });
|
|
36
|
+
return ids.map((id) => {
|
|
37
|
+
const meta = STORYBOARD_CHECKS[id] ?? { lane: 'layout', title: id };
|
|
38
|
+
if (policy === 'static') return { id, lane: meta.lane, ...notRun(meta, '档位 static 不要求布局车道') };
|
|
39
|
+
if (!storyboard) return { id, lane: meta.lane, ...notRun(meta, stale || 'pnpm storyboard 未产出结果') };
|
|
40
|
+
if (storyboard.status === 'not-run') return { id, lane: meta.lane, ...notRun(meta, storyboard.reason || 'storyboard 记 not-run') };
|
|
41
|
+
if (frames.length === 0) return { id, lane: meta.lane, ...notRun(meta, '没有生成任何帧') };
|
|
42
|
+
|
|
43
|
+
if (id === 'storyboard.render') {
|
|
44
|
+
const failed = frames.filter((frame) => frame.error);
|
|
45
|
+
if (failed.length > 0) {
|
|
46
|
+
return { id, lane: meta.lane, status: 'fail', detail: failed.length + '/' + frames.length + ' 帧未渲染:' + failed.slice(0, 2).map((frame) => frame.id + '(' + frame.error + ')').join(';') };
|
|
47
|
+
}
|
|
48
|
+
if (storyboard.status === 'partial') return { id, lane: meta.lane, status: 'fail', detail: '故事板未跑完:' + (storyboard.reason || '超过预算') };
|
|
49
|
+
const planned = Number(storyboard.planned ?? frames.length);
|
|
50
|
+
const scope = planned > frames.length ? frames.length + '/' + planned + ' 帧(预算/页数截断,已渲染帧全部通过)' : frames.length + ' 帧';
|
|
51
|
+
return { id, lane: meta.lane, status: 'pass', detail: scope + '(' + [...new Set(frames.map((frame) => frame.width))].sort((a, b) => a - b).join('/') + ' 宽)' };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const cardFrames = frames.filter((frame) => frame.source === 'card-samples');
|
|
55
|
+
if (id !== 'storyboard.render' && cardCount === 0) return { id, lane: meta.lane, ...notRun(meta, '应用没有卡片') };
|
|
56
|
+
const hits = [];
|
|
57
|
+
for (const frame of frames) {
|
|
58
|
+
for (const problem of frame.problems ?? []) if (problem.id === id) hits.push(problem.detail);
|
|
59
|
+
}
|
|
60
|
+
if (hits.length > 0) return { id, lane: meta.lane, status: 'fail', detail: hits.length + ' 处:' + hits.slice(0, 3).join(';') };
|
|
61
|
+
return { id, lane: meta.lane, status: 'pass', detail: (cardFrames.length > 0 ? cardFrames.length + ' 个卡片帧' : frames.length + ' 个壳帧') + '无问题' };
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function mergeProbeChecks({ probe, ids, policy, stale = '' }) {
|
|
66
|
+
const skipped = String(stale).includes('协议版本');
|
|
67
|
+
return ids.map((id) => {
|
|
68
|
+
const meta = PROBE_CHECKS[id] ?? { lane: 'layout', title: id };
|
|
69
|
+
if (policy === 'static') {
|
|
70
|
+
return { id, lane: meta.lane, status: 'deferred', detail: '未运行 ' + meta.title + ':档位 static 不要求布局/运行时' };
|
|
71
|
+
}
|
|
72
|
+
const found = Array.isArray(probe?.items) ? probe.items.find((item) => item.id === id) : undefined;
|
|
73
|
+
if (found) {
|
|
74
|
+
return { id, lane: found.lane ?? meta.lane, status: found.status === 'not-run' ? 'deferred' : found.status, detail: found.detail };
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
id,
|
|
78
|
+
lane: meta.lane,
|
|
79
|
+
status: skipped ? 'skip' : 'deferred',
|
|
80
|
+
detail: skipped
|
|
81
|
+
? meta.title + ':' + stale
|
|
82
|
+
: (stale ? '未运行 ' + meta.title + ':' + stale : '未运行 ' + meta.title + ':pnpm probe:shell 未产出结果'),
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
}
|