|
|
@@ -8,7 +8,10 @@ from mcp_protocol import McpProtocolHandler
|
|
|
from public_gateway import PublicGatewayApp
|
|
|
from public_server import PublicMcpHttpHandler
|
|
|
from services.output_presenter import OutputPresenter
|
|
|
-from tools.goods_ai_pre_audit_common import HINT_FIELDS, HINT_ROW_FIELDS
|
|
|
+from tools.goods_ai_pre_audit_common import (
|
|
|
+ CERTIFICATION_FILE_GROUPS, HINT_FIELDS, HINT_ROW_FIELDS,
|
|
|
+ SAVE_INPUT_SCHEMA, matches_schema,
|
|
|
+)
|
|
|
|
|
|
|
|
|
TOOL_ROUTES = {
|
|
|
@@ -66,6 +69,14 @@ def page_values():
|
|
|
'yf_clearance_data': [],
|
|
|
'sync_orders': [{'order_id': '8', 'order_number': 'SO-8', 'status_name': ''}],
|
|
|
})
|
|
|
+ values.update({
|
|
|
+ 'brand_type': '自主品牌', 'brand': 'Brand A', 'type': 'Model B',
|
|
|
+ 'clearance_hscode': '1234(税率: 5%, 材质占比: 100%)',
|
|
|
+ 'ys_kit_hscode': '1234: 5678', 'ys_adjust_rate': '1234:(加征1: 9901)',
|
|
|
+ 'purchase_price': '19.05', 'purchase_price_usd': '3.00(汇率:6.35)',
|
|
|
+ 'clearance_price': '2.5000 CAD (13.15 CNY)',
|
|
|
+ })
|
|
|
+ values.update(certification_files())
|
|
|
return values
|
|
|
|
|
|
|
|
|
@@ -256,6 +267,30 @@ class GoodsAiPreAuditToolsTest(unittest.TestCase):
|
|
|
self.assertFalse(result['is_error'])
|
|
|
self.assertEqual(data, result['structured_content'])
|
|
|
|
|
|
+ def test_read_presenter_accepts_current_customer_detail_and_certification_page_fields(self):
|
|
|
+ data = read_data()
|
|
|
+ detail = {
|
|
|
+ 'brand_type': '自主品牌', 'brand': 'Brand A', 'type': 'Model B',
|
|
|
+ 'clearance_hscode': '1234(税率: 5%, 材质占比: 100%)',
|
|
|
+ 'ys_kit_hscode': '1234: 5678', 'ys_adjust_rate': '1234:(加征1: 9901)',
|
|
|
+ 'purchase_price': '19.05', 'purchase_price_usd': '3.00(汇率:6.35)',
|
|
|
+ 'clearance_price': '2.5000 CAD (13.15 CNY)',
|
|
|
+ }
|
|
|
+ data['page_values'].update(detail)
|
|
|
+ data['page_values'].update(certification_files())
|
|
|
+ result = OutputPresenter().present('query_goods_ai_pre_audit', envelope(data))
|
|
|
+ self.assertFalse(result['is_error'], result['text'])
|
|
|
+ self.assertEqual(data, result['structured_content'])
|
|
|
+ self.assertEqual(data, json.loads(result['text']))
|
|
|
+ save = save_arguments()
|
|
|
+ save['fields'].update({key: leaf(value) for key, value in detail.items()})
|
|
|
+ save['fields'].update({key: leaf(value) for key, value in certification_files().items()})
|
|
|
+ self.assertTrue(matches_schema(save, SAVE_INPUT_SCHEMA),
|
|
|
+ 'read-only customer evidence fields must remain in the exact field roundtrip')
|
|
|
+ save['fields']['battery_file']['suggested_value'] = certification_files()['battery_file']
|
|
|
+ self.assertFalse(matches_schema(save, SAVE_INPUT_SCHEMA),
|
|
|
+ 'certification evidence fields never accept an AI replacement value')
|
|
|
+
|
|
|
def test_read_presenter_rejects_unknown_and_malformed_nested_content(self):
|
|
|
mutations = [
|
|
|
lambda d: d.update(internal_token='private'),
|
|
|
@@ -303,6 +338,8 @@ class GoodsAiPreAuditToolsTest(unittest.TestCase):
|
|
|
self.assertEqual(original, result['structured_content'])
|
|
|
self.assertEqual(original, json.loads(result['text']))
|
|
|
self.assertEqual(original, data)
|
|
|
+ for group, files in original['context']['certification_files'].items():
|
|
|
+ self.assertEqual(files, original['page_values'][group])
|
|
|
self.assertEqual({'request_id': 'rq_pre_audit'}, result['meta'])
|
|
|
|
|
|
def test_legacy_read_without_certification_files_does_not_invent_empty_groups(self):
|
|
|
@@ -356,6 +393,12 @@ class GoodsAiPreAuditToolsTest(unittest.TestCase):
|
|
|
self.assertTrue(result['is_error'])
|
|
|
self.assertNotIn('private-certification', json.dumps(result))
|
|
|
|
|
|
+ data = read_data()
|
|
|
+ data['page_values'][group] = [valid, item]
|
|
|
+ result = OutputPresenter().present('query_goods_ai_pre_audit', envelope(data))
|
|
|
+ self.assertTrue(result['is_error'])
|
|
|
+ self.assertNotIn('private-certification', json.dumps(result))
|
|
|
+
|
|
|
def test_read_certification_file_urls_reject_unsafe_or_malformed_values(self):
|
|
|
urls = (
|
|
|
'', ' ', 'javascript:alert(1)', 'data:application/pdf;base64,AA==',
|
|
|
@@ -378,8 +421,13 @@ class GoodsAiPreAuditToolsTest(unittest.TestCase):
|
|
|
self.assertTrue(OutputPresenter().present(
|
|
|
'query_goods_ai_pre_audit', envelope(data),
|
|
|
)['is_error'])
|
|
|
+ data = read_data()
|
|
|
+ data['page_values']['other_file'] = [{'name': 'cert.pdf', 'url': url}]
|
|
|
+ self.assertTrue(OutputPresenter().present(
|
|
|
+ 'query_goods_ai_pre_audit', envelope(data),
|
|
|
+ )['is_error'])
|
|
|
|
|
|
- def test_certification_files_are_rejected_outside_readonly_context(self):
|
|
|
+ def test_certification_files_are_limited_to_context_and_page_source_fields(self):
|
|
|
for key in ('certification_files', *certification_files()):
|
|
|
value = certification_files() if key == 'certification_files' else certification_files()[key]
|
|
|
for location in ('top', 'page_values', 'selected_labels', 'context'):
|
|
|
@@ -391,9 +439,11 @@ class GoodsAiPreAuditToolsTest(unittest.TestCase):
|
|
|
'selected_labels': data['context']['selected_labels'],
|
|
|
'context': data['context']}[location]
|
|
|
target[key] = value
|
|
|
- self.assertTrue(OutputPresenter().present(
|
|
|
- 'query_goods_ai_pre_audit', envelope(data),
|
|
|
- )['is_error'])
|
|
|
+ result = OutputPresenter().present('query_goods_ai_pre_audit', envelope(data))
|
|
|
+ if location == 'page_values' and key in CERTIFICATION_FILE_GROUPS:
|
|
|
+ self.assertFalse(result['is_error'])
|
|
|
+ else:
|
|
|
+ self.assertTrue(result['is_error'])
|
|
|
for name, data in (
|
|
|
('claim_goods_ai_pre_audit', claimed()),
|
|
|
('save_goods_ai_pre_audit_result', {'goods_id': 17, 'saved': True,
|
|
|
@@ -405,7 +455,7 @@ class GoodsAiPreAuditToolsTest(unittest.TestCase):
|
|
|
name, envelope(dict(data, **{key: certification_files()})),
|
|
|
)['is_error'])
|
|
|
|
|
|
- def test_local_and_public_inputs_reject_certification_files_and_group_keys(self):
|
|
|
+ def test_local_and_public_inputs_reject_certification_keys_outside_field_rows(self):
|
|
|
local_client, public_client = LocalClient(), PublicClient()
|
|
|
local = GatewayApp(api_client=local_client)
|
|
|
public = PublicGatewayApp(SessionStore(), public_client)
|
|
|
@@ -418,7 +468,7 @@ class GoodsAiPreAuditToolsTest(unittest.TestCase):
|
|
|
for key in ('context', 'certification_files', *certification_files()):
|
|
|
value = certification_files().get(key, certification_files())
|
|
|
cases.append((name, dict(payload, **{key: value})))
|
|
|
- if name == 'save_goods_ai_pre_audit_result':
|
|
|
+ if name == 'save_goods_ai_pre_audit_result' and key in ('context', 'certification_files'):
|
|
|
nested = deepcopy(payload)
|
|
|
nested['fields'][key] = leaf(value)
|
|
|
cases.append((name, nested))
|