Files
quality_analyse/verification/test_native_exploration.py
T
lyun ff7bbe3e46 同步:完善质量分析工作台并更新主题字体
同步已上线的智能分析执行协议、来源查询、图表报告与管理页面配套代码。
补齐数据库迁移、运行依赖和回归测试,保留原有指标计算口径。
统一午夜黑及其他主题的控件细节、中文和业务数字字体。
排除本地业务数据、凭据、预览、发布与验收产物。

验证:生产构建通过,320项前端回归通过;本轮仅同步Git,不再次部署。
2026-10-30 22:40:58 +08:00

394 lines
27 KiB
Python

"""Native tool loop boundaries, using actual tool adapters and captured-like APIs."""
import copy
import sys
import tempfile
import unittest
import threading
from unittest.mock import patch
from pathlib import Path
sys.path[:0] = [str(Path(__file__).resolve().parents[1] / 'scripts'), str(Path(__file__).parent)]
from nao_native_exploration import prepare_step, NativeExplorationTools, _proofs, native_model_view
from nao_agent_task import normalize_task, plan_task
from nao_quality_tools import QualityToolError
from test_nao_protocol_execution import BoundApi, identity
from test_nao_quality_tools import RELEASE
from test_nao_agent_task import task_value
from test_nao_query_plan_raw import InvestigationApi
def root():
return {'version': 1, 'goal': '解释质量变化并根据结果调查', 'question': '9月份合格率下降原因',
'executionMode': 'native_agent', 'kind': 'analysis', 'period': {'year': 2026, 'month': 9},
'comparisonPeriod': {'year': 2026, 'month': 8}, 'filters': {}, 'fields': ['rate'],
'dimensions': [], 'stages': [], 'dimensionStages': {}, 'visualPreference': 'auto',
'verifySource': False, 'fullDetails': False, 'freshQuery': True,
'comparisonRequired': True, 'trendRequired': False}
class Delegated(BoundApi):
def __init__(self):
super().__init__()
self.steps, self.authorization_calls = [], 0
self.timeout, self.deadline_reserve_seconds = 30, None
def call(self, path, payload=None, method=None, *, node_id=None, scope_id=None):
if path == '/api/analysis/model-authorization':
self.authorization_calls += 1
return {}
if path == '/api/analysis/protocol/queries':
return {'scopeCoverage':[{'nodeId':step['node']['nodeId'], 'scopeId':'scope-'+step['node']['nodeId'],
'complete':True,'missingEvidence':[]} for step in self.steps], 'rootGoalGaps':[]}
if path == '/api/analysis/protocol/exploration/steps':
self.steps.append(copy.deepcopy(payload))
task = root()
task.update(comparisonRequired=payload['node']['comparisonRequired'])
task['filters'] = {}
node = payload['node']
selector = node['selector']
if selector['kind'] == 'catalog_members': task['filters'][selector['dimension']] = selector['names'][0]
return {'nodeId': node['nodeId'], 'scopeId': 'scope-' + node['nodeId'],
'task': task, 'scope': {'nodeId': node['nodeId'], 'task': task}}
response = super().call(path, payload=payload, method=method)
if path.startswith('/api/metrics'):
from urllib.parse import urlsplit, parse_qs
month = parse_qs(urlsplit(path).query).get('month', ['0'])[0]
response['protocolEvidence'] = {**identity(), 'nodeId': node_id, 'scopeId': scope_id,
'queryId': 'query-' + month, 'responseHash': 'a'*64}
return response
class NativeExplorationTests(unittest.TestCase):
def state(self): return {'releaseId': RELEASE, 'scopes': []}
def test_model_view_removes_only_transport_and_identical_signal_duplicates(self):
row={'key':'甲','label':'甲','rank':1,'current':{'rate':0,'scrapWeight':None},
'comparison':{'rate':None,'scrapWeight':0}}
source={'kind':'quality_changes','rows':[row],'totalRows':9,'sort':'current_rate',
'prioritySignals':{'scale':[{'key':'甲','label':'甲','current':copy.deepcopy(row['current']),
'comparison':copy.deepcopy(row['comparison'])},{'key':'乙','current':{'rate':0.9}}]},
'evidenceRef':'Q12345678','protocolEvidence':{'queryId':'private'},'evidencePath':'private/path'}
view=native_model_view(source)
self.assertEqual(view['rows'],[row]);self.assertEqual(view['totalRows'],9)
self.assertEqual(view['prioritySignals']['scale'][0]['sameAsReturnedRow'],'甲')
self.assertEqual(view['prioritySignals']['scale'][1],source['prioritySignals']['scale'][1])
self.assertNotIn('protocolEvidence',view);self.assertNotIn('evidencePath',view)
self.assertEqual(view['evidenceRef'],'Q12345678')
self.assertIn('protocolEvidence',source)
source['prioritySignals']['scale'][0]['rateDrop']=None
changed=native_model_view(source)
self.assertIn('rateDrop',changed['prioritySignals']['scale'][0])
self.assertIsNone(changed['prioritySignals']['scale'][0]['rateDrop'])
def test_explicit_cause_cannot_silently_become_a_static_recipe(self):
from nao_native_planning import explicit_investigation
self.assertTrue(explicit_investigation('为什么下降?请自行深挖'))
self.assertFalse(explicit_investigation('取消原因分析,只查合格率'))
native = task_value(executionMode='native_agent', dimensions=[], stages=[], fields=['rate'],
period={'year':2026,'month':9}, comparisonPeriod={'year':2026,'month':8},
comparisonRequired=True, trendRequired=False)
wrong = copy.deepcopy(native); wrong.pop('executionMode')
with patch('nao_agent_task._model_json', side_effect=[wrong,native]) as model:
task = plan_task(base_url='http://offline.invalid', api_key='fixture', model='fixture',
question='为什么下降?请深入分析', context={'_protocol':{'version':1,'autonomousEnabled':True}},
cancel_event=threading.Event())
self.assertEqual(task['executionMode'],'native_agent')
self.assertNotIn('queryPlan', task)
self.assertEqual(model.call_count,2)
self.assertNotIn('黑片投入重量排名后查看前两项',model.call_args.kwargs['system'])
def test_clear_ranking_rejects_native_route_before_confirmation(self):
from nao_native_planning import explicit_batch_ranking
question='2026年9月汽车交通哪些规格合格率最低?按本期综合合格率从低到高列出前5个,同时说明投入和报废规模。'
self.assertTrue(explicit_batch_ranking(question))
self.assertFalse(explicit_batch_ranking('产品合格率最低的原因是什么?请深入调查'))
self.assertFalse(explicit_batch_ranking('不要排名,只查产品合格率'))
native=task_value(kind='analysis',executionMode='native_agent',dimensions=[],dimensionStages={},
fields=['rate'],stages=[],period={'year':2026,'month':9},comparisonRequired=True,
comparisonPeriod={'year':2026,'month':8})
batch={**native,'dimensions':['product'],'fields':['rate','totalWeight','scrapWeight'],
'dimensionStages':{'product':[]},'queryPlan':[{
'nodeId':'rank','purpose':'changes','dimension':'product','sort':'current_rate','limit':5,
'fields':['rate','totalWeight','scrapWeight'],'stages':[],
'selector':{'kind':'base'},'comparisonRequired':True,'visualType':'bar','visualPreference':'auto'}]}
batch.pop('executionMode')
with patch('nao_agent_task._model_json',side_effect=[native,batch]):
task=plan_task(base_url='https://offline.invalid/v1',api_key='fixture',model='fixture',
question=question,context={'_protocol':{'version':1,'autonomousEnabled':True}},
cancel_event=threading.Event())
self.assertNotEqual(task.get('executionMode'),'native_agent')
self.assertEqual(task['queryPlan'][0]['sort'],'current_rate')
self.assertEqual(task['queryPlan'][0]['limit'],5)
self.assertEqual(task['planRecovery']['modelAttempts'],2)
def test_root_cannot_invent_domestic_and_explicit_group_gets_its_catalog_parent(self):
from nao_native_planning import validate_root_scope
catalog = {'groups':['汽车交通-国内','汽车交通-海外'],
'groupDepartments':{'汽车交通-国内':'新能源汽车磁钢','汽车交通-海外':'新能源汽车磁钢'}}
narrowed = root(); narrowed['filters'] = {'group':'汽车交通-国内'}
with self.assertRaisesRegex(ValueError,'擅自缩'):
validate_root_scope(copy.deepcopy(narrowed), '汽车交通为什么下降', catalog)
valid = validate_root_scope(copy.deepcopy(narrowed), '那国内为什么下降', catalog)
self.assertEqual(valid['filters'],{'group':'汽车交通-国内','department':'新能源汽车磁钢'})
inherited = validate_root_scope(copy.deepcopy(narrowed),'继续分析原因',catalog,{'group':'汽车交通-国内'})
self.assertEqual(inherited['filters']['group'],'汽车交通-国内')
new = copy.deepcopy(narrowed); new['newTask'] = True
with self.assertRaises(ValueError):
validate_root_scope(new,'换个问题,公司为什么下降',catalog,{'group':'汽车交通-国内'})
from dbgpt_trial_data import encoded_selection
multi = root(); multi['filters'] = {'group':encoded_selection(['汽车交通-国内','汽车交通-海外'])}
with self.assertRaises(ValueError):
validate_root_scope(copy.deepcopy(multi),'公司为什么下降',catalog)
explicit = validate_root_scope(copy.deepcopy(multi),'汽车交通国内和海外为什么下降',catalog)
self.assertEqual(explicit['filters']['department'],'新能源汽车磁钢')
self.assertEqual(validate_root_scope(copy.deepcopy(multi),'继续分析',catalog,multi['filters'])['filters'],explicit['filters'])
def test_explicit_authorized_department_cannot_disappear_from_root(self):
from nao_native_planning import validate_root_scope
catalog={'departments':['新能源汽车磁钢','消费电子-3C'],'groups':[], 'groupDepartments':{}}
for question in ('汽车交通为什么下降','分析汽车交通不良原因','新能源汽车磁钢9月合格率', '3C合格率',
'只分析汽车交通,不需要全公司数据','仅看汽车交通,不和消费电子比较',
'汽车交通为什么下降,不看其他部门'):
with self.subTest(question=question), self.assertRaises(ValueError):
validate_root_scope({'filters':{}},question,catalog)
for question in ('汽车交通不要了,改看公司整体','排除汽车交通看其余',
'汽车交通和消费电子比较','比较3C与汽车交通',
'汽车交通相比其他产业部如何','不含汽车交通,查全公司'):
with self.subTest(question=question):
self.assertEqual(validate_root_scope({'filters':{}},question,catalog)['filters'],{})
self.assertEqual(validate_root_scope({'filters':{'department':'新能源汽车磁钢'}},
'分析汽车交通不良原因',catalog)['filters']['department'],'新能源汽车磁钢')
with self.assertRaises(ValueError):
validate_root_scope({'filters':{'department':'消费电子-3C'}},'汽车交通为什么下降',catalog)
# A product containing the suffix is not a department mention.
self.assertEqual(validate_root_scope({'filters':{}},'查规格A3CX1',catalog)['filters'],{})
def test_department_omission_is_repaired_before_confirmation(self):
value=task_value(kind='analysis',executionMode='native_agent',dimensions=[],dimensionStages={},
fields=['rate'],stages=[],period={'year':2026,'month':9})
context={'_protocol':{'version':1,'autonomousEnabled':True},
'_businessCatalog':{'departments':['新能源汽车磁钢','消费电子-3C']}}
with patch('nao_agent_task._model_json',side_effect=[value,{**value,'filterUpdates':{'department':'新能源汽车磁钢'}}]):
task=plan_task(base_url='https://offline.invalid/v1',api_key='fixture',model='fixture',
question='请深挖汽车交通为什么下降',context=context,cancel_event=threading.Event())
self.assertEqual(task['filters']['department'],'新能源汽车磁钢')
self.assertEqual(task['planRecovery']['modelAttempts'],2)
self.assertEqual(task['planRecovery']['errors'][0]['field'],'filterUpdates.department')
def test_negated_broad_scope_cannot_bypass_department_repair(self):
value=task_value(kind='analysis',executionMode='native_agent',dimensions=[],dimensionStages={},
fields=['rate'],stages=[],period={'year':2026,'month':9})
context={'_protocol':{'version':1,'autonomousEnabled':True},
'_businessCatalog':{'departments':['新能源汽车磁钢','消费电子-3C']}}
for question in ('只分析汽车交通,不需要全公司数据','仅看汽车交通,不和消费电子比较',
'汽车交通为什么下降,不看其他部门'):
with self.subTest(question=question), patch('nao_agent_task._model_json',side_effect=[
value,{**value,'filterUpdates':{'department':'新能源汽车磁钢'}}]):
task=plan_task(base_url='https://offline.invalid/v1',api_key='fixture',model='fixture',
question=question,context=context,cancel_event=threading.Event())
self.assertEqual(task['filters']['department'],'新能源汽车磁钢')
self.assertEqual(task['planRecovery']['modelAttempts'],2)
def test_business_cross_check_is_not_raw_file_permission(self):
value = task_value(kind='analysis', dimensions=[], stages=[], fields=['rate'],
period={'year': 2026, 'month': 9}, executionMode='native_agent',
verifySource=True, fullDetails=True, trendRequired=False)
context = {'_protocol': {'version': 1, 'autonomousEnabled': True}}
task = normalize_task(value, '核对主要线索,先给分析', context)
self.assertFalse(task['verifySource']); self.assertFalse(task['fullDetails'])
explicit = normalize_task(value, '请核验原表,并逐行读取全部原始记录', context)
self.assertTrue(explicit['verifySource']); self.assertTrue(explicit['fullDetails'])
context['_protocol']['previousTask'] = explicit
cancelled = normalize_task(value, '取消原表核验,不要逐行读取', context)
self.assertFalse(cancelled['verifySource']); self.assertFalse(cancelled['fullDetails'])
for wording in ('后面不要原始数据,只分析统计', '别再看原始行了', '原始数据不用了'):
cancelled = normalize_task(value, wording, context)
self.assertFalse(cancelled['verifySource'], wording)
self.assertFalse(cancelled['fullDetails'], wording)
for wording in ('不需要每行数据', '不要数据行', '不要每一条记录'):
cancelled = normalize_task(value, wording, context)
self.assertFalse(cancelled['fullDetails'], wording)
retained = normalize_task(value, '不要逐行记录,继续核验原表', context)
self.assertFalse(retained['fullDetails'])
self.assertTrue(retained['verifySource'])
for wording, flag in (('请核验不良品原表', 'verifySource'),
('分析不合格原因并核验原表', 'verifySource'),
('请逐行读取不合格的原始记录', 'fullDetails')):
allowed = normalize_task(value, wording, {'_protocol': {'version': 1, 'autonomousEnabled': True}})
self.assertTrue(allowed[flag], wording)
def test_disabled_comparison_does_not_revive_an_optional_old_comparison_date(self):
value = task_value(kind='metrics', dimensions=[], fields=['rate'], stages=[],
period={'year':2026,'month':10}, comparisonRequired=False,
comparisonPeriod={'year':2026,'month':9})
task = normalize_task(value,'只查十月,不比较',{'_protocol':{'version':1,'autonomousEnabled':True}})
self.assertIsNone(task['comparisonPeriod'])
def test_new_confirmed_goal_does_not_restore_cancelled_historical_ranking(self):
value=task_value(goal='只查询综合合格率,取消排名及规模要求',kind='metrics',
dimensions=[],stages=[],fields=['rate'],period={'year':2026,'month':9},comparisonRequired=False)
previous={'goal':'按低率排名五个规格及规模','rootGoal':'按低率排名五个规格及规模','kind':'analysis','filters':{}}
with patch('nao_agent_task._model_json',return_value=value):
planned=plan_task(base_url='http://offline.invalid',api_key='fixture',model='fixture',
question='取消排名和规模,只查合格率',previous=previous,
context={'_protocol':{'version':1,'autonomousEnabled':True},
'_serverHistory':[{'question':previous['goal'],'evidenceRefs':['Q12345678']}]},
cancel_event=threading.Event())
self.assertEqual(planned['rootGoal'],value['goal'])
def test_planner_failure_clarification_keeps_explicit_negative_product_constraint(self):
context={'year':2026,'month':9,'_protocol':{'version':1,'autonomousEnabled':True},
'_businessCatalog':{'explicitlyExcludedProducts':['18X15X4.1+Z'],
'productMatch':{'status':'ambiguous','query':'18x15x4','truncated':False,
'candidates':[{'name':'18X15X4+T'},{'name':'18X15X4+Z'}]}}}
with patch('nao_agent_task._model_json',return_value=None):
task=plan_task(base_url='http://offline.invalid',api_key='fixture',model='fixture',
question='18X15X4合格率,不要包含18X15X4.1',context=context,cancel_event=threading.Event())
self.assertTrue(task['needsClarification'])
self.assertEqual(task['period'],{'year':2026,'month':9})
self.assertEqual(task['filters']['exclusions']['product'],['18X15X4.1+Z'])
def test_root_scope_cannot_be_changed_or_old_filter_reintroduced(self):
task = root(); task['filters'] = {'department': '甲'}
with self.assertRaises(QualityToolError):
prepare_step({'mode': 'compare', 'filters': {'department': '乙'}}, task, self.state())
args, _ = prepare_step({'mode': 'compare'}, task, self.state())
self.assertEqual(args['filters'], {'department': '甲'})
self.assertEqual(task['filters'], {'department': '甲'})
def test_next_observation_can_choose_a_new_dimension_and_another_stage(self):
task = root()
first, a = prepare_step({'mode': 'changes', 'dimension': 'group', 'sort': 'rate_drop'}, task, self.state())
second, b = prepare_step({'mode': 'defects', 'stage': 'bright', 'filters': {'product': '规格乙'}}, task, self.state())
self.assertEqual(a['node']['dimension'], 'group')
self.assertEqual(b['node']['selector']['names'], ['规格乙'])
self.assertEqual(b['node']['stages'], ['bright'])
self.assertNotEqual(a['node']['nodeId'], b['node']['nodeId'])
self.assertEqual(task, root())
def test_raw_reads_require_explicit_root_request(self):
with self.assertRaises(QualityToolError):
prepare_step({'mode': 'investigate', 'stage': 'black', 'action': 'rows'}, root(), self.state())
def test_exact_product_without_defect_uses_its_defect_breakdown_not_product_ranking(self):
args, step=prepare_step({'mode':'defects','stage':'black','dimension':'product',
'filters':{'product':'规格甲'}},root(),self.state())
self.assertEqual(args['dimension'],'defect')
self.assertEqual(step['node']['dimension'],'defect')
self.assertEqual(args['filters'],{'product':'规格甲'})
unchanged, _=prepare_step({'mode':'defects','stage':'black','dimension':'product','defect':'责废缺角重量'},root(),self.state())
self.assertEqual(unchanged['dimension'],'product')
def test_raw_tools_use_protocol_endpoints_and_exact_defaults(self):
task = root(); task['fullDetails'] = True; task['verifySource'] = True
args, proposal = prepare_step({'mode': 'details', 'stage': 'black'}, task, self.state())
self.assertEqual(args['mode'], 'investigate')
self.assertEqual((args['action'], args['offset'], args['recordFilter']), ('rows', 0, 'all'))
self.assertEqual(proposal['node']['purpose'], 'records')
args, proposal = prepare_step({'mode': 'investigate', 'stage': 'bright', 'action': 'source'}, task, self.state())
self.assertEqual(args['limit'], 100)
self.assertEqual(proposal['node']['purpose'], 'source')
def test_multilevel_child_inherits_verified_parent(self):
state = self.state(); state['scopes'] = [{'filters': {'group': '甲'}, 'queryIds': ['q1']}]
_, step = prepare_step({'mode': 'defects', 'stage': 'black', 'filters': {'group': '甲', 'product': '乙'}}, root(), state)
self.assertEqual(step['parentQueryIds'], ['q1'])
self.assertEqual(step['node']['selector'], {'kind': 'catalog_members', 'dimension': 'product', 'names': ['乙']})
def test_equivalent_single_month_syntax_keeps_the_confirmed_frame(self):
task = root()
args, _ = prepare_step({'mode': 'compare', 'period': {'year': 2026, 'monthStart': 9, 'monthEnd': 9}}, task, self.state())
self.assertEqual(args['period'], {'year': 2026, 'month': 9})
with self.assertRaises(QualityToolError):
prepare_step({'mode': 'compare', 'period': {'year': 2026, 'monthStart': 8, 'monthEnd': 9}}, task, self.state())
def test_invalid_shape_is_rejected_before_registering_a_scope(self):
with tempfile.TemporaryDirectory() as folder:
api = Delegated(); p = Path(folder)
tools = NativeExplorationTools(delegated=api, evidence_dir=p/'evidence', task=root(),
identity={**identity(), 'releaseId': RELEASE}, state_path=p/'state.json')
with self.assertRaises(QualityToolError):
tools.quality_data({'mode': 'compare', 'dimension': 'product'})
self.assertEqual(api.steps, [])
def test_actual_compare_preserves_both_proofs_and_duplicate_reads_are_cached(self):
with tempfile.TemporaryDirectory() as folder:
api = Delegated(); p = Path(folder)
tools = NativeExplorationTools(delegated=api, evidence_dir=p/'evidence', task=root(),
identity={**identity(), 'releaseId': RELEASE}, state_path=p/'state.json')
result = tools.quality_data({'mode': 'compare'})
self.assertEqual(len(_proofs(result)), 2)
self.assertEqual(len(api.steps), 1)
for _ in range(3):
duplicate = tools.quality_data({'mode': 'compare'})
self.assertTrue(duplicate['reusedEvidence'])
self.assertEqual(duplicate['evidenceRef'], result['evidenceRef'])
self.assertEqual(len(api.steps), 1)
self.assertEqual(api.authorization_calls, 4)
with self.assertRaisesRegex(QualityToolError, '停止'):
tools.quality_data({'mode': 'compare'})
def test_new_execution_never_reuses_previous_attempt_cache(self):
with tempfile.TemporaryDirectory() as folder:
api = Delegated(); p = Path(folder)
kwargs = dict(delegated=api, evidence_dir=p/'evidence', task=root(), state_path=p/'state.json')
a = NativeExplorationTools(**kwargs, identity={**identity(), 'releaseId': RELEASE})
first = a.quality_data({'mode': 'compare'})
b = NativeExplorationTools(**kwargs, identity={**identity(), 'executionId': 'new-execution', 'releaseId': RELEASE})
second = b.quality_data({'mode': 'compare'})
self.assertNotEqual(first['evidenceRef'], second['evidenceRef'])
self.assertEqual(len(api.steps), 2)
def test_explicit_refresh_reexecutes_but_identical_responses_are_still_no_progress(self):
with tempfile.TemporaryDirectory() as folder:
p=Path(folder); api=Delegated()
tools=NativeExplorationTools(delegated=api,evidence_dir=p/'evidence',task=root(),
identity={**identity(),'releaseId':RELEASE},state_path=p/'state.json')
first=tools.quality_data({'mode':'compare'})
for _ in range(3):
checked=tools.quality_data({'mode':'compare','freshQuery':True})
self.assertNotEqual(first['evidenceRef'],checked['evidenceRef'])
self.assertIn('没有新增',checked['investigationNotice'])
self.assertEqual(len(api.steps),1)
with self.assertRaisesRegex(QualityToolError,'停止'):
tools.quality_data({'mode':'compare','freshQuery':True})
def test_record_pages_share_authorized_scope_but_have_distinct_cached_evidence(self):
task = root()
task.update(fullDetails=True, comparisonRequired=False, comparisonPeriod=None, stages=['black'])
class Pages(InvestigationApi):
timeout = 30
deadline_reserve_seconds = None
def __init__(self):
super().__init__(total_rows=165)
self.registered = []
def call(self, path, payload=None, method=None, **kwargs):
if path == '/api/analysis/model-authorization': return {}
if path == '/api/analysis/protocol/queries':
return {'scopeCoverage':[{'nodeId':s['nodeId'],'scopeId':s['scopeId'],
'complete':self.query_count >= 2,'missingEvidence':[] if self.query_count >= 2 else ['后续页尚未读取']}
for s in self.scopes], 'rootGoalGaps':[]}
if path == '/api/analysis/protocol/exploration/steps':
self.registered.append(copy.deepcopy(payload))
self.add_scope(payload['node']['nodeId'], 'record-scope', 'records', task)
scope = self.scopes[-1]
return {'nodeId':scope['nodeId'], 'scopeId':scope['scopeId'], 'task':scope['task'], 'scope':scope}
return super().call(path, payload, method, **kwargs)
with tempfile.TemporaryDirectory() as folder:
p = Path(folder); api = Pages()
tools = NativeExplorationTools(delegated=api, evidence_dir=p/'evidence', task=task,
identity={**identity(), 'releaseId':RELEASE}, state_path=p/'state.json')
first = tools.quality_data({'mode':'details', 'stage':'black', 'offset':0})
last = tools.quality_data({'mode':'details', 'stage':'black', 'offset':100})
self.assertEqual(len(api.registered), 1)
self.assertFalse(first['investigationCoverage']['scopeComplete'])
self.assertTrue(last['investigationCoverage']['scopeComplete'])
reads = [c for c in api.calls if c['path'] == '/api/analysis/investigate']
self.assertEqual([c['payload']['offset'] for c in reads], [0,100])
self.assertEqual(len({(c['nodeId'],c['scopeId']) for c in reads}), 1)
self.assertNotEqual(first['evidenceRef'], last['evidenceRef'])
cached = tools.quality_data({'mode':'details', 'stage':'black', 'offset':100})
self.assertTrue(cached['reusedEvidence'])
self.assertEqual(api.query_count, 2)
tools.quality_data({'mode':'details', 'stage':'black', 'offset':100, 'freshQuery':True})
self.assertEqual(api.query_count, 3)
self.assertEqual(len(api.registered), 1)
if __name__ == '__main__': unittest.main()