Files
syops/docs/superpowers/plans/2026-10-19-freight-rpa-outbound-and-rename.md
T
hugo 911afa0f73 feat(freight-rpa): 增加出站报表配置与回调支持,重构相关服务
- 将 RPA 管理 API 扩展至出站报表配置,新增出站相关的回调接口。
- 重构 freight_rpa_report_config_service,支持入站与出站报表配置的管理。
- 更新 ORM 模型,增加出站报表相关的持久化模型。
- 统一命名规范,确保在手、入站与出站的概念一致性。
2026-10-19 18:45:16 +08:00

35 KiB
Raw Blame History

货代 RPA:报表规则改名 + 出站全栈 + 入站运维瘦身 Implementation Plan

For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (- [ ]) syntax for tracking.

Goal: 管理端改名为「报表规则 / 来源站点 / 入站报表」,交付与入站同构的出站 RPA 全栈,并拆除入站 deliveries 与工作台收料文件页。

Architecture: 做法 A——按入站包逐文件克隆出站(models / trigger_io / report_archive / schedule job / Worker / 调拨 trigger / sink),不先做泛化层。改名与入站瘦身穿插在前序任务,降低出站联调噪声。purpose=outbound 校验改走 MOVEMENT_FIELDS。通知只走排程 notify_user_ids。

Tech Stack: Flask、SQLAlchemy 2.0、Alembic、Vue 3、pytest、Playwright Worker(Python)。后端测试工作目录 backend/;Windows 上 Python 用 backend/.venv/Scripts/python.exe(若无则用已激活的 venv)。

Spec: docs/superpowers/specs/2026-10-19-freight-rpa-outbound-and-rename-design.md

Global Constraints

  • 入口文案:库存解析 → 报表规则;库存站点 → 来源站点;收料报表配置 → 入站报表配置。父级「库存管理」、库存字段目录不改。
  • 出站类名一律 FreightRpaOutbound*;假定 class-prefix 已合入(FreightRpaSource 等)。禁止引入 Shipping*Outbound*。
  • 出站新建三表:freight_rpa_outbound_report_configs / freight_rpa_outbound_rpa_unit_runs / freight_rpa_outbound_report_files。禁止建 *_notification_deliveries。
  • 删除 freight_rpa_inbound_notification_deliveries 及 resend / 工作台收料页 / inbound_report_access。
  • receipt-raw-zip → inbound-raw-zip(路径与深链参数),无兼容别名。
  • 出站配置非启用硬门槛;触发时站点停用/缺配置 fail-closed。
  • purpose=outbound 与 inbound 同异动契约;旧 onhand 形态 outbound 草稿不自动迁移。
  • RPA 层不强制 in_out_flag;方向过滤留在调拨域。
  • 不改履约出货 / upload;不新建工作台出站文件页。
  • 四语言 i18n 同步;错误码新增须写 locales/*/errors.json。
  • 改函数签名或模块协作时同步文件头与函数注释(AGENTS.md §5)。
  • 禁止 git add -A / git commit;每任务只 stage 该任务列出的路径。工作区可能已有未提交的其它批次,勿混入。
  • 跨机路径(硬约束):出站回调 file_path 只按「outbound drop 根内文件名」解析。后端必须 replace('\\','/') 后取 .name,再拼 FREIGHT_RPA_SHARED_OUTBOUND_DROP_DIR,relative_to(root) 防穿越。禁止把 Windows 绝对路径当 Linux 路径打开。对照入站 _read_inbound_callback_file 与在手 resolve_shared_inventory_drop_file。Worker 侧优先只上报文件名。必须有带 C:\\...\\foo.xlsx 的回归测。

文件地图

文件 / 目录 职责
frontend/src/locales/{zh-CN,zh-TW,en,th}/admin.json 等 报表规则 / 来源站点 / 入站·出站报表文案
frontend/src/features/admin/modules/freight-rpa/* 来源站点三块配置、报表规则 purpose=outbound UI
frontend/src/features/workspace/**(收料页相关) 删除
backend/app/models/freight_rpa_outbound_report.py 出站三模型(新建)
backend/app/models/freight_rpa_inbound_report.py 去掉 NotificationDelivery
backend/migrations/versions/*_freight_rpa_outbound_and_inbound_slim.py 出站建表 + drop deliveries
backend/app/services/shipping_notice/onhand_parsing_profile.py outbound → 异动校验
backend/app/services/admin/shipping_onhand_admin_service.py get_/save_inbound_* + get_/save_outbound_*
backend/app/services/freight_rpa/outbound/* trigger_io、report_archive
backend/app/services/schedule/freight_rpa_outbound_*.py job / finalize / archive / retention
backend/app/api/freight_rpa.py outbound 回调路由
backend/app/api/schedule/runs.py inbound-raw-zip、outbound-raw-zip、outbound units
backend/app/services/in_transit_transfer/outbound_trigger_service.py 按需触发
backend/app/services/in_transit_transfer/outbound_report_handler.py sink handler
backend/app/services/shipping_notice/rpa_sinks.py register_outbound_sinks
scripts/freight_rpa/outbound/* Worker / ps1 / 驱动
docs/features/freight-rpa/GLOSSARY.md 等 术语与运维文档

Task 1: 管理端改名(报表规则 / 来源站点 / 入站报表)

Files:

  • Modify: frontend/src/locales/zh-CN/admin.json
  • Modify: frontend/src/locales/zh-TW/admin.json
  • Modify: frontend/src/locales/en/admin.json
  • Modify: frontend/src/locales/th/admin.json
  • Modify: frontend/src/features/admin/shippingConfigNavigation.spec.ts(若断言旧文案)
  • Modify: frontend/src/features/admin/modules/freight-rpa/FreightRpaPage.vue(仅当硬编码「收料」时)
  • Modify: frontend/src/features/admin/modules/freight-rpa/receiptReportConfigForm.ts → 重命名文件为 inboundReportConfigForm.ts,并改导出函数名
  • Modify: 所有 import 上述 form 的文件(FreightRpaPage.vue、*.spec.ts)
  • Test: frontend/src/features/admin/modules/freight-rpa/receiptReportConfigForm.spec.ts → inboundReportConfigForm.spec.ts

Interfaces:

  • Consumes: 现有 i18n 键 admin.freightRpa.parsingProfiles、sources、receiptReportConfig*

  • Produces: 用户可见字符串变更;键名可将 receiptReportConfig 改为 inboundReportConfig(四语言同步改键,调用处同步);buildInboundReportConfigPayload 替代 buildReceiptReportConfigPayload

  • Step 1: 写失败的导航/文案断言(若已有 spec 则改期望)

在 shippingConfigNavigation.spec.ts 或新建窄测中断言 labelKey 对应文案解析后为「报表规则」「来源站点」(用 i18n 或直接断言 key 不变、另测 locale 文件内容)。

最小 locale 断言脚本(Node,在 frontend/):

const zh = require('./src/locales/zh-CN/admin.json');
if (zh.freightRpa.parsingProfiles !== '报表规则') throw new Error('parsingProfiles');
if (zh.freightRpa.sources !== '来源站点') throw new Error('sources');
if ((zh.freightRpa.inboundReportConfig || zh.freightRpa.receiptReportConfig) !== '入站报表配置') {
  throw new Error('inboundReportConfig');
}

先跑应失败(当前为库存解析/库存站点/收料报表配置)。

  • Step 2: 改四语言文案与键

zh-CN 最低改动示例:

"parsingProfiles": "报表规则",
"parsingProfilesHelp": "维护可辨识的文件解析规则:库存面向字段目录与订单匹配,入站/出站面向标准异动字段(只读契约)。",
"sources": "来源站点",
"inventorySites": "来源站点",
"inboundReportConfig": "入站报表配置",
"inboundReportConfigHint": "与库存配置同构:报表路径 + 查询条件。查询条件可选,空则使用页面默认;排程按站点一对一导出。入站无独立开关,随站点统一启停。",
"outboundReportConfig": "出站报表配置",
"outboundReportConfigHint": "与入站配置同构:报表路径 + 查询条件;出站无独立开关,随站点统一启停。"

删除或停止使用 receiptReportConfig* 键。zh-TW / en / th 同步语义(en: Report Rules / Source Sites / Inbound Report Config / Outbound Report Config)。

同步 parsingPurposeHint 等仍写「仅入站」的句子,改为「入站/出站」。

  • Step 3: 重命名前端 form 模块

buildReceiptReportConfigPayload → buildInboundReportConfigPayload;文件改名;FreightRpaPage.vue 中 receiptConfig 展示文案键改为 inboundReportConfig*(状态变量可暂留,Task 6/11 再统一)。

  • Step 4: 跑前端相关测试

Run: cd frontend && npx vitest run src/features/admin/modules/freight-rpa/inboundReportConfigForm.spec.ts src/features/admin/shippingConfigNavigation.spec.ts
Expected: PASS

  • Step 5: Stage
git add frontend/src/locales/zh-CN/admin.json frontend/src/locales/zh-TW/admin.json frontend/src/locales/en/admin.json frontend/src/locales/th/admin.json frontend/src/features/admin/modules/freight-rpa/inboundReportConfigForm.ts frontend/src/features/admin/modules/freight-rpa/inboundReportConfigForm.spec.ts frontend/src/features/admin/modules/freight-rpa/FreightRpaPage.vue frontend/src/features/admin/shippingConfigNavigation.spec.ts

(含删除旧 receiptReportConfigForm* 的 staged deletion。)


Task 2: 拆除入站 deliveries + 工作台收料页

Files:

  • Modify: backend/app/models/freight_rpa_inbound_report.py(删 FreightRpaInboundNotificationDelivery 与 relationship)
  • Modify: backend/app/models/__init__.py
  • Modify: backend/app/services/freight_rpa/inbound/report_archive.py(删 deliver_inbound_file、_recipient_ids 及 WeCom 投递 import)
  • Modify: backend/app/api/schedule/runs.py(删 resend 路由)
  • Delete: backend/app/services/shipping_notice/inbound_report_access.py
  • Modify: backend/app/api/workspace/shipping_notice.py(删 list/download inbound-report-files 两路由)
  • Delete: frontend/src/features/workspace/pages/InboundReportFilesPage.vue 及其 .spec.ts
  • Delete: frontend/src/features/workspace/api/inbound-report.api.ts 及其 .spec.ts(若仅服务该页)
  • Modify: frontend/src/app/router/routes/workspace.routes.ts
  • Modify: frontend/src/features/workspace/components/WorkspaceSidebar.vue
  • Modify: frontend/src/features/workspace/constants/routes.ts
  • Modify: frontend/src/features/workspace/composables/useWorkspaceNavigation.ts
  • Modify: 四语言 workspace locale(去掉 inboundReports / nav 项)
  • Delete or rewrite: backend/tests/test_freight_receipt_rpa_notifications.py、test_freight_receipt_rpa_access.py(去掉 deliveries/resend/workspace 断言)
  • Create: backend/migrations/versions/<rev>_drop_inbound_notification_deliveries.py(可与 Task 4 合并为一迁移;若拆分则本任务只 drop)
  • Test: 新建 backend/tests/test_freight_rpa_inbound_slim_gate.py

Interfaces:

  • Consumes: 无

  • Produces: 无 FreightRpaInboundNotificationDelivery;无 resend API;无 workspace 收料路由

  • Step 1: 写 grep gate 失败用例

# backend/tests/test_freight_rpa_inbound_slim_gate.py
from pathlib import Path

ROOT = Path(__file__).resolve().parents[2]


def test_no_inbound_notification_delivery_symbol():
    hits = []
    for path in (ROOT / "app").rglob("*.py"):
        text = path.read_text(encoding="utf-8")
        if "InboundNotificationDelivery" in text or "deliver_inbound_file" in text:
            hits.append(str(path))
    assert hits == []


def test_no_workspace_inbound_report_routes():
    text = (ROOT / "app/api/workspace/shipping_notice.py").read_text(encoding="utf-8")
    assert "inbound-report-files" not in text

Run: pytest tests/test_freight_rpa_inbound_slim_gate.py -v
Expected: FAIL

  • Step 2: 删模型、服务、API、前端页与测试中的引用

按 Files 列表删除/改写。report_archive.py 文件头 docstring 去掉投递职责。迁移 op.drop_table('freight_rpa_inbound_notification_deliveries')(downgrade 可重建最小表结构或 pass 并在注释标明不可逆——推荐完整 rebuild 以便本地 downgrade)。

  • Step 3: 再跑 gate + 受影响测试

Run: pytest tests/test_freight_rpa_inbound_slim_gate.py tests/test_freight_receipt_rpa_notifications.py tests/test_freight_receipt_rpa_access.py -v
Expected: gate PASS;旧测文件已删或改写后 PASS

  • Step 4: Stage 本任务路径
git add backend/app/models/freight_rpa_inbound_report.py backend/app/models/__init__.py backend/app/services/freight_rpa/inbound/report_archive.py backend/app/api/schedule/runs.py backend/app/api/workspace/shipping_notice.py backend/migrations/versions/ backend/tests/test_freight_rpa_inbound_slim_gate.py frontend/src/app/router/routes/workspace.routes.ts frontend/src/features/workspace/

Task 3: receipt-raw-zip → inbound-raw-zip

Files:

  • Modify: backend/app/api/schedule/runs.py(路由与函数名)
  • Modify: backend/app/services/schedule/freight_rpa_inbound_archive.py(receipt_raw_zip_* → inbound_raw_zip_* 函数名)
  • Modify: backend/app/services/schedule/scheduler_service.py(深链 download=inbound_raw_zip)
  • Modify: backend/app/services/schedule/query_service.py(summary 字段 inbound_raw_zip_available)
  • Modify: frontend/src/features/admin/api/schedule.api.ts
  • Modify: frontend/src/features/admin/modules/schedules/**(文案与 query 参数)
  • Modify: 四语言 admin.json 中 downloadReceipt* → downloadInbound*
  • Test: 既有 receipt zip 相关测改断言

Interfaces:

  • Consumes: resolve_receipt_raw_zip_download(旧)

  • Produces: resolve_inbound_raw_zip_download(run) -> tuple[Path, str];路由 GET /api/admin/schedule-runs/<id>/inbound-raw-zip;深链 download=inbound_raw_zip

  • Step 1: 改后端路由与函数名,更新调用方

路由:

@schedule_admin_bp.route('/schedule-runs/<int:run_id>/inbound-raw-zip', methods=['GET'])
@require_admin
def get_schedule_run_inbound_raw_zip(run_id: int):
    """下载入站 RPA 排程 run 的原始入站 Excel 打包(ZIP + manifest)。"""
    ...

禁止保留 receipt-raw-zip 路由。

  • Step 2: 改前端 API 与深链
export const scheduleRunInboundRawZipUrl = (runId: number) =>
  `/api/admin/schedule-runs/${runId}/inbound-raw-zip`;

useScheduleAdminDeepLink:downloadKind === 'inbound_raw_zip'。

  • Step 3: 跑相关测试

Run: pytest tests/ -k "inbound_raw_zip or receipt_raw_zip" -v
Expected: 无 receipt_raw_zip 残留失败;新名 PASS

  • Step 4: Stage
git add backend/app/api/schedule/runs.py backend/app/services/schedule/freight_rpa_inbound_archive.py backend/app/services/schedule/scheduler_service.py backend/app/services/schedule/query_service.py frontend/src/features/admin/api/schedule.api.ts frontend/src/features/admin/modules/schedules frontend/src/locales

Task 4: 出站模型 + Alembic 迁移

Files:

  • Create: backend/app/models/freight_rpa_outbound_report.py
  • Modify: backend/app/models/freight_rpa_config.py(FreightRpaSource.outbound_report_config relationship)
  • Modify: backend/app/models/__init__.py
  • Create/Modify: Alembic revision(建三表;若 Task 2 未 drop deliveries 则本迁移一并 drop)
  • Test: backend/tests/test_freight_rpa_outbound_models.py

Interfaces:

  • Consumes: FreightRpaSource、FreightRpaParsingProfile

  • Produces: FreightRpaOutboundReportConfig / UnitRun / ReportFile;表名见 Global Constraints

  • Step 1: 写模型存在性测试

from app.models import FreightRpaOutboundReportConfig, FreightRpaOutboundUnitRun, FreightRpaOutboundReportFile

def test_outbound_model_tablenames():
    assert FreightRpaOutboundReportConfig.__tablename__ == "freight_rpa_outbound_report_configs"
    assert FreightRpaOutboundUnitRun.__tablename__ == "freight_rpa_outbound_rpa_unit_runs"
    assert FreightRpaOutboundReportFile.__tablename__ == "freight_rpa_outbound_report_files"

Expected FAIL(未建类)

  • Step 2: 复制入站模型文件并改名

以 freight_rpa_inbound_report.py 为模板新建 outbound 文件:

  • 类/表/约束名全面 Inbound→Outbound、inbound→outbound

  • 不要复制 NotificationDelivery

  • 文件头 docstring 写清出站职责;注释去掉「收料」

  • FreightRpaSource:outbound_report_config = relationship(..., uselist=False, back_populates='source')

  • Step 3: 生成并手审迁移

Run: flask db migrate -m "freight_rpa outbound tables and drop inbound notification deliveries"
手审:仅目标三表 create + deliveries drop;无无关 drop。

Run: flask db upgrade
Expected: OK

  • Step 4: 跑模型测

Run: pytest tests/test_freight_rpa_outbound_models.py -v
Expected: PASS

  • Step 5: Stage
git add backend/app/models/freight_rpa_outbound_report.py backend/app/models/freight_rpa_config.py backend/app/models/__init__.py backend/migrations/versions/ backend/tests/test_freight_rpa_outbound_models.py

Task 5: purpose=outbound 改走异动校验

Files:

  • Modify: backend/app/services/shipping_notice/onhand_parsing_profile.py
  • Modify: backend/tests/test_parsing_profile_purpose.py
  • Modify: frontend/src/features/admin/modules/freight-rpa/FreightRpaPage.vue(parsing.purpose === 'inbound' 判断扩展为 inbound|outbound 共用异动 UI)
  • Modify: frontend/src/features/admin/modules/freight-rpa/movementParsingProfileForm.ts(若有 purpose 分支)

Interfaces:

  • Consumes: _validate_definition(..., purpose=)

  • Produces: purpose in {'inbound','outbound'} 均走 _required_movement_field_ids,match_keys=[]

  • Step 1: 改测试期望

def test_outbound_definition_uses_movement_fields():
    definition = _validate_definition(_inbound_definition(), purpose='outbound')
    assert definition['match_keys'] == []
    assert definition['field_mapping']['doc_no'] == '单据编号'


def test_outbound_onhand_shaped_definition_rejected():
    """库存目录形态(含 match_keys)在 outbound 下应失败。"""
    # 使用现有 onhand 合法定义夹具;expect ValidationError
    ...

文件头注释:删除「onhand/outbound 维持库存字段目录」。

Run: pytest tests/test_parsing_profile_purpose.py::test_outbound_definition_uses_movement_fields -v
Expected: FAIL

  • Step 2: 改校验分支
    if purpose in {'inbound', 'outbound'}:
        _required_movement_field_ids(raw)
        return {
            'sheet_name': str(raw.get('sheet_name') or '').strip() or None,
            'header_row_index': header_row_index,
            'field_mapping': {str(key).strip(): str(value).strip() for key, value in field_mapping.items()},
            'match_keys': [],
        }

同步所有 purpose == 'inbound' 的文档字符串与 purpose != 'inbound' 的前端条件 → purpose === 'onhand' 才走库存目录 UI。

站点绑定过滤:

  • 库存报表:purpose === 'onhand'(不要再用 !== 'inbound',以免 outbound 混入)

  • 入站:purpose === 'inbound'

  • 出站:purpose === 'outbound'

  • Step 3: 跑测试

Run: pytest tests/test_parsing_profile_purpose.py -v
Expected: PASS

  • Step 4: Stage
git add backend/app/services/shipping_notice/onhand_parsing_profile.py backend/tests/test_parsing_profile_purpose.py frontend/src/features/admin/modules/freight-rpa/FreightRpaPage.vue frontend/src/features/admin/modules/freight-rpa/movementParsingProfileForm.ts

Task 6: 出站报表配置 Admin API + receipt→inbound 服务符号

Files:

  • Modify: backend/app/services/admin/shipping_onhand_admin_service.py
  • Modify: backend/app/api/admin_freight_rpa.py
  • Modify: frontend/src/features/admin/api/admin.api.ts
  • Create: frontend/src/features/admin/modules/freight-rpa/outboundReportConfigForm.ts(镜像 inbound form)
  • Test: backend/tests/test_freight_rpa_outbound_report_config_api.py

Interfaces:

  • Consumes: FreightRpaOutboundReportConfig

  • Produces:

    • get_inbound_report_config(source_id) -> dict | None(由 get_receipt_report_config 改名)
    • save_inbound_report_config(source_id, data, *, actor_id) -> dict
    • get_outbound_report_config(source_id) -> dict | None
    • save_outbound_report_config(source_id, data, *, actor_id) -> dict
    • 路由 GET/PUT /api/admin/freight-rpa/sources/<id>/outbound-report-config
    • 载荷键:parsing_profile_id、report_path_json、query_parameters_json(与入站相同)
  • Step 1: API 契约测试(失败)

def test_put_outbound_report_config_requires_outbound_profile(client, admin_headers, source_id, onhand_profile_id):
    resp = client.put(
        f"/api/admin/freight-rpa/sources/{source_id}/outbound-report-config",
        json={"parsing_profile_id": onhand_profile_id, "report_path_json": {}, "query_parameters_json": []},
        headers=admin_headers,
    )
    assert resp.status_code in (400, 422)
  • Step 2: 实现服务与路由

校验:parsing_profile.purpose == 'outbound' and status == 'published'(或允许草稿绑定策略与入站现行一致——逐行对照 _validate_receipt_report_config 后改名为 _validate_inbound_report_config,再复制为 _validate_outbound_report_config 只改 purpose)。

重命名所有 receipt_report_config 服务函数与事件名中的 receipt→inbound(审计 event_type 若已有历史,新事件用 shipping_outbound_report_config_saved / freight_rpa_inbound_report_config_saved,不强制改历史事件字符串除非测试锁死)。

  • Step 3: 前端 API
export const getOutboundReportConfig = (sourceId: number) =>
  requestJson(`/api/admin/freight-rpa/sources/${sourceId}/outbound-report-config`);
export const saveOutboundReportConfig = (sourceId: number, body: unknown) =>
  requestJson(`/api/admin/freight-rpa/sources/${sourceId}/outbound-report-config`, { method: 'PUT', body });
  • Step 4: 跑测

Run: pytest tests/test_freight_rpa_outbound_report_config_api.py -v
Expected: PASS

  • Step 5: Stage 列出文件

Task 7: 出站 trigger_io + Worker 心跳能力

Files:

  • Create: backend/app/services/freight_rpa/outbound/__init__.py
  • Create: backend/app/services/freight_rpa/outbound/trigger_io.py
  • Modify: backend/app/services/freight_rpa/common/worker_heartbeat.py(OUTBOUND_EXPORT_CAPABILITY、assert_outbound_rpa_worker_ready)
  • Modify: scripts/freight_rpa/common/rpa_callbacks.py(outbound 回调路径常量)
  • Test: backend/tests/services/freight_rpa/test_outbound_trigger_contract.py

Interfaces:

  • Produces:

    • SCHEMA = "freight_rpa.outbound.v1"
    • ACTION_OUTBOUND_EXPORT_BATCH = "outbound_export_batch"
    • write_outbound_export_batch_trigger(run_no, units, meta) -> str | None
    • outbound_trigger_dir() / outbound_drop_dir() 读 FREIGHT_RPA_SHARED_OUTBOUND_*
    • OUTBOUND_EXPORT_CAPABILITY = "outbound_export"
  • Step 1: 契约测试

from app.services.freight_rpa.outbound import trigger_io
from app.services.freight_rpa.common.worker_heartbeat import OUTBOUND_EXPORT_CAPABILITY

def test_outbound_trigger_constants():
    assert trigger_io.SCHEMA == "freight_rpa.outbound.v1"
    assert trigger_io.ACTION_OUTBOUND_EXPORT_BATCH == "outbound_export_batch"
    assert OUTBOUND_EXPORT_CAPABILITY == "outbound_export"
  • Step 2: 实现(逐函数对照 inbound/trigger_io.py 与 assert_receipt_rpa_worker_ready,符号全部 outbound 化;禁止复用 inbound 目录配置键)

  • Step 3: 跑测并 stage


Task 8: 出站排程 job / finalize / archive / retention + 注册

Files:

  • Create: backend/app/services/schedule/freight_rpa_outbound_job.py
  • Create: backend/app/services/schedule/freight_rpa_outbound_finalize.py
  • Create: backend/app/services/schedule/freight_rpa_outbound_archive.py
  • Create: backend/app/services/schedule/freight_rpa_outbound_retention.py
  • Modify: backend/app/services/schedule/job_registry.py
  • Modify: backend/app/services/schedule/__init__.py(若需注册 excel headers)
  • Test: backend/tests/test_freight_rpa_outbound_job.py

Interfaces:

  • Consumes: write_outbound_export_batch_trigger、assert_outbound_rpa_worker_ready

  • Produces:

    • OUTBOUND_RPA_JOB_KEY = "freight-rpa-outbound"
    • OUTBOUND_RETENTION_JOB_KEY = "freight-rpa-outbound-retention"
    • AWAITING_OUTBOUND_RPA_CALLBACK_STATUS = "awaiting_outbound_rpa_callback"
    • 错误码使用 RPA.OUTBOUND_*(如 RPA.OUTBOUND_TRIGGER_UNAVAILABLE、RPA.OUTBOUND_CALLBACK_TIMEOUT),四语言 errors 本任务或 Task 13 补齐
    • 单元表写入 FreightRpaOutboundUnitRun
  • Step 1: 对照入站 job 写「空 source 列表 fail-closed / worker 离线 failed」测试

  • Step 2: 复制入站四文件并全文替换符号(receipt→outbound 语义处改为 outbound;状态串不要沿用 awaiting_receipt_*)

  • Step 3: job_registry 注册两个 platform job

  • Step 4: 跑测并 stage


Task 9: 出站回调 API + report_archive ingest

Files:

  • Create: backend/app/services/freight_rpa/outbound/report_archive.py
  • Modify: backend/app/api/freight_rpa.py
  • Modify: scripts/freight_rpa/common/rpa_callbacks.py(若 Task 7 未完)
  • Test: backend/tests/test_freight_rpa_outbound_callback.py
  • Optional Create: backend/app/services/freight_rpa/common/drop_path.py(若抽取共用「drop 根 + 文件名」解析,供 outbound 使用;抽取时入站可后续再迁,本任务不强制改 inbound)

Interfaces:

  • Produces: ingest_outbound_callback(payload) -> None;_read_outbound_callback_file(file_path: str) -> bytes;路由:

    • POST /api/freight-rpa/outbound-batch-ready
    • POST /api/freight-rpa/outbound-unit-progress
    • POST /api/freight-rpa/outbound-batch-progress
  • 归档成功后 dispatch_report_fact(report_kind='outbound', ...)(handler 可在 Task 10 注册前用测内临时 register)

  • 路径解析语义与入站 _read_inbound_callback_file 一致(见 Global Constraints)

  • Step 1: 先写跨机路径回归测(必须红)

def test_read_outbound_callback_file_accepts_windows_absolute_path(tmp_path, app):
    """Worker 上报 C:\\...\\drop\\foo.xlsx 时,Linux 侧只按文件名拼本机 drop 根。"""
    drop = tmp_path / "outbound_drop"
    drop.mkdir()
    target = drop / "foo.xlsx"
    target.write_bytes(b"PK\x03\x04fake")
    with app.app_context():
        app.config["FREIGHT_RPA_SHARED_OUTBOUND_DROP_DIR"] = str(drop)
        from app.services.freight_rpa.outbound.report_archive import _read_outbound_callback_file
        data = _read_outbound_callback_file(r"C:\HxopsRpaTest\data\freight_rpa\outbound\drop\foo.xlsx")
        assert data.startswith(b"PK")


def test_read_outbound_callback_file_rejects_traversal(tmp_path, app):
    drop = tmp_path / "outbound_drop"
    drop.mkdir()
    with app.app_context():
        app.config["FREIGHT_RPA_SHARED_OUTBOUND_DROP_DIR"] = str(drop)
        from app.services.freight_rpa.outbound.report_archive import _read_outbound_callback_file
        from app.core.errors import ValidationError
        with pytest.raises(ValidationError):
            _read_outbound_callback_file(r"..\..\etc\passwd")

另测:file_path="foo.xlsx"(仅文件名)同样成功。
Run: pytest tests/test_freight_rpa_outbound_callback.py -k windows_absolute -v
Expected: FAIL(函数未实现)

  • Step 2: 回调 schema 校验失败测试(错误 schema → 4xx)

  • Step 3: 实现 _read_outbound_callback_file + archive

最小实现(对照入站,禁止 Path(file_path).read_bytes() 直接读回调串):

def _read_outbound_callback_file(file_path: str) -> bytes:
    configured_root = str(outbound_drop_dir() or "").strip()
    if not configured_root:
        raise ValidationError("outbound callback file root is unavailable", code="SHIPPING.OUTBOUND_CALLBACK_FILE_INVALID")
    root = Path(configured_root).resolve()
    name = Path(str(file_path).replace("\\", "/")).name
    path = (root / name).resolve()
    try:
        path.relative_to(root)
    except ValueError as exc:
        raise ValidationError(
            "outbound callback file is outside outbound drop root",
            code="SHIPPING.OUTBOUND_CALLBACK_FILE_INVALID",
        ) from exc
    if path.suffix.lower() != ".xlsx" or not path.is_file():
        raise ValidationError(
            "outbound callback file must be an existing xlsx",
            code="SHIPPING.OUTBOUND_CALLBACK_FILE_INVALID",
        )
    ...
    return path.read_bytes()

不要移植已删除的 deliver_inbound_file。

  • Step 4: 接线路由与鉴权(与入站回调同 ToolApiKey 机制)

  • Step 5: 跑测并 stage(含 Step 1 路径测必须绿)


Task 10: 调拨 outbound_trigger_service + handler/sink

Files:

  • Create: backend/app/services/in_transit_transfer/outbound_trigger_service.py
  • Create: backend/app/services/in_transit_transfer/outbound_report_handler.py
  • Modify: backend/app/services/shipping_notice/rpa_sinks.py(register_outbound_sinks)
  • Modify: backend/app/__init__.py 或组合根调用处(与 register_inbound_sinks 并列)
  • Modify: backend/app/services/freight_rpa/reports/queries.py(get_outbound_config / list_outbound_configured_source_codes,对照 inbound)
  • Test: backend/tests/services/in_transit_transfer/test_outbound_trigger_service.py

Interfaces:

  • Produces:

    • trigger_outbound_rpa(...) / trigger_outbound_rpa_batch(...)
    • handle_outbound_report(fact) -> None(对称 handle_inbound_report:推进等待中的出站相关 SourceJob;无等待任务则 no-op;可重入)
    • register_outbound_sinks() → register_report_handler('outbound', handle_outbound_report)
  • Step 1: 缺配置 fail-closed 测试

  • Step 2: 实现 trigger + handler(对照 inbound 文件;调拨状态机字段名以现有 outbound record_kind / SourceJob 为准,禁止猜新状态——若入站 handler 推 waiting_rpa_callback→file_ready,出站同一套等待态字段)

  • Step 3: 组合根注册

  • Step 4: 跑测并 stage


Task 11: 管理端来源站点出站配置卡 + 排程运维 UI

Files:

  • Modify: frontend/src/features/admin/modules/freight-rpa/FreightRpaPage.vue
  • Create: frontend/src/features/admin/modules/freight-rpa/outboundReportConfigForm.ts(若 Task 6 未建)
  • Modify: frontend/src/features/admin/modules/schedules/composables/schedule-admin/useScheduleAdminRuns.ts
  • Modify: backend/app/api/schedule/runs.py(outbound-rpa-units list/retry、outbound-raw-zip)
  • Modify: 四语言 admin schedule 文案
  • Test: vitest 组件/ composable 窄测;后端 units API 测

Interfaces:

  • Produces: 来源站点第三折叠「出站报表配置」;排程 scope outbound;rpaWorkerStatusScope: 'onhand'|'inbound'|'outbound'

  • Step 1: Vue —— 在入站配置块后复制一块出站,绑定 outboundConfig,保存调 saveOutboundReportConfig;解析下拉 purpose === 'outbound'

  • Step 2: 排程 —— 对齐 inbound 的 worker 徽标与 raw-zip 下载按钮

  • Step 3: 后端 units/retry/raw-zip 对照 inbound 路由实现

  • Step 4: cd frontend && npm run build Expected: PASS

  • Step 5: Stage


Task 12: Windows Outbound Worker 脚本

Files:

  • Create: scripts/freight_rpa/outbound/outbound_rpa_worker.py
  • Create: scripts/freight_rpa/outbound/start_outbound_worker.ps1
  • Create: scripts/freight_rpa/outbound/register_outbound_worker_tasks.ps1
  • Create: scripts/freight_rpa/outbound/outbound_dbs_export.py
  • Create: scripts/freight_rpa/outbound/outbound_crane_export.py
  • Modify: scripts/freight_rpa/README.md
  • Modify: scripts/freight_rpa/common/rpa_callbacks.py(确认 outbound 端点)
  • Test: 后端侧可用「trigger 文件名/schema」合同测;Worker 无 pytest 时用脚本静态断言(读常量)

Interfaces:

  • Consumes: freight_rpa.outbound.v1 / outbound_export_batch

  • Produces: 轮询 FREIGHT_RPA_SHARED_OUTBOUND_TRIGGER_DIR;回调 outbound-*-progress/ready;心跳 outbound_export;Worker ID *-outbound

  • Step 1: 复制 inbound Worker 目录结构并替换常量/路径/回调

  • Step 2: 回调 file_path 只报文件名

在 outbound Worker 组装 batch-ready / unit 成功载荷时,file_path(及若有的等价字段)必须是 Path(local_drop_file).name,禁止把 C:\\...\\drop\\xxx.xlsx 整串作为契约主值(与入站现行「后端可容忍绝对路径、Worker 应只报文件名」一致)。在 worker 内加注释指向规格 §4.2 跨机路径契约。

  • Step 3: DBS 使用配置 report_path;Crane 固定出站页(页面选择器字符串实现时按货代实名填写,注释标明来源截图/环境;禁止误用 Inbound Details)

  • Step 4: ps1 注入 FREIGHT_RPA_WORKER_ID=<host>-outbound、outbound logs 目录

  • Step 5: Stage scripts/freight_rpa/outbound/ 与 README


Task 13: 错误码四语言 + 文档 + ADR + 规格状态

Files:

  • Modify: frontend/src/locales/{zh-CN,zh-TW,en,th}/errors.json
  • Modify: docs/features/freight-rpa/GLOSSARY.md
  • Modify: docs/features/shipping-notice/technical.md(改名 + 出站部署节,对称 §1.9)
  • Modify: docs/funclist.md
  • Modify: docs/adr/0004-freight-rpa-report-ownership.md
  • Modify: docs/superpowers/specs/2026-10-19-freight-rpa-outbound-and-rename-design.md(状态 → 已有实施计划)
  • Modify: 环境变量权威文档(若缺 OUTBOUND 项则补齐说明,不改真实密钥)

Interfaces: 无代码接口

  • Step 1: 为 Task 8/9 引入的每个新 code= 补四语言

  • Step 2: Glossary —— Outbound 改为已交付抓取;注明无 deliveries、无工作台收料页;Inbound 用户文案「入站」

  • Step 3: ADR 0004 Consequences 增加「本阶段注册 outbound handler」

  • Step 4: 规格头状态改为「已有实施计划」并链到本 plan 路径

  • Step 5: Stage 文档与 errors.json


Task 14: 总闸门(grep + 构建)

Files:

  • Create/Modify: backend/tests/test_freight_rpa_outbound_rename_gate.py

Interfaces: 无

  • Step 1: 写入总闸门测试
def test_no_receipt_raw_zip_route():
    text = Path("app/api/schedule/runs.py").read_text(encoding="utf-8")
    assert "receipt-raw-zip" not in text
    assert "inbound-raw-zip" in text

def test_outbound_purpose_not_catalog_in_validate_docstring():
    text = Path("app/services/shipping_notice/onhand_parsing_profile.py").read_text(encoding="utf-8")
    assert "purpose in {'inbound', 'outbound'}" in text or 'purpose in {"inbound", "outbound"}' in text

def test_no_outbound_notification_deliveries_table_reference():
    ...
  • Step 2: 跑闸门 + 出站相关测 + frontend build

Run:

cd backend && pytest tests/test_freight_rpa_outbound_rename_gate.py tests/test_freight_rpa_inbound_slim_gate.py tests/test_parsing_profile_purpose.py tests/test_freight_rpa_outbound_models.py -v
cd ../frontend && npm run build

Expected: 全部 PASS

  • Step 3: Stage 闸门测试

Spec coverage(自检)

规格项 任务
报表规则 / 来源站点 / 入站报表文案 T1
出站报表配置 UI T11(API T6)
outbound 异动解析 T5
出站三表 + 迁移 T4
无 outbound deliveries;删入站 deliveries T2、T4
下线工作台收料页 T2
inbound-raw-zip T3
trigger/心跳/回调/排程/retention T7–T9、T8
按需 trigger + sink T10
Worker 脚本 T12
错误码 / 文档 / ADR T13
单发布总闸门 T14
启用非硬门槛 T6 校验不接入 activation checks(显式不改 _source_activation_checks)
Crane 固定出站页 T12
class-prefix 前置 Global Constraints
跨机路径:Windows file_path → Linux drop 文件名映射 T9(测+读)、T12(Worker 只报文件名)、Global Constraints

无 TBD。入站历史错误码 RPA.RECEIPT_* 本计划不强制改名(避免无收益大爆炸);用户可见「收料」文案必须清掉。