feat(shipping-notice): 添加 RPA 工作者心跳告警开关,更新环境配置以支持样本证据历史记录
This commit is contained in:
1 parent
705971ad03
commit
88408490d7
34 files changed
+1697
-109
No files matched your search
@@ -16,7 +16,7 @@ from app.services.admin import shipping_inventory_service
|
||||
from app.services.shipping_notice import inventory_parsing_profile
|
||||
from app.services.shipping_notice.order_schema import service as order_schema_service
|
||||
from app import db
|
||||
from app.models import ShippingExcelTemplate, ShippingInventoryField
|
||||
from app.models import ShippingExcelTemplate, ShippingInventoryField, ShippingInventoryStructureAnalysis
|
||||
|
||||
|
||||
def _profile_data(*, code: str = 'DBS_EU', connector_type: str = 'dbs') -> dict:
|
||||
@@ -27,6 +27,26 @@ def _profile_data(*, code: str = 'DBS_EU', connector_type: str = 'dbs') -> dict:
|
||||
}
|
||||
|
||||
|
||||
def _sample_evidence() -> int:
|
||||
"""创建最小表头证据,确保库存源服务测试不绕过解析方案样本门禁。"""
|
||||
item = ShippingInventoryStructureAnalysis(
|
||||
source_kind='sample_upload', source_file_name='service-sample.xlsx', storage_path=None,
|
||||
file_checksum='b' * 64, file_format='xlsx', analysis_status='ready',
|
||||
structure_json={'candidates': [{
|
||||
'sheet_name': None, 'header_row_index': 1,
|
||||
'headers': ['Supplier Sku', 'Reservation ID', 'Qty Available'],
|
||||
'columns': [
|
||||
{'header': 'Supplier Sku', 'duplicate': False},
|
||||
{'header': 'Reservation ID', 'duplicate': False},
|
||||
{'header': 'Qty Available', 'duplicate': False},
|
||||
],
|
||||
}]}, suggested_mapping_json={}, validation_summary_json={}, sample_rows_json=[], warning_json=[],
|
||||
)
|
||||
db.session.add(item)
|
||||
db.session.flush()
|
||||
return item.id
|
||||
|
||||
|
||||
def _parsing_profile() -> dict:
|
||||
"""发布可由多个库存源共享的最小库存解析 Profile。"""
|
||||
state = order_schema_service.get_state()
|
||||
@@ -63,6 +83,7 @@ def _parsing_profile() -> dict:
|
||||
assert set(inventory_fields) == {'part_number', 'reservation_id', 'available_qty'}
|
||||
draft = inventory_parsing_profile.save_draft({
|
||||
'profile_code': 'COMMON_DBS', 'display_name': 'Common DBS', 'file_format': 'xlsx',
|
||||
'sample_analysis_id': _sample_evidence(),
|
||||
'definition': {
|
||||
'header_row_index': 1,
|
||||
'field_mapping': {
|
||||
@@ -206,6 +227,35 @@ def test_activation_is_a_separate_gate_and_reports_unfinished_steps(app):
|
||||
assert exc_info.value.details['missing_requirements'] == ['parsing_profile', 'excel_template', 'configuration_test']
|
||||
|
||||
|
||||
def test_activation_status_exposes_structured_checks_without_duplicate_test_blocks(app):
|
||||
"""未测试站点应显示后续验证步骤,但只由测试门禁阻断,避免管理员面对重复待办。"""
|
||||
app.config['SHIPPING_NOTICE_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
|
||||
with app.app_context():
|
||||
login = shipping_inventory_service.save_profile(_profile_data(code='CHECKS_LOGIN'), actor_id=None)
|
||||
payload = {
|
||||
'source_code': 'CHECKS_SOURCE', 'display_name': 'Checks Source', 'connector_type': 'dbs',
|
||||
'rpa_profile_id': login['id'], 'parsing_profile_id': None, 'excel_template_id': None,
|
||||
'warehouse_resolution_mode': 'fixed', 'fixed_warehouse_id': 'DUB', 'snapshot_ttl_seconds': 3600,
|
||||
'report_path_json': {
|
||||
'program_group': 'Bison', 'program_label': 'AWSBI',
|
||||
'report_group': 'Inventory', 'report_name': 'On Hand',
|
||||
},
|
||||
'query_parameters_json': [], 'match_aliases_json': [], 'enabled': False,
|
||||
}
|
||||
draft = shipping_inventory_service.save_source(payload, actor_id=None, allow_enable_transition=False)
|
||||
|
||||
checks = {item['code']: item for item in draft['activation']['checks']}
|
||||
|
||||
# 关键断言:未进行测试时,解析/仓库验证被展示为待测试而非额外阻断门禁。
|
||||
assert checks['configuration_test']['blocking'] is True
|
||||
assert checks['configuration_test']['evidence'] == {'state': 'not_started'}
|
||||
assert checks['parsing_validation']['status'] == 'pending'
|
||||
assert checks['parsing_validation']['blocking'] is False
|
||||
assert checks['warehouse_mapping']['status'] == 'pending'
|
||||
assert checks['warehouse_mapping']['blocking'] is False
|
||||
assert draft['activation']['missing_requirements'] == ['parsing_profile', 'excel_template', 'configuration_test']
|
||||
|
||||
|
||||
def test_enabled_source_rejects_disabled_rpa_profile(app):
|
||||
"""启用库存源不得绑定停用连接,避免后台配置与运行时读取结果不一致。"""
|
||||
app.config['SHIPPING_NOTICE_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
|
||||
|
||||
Reference in new issue
Block a user