feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3a9fbac2fc
commit
d2b3d74def
571 files changed
+78064
-24681
No files matched your search
@@ -8,6 +8,9 @@ backend/tests/test_shipping_audit_event.py
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from app import db
|
||||
@@ -178,3 +181,41 @@ def test_stage0_i18n_key_inventory_is_frozen():
|
||||
assert 'shippingOrderExtractionHealthTip.processing_attention' in joined
|
||||
assert 'SHIPPING_NOTICE.CANCEL_REASON_REQUIRED' in joined
|
||||
assert 'admin.shippingAudit.export' in joined
|
||||
|
||||
|
||||
def test_shipping_audit_result_literals_follow_service_contract():
|
||||
"""生产代码中的审计 result 字面量必须受统一枚举约束,禁止 ok/failed/needs_review 等业务状态越界。"""
|
||||
allowed_results = {'success', 'failure', 'rejected', 'ignored'}
|
||||
backend_app = Path(__file__).resolve().parents[1] / 'app'
|
||||
invalid_literals: list[str] = []
|
||||
|
||||
def _result_literal_values(node: ast.AST) -> list[str]:
|
||||
"""提取 result 表达式实际可能返回的字符串分支,不把比较条件中的事件名误判为结果值。"""
|
||||
if isinstance(node, ast.Constant) and isinstance(node.value, str):
|
||||
return [node.value]
|
||||
if isinstance(node, ast.IfExp):
|
||||
return _result_literal_values(node.body) + _result_literal_values(node.orelse)
|
||||
return []
|
||||
|
||||
# 关键断言:递归检查条件表达式中的所有字符串分支,避免只验证最终运行到的单一路径。
|
||||
for source_path in backend_app.rglob('*.py'):
|
||||
tree = ast.parse(source_path.read_text(encoding='utf-8-sig'), filename=str(source_path))
|
||||
for node in ast.walk(tree):
|
||||
if not isinstance(node, ast.Call):
|
||||
continue
|
||||
function_name = (
|
||||
node.func.id if isinstance(node.func, ast.Name)
|
||||
else node.func.attr if isinstance(node.func, ast.Attribute)
|
||||
else ''
|
||||
)
|
||||
if function_name not in {'append_shipping_audit_event', '_layout_job_audit'}:
|
||||
continue
|
||||
result_keyword = next((item for item in node.keywords if item.arg == 'result'), None)
|
||||
if result_keyword is None:
|
||||
continue
|
||||
for result_value in _result_literal_values(result_keyword.value):
|
||||
if result_value not in allowed_results:
|
||||
relative_path = source_path.relative_to(backend_app.parent)
|
||||
invalid_literals.append(f'{relative_path}:{node.lineno}:{result_value}')
|
||||
|
||||
assert invalid_literals == []
|
||||
Reference in new issue
Block a user