Commit 9a9c8ae0 by 张立顺

test: establish subpackage split baseline

1 parent ca558bec
# AI 与工作日报分包拆分 Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use `superpowers:executing-plans` to implement this plan task-by-task in the current Git branch. Do not create a branch or worktree unless the user explicitly requests one.
**Goal:** 在不改变现有业务逻辑、接口契约、路由参数和页面生命周期的前提下,将权益 AI 功能迁入 `packageEquityAI`,将旧版工作日报迁入 `packageWorkReport`,并让每个上传包保留至少 10% 的 2MB 余量。
**Architecture:** 先通过行为特征测试、API 转发契约测试、开发者工具自动化和真机预览固化现状,再增加一个纯函数路由兼容层。两个新包均为普通分包,各自携带专属页面、组件、工具和 service;它们只允许依赖自身或主包,禁止同步依赖兄弟分包。
**Tech Stack:** 原生微信小程序、ES Modules、`node:test`、`miniprogram-automator`、微信开发者工具 CLI、项目知识图谱与迁移门禁。
**Spec:** `packageEquity/docs/SUBPACKAGE-ANALYSIS.md`、`packageEquity/docs/ROUTE-ALIAS-COMPAT-DESIGN.md`、`packageEquity/docs/P1-SPLIT-MIGRATION-CHECKLIST.md`
## Global Constraints
- 先补测试并记录当前行为基线,再修改路由或移动任何业务文件。
- 新包使用普通分包;不设置 `independent`,不新增 `preloadRule`。
- `packageEquityAI` 不得同步引用 `packageEquity`、`packageWorkReport` 或其他分包;`packageWorkReport` 不得同步引用 `tabWorkOrder`、`packageEquityAI` 或其他分包。
- 分包可以继续使用主包的 `api/`、`store/`、`utils/`、`mixins/`、全局组件和 npm 依赖。
- 不修改 ROP method、请求参数、网关、返回消费方式;API 代码迁移前必须通过最新 `develop` Swagger 契约门禁。
- 不修改全局 `Merchant-Seles`、`Coupon`、Popup 等共享组件,不合并当前同名但行为不同的 AI/报价组件。
- 路由 query、EventChannel 参数、`wx.$router.getData()`、H5 `wx.$SCENE` 和返回页判断必须保持现有语义。
- 列表及统计接口生命周期保持不变;本次不借拆包调整 `onLoad`、`onShow` 或 `onRoute` 行为。
- 原始源码门禁:`packageEquity <= 1,850,000`、`packageEquityAI <= 550,000`、`tabWorkOrder <= 1,700,000`、`packageWorkReport <= 450,000` bytes。
- 微信开发者工具实际上传/预览包体要求:主包和上述四个分包分别 `< 1.80MB`。
- 真机验收至少覆盖一台 Android 和一台 iOS;缺少任一设备结果时只能标记为代码完成,不能标记为发布验收通过。
## Current Baseline
- 基线提交:`ca558bec`。
- `npm test`:通过。
- `node scripts/scan-component-paths.mjs`:`BROKEN_COMPONENT_PATHS=0`。
- `node scripts/scan-broken-imports.mjs`:当前基线存在 2 个 `CRITICAL_CROSS_ROOT` 和 23 个 `OTHER_BROKEN`,均不在本次迁移目录;迁移不得增加数量,新建两个包内部必须为 0。
- 当前原始源码:`packageEquity=2,221,470` bytes,AI 候选组 `458,472` bytes;`tabWorkOrder=2,030,290` bytes,日报候选组 `395,510` bytes。
---
### Task 1: 建立迁移清单、不可变契约和基线测试
**Files:**
- Create: `docs/migrations/subpackage-ai-work-report-split/manifest.json`
- Create: `docs/migrations/subpackage-ai-work-report-split/api-inventory.md`
- Create: `docs/migrations/subpackage-ai-work-report-split/test-acceptance.md`
- Create: `tests/subpackage-split/fixtures/api-contracts.mjs`
- Create: `tests/subpackage-split/support/load-api-facade.mjs`
- Create: `tests/subpackage-split/api-contracts.test.mjs`
- Create: `tests/subpackage-split/navigation-baseline.test.mjs`
- Modify: `package.json`
- Modify: `project.config.json`
**Interfaces:**
- Produces: `loadApiFacade(relativePath, requestSpy): Promise<object>`,兼容当前 CommonJS/ES default API facade,并记录 `request.post(...args)` 的完整参数。
- Produces: 不可变 `AI_API_CONTRACTS` 与 `WORK_REPORT_API_CONTRACTS`,迁移前后复用同一组 method、网关和参数断言。
- [ ] **Step 1: 锁定所有 API 转发契约**
AI 契约必须覆盖:
```js
const aiWrappers = [
'sparring', 'objectionSparring',
'inspiration', 'objectionInspiration',
'enhancement', 'objectionEnhancement',
'getSensitive', 'getPhrases', 'getVoice',
'getSparringPage', 'setSparringVerify', 'getToken',
'getInspectionDetail', 'getSparringPage', 'getSparringDetail',
'getSparringResult', 'sparringCommit', 'behaviorSave',
'objectionPage', 'sparringRole', 'sparringRrain'
]
```
其中自定义 AI 网关必须逐项断言第四至第六个参数,例如 `/router/sparring/1.0.0`、`AI`、`false`;派练接口必须断言 `/rop-dj-pairexc/router`。
日报契约必须覆盖:
```js
const reportWrappers = [
'staffDailyReportSave', 'staffDailyReportDetail',
'staffDailyReportDetailWeeklyList', 'staffDailyReportApprove',
'querySceneRefByShop', 'staffDailyReportMerchantCarBand',
'getDateRecord', 'getRecordDetail', 'getWeeklyRecordDetail',
'getMonthCalWeek', 'getMonthlyRecordDetail', 'saveTempReport',
'getStaffList', 'dailyReportCheck', 'userStat',
'outputValueStatistics'
]
```
- [ ] **Step 2: 对 ROP dotted methods 执行只读 Swagger inspect**
对下列非空 dotted method 逐个执行:
```powershell
$methods = @(
'dj.api.carboutique.ai.sparring.staff.record.page',
'dj.api.carboutique.ai.sparring.verify',
'dj.api.smartcarlife.recepiton.customer.oss.getToken',
'dj.api.smartcarlife.app.inspection.conversation.check.detail',
'dj.api.carboutique.ai.sparring.task.page',
'dj.api.carboutique.ai.sparring.task.staff.detail.page',
'dj.api.carboutique.ai.sparring.detail.check.result',
'dj.api.carboutique.ai.sparring.detail.commit',
'dj.api.carboutique.ai.sparring.staff.behavior.save',
'dj.api.carboutique.ai.sparring.objection.page',
'dj.api.carboutique.ai.sparring.role.info.page',
'dj.api.carboutique.ai.sparring.start.train',
'dj.api.smartcarlife.staff.daily.report.save',
'dj.api.smartcarlife.staff.daily.report.detail',
'dj.api.smartcarlife.staff.daily.report.weekly.list',
'dj.api.smartcarlife.staff.daily.report.approve',
'dj.api.scenemerchantref.querySceneRefByShop',
'dj.api.smartcarlife.staff.daily.report.car.brand',
'dj.api.mindworkplate.app.daily.report.mySubmittedDateRecord',
'dj.api.mindworkplate.app.daily.report.myRecordDetail',
'dj.api.carboutique.assign.month.find.staff.weekly.report.submit',
'dj.api.carboutique.assign.month.cal.week',
'dj.api.carboutique.assign.year.find.staff.monthly.report.submit',
'dj.api.mindworkplate.app.daily.report.save',
'dj.api.mindworkplate.app.daily.report.staffBaseInfo.page',
'dj.api.smartcarlife.staff.daily.report.data.check',
'dj.api.smartcarlife.user.stat',
'dj.api.smartcarlife.vehicle.damage.upgrade.quotation.outputValueStatistics'
)
foreach ($method in $methods) {
node "C:\Users\admin\.codex\skills\integrating-rop-apis\scripts\rop-swagger-contract.mjs" inspect --project "." --method $method --json
if ($LASTEXITCODE -ne 0) { throw "Swagger inspect failed: $method" }
}
```
只有全部候选网关返回 `found` 才能继续。`not-found`、`conflict`、`partial-online`、`method-removed` 或离线状态均按 API 契约门禁停止,不进入 API 文件迁移。
- [ ] **Step 3: 编写并运行基线 API 契约测试**
测试直接加载当前 `packageEquity/aiApi.js`、`packageEquity/carEquityApi.js` 和 `tabWorkOrder/api.js`,断言:
```js
assert.deepEqual(spy.calls[0], {
method: expected.method,
payload,
extraArgs: expected.extraArgs
})
assert.equal(spy.calls[0].payload, payload)
```
同时覆盖 transport rejection 原样向上抛出。运行:
```powershell
node --test tests/subpackage-split/api-contracts.test.mjs
```
Expected: PASS against the pre-migration implementation.
- [ ] **Step 4: 固化导航入口的当前业务选择规则**
`navigation-baseline.test.mjs` 覆盖:权益/轻改用户分别进入 `staffDaily`/`upgradeStaffDaily`、三种主管日报菜单携带 `reportTypeAttr`、AI 菜单进入 start、AI 练习入口保留 `staffid/tryCount/roleType/promptOnOff`、H5 `page=staffDaily|upgradeStaffDaily|aiDetail` 的当前目标和免登录判断。
断言用户可观察的目标页面和参数,不断言无业务意义的源代码文本。
- [ ] **Step 5: 建立迁移 manifest 并通过 pre 门禁**
`manifest.json` 的测试项引用本任务新增且已通过的基线测试;`api-inventory.md` 记录上述完整接口矩阵;`test-acceptance.md` 记录基线提交、自动化结果和真机用例编号。运行:
```powershell
npm run check:migration -- --manifest docs/migrations/subpackage-ai-work-report-split/manifest.json --phase pre
```
Expected: `Migration readiness pre check passed`。
- [ ] **Step 6: 更新上传忽略项和测试入口**
`project.config.json` 忽略 `tests/subpackage-split` 与迁移文档;保持 `ignoreUploadUnusedFiles: true`。新增:
```json
{
"test:subpackage-split": "node --experimental-detect-module --test tests/subpackage-split"
}
```
- [ ] **Step 7: 保存测试准备提交**
```powershell
git add docs/migrations/subpackage-ai-work-report-split tests/subpackage-split package.json project.config.json
git commit -m "test: establish subpackage split baseline"
```
---
### Task 2: 建立开发者工具自动化与改造前真机基线
**Files:**
- Create: `tests/subpackage-split/ui/live-config.mjs`
- Create: `tests/subpackage-split/ui/page-driver.mjs`
- Create: `tests/subpackage-split/ui/evidence.mjs`
- Create: `tests/subpackage-split/ui/subpackage-split.live.test.mjs`
- Create: `tests/subpackage-split/ui/live-config.test.mjs`
- Modify: `package.json`
- Modify: `docs/migrations/subpackage-ai-work-report-split/test-acceptance.md`
**Interfaces:**
- Consumes: `tests/order-lifecycle/ui/uiLauncher.mjs` 的 `openMiniProgram`、`releaseMiniProgram`。
- Produces: 运行时环境变量控制的只读 smoke;保存/批复/AI 提交必须由独立 allow flag 显式授权。
- [ ] **Step 1: 先写 live 配置失败测试**
覆盖默认禁用、凭据只从运行时读取、WebSocket 仅允许 loopback、CLI 固定为已安装路径、service port 与 automation port 不得相同、写操作默认关闭、生产网关拒绝执行。
```powershell
node --test tests/subpackage-split/ui/live-config.test.mjs
```
Expected: FAIL because `live-config.mjs` does not exist.
- [ ] **Step 2: 实现最小安全配置并转绿**
使用以下环境变量,任何错误信息不得回显手机号或验证码:
```text
RUN_SPLIT_UI_E2E
SPLIT_E2E_MOBILE
SPLIT_E2E_CODE
SPLIT_E2E_PARK_NAME
SPLIT_E2E_STORE_NAME
SPLIT_E2E_AI_TASK_ID
SPLIT_E2E_REPORT_DATE
SPLIT_E2E_ALLOW_AI_WRITE
SPLIT_E2E_ALLOW_REPORT_WRITE
SPLIT_UI_AUTOMATION_PORT
SPLIT_UI_SERVICE_PORT
SPLIT_UI_EVIDENCE_DIR
```
- [ ] **Step 3: 编写自动化页面行为用例**
基线路径使用当前物理路径,post 阶段通过配置切换为新路径。用例至少包括:
- `IT-SPLIT-UI-001`:登录、选择园区/4S 店/精品升级场景。
- `IT-SPLIT-UI-010`:权益菜单进入 AI start,记录列表正常渲染。
- `IT-SPLIT-UI-011`:AI 练习列表进入详情和结果,关键 query 不丢失。
- `IT-SPLIT-UI-012`:质检详情进入接待页并可返回。
- `IT-SPLIT-UI-020`:员工日报/轻改日报按 sceneType 选择正确页面,周历和已有详情加载成功。
- `IT-SPLIT-UI-021`:主管日报 daily/weekly/monthly 切换,`routeParams`、模板、日期维度保持正确。
- `IT-SPLIT-UI-022`:`GLCustForm` 车品牌跳转和回填正常。
- `IT-SPLIT-UI-030`:H5 深链携带 query 到达目标页。
默认只读;写入类动作仅在 test 环境且 allow flag 为 `1` 时执行,并记录操作对象 ID。
- [ ] **Step 4: 运行改造前开发者工具 smoke**
```powershell
npm run test:subpackage-split:ui
```
Expected: 所有启用用例 PASS,证据写入 `outputs/subpackage-split/baseline/`。
- [ ] **Step 5: 生成改造前真机预览二维码**
```powershell
& 'C:\Program Files (x86)\Tencent\微信web开发者工具\cli.bat' preview --project . --qr-format image --qr-output outputs/subpackage-split/baseline/preview.png --info-output outputs/subpackage-split/baseline/preview-info.json
```
Android 与 iOS 分别执行本文末尾真机矩阵;记录设备型号、系统版本、微信版本、首次分包下载、页面路径、截图和结果。两端均通过后才进入 Task 3。
- [ ] **Step 6: 保存基线证据记录提交**
只提交不含凭据的验收记录,不提交 `outputs/`:
```powershell
git add tests/subpackage-split/ui package.json docs/migrations/subpackage-ai-work-report-split/test-acceptance.md
git commit -m "test: capture pre-split UI behavior"
```
---
### Task 3: 用 TDD 建立无歧义路由兼容层
**Files:**
- Create: `router/routeAliases.js`
- Create: `tests/subpackage-split/route-aliases.test.mjs`
- Create: `tests/subpackage-split/router-integration.test.mjs`
- Modify: `router/router.js`
**Interfaces:**
- Produces: `resolveRoute(input: string): ResolvedRoute`。
- `ResolvedRoute` 为 `{ kind: 'named', route, query, rewritten }` 或 `{ kind: 'path', path, query, rewritten }`。
- Produces: `assertRouteTargetRegistered(path, appConfig)` 测试 helper,保证兼容表输出的每个物理路径都在 `app.json` 注册。
- [ ] **Step 1: 写纯函数 RED 用例**
覆盖以下不可变行为:
```js
const routeCases = [
['packageEquity.start?stage=lead', '/packageEquityAI/pages/aiCheck/start/start', '?stage=lead'],
['packageEquity.detail?staffid=1', '/packageEquityAI/pages/aiExcercise/detail/detail', '?staffid=1'],
['packageEquity.result?staffid=1', '/packageEquityAI/pages/aiExcercise/result/result', '?staffid=1'],
['packageEquityAI.aiCheckDetail', '/packageEquityAI/pages/aiCheck/detail/detail', ''],
['packageEquityAI.aiCheckResult', '/packageEquityAI/pages/aiCheck/result/result', ''],
['tabWorkOrder.staffDaily', '/packageWorkReport/pages/staffDaily/staffDaily', ''],
['tabWorkOrder.supervisorDaily', '/packageWorkReport/pages/supervisorDaily/supervisorDaily', ''],
['/packageEquity/pages/aiCheck/chat/chat?id=7', '/packageEquityAI/pages/aiCheck/chat/chat', '?id=7'],
['/tabWorkOrder/pages/upgradeStaffDaily/upgradeStaffDaily?reportDate=2026-09-04', '/packageWorkReport/pages/upgradeStaffDaily/upgradeStaffDaily', '?reportDate=2026-09-04']
]
```
额外覆盖未知路由保持原样、空输入不吞异常、已是新路径不重复改写、编码 query 不被重复 encode。
```powershell
node --test tests/subpackage-split/route-aliases.test.mjs
```
Expected: FAIL because `routeAliases.js` does not exist.
- [ ] **Step 2: 实现显式全路径别名,规避同名页面冲突**
`FULL_ROUTE_ALIASES` 同时维护旧别名和新语义别名。新业务代码禁止使用有歧义的 `packageEquityAI.detail`、`packageEquityAI.result`,统一使用:
```js
export const AI_ROUTES = Object.freeze({
exerciseHome: 'packageEquityAI.exerciseHome',
exerciseList: 'packageEquityAI.exerciseList',
exerciseDetail: 'packageEquityAI.exerciseDetail',
exerciseResult: 'packageEquityAI.exerciseResult',
aiCheckStart: 'packageEquityAI.aiCheckStart',
aiCheckChat: 'packageEquityAI.aiCheckChat',
aiCheckResult: 'packageEquityAI.aiCheckResult',
aiCheckScene: 'packageEquityAI.aiCheckScene',
aiCheckDetail: 'packageEquityAI.aiCheckDetail',
aiCheckDefense: 'packageEquityAI.aiCheckDefense',
aiCheckRedundance: 'packageEquityAI.aiCheckRedundance',
inspectionDetail: 'packageEquityAI.aiInspectionDetail',
inspectionReception: 'packageEquityAI.aiInspectionReception'
})
```
工作日报公开名固定为 `packageWorkReport.staffDaily`、`packageWorkReport.upgradeStaffDaily`、`packageWorkReport.supervisorDaily`;旧 `tabWorkOrder.*` 别名继续映射四个发布版本。
- [ ] **Step 3: 写 Router 集成 RED 用例**
使用真实 `Router` 和最小 `wx` fake,分别调用 `go`、`redirectTo`、`reLaunch`、`_to`,断言最终 URL、query、EventChannel `getData` 参数和 `globalData.ROUTE_QUERY` 均不变。
- [ ] **Step 4: 将 resolver 接入全部跳转入口**
`router/router.js` 的 `checkRouter`、绝对路径 `go`、`redirectTo`、`reLaunch`、`_to` 统一调用 resolver。找不到路由时保留清晰错误并停止调用微信跳转 API,避免解构 `undefined` 产生二次异常。
- [ ] **Step 5: 运行路由测试和现有菜单测试**
```powershell
node --test tests/subpackage-split/route-aliases.test.mjs tests/subpackage-split/router-integration.test.mjs packageEquity/tests/equityMenu.test.mjs packageEquity/tests/equityMenuJump.test.mjs tabIndex/tests/tabIndexMenu.test.mjs tabIndex/tests/tabIndexMenuJump.test.mjs packageDynamicForm/tests/staffDailyReportNavigation.test.mjs
```
Expected: PASS.
- [ ] **Step 6: 保存路由基础设施提交**
```powershell
git add router tests/subpackage-split
git commit -m "refactor: add subpackage route compatibility"
```
---
### Task 4: 增加跨包引用编译门禁
**Files:**
- Create: `scripts/check-subpackage-boundaries.mjs`
- Create: `tests/subpackage-split/subpackage-boundaries.test.mjs`
- Create: `tests/subpackage-split/fixtures/boundaries/`
- Modify: `package.json`
**Interfaces:**
- Produces: `checkSubpackageBoundaries(projectRoot, appConfig, options): BoundaryIssue[]`,`options.roots` 可只校验新包或本次变更路径,`options.allowlist` 仅承载已记录的仓库基线问题。
- `BoundaryIssue` 包含 `{ importer, specifier, importerPackage, targetPackage, kind }`。
- [ ] **Step 1: 写边界扫描 RED 用例**
fixture 必须证明扫描器能够发现:JS `import/export from/require`、`~/packageEquity/...` 这类分包别名、相对路径越界、JSON `usingComponents`、WXML `import/include/wxs src`、WXS `require`、WXSS/SASS `@import` 的跨兄弟包引用,以及主包同步引用分包。
同时证明“分包引用主包”和“分包引用自身”合法。
- [ ] **Step 2: 实现最小扫描器并转绿**
忽略 `docs/tests/node_modules/miniprogram_npm/.git/outputs`。本次明确不启用跨分包异步组件,因此不同 subpackage root 之间的静态资源引用一律报错。
- [ ] **Step 3: 对当前项目运行基线扫描**
```powershell
node scripts/check-subpackage-boundaries.mjs --roots packageEquityAI,packageWorkReport
```
Expected before physical move: CLI 明确报告两个 root 尚未注册。Task 5、6 完成后,同一命令必须返回 `BOUNDARY_ISSUES=0`;全库模式通过基线 allowlist 隔离与本次无关的既有问题,allowlist 数量不得增长。
- [ ] **Step 4: 保存边界门禁提交**
```powershell
git add scripts/check-subpackage-boundaries.mjs tests/subpackage-split package.json
git commit -m "test: guard mini program package boundaries"
```
---
### Task 5: 迁移 `packageEquityAI`
**Files:**
- Create: `packageEquityAI/services/aiApi.js`
- Create: `packageEquityAI/services/carLifeApi.js`
- Move: `packageEquity/pages/aiCheck/` -> `packageEquityAI/pages/aiCheck/`
- Move: `packageEquity/pages/aiExcercise/` -> `packageEquityAI/pages/aiExcercise/`
- Move: `packageEquity/pages/aiInspectionDetail/` -> `packageEquityAI/pages/aiInspectionDetail/`
- Move: `packageEquity/pages/aiInspectionReception/` -> `packageEquityAI/pages/aiInspectionReception/`
- Move: `packageEquity/utils/aliyun/` -> `packageEquityAI/utils/aliyun/`
- Modify: `app.json`
- Modify: AI callers in `packageEquity/menu/`, `packageEquity/pages/TabBar/equityPage.js`, `packageEquity/pages/receptionDetail/receptionDetail.js`, `packageEquity/pages/aiInspection/components/contentItem/contentItem.js`, `store/index.js`
- Modify: `project.private.config.json`
- Modify: `tests/subpackage-split/api-contracts.test.mjs`
**Interfaces:**
- `packageEquityAI/services/aiApi.js` 保持当前动态访问 `aiApi[api_params](payload)` 的 default facade。
- `packageEquityAI/services/carLifeApi.js` 保持当前 `carLifeApi.method(payload)` facade。
- 不移动 `packageEquity/pages/aiInspection/components/`,因为报价接待仍消费其中的 `contentItem`。
- [ ] **Step 1: 写 AI 包注册和 API owner 的 RED 用例**
断言 `app.json` 注册 13 个 AI 页面、新包路径存在、旧 `packageEquity` 页面清单不再包含它们、API 契约 fixture 改由新 service 承载、所有 `AI_ROUTES` 目标均注册。
- [ ] **Step 2: 在编辑 API 前同步 Swagger**
对 Task 1 已 `found` 的 AI dotted methods 执行 `sync --write`。若在线契约发生变化,先更新差异报告并停止,不静默改写业务请求。
- [ ] **Step 3: 先创建并验证新包本地 API facade**
复制的只是 Task 1 契约中真实被 AI 页面使用的 wrappers;不顺带搬运话术抽取、线索、报价等未使用接口。运行契约测试,Expected: 新 facade PASS,完整 `request.post` 参数与旧 facade 相同。
- [ ] **Step 4: 整体移动 AI 页面和阿里云工具**
保持各页面 JS/WXML/WXSS/JSON 与组件目录结构;只改因 root 改变而失效的 import、require 和路径。所有 `~/packageEquity/utils/aliyun/*` 改为 `~/packageEquityAI/utils/aliyun/*`,所有旧 `../../../aiApi`、`../../../carEquityApi` 改为新包 service。
- [ ] **Step 5: 更新全部 AI 页面内跳转**
必须逐项处理:
- `chat -> result`,`scene -> chat`,`result -> defense/scene/start/detail`。
- `detail -> scene/start`,`defense -> chat`,`RecordList -> result`,`introduction -> defense/scene`,`fluent -> redundance`。
- AI 练习 `home -> list/detail/result`,`list -> result`。
- `aiInspectionDetail -> aiInspectionReception`。
- `prevPage.route === packageEquity/pages/aiCheck/start/start` 改为新物理路径常量。
新代码使用 `AI_ROUTES` 语义名;旧物理路径仅允许存在于兼容映射与兼容测试。
- [ ] **Step 6: 更新分包外 AI 入口**
权益菜单、权益 TabBar、接待详情、`aiInspection/components/contentItem` 和 H5 `pagePath.aiDetail` 全部指向新语义路由/新物理路径,并保留原 query 与 EventChannel 数据。
- [ ] **Step 7: 运行 AI 定向验证**
```powershell
npm run test:subpackage-split
npm run test:equity
node scripts/check-subpackage-boundaries.mjs
node scripts/scan-component-paths.mjs
node scripts/scan-broken-imports.mjs
```
Expected: AI 新包边界 0、组件路径 0、现有 broken-import 基线不增加。
- [ ] **Step 8: 开发者工具完整编译 AI 包**
用 CLI preview 编译并通过 automator 重跑 `IT-SPLIT-UI-010` 至 `012`;Console 不得出现 `module not found`、`not in current package`、`找不到路由`、组件/WXS 加载失败。
- [ ] **Step 9: 保存 AI 拆包提交**
```powershell
git add app.json packageEquity packageEquityAI router store project.private.config.json tests
git commit -m "refactor: split equity AI subpackage"
```
---
### Task 6: 迁移 `packageWorkReport`
**Files:**
- Create: `packageWorkReport/services/reportApi.js`
- Move: `tabWorkOrder/pages/staffDaily/` -> `packageWorkReport/pages/staffDaily/`
- Move: `tabWorkOrder/pages/upgradeStaffDaily/` -> `packageWorkReport/pages/upgradeStaffDaily/`
- Move: `tabWorkOrder/pages/supervisorDaily/` -> `packageWorkReport/pages/supervisorDaily/`
- Move: `tabWorkOrder/components/GLCustForm/` -> `packageWorkReport/components/GLCustForm/`
- Move: `tabWorkOrder/utils/ruleFn.js` -> `packageWorkReport/utils/ruleFn.js`
- Modify: `tabWorkOrder/api.js`
- Modify: `app.json`
- Modify: callers in `utils/staffDailyReportNavigation.js`, `tabIndex/menu/`, `packageEquity/menu/`, `packageEquity/services/todoService.js`, `packageEquity/pages/salaryAppeal/salaryAppeal.js`, `packageUsedCar/ModalToQueueUsedCarControl.js`, `store/index.js`
- Modify: `project.config.json`, `project.private.config.json`, `package.json`, `scripts/knowledge-graph/affected-tests.mjs`
**Interfaces:**
- Produces: `packageWorkReport/services/reportApi.js` default ES facade,承载 Task 1 的 16 个日报 wrappers。
- 保留 `tabWorkOrder/api.js#staffDailyReportMerchantValid`,因为开单、建档、战败、补录等页面仍使用日报填写门禁。
- [ ] **Step 1: 写日报包注册、路由和 API owner RED 用例**
断言三个页面只注册在 `packageWorkReport`;日报 facade 的 16 个契约保持不变;`staffDailyReportMerchantValid` 仍属于 `tabWorkOrder/api.js`;三个新目标路由均已注册。
- [ ] **Step 2: 在编辑 API 前同步 Swagger**
对 Task 1 已 `found` 的日报 dotted methods 执行 `sync --write`。任何 method、必填字段或网关差异都先停止并展示,不改变本次“只迁移不改契约”的边界。
- [ ] **Step 3: 创建并验证 `reportApi`**
新 facade 完整复制 16 个 wrappers 的 method 和 request 参数;契约测试转绿后,再从 `tabWorkOrder/api.js` 删除仅被迁移页面使用的对应 wrappers。
- [ ] **Step 4: 整体移动三个日报页面及私有依赖**
同时移动 `upgradeStaffDaily/services/dailyReportInconsistency.helpers.js` 及其测试。三个页面之间的相对引用保持包内;对 `~/api/api`、`~/store/index`、`~/mixins/reportPageTrackMixin`、`dayjs`、`number-precision` 的主包/npm 引用保持不变。
- [ ] **Step 5: 修正组件、WXS 和 JSON 路径**
`supervisorDaily.json` 的 `weekCalendar`、`select-item-popup` 继续指向同包页面组件;`gl-cust-form` 改为 `/packageWorkReport/components/GLCustForm/GLCustForm`;`GLCustForm.wxml` 的 WXS 改为 `/packageWorkReport/components/GLCustForm/GLForm.wxs`。
- [ ] **Step 6: 更新所有日报入口和 H5 深链**
更新首页/权益菜单、日报导航 helper、权益待办、薪资申诉、二手车弹窗、`store/index.js` 的 `staffDaily`/`upgradeStaffDaily` pagePath 与免登录 allowlist。保留 `reportDate`、`scene`、`params` 和 `reportTypeAttr`。
- [ ] **Step 7: 更新开发、测试和知识图谱路径**
更新 `project.private.config.json` 启动项、`project.config.json` ignore/include、`package.json` 测试路径、`affected-tests.mjs`。旧测试文件路径不得继续被脚本引用。
- [ ] **Step 8: 运行日报定向验证**
```powershell
npm run test:subpackage-split
node --test packageWorkReport/pages/upgradeStaffDaily/tests/dailyReportInconsistency.helpers.test.mjs
node --test packageDynamicForm/tests/staffDailyReportNavigation.test.mjs packageEquity/tests/todoService.test.mjs packageEquity/tests/equityMenuJump.test.mjs tabIndex/tests/tabIndexMenuJump.test.mjs
node scripts/check-subpackage-boundaries.mjs
node scripts/scan-component-paths.mjs
node scripts/scan-broken-imports.mjs
```
Expected: 日报新包边界 0、组件路径 0、现有 broken-import 基线不增加。
- [ ] **Step 9: 开发者工具完整编译日报包**
用 CLI preview 编译并通过 automator 重跑 `IT-SPLIT-UI-020` 至 `030`;特别检查 `wx.$router.getData()`、主管日报 daily/weekly/monthly 动态 API 选择、`GLCustForm` WXS 和车品牌跳转。
- [ ] **Step 10: 保存日报拆包提交**
```powershell
git add app.json tabWorkOrder packageWorkReport packageEquity tabIndex packageUsedCar store utils project.config.json project.private.config.json package.json scripts tests
git commit -m "refactor: split work report subpackage"
```
---
### Task 7: 增加体积门禁并完成全量自动化回归
**Files:**
- Create: `scripts/check-subpackage-size.mjs`
- Create: `tests/subpackage-split/package-size.test.mjs`
- Modify: `package.json`
- Modify: `docs/DOMAIN-INDEX.md`
- Modify: `packageEquity/docs/SUBPACKAGE-ANALYSIS.md`
- Modify: `packageEquity/docs/P1-SPLIT-MIGRATION-CHECKLIST.md`
- Modify: `packageEquity/docs/ROUTE-ALIAS-COMPAT-DESIGN.md`
- Regenerate: `docs/COMPONENT-PAGE-INDEX.md` and knowledge graph outputs
**Interfaces:**
- Produces: `measurePackageBytes(root, ignoreRules): number` 与 CLI 非零退出码体积门禁。
- 原始源码门禁仅用于防回涨,不替代微信开发者工具的实际包体结果。
- [ ] **Step 1: 写体积门禁 RED 用例**
fixture 覆盖阈值内、刚好等于阈值、超过 1 byte、忽略 tests/docs/node_modules/miniprogram_npm、路径不存在。运行后 Expected: FAIL because size checker does not exist.
- [ ] **Step 2: 实现体积脚本并接入 npm**
```json
{
"check:subpackage-size": "node scripts/check-subpackage-size.mjs"
}
```
- [ ] **Step 3: 更新正式文档和路由冲突说明**
明确纠正旧 Checklist 中“同 parent 下 detail/result 无需处理”的结论;记录新语义别名、旧路由兼容周期、包体 before/after、日报新域及不拆 Quote 的边界。
- [ ] **Step 4: 更新组件索引与影响测试计划**
```powershell
npm run gen:component-index
npm run test:affected -- --list --format json
```
检查 `GLCustForm` 消费者只剩新日报包,AI 页面组件路径均指向新 root。
- [ ] **Step 5: 运行全部静态和自动化门禁**
```powershell
npm run knowledge:check
npm run check:subpackage-size
npm run test:subpackage-split
npm test
node scripts/check-subpackage-boundaries.mjs
node scripts/scan-component-paths.mjs
node scripts/scan-broken-imports.mjs
git diff --check
```
Expected: 新增测试与全量测试 PASS;新包边界 0;组件路径 0;broken-import 数量不高于基线 2/23,且本次变更文件无命中;`git diff --check` 无输出。
- [ ] **Step 6: 保存治理与文档提交**
```powershell
git add scripts tests package.json docs packageEquity/docs
git commit -m "chore: enforce subpackage size and migration gates"
```
---
### Task 8: 改造后真机验收与 migration post
**Files:**
- Modify: `docs/migrations/subpackage-ai-work-report-split/test-acceptance.md`
- Modify: `docs/migrations/subpackage-ai-work-report-split/manifest.json`
- Evidence only: `outputs/subpackage-split/post/`
- [ ] **Step 1: 生成 post 预览和包体信息**
```powershell
& 'C:\Program Files (x86)\Tencent\微信web开发者工具\cli.bat' preview --project . --qr-format image --qr-output outputs/subpackage-split/post/preview.png --info-output outputs/subpackage-split/post/preview-info.json
```
记录开发者工具实际主包、`packageEquity`、`packageEquityAI`、`tabWorkOrder`、`packageWorkReport` 体积,任一达到 `1.80MB` 即不进入真机放行。
- [ ] **Step 2: Android 与 iOS 执行同一真机矩阵**
**AI:**
1. 权益菜单进入 AI start,首次下载无白屏。
2. AI 场景进入 chat,麦克风授权、录音、ASR、TTS 正常。
3. chat 完成后进入 result,并进入 detail、defense、redundance。
4. AI 练习列表进入详情/结果,参数和返回路径正确。
5. 接待详情/contentItem 进入质检详情,再进入接待页并返回。
**日报:**
1. 首页与权益菜单分别进入员工日报、轻改日报和主管日报。
2. sceneType 0/1 仍选择正确日报版本,`reportDate` 保留。
3. 主管日报 daily/weekly/monthly 查询、日期切换、编辑态与只读态正常。
4. `GLCustForm` 输入、地区、车品牌选择与回填正常。
5. 在授权测试数据上执行保存/批复,并核对详情回显与提示。
6. H5 `page=staffDaily|upgradeStaffDaily|aiDetail` 在已登录和免登录流程均到达正确页面。
**通用:** 页面前进、返回、重定向、冷启动深链均无 `not found route`、跨包引用、组件/WXS 加载或模块编译错误。
- [ ] **Step 3: 对比 baseline 与 post 证据**
对每个用例比较目标页面、query、关键 data shape、接口 method/参数、成功/失败提示和返回路径。业务差异必须修复并重跑对应自动化和真机用例,不能通过修改基线期望掩盖差异。
- [ ] **Step 4: 更新 manifest 并执行 post 门禁**
将每个测试状态写为 `pass`;只有外部服务或设备不可用且已有证据时才可记 `blocked`,但 blocked 不视为发布验收完成。运行:
```powershell
npm run check:migration -- --manifest docs/migrations/subpackage-ai-work-report-split/manifest.json --phase post
```
Expected: `Migration readiness post check passed`,且真机矩阵无 blocked。
- [ ] **Step 5: 保存最终验收记录提交**
```powershell
git add docs/migrations/subpackage-ai-work-report-split
git commit -m "test: record subpackage split acceptance"
```
## Completion Criteria
- 13 个 AI 页面只属于 `packageEquityAI`,3 个旧版日报页面只属于 `packageWorkReport`。
- 旧别名和旧绝对路径在兼容期内仍能到达新页面;新代码使用无歧义语义路由。
- `detail/result` 同名页面有明确的全路径映射,不依赖 `__wxConfig.pages` 的首个同名项。
- 新包不存在任何同步跨兄弟包 JS、组件、WXML/WXS 或样式引用。
- Task 1 的 API 契约矩阵迁移前后完全一致。
- 全量自动化、开发者工具编译、Android/iOS 真机矩阵、体积门禁和 migration post 全部通过。
- 不执行生产上传或发布;最终交付为当前分支上的已验证代码和真机证据记录。
# AI 与工作日报分包 API 清单
## 边界
本次只迁移调用位置,不改变 method、payload、网关、签名排除字段、失败提示开关或响应消费方式。基线由 `tests/subpackage-split/api-contracts.test.mjs` 直接监听现有 facade 的 `request.post` 完整参数。
在线来源为 `develop` 环境的 `dj-car-boutique-work-wechat` 配置中心。已注册来源 `axios / rop-dj-car-boutique` 于 2026-09-04 在线读取成功;不带来源约束时,候选 `axios2 / rop-dj-smartcarlife` 的内网 Swagger 当前不可达,因此每个已确认方法均使用已注册 `axios` 来源执行精确匹配。
## 非 ROP AI transport
这些调用没有 dotted method,原样使用 AI 域名与路径,靠转发契约测试锁定。
| facade | path | domain | failTips |
| --- | --- | --- | --- |
| `sparring` | `/router/sparring/1.0.0` | `AI` | `false` |
| `objectionSparring` | `/router/objection/sparring/1.0.0` | `AI` | `false` |
| `inspiration` | `/router/inspiration/1.0.0` | `AI` | 默认值 |
| `objectionInspiration` | `/router/objection/inspiration/1.0.0` | `AI` | 默认值 |
| `enhancement` | `/router/enhancement/1.0.0` | `AI` | `false` |
| `objectionEnhancement` | `/router/objection/enhancement/1.0.0` | `AI` | `false` |
| `getSensitive` | `/router/is/sensitive/1.0.0` | `AI` | `false` |
| `getPhrases` | `/router/similar/phrases/1.0.0` | `AI` | `false` |
| `getVoice` | `/router/get/voice/to/text/1.0.0` | `AI` | `false` |
## AI ROP methods
| facade | method | 当前请求网关 | develop Swagger | 迁移处理 |
| --- | --- | --- | --- | --- |
| `aiApi.getSparringPage` | `dj.api.carboutique.ai.sparring.staff.record.page` | `/rop-dj-pairexc/router` | `axios` 未收录 | 保持原调用;API 写入门禁暂缓 |
| `aiApi.setSparringVerify` | `dj.api.carboutique.ai.sparring.verify` | `/rop-dj-pairexc/router` | `axios` 未收录 | 保持原调用;API 写入门禁暂缓 |
| `aiApi.getToken` | `dj.api.smartcarlife.recepiton.customer.oss.getToken` | 默认 | `found`, fresh | 原样迁移 |
| `carEquityApi.getInspectionDetail` | `dj.api.smartcarlife.app.inspection.conversation.check.detail` | 默认 | `found`, fresh | 原样迁移 |
| `carEquityApi.getSparringPage` | `dj.api.carboutique.ai.sparring.task.page` | `/rop-dj-pairexc/router` | `axios` 未收录 | 保持原调用;API 写入门禁暂缓 |
| `carEquityApi.getSparringDetail` | `dj.api.carboutique.ai.sparring.task.staff.detail.page` | `/rop-dj-pairexc/router` | `axios` 未收录 | 保持原调用;API 写入门禁暂缓 |
| `carEquityApi.getSparringResult` | `dj.api.carboutique.ai.sparring.detail.check.result` | `/rop-dj-pairexc/router` | `axios` 未收录 | 保持原调用;API 写入门禁暂缓 |
| `carEquityApi.sparringCommit` | `dj.api.carboutique.ai.sparring.detail.commit` | `/rop-dj-pairexc/router` | `axios` 未收录 | 保持原调用;API 写入门禁暂缓 |
| `carEquityApi.behaviorSave` | `dj.api.carboutique.ai.sparring.staff.behavior.save` | `/rop-dj-pairexc/router` | `axios` 未收录 | 保持原调用;API 写入门禁暂缓 |
| `carEquityApi.objectionPage` | `dj.api.carboutique.ai.sparring.objection.page` | `/rop-dj-pairexc/router` | `axios` 未收录 | 保持原调用;API 写入门禁暂缓 |
| `carEquityApi.sparringRole` | `dj.api.carboutique.ai.sparring.role.info.page` | `/rop-dj-pairexc/router` | `found`, fresh | method 已收录;网关仍保持不变 |
| `carEquityApi.sparringRrain` | `dj.api.carboutique.ai.sparring.start.train` | `/rop-dj-pairexc/router` | `axios` 未收录 | 保持原调用;API 写入门禁暂缓 |
`/rop-dj-pairexc/swagger-rop/api-docs` 经当前 develop 公共域名读取返回 HTTP 502,配置中心也未登记该 ROP source。因此上述 9 个方法属于“Swagger 尚未收录且目标 Swagger 不可验证”;在取得一次性契约覆盖确认前,不创建或改写 AI API facade。
## 工作日报 ROP methods
下列 16 项在 `axios / rop-dj-car-boutique` 的最新 develop Swagger 中均为 `found`、`fresh=true`、`relevantMethodChanged=false`。
| facade | method |
| --- | --- |
| `staffDailyReportSave` | `dj.api.smartcarlife.staff.daily.report.save` |
| `staffDailyReportDetail` | `dj.api.smartcarlife.staff.daily.report.detail` |
| `staffDailyReportDetailWeeklyList` | `dj.api.smartcarlife.staff.daily.report.weekly.list` |
| `staffDailyReportApprove` | `dj.api.smartcarlife.staff.daily.report.approve` |
| `querySceneRefByShop` | `dj.api.scenemerchantref.querySceneRefByShop` |
| `staffDailyReportMerchantCarBand` | `dj.api.smartcarlife.staff.daily.report.car.brand` |
| `getDateRecord` | `dj.api.mindworkplate.app.daily.report.mySubmittedDateRecord` |
| `getRecordDetail` | `dj.api.mindworkplate.app.daily.report.myRecordDetail` |
| `getWeeklyRecordDetail` | `dj.api.carboutique.assign.month.find.staff.weekly.report.submit` |
| `getMonthCalWeek` | `dj.api.carboutique.assign.month.cal.week` |
| `getMonthlyRecordDetail` | `dj.api.carboutique.assign.year.find.staff.monthly.report.submit` |
| `saveTempReport` | `dj.api.mindworkplate.app.daily.report.save` |
| `getStaffList` | `dj.api.mindworkplate.app.daily.report.staffBaseInfo.page` |
| `dailyReportCheck` | `dj.api.smartcarlife.staff.daily.report.data.check` |
| `userStat` | `dj.api.smartcarlife.user.stat` |
| `outputValueStatistics` | `dj.api.smartcarlife.vehicle.damage.upgrade.quotation.outputValueStatistics` |
`staffDailyReportMerchantValid` 留在 `tabWorkOrder/api.js`,因为迁移范围外页面和主包弹窗队列仍消费它。
{
"id": "subpackage-ai-work-report-split",
"title": "权益 AI 与旧版工作日报独立分包迁移",
"sourceProject": "dj-car-boutique-work-wechat",
"affectedPaths": [
"app.json",
"router",
"store",
"utils",
"packageEquity",
"tabWorkOrder",
"tabIndex",
"packageUsedCar",
"packageDynamicForm",
"tests",
"docs"
],
"interfaces": [
"packageEquityAI semantic routes and legacy packageEquity route aliases",
"packageWorkReport semantic routes and legacy tabWorkOrder route aliases",
"AI API request.post method, payload identity, gateway and transport flags",
"work report API request.post method and payload identity",
"H5 page mapping, login allowlist and wx.$SCENE path",
"cross-package imports, usingComponents78 and WXS src references"
],
"tests": [
{
"id": "subpackage-api-forwarding-contracts",
"file": "tests/subpackage-split/api-contracts.test.mjs",
"level": "contract",
"expectedBefore": "pass",
"status": "pass"
},
{
"id": "subpackage-navigation-baseline",
"file": "tests/subpackage-split/navigation-baseline.test.mjs",
"level": "integration",
"expectedBefore": "pass",
"status": "pass"
}
],
"baseline": {
"command": "npm run test:subpackage-split",
"result": "44/44 pass at ca558bec before production code migration"
},
"apiInventory": "docs/migrations/subpackage-ai-work-report-split/api-inventory.md",
"acceptance": "docs/migrations/subpackage-ai-work-report-split/test-acceptance.md",
"verification": {
"commands": [
{
"command": "npm run test:subpackage-split",
"status": "pass"
},
{
"command": "npm test",
"status": "pass"
},
{
"command": "node scripts/check-subpackage-boundaries.mjs",
"status": "blocked",
"blocker": "The migration boundary scanner is created during the implementation phase."
},
{
"command": "npm run check:subpackage-size",
"status": "blocked",
"blocker": "The per-package size gate is created after the two target subpackages exist."
},
{
"command": "git diff --check",
"status": "pass"
}
]
}
}
# AI 与工作日报分包测试验收
## 基线
- 基线提交:`ca558bec`
- 建立日期:2026-09-04
- `npm test`:通过(建立迁移计划前执行)
- `npm run test:subpackage-split`:44/44 通过
- `node scripts/scan-component-paths.mjs`:`BROKEN_COMPONENT_PATHS=0`
- `node scripts/scan-broken-imports.mjs`:基线 `CRITICAL_CROSS_ROOT=2`、`OTHER_BROKEN=23`;均不在迁移目标目录,迁移后总数不得增加,新包必须为 0
- `project.config.json` 已整体忽略 `tests` 与 `docs`,并保持 `ignoreUploadUnusedFiles: true`,所以新增测试和迁移资料不会进入上传包
## 自动化用例
| 编号 | 层级 | 范围 | 改造前 | 改造后 |
| --- | --- | --- | --- | --- |
| SS-API-001 | contract | 21 个 AI facade 完整 transport 参数与 rejection | pass | 尚未执行 |
| SS-API-002 | contract | 16 个旧版日报 facade method 与 payload identity | pass | 尚未执行 |
| SS-NAV-001 | integration | 权益/轻改旧版日报选择 | pass | 尚未执行 |
| SS-NAV-002 | integration | 日/周/月主管日报菜单参数 | pass | 尚未执行 |
| SS-NAV-003 | integration | AI 菜单与任务提醒 query | pass | 尚未执行 |
| SS-NAV-004 | integration | H5 page 映射与免登录规则 | pass | 尚未执行 |
| SS-BOUNDARY-001 | static | 新包同步依赖、usingComponents、WXS 路径 | 尚未建立 | 尚未执行 |
| SS-SIZE-001 | static | 四个相关包源码预算与 DevTools 包体 | 尚未建立 | 尚未执行 |
## 真机矩阵
| 编号 | 平台 | 路径 | 改造前 | 改造后 |
| --- | --- | --- | --- | --- |
| SS-DEVICE-AI-ANDROID | Android | AI 菜单→开始→场景→对话→结果→返回 | 等待扫码执行 | 尚未执行 |
| SS-DEVICE-AI-IOS | iOS | AI 菜单→开始→场景→对话→结果→返回 | 等待扫码执行 | 尚未执行 |
| SS-DEVICE-TASK-ANDROID | Android | 对练提醒携参进入任务→详情/结果→返回 | 等待扫码执行 | 尚未执行 |
| SS-DEVICE-TASK-IOS | iOS | 对练提醒携参进入任务→详情/结果→返回 | 等待扫码执行 | 尚未执行 |
| SS-DEVICE-REPORT-ANDROID | Android | 驻店日报与日/周/月主管日报加载、保存、批复、返回 | 等待扫码执行 | 尚未执行 |
| SS-DEVICE-REPORT-IOS | iOS | 驻店日报与日/周/月主管日报加载、保存、批复、返回 | 等待扫码执行 | 尚未执行 |
| SS-DEVICE-H5-ANDROID | Android | H5 `staffDaily`、`upgradeStaffDaily`、`aiDetail` 深链 | 等待扫码执行 | 尚未执行 |
| SS-DEVICE-H5-IOS | iOS | H5 `staffDaily`、`upgradeStaffDaily`、`aiDetail` 深链 | 等待扫码执行 | 尚未执行 |
## 契约门禁状态
- 日报 16 个 ROP method:最新 develop Swagger 已全部确认。
- AI 的 3 个 ROP method:最新 develop Swagger 已确认。
- AI 的 9 个派练 ROP method:当前 `axios` Swagger 未收录,运行时 `/rop-dj-pairexc` Swagger 返回 HTTP 502;API 文件写入保持暂停。
- 9 个非 ROP AI HTTP path:已由 transport 特征测试锁定。
## 发布判定
只有自动化、开发者工具预览、Android 与 iOS 真机矩阵均通过,并且迁移 post 门禁通过,才标记为发布验收完成。设备或外部服务不可用时可以记录阻塞证据,但不能算发布通过。
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
"test:orderLifecycle:ui": "node --test tests/order-lifecycle/ui/miniProgramSmoke.live.test.mjs", "test:orderLifecycle:ui": "node --test tests/order-lifecycle/ui/miniProgramSmoke.live.test.mjs",
"test:storeDailyReport:ui": "node --test tests/store-daily-report/ui/storeDailyReport.live.test.mjs", "test:storeDailyReport:ui": "node --test tests/store-daily-report/ui/storeDailyReport.live.test.mjs",
"test:quotation": "node --experimental-detect-module --test packageEquity/tests/quotationCustomerDailyFields.test.mjs packageEquity/tests/quotationCustomerDailyFields.ui.test.mjs packageEquity/tests/quotationMoney.helpers.test.mjs packageEquity/tests/quotationPayload.helpers.test.mjs packageEquity/tests/ruleFn.test.mjs", "test:quotation": "node --experimental-detect-module --test packageEquity/tests/quotationCustomerDailyFields.test.mjs packageEquity/tests/quotationCustomerDailyFields.ui.test.mjs packageEquity/tests/quotationMoney.helpers.test.mjs packageEquity/tests/quotationPayload.helpers.test.mjs packageEquity/tests/ruleFn.test.mjs",
"test:subpackage-split": "node --experimental-detect-module --test tests/subpackage-split",
"test:components": "node --test tests/popupBehavior.test.mjs tests/calendarMonthMode.test.mjs tests/componentsImageUrl.test.mjs tests/technicianSelect.helpers.test.mjs tests/sideSelectDataSource.test.mjs tests/storePickerConfirm.test.mjs", "test:components": "node --test tests/popupBehavior.test.mjs tests/calendarMonthMode.test.mjs tests/componentsImageUrl.test.mjs tests/technicianSelect.helpers.test.mjs tests/sideSelectDataSource.test.mjs tests/storePickerConfirm.test.mjs",
"knowledge:build": "node scripts/knowledge-graph/knowledge-build.mjs", "knowledge:build": "node scripts/knowledge-graph/knowledge-build.mjs",
"knowledge:check": "node scripts/knowledge-graph/knowledge-check.mjs", "knowledge:check": "node scripts/knowledge-graph/knowledge-check.mjs",
......
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
AI_API_CONTRACTS,
WORK_REPORT_API_CONTRACTS
} from './fixtures/api-contracts.mjs'
import { loadApiFacade } from './support/load-api-facade.mjs'
const ALL_CONTRACTS = [...AI_API_CONTRACTS, ...WORK_REPORT_API_CONTRACTS]
function createRequestSpy(result = { code: 0 }) {
const calls = []
return {
calls,
post(...args) {
calls.push({
method: args[0],
payload: args[1],
extraArgs: args.slice(2)
})
return Promise.resolve(result)
}
}
}
describe('subpackage split API forwarding contracts', () => {
for (const contract of ALL_CONTRACTS) {
it(`${contract.id} preserves method, payload identity and transport args`, async () => {
const requestSpy = createRequestSpy()
const facade = await loadApiFacade(contract.source, requestSpy)
const payload = { marker: contract.id }
const result = contract.acceptsPayload === false
? await facade[contract.name]()
: await facade[contract.name](payload)
assert.deepEqual(result, { code: 0 })
assert.equal(requestSpy.calls.length, 1)
assert.deepEqual(requestSpy.calls[0], {
method: contract.method,
payload: contract.acceptsPayload === false ? undefined : payload,
extraArgs: contract.extraArgs
})
if (contract.acceptsPayload !== false) {
assert.equal(requestSpy.calls[0].payload, payload)
}
})
}
it('does not swallow transport rejection', async () => {
const transportError = new Error('transport rejected')
const facade = await loadApiFacade('packageEquity/aiApi.js', {
post: () => Promise.reject(transportError)
})
await assert.rejects(
() => facade.sparring({ marker: 'reject' }),
error => error === transportError
)
})
})
/**
* @file 分包迁移前后的 API 转发契约。这里只锁定 transport 调用,不推断业务响应。
*/
const freezeContracts = contracts =>
Object.freeze(
contracts.map(contract =>
Object.freeze({
...contract,
extraArgs: Object.freeze([...(contract.extraArgs || [])])
})
)
)
/** AI 页面当前实际使用的 API facade 契约。 */
export const AI_API_CONTRACTS = freezeContracts([
{
id: 'ai.sparring',
source: 'packageEquity/aiApi.js',
name: 'sparring',
method: '',
extraArgs: [[], '/router/sparring/1.0.0', 'AI', false]
},
{
id: 'ai.objectionSparring',
source: 'packageEquity/aiApi.js',
name: 'objectionSparring',
method: '',
extraArgs: [[], '/router/objection/sparring/1.0.0', 'AI', false]
},
{
id: 'ai.inspiration',
source: 'packageEquity/aiApi.js',
name: 'inspiration',
method: '',
extraArgs: [[], '/router/inspiration/1.0.0', 'AI']
},
{
id: 'ai.objectionInspiration',
source: 'packageEquity/aiApi.js',
name: 'objectionInspiration',
method: '',
extraArgs: [[], '/router/objection/inspiration/1.0.0', 'AI']
},
{
id: 'ai.enhancement',
source: 'packageEquity/aiApi.js',
name: 'enhancement',
method: '',
extraArgs: [[], '/router/enhancement/1.0.0', 'AI', false]
},
{
id: 'ai.objectionEnhancement',
source: 'packageEquity/aiApi.js',
name: 'objectionEnhancement',
method: '',
extraArgs: [[], '/router/objection/enhancement/1.0.0', 'AI', false]
},
{
id: 'ai.getSensitive',
source: 'packageEquity/aiApi.js',
name: 'getSensitive',
method: '',
extraArgs: [[], '/router/is/sensitive/1.0.0', 'AI', false]
},
{
id: 'ai.getPhrases',
source: 'packageEquity/aiApi.js',
name: 'getPhrases',
method: '',
extraArgs: [[], '/router/similar/phrases/1.0.0', 'AI', false]
},
{
id: 'ai.getVoice',
source: 'packageEquity/aiApi.js',
name: 'getVoice',
method: '',
extraArgs: [[], '/router/get/voice/to/text/1.0.0', 'AI', false]
},
{
id: 'ai.getSparringPage',
source: 'packageEquity/aiApi.js',
name: 'getSparringPage',
method: 'dj.api.carboutique.ai.sparring.staff.record.page',
extraArgs: [[], '/rop-dj-pairexc/router']
},
{
id: 'ai.setSparringVerify',
source: 'packageEquity/aiApi.js',
name: 'setSparringVerify',
method: 'dj.api.carboutique.ai.sparring.verify',
extraArgs: [[], '/rop-dj-pairexc/router']
},
{
id: 'ai.getToken',
source: 'packageEquity/aiApi.js',
name: 'getToken',
method: 'dj.api.smartcarlife.recepiton.customer.oss.getToken',
acceptsPayload: false
},
{
id: 'car.getInspectionDetail',
source: 'packageEquity/carEquityApi.js',
name: 'getInspectionDetail',
method: 'dj.api.smartcarlife.app.inspection.conversation.check.detail'
},
{
id: 'car.getSparringPage',
source: 'packageEquity/carEquityApi.js',
name: 'getSparringPage',
method: 'dj.api.carboutique.ai.sparring.task.page',
extraArgs: [[], '/rop-dj-pairexc/router']
},
{
id: 'car.getSparringDetail',
source: 'packageEquity/carEquityApi.js',
name: 'getSparringDetail',
method: 'dj.api.carboutique.ai.sparring.task.staff.detail.page',
extraArgs: [[], '/rop-dj-pairexc/router']
},
{
id: 'car.getSparringResult',
source: 'packageEquity/carEquityApi.js',
name: 'getSparringResult',
method: 'dj.api.carboutique.ai.sparring.detail.check.result',
extraArgs: [[], '/rop-dj-pairexc/router']
},
{
id: 'car.sparringCommit',
source: 'packageEquity/carEquityApi.js',
name: 'sparringCommit',
method: 'dj.api.carboutique.ai.sparring.detail.commit',
extraArgs: [[], '/rop-dj-pairexc/router']
},
{
id: 'car.behaviorSave',
source: 'packageEquity/carEquityApi.js',
name: 'behaviorSave',
method: 'dj.api.carboutique.ai.sparring.staff.behavior.save',
extraArgs: [[], '/rop-dj-pairexc/router']
},
{
id: 'car.objectionPage',
source: 'packageEquity/carEquityApi.js',
name: 'objectionPage',
method: 'dj.api.carboutique.ai.sparring.objection.page',
extraArgs: [[], '/rop-dj-pairexc/router']
},
{
id: 'car.sparringRole',
source: 'packageEquity/carEquityApi.js',
name: 'sparringRole',
method: 'dj.api.carboutique.ai.sparring.role.info.page',
extraArgs: [[], '/rop-dj-pairexc/router']
},
{
id: 'car.sparringRrain',
source: 'packageEquity/carEquityApi.js',
name: 'sparringRrain',
method: 'dj.api.carboutique.ai.sparring.start.train',
extraArgs: [[], '/rop-dj-pairexc/router']
}
])
/** 旧版员工、主管日报页面当前实际使用的 API facade 契约。 */
export const WORK_REPORT_API_CONTRACTS = freezeContracts([
['staffDailyReportSave', 'dj.api.smartcarlife.staff.daily.report.save'],
['staffDailyReportDetail', 'dj.api.smartcarlife.staff.daily.report.detail'],
['staffDailyReportDetailWeeklyList', 'dj.api.smartcarlife.staff.daily.report.weekly.list'],
['staffDailyReportApprove', 'dj.api.smartcarlife.staff.daily.report.approve'],
['querySceneRefByShop', 'dj.api.scenemerchantref.querySceneRefByShop'],
['staffDailyReportMerchantCarBand', 'dj.api.smartcarlife.staff.daily.report.car.brand'],
['getDateRecord', 'dj.api.mindworkplate.app.daily.report.mySubmittedDateRecord'],
['getRecordDetail', 'dj.api.mindworkplate.app.daily.report.myRecordDetail'],
['getWeeklyRecordDetail', 'dj.api.carboutique.assign.month.find.staff.weekly.report.submit'],
['getMonthCalWeek', 'dj.api.carboutique.assign.month.cal.week'],
['getMonthlyRecordDetail', 'dj.api.carboutique.assign.year.find.staff.monthly.report.submit'],
['saveTempReport', 'dj.api.mindworkplate.app.daily.report.save'],
['getStaffList', 'dj.api.mindworkplate.app.daily.report.staffBaseInfo.page'],
['dailyReportCheck', 'dj.api.smartcarlife.staff.daily.report.data.check'],
['userStat', 'dj.api.smartcarlife.user.stat'],
['outputValueStatistics', 'dj.api.smartcarlife.vehicle.damage.upgrade.quotation.outputValueStatistics']
].map(([name, method]) => ({
id: `report.${name}`,
source: 'tabWorkOrder/api.js',
name,
method
})))
import { describe, it, mock } from 'node:test'
import assert from 'node:assert/strict'
import {
loadMiniProgramDefinition,
loadSourceExports
} from './support/load-mini-program-source.mjs'
globalThis.wx = {
getAccountInfoSync: () => ({ miniProgram: { envVersion: 'release' } }),
getDeviceInfo: () => ({ platform: 'devtools' }),
getWindowInfo: () => ({
windowWidth: 375,
windowHeight: 667,
statusBarHeight: 20,
pixelRatio: 2,
screenWidth: 375,
screenHeight: 667,
safeArea: { top: 20, bottom: 667, height: 647 }
}),
getAppBaseInfo: () => ({
SDKVersion: '3.0.0',
host: 'WeChat',
version: '8.0.0',
language: 'zh_CN'
}),
$hasPermission: {
isSuper: () => false,
isNotMentor: () => true,
canSelectMultiStore: () => false,
canSelectMultiStoreForStaffDaily: () => false,
canViewMentorship: () => false,
canViewRecruit: () => false,
canViewViolation: () => false
}
}
globalThis.getApp = () => ({ globalData: { isStaff: true } })
const { resolveLegacyStaffDailyRoute } = await import('../../utils/staffDailyReportNavigation.js')
const { EQUITY_MENU_REGISTRY, ASYNC_MENU_REGISTRY: EQUITY_ASYNC_MENUS } =
await import('../../packageEquity/menu/registry.js')
const { MENU_REGISTRY } = await import('../../tabIndex/menu/registry.js')
function findById(items, id) {
const item = items.find(candidate => candidate.id === id)
assert.ok(item, `menu not found: ${id}`)
return item
}
describe('subpackage split navigation baseline', () => {
it('keeps legacy staff report route selection by scene type', () => {
assert.deepEqual(resolveLegacyStaffDailyRoute({ sceneType: 0 }), {
type: 'router',
route: 'tabWorkOrder.staffDaily',
params: { scene: 0 }
})
assert.deepEqual(resolveLegacyStaffDailyRoute({ sceneType: 1 }), {
type: 'router',
route: 'tabWorkOrder.upgradeStaffDaily',
params: {}
})
})
for (const [source, menus] of [
['equity', EQUITY_MENU_REGISTRY],
['home', MENU_REGISTRY]
]) {
it(`${source} work report menus preserve type and reportTypeAttr`, () => {
const expected = [
['work_daily_report', 'daily', '1'],
['work_weekly_report', 'weekly', '2'],
['work_monthly_report', 'monthly', '3']
]
for (const [id, reportTypeAttr, reportTypeVal] of expected) {
const item = findById(menus, id)
assert.equal(item.action.type, 'workReport')
assert.equal(item.action.target, 'tabWorkOrder.supervisorDaily')
assert.equal(item.reportTypeAttr, reportTypeAttr)
assert.equal(item.reportTypeVal, reportTypeVal)
}
})
}
it('AI menu enters the current start alias', () => {
const item = findById(EQUITY_ASYNC_MENUS, 'ai_fun_practice')
assert.deepEqual(item.action, {
type: 'router',
target: 'packageEquity.start'
})
})
it('AI task reminder preserves staff and task query values', async () => {
const go = mock.fn()
const wxMock = {
getStorageSync: () => undefined,
setStorageSync: mock.fn(),
$util: { getUserInfo: () => ({ merchantId: 'merchant-1' }) },
$hasPermission: { canSelectMultiStore: () => false },
$router: { go },
__HAS_NOTLOGIN_MODAL: false
}
class TestDate extends Date {
format() { return '2026-09-04' }
}
const definition = await loadMiniProgramDefinition(
'packageEquity/pages/TabBar/equityPage.js',
{
wx: wxMock,
getApp: () => ({ globalData: { isStaff: true } }),
require: () => ({}),
Date: TestDate,
IMG_URL: 'https://static.example/',
carLifeApi: {
getSparringPage: async () => ({
data: {
list: [{
task: { aiType: 7, promptOnOff: true },
staff: { id: 'staff-9', tryCount: 1 }
}]
}
})
}
}
)
await definition.checkTask.call({
addModalToQueue(_title, _content, _confirmText, _showCancel, _priority, callback) {
callback({ confirm: true })
}
})
assert.equal(
go.mock.calls[0].arguments[0],
'packageEquity.list?staffid=staff-9&tryCount=1&roleType=7&promptOnOff=true'
)
})
it('H5 scene mapping keeps report allowlist and AI login requirement', async () => {
const wxMock = {
$util: { getStorageSync: () => undefined },
$SCENE: null
}
const { checkScene } = await loadSourceExports('store/index.js', {
wx: wxMock,
console: { log() {}, error() {}, warn() {} },
getApp: () => ({ globalData: {} }),
api: {},
envIndex: 0,
removeSystemStorage: () => {},
util: { removeStorage: () => {} },
getSystemInfo: () => ({})
})
for (const [page, path] of [
['staffDaily', 'tabWorkOrder/pages/staffDaily/staffDaily'],
['upgradeStaffDaily', 'tabWorkOrder/pages/upgradeStaffDaily/upgradeStaffDaily']
]) {
const options = { query: { page } }
assert.equal(checkScene(options), undefined)
assert.equal(options.path, path)
}
const aiOptions = { query: { page: 'aiDetail' } }
assert.equal(checkScene(aiOptions), '未登录,请登录。')
assert.equal(aiOptions.path, 'packageEquity/pages/aiExcercise/ai/ai')
})
})
/**
* @file 在 Node 测试中注入 request spy,加载小程序 API facade;不执行真实网络请求。
*/
import { readFile } from 'node:fs/promises'
import path from 'node:path'
const projectRoot = path.resolve(process.cwd())
/**
* 加载 API facade,并以 spy 替代 `~/utils/request/request.js`。
* @param {string} relativePath 仓库内 API 文件路径
* @param {{post: Function}} requestSpy request facade spy
* @returns {Promise<object>} API facade
*/
export async function loadApiFacade(relativePath, requestSpy) {
const absolutePath = path.resolve(projectRoot, relativePath)
const relativeToRoot = path.relative(projectRoot, absolutePath)
if (
relativeToRoot === '..' ||
relativeToRoot.startsWith(`..${path.sep}`) ||
path.isAbsolute(relativeToRoot)
) {
throw new Error(`API facade must stay inside project: ${relativePath}`)
}
const source = await readFile(absolutePath, 'utf8')
const executable = source
.replace(/^\s*import\s+api\s+from\s+['"][^'"]+['"];?\s*$/m, '')
.replace(/export\s+default\s+/, 'const __facade = ')
.replace(/module\.exports\s*=\s*/, 'const __facade = ')
if (!executable.includes('const __facade = ')) {
throw new Error(`Unsupported API facade export: ${relativePath}`)
}
return new Function('api', `${executable}\nreturn __facade;`)(requestSpy)
}
/**
* @file 以依赖注入方式加载小程序页面或 ES 模块,仅用于迁移行为特征测试。
*/
import { readFile } from 'node:fs/promises'
import path from 'node:path'
import { parse } from '@babel/parser'
import generatorModule from '@babel/generator'
const generate = generatorModule.default || generatorModule
const projectRoot = path.resolve(process.cwd())
async function transformSource(relativePath) {
const absolutePath = path.resolve(projectRoot, relativePath)
const relativeToRoot = path.relative(projectRoot, absolutePath)
if (
relativeToRoot === '..' ||
relativeToRoot.startsWith(`..${path.sep}`) ||
path.isAbsolute(relativeToRoot)
) {
throw new Error(`Source must stay inside project: ${relativePath}`)
}
const source = await readFile(absolutePath, 'utf8')
const ast = parse(source, { sourceType: 'module' })
const exportNames = []
const body = []
for (const node of ast.program.body) {
if (node.type === 'ImportDeclaration') continue
if (node.type === 'ExportNamedDeclaration') {
if (node.declaration) {
body.push(node.declaration)
if (node.declaration.type === 'VariableDeclaration') {
for (const declaration of node.declaration.declarations) {
if (declaration.id.type === 'Identifier') exportNames.push(declaration.id.name)
}
} else if (node.declaration.id?.name) {
exportNames.push(node.declaration.id.name)
}
}
for (const specifier of node.specifiers || []) {
exportNames.push(specifier.local.name)
}
continue
}
if (node.type === 'ExportDefaultDeclaration') {
body.push({
type: 'VariableDeclaration',
kind: 'const',
declarations: [{
type: 'VariableDeclarator',
id: { type: 'Identifier', name: '__defaultExport' },
init: node.declaration
}]
})
exportNames.push('__defaultExport')
continue
}
body.push(node)
}
ast.program.body = body
return { code: generate(ast).code, exportNames }
}
/**
* 加载模块的命名导出,import 依赖由调用方显式注入。
* @param {string} relativePath 仓库内模块路径
* @param {Record<string, unknown>} [dependencies] 顶层依赖
* @returns {Promise<Record<string, unknown>>} 模块导出
*/
export async function loadSourceExports(relativePath, dependencies = {}) {
const { code, exportNames } = await transformSource(relativePath)
const names = Object.keys(dependencies)
const values = Object.values(dependencies)
const resultExpression = exportNames
.map(name => `${JSON.stringify(name)}: ${name}`)
.join(',')
return new Function(...names, `${code}\nreturn {${resultExpression}};`)(...values)
}
/**
* 捕获 Page/Component 注册对象,便于直接验证页面编排行为。
* @param {string} relativePath 仓库内页面脚本
* @param {Record<string, unknown>} [dependencies] 页面顶层依赖
* @param {'Page'|'Component'} [registerName] 注册函数名
* @returns {Promise<object>} 页面或组件定义
*/
export async function loadMiniProgramDefinition(
relativePath,
dependencies = {},
registerName = 'Page'
) {
const { code } = await transformSource(relativePath)
let definition
const register = value => {
definition = value
}
const injected = { ...dependencies, [registerName]: register }
new Function(...Object.keys(injected), code)(...Object.values(injected))
if (!definition) throw new Error(`${registerName} was not registered: ${relativePath}`)
return definition
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!