@tbox.cn/app-template-agent 1.0.0-alpha.7 → 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 +11 -8
- package/apps/client/index.html +0 -43
- package/apps/client/package.json +1 -0
- package/apps/client/scripts/acceptance-changes.test.mjs +97 -0
- package/apps/client/scripts/check-evidence.mjs +625 -108
- 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 +337 -0
- package/apps/client/scripts/evidence-gate.test.mjs +135 -0
- 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 +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 +95 -126
- 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 +54 -0
- package/apps/client/scripts/theme-kernel.mjs +236 -0
- package/apps/client/scripts/theme-kernel.test.mjs +136 -0
- package/apps/client/src/app.config.ts +4 -1
- package/apps/client/src/styles/brand.css +13 -14
- package/apps/client/src/styles/tailwind.css +20 -21
- package/apps/client/vite.config.ts +2 -1
- package/apps/server/scripts/probe.mjs +6 -1
- package/apps/server/scripts/scenario-lib.mjs +56 -8
- package/apps/server/scripts/scenario.mjs +41 -7
- package/config/AGENTS.md +1 -0
- package/config/chat.json +21 -9
- package/docs/agent/agent-prompt.md +1 -1
- package/docs/agent/card-action.md +5 -0
- package/docs/agent/card.md +45 -2
- package/docs/agent/kit.md +3 -3
- package/docs/agent/shell.md +1 -0
- package/docs/agent/style.md +11 -3
- package/docs/agent/tool-emits-card.md +7 -2
- package/docs/agent/tool.md +2 -0
- package/docs/agent/verify.md +59 -16
- package/package.json +21 -7
- package/packages/agent-ui-kit/AGENTS.md +1 -1
- package/packages/agent-ui-kit/README.md +21 -1
- package/packages/agent-ui-kit/catalog.json +8 -4
- package/packages/agent-ui-kit/package.json +9 -1
- package/packages/agent-ui-kit/src/._surface.tsx +0 -0
- package/packages/agent-ui-kit/src/ChatPage.tsx +70 -17
- package/packages/agent-ui-kit/src/card/._action-list-pending.test.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._define-card.test.ts +0 -0
- package/packages/agent-ui-kit/src/card/._view-card-inline.test.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._view-card.test.tsx +0 -0
- package/packages/agent-ui-kit/src/card/._view-card.tsx +0 -0
- package/packages/agent-ui-kit/src/card/action-list-pending.test.tsx +91 -0
- package/packages/agent-ui-kit/src/card/define-card.test.ts +25 -0
- package/packages/agent-ui-kit/src/card/define-card.ts +18 -5
- package/packages/agent-ui-kit/src/card/primitives.test.tsx +10 -0
- package/packages/agent-ui-kit/src/card/primitives.tsx +136 -37
- package/packages/agent-ui-kit/src/card/view-card-inline.test.tsx +42 -0
- package/packages/agent-ui-kit/src/card/view-card.test.tsx +79 -0
- package/packages/agent-ui-kit/src/card/view-card.tsx +250 -0
- 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 +22 -17
- package/packages/agent-ui-kit/src/components/HistoryEntry/index.tsx +3 -2
- package/packages/agent-ui-kit/src/components/MessageBubble/index.tsx +11 -5
- package/packages/agent-ui-kit/src/components/QuickCommands/index.test.tsx +3 -1
- package/packages/agent-ui-kit/src/components/QuickCommands/index.tsx +31 -8
- 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 +8 -0
- package/packages/agent-ui-kit/src/preview-provider.tsx +47 -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/surface.test.tsx +35 -0
- package/packages/agent-ui-kit/src/surface.tsx +44 -0
- package/packages/agent-ui-kit/src/theme/base.css +9 -11
- package/packages/agent-ui-kit/src/theme/contract.json +123 -2
- package/packages/agent-ui-kit/src/theme/theme-contract.test.ts +16 -0
- package/packages/agent-ui-kit/src/theme/tokens.css +9 -12
- 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/._assert-pack.mjs +0 -0
- package/scripts/._deliver.mjs +0 -0
- package/scripts/._shell-probe.mjs +0 -0
- package/scripts/._storyboard.mjs +0 -0
- package/scripts/assert-pack.mjs +48 -0
- package/scripts/check-css-target.mjs +6 -3
- package/scripts/check-fast.mjs +1 -0
- package/scripts/checks.json +400 -26
- 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/.tbox/card-render/baseline/demo.png +0 -0
- package/.tbox/card-render/demo.html +0 -342
- package/.tbox/card-render/demo.png +0 -0
- package/.tbox/card-render/scale-demo.audit.html +0 -984
- package/.tbox/card-render/scale-demo.html +0 -939
- package/.tbox/evidence/cards.txt +0 -1
- package/.tbox/evidence/gate.json +0 -1
- package/.tbox/evidence/last-gate.json +0 -1
- package/.tbox/evidence/scenarios.json +0 -1
- package/apps/client/.tbox-gen/app-registry.ts +0 -3
- package/apps/client/.tbox-gen/documents/_tbox/card-preview.html +0 -62
- package/apps/client/.tbox-gen/documents/index.html +0 -63
- package/apps/client/.tbox-gen/entries/card-preview.tsx +0 -6
- package/apps/client/.tbox-gen/entries/index.tsx +0 -11
- package/apps/client/.tbox-gen/manifest.json +0 -17
- package/apps/client/.tbox-gen/registry.client.ts +0 -6
- package/apps/client/.tbox-gen/registry.server.ts +0 -15
- package/apps/client/STYLE_GUIDE.md +0 -48
- package/apps/client/VISUAL_RESTORE.md +0 -90
- package/profiles/mall/config/llm_provider.json +0 -5
- package/profiles/mall/config/plugins.json +0 -3
- package/scripts/compat-probe.mjs +0 -108
- package/scripts/gen-tailwind-sources.mjs +0 -55
- /package/.tbox/{card-render/._demo.html → factory/._chat.json} +0 -0
- /package/{.tbox/card-render/._demo.png → apps/client/scripts/._acceptance-changes.test.mjs} +0 -0
- /package/{.tbox/card-render/._scale-demo.audit.html → apps/client/scripts/._color-scan.mjs} +0 -0
- /package/{.tbox/card-render/._scale-demo.html → apps/client/scripts/._color-scan.test.mjs} +0 -0
- /package/{.tbox/card-render/baseline/._demo.png → apps/client/scripts/._evidence-gate.mjs} +0 -0
- /package/{.tbox/evidence/._cards.txt → apps/client/scripts/._evidence-gate.test.mjs} +0 -0
- /package/{.tbox/evidence/._gate.json → apps/client/scripts/._experience-checks.mjs} +0 -0
- /package/{.tbox/evidence/._last-gate.json → apps/client/scripts/._geometry-kernel.test.mjs} +0 -0
- /package/{.tbox/evidence/._scenarios.json → apps/client/scripts/._in-process-checks.mjs} +0 -0
- /package/apps/client/{._STYLE_GUIDE.md → scripts/._probe-checks.mjs} +0 -0
- /package/apps/client/{._VISUAL_RESTORE.md → scripts/._sample-entries.test.mjs} +0 -0
- /package/apps/client/{.tbox-gen/._app-registry.ts → scripts/._storyboard.test.mjs} +0 -0
- /package/apps/client/{.tbox-gen/._manifest.json → scripts/._surface-css.mjs} +0 -0
- /package/apps/client/{.tbox-gen/._registry.client.ts → scripts/._theme-kernel.mjs} +0 -0
- /package/apps/client/{.tbox-gen/._registry.server.ts → scripts/._theme-kernel.test.mjs} +0 -0
- /package/apps/client/{.tbox-gen/documents/._index.html → scripts/lib/._card-registry.mjs} +0 -0
- /package/apps/client/{.tbox-gen/documents/_tbox/._card-preview.html → scripts/lib/._card-registry.test.mjs} +0 -0
- /package/apps/client/{.tbox-gen/entries/._card-preview.tsx → scripts/lib/._evidence-inputs.mjs} +0 -0
- /package/apps/client/{.tbox-gen/entries/._index.tsx → scripts/lib/._evidence-inputs.test.mjs} +0 -0
- /package/{profiles/mall/config/._llm_provider.json → apps/client/scripts/lib/._static-render.mjs} +0 -0
- /package/{profiles/mall/config/._plugins.json → apps/client/scripts/lib/._static-render.test.mjs} +0 -0
- /package/{scripts/._compat-probe.mjs → packages/agent-ui-kit/src/._preview-provider.tsx} +0 -0
- /package/{scripts/._gen-tailwind-sources.mjs → packages/agent-ui-kit/src/._surface.test.tsx} +0 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 静态体验检查执行器(checks.json 的 source=experience + phase=static)。
|
|
3
|
+
*
|
|
4
|
+
* 新增检查 = checks.json 一行 + STATIC_CHECKS 一段;门禁主流程不再改。
|
|
5
|
+
* 每条返回 { status, detail },lane 由 checks.json 决定。
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, readFileSync, readdirSync } from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { scanColorLiterals } from './color-scan.mjs';
|
|
10
|
+
import { nearestToken, readTokens } from './theme-kernel.mjs';
|
|
11
|
+
|
|
12
|
+
export const STATIC_CHECKS = {
|
|
13
|
+
'boot.inline-script': ({ clientDir }) => {
|
|
14
|
+
try {
|
|
15
|
+
const html = readFileSync(path.join(clientDir, 'index.html'), 'utf8');
|
|
16
|
+
const inline = [...html.matchAll(/<script\b([^>]*)>/gi)].filter((match) => !/\bsrc\s*=/.test(match[1]));
|
|
17
|
+
return { status: inline.length === 0 ? 'pass' : 'fail', detail: inline.length === 0 ? '入口零内联脚本' : '入口有 ' + inline.length + ' 段内联脚本' };
|
|
18
|
+
} catch (error) {
|
|
19
|
+
return { status: 'fail', detail: '读不到 apps/client/index.html:' + (error?.message ?? error) };
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
'shell.identity': ({ appDir }) => {
|
|
24
|
+
try {
|
|
25
|
+
const source = readFileSync(path.join(appDir, 'packages/agent-ui-kit/src/components/MessageBubble/index.tsx'), 'utf8');
|
|
26
|
+
return { status: source.includes('identity?.name') ? 'pass' : 'fail', detail: '发送者名取 identity.name' };
|
|
27
|
+
} catch (error) {
|
|
28
|
+
return { status: 'deferred', detail: 'kit 副本不在预期位置:' + (error?.message ?? error) };
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
'quick.label-query': ({ appDir }) => {
|
|
33
|
+
try {
|
|
34
|
+
const chat = JSON.parse(readFileSync(path.join(appDir, 'config/chat.json'), 'utf8'));
|
|
35
|
+
const bad = (Array.isArray(chat.quickCommands) ? chat.quickCommands : []).filter((command) =>
|
|
36
|
+
command && command.label && command.query && command.query !== command.label && !String(command.query).includes(command.label));
|
|
37
|
+
return {
|
|
38
|
+
status: bad.length > 0 ? 'fail' : 'pass',
|
|
39
|
+
detail: bad.length > 0 ? '文案不一致:' + bad.map((command) => command.label + '→' + command.query).join('、') : '快捷问题文案一致',
|
|
40
|
+
};
|
|
41
|
+
} catch {
|
|
42
|
+
return { status: 'deferred', detail: '读不到 config/chat.json' };
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
'meta.brand': ({ appDir }) => {
|
|
47
|
+
try {
|
|
48
|
+
const chatPage = readFileSync(path.join(appDir, 'packages/agent-ui-kit/src/ChatPage.tsx'), 'utf8');
|
|
49
|
+
const ok = chatPage.includes('document.title') && chatPage.includes('theme-color');
|
|
50
|
+
return { status: ok ? 'pass' : 'fail', detail: ok ? '标题与主题色跟身份注入' : 'kit 未注入标题/主题色' };
|
|
51
|
+
} catch {
|
|
52
|
+
return { status: 'deferred', detail: 'kit 副本不在预期位置' };
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
'style.url-quoted': ({ appDir }) => {
|
|
57
|
+
try {
|
|
58
|
+
const files = ['components/QuickCommands/index.tsx', 'components/ChatInput/index.tsx'];
|
|
59
|
+
const offenders = files.filter((file) => {
|
|
60
|
+
const full = path.join(appDir, 'packages/agent-ui-kit/src', file);
|
|
61
|
+
if (!existsSync(full)) return false;
|
|
62
|
+
return /url\(\$\{/.test(readFileSync(full, 'utf8'));
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
status: offenders.length > 0 ? 'fail' : 'pass',
|
|
66
|
+
detail: offenders.length > 0 ? '未加引号的 url():' + offenders.join('、') : 'url() 均已加引号',
|
|
67
|
+
};
|
|
68
|
+
} catch {
|
|
69
|
+
return { status: 'deferred', detail: 'kit 源码不可读' };
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
'kit.color-literal': ({ appDir }) => {
|
|
74
|
+
try {
|
|
75
|
+
const cardDir = path.join(appDir, 'packages/agent-ui-kit/src/card');
|
|
76
|
+
const sources = ['primitives.tsx', 'view-card.tsx']
|
|
77
|
+
.filter((file) => existsSync(path.join(cardDir, file)))
|
|
78
|
+
.map((file) => readFileSync(path.join(cardDir, file), 'utf8'))
|
|
79
|
+
.join('\n');
|
|
80
|
+
const literals = sources.match(/#[0-9a-fA-F]{3,8}\b|rgba?\(/g) ?? [];
|
|
81
|
+
return {
|
|
82
|
+
status: literals.length > 0 ? 'fail' : 'pass',
|
|
83
|
+
detail: literals.length > 0 ? '卡片基元里有 ' + literals.length + ' 处非令牌色值' : '卡片基元零色值字面量',
|
|
84
|
+
};
|
|
85
|
+
} catch {
|
|
86
|
+
return { status: 'deferred', detail: 'kit 卡片源码不可读' };
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
// 同一色值三处以上就该进契约(style.md 的规则由检查兜住);只提示不阻断。
|
|
91
|
+
'style.color-repeat': ({ appDir }) => {
|
|
92
|
+
try {
|
|
93
|
+
const files = [];
|
|
94
|
+
// styles/ 是令牌的家(brand.css 与 tailwind.css 的 var(..., 兜底) 映射):那里不是「写死的色值」。
|
|
95
|
+
const stylesDir = path.join(appDir, 'apps/client/src/styles');
|
|
96
|
+
for (const dir of ['apps/client/src', 'apps/server/src/cards']) {
|
|
97
|
+
const root = path.join(appDir, dir);
|
|
98
|
+
if (!existsSync(root)) continue;
|
|
99
|
+
const walk = (current) => {
|
|
100
|
+
for (const entry of readdirSync(current, { withFileTypes: true })) {
|
|
101
|
+
const full = path.join(current, entry.name);
|
|
102
|
+
if (entry.isDirectory()) walk(full);
|
|
103
|
+
else if (/\.(tsx?|css)$/.test(entry.name) && !full.startsWith(stylesDir)) files.push(full);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
walk(root);
|
|
107
|
+
}
|
|
108
|
+
const tokens = readTokens([
|
|
109
|
+
path.join(appDir, 'packages/agent-ui-kit/src/theme/tokens.css'),
|
|
110
|
+
path.join(appDir, 'apps/client/src/styles/brand.css'),
|
|
111
|
+
].filter((file) => existsSync(file)));
|
|
112
|
+
const groups = [...scanColorLiterals(files).entries()].filter(([, value]) => value.count >= 3).sort((left, right) => right[1].count - left[1].count);
|
|
113
|
+
if (groups.length === 0) return { status: 'pass', detail: '没有重复 3 次以上的色值字面量' };
|
|
114
|
+
const detail = groups.slice(0, 5).map(([hex, value]) => {
|
|
115
|
+
const near = nearestToken(hex, tokens);
|
|
116
|
+
return hex + ' ×' + value.count + (near ? ' → 最近令牌 ' + near.token + '(ΔE ' + near.delta + ')' : '');
|
|
117
|
+
}).join(';');
|
|
118
|
+
return { status: 'fail', detail: groups.length + ' 组重复色值:' + detail };
|
|
119
|
+
} catch (error) {
|
|
120
|
+
return { status: 'deferred', detail: '色值扫描不可用:' + (error instanceof Error ? error.message : String(error)) };
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
'card.action-primary': ({ appDir }) => {
|
|
125
|
+
try {
|
|
126
|
+
const viewCard = readFileSync(path.join(appDir, 'packages/agent-ui-kit/src/card/view-card.tsx'), 'utf8');
|
|
127
|
+
const ok = viewCard.includes('index === 0') && viewCard.includes("'primary'") && viewCard.includes("'secondary'");
|
|
128
|
+
return { status: ok ? 'pass' : 'fail', detail: ok ? '首个动作为主按钮' : '视图卡未按序分主次' };
|
|
129
|
+
} catch {
|
|
130
|
+
return { status: 'deferred', detail: '视图卡源码不可读' };
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
'shell.type-scale': ({ appDir, clientDir }) => {
|
|
135
|
+
const offScale = [];
|
|
136
|
+
for (const root of [path.join(clientDir, 'src'), path.join(appDir, 'packages/agent-ui-kit/src')]) {
|
|
137
|
+
if (!existsSync(root)) continue;
|
|
138
|
+
const walk = (dir) => {
|
|
139
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
140
|
+
const full = path.join(dir, entry.name);
|
|
141
|
+
if (entry.isDirectory()) walk(full);
|
|
142
|
+
else if (/\.(tsx?|css)$/.test(entry.name) && !entry.name.endsWith('.test.tsx')) {
|
|
143
|
+
if (/text-\[\d+(?:\.\d+)?px\]/.test(readFileSync(full, 'utf8'))) offScale.push(path.relative(appDir, full));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
walk(root);
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
status: offScale.length === 0 ? 'pass' : 'fail',
|
|
151
|
+
detail: offScale.length === 0 ? '档外字号 0 处' : '档外字号:' + offScale.slice(0, 5).join('、'),
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/** 按 checks.json 的 phase=static 顺序执行;未知 id 明确失败,避免「登记了但静默没跑」。 */
|
|
157
|
+
export function runStaticChecks(context, ids) {
|
|
158
|
+
return ids.map((id) => {
|
|
159
|
+
const run = STATIC_CHECKS[id];
|
|
160
|
+
if (!run) return { id, status: 'fail', detail: '静态执行器没有实现(检查登记与 experience-checks.mjs 不一致)' };
|
|
161
|
+
return { id, ...run(context) };
|
|
162
|
+
});
|
|
163
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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
|
+
});
|