- 客户主数据新增 odm_ids 白名单字段(含 Alembic 迁移),表单与管理端支持维护 - 导出库存命中行按客户白名单与整单 ODM 裁决收敛,新增 notice_odm_choice_service - 工作台新增 odm-options / odm-choice 接口,投影行级候选并持久化用户选择 - 修复复核工作台跨 Run 切换时接收解析上下文残留 - 同步四语言 i18n、测试用例、funclist 与 shipping-notice 技术文档
668 lines
30 KiB
Markdown
668 lines
30 KiB
Markdown
# 订单队列图标语义重映射 + needs_attention 标志 实现计划
|
||
|
||
> **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:** 队列行内图标收敛为五态语义(需人工⚠/进行中🔄/终态✓/失败✗/中性○),后端队列下发 `needs_attention` 门禁阻塞标志,summary 计数同口径对齐。
|
||
|
||
**Architecture:** 后端在既有批量 Gate 缓存上新增只读判定函数(零额外 SQL),`_serialize_review_case_summary` 增量输出字段;前端单组件重写 `navIconKind` 优先级链并新增 LoaderCircle 分支。无迁移、无接口破坏性变更。
|
||
|
||
**Tech Stack:** Flask + SQLAlchemy 2.0(后端);Vue 3 `<script setup>` + lucide-vue-next + vitest(前端);pytest(后端测试)。
|
||
|
||
**Spec:** `docs/superpowers/specs/2026-09-16-review-queue-icon-semantics-design.md`
|
||
|
||
## Global Constraints
|
||
|
||
- 🚫 **禁止自动 commit**(用户强规则,覆盖本 skill 模板的提交步骤):每个任务只落盘 + 跑验证,最后统一停在"完成、未提交"状态;仅当用户当轮明确说提交时才 `git add <具体文件>` + commit。
|
||
- 外科手术式改动:只改本计划列出的文件与位置;不顺手改注释/格式/相邻代码。
|
||
- 无数据库迁移;无新增第三方依赖;不改既有字段语义(`status`/`issue_count`/`lifecycle_stage` 原样保留)。
|
||
- 验证基线:改动文件对应测试通过 + `cd frontend && npm run build` 通过(Task 4 统一回归)。
|
||
- 注释遵循 AGENTS.md §5:新增函数带含 Args/Returns 的 docstring;逻辑变化同步更新受影响注释。
|
||
|
||
---
|
||
|
||
### Task 1: 后端 `needs_attention` 字段
|
||
|
||
**Files:**
|
||
- Modify: `backend/app/services/shipping_notice/order_review_projection.py`(在 `_queue_current_gate_hint` 之后、`_serialize_review_case_summary` 之前插入辅助函数;在 `_serialize_review_case_summary` 返回 dict 增加一行)
|
||
- Test: `backend/tests/test_shipping_order_review_service.py`(文件末尾追加 3 个测试)
|
||
|
||
**Interfaces:**
|
||
- Consumes: 会话级缓存 `shipping_conversation_projection_read_cache` 中的 `execution_by_case_id` / `gates_by_execution_id`(`_load_review_case_summary_batch` 已预取,`:1333-1355`)。
|
||
- Produces: 队列 item 新增 `'needs_attention': bool`(`serialize_review_queue` 与 `serialize_review_run` 的 items 均携带);模块级函数 `_queue_gate_needs_attention(case: ShippingOrderReviewCase) -> bool`,Task 2 依赖该字段。
|
||
|
||
- [ ] **Step 1: 追加失败测试**
|
||
|
||
在 `backend/tests/test_shipping_order_review_service.py` 文件末尾追加(fixture 写法仿照同文件 `test_review_queue_falls_back_to_process_gate_when_ot_stage_is_legacy_step`,`:351-406`):
|
||
|
||
```python
|
||
def test_review_queue_flags_blocked_gate_cases_as_needs_attention(app):
|
||
"""门禁 blocked_manual(如库存缺口)的已建任务单,队列必须下发 needs_attention=True。"""
|
||
from app.models import ShippingProcessExecution, ShippingProcessGate
|
||
|
||
with app.app_context():
|
||
user, agent, session, intake, document = _seed_run_input(suffix='REVIEW-QUEUE-NEEDS-ATTN')
|
||
run = _materialized_run(user=user, agent=agent, session=session, intake=intake)
|
||
candidate = ShippingOrderCandidate(
|
||
candidate_no='CAND-REVIEW-QUEUE-NEEDS-ATTN',
|
||
intake_id=intake.id,
|
||
primary_document_id=document.id,
|
||
candidate_key='review-queue-needs-attn',
|
||
order_extraction_run_id=run.id,
|
||
po_number='PO-QUEUE-ATTN',
|
||
)
|
||
db.session.add(candidate)
|
||
db.session.flush()
|
||
case = ensure_review_case_for_unit(run=run, unit=run.extraction_plan.units[0])
|
||
task = ShippingOrderTask(
|
||
task_no='OT-REVIEW-QUEUE-NEEDS-ATTN',
|
||
user_id=user.id,
|
||
conversation_id=session.session_id,
|
||
extraction_run_id=run.id,
|
||
status='processing',
|
||
stage='inventory_preparation',
|
||
)
|
||
db.session.add(task)
|
||
db.session.flush()
|
||
execution = ShippingProcessExecution(
|
||
execution_no='SPE-REVIEW-QUEUE-NEEDS-ATTN',
|
||
task_id=task.id,
|
||
review_case_id=case.id,
|
||
status='active',
|
||
current_gate_code='inventory_sufficiency',
|
||
)
|
||
db.session.add(execution)
|
||
db.session.flush()
|
||
db.session.add(ShippingProcessGate(
|
||
execution_id=execution.id,
|
||
gate_code='inventory_sufficiency',
|
||
sequence_no=16,
|
||
status='blocked_manual',
|
||
))
|
||
task.active_process_execution_id = execution.id
|
||
case.status = 'confirmed'
|
||
case.confirmed_task_id = task.id
|
||
db.session.commit()
|
||
|
||
item = serialize_review_queue([run])['items'][0]
|
||
|
||
# 关键断言:库存缺口类门禁阻塞必须在队列可见,不再只依赖当前单的完整详情。
|
||
assert item['needs_attention'] is True
|
||
assert item['lifecycle_stage'] == 'fulfillment_prep'
|
||
|
||
|
||
def test_review_queue_waiting_external_gate_is_not_needs_attention(app):
|
||
"""RPA 外部等待(waiting_external)属于系统在办,不得标记 needs_attention。"""
|
||
from app.models import ShippingProcessExecution, ShippingProcessGate
|
||
|
||
with app.app_context():
|
||
user, agent, session, intake, document = _seed_run_input(suffix='REVIEW-QUEUE-WAIT-EXT')
|
||
run = _materialized_run(user=user, agent=agent, session=session, intake=intake)
|
||
candidate = ShippingOrderCandidate(
|
||
candidate_no='CAND-REVIEW-QUEUE-WAIT-EXT',
|
||
intake_id=intake.id,
|
||
primary_document_id=document.id,
|
||
candidate_key='review-queue-wait-ext',
|
||
order_extraction_run_id=run.id,
|
||
po_number='PO-QUEUE-WAIT',
|
||
)
|
||
db.session.add(candidate)
|
||
db.session.flush()
|
||
case = ensure_review_case_for_unit(run=run, unit=run.extraction_plan.units[0])
|
||
task = ShippingOrderTask(
|
||
task_no='OT-REVIEW-QUEUE-WAIT-EXT',
|
||
user_id=user.id,
|
||
conversation_id=session.session_id,
|
||
extraction_run_id=run.id,
|
||
status='processing',
|
||
stage='freight_uploading',
|
||
)
|
||
db.session.add(task)
|
||
db.session.flush()
|
||
execution = ShippingProcessExecution(
|
||
execution_no='SPE-REVIEW-QUEUE-WAIT-EXT',
|
||
task_id=task.id,
|
||
review_case_id=case.id,
|
||
status='waiting_external',
|
||
current_gate_code='freight_upload_rpa',
|
||
)
|
||
db.session.add(execution)
|
||
db.session.flush()
|
||
db.session.add(ShippingProcessGate(
|
||
execution_id=execution.id,
|
||
gate_code='freight_upload_rpa',
|
||
sequence_no=18,
|
||
status='waiting_external',
|
||
))
|
||
task.active_process_execution_id = execution.id
|
||
case.status = 'confirmed'
|
||
case.confirmed_task_id = task.id
|
||
db.session.commit()
|
||
|
||
item = serialize_review_queue([run])['items'][0]
|
||
|
||
# 关键断言:外部等待是在办不是待办,图标应走进行中而非需人工。
|
||
assert item['needs_attention'] is False
|
||
|
||
|
||
def test_review_queue_without_execution_is_not_needs_attention(app):
|
||
"""已建任务但尚无 Execution(或缓存未命中)时,needs_attention 必须为 False。"""
|
||
with app.app_context():
|
||
user, agent, session, intake, document = _seed_run_input(suffix='REVIEW-QUEUE-NO-EXEC')
|
||
run = _materialized_run(user=user, agent=agent, session=session, intake=intake)
|
||
candidate = ShippingOrderCandidate(
|
||
candidate_no='CAND-REVIEW-QUEUE-NO-EXEC',
|
||
intake_id=intake.id,
|
||
primary_document_id=document.id,
|
||
candidate_key='review-queue-no-exec',
|
||
order_extraction_run_id=run.id,
|
||
po_number='PO-QUEUE-NOEXEC',
|
||
)
|
||
db.session.add(candidate)
|
||
db.session.flush()
|
||
case = ensure_review_case_for_unit(run=run, unit=run.extraction_plan.units[0])
|
||
task = ShippingOrderTask(
|
||
task_no='OT-REVIEW-QUEUE-NO-EXEC',
|
||
user_id=user.id,
|
||
conversation_id=session.session_id,
|
||
extraction_run_id=run.id,
|
||
status='processing',
|
||
stage='inventory_preparation',
|
||
)
|
||
db.session.add(task)
|
||
db.session.flush()
|
||
case.status = 'confirmed'
|
||
case.confirmed_task_id = task.id
|
||
db.session.commit()
|
||
|
||
item = serialize_review_queue([run])['items'][0]
|
||
|
||
# 关键断言:无门禁事实时不臆造需人工标志。
|
||
assert item['needs_attention'] is False
|
||
```
|
||
|
||
若文件顶部 import 缺少 `ShippingOrderCandidate` / `ShippingOrderTask` / `ensure_review_case_for_unit` / `db`,按同文件既有测试的 import 方式补齐(它们已在既有测试中使用,通常已在顶部导入)。
|
||
|
||
- [ ] **Step 2: 运行验证测试失败**
|
||
|
||
Run: `cd backend && source venv/bin/activate && python -m pytest tests/test_shipping_order_review_service.py::test_review_queue_flags_blocked_gate_cases_as_needs_attention -v`
|
||
Expected: FAIL,`KeyError: 'needs_attention'`
|
||
|
||
- [ ] **Step 3: 实现辅助函数与字段**
|
||
|
||
3a. 在 `order_review_projection.py` 的 `_queue_current_gate_hint` 函数结束(`:1065` 的 `return None`)与 `_serialize_review_case_summary`(`:1068`)之间插入:
|
||
|
||
```python
|
||
# 队列当前 Gate 活跃口径:在 _queue_current_gate_hint 活跃集合上补 queued/failed_terminal,
|
||
# 供 needs_attention 兜底取 Gate,避免终态失败的单被漏判。
|
||
_QUEUE_CURRENT_GATE_STATUSES = frozenset({
|
||
'pending', 'queued', 'running', 'blocked_retryable', 'blocked_manual', 'waiting_external', 'failed_terminal',
|
||
})
|
||
# 需要人工介入的 Gate 状态;waiting_external/running/pending/queued 属系统在办,不算需人工。
|
||
_QUEUE_ATTENTION_GATE_STATUSES = frozenset({'blocked_manual', 'blocked_retryable', 'failed_terminal'})
|
||
|
||
|
||
def _queue_gate_needs_attention(case: ShippingOrderReviewCase) -> bool:
|
||
"""
|
||
判定 Case 当前正式门禁是否需要人工介入;供队列摘要下发 needs_attention。
|
||
|
||
只读会话级批量缓存(_load_review_case_summary_batch 已预取 Execution/Gate),
|
||
零额外 SQL;当前 Gate 取 execution.current_gate_code 对应 Gate,缺失时按
|
||
sequence_no 取第一个活跃 Gate。调用方禁止据此之外再自行推断阻塞。
|
||
|
||
Args:
|
||
case: 当前复核 Case。
|
||
|
||
Returns:
|
||
当前 Gate 状态 ∈ {blocked_manual, blocked_retryable, failed_terminal} 时 True;
|
||
无 Execution / 无活跃 Gate 时 False。
|
||
"""
|
||
cache = db.session.info.get('shipping_conversation_projection_read_cache')
|
||
if not isinstance(cache, dict) or getattr(case, 'id', None) is None:
|
||
return False
|
||
execution = (cache.get('execution_by_case_id') or {}).get(int(case.id))
|
||
if execution is None:
|
||
return False
|
||
gate_code = str(getattr(execution, 'current_gate_code', None) or '').strip().lower()
|
||
gates = (cache.get('gates_by_execution_id') or {}).get(int(execution.id), []) or []
|
||
current = None
|
||
if gate_code:
|
||
for gate in gates:
|
||
if str(getattr(gate, 'gate_code', '') or '').strip().lower() == gate_code:
|
||
current = gate
|
||
break
|
||
if current is None:
|
||
for gate in gates:
|
||
if str(getattr(gate, 'status', '') or '').strip().lower() in _QUEUE_CURRENT_GATE_STATUSES:
|
||
current = gate
|
||
break
|
||
if current is None:
|
||
return False
|
||
return str(getattr(current, 'status', '') or '').strip().lower() in _QUEUE_ATTENTION_GATE_STATUSES
|
||
```
|
||
|
||
3b. 在 `_serialize_review_case_summary` 返回 dict 中,`'issue_count': len(draft.issue_summary_json or []) if draft is not None else 0,`(`:1159`)之后插入一行:
|
||
|
||
```python
|
||
'needs_attention': _queue_gate_needs_attention(case),
|
||
```
|
||
|
||
- [ ] **Step 4: 运行新测试通过**
|
||
|
||
Run: `cd backend && source venv/bin/activate && python -m pytest tests/test_shipping_order_review_service.py -v -k "needs_attention"`
|
||
Expected: 3 passed
|
||
|
||
- [ ] **Step 5: 跑整个测试文件防回归**
|
||
|
||
Run: `cd backend && source venv/bin/activate && python -m pytest tests/test_shipping_order_review_service.py -v`
|
||
Expected: 全部 passed(既有测试只断言 `lifecycle_stage`,不受新字段影响)
|
||
|
||
---
|
||
|
||
### Task 2: 后端 summary 计数对齐
|
||
|
||
**Files:**
|
||
- Modify: `backend/app/services/shipping_notice/order_review_projection.py`(`serialize_review_queue` 前插入归类函数;替换 `:1447-1452` 的 counts 块)
|
||
- Test: `backend/tests/test_shipping_order_review_service.py`(追加 2 个测试)
|
||
|
||
**Interfaces:**
|
||
- Consumes: Task 1 的 item 字段 `needs_attention`。
|
||
- Produces: 模块级函数 `_queue_summary_bucket(item: dict[str, Any]) -> str`(返回 `'needs_action' | 'processing' | 'completed'`);`serialize_review_queue` 返回的 `summary` 三桶新口径。
|
||
|
||
- [ ] **Step 1: 追加失败测试**
|
||
|
||
```python
|
||
def test_review_queue_summary_counts_terminal_stage_as_completed(app):
|
||
"""OT.stage=completed(通知完成)的已建任务单计入 completed,不再计入 processing。"""
|
||
with app.app_context():
|
||
user, agent, session, intake, document = _seed_run_input(suffix='REVIEW-QUEUE-SUM-DONE')
|
||
run = _materialized_run(user=user, agent=agent, session=session, intake=intake)
|
||
candidate = ShippingOrderCandidate(
|
||
candidate_no='CAND-REVIEW-QUEUE-SUM-DONE',
|
||
intake_id=intake.id,
|
||
primary_document_id=document.id,
|
||
candidate_key='review-queue-sum-done',
|
||
order_extraction_run_id=run.id,
|
||
po_number='PO-QUEUE-SUMDONE',
|
||
)
|
||
db.session.add(candidate)
|
||
db.session.flush()
|
||
case = ensure_review_case_for_unit(run=run, unit=run.extraction_plan.units[0])
|
||
task = ShippingOrderTask(
|
||
task_no='OT-REVIEW-QUEUE-SUM-DONE',
|
||
user_id=user.id,
|
||
conversation_id=session.session_id,
|
||
extraction_run_id=run.id,
|
||
status='processing',
|
||
stage='completed',
|
||
)
|
||
db.session.add(task)
|
||
db.session.flush()
|
||
case.status = 'confirmed'
|
||
case.confirmed_task_id = task.id
|
||
db.session.commit()
|
||
|
||
summary = serialize_review_queue([run])['summary']
|
||
|
||
# 关键断言:summary 与五态图标同口径——confirmed+终态=completed 而非 processing。
|
||
assert summary['total'] == 1
|
||
assert summary['completed'] == 1
|
||
assert summary['processing'] == 0
|
||
assert summary['needs_action'] == 0
|
||
|
||
|
||
def test_review_queue_summary_counts_quality_issue_as_needs_action(app):
|
||
"""quality_issue(文件质量异常)从 completed 改归 needs_action,与黄⚠图标一致。"""
|
||
with app.app_context():
|
||
user, agent, session, intake, document = _seed_run_input(suffix='REVIEW-QUEUE-SUM-QI')
|
||
run = _materialized_run(user=user, agent=agent, session=session, intake=intake)
|
||
candidate = ShippingOrderCandidate(
|
||
candidate_no='CAND-REVIEW-QUEUE-SUM-QI',
|
||
intake_id=intake.id,
|
||
primary_document_id=document.id,
|
||
candidate_key='review-queue-sum-qi',
|
||
order_extraction_run_id=run.id,
|
||
po_number='PO-QUEUE-SUMQI',
|
||
)
|
||
db.session.add(candidate)
|
||
db.session.flush()
|
||
case = ensure_review_case_for_unit(run=run, unit=run.extraction_plan.units[0])
|
||
case.status = 'quality_issue'
|
||
db.session.commit()
|
||
|
||
summary = serialize_review_queue([run])['summary']
|
||
|
||
# 关键断言:质量异常是待办不是完成。
|
||
assert summary['needs_action'] == 1
|
||
assert summary['completed'] == 0
|
||
assert summary['processing'] == 0
|
||
|
||
|
||
def test_review_queue_summary_counts_plain_confirmed_as_processing(app):
|
||
"""已建任务、无阻塞、非终态的 confirmed 单计入 processing(对应转圈图标)。"""
|
||
with app.app_context():
|
||
user, agent, session, intake, document = _seed_run_input(suffix='REVIEW-QUEUE-SUM-PROC')
|
||
run = _materialized_run(user=user, agent=agent, session=session, intake=intake)
|
||
candidate = ShippingOrderCandidate(
|
||
candidate_no='CAND-REVIEW-QUEUE-SUM-PROC',
|
||
intake_id=intake.id,
|
||
primary_document_id=document.id,
|
||
candidate_key='review-queue-sum-proc',
|
||
order_extraction_run_id=run.id,
|
||
po_number='PO-QUEUE-SUMPROC',
|
||
)
|
||
db.session.add(candidate)
|
||
db.session.flush()
|
||
case = ensure_review_case_for_unit(run=run, unit=run.extraction_plan.units[0])
|
||
task = ShippingOrderTask(
|
||
task_no='OT-REVIEW-QUEUE-SUM-PROC',
|
||
user_id=user.id,
|
||
conversation_id=session.session_id,
|
||
extraction_run_id=run.id,
|
||
status='processing',
|
||
stage='inventory_preparation',
|
||
)
|
||
db.session.add(task)
|
||
db.session.flush()
|
||
case.status = 'confirmed'
|
||
case.confirmed_task_id = task.id
|
||
db.session.commit()
|
||
|
||
summary = serialize_review_queue([run])['summary']
|
||
|
||
# 关键断言:已创建任务是在办不是完成。
|
||
assert summary['processing'] == 1
|
||
assert summary['completed'] == 0
|
||
assert summary['needs_action'] == 0
|
||
```
|
||
|
||
- [ ] **Step 2: 运行验证测试失败**
|
||
|
||
Run: `cd backend && source venv/bin/activate && python -m pytest tests/test_shipping_order_review_service.py -v -k "summary_counts"`
|
||
Expected: 3 FAILED(terminal 单被计入 processing;quality_issue 被计入 completed;plain confirmed 被计入 completed)
|
||
|
||
- [ ] **Step 3: 实现归类函数并替换 counts**
|
||
|
||
3a. 在 `serialize_review_queue`(`:1380`)定义之前插入:
|
||
|
||
```python
|
||
def _queue_summary_bucket(item: dict[str, Any]) -> str:
|
||
"""
|
||
队列计数桶归类;优先级与前端队列图标一致:需人工 > 终态完成 > 进行中。
|
||
|
||
桶是"处置去向"粗归类,与五态图标非一一映射(non_order 计入 completed,
|
||
图标为中性别灰○);needs_attention(门禁阻塞)恒优先于 completed,
|
||
避免阻塞单被计数成"完成"。
|
||
|
||
Args:
|
||
item: 队列 item 投影(含 status / needs_attention / lifecycle_stage)。
|
||
|
||
Returns:
|
||
'needs_action' | 'completed' | 'processing'。
|
||
"""
|
||
status = str(item.get('status') or '')
|
||
if status in ('unreviewed', 'draft', 'ready', 'quality_issue') or item.get('needs_attention'):
|
||
return 'needs_action'
|
||
if status in ('non_order', 'closed', 'completed') or str(item.get('lifecycle_stage') or '') == 'upload_complete':
|
||
return 'completed'
|
||
return 'processing'
|
||
```
|
||
|
||
3b. 将 `serialize_review_queue` 末尾的 counts 块(原 `:1447-1452`):
|
||
|
||
```python
|
||
counts = {
|
||
'total': len(items),
|
||
'needs_action': sum(1 for item in items if item['status'] in ('unreviewed', 'draft', 'ready')),
|
||
'processing': sum(1 for item in items if item['status'] in ('confirming', 'reparse_pending')),
|
||
'completed': sum(1 for item in items if item['status'] in ('confirmed', 'non_order', 'quality_issue')),
|
||
}
|
||
```
|
||
|
||
替换为:
|
||
|
||
```python
|
||
buckets = [_queue_summary_bucket(item) for item in items]
|
||
counts = {
|
||
'total': len(items),
|
||
'needs_action': buckets.count('needs_action'),
|
||
'processing': buckets.count('processing'),
|
||
'completed': buckets.count('completed'),
|
||
}
|
||
```
|
||
|
||
- [ ] **Step 4: 运行新测试通过**
|
||
|
||
Run: `cd backend && source venv/bin/activate && python -m pytest tests/test_shipping_order_review_service.py -v -k "summary_counts or needs_attention"`
|
||
Expected: 6 passed
|
||
|
||
- [ ] **Step 5: 跑整个测试文件防回归**
|
||
|
||
Run: `cd backend && source venv/bin/activate && python -m pytest tests/test_shipping_order_review_service.py -v`
|
||
Expected: 全部 passed(已核实 `summary` 三桶除本文件外无其他消费方;`test_shipping_conversation_processing_api.py` 等文件的 `needs_action` 属另一投影 `ShippingProcessingProjection`,不受影响)
|
||
|
||
---
|
||
|
||
### Task 3: 前端类型 + 图标映射重写
|
||
|
||
**Files:**
|
||
- Modify: `frontend/src/features/chat/types/shipping.api.types.ts`(`ShippingOrderReviewCaseSummary`,`:2322` 的 `issue_count` 之后)
|
||
- Modify: `frontend/src/features/chat/components/shipping-review/ReviewDocumentNavigation.vue`
|
||
- Test: `frontend/src/features/chat/components/shipping-review/ReviewDocumentNavigation.spec.ts`
|
||
|
||
**Interfaces:**
|
||
- Consumes: 队列 item 的 `needs_attention?: boolean`(Task 1 下发;旧后端缺省按 false)。
|
||
- Produces: `navIconKind(item): 'alert' | 'done' | 'failed' | 'processing' | 'idle'`(删除 `'active'`);`ReviewDocumentNavItem` 新增 `needs_attention?: boolean | null`。
|
||
|
||
- [ ] **Step 1: 追加失败测试**
|
||
|
||
在 `ReviewDocumentNavigation.spec.ts` 的最后一个 `describe` 之后追加:
|
||
|
||
```ts
|
||
describe('ReviewDocumentNavigation queue row status icons', () => {
|
||
/**
|
||
* 以指定字段挂载单行侧栏队列,返回该行按钮包装器。
|
||
*/
|
||
function mountRow(item: Partial<ReviewDocumentNavItem>) {
|
||
return mount(ReviewDocumentNavigation, {
|
||
props: {
|
||
items: [{ case_no: 'C-1', file_name: 'f1.pdf', status: 'draft', ...item }],
|
||
activeCaseNo: 'C-1',
|
||
navAriaLabel: 'nav',
|
||
forceMode: 'sidebar',
|
||
},
|
||
global: { plugins: i18n },
|
||
}).get('[data-testid="review-doc-nav-C-1"]');
|
||
}
|
||
|
||
it('renders confirmed cases as in-progress spinner instead of done check', () => {
|
||
const row = mountRow({ status: 'confirmed' });
|
||
// 关键断言:已创建任务是系统在办中间态,必须转圈而非绿勾。
|
||
expect(row.find('svg.animate-spin').exists()).toBe(true);
|
||
expect(row.find('svg.text-emerald-500').exists()).toBe(false);
|
||
});
|
||
|
||
it('renders ready-to-confirm cases as amber attention icon', () => {
|
||
const row = mountRow({ status: 'ready' });
|
||
// 关键断言:可确认是等人操作,属于待办而非完成。
|
||
expect(row.find('svg.text-amber-500').exists()).toBe(true);
|
||
});
|
||
|
||
it('renders backend gate-blocked cases as amber attention icon', () => {
|
||
const row = mountRow({ status: 'confirmed', needs_attention: true });
|
||
// 关键断言:needs_attention 是后端门禁裁决,优先于中间态转圈。
|
||
expect(row.find('svg.text-amber-500').exists()).toBe(true);
|
||
expect(row.find('svg.animate-spin').exists()).toBe(false);
|
||
});
|
||
|
||
it('reserves the green check for terminal upload_complete', () => {
|
||
const row = mountRow({ status: 'confirmed', lifecycle_stage: 'upload_complete' });
|
||
expect(row.find('svg.text-emerald-500').exists()).toBe(true);
|
||
expect(row.find('svg.animate-spin').exists()).toBe(false);
|
||
});
|
||
|
||
it('renders failed and neutral states as before', () => {
|
||
expect(mountRow({ status: 'failed' }).find('svg.text-rose-500').exists()).toBe(true);
|
||
const idle = mountRow({ status: 'non_order' });
|
||
expect(idle.find('svg.text-muted').exists()).toBe(true);
|
||
expect(idle.find('svg.animate-spin').exists()).toBe(false);
|
||
});
|
||
|
||
it('keeps the truthful state icon on the selected row', () => {
|
||
const row = mountRow({ status: 'draft' });
|
||
// 关键断言:选中态由行高亮表达,图标不再被 active 覆盖成灰圈。
|
||
expect(row.find('svg.text-amber-500').exists()).toBe(true);
|
||
});
|
||
|
||
it('treats missing needs_attention as false for old queue payloads', () => {
|
||
const row = mountRow({ status: 'confirmed', needs_attention: undefined });
|
||
expect(row.find('svg.animate-spin').exists()).toBe(true);
|
||
});
|
||
});
|
||
```
|
||
|
||
- [ ] **Step 2: 运行验证测试失败**
|
||
|
||
Run: `cd frontend && npx vitest run src/features/chat/components/shipping-review/ReviewDocumentNavigation.spec.ts`
|
||
Expected: 新增用例 FAIL(confirmed 画绿勾、选中草稿被灰圈覆盖、`needs_attention` 未消费);既有用例仍 PASS
|
||
|
||
- [ ] **Step 3: 修改类型 `shipping.api.types.ts`**
|
||
|
||
在 `ShippingOrderReviewCaseSummary` 的 `issue_count: number;`(`:2322`)之后插入:
|
||
|
||
```ts
|
||
/** 队列后端按当前门禁裁决:blocked_manual/blocked_retryable/failed_terminal 为 true;前端禁止自行推断阻塞。 */
|
||
needs_attention?: boolean;
|
||
```
|
||
|
||
- [ ] **Step 4: 重写组件映射与模板**
|
||
|
||
4a. `ReviewDocumentNavigation.vue` import 块(`:9-17`)加入 `LoaderCircle`(保持字母序):
|
||
|
||
```ts
|
||
import {
|
||
Check,
|
||
ChevronLeft,
|
||
ChevronRight,
|
||
Circle,
|
||
LoaderCircle,
|
||
Search,
|
||
TriangleAlert,
|
||
X,
|
||
} from 'lucide-vue-next';
|
||
```
|
||
|
||
4b. `ReviewDocumentNavItem` 类型(`:21-31`):`issue_count` 之后新增字段,并同步 `lifecycle_stage` 注释:
|
||
|
||
```ts
|
||
issue_count?: number;
|
||
/** 队列接口按当前门禁裁决的"需人工"标志(blocked_manual/blocked_retryable/failed_terminal);前端禁止自行推断阻塞。 */
|
||
needs_attention?: boolean | null;
|
||
po_number?: string | null;
|
||
customer_name?: string | null;
|
||
stage_label?: string | null;
|
||
/** 队列接口下发的生命周期码;用于阶段文字展示与终态(upload_complete)绿勾判定,不参与阶段裁决。 */
|
||
lifecycle_stage?: ReviewLifecycleStageCode | null;
|
||
```
|
||
|
||
4c. 整体替换 `navIconKind` 函数(`:120-133`):
|
||
|
||
```ts
|
||
/**
|
||
* 队列状态图标语义,按优先级命中即停:
|
||
* 失败 → 需人工(草稿问题数 / needs_attention 门禁阻塞)→ 终态绿勾
|
||
* → 等人状态 ⚠ → 系统在办转圈 → 中性灰圈 → 兜底转圈。
|
||
* 绿勾只属于终态(upload_complete / closed / completed);选中态由行高亮表达,
|
||
* 本函数不感知选中,图标永远如实反映状态。
|
||
*/
|
||
function navIconKind(item: ReviewDocumentNavItem): 'alert' | 'done' | 'failed' | 'processing' | 'idle' {
|
||
const status = String(item.status || '').toLowerCase();
|
||
if (status === 'failed' || status === 'error') return 'failed';
|
||
if ((item.issue_count && item.issue_count > 0) || item.needs_attention === true) return 'alert';
|
||
if (item.lifecycle_stage === 'upload_complete' || status === 'completed' || status === 'closed') return 'done';
|
||
if (['draft', 'ready', 'unreviewed', 'quality_issue', 'pending_review', 'waiting_review'].includes(status)) return 'alert';
|
||
if (['confirmed', 'confirming', 'processing', 'reparse_pending', 'queued'].includes(status)) return 'processing';
|
||
if (['non_order', 'cancelled', 'superseded'].includes(status)) return 'idle';
|
||
return 'processing';
|
||
}
|
||
```
|
||
|
||
4d. `matchesStatusFilter`(`:142`)的 processing 分支改为:
|
||
|
||
```ts
|
||
if (statusFilter.value === 'processing') return kind === 'processing';
|
||
```
|
||
|
||
4e. tabs 模板分支(`:216-225` 的 `<X>` 块之后、`<Circle>` 之前)插入:
|
||
|
||
```html
|
||
<LoaderCircle
|
||
v-else-if="navIconKind(item) === 'processing'"
|
||
class="h-3.5 w-3.5 shrink-0 animate-spin text-brand-600"
|
||
aria-hidden="true"
|
||
/>
|
||
```
|
||
|
||
4f. sidebar 模板分支(`:328-331` 的 `<X>` 块之后、`<Circle>` 之前)插入(该分支图标不带 aria-hidden,保持一致):
|
||
|
||
```html
|
||
<LoaderCircle
|
||
v-else-if="navIconKind(item) === 'processing'"
|
||
class="mt-0.5 h-3.5 w-3.5 shrink-0 animate-spin text-brand-600"
|
||
/>
|
||
```
|
||
|
||
- [ ] **Step 5: 运行新测试通过**
|
||
|
||
Run: `cd frontend && npx vitest run src/features/chat/components/shipping-review/ReviewDocumentNavigation.spec.ts`
|
||
Expected: 全部 passed(含既有 8 个用例)
|
||
|
||
- [ ] **Step 6: 构建验证**
|
||
|
||
Run: `cd frontend && npm run build`
|
||
Expected: 构建通过,无 vue-tsc 类型错误
|
||
|
||
---
|
||
|
||
### Task 4: 文档同步 + 全量回归
|
||
|
||
**Files:**
|
||
- Modify: `docs/features/shipping-notice/technical.md`(文件末尾追加章节)
|
||
- Modify: `docs/funclist.md`(`:95` 工作台条目所在表格追加一行)
|
||
|
||
**Interfaces:**
|
||
- Consumes: Task 1–3 的最终实现。
|
||
- Produces: 与代码一致的权威文档(AGENTS.md §9 要求同一 PR 内同步)。
|
||
|
||
- [ ] **Step 1: technical.md 末尾追加**
|
||
|
||
在 `docs/features/shipping-notice/technical.md` 文件末尾(「客户数据 ODM ID 范围与整单 ODM 裁决(2026-09)」章节之后)追加:
|
||
|
||
```markdown
|
||
## 订单队列五态图标与 needs_attention(2026-09)
|
||
|
||
- 队列接口(`serialize_review_queue` / `serialize_review_run` 共用的 `_serialize_review_case_summary`)每个 item 新增 `needs_attention: bool`:复用批量预取的 Execution/Gate 会话缓存(零额外 SQL),当前 Gate(优先 `execution.current_gate_code`,缺失按 `sequence_no` 取第一个活跃 Gate)状态 ∈ {`blocked_manual`, `blocked_retryable`, `failed_terminal`} 时为 True;`waiting_external`/`running`/`pending`/`queued` 属系统在办。前端禁止自行推断阻塞。
|
||
- 左侧文件队列图标五态口径(`ReviewDocumentNavigation.vue` 的 `navIconKind`,优先级命中即停):失败 ✗ → 需人工 ⚠(`issue_count>0` 或 `needs_attention`,以及 `draft`/`ready`/`unreviewed`/`quality_issue`)→ 终态绿勾 ✓(`lifecycle_stage=upload_complete` 或 `closed`/`completed`)→ 系统在办蓝转圈(`confirmed`/`confirming`/`processing`/`reparse_pending`/`queued`)→ 中性灰圈(`non_order`/`cancelled`/`superseded`)→ 兜底转圈。绿勾不再被「已创建任务」等中间态占用;选中态仅由行高亮表达。
|
||
- 队列 `summary` 三桶与图标同口径(`_queue_summary_bucket`):`quality_issue` 归 needs_action;`confirmed` 归 processing;仅终态归 completed。前端当前未消费三桶,属契约纠偏。
|
||
- 已知边界(fail-safe):队列 `lifecycle_stage` 为轻量投影,极端场景会偏早(兜回 `intake_parse`),后果是完成单暂不亮绿勾;反向(未完成亮绿勾)不可能——`upload_complete` 仅由已持久化 `OT.stage=completed` 驱动。
|
||
```
|
||
|
||
- [ ] **Step 2: funclist.md 追加条目**
|
||
|
||
在 `docs/funclist.md:95`(「订单生命周期工作台状态展示统一(v2)」行)之后同表追加一行:
|
||
|
||
```markdown
|
||
| 订单队列五态图标与门禁阻塞标志 | 已实现 | 队列 item 新增 `needs_attention`(复用批量 Gate 缓存零额外 SQL,blocked_manual/blocked_retryable/failed_terminal 为真);左侧文件队列图标收敛为 需人工⚠/进行中🔄/终态✓/失败✗/中性○ 五态,绿勾仅限通知完成终态;队列 summary 三桶同口径。设计:[2026-09-16 队列图标语义设计](superpowers/specs/2026-09-16-review-queue-icon-semantics-design.md) |
|
||
```
|
||
|
||
- [ ] **Step 3: 全量回归**
|
||
|
||
Run: `cd backend && source venv/bin/activate && python -m pytest tests/test_shipping_order_review_service.py -v`
|
||
Expected: 全部 passed
|
||
|
||
Run: `cd frontend && npx vitest run src/features/chat/components/shipping-review/ReviewDocumentNavigation.spec.ts && npm run build`
|
||
Expected: 测试全过、构建通过
|
||
|
||
- [ ] **Step 4: 停在"完成、未提交"**
|
||
|
||
向用户汇报改动文件清单与验证结果;**不执行任何 git add/commit**,等用户指示。
|