feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-08-06 10:18:37 +08:00
1 parent 3a9fbac2fc
commit d2b3d74def
571 files changed
+78064 -24681

No files matched your search

@@ -184,3 +184,90 @@ def test_association_chain_expands_across_workflow_keys(app):
event_type='audit_access', action='list_audit_association_chain',
).count()
assert access >= 1
def test_xfa_full_snapshot_requires_sensitive_read_and_re_audits(app):
"""只有 audit_sensitive_read 可读完整快照;每次读取再写访问审计。"""
from app.services.shipping_notice.audit_query_service import get_xfa_audit_full_snapshot
from app.services.shipping_notice.audit_snapshot_service import create_xfa_audit_snapshot
with app.app_context():
if not str(app.config.get('SECRET_KEY') or '').strip():
app.config['SECRET_KEY'] = 'test-shipping-xfa-audit-secret'
row = create_xfa_audit_snapshot(
payload={'secret_po': '4510039227', 'definition_checksum': 'cs'},
object_type='shipping_order_document_profile',
object_id='88',
purpose='after',
operation_id='op-sens-read',
)
db.session.commit()
ref = row.snapshot_ref
redacted = get_xfa_audit_full_snapshot(
admin_user_id=9,
request_id='req-xfa-deny',
snapshot_ref=ref,
include_sensitive=False,
)
# 关键断言:无权限仅脱敏摘要,无完整 payload。
assert redacted['sensitive_redacted'] is True
assert redacted['payload'] is None
assert 'secret_po' not in str(redacted.get('summary') or {})
allowed = get_xfa_audit_full_snapshot(
admin_user_id=9,
request_id='req-xfa-allow',
snapshot_ref=ref,
include_sensitive=True,
)
assert allowed['sensitive_redacted'] is False
assert allowed['payload']['secret_po'] == '4510039227'
views = (
ShippingAuditEvent.query
.filter_by(event_type='xfa_audit_snapshot_viewed', aggregate_id=ref)
.order_by(ShippingAuditEvent.id.asc())
.all()
)
# 关键断言:拒绝与允许各产生一条访问审计。
assert len(views) >= 2
actions = {v.action for v in views}
assert 'read_xfa_snapshot_redacted' in actions
assert 'read_xfa_snapshot_full' in actions
def test_ordinary_export_is_redacted_summary_only(app):
"""普通导出仅含脱敏摘要,不含完整快照正文。"""
from app.services.shipping_notice.audit_query_service import export_shipping_audit_events
with app.app_context():
if not str(app.config.get('SECRET_KEY') or '').strip():
app.config['SECRET_KEY'] = 'test-shipping-xfa-audit-secret'
app.config['SHIPPING_NOTICE_AUDIT_EXPORT_ENABLED'] = True
append_shipping_audit_event(
event_type='xfa_mapping_saved',
aggregate_type='shipping_order_document_profile',
aggregate_id='export-1',
actor_type='admin',
actor_id=1,
operation_id='op-export',
request_id='req-export',
result='success',
sensitivity_level='sensitive',
after={'definition_checksum': 'exp-cs', 'template_mode': 'xfa_dataset'},
full_after={'definition': {'po': 'SECRET-PO'}, 'definition_checksum': 'exp-cs'},
)
db.session.commit()
exported = export_shipping_audit_events(
admin_user_id=1,
request_id='req-export-run',
filters={'aggregate_id': 'export-1'},
limit=50,
format='json',
)
content = exported['content']
# 关键断言:导出不含完整 definition 或 SECRET-PO。
assert 'SECRET-PO' not in content
assert 'ciphertext' not in content