6.3 KiB
Huizhou Additional Notification Implementation Plan
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox syntax for tracking.
Goal: 为原15类增加可选择惠州模板的附加通知,沿用原收件人且两路结果独立。
Architecture: 先扩展模板模式和规则字段,再实现按明细筛选的惠州批次及独立通知预留。前端使用现有Tabler规则/模板/订单/批次页面,归档与权限服务复用。
Tech Stack: Node.js >=22.13, CommonJS, SQLite加密记录, Tabler 1.6.1, node:test, Playwright。
Spec: ../specs/2026-10-21-huizhou-notification-design.md
Global Constraints
- 仅开发现有modular-refactor工作树;不改原共享源码,不推送合并。
- 自动处理、自动发信保持暂停,不发真实邮件、不办理BPM、不操作服务机。
- 保留账号、密码、密钥、样本、草稿及历史;不读取account-recovery。
- 旧数据默认普通模式/惠州关闭;已冻结快照保持;未知发送结果禁止自动重发。
- 无新增依赖;安全投影、源权限、发布证据、全局门控、日历与原冻结期限继续有效。
Task 1: 模板模式与规则契约
Files: src/modules/mail/{store,rule-template}.cjs, src/modules/order-rules/{catalog,validation,api}.cjs; tests/mail/huizhou-template.test.cjs, tests/order-rules/huizhou-config.test.cjs。
Interfaces: rule.huizhouEnabled (default false), rule.huizhouTemplateId (default empty); template.notificationMode ('normal'|'huizhou', legacy normal); ruleTemplate(store,categoryId,rule,mode='normal') resolves the mode's selected active template and rejects mismatches. Hui mode requires an explicit selected template when enabled. Existing templateResolver accepts fourth mode argument or call with mode-specific rule projection (record the chosen contract).
- Write failing real-store tests for legacy default, persisted settings, invalid booleans/template modes and selecting an inactive/wrong-mode template.
- Run
node --test tests/mail/huizhou-template.test.cjs tests/order-rules/huizhou-config.test.cjs; verify missing mode isolation causes assertions to fail. - Add templates.notification_mode column and rebuild active index over channel_id,scope,notification_mode. Use explicit insert columns. Preserve all old rows, payloads, and versions; normal and huizhou scopes no longer archive each other.
- Extend validation and save/publish/resume checks, public summaries and resolver. No server accepts arbitrary To/Cc for Hui mode.
- Run new tests plus existing mail/store and rule-validation slices; commit only task-owned changes.
Task 2: 惠州识别、双路冻结与恢复
Files: src/modules/order-rules/{title,matching,batch,template,store,dispatcher,query,migrations,effects-preview}.cjs; src/modules/order-execution/coordinator.cjs; src/app/application.cjs; new src/modules/order-rules/huizhou.cjs and delivery helper if needed; tests/order-rules/huizhou-notification.test.cjs.
Interfaces: batches.notificationMode, order-specific independent Hui status/batch reservation, helper selecting titleOrders for mode; query detail exposes both notifications without raw source data. Task 1 resolver supports mode selection.
- Write failing tests with a mixed title containing ordinary O-100 and Hui H-200; assert Hui subject/text excludes O-100 and uses exact frozen normal To/Cc.
- Add tests proving HA prefix alone does not trigger, disabled/legacy produces one batch, empty Hui produces no batch, repeated prepare produces exactly one batch per mode.
- Run new test file and confirm expected red assertions before production edits.
- Add segment-aware recognition, Hui-specific mail rendering, mode-aware batch identity and independent reservations. Reuse archive evidence, never create extra capture/archive tasks.
- Forward mode in application templateResolver=(categoryId,rule,mode='normal')=>ruleTemplate(mail.store,categoryId,rule,mode). Normal sent/unknown must not stop archived runtime checks while Hui remains pending/batched. HA alone or contradictory customer/mode evidence is visible Hui-only uncertainty, never automatic Hui confirmation or silently forgotten potential Hui demand.
- Extend begin/finish/resolve/manual resend and restart recovery for matching mode only; preserve normal legacy state behavior. Block stale rules, incomplete source evidence and unknown outcomes.
- Verify normal sent + Hui failed can resend Hui once without normal send; normal unknown + Hui result remains independent; restart while Hui sending marks only Hui unknown. Verify no old frozen batches gain companions.
- Expose mode and delivery summaries in authorized projections/preview; run dispatcher/query/migration/execution regression slices and commit.
Task 3: Tabler页面、回归与本机交付
Files: web/modules/order-rules/{editor,resources,view,preview}.js; web/modules/mail templates views; web/modules/order-notifications/{records,detail}.js; web/app.js viewTemplates existing usage area; related UI tests; docs/HANDOFF.md and current design/action guides.
Interfaces: Task 1 fields and Task 2 query/preview schema are binding; record concrete output shapes in task report.
- Write and run red UI tests exercising toggle -> mode-filtered selector -> save/reload, viewer read-only and leave-with-unsaved protection.
- Add rule controls, default false, inherited recipient explanation, proper mode selection in template confirmation/list and independent delivery results in order/batch details. Use existing lifecycle/dirty/role/escaping helpers.
- Verify mixed preview shows only Hui detail in supplemental email, unchanged normal contents, no Hui To/Cc inputs, and original navigation/pagination intact.
- Run scoped UI/backend tests and fresh full npm test; node --check changed JS/CJS; git diff --check; inspect staged files for private artifacts.
- Final review against spec and independent delivery recovery, resolve findings, commit code/docs.
- Stop original local test instance, create/verify backup, npm start; verify both ports/login/static assets, preserved accounts/keys/sample/draft/history summaries, and both automatic switches false. Do not enable business operations. Record evidence and final commit.