优化:未分类连续维护与柏拉图预汇总,同步已发布修复
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import copy
|
||||
import io
|
||||
import json
|
||||
import sys
|
||||
@@ -220,6 +221,77 @@ class AgentTaskTest(unittest.TestCase):
|
||||
self.assertEqual(planned['fields'],['totalWeight','scrapRate'])
|
||||
self.assertTrue(planned['trendRequired'])
|
||||
|
||||
def test_stage_weight_top_with_same_stage_rate_uses_ranking_top_child(self):
|
||||
from unittest.mock import patch
|
||||
cases = [
|
||||
('black','scrapWeight','黑片','报废重量',3),
|
||||
('bright','totalWeight','亮片','投入重量',2),
|
||||
]
|
||||
for stage, metric, stage_label, metric_label, count in cases:
|
||||
with self.subTest(stage=stage,metric=metric,count=count):
|
||||
question = (f'按{stage_label}{metric_label}排名前{count}个规格,'
|
||||
f'并显示同批规格的{stage_label}合格率')
|
||||
plan = [
|
||||
{'nodeId':'rank','purpose':'ranking','dimension':'product','limit':count,
|
||||
'fields':[metric],'stages':[stage],'selector':{'kind':'base'},
|
||||
'visualType':'bar','visualPreference':'auto','comparisonRequired':False},
|
||||
{'nodeId':'top_rate','purpose':'metrics','fields':['rate'],'stages':[stage],
|
||||
'selector':{'kind':'ranking_top','sourceNodeId':'rank','stage':stage,
|
||||
'metric':metric,'count':count},
|
||||
'visualType':None,'visualPreference':'none','comparisonRequired':False},
|
||||
]
|
||||
invalid_plan = copy.deepcopy(plan)
|
||||
invalid_plan[1]['selector'].pop('count')
|
||||
invalid = task_value(goal=question,kind='analysis',queryPlan=invalid_plan,
|
||||
dimensions=['product'],fields=[metric,'rate'],stages=[stage],
|
||||
dimensionStages={'product':[stage]},trendRequired=False,comparisonRequired=False,
|
||||
period={'year':2026,'month':9},visualPreference='auto')
|
||||
valid = {**invalid,'queryPlan':plan}
|
||||
review = {**semantic_ok(),'requiresTrend':False,'requiresComparison':False}
|
||||
with patch('nao_agent_task._model_json',side_effect=[invalid,valid,review]) as call:
|
||||
planned = plan_task(base_url='https://offline.invalid/v1',api_key='synthetic',model='m',
|
||||
question=question,context={'_protocol':{'version':1}},
|
||||
cancel_event=threading.Event())
|
||||
|
||||
self.assertEqual(planned['goal'],question)
|
||||
self.assertEqual(planned['rootGoal'],question)
|
||||
self.assertEqual(planned['kind'],'analysis')
|
||||
self.assertEqual(planned['dimensions'],['product'])
|
||||
self.assertEqual(set(planned['fields']),{metric,'rate'})
|
||||
self.assertEqual(planned['stages'],[stage])
|
||||
self.assertEqual(planned['dimensionStages'],{'product':[stage]})
|
||||
self.assertFalse(planned['trendRequired'])
|
||||
self.assertFalse(planned['comparisonRequired'])
|
||||
self.assertEqual(len(planned['queryPlan']),2)
|
||||
rank, rate = planned['queryPlan']
|
||||
self.assertEqual((rank['purpose'],rank['fields'],rank['stages'],rank['limit']),
|
||||
('ranking',[metric],[stage],count))
|
||||
self.assertEqual(rank['selector'],{'kind':'base'})
|
||||
self.assertEqual(rank['visualPreference'],'auto')
|
||||
self.assertEqual(rate['purpose'],'metrics')
|
||||
self.assertEqual(rate['fields'],['rate'])
|
||||
self.assertEqual(rate['stages'],[stage])
|
||||
self.assertEqual(rate['selector'],{'kind':'ranking_top','sourceNodeId':'rank',
|
||||
'stage':stage,'metric':metric,'count':count})
|
||||
self.assertIsNone(rate['visualType'])
|
||||
self.assertEqual(rate['visualPreference'],'none')
|
||||
self.assertNotIn('defect',planned['dimensions'])
|
||||
|
||||
system = call.call_args_list[0].kwargs['system']
|
||||
self.assertIn('这批对象同阶段rate',system)
|
||||
self.assertIn('rate节点只查rate',system)
|
||||
review_system = call.call_args_list[2].kwargs['system']
|
||||
self.assertIn('source/stage/metric/count与重量ranking一致',review_system)
|
||||
retry = call.call_args_list[1].kwargs['payload']
|
||||
self.assertIn('ranking_top for the same objects',
|
||||
retry['requiredShapes']['queryPlanRankingTopStageRate'])
|
||||
self.assertIn('保持ranking重量选择与ranking_top rate子查询',
|
||||
retry['repairInstructions'])
|
||||
|
||||
from nao_native_planning import NATIVE_ROOT_PROMPT, STATIC_NODE_CONTRACT
|
||||
self.assertIn('按一个阶段的totalWeight或scrapWeight选产品Top N',NATIVE_ROOT_PROMPT)
|
||||
self.assertIn('selector={\"kind\":\"ranking_top\"',STATIC_NODE_CONTRACT)
|
||||
|
||||
def test_query_plan_prompt_explains_selector_objects_and_root_stage_union(self):
|
||||
from unittest.mock import patch
|
||||
nodes = [
|
||||
@@ -550,6 +622,63 @@ class AgentTaskTest(unittest.TestCase):
|
||||
self.assertEqual(task['historyMode'],'first')
|
||||
self.assertEqual(task['planRecovery']['modelAttempts'],2)
|
||||
|
||||
def test_history_report_allows_null_period_fields_after_previous_report_retry(self):
|
||||
from unittest.mock import patch
|
||||
# A previous report can itself be PARTIAL and have no receipt. Its
|
||||
# summary task remains useful conversation context, but it must not
|
||||
# turn an explicit null date in the next report proposal into a fresh
|
||||
# scope change or become the source set for the report.
|
||||
previous = task_value(goal='整合会话已确认结果', kind='report', historyMode='all',
|
||||
freshQuery=False, dimensions=[], dimensionStages={}, fields=[], stages=[],
|
||||
comparisonRequired=False, trendRequired=False, filterUpdates={},
|
||||
period=None, comparisonPeriod=None, visualPreference='none',
|
||||
periodCoverage='complete')
|
||||
previous['question'] = '基于本会话已完成的结果生成综合报告,按各轮实际期间和范围组织。'
|
||||
previous.update(historySelectionHash='a' * 64,
|
||||
historySourceTurnIds=['completed-1', 'completed-2', 'completed-3'])
|
||||
context = {
|
||||
'year': 2026, 'month': 9, 'view': 'overall', 'filters': {},
|
||||
'_agentTask': previous,
|
||||
'_serverHistory': [
|
||||
{'turnId': 'completed-1', 'status': 'COMPLETED'},
|
||||
{'turnId': 'completed-2', 'status': 'COMPLETED'},
|
||||
{'turnId': 'completed-3', 'status': 'COMPLETED'},
|
||||
{'turnId': 'partial-report-no-receipt', 'status': 'PARTIAL'},
|
||||
],
|
||||
'_serverQuestions': [
|
||||
{'turnId': 'completed-1', 'question': '9月3C规格Top5', 'status': 'COMPLETED'},
|
||||
{'turnId': 'completed-2', 'question': '9月Top产品', 'status': 'COMPLETED'},
|
||||
{'turnId': 'completed-3', 'question': '清除筛选后查看8月全公司Top3', 'status': 'COMPLETED'},
|
||||
{'turnId': 'partial-report-no-receipt', 'question': '整合会话结果', 'status': 'PARTIAL'},
|
||||
],
|
||||
'_protocol': {'version': 1, 'autonomousEnabled': True, 'previousTask': previous},
|
||||
}
|
||||
proposal = task_value(goal='基于已完成的会话结果生成报告', kind='report',
|
||||
historyMode='all', freshQuery=False, dimensions=[], dimensionStages={}, fields=[],
|
||||
stages=[], comparisonRequired=False, trendRequired=False, filterUpdates={},
|
||||
period=None, comparisonPeriod=None)
|
||||
with patch('nao_agent_task._model_json', return_value=proposal):
|
||||
task = plan_task(base_url='https://offline.invalid/v1', api_key='synthetic', model='m',
|
||||
question='基于本会话已完成的结果生成报告,不查询新数据。', context=context,
|
||||
previous=previous, cancel_event=threading.Event())
|
||||
self.assertEqual(task['kind'], 'report')
|
||||
self.assertEqual(task['historyMode'], 'all')
|
||||
self.assertFalse(task['freshQuery'])
|
||||
self.assertIsNone(task['period'])
|
||||
self.assertIsNone(task['comparisonPeriod'])
|
||||
self.assertEqual(task['filters'], {})
|
||||
self.assertNotIn('historySourceTurnIds', task)
|
||||
self.assertNotIn('historySelectionHash', task)
|
||||
for scope_change in (
|
||||
{'period': {'year': 2026, 'month': 9}},
|
||||
{'comparisonPeriod': {'year': 2026, 'month': 8}},
|
||||
{'filterUpdates': {'group': '消费电子-3C'}},
|
||||
):
|
||||
with self.subTest(scope_change=scope_change), self.assertRaises(TaskUnavailable) as error:
|
||||
normalize_task({**proposal, **scope_change},
|
||||
'基于本会话已完成的结果生成报告,不查询新数据。', context)
|
||||
self.assertEqual(error.exception.field, 'freshQuery')
|
||||
|
||||
def test_selection_completes_pending_empty_metric_intent_without_erasing_scope(self):
|
||||
from unittest.mock import patch
|
||||
original='2026年9月18X15X4合格率是多少,不含18X15X4.1'
|
||||
|
||||
Reference in New Issue
Block a user