优化:未分类连续维护与柏拉图预汇总,同步已发布修复

This commit is contained in:
2026-11-01 12:40:50 +08:00
parent 572873c6b8
commit 38290f5fec
135 changed files with 17613 additions and 663 deletions
+81 -1
View File
@@ -12,7 +12,8 @@ from unittest.mock import MagicMock, patch
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'scripts'))
import nao_quality_runtime as runtime
from nao_protocol_execution import execute
from nao_protocol_execution import (execute, _controlled_failure_diagnostic,
_private_failure_diagnostic, _private_module_provenance)
from nao_agent_task import normalize_task, bind_task
from test_nao_agent_task import task_value
from test_nao_quality_tools import FakeApi, RELEASE
@@ -85,6 +86,85 @@ class BoundRankingApi(BoundApi):
return result
class ProtocolExecutionTests(unittest.TestCase):
def test_controlled_failure_diagnostics_classify_without_copying_exception_text(self):
from nao_quality_tools import QualityToolError, SourceCoverageUnavailable
source = _controlled_failure_diagnostic(
SourceCoverageUnavailable({'year': 2026, 'month': 9}), node_id='rank', purpose='ranking')
self.assertEqual(source['failureKind'], 'source_coverage')
self.assertEqual(source['nodeId'], 'rank')
self.assertNotIn('message', source)
upstream = runtime.RuntimeErrorSafe('token=secret SELECT * FROM private_table',
retryable=True, http_status=503)
transient = _controlled_failure_diagnostic(upstream, node_id='rank', purpose='ranking')
self.assertEqual(transient['failureKind'], 'transient_http')
self.assertEqual(transient['httpStatus'], 503)
self.assertTrue(transient['retryable'])
self.assertNotIn('secret', str(transient))
self.assertNotIn('private_table', str(transient))
denied = _controlled_failure_diagnostic(
runtime.RuntimeErrorSafe('upstream detail must not escape', retryable=False, http_status=403),
node_id='rank', purpose='ranking')
self.assertEqual(denied['failureKind'], 'http_error')
self.assertEqual(denied['httpStatus'], 403)
self.assertFalse(denied['retryable'])
self.assertNotIn('upstream detail', str(denied))
rejected = _controlled_failure_diagnostic(QualityToolError('scope=private-value'),
node_id='metrics', purpose='metrics')
self.assertEqual(rejected['failureKind'], 'formal_query_rejected')
self.assertNotIn('private-value', str(rejected))
product = '07394-L0.323XR28.96XR28.96X5.398X8.11+R+Z'
import nao_weight_ranking
import nao_combined_ranking
error = QualityToolError('正式指标接口未确认 filters.product;结果已拒绝。' + product)
try:
raise error
except QualityToolError as captured:
captured._quality_private_rank_trace = {
'queryId': 'private-query-id',
'coverageSourceMonths': [{'year': 2026, 'month': 9, 'blackRows': 2, 'brightRows': 15}],
'summaryCoverage': {'blackRows': 2, 'brightRows': 0},
}
error = captured
public = _controlled_failure_diagnostic(error, node_id='rank', purpose='ranking')
private = _private_failure_diagnostic(error, public, {'filters': {'product': product}}, {
'mode': 'rank', 'dimension': 'product', 'metric': 'scrapWeight',
'stage': None, 'limit': 1, 'filters': {'product': product},
})
self.assertNotIn('errorSummary', public)
self.assertNotIn('queryInput', public)
self.assertNotIn('rankResponseTrace', public)
self.assertIn('正式指标接口未确认 filters.product', private['errorSummary'])
self.assertNotIn(product, private['errorSummary'])
self.assertEqual(private['rankResponseTrace']['queryId'], 'private-query-id')
self.assertEqual(private['rankResponseTrace']['summaryCoverage'], {'blackRows': 2, 'brightRows': 0})
self.assertTrue(any(frame['function'] == 'test_controlled_failure_diagnostics_classify_without_copying_exception_text'
and frame['file'] == 'test_nao_protocol_execution.py'
for frame in private['exceptionFrames']))
self.assertNotIn('exceptionFrames', public)
self.assertEqual(private['queryInput'], {
'mode': 'rank', 'dimension': 'product', 'metric': 'scrapWeight',
'stage': None, 'limit': 1,
})
provenance = private['moduleProvenance']
self.assertNotIn('moduleProvenance', public)
for module_name, function_name in (
('nao_weight_ranking', 'rank_response'),
('nao_combined_ranking', 'combined_response')):
with self.subTest(module=module_name):
module = provenance['modules'][module_name]
self.assertTrue(module['loaded'])
self.assertTrue(module['file'].endswith('/scripts/' + module_name + '.py'))
self.assertEqual(len(module['functions'][function_name]), 64)
unsafe = _private_failure_diagnostic(
QualityToolError('SELECT * FROM private_table; token=secret'), public, {})
self.assertEqual(unsafe['errorSummary'], '受控查询校验失败;详细内容已隐藏。')
self.assertNotIn('private_table', unsafe['errorSummary'])
def test_comparison_returns_both_proofs_and_the_confirmed_comparison_context(self):
value=task_value(kind='metrics',dimensions=[],stages=['black'],fields=['rate'],trendRequired=False,
comparisonRequired=True,period={'year':2026,'month':9},comparisonPeriod={'year':2026,'month':8},visualPreference='none')