docs/test(P19ERP1-5,P19ERP1-6): 收口ERP文档矩阵与回归
这个提交包含在:
+9
-2
@@ -1,7 +1,7 @@
|
||||
# 领域事件清单(P19 / P19+IM-1)
|
||||
# 领域事件清单(P19 / P19+IM-1 / P19+ERP-1)
|
||||
|
||||
**快照日期**:2026-03-08
|
||||
**目标**:冻结 `hyb-oa` 当前采购与资产域的标准领域事件名,并补充 `P19+IM-1` 已实际消费的 IM 通知类型清单,作为后续 ERP / IM / AI 适配的事实源。
|
||||
**目标**:冻结 `hyb-oa` 当前采购与资产域的标准领域事件名,并补充 `P19+IM-1` 已实际消费的 IM 通知类型清单,以及 `P19+ERP-1` 已实际落地的 ERP 消费映射,作为后续 ERP / IM / AI 适配的事实源。
|
||||
|
||||
## 1. 使用原则
|
||||
- 本文档同时维护两类事实:
|
||||
@@ -90,3 +90,10 @@
|
||||
- `inventory_check.started`
|
||||
|
||||
这些事件名称仍保留在长期蓝图中,但不属于 `P19+IM-1` 的首批协同覆盖范围。
|
||||
|
||||
## 10. P19+ERP-1 已实现消费映射
|
||||
- `P19+ERP-1` 没有新增新的领域事件名;当前 ERP 一期真正落地消费的既有业务事实是 `reimbursement.paid`。
|
||||
- 运行时不会把 ERP 专有结构写回核心报销表,而是先构建标准化 `ReimbursementJournalSlice`,再通过 `erp.journal.export` 写入 `IntegrationOutbox` 异步派发。
|
||||
- `ReimbursementJournalSlice.sourceEventName` 固定为 `reimbursement.paid`,用于标记该凭证切片来源于“报销付款完成”这一既有业务事实。
|
||||
- ERP 主数据同步(`LegalEntity` / `CostCenter` / `Supplier`)属于主动 Pull,不作为新的领域事件名纳入本表。
|
||||
- `purchase_request.approved`、`asset.card.created`、`inventory_check.completed` 等事件仍只冻结名称与最小载荷;真实 ERP 导出留待后续 `P19+ERP-2 / ERP-3`。
|
||||
|
||||
+12
-3
@@ -1,8 +1,8 @@
|
||||
# hyb-oa 实现状态矩阵(P5-P19+IM-1)
|
||||
# hyb-oa 实现状态矩阵(P5-P19+IM-1+ERP-1)
|
||||
|
||||
**快照日期**:2026-03-08
|
||||
**范围**:`F1-F42`(含 `F19b/F19c/F19d`)+ `R1-S2` + `P9A1-P9D1` + `P10E1-P10G1` + `G0-G6` + `H1` + `M1-M4` + `P13-0-P13-8` + `P14-0-P14-8` + `P15A-0-P15A-5` + `P15B-0-P15B-6` + `P16A-0-P16A-6` + `P16B-0-P16B-6` + `P16C-0-P16C-6` + `R9-0-R9-3` + `G2-0-G2-6` + `P17A-0-P17A-6` + `P17B-0-P17B-6` + `P18A-0-P18A-6` + `P18B-0-P18B-6` + `P19-0-P19-6` + `P19IM1-0-P19IM1-6`,共 199 项。
|
||||
**事实源**:`issues/2026-02-09_13-39-02-p5-blueprint-v3.csv` + `issues/2026-02-09_23-30-00-p6-p8-remaining-work-master.csv` + `issues/2026-02-10_09-42-31-p9-maintenance-performance-matrix.csv` + `issues/2026-02-10_10-35-30-p10-production-hardening.csv` + `issues/2026-02-11-p11-p12-governance-mobile.csv` + `issues/2026-02-12_01-09-41-p13-l5-governance.csv` + `issues/2026-02-13_00-11-56-p14-l5-operationalization.csv` + `issues/2026-03-06_14-30-00-p15a-l5-permission-decouple.csv` + `issues/2026-03-06_14-30-00-p15b-l5-leave-v1.csv` + `issues/2026-03-07_13-47-05-p16a-l5-master-data-core.csv` + `issues/2026-03-07_16-22-07-p16b-l5-holiday-calendar.csv` + `issues/2026-03-07_17-14-39-p16c-l5-suppliers.csv` + `issues/2026-03-07_18-15-03-r9-g2-p19-roadmap-refresh.csv` + `issues/2026-03-07_18-16-00-g2-l5-cross-domain-bridge.csv` + `issues/2026-03-07_19-33-09-p17a-l5-procurement-core.csv` + `issues/2026-03-07_21-00-37-p17b-l5-procurement-budget-archive.csv` + `issues/2026-03-07_22-02-09-p18a-l5-asset-registry-core.csv` + `issues/2026-03-07_22-34-03-p18b-l5-asset-movements-inventory.csv` + `issues/2026-03-07_23-22-00-p19-l4-integration-readiness.csv` + `issues/2026-03-08_12-18-10-p19-im-1-l5-collaboration-adapter.csv`(执行合同)
|
||||
**范围**:`F1-F42`(含 `F19b/F19c/F19d`)+ `R1-S2` + `P9A1-P9D1` + `P10E1-P10G1` + `G0-G6` + `H1` + `M1-M4` + `P13-0-P13-8` + `P14-0-P14-8` + `P15A-0-P15A-5` + `P15B-0-P15B-6` + `P16A-0-P16A-6` + `P16B-0-P16B-6` + `P16C-0-P16C-6` + `R9-0-R9-3` + `G2-0-G2-6` + `P17A-0-P17A-6` + `P17B-0-P17B-6` + `P18A-0-P18A-6` + `P18B-0-P18B-6` + `P19-0-P19-6` + `P19IM1-0-P19IM1-6` + `P19ERP1-0-P19ERP1-6`,共 206 项。
|
||||
**事实源**:`issues/2026-02-09_13-39-02-p5-blueprint-v3.csv` + `issues/2026-02-09_23-30-00-p6-p8-remaining-work-master.csv` + `issues/2026-02-10_09-42-31-p9-maintenance-performance-matrix.csv` + `issues/2026-02-10_10-35-30-p10-production-hardening.csv` + `issues/2026-02-11-p11-p12-governance-mobile.csv` + `issues/2026-02-12_01-09-41-p13-l5-governance.csv` + `issues/2026-02-13_00-11-56-p14-l5-operationalization.csv` + `issues/2026-03-06_14-30-00-p15a-l5-permission-decouple.csv` + `issues/2026-03-06_14-30-00-p15b-l5-leave-v1.csv` + `issues/2026-03-07_13-47-05-p16a-l5-master-data-core.csv` + `issues/2026-03-07_16-22-07-p16b-l5-holiday-calendar.csv` + `issues/2026-03-07_17-14-39-p16c-l5-suppliers.csv` + `issues/2026-03-07_18-15-03-r9-g2-p19-roadmap-refresh.csv` + `issues/2026-03-07_18-16-00-g2-l5-cross-domain-bridge.csv` + `issues/2026-03-07_19-33-09-p17a-l5-procurement-core.csv` + `issues/2026-03-07_21-00-37-p17b-l5-procurement-budget-archive.csv` + `issues/2026-03-07_22-02-09-p18a-l5-asset-registry-core.csv` + `issues/2026-03-07_22-34-03-p18b-l5-asset-movements-inventory.csv` + `issues/2026-03-07_23-22-00-p19-l4-integration-readiness.csv` + `issues/2026-03-08_12-18-10-p19-im-1-l5-collaboration-adapter.csv` + `issues/2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv`(执行合同)
|
||||
|
||||
**说明**:
|
||||
- 本矩阵用于全局读图(审计/交接/回归覆盖追踪),不替代 `issues/*.csv` 的执行合同职责。
|
||||
@@ -229,3 +229,12 @@
|
||||
| P19IM1-4 | 前端渠道管理页与导航入口 | N/A | 2026-03-08_12-18-10-p19-im-1-l5-collaboration-adapter.csv | 2026-03-08_12-18-10-p19-im-1-l5-collaboration-adapter.csv | 2026-03-08 | DONE | client:typecheck/build | 新增 `NotificationChannelsPage`、`/system/notification-channels` 路由与菜单入口,支持测试发送 |
|
||||
| P19IM1-5 | OpenAPI文档与矩阵同步 | N/A | 2026-03-08_12-18-10-p19-im-1-l5-collaboration-adapter.csv | 2026-03-08_12-18-10-p19-im-1-l5-collaboration-adapter.csv | 2026-03-08 | DONE | validate-feature-matrix | 集成边界、领域事件与 Feature Matrix 更新到 `P5-P19+IM-1` 并纳入新合同事实源 |
|
||||
| P19IM1-6 | P19IM1回归与验收收口 | N/A | 2026-03-08_12-18-10-p19-im-1-l5-collaboration-adapter.csv | 2026-03-08_12-18-10-p19-im-1-l5-collaboration-adapter.csv | 2026-03-08 | DONE | server:test + regression-all + client:typecheck/build | 企微 mock / webhook、渠道后台、业务入队与回归脚本全部通过,且站内通知 / 邮件零回归 |
|
||||
|
||||
| P19ERP1-0 | P19ERP1执行合同建档 | N/A | 2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv | 2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv | 2026-03-08 | DONE | CSV 校验 | ERP 主数据同步与报销付款凭证桥接执行合同建档,冻结先入后出与不污染核心域原则 |
|
||||
| P19ERP1-1 | ERP适配契约与集成层模型 | N/A | 2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv | 2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv | 2026-03-08 | DONE | prisma:validate + server:test | 新增 `IntegrationBinding` / `IntegrationSyncState` 与 ERP provider 扩展契约,且不向核心事务表写 ERP 私有字段 |
|
||||
| P19ERP1-2 | 主数据入站同步服务与接口 | N/A | 2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv | 2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv | 2026-03-08 | DONE | server:test + regression-integrations | `LegalEntity`、`CostCenter`、`Supplier` 支持 ERP 全量 Pull、状态查询与可选 cron,同步冲突与 skip 语义可追踪 |
|
||||
| P19ERP1-3 | 报销付款凭证切片出站 | N/A | 2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv | 2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv | 2026-03-08 | DONE | server:test + regression-integrations + regression-all | `reimbursement.paid` 可预览标准 journal slice,并通过 `erp.journal.export` Outbox 导出;旧 `/api/integrations/erp/sync/:id` 继续兼容 |
|
||||
| P19ERP1-4 | ERP管理页与报销详情导出入口 | N/A | 2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv | 2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv | 2026-03-08 | DONE | client:typecheck/build | 新增 `ErpIntegrationPage`、系统导航入口与报销详情 ERP 导出卡片,支持手动同步与导出反馈 |
|
||||
| P19ERP1-5 | OpenAPI文档与矩阵同步 | N/A | 2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv | 2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv | 2026-03-08 | DONE | validate-feature-matrix | 集成边界、领域事件、Feature Matrix 与校验器同步到 `P5-P19+IM-1+ERP-1`,并纳入 ERP-1 合同事实源 |
|
||||
| P19ERP1-6 | P19ERP1回归与安全收口 | N/A | 2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv | 2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv | 2026-03-08 | DONE | server:test + regression-integrations + regression-all + client:typecheck/build | 主数据 Pull、报销凭证切片、ERP 管理入口、开关阻断与 dead_letter 重入全部通过,且既有主流程零回归 |
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# 集成边界冻结(P19 / P19+IM-1)
|
||||
# 集成边界冻结(P19 / P19+IM-1 / P19+ERP-1)
|
||||
|
||||
**快照日期**:2026-03-08
|
||||
**当前基线**:`P19+IM-1` 已完成,当前运行时已落地企微群机器人 + 深链 + Outbox 异步派发的一期协同适配。
|
||||
**目标**:在保持核心域稳定的前提下,冻结 ERP / IM / AI / MCP 的长期边界,并记录 IM 一期的已实现范围与后续禁入规则。
|
||||
**当前基线**:`P19+IM-1` 与 `P19+ERP-1` 已完成;当前运行时已落地企微群机器人 + 深链 + Outbox 异步派发的一期协同适配,以及 ERP 主数据 Pull / 报销付款凭证切片的一期桥接。
|
||||
**目标**:在保持核心域稳定的前提下,冻结 ERP / IM / AI / MCP 的长期边界,并记录 IM 一期与 ERP 一期的已实现范围、禁入规则和后续扩展位。
|
||||
|
||||
## 1. 总体原则
|
||||
|
||||
@@ -51,6 +51,13 @@
|
||||
- `P19+ERP-2`:采购审批结果导出 / 回写协议
|
||||
- `P19+ERP-3`:资产台账摘要导出协议
|
||||
|
||||
### 2.5 P19+ERP-1 已实现范围
|
||||
- 已新增 `IntegrationBinding` 与 `IntegrationSyncState` 两张集成层私有表,用于维护 ERP 映射与同步状态,不向核心事务表注入 ERP 私有字段。
|
||||
- 已实现 `LegalEntity`、`CostCenter`、`Supplier` 的 ERP 全量 Pull,同步方式固定为 `manual + cron`;其中 `ERP_MASTER_DATA_SYNC_CRON` 为空时不自动调度。
|
||||
- 已实现 `reimbursement.paid` 的标准化凭证切片导出,运行时通过 `erp.journal.export` 写入 `IntegrationOutbox` 并由 dispatcher 异步派发。
|
||||
- 已兼容保留历史 `erp.reimbursement.paid` 派发路径;成功导出后统一回写 `integration_bindings(provider=erp, entity_type=reimbursement_journal)`。
|
||||
- 已明确 `ERP_SYNC_ENABLED` 与 `erp_sync` feature flag 共同构成 ERP 管理端总闸,任一关闭都必须阻断主数据同步与手动导出。
|
||||
|
||||
## 3. IM / 协同适配边界
|
||||
|
||||
### 3.1 一期已实现能力(P19+IM-1)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
ID,Title,Description,Acceptance,Test_Method,Tools,Dev_Status,Review1_Status,Regression_Status,Files,Dependencies,Notes
|
||||
P19ERP1-0,P19ERP1执行合同建档,创建并校验P19ERP1主数据同步与凭证切片执行合同CSV,CSV通过校验且字段完整,python3 /home/shunli/.codex/skills/plan/scripts/validate_issues_csv.py issues/2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv,manual,DONE,DONE,DONE,issues/2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv,[],P19ERP1先做主数据入站与报销付款凭证切片 不进入采购资产真实过账
|
||||
P19ERP1-1,ERP适配契约与集成层模型,新增IntegrationBinding与IntegrationSyncState并扩展ERP provider契约,不向核心事务表写ERP私有字段且provider支持master data pull与journal export两类能力,cd server && npm run prisma:validate && npm run test,manual,TODO,TODO,TODO,server/prisma/schema.prisma | server/src/services/integrations/erp.js | server/src/config.js | server/tests,"[""P19ERP1-0""]",仅允许新增集成层私有表 不得把ERP字段塞入LegalEntity CostCenter Supplier PurchaseRequest AssetCard
|
||||
P19ERP1-2,主数据入站同步服务与接口,实现LegalEntity CostCenter Supplier的ERP拉取同步 手动接口 状态查询与cron作业,三类主数据可按业务键幂等upsert并记录同步状态 停用仅归档不硬删,cd server && npm run test && ./scripts/regression-integrations.sh,manual,TODO,TODO,TODO,server/src/routes/integrations.js | server/src/services/integrations/erpMasterData.js | server/src/jobs | server/tests,"[""P19ERP1-1""]",同步顺序固定为LegalEntity再CostCenter再Supplier 无稳定supplier code则安全skip
|
||||
P19ERP1-3,报销付款凭证切片出站,将现有erp.reimbursement.paid泛化为erp.journal.export并提供预览与导出接口,paid报销单可预览标准凭证切片并通过Outbox导出ERP且旧接口保持兼容,cd server && npm run test && OCR_PROVIDER=mock JOBS_ENABLED=false ./scripts/regression-all.sh,manual,TODO,TODO,TODO,server/src/routes/reimbursements.js | server/src/routes/integrations.js | server/src/services/integrations/erpJournal.js | server/src/services/integrations/dispatcher.js | server/src/services/integrations/outbox.js | server/tests,"[""P19ERP1-2""]",ERP-1只实装reimbursement paid journal export 采购资产仅保留后续扩展位
|
||||
P19ERP1-4,ERP管理页与报销详情导出入口,新增ERP集成管理页并在报销详情页增加ERP导出卡片,integrations后台可查看主数据同步状态且paid报销详情可执行ERP导出,cd client && npm run typecheck && npm run build,manual,TODO,TODO,TODO,client/src/pages/ErpIntegrationPage.tsx | client/src/pages/ReimbursementDetailPage.tsx | client/src/api/integrations.ts | client/src/router/index.tsx | client/src/components/navigation/NavLinks.tsx,"[""P19ERP1-3""]",继续使用integration.manage 不新增ERP配置大表单
|
||||
P19ERP1-5,OpenAPI文档与矩阵同步,同步ERP-1接口说明 集成边界 事件映射与Feature Matrix事实源,Feature Matrix收口到P5-P19+IM-1+ERP-1且事实源纳入新合同,python3 scripts/validate-feature-matrix.py,manual,TODO,TODO,TODO,docs/integration-boundaries.md | docs/domain-events.md | docs/feature-matrix.md | scripts/validate-feature-matrix.py | issues/2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv,"[""P19ERP1-4""]",矩阵总数从199更新到206 并追加P19ERP1-0到P19ERP1-6
|
||||
P19ERP1-6,P19ERP1回归与安全收口,完成主数据同步 凭证切片 后台入口与集成回归验证后再进入下一专项,ERP mock与http模式可回归 关闭ERP开关时核心业务零回归且无越权导出,cd server && npm run test && ./scripts/regression-integrations.sh && OCR_PROVIDER=mock JOBS_ENABLED=false ./scripts/regression-all.sh && cd ../client && npm run typecheck && npm run build,manual,TODO,TODO,TODO,issues/2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv | server/scripts/regression-integrations.sh | client/src/pages/ErpIntegrationPage.tsx | client/src/pages/ReimbursementDetailPage.tsx,"[""P19ERP1-5""]",重点核对主数据绑定冲突 凭证死信重入 越权导出与ERP 4xx 5xx timeout处理
|
||||
ID,Title,Description,Acceptance,Test_Method,Tools,Dev_Status,Review1_Status,Regression_Status,Files,Dependencies,Notes
|
||||
P19ERP1-0,P19ERP1执行合同建档,创建并校验P19ERP1主数据同步与凭证切片执行合同CSV,CSV通过校验且字段完整,python3 /home/shunli/.codex/skills/plan/scripts/validate_issues_csv.py issues/2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv,manual,DONE,DONE,DONE,issues/2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv,[],P19ERP1先做主数据入站与报销付款凭证切片 不进入采购资产真实过账
|
||||
P19ERP1-1,ERP适配契约与集成层模型,新增IntegrationBinding与IntegrationSyncState并扩展ERP provider契约,不向核心事务表写ERP私有字段且provider支持master data pull与journal export两类能力,cd server && npm run prisma:validate && npm run test,manual,DONE,DONE,DONE,server/prisma/schema.prisma | server/src/services/integrations/erp.js | server/src/config.js | server/tests,"[""P19ERP1-0""]",仅允许新增集成层私有表 不得把ERP字段塞入LegalEntity CostCenter Supplier PurchaseRequest AssetCard
|
||||
P19ERP1-2,主数据入站同步服务与接口,实现LegalEntity CostCenter Supplier的ERP拉取同步 手动接口 状态查询与cron作业,三类主数据可按业务键幂等upsert并记录同步状态 停用仅归档不硬删,cd server && npm run test && ./scripts/regression-integrations.sh,manual,DONE,DONE,DONE,server/src/routes/integrations.js | server/src/services/integrations/erpMasterData.js | server/src/jobs | server/tests,"[""P19ERP1-1""]",同步顺序固定为LegalEntity再CostCenter再Supplier 无稳定supplier code则安全skip
|
||||
P19ERP1-3,报销付款凭证切片出站,将现有erp.reimbursement.paid泛化为erp.journal.export并提供预览与导出接口,paid报销单可预览标准凭证切片并通过Outbox导出ERP且旧接口保持兼容,cd server && npm run test && OCR_PROVIDER=mock JOBS_ENABLED=false ./scripts/regression-all.sh,manual,DONE,DONE,DONE,server/src/routes/reimbursements.js | server/src/routes/integrations.js | server/src/services/integrations/erpJournal.js | server/src/services/integrations/dispatcher.js | server/src/services/integrations/outbox.js | server/tests,"[""P19ERP1-2""]",ERP-1只实装reimbursement paid journal export 采购资产仅保留后续扩展位
|
||||
P19ERP1-4,ERP管理页与报销详情导出入口,新增ERP集成管理页并在报销详情页增加ERP导出卡片,integrations后台可查看主数据同步状态且paid报销详情可执行ERP导出,cd client && npm run typecheck && npm run build,manual,DONE,DONE,DONE,client/src/pages/ErpIntegrationPage.tsx | client/src/pages/ReimbursementDetailPage.tsx | client/src/api/integrations.ts | client/src/router/index.tsx | client/src/components/navigation/NavLinks.tsx,"[""P19ERP1-3""]",继续使用integration.manage 不新增ERP配置大表单
|
||||
P19ERP1-5,OpenAPI文档与矩阵同步,同步ERP-1接口说明 集成边界 事件映射与Feature Matrix事实源,Feature Matrix收口到P5-P19+IM-1+ERP-1且事实源纳入新合同,python3 scripts/validate-feature-matrix.py,manual,DONE,DONE,DONE,docs/integration-boundaries.md | docs/domain-events.md | docs/feature-matrix.md | scripts/validate-feature-matrix.py | issues/2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv,"[""P19ERP1-4""]",矩阵总数从199更新到206 并追加P19ERP1-0到P19ERP1-6
|
||||
P19ERP1-6,P19ERP1回归与安全收口,完成主数据同步 凭证切片 后台入口与集成回归验证后再进入下一专项,ERP mock与http模式可回归 关闭ERP开关时核心业务零回归且无越权导出,cd server && npm run test && ./scripts/regression-integrations.sh && OCR_PROVIDER=mock JOBS_ENABLED=false ./scripts/regression-all.sh && cd ../client && npm run typecheck && npm run build,manual,DONE,DONE,DONE,issues/2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv | server/scripts/regression-integrations.sh | client/src/pages/ErpIntegrationPage.tsx | client/src/pages/ReimbursementDetailPage.tsx,"[""P19ERP1-5""]",重点核对主数据绑定冲突 凭证死信重入 越权导出与ERP 4xx 5xx timeout处理
|
||||
|
||||
|
@@ -39,6 +39,7 @@ CSV_FACT_SOURCES = [
|
||||
ROOT / "issues" / "2026-03-07_22-34-03-p18b-l5-asset-movements-inventory.csv",
|
||||
ROOT / "issues" / "2026-03-07_23-22-00-p19-l4-integration-readiness.csv",
|
||||
ROOT / "issues" / "2026-03-08_12-18-10-p19-im-1-l5-collaboration-adapter.csv",
|
||||
ROOT / "issues" / "2026-03-08_14-10-53-p19-erp-1-l5-masterdata-journal-bridge.csv",
|
||||
]
|
||||
|
||||
ID_PATTERN = re.compile(r"^[A-Z][0-9][0-9A-Za-z-]*$")
|
||||
|
||||
@@ -3,6 +3,16 @@ set -euo pipefail
|
||||
|
||||
ERP_SYNC_TIMEOUT_MS="${ERP_SYNC_TIMEOUT_MS:-300}"
|
||||
MOCK_ERP_PORT="${MOCK_ERP_PORT:-$((3900 + RANDOM % 500))}"
|
||||
APP_PORT="${APP_PORT:-$((4300 + RANDOM % 500))}"
|
||||
BASE_URL="http://127.0.0.1:${APP_PORT}"
|
||||
DEVICE_FINGERPRINT="${DEVICE_FINGERPRINT:-regression-integrations}"
|
||||
FINANCE_MGR_IDENTIFIER="${FINANCE_MGR_IDENTIFIER:-finance_mgr@hyinda.com}"
|
||||
FINANCE_MGR_PASSWORD="${FINANCE_MGR_PASSWORD:-FinanceMgrPassword1234}"
|
||||
RUN_SUFFIX="$(date +%s)-$RANDOM"
|
||||
RUN_SUFFIX_NUMERIC="${RUN_SUFFIX//[^0-9]/}"
|
||||
LEGAL_ENTITY_CODE="LE${RUN_SUFFIX_NUMERIC}"
|
||||
COST_CENTER_CODE="CC${RUN_SUFFIX_NUMERIC}"
|
||||
SUPPLIER_CODE="SUP${RUN_SUFFIX_NUMERIC}"
|
||||
|
||||
if ! command -v node >/dev/null 2>&1; then
|
||||
echo "[ERROR] node not found" >&2
|
||||
@@ -35,10 +45,15 @@ if [[ -z "${DATABASE_URL:-}" ]]; then
|
||||
fi
|
||||
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
RUN_SUFFIX="$(date +%s)-$RANDOM"
|
||||
MOCK_SERVER_PID=""
|
||||
APP_SERVER_PID=""
|
||||
TOKEN=""
|
||||
|
||||
cleanup() {
|
||||
if [[ -n "$APP_SERVER_PID" ]] && kill -0 "$APP_SERVER_PID" >/dev/null 2>&1; then
|
||||
kill "$APP_SERVER_PID" >/dev/null 2>&1 || true
|
||||
wait "$APP_SERVER_PID" >/dev/null 2>&1 || true
|
||||
fi
|
||||
if [[ -n "$MOCK_SERVER_PID" ]] && kill -0 "$MOCK_SERVER_PID" >/dev/null 2>&1; then
|
||||
kill "$MOCK_SERVER_PID" >/dev/null 2>&1 || true
|
||||
wait "$MOCK_SERVER_PID" >/dev/null 2>&1 || true
|
||||
@@ -47,31 +62,102 @@ cleanup() {
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
assert_status() {
|
||||
local actual="$1"
|
||||
local expected="$2"
|
||||
local name="$3"
|
||||
if [[ "$actual" != "$expected" ]]; then
|
||||
echo "[ERROR] $name expected HTTP $expected but got $actual" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
start_mock_erp_server() {
|
||||
local server_file="$TMP_DIR/mock-erp-server.js"
|
||||
|
||||
cat >"$server_file" <<'NODE'
|
||||
const http = require("node:http");
|
||||
const { URL } = require("node:url");
|
||||
const http = require('node:http');
|
||||
const { URL } = require('node:url');
|
||||
|
||||
const port = Number(process.argv[2] || 3900);
|
||||
const runSuffix = String(process.env.RUN_SUFFIX ?? '001');
|
||||
const runDigits = runSuffix.replace(/\D+/g, '');
|
||||
const legalEntityCode = `LE${runDigits}`;
|
||||
const costCenterCode = `CC${runDigits}`;
|
||||
const supplierCode = `SUP${runDigits}`;
|
||||
|
||||
function sendJson(res, status, payload) {
|
||||
res.statusCode = status;
|
||||
res.setHeader("content-type", "application/json; charset=utf-8");
|
||||
res.setHeader('content-type', 'application/json; charset=utf-8');
|
||||
res.end(JSON.stringify(payload));
|
||||
}
|
||||
|
||||
const server = http.createServer(async (req, res) => {
|
||||
const url = new URL(req.url, `http://${req.headers.host || `127.0.0.1:${port}`}`);
|
||||
|
||||
if (req.method === "GET" && url.pathname === "/health") {
|
||||
return sendJson(res, 200, { ok: true, mode: "health" });
|
||||
if (req.method === 'GET' && url.pathname === '/health') {
|
||||
return sendJson(res, 200, { ok: true, mode: 'health' });
|
||||
}
|
||||
|
||||
if (req.method === "POST" && url.pathname === "/erp/reimbursements/paid") {
|
||||
const mode = url.searchParams.get("mode") || "success";
|
||||
if (req.method === 'POST' && url.pathname === '/erp/master-data/pull') {
|
||||
const mode = url.searchParams.get('mode') || 'success';
|
||||
if (mode === 'timeout') {
|
||||
setTimeout(() => {
|
||||
sendJson(res, 200, { ok: true, delayed: true });
|
||||
}, 1500);
|
||||
return;
|
||||
}
|
||||
if (mode === 'client') {
|
||||
return sendJson(res, 422, { ok: false, code: 'invalid_payload', message: 'mock client error' });
|
||||
}
|
||||
if (mode === 'server') {
|
||||
return sendJson(res, 503, { ok: false, code: 'service_unavailable', message: 'mock server error' });
|
||||
}
|
||||
|
||||
return sendJson(res, 200, {
|
||||
ok: true,
|
||||
legalEntities: [
|
||||
{
|
||||
externalId: `ERP-${legalEntityCode}`,
|
||||
code: legalEntityCode,
|
||||
name: `法体-${runSuffix}`,
|
||||
shortName: `法体-${runDigits}`,
|
||||
currencyCode: 'CNY',
|
||||
taxNo: `TAX-${runDigits}`,
|
||||
enabled: true,
|
||||
},
|
||||
],
|
||||
costCenters: [
|
||||
{
|
||||
externalId: `ERP-${costCenterCode}`,
|
||||
legalEntityCode,
|
||||
code: costCenterCode,
|
||||
name: `成本中心-${runSuffix}`,
|
||||
enabled: true,
|
||||
},
|
||||
],
|
||||
suppliers: [
|
||||
{
|
||||
externalId: `ERP-${supplierCode}`,
|
||||
legalEntityCode,
|
||||
code: supplierCode,
|
||||
name: `供应商-${runSuffix}`,
|
||||
shortName: `供应商-${runDigits}`,
|
||||
taxNo: `SUP-TAX-${runDigits}`,
|
||||
contactName: '张三',
|
||||
contactPhone: '13800000000',
|
||||
paymentTerms: '月结30天',
|
||||
enabled: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
if (
|
||||
req.method === 'POST' &&
|
||||
(url.pathname === '/erp/journals/reimbursements/paid' || url.pathname === '/erp/reimbursements/paid')
|
||||
) {
|
||||
const mode = url.searchParams.get('mode') || 'success';
|
||||
const chunks = [];
|
||||
for await (const chunk of req) {
|
||||
chunks.push(chunk);
|
||||
@@ -79,58 +165,58 @@ const server = http.createServer(async (req, res) => {
|
||||
|
||||
let parsedBody = null;
|
||||
try {
|
||||
parsedBody = JSON.parse(Buffer.concat(chunks).toString("utf8") || "{}");
|
||||
parsedBody = JSON.parse(Buffer.concat(chunks).toString('utf8') || '{}');
|
||||
} catch {
|
||||
parsedBody = null;
|
||||
}
|
||||
|
||||
if (mode === "timeout") {
|
||||
if (mode === 'timeout') {
|
||||
setTimeout(() => {
|
||||
sendJson(res, 200, {
|
||||
ok: true,
|
||||
scenario: "timeout",
|
||||
scenario: 'timeout',
|
||||
externalId: `ERP-TIMEOUT-${Date.now()}`,
|
||||
reimbursementId: parsedBody?.reimbursementId || null,
|
||||
reimbursementId: parsedBody?.reimbursementId || parsedBody?.entityId || null,
|
||||
});
|
||||
}, 1500);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode === "client") {
|
||||
if (mode === 'client') {
|
||||
return sendJson(res, 422, {
|
||||
ok: false,
|
||||
scenario: "client",
|
||||
code: "invalid_payload",
|
||||
message: "mock client error",
|
||||
scenario: 'client',
|
||||
code: 'invalid_payload',
|
||||
message: 'mock client error',
|
||||
});
|
||||
}
|
||||
|
||||
if (mode === "server") {
|
||||
if (mode === 'server') {
|
||||
return sendJson(res, 503, {
|
||||
ok: false,
|
||||
scenario: "server",
|
||||
code: "service_unavailable",
|
||||
message: "mock server error",
|
||||
scenario: 'server',
|
||||
code: 'service_unavailable',
|
||||
message: 'mock server error',
|
||||
});
|
||||
}
|
||||
|
||||
return sendJson(res, 200, {
|
||||
ok: true,
|
||||
scenario: "success",
|
||||
externalId: `ERP-${parsedBody?.formNumber || parsedBody?.reimbursementId || Date.now()}`,
|
||||
reimbursementId: parsedBody?.reimbursementId || null,
|
||||
scenario: 'success',
|
||||
externalId: `ERP-${parsedBody?.documentNo || parsedBody?.formNumber || parsedBody?.entityId || Date.now()}`,
|
||||
reimbursementId: parsedBody?.reimbursementId || parsedBody?.entityId || null,
|
||||
});
|
||||
}
|
||||
|
||||
sendJson(res, 404, { ok: false, message: "not_found" });
|
||||
sendJson(res, 404, { ok: false, message: 'not_found' });
|
||||
});
|
||||
|
||||
server.listen(port, "127.0.0.1", () => {
|
||||
server.listen(port, '127.0.0.1', () => {
|
||||
process.stdout.write(`mock-erp-listening:${port}\n`);
|
||||
});
|
||||
NODE
|
||||
|
||||
node "$server_file" "$MOCK_ERP_PORT" >"$TMP_DIR/mock-erp.log" 2>&1 &
|
||||
RUN_SUFFIX="$RUN_SUFFIX" node "$server_file" "$MOCK_ERP_PORT" >"$TMP_DIR/mock-erp.log" 2>&1 &
|
||||
MOCK_SERVER_PID="$!"
|
||||
|
||||
for _ in $(seq 1 30); do
|
||||
@@ -145,180 +231,71 @@ NODE
|
||||
exit 1
|
||||
}
|
||||
|
||||
create_paid_reimbursement_and_enqueue() {
|
||||
local scenario="$1"
|
||||
DATABASE_URL="$DATABASE_URL" RUN_SUFFIX="$RUN_SUFFIX" SCENARIO="$scenario" node <<'NODE'
|
||||
require("dotenv/config");
|
||||
|
||||
const { createPrismaClient } = require("./src/prismaClient");
|
||||
const { getConfig } = require("./src/config");
|
||||
const { buildErpPayload } = require("./src/services/integrations/erp");
|
||||
const { enqueueIntegrationEvent } = require("./src/services/integrations/outbox");
|
||||
|
||||
(async () => {
|
||||
const runSuffix = process.env.RUN_SUFFIX;
|
||||
const scenario = process.env.SCENARIO;
|
||||
const config = getConfig();
|
||||
const { prisma, pool } = createPrismaClient();
|
||||
|
||||
await prisma.$connect();
|
||||
try {
|
||||
const owner = await prisma.employee.findFirst({
|
||||
where: {
|
||||
email: {
|
||||
in: ["[email protected]", "[email protected]"],
|
||||
},
|
||||
},
|
||||
select: { id: true, department_id: true },
|
||||
orderBy: { created_at: "asc" },
|
||||
});
|
||||
|
||||
if (!owner) {
|
||||
throw new Error("employee/finance_mgr not found");
|
||||
}
|
||||
|
||||
const reimbursement = await prisma.reimbursementForm.create({
|
||||
data: {
|
||||
form_number: `BX-P10-${scenario}-${runSuffix}`.slice(0, 60),
|
||||
submitter_id: owner.id,
|
||||
owner_id: owner.id,
|
||||
department_id: owner.department_id,
|
||||
reimbursement_date: new Date("2026-02-10T00:00:00.000Z"),
|
||||
total_amount: "100.00",
|
||||
status: "paid",
|
||||
payment_voucher_no: `PV-${scenario}-${runSuffix}`.slice(0, 60),
|
||||
payment_date: new Date("2026-02-10T00:00:00.000Z"),
|
||||
paid_at: new Date(),
|
||||
created_by: owner.id,
|
||||
updated_by: owner.id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
form_number: true,
|
||||
owner_id: true,
|
||||
submitter_id: true,
|
||||
total_amount: true,
|
||||
payment_voucher_no: true,
|
||||
payment_date: true,
|
||||
paid_at: true,
|
||||
},
|
||||
});
|
||||
|
||||
const payload = buildErpPayload({ reimbursement });
|
||||
const enqueued = await enqueueIntegrationEvent(prisma, {
|
||||
eventType: "erp.reimbursement.paid",
|
||||
payload,
|
||||
dedupeKey: reimbursement.id,
|
||||
maxAttempts: config.integrationOutboxMaxAttempts,
|
||||
actorId: owner.id,
|
||||
});
|
||||
|
||||
process.stdout.write(
|
||||
JSON.stringify({
|
||||
scenario,
|
||||
reimbursementId: reimbursement.id,
|
||||
outboxId: enqueued.id,
|
||||
duplicated: enqueued.duplicated,
|
||||
}),
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
await pool.end();
|
||||
}
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
NODE
|
||||
}
|
||||
|
||||
query_outbox_state() {
|
||||
local outbox_id="$1"
|
||||
DATABASE_URL="$DATABASE_URL" OUTBOX_ID="$outbox_id" node <<'NODE'
|
||||
require("dotenv/config");
|
||||
|
||||
const { createPrismaClient } = require("./src/prismaClient");
|
||||
|
||||
(async () => {
|
||||
const outboxId = process.env.OUTBOX_ID;
|
||||
const { prisma, pool } = createPrismaClient();
|
||||
await prisma.$connect();
|
||||
|
||||
try {
|
||||
const row = await prisma.integrationOutbox.findUnique({
|
||||
where: { id: outboxId },
|
||||
select: {
|
||||
id: true,
|
||||
status: true,
|
||||
attempts: true,
|
||||
next_retry_at: true,
|
||||
dead_letter_at: true,
|
||||
last_error: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!row) {
|
||||
throw new Error(`outbox not found: ${outboxId}`);
|
||||
}
|
||||
|
||||
process.stdout.write(
|
||||
JSON.stringify({
|
||||
id: row.id,
|
||||
status: row.status,
|
||||
attempts: row.attempts,
|
||||
nextRetryAt: row.next_retry_at ? row.next_retry_at.toISOString() : null,
|
||||
deadLetterAt: row.dead_letter_at ? row.dead_letter_at.toISOString() : null,
|
||||
lastError: row.last_error,
|
||||
}),
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
await pool.end();
|
||||
}
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
NODE
|
||||
}
|
||||
|
||||
run_outbox_once() {
|
||||
local endpoint="$1"
|
||||
start_app_server() {
|
||||
PORT="$APP_PORT" \
|
||||
HOST="127.0.0.1" \
|
||||
JOBS_ENABLED=false \
|
||||
OCR_PROVIDER=mock \
|
||||
ERP_SYNC_ENABLED=true \
|
||||
ERP_SYNC_PROVIDER=http \
|
||||
ERP_SYNC_ENDPOINT="$endpoint" \
|
||||
ERP_MASTER_DATA_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/master-data/pull?mode=success" \
|
||||
ERP_JOURNAL_EXPORT_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/journals/reimbursements/paid?mode=success" \
|
||||
ERP_SYNC_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/reimbursements/paid?mode=success" \
|
||||
ERP_SYNC_TIMEOUT_MS="$ERP_SYNC_TIMEOUT_MS" \
|
||||
ERP_MASTER_DATA_TIMEOUT_MS="$ERP_SYNC_TIMEOUT_MS" \
|
||||
ERP_SYNC_AUTH_TOKEN="" \
|
||||
npm run --silent job:integration-outbox-once >"$TMP_DIR/outbox-once.log"
|
||||
node src/index.js >"$TMP_DIR/app.log" 2>&1 &
|
||||
APP_SERVER_PID="$!"
|
||||
|
||||
for _ in $(seq 1 60); do
|
||||
if curl -sS "$BASE_URL/health" >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
sleep 0.5
|
||||
done
|
||||
|
||||
echo "[ERROR] app server failed to start" >&2
|
||||
cat "$TMP_DIR/app.log" >&2 || true
|
||||
exit 1
|
||||
}
|
||||
|
||||
login_finance_mgr() {
|
||||
local login_body="$TMP_DIR/login.json"
|
||||
local login_status
|
||||
login_status="$(curl -sS -o "$login_body" -w "%{http_code}" \
|
||||
-X POST "$BASE_URL/api/auth/login" \
|
||||
-H "content-type: application/json" \
|
||||
-H "x-device-fingerprint: ${DEVICE_FINGERPRINT}-finance" \
|
||||
-d "{\"identifier\":\"$FINANCE_MGR_IDENTIFIER\",\"password\":\"$FINANCE_MGR_PASSWORD\"}")"
|
||||
assert_status "$login_status" "200" "finance_mgr login"
|
||||
TOKEN="$(jq -er '.data.accessToken' "$login_body")"
|
||||
}
|
||||
|
||||
set_erp_flag() {
|
||||
local mode="$1"
|
||||
DATABASE_URL="$DATABASE_URL" MODE="$mode" node <<'NODE'
|
||||
require("dotenv/config");
|
||||
|
||||
const { createPrismaClient } = require("./src/prismaClient");
|
||||
require('dotenv/config');
|
||||
const { createPrismaClient } = require('./src/prismaClient');
|
||||
|
||||
(async () => {
|
||||
const mode = process.env.MODE;
|
||||
const { prisma, pool } = createPrismaClient();
|
||||
await prisma.$connect();
|
||||
|
||||
try {
|
||||
await prisma.featureFlag.upsert({
|
||||
where: { flag_key: "erp_sync" },
|
||||
where: { flag_key: 'erp_sync' },
|
||||
create: {
|
||||
flag_key: "erp_sync",
|
||||
flag_key: 'erp_sync',
|
||||
override_mode: mode,
|
||||
rollout_type: "global",
|
||||
rollout_type: 'global',
|
||||
department_ids: [],
|
||||
note: "regression-integrations",
|
||||
note: 'regression-integrations',
|
||||
},
|
||||
update: {
|
||||
override_mode: mode,
|
||||
rollout_type: "global",
|
||||
rollout_type: 'global',
|
||||
department_ids: [],
|
||||
note: "regression-integrations",
|
||||
note: 'regression-integrations',
|
||||
version: { increment: 1 },
|
||||
},
|
||||
});
|
||||
@@ -333,10 +310,250 @@ const { createPrismaClient } = require("./src/prismaClient");
|
||||
NODE
|
||||
}
|
||||
|
||||
echo "[0/6] Ensure ERP feature flag force_on"
|
||||
set_erp_flag "force_on"
|
||||
create_paid_reimbursement() {
|
||||
DATABASE_URL="$DATABASE_URL" RUN_SUFFIX="$RUN_SUFFIX" node <<'NODE'
|
||||
require('dotenv/config');
|
||||
|
||||
assert_mode_semantics() {
|
||||
const { createPrismaClient } = require('./src/prismaClient');
|
||||
|
||||
(async () => {
|
||||
const runSuffix = process.env.RUN_SUFFIX;
|
||||
const { prisma, pool } = createPrismaClient();
|
||||
await prisma.$connect();
|
||||
try {
|
||||
const owner = await prisma.employee.findFirst({
|
||||
where: {
|
||||
email: {
|
||||
in: ['[email protected]', '[email protected]'],
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
department_id: true,
|
||||
legal_entity_id: true,
|
||||
},
|
||||
orderBy: { created_at: 'asc' },
|
||||
});
|
||||
|
||||
if (!owner) {
|
||||
throw new Error('seed employee not found');
|
||||
}
|
||||
|
||||
const uniqueSuffix = `${runSuffix}-${Date.now()}-${Math.floor(Math.random() * 1000000)}`;
|
||||
|
||||
const reimbursement = await prisma.reimbursementForm.create({
|
||||
data: {
|
||||
form_number: `BX-ERP-${uniqueSuffix}`.slice(0, 60),
|
||||
submitter_id: owner.id,
|
||||
owner_id: owner.id,
|
||||
department_id: owner.department_id,
|
||||
reimbursement_date: new Date('2026-03-08T00:00:00.000Z'),
|
||||
total_amount: '100.00',
|
||||
status: 'paid',
|
||||
payment_voucher_no: `PV-ERP-${uniqueSuffix}`.slice(0, 60),
|
||||
payment_date: new Date('2026-03-08T00:00:00.000Z'),
|
||||
paid_at: new Date(),
|
||||
created_by: owner.id,
|
||||
updated_by: owner.id,
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
process.stdout.write(reimbursement.id);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
await pool.end();
|
||||
}
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
NODE
|
||||
}
|
||||
|
||||
query_outbox_state() {
|
||||
local outbox_id="$1"
|
||||
DATABASE_URL="$DATABASE_URL" OUTBOX_ID="$outbox_id" node <<'NODE'
|
||||
require('dotenv/config');
|
||||
const { createPrismaClient } = require('./src/prismaClient');
|
||||
|
||||
(async () => {
|
||||
const outboxId = process.env.OUTBOX_ID;
|
||||
const { prisma, pool } = createPrismaClient();
|
||||
await prisma.$connect();
|
||||
try {
|
||||
const row = await prisma.integrationOutbox.findUnique({
|
||||
where: { id: outboxId },
|
||||
select: {
|
||||
id: true,
|
||||
event_type: true,
|
||||
status: true,
|
||||
attempts: true,
|
||||
next_retry_at: true,
|
||||
processed_at: true,
|
||||
dead_letter_at: true,
|
||||
last_error: true,
|
||||
},
|
||||
});
|
||||
if (!row) {
|
||||
throw new Error(`outbox not found: ${outboxId}`);
|
||||
}
|
||||
process.stdout.write(JSON.stringify({
|
||||
id: row.id,
|
||||
eventType: row.event_type,
|
||||
status: row.status,
|
||||
attempts: row.attempts,
|
||||
nextRetryAt: row.next_retry_at ? row.next_retry_at.toISOString() : null,
|
||||
processedAt: row.processed_at ? row.processed_at.toISOString() : null,
|
||||
deadLetterAt: row.dead_letter_at ? row.dead_letter_at.toISOString() : null,
|
||||
lastError: row.last_error,
|
||||
}));
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
await pool.end();
|
||||
}
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
NODE
|
||||
}
|
||||
|
||||
query_binding_state() {
|
||||
local reimbursement_id="$1"
|
||||
DATABASE_URL="$DATABASE_URL" REIMBURSEMENT_ID="$reimbursement_id" node <<'NODE'
|
||||
require('dotenv/config');
|
||||
const { createPrismaClient } = require('./src/prismaClient');
|
||||
|
||||
(async () => {
|
||||
const reimbursementId = process.env.REIMBURSEMENT_ID;
|
||||
const { prisma, pool } = createPrismaClient();
|
||||
await prisma.$connect();
|
||||
try {
|
||||
const row = await prisma.integrationBinding.findUnique({
|
||||
where: {
|
||||
provider_entity_type_local_id: {
|
||||
provider: 'erp',
|
||||
entity_type: 'reimbursement_journal',
|
||||
local_id: reimbursementId,
|
||||
},
|
||||
},
|
||||
select: {
|
||||
external_id: true,
|
||||
external_code: true,
|
||||
last_synced_at: true,
|
||||
},
|
||||
});
|
||||
process.stdout.write(JSON.stringify({
|
||||
externalId: row?.external_id ?? null,
|
||||
externalCode: row?.external_code ?? null,
|
||||
lastSyncedAt: row?.last_synced_at ? row.last_synced_at.toISOString() : null,
|
||||
}));
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
await pool.end();
|
||||
}
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
NODE
|
||||
}
|
||||
|
||||
assert_master_data_seeded() {
|
||||
DATABASE_URL="$DATABASE_URL" LEGAL_ENTITY_CODE="$LEGAL_ENTITY_CODE" COST_CENTER_CODE="$COST_CENTER_CODE" SUPPLIER_CODE="$SUPPLIER_CODE" node <<'NODE'
|
||||
require('dotenv/config');
|
||||
const { createPrismaClient } = require('./src/prismaClient');
|
||||
|
||||
(async () => {
|
||||
const { prisma, pool } = createPrismaClient();
|
||||
await prisma.$connect();
|
||||
try {
|
||||
const legalEntity = await prisma.legalEntity.findUnique({
|
||||
where: { code: process.env.LEGAL_ENTITY_CODE },
|
||||
select: { id: true },
|
||||
});
|
||||
const supplier = await prisma.supplier.findUnique({
|
||||
where: { code: process.env.SUPPLIER_CODE },
|
||||
select: { id: true },
|
||||
});
|
||||
const costCenter = await prisma.costCenter.findFirst({
|
||||
where: { code: process.env.COST_CENTER_CODE },
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
if (!legalEntity || !costCenter || !supplier) {
|
||||
throw new Error('master data not synced as expected');
|
||||
}
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
await pool.end();
|
||||
}
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
NODE
|
||||
}
|
||||
|
||||
run_outbox_once() {
|
||||
local mode="$1"
|
||||
DATABASE_URL="$DATABASE_URL" \
|
||||
INTEGRATION_OUTBOX_BATCH_SIZE=500 \
|
||||
ERP_SYNC_ENABLED=true \
|
||||
ERP_SYNC_PROVIDER=http \
|
||||
ERP_JOURNAL_EXPORT_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/journals/reimbursements/paid?mode=$mode" \
|
||||
ERP_SYNC_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/reimbursements/paid?mode=$mode" \
|
||||
ERP_SYNC_TIMEOUT_MS="$ERP_SYNC_TIMEOUT_MS" \
|
||||
ERP_SYNC_AUTH_TOKEN="" \
|
||||
npm run --silent job:integration-outbox-once >"$TMP_DIR/outbox-once.log"
|
||||
}
|
||||
|
||||
assert_pull_mode() {
|
||||
local mode="$1"
|
||||
ERP_SYNC_ENABLED=true \
|
||||
ERP_SYNC_PROVIDER=http \
|
||||
ERP_MASTER_DATA_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/master-data/pull?mode=$mode" \
|
||||
ERP_MASTER_DATA_TIMEOUT_MS="$ERP_SYNC_TIMEOUT_MS" \
|
||||
ERP_SYNC_AUTH_TOKEN="" \
|
||||
node <<'NODE'
|
||||
const { pullMasterDataFromErp } = require('./src/services/integrations/erp');
|
||||
(async () => {
|
||||
const result = await pullMasterDataFromErp({
|
||||
erpSyncEnabled: true,
|
||||
erpSyncProvider: 'http',
|
||||
erpMasterDataEndpoint: process.env.ERP_MASTER_DATA_ENDPOINT,
|
||||
erpMasterDataTimeoutMs: Number(process.env.ERP_MASTER_DATA_TIMEOUT_MS ?? 300),
|
||||
erpSyncAuthToken: process.env.ERP_SYNC_AUTH_TOKEN ?? '',
|
||||
}, { resources: ['legal_entity'] });
|
||||
process.stdout.write(JSON.stringify(result));
|
||||
})().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
NODE
|
||||
}
|
||||
|
||||
api_get() {
|
||||
local path="$1"
|
||||
local out_file="$2"
|
||||
curl -sS -o "$out_file" -w "%{http_code}" \
|
||||
-H "authorization: Bearer $TOKEN" \
|
||||
"$BASE_URL$path"
|
||||
}
|
||||
|
||||
api_post() {
|
||||
local path="$1"
|
||||
local body="$2"
|
||||
local out_file="$3"
|
||||
curl -sS -o "$out_file" -w "%{http_code}" \
|
||||
-X POST "$BASE_URL$path" \
|
||||
-H "authorization: Bearer $TOKEN" \
|
||||
-H "content-type: application/json" \
|
||||
-d "$body"
|
||||
}
|
||||
|
||||
assert_export_mode_semantics() {
|
||||
local mode="$1"
|
||||
local state_json="$2"
|
||||
|
||||
@@ -363,20 +580,22 @@ assert_mode_semantics() {
|
||||
esac
|
||||
}
|
||||
|
||||
run_mode_case() {
|
||||
run_export_mode_case() {
|
||||
local mode="$1"
|
||||
local reimbursement_id
|
||||
reimbursement_id="$(create_paid_reimbursement)"
|
||||
|
||||
local created_json
|
||||
created_json="$(create_paid_reimbursement_and_enqueue "$mode")"
|
||||
local export_body="$TMP_DIR/export-$mode.json"
|
||||
local export_status
|
||||
export_status="$(api_post "/api/integrations/erp/journals/reimbursements/${reimbursement_id}/export?runNow=0" '{}' "$export_body")"
|
||||
assert_status "$export_status" "200" "journal export enqueue $mode"
|
||||
local outbox_id
|
||||
outbox_id="$(jq -er '.outboxId' <<<"$created_json")"
|
||||
|
||||
local endpoint="http://127.0.0.1:$MOCK_ERP_PORT/erp/reimbursements/paid?mode=$mode"
|
||||
outbox_id="$(jq -er '.data.outboxId' "$export_body")"
|
||||
|
||||
local state_json=""
|
||||
local status=""
|
||||
for _ in $(seq 1 8); do
|
||||
run_outbox_once "$endpoint"
|
||||
run_outbox_once "$mode"
|
||||
state_json="$(query_outbox_state "$outbox_id")"
|
||||
status="$(jq -r '.status' <<<"$state_json")"
|
||||
if [[ "$status" != "pending" && "$status" != "processing" ]]; then
|
||||
@@ -386,37 +605,122 @@ run_mode_case() {
|
||||
done
|
||||
|
||||
if [[ "$status" == "pending" || "$status" == "processing" ]]; then
|
||||
echo "[ERROR] mode=$mode did not finish processing" >&2
|
||||
echo "[ERROR] export mode=$mode did not finish processing" >&2
|
||||
echo "$state_json" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! assert_mode_semantics "$mode" "$state_json"; then
|
||||
echo "[ERROR] mode=$mode semantics assertion failed" >&2
|
||||
echo "$state_json" >&2
|
||||
exit 1
|
||||
assert_export_mode_semantics "$mode" "$state_json"
|
||||
|
||||
if [[ "$mode" == "success" ]]; then
|
||||
local binding_json
|
||||
binding_json="$(query_binding_state "$reimbursement_id")"
|
||||
jq -e '.externalId != null and .externalCode != null' <<<"$binding_json" >/dev/null
|
||||
fi
|
||||
|
||||
echo "[OK] mode=$mode outbox_status=$status"
|
||||
echo "[OK] export mode=$mode outbox_status=$status" >&2
|
||||
printf '%s' "$reimbursement_id"
|
||||
}
|
||||
|
||||
echo "[1/6] Start embedded mock ERP server"
|
||||
echo "[0/9] Ensure ERP feature flag force_on"
|
||||
set_erp_flag "force_on"
|
||||
|
||||
echo "[1/9] Start embedded mock ERP server"
|
||||
start_mock_erp_server
|
||||
|
||||
echo "[2/6] ERP success path => succeeded"
|
||||
run_mode_case "success"
|
||||
echo "[2/9] Start isolated app server"
|
||||
start_app_server
|
||||
|
||||
echo "[3/6] ERP 4xx path => dead_letter"
|
||||
run_mode_case "client"
|
||||
sleep 1
|
||||
|
||||
echo "[4/6] ERP 5xx path => failed(retryable)"
|
||||
run_mode_case "server"
|
||||
echo "[3/9] Login finance manager"
|
||||
login_finance_mgr
|
||||
|
||||
echo "[5/6] ERP timeout path => failed(retryable)"
|
||||
run_mode_case "timeout"
|
||||
echo "[4/9] ERP status + master data sync success"
|
||||
status_body="$TMP_DIR/status.json"
|
||||
status_code="$(api_get '/api/integrations/erp/master-data/status' "$status_body")"
|
||||
assert_status "$status_code" "200" "erp status"
|
||||
jq -e '.data.gate.provider == "http" and (.data.items | length) == 3' "$status_body" >/dev/null
|
||||
|
||||
sync_body="$TMP_DIR/master-sync.json"
|
||||
sync_code="$(api_post '/api/integrations/erp/master-data/sync' '{"resources":["legal_entity","cost_center","supplier"]}' "$sync_body")"
|
||||
assert_status "$sync_code" "200" "erp master data sync"
|
||||
jq -e '.data.items | all(.status == "succeeded")' "$sync_body" >/dev/null
|
||||
assert_master_data_seeded
|
||||
|
||||
echo "[5/9] ERP master data provider error modes"
|
||||
for mode in client server timeout; do
|
||||
mode_json="$(assert_pull_mode "$mode")"
|
||||
case "$mode" in
|
||||
client) jq -e '.ok == false and .code == "erp_master_data_http_4xx"' <<<"$mode_json" >/dev/null ;;
|
||||
server) jq -e '.ok == false and .code == "erp_master_data_http_5xx"' <<<"$mode_json" >/dev/null ;;
|
||||
timeout) jq -e '.ok == false and .code == "erp_master_data_timeout"' <<<"$mode_json" >/dev/null ;;
|
||||
esac
|
||||
echo "[OK] master-data mode=$mode validated"
|
||||
done
|
||||
|
||||
echo "[6/9] Preview paid reimbursement journal"
|
||||
preview_reimbursement_id="$(create_paid_reimbursement)"
|
||||
preview_body="$TMP_DIR/preview.json"
|
||||
preview_code="$(api_get "/api/integrations/erp/journals/reimbursements/${preview_reimbursement_id}/preview" "$preview_body")"
|
||||
assert_status "$preview_code" "200" "journal preview"
|
||||
jq -e '.data.journal.journalType == "reimbursement_paid" and .data.journal.entityId != null' "$preview_body" >/dev/null
|
||||
|
||||
echo "[7/9] Export journal success / 4xx / 5xx / timeout"
|
||||
run_export_mode_case success >/dev/null
|
||||
client_reimbursement_id="$(run_export_mode_case client)"
|
||||
run_export_mode_case server >/dev/null
|
||||
run_export_mode_case timeout >/dev/null
|
||||
|
||||
echo "[8/9] Dead-letter requeue + legacy alias"
|
||||
requeue_body="$TMP_DIR/requeue.json"
|
||||
requeue_code="$(api_post "/api/integrations/erp/journals/reimbursements/${client_reimbursement_id}/export?runNow=0" '{}' "$requeue_body")"
|
||||
assert_status "$requeue_code" "200" "journal export requeue"
|
||||
jq -e '.data.requeued == true and .data.duplicated == false' "$requeue_body" >/dev/null
|
||||
requeue_outbox_id="$(jq -er '.data.outboxId' "$requeue_body")"
|
||||
requeue_state="$(query_outbox_state "$requeue_outbox_id")"
|
||||
jq -e '.status == "pending" and .attempts == 0 and .lastError == null' <<<"$requeue_state" >/dev/null
|
||||
run_outbox_once success
|
||||
requeue_state_done="$(query_outbox_state "$requeue_outbox_id")"
|
||||
jq -e '.status == "succeeded"' <<<"$requeue_state_done" >/dev/null
|
||||
|
||||
legacy_reimbursement_id="$(create_paid_reimbursement)"
|
||||
legacy_body="$TMP_DIR/legacy-export.json"
|
||||
legacy_code="$(api_post "/api/integrations/erp/sync/${legacy_reimbursement_id}?runNow=0" '{}' "$legacy_body")"
|
||||
assert_status "$legacy_code" "200" "legacy erp sync alias"
|
||||
legacy_outbox_id="$(jq -er '.data.outboxId' "$legacy_body")"
|
||||
legacy_state="$(query_outbox_state "$legacy_outbox_id")"
|
||||
jq -e '.eventType == "erp.journal.export" and .status == "pending"' <<<"$legacy_state" >/dev/null
|
||||
|
||||
echo "[9/9] ERP env gate off blocks sync"
|
||||
if kill -0 "$APP_SERVER_PID" >/dev/null 2>&1; then
|
||||
kill "$APP_SERVER_PID" >/dev/null 2>&1 || true
|
||||
wait "$APP_SERVER_PID" >/dev/null 2>&1 || true
|
||||
fi
|
||||
APP_SERVER_PID=""
|
||||
PORT="$APP_PORT" \
|
||||
HOST="127.0.0.1" \
|
||||
JOBS_ENABLED=false \
|
||||
OCR_PROVIDER=mock \
|
||||
ERP_SYNC_ENABLED=false \
|
||||
ERP_SYNC_PROVIDER=http \
|
||||
ERP_MASTER_DATA_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/master-data/pull?mode=success" \
|
||||
ERP_JOURNAL_EXPORT_ENDPOINT="http://127.0.0.1:$MOCK_ERP_PORT/erp/journals/reimbursements/paid?mode=success" \
|
||||
ERP_SYNC_TIMEOUT_MS="$ERP_SYNC_TIMEOUT_MS" \
|
||||
ERP_MASTER_DATA_TIMEOUT_MS="$ERP_SYNC_TIMEOUT_MS" \
|
||||
ERP_SYNC_AUTH_TOKEN="" \
|
||||
node src/index.js >"$TMP_DIR/app-gate-off.log" 2>&1 &
|
||||
APP_SERVER_PID="$!"
|
||||
for _ in $(seq 1 60); do
|
||||
if curl -sS "$BASE_URL/health" >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
sleep 0.5
|
||||
done
|
||||
login_finance_mgr
|
||||
blocked_body="$TMP_DIR/blocked.json"
|
||||
blocked_code="$(api_post '/api/integrations/erp/master-data/sync' '{"resources":["legal_entity"]}' "$blocked_body")"
|
||||
assert_status "$blocked_code" "409" "erp gate off blocked"
|
||||
jq -e '.error.code == "VALID_001" and (.error.details.integration == "erp_sync_disabled" or .error.details.reason == "env_hard_off")' "$blocked_body" >/dev/null
|
||||
|
||||
echo "[6/6] Done"
|
||||
echo "[OK] Integrations regression passed"
|
||||
|
||||
echo "[post] Reset ERP feature flag force_off"
|
||||
set_erp_flag "force_off"
|
||||
|
||||
在新工单中引用
屏蔽一个用户