@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
package/.gitignore
CHANGED
package/.tbox/app.json
CHANGED
package/AGENTS.md
CHANGED
|
@@ -4,13 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
## 第一原则
|
|
6
6
|
|
|
7
|
-
- **能力建在平台上**:对话能力 = `apps/server/src/tools/*.tool.ts` 的工具 +
|
|
7
|
+
- **能力建在平台上**:对话能力 = `apps/server/src/tools/*.tool.ts` 的工具 + 卡片(默认视图卡),首页用 `ChatPage` 渲染。不要用前端规则引擎、自写聊天组件或本地意图匹配替代平台引擎——那样对话不经过模型,卡片与状态也不再可用。
|
|
8
8
|
- **模型由平台托管**:需求里的「不需要 API Key」指不用自配密钥,不等于不用模型。
|
|
9
9
|
- **不读 `node_modules`**:API 形状查 `docs/agent/` 或 `pnpm exec tbox-app api <符号>`,约定查 `docs/agent/`。读构建产物反推是最慢的路径。
|
|
10
|
-
-
|
|
10
|
+
- 先跑通一片再铺开:验收项 → 领域与状态 → 第一项能力整条竖切(卡片 + 工具 + 动作 + 一条场景)→ `pnpm check:fast` → 其余能力成批写。每步都有固定成本(首 token 等待),一次只写一个文件是最贵的写法;但把全部写完才首验更贵——首验越晚,返工越大。开发期不跑 `pnpm build`。
|
|
11
|
+
- 卡片默认写视图卡:`defineViewCard` + `view(data)`,一张卡只有服务端一个文件(客户端由 app-build 派生);只有需要局部自定义图形或富交互时才写 `defineCard` + tsx 三件套。
|
|
11
12
|
- **动手前先跑一次 `pnpm exec tbox-app brief`**:应用现状、核心 API 签名、基元、壳契约、样式变量、命令、配方索引都在里面。
|
|
12
13
|
- **不读源码**:`packages/agent-ui-kit/src`、`apps/server/src/app.ts`、`README.md`、`.tbox-gen`、`tgz` 都不必读——装配由平台生成,写法以简报与配方为准。
|
|
13
|
-
- **交付纪律**:实现前先把需求拆成 `scenarios/acceptance.jsonc`
|
|
14
|
+
- **交付纪律**:实现前先把需求拆成 `scenarios/acceptance.jsonc` 的验收项;开发期用 `pnpm check:fast`,交付时用 `pnpm deliver`(裁决 + 摘要 + DELIVERY.md)。`verdict: "deliverable"` 即交付,交付后不再逐行复审;`reopened` 表示交付后内容又变了,重跑确认再交付。摘要里的 `handoff`、`notRun` 与 `delivery.deferred` 是当前策略验不了的项——原样写进交付说明,不要用读代码代替验证。
|
|
14
15
|
- 用户说「不要测试」「快速交付」指不起 dev server、不开浏览器、不写测试文件;`check:fast` 属于构建,照常运行。
|
|
15
16
|
|
|
16
17
|
## 我要做什么
|
|
@@ -20,8 +21,8 @@
|
|
|
20
21
|
|---|---|---|
|
|
21
22
|
| 快速了解现状与写法 | — | `pnpm exec tbox-app brief` |
|
|
22
23
|
| 试跑一条链路:看逐步出参、出卡与状态差异;可存成场景 | [verify](docs/agent/verify.md) | `pnpm exec tbox-app probe "<步骤>"` |
|
|
23
|
-
|
|
|
24
|
-
|
|
|
24
|
+
| 新增一项对话能力(视图卡竖切) | [tool](docs/agent/tool.md) | `pnpm exec tbox-app new feature <name> --view` |
|
|
25
|
+
| 写一张卡片(默认视图卡) | [card](docs/agent/card.md) | `pnpm exec tbox-app new card <name> --view` |
|
|
25
26
|
| 让工具结果以卡片展示 | [tool-emits-card](docs/agent/tool-emits-card.md) | — |
|
|
26
27
|
| 卡片上的写操作按钮(确定性执行) | [card-action](docs/agent/card-action.md) | `pnpm exec tbox-app new action <name>` |
|
|
27
28
|
| 用户身份与状态 | [state](docs/agent/state.md) | `pnpm exec tbox-app new feature <name> --state` |
|
|
@@ -56,7 +57,7 @@
|
|
|
56
57
|
- 页面:`apps/client/src/pages/page.tsx`,inline `export const page`;入口脚本由 app-build 生成。
|
|
57
58
|
- 默认不要创建 `apps/client/src/entry.tsx`;只有需要完全自定义路由/注册时才用它全量接管(高级逃生舱)。
|
|
58
59
|
- 函数:`apps/server/src/functions/*.server.ts`,文件名即 `/api/fn/<id>`。
|
|
59
|
-
- 工具/技能/卡片/动作:`apps/server/src/tools/*.tool.ts`、`skills/*.skill.ts`、`cards/*.card.ts`、`actions/*.action.ts
|
|
60
|
+
- 工具/技能/卡片/动作:`apps/server/src/tools/*.tool.ts`、`skills/*.skill.ts`、`cards/*.card.ts`、`actions/*.action.ts`;卡片默认视图卡(服务端单文件,客户端由 app-build 派生),三件套才需要成对的 `apps/client/src/cards/*.card.tsx`。
|
|
60
61
|
- 模块:`modules/<id>/src/server/index.ts` 导出 `serverModule`,`src/client/index.ts` 导出 `clientModule`;只注册,不在顶层解析服务。
|
|
61
62
|
- 双端 registry、manifest 与 entry 由 `pnpm generate` 生成;`.tbox-gen` 是 IR,不要手写/不要 import。
|
|
62
63
|
- 生产只启动 `apps/server/dist/index.js`;静态根是 `apps/client/dist`。
|
|
@@ -70,7 +71,7 @@ export const orderStatusCardSchema = z.object({ title: z.string() });
|
|
|
70
71
|
export type OrderStatusCardData = z.infer<typeof orderStatusCardSchema>;
|
|
71
72
|
```
|
|
72
73
|
|
|
73
|
-
服务端卡片 meta 从 `@app/shared/cards/<id>` 引用同一份 schema;客户端只 `import type`(eslint 拦截值导入,zod
|
|
74
|
+
服务端卡片 meta 从 `@app/shared/cards/<id>` 引用同一份 schema;客户端只 `import type`(eslint 拦截值导入,zod 不进客户端产物)。样例由 `sampleState` / `samples` 派生(三件套写在声明里)——`card render` 与场景断言读派生结果。不 import React、Node、`apps/*`、`modules/*`、数据库或网络;不要创建 `apps/shared/`。
|
|
74
75
|
|
|
75
76
|
## 模块
|
|
76
77
|
|
|
@@ -90,6 +91,8 @@ export const clientModule = { cards: {}, register(ctx) {} } satisfies ClientModu
|
|
|
90
91
|
|
|
91
92
|
```sh
|
|
92
93
|
pnpm check:fast # 生成 → 类型 → lint 修复 → 结构 → 证据包(样式/原语/真渲染/场景;开发期主力,秒级)
|
|
94
|
+
pnpm probe:shell # 壳体验探针(390 宽空态;无 Chrome 记 not-run)
|
|
95
|
+
pnpm deliver # 交付:裁决 + 摘要 + DELIVERY.md(交付唯一入口)
|
|
93
96
|
pnpm scenario # 跑 scenarios/*.json(进程内,零端口零模型)
|
|
94
97
|
pnpm generate # 生成 manifest/registry/entries
|
|
95
98
|
pnpm typecheck
|
|
@@ -97,7 +100,7 @@ pnpm test
|
|
|
97
100
|
pnpm lint
|
|
98
101
|
pnpm check # 结构、workspace、inspector
|
|
99
102
|
pnpm smoke
|
|
100
|
-
pnpm verify #
|
|
103
|
+
pnpm verify # 发布前全量(人/CI):typecheck + test + lint + build + smoke + generated
|
|
101
104
|
pnpm dev # 单端口 8000(Vite + server)
|
|
102
105
|
```
|
|
103
106
|
|
package/apps/client/index.html
CHANGED
|
@@ -8,53 +8,10 @@
|
|
|
8
8
|
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
|
|
9
9
|
/>
|
|
10
10
|
<meta name="theme-color" content="#fbfcfe" />
|
|
11
|
-
<!-- 兼容探测(S0b):入口同步判定内核档位,写 window.__tboxCompat 并广播 tbox:compat;
|
|
12
|
-
非 v4 原生档显示升级提示,避免无样式页面静默降级。 -->
|
|
13
|
-
<script>
|
|
14
|
-
(function () {
|
|
15
|
-
var el = document.documentElement;
|
|
16
|
-
function supports(prop, value) {
|
|
17
|
-
try { return CSS.supports(prop, value); } catch (e) { return false; }
|
|
18
|
-
}
|
|
19
|
-
function rule(css) {
|
|
20
|
-
try {
|
|
21
|
-
var style = document.createElement('style');
|
|
22
|
-
style.textContent = css;
|
|
23
|
-
document.head.appendChild(style);
|
|
24
|
-
var kept = !!(style.sheet && style.sheet.cssRules && style.sheet.cssRules.length);
|
|
25
|
-
document.head.removeChild(style);
|
|
26
|
-
return kept;
|
|
27
|
-
} catch (e) { return false; }
|
|
28
|
-
}
|
|
29
|
-
var result = {
|
|
30
|
-
ua: navigator.userAgent,
|
|
31
|
-
layers: rule('@layer a { --tbox-probe: 1 }'),
|
|
32
|
-
transform: supports('translate', '0 1px'),
|
|
33
|
-
logical: supports('padding-inline', '1px'),
|
|
34
|
-
where: supports('selector(:where(a))'),
|
|
35
|
-
};
|
|
36
|
-
result.engine = !result.layers ? 'v3.4' : (!result.transform || !result.where ? 'v4-flat' : 'v4');
|
|
37
|
-
window.__tboxCompat = result;
|
|
38
|
-
el.setAttribute('data-tbox-compat', result.engine);
|
|
39
|
-
try {
|
|
40
|
-
window.dispatchEvent(new CustomEvent('tbox:compat', { detail: result }));
|
|
41
|
-
} catch (e) {}
|
|
42
|
-
if (result.engine !== 'v4') {
|
|
43
|
-
var notice = document.createElement('div');
|
|
44
|
-
notice.id = 'tbox-compat-notice';
|
|
45
|
-
notice.setAttribute('role', 'status');
|
|
46
|
-
notice.textContent = '当前支付宝版本较旧,部分样式可能显示异常,建议升级支付宝或系统。';
|
|
47
|
-
notice.style.cssText = 'position:fixed;left:8px;right:8px;bottom:8px;z-index:9999;padding:8px 12px;border-radius:8px;background:#fff7e6;color:#8a5a00;font:12px/1.5 -apple-system,sans-serif;box-shadow:0 2px 8px rgba(0,0,0,.12);';
|
|
48
|
-
document.body.appendChild(notice);
|
|
49
|
-
console.info('[tbox-compat]', result);
|
|
50
|
-
}
|
|
51
|
-
})();
|
|
52
|
-
</script>
|
|
53
11
|
<!-- 出厂标题 = 此处静态值(theme-tbox brand.js 出厂不覆写标题);租户主题经其 brand.js 运行时覆写 document.title -->
|
|
54
12
|
<title>AI 助手</title>
|
|
55
13
|
<!-- 平台微调(inspector) runtime:由 server 提供 GET /__vs_inspector__.js;dev 下经 Vite 代理到 server。-->
|
|
56
14
|
<script src="/__vs_inspector__.js" defer></script>
|
|
57
|
-
|
|
58
15
|
</head>
|
|
59
16
|
<body>
|
|
60
17
|
<div id="root"></div>
|
package/apps/client/package.json
CHANGED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { acceptanceChangesOf, defaultModuleDrift, matchFrame, summarizeAcceptanceChanges } from './evidence-gate.mjs';
|
|
3
|
+
|
|
4
|
+
const digest = (entries) => Object.fromEntries(entries.map(([id, text, handoff, coveredBy]) => [id, { text, handoff, coveredBy }]));
|
|
5
|
+
|
|
6
|
+
describe('验收变更(D4)', () => {
|
|
7
|
+
it('首轮没有基线 → 不报变更', () => {
|
|
8
|
+
const result = acceptanceChangesOf(undefined, digest([['a', 'h1', false, ['s1']]]));
|
|
9
|
+
expect(result.changes).toEqual([]);
|
|
10
|
+
expect(result.cumulative).toEqual([]);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('六类变更各按语义分类,弱化标记正确', () => {
|
|
14
|
+
const prev = { acceptanceDigest: digest([
|
|
15
|
+
['keep', 'h1', false, ['s1']],
|
|
16
|
+
['shrink', 'h2', false, ['s1', 's2']],
|
|
17
|
+
['reword', 'h3', false, []],
|
|
18
|
+
['handoff', 'h4', false, []],
|
|
19
|
+
['gone', 'h5', false, []],
|
|
20
|
+
]) };
|
|
21
|
+
const next = digest([
|
|
22
|
+
['keep', 'h1', false, ['s1']],
|
|
23
|
+
['shrink', 'h2', false, ['s1']],
|
|
24
|
+
['reword', 'h3x', false, []],
|
|
25
|
+
['handoff', 'h4', true, []],
|
|
26
|
+
['new', 'h6', false, []],
|
|
27
|
+
]);
|
|
28
|
+
const { changes } = acceptanceChangesOf(prev, next);
|
|
29
|
+
const byId = Object.fromEntries(changes.map((item) => [item.id, item]));
|
|
30
|
+
expect(byId.shrink).toMatchObject({ kind: 'covers-shrunk', weakening: true, before: '2', after: '1' });
|
|
31
|
+
expect(byId.reword).toMatchObject({ kind: 'item-reworded', weakening: true });
|
|
32
|
+
expect(byId.handoff).toMatchObject({ kind: 'handoff-added', weakening: true });
|
|
33
|
+
expect(byId.gone).toMatchObject({ kind: 'item-removed', weakening: true });
|
|
34
|
+
expect(byId.new).toMatchObject({ kind: 'item-added', weakening: false });
|
|
35
|
+
expect(byId.keep).toBeUndefined();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('跨轮累计:同 id 同 kind 只留最早一次', () => {
|
|
39
|
+
const prev = { acceptanceDigest: digest([['a', 'h1', false, ['s1', 's2']]]), acceptanceChanges: [] };
|
|
40
|
+
const first = acceptanceChangesOf(prev, digest([['a', 'h1', false, ['s1']]]));
|
|
41
|
+
expect(first.cumulative).toHaveLength(1);
|
|
42
|
+
const second = acceptanceChangesOf({ ...prev, acceptanceDigest: digest([['a', 'h1', false, ['s1']]]), acceptanceChanges: first.cumulative }, digest([['a', 'h1', false, ['s1']]]));
|
|
43
|
+
expect(second.changes).toEqual([]);
|
|
44
|
+
expect(second.cumulative).toHaveLength(1);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('恢复原状后该条目从累计里移除', () => {
|
|
48
|
+
const cumulative = [{ id: 'a', kind: 'covers-shrunk', weakening: true, before: '2', after: '0', firstSeenAt: 1 }];
|
|
49
|
+
const prev = { acceptanceDigest: digest([['a', 'h1', false, []]]), acceptanceChanges: cumulative };
|
|
50
|
+
const result = acceptanceChangesOf(prev, digest([['a', 'h1', false, ['s1', 's2']]]));
|
|
51
|
+
expect(result.cumulative).toEqual([]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('删掉的验收项又加回来 → 这条账出账(不留永久噪声)', () => {
|
|
55
|
+
const prev = {
|
|
56
|
+
acceptanceDigest: digest([['a', 'h1', false, []]]),
|
|
57
|
+
acceptanceChanges: [{ id: 'a', kind: 'item-removed', weakening: true, firstSeenAt: 1 }],
|
|
58
|
+
};
|
|
59
|
+
const result = acceptanceChangesOf(prev, digest([['a', 'h1', false, []]]));
|
|
60
|
+
expect(result.cumulative).toEqual([]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('摘要只列弱化项,带前后数量', () => {
|
|
64
|
+
const summary = summarizeAcceptanceChanges([
|
|
65
|
+
{ id: 'parking.rule', kind: 'covers-shrunk', weakening: true, before: '2', after: '0' },
|
|
66
|
+
{ id: 'ui.mobile', kind: 'handoff-added', weakening: true },
|
|
67
|
+
{ id: 'new', kind: 'item-added', weakening: false },
|
|
68
|
+
]);
|
|
69
|
+
expect(summary).toEqual(['parking.rule 覆盖 2→0', 'ui.mobile 改为移交']);
|
|
70
|
+
expect(summarizeAcceptanceChanges([
|
|
71
|
+
{ id: 'x', kind: 'item-reworded', weakening: true },
|
|
72
|
+
{ id: 'x', kind: 'handoff-added', weakening: true },
|
|
73
|
+
])).toEqual(['x 文本改写、改为移交']);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('出厂模块偏离(D4)', () => {
|
|
78
|
+
it('少了出厂模块 → module-removed;新增 → module-added', () => {
|
|
79
|
+
const drift = defaultModuleDrift({
|
|
80
|
+
factory: [{ package: '@tbox.cn/app-module-ai-payment', version: '1.0.0' }],
|
|
81
|
+
actual: [{ package: '@tbox.cn/app-module-custom' }],
|
|
82
|
+
});
|
|
83
|
+
expect(drift.skipped).toBe(false);
|
|
84
|
+
expect(drift.items.map((item) => item.kind)).toEqual(['module-removed', 'module-added']);
|
|
85
|
+
expect(drift.items[0].key).toBe('@tbox.cn/app-module-ai-payment');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('出厂快照没有模块时跳过,不误报', () => {
|
|
89
|
+
expect(defaultModuleDrift({ factory: [], actual: [] }).skipped).toBe(true);
|
|
90
|
+
expect(defaultModuleDrift({ factory: undefined, actual: [{ package: 'x' }] }).skipped).toBe(true);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('当前文件缺失或为空数组时,出厂模块全部算移除', () => {
|
|
94
|
+
const drift = defaultModuleDrift({ factory: [{ package: 'a' }, { package: 'b' }], actual: [] });
|
|
95
|
+
expect(drift.items).toHaveLength(2);
|
|
96
|
+
});
|
|
97
|
+
});
|