update
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
import copy
|
||||
import pytest
|
||||
|
||||
from app.modules.work_assistant.message_push import PushPreviewRequest, generate_preview
|
||||
|
||||
|
||||
def request(kind='log', content='张甲已提交会议纪要,待负责人核对。'):
|
||||
return PushPreviewRequest(kind=kind, subject='综合部', period='2026-11-16 至 2026-11-22',
|
||||
contents={'log':['内容检查'],'project':['交付与阻碍'],'risk':['节点风险'],'performance':['履职检查']}[kind],
|
||||
presentation='executive', evidence=[dict(id='s1',label='张甲工作记录',content=content,kind='review',relation='published_result')],limits=[])
|
||||
|
||||
|
||||
def candidate():
|
||||
basis=[dict(excerpt_id='e1')]
|
||||
return dict(summary=dict(text='张甲已提交会议纪要,待负责人核对。',basis=basis),messages=[dict(
|
||||
title='纪要已提交,待核对',work='张甲',judgment='已提交会议纪要,核对结果尚未确认。',
|
||||
suggestion='请负责人核对会议纪要。',priority='verify',basis=basis)],empty_reason='')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('kind',['log','project','risk','performance'])
|
||||
def test_each_kind_runs_generation_and_audit_with_bound_citations(kind):
|
||||
calls=[]
|
||||
def invoke(prompt,material,schema,**kwargs):
|
||||
calls.append((prompt,material))
|
||||
if 'decisions' in schema['properties']:
|
||||
return {'decisions':[dict(index=p['index'],supported=True,reason='与引用一致。') for p in material['points']]}
|
||||
return candidate()
|
||||
result=generate_preview(request(kind),invoke=invoke)
|
||||
assert result['version']=='message-brief-v2'
|
||||
assert len(calls)==2
|
||||
assert {'log':'工作日志简报','project':'项目进展简报','risk':'项目风险简报','performance':'绩效检查简报'}[kind] in calls[0][0]
|
||||
assert result['summary']['basis'][0]==dict(id='s1',quote='张甲已提交会议纪要,待负责人核对。')
|
||||
assert result['messages'][0]['work']=='张甲'
|
||||
|
||||
|
||||
def run(value, decisions=None, content='张甲已提交会议纪要,待负责人核对。'):
|
||||
def invoke(prompt,material,schema,**kwargs):
|
||||
if 'decisions' in schema['properties']:
|
||||
return {'decisions':[dict(index=p['index'],supported=decisions(p) if decisions else True,reason='隔离测试结论。') for p in material['points']]}
|
||||
return copy.deepcopy(value)
|
||||
return generate_preview(request(content=content),invoke=invoke)
|
||||
|
||||
|
||||
def test_rejected_lead_cannot_survive_while_details_pass():
|
||||
value=candidate();value['summary']['text']='全公司所有工作均按期交付。'
|
||||
result=run(value)
|
||||
assert result['summary']['text']=='本期重点:纪要已提交,待核对'
|
||||
assert '全公司' not in str(result)
|
||||
|
||||
|
||||
def test_rejected_lead_uses_verified_titles_without_regenerating_good_items():
|
||||
value=candidate();value['summary']['text']='全公司所有工作均按期交付。'
|
||||
second=copy.deepcopy(value['messages'][0]);second.update(work='李乙',title='另一项记录待核对');value['messages'].append(second)
|
||||
calls=[]
|
||||
def invoke(prompt,material,schema,**kwargs):
|
||||
calls.append(material)
|
||||
if 'decisions' in schema['properties']:
|
||||
return {'decisions':[dict(index=p['index'],supported=True,reason='核对。') for p in material['points']]}
|
||||
return value
|
||||
result=generate_preview(request(),invoke=invoke)
|
||||
assert len(calls)==2
|
||||
assert result['summary']['text']=='本期重点:纪要已提交,待核对;另一项记录待核对'
|
||||
assert len(result['summary']['basis'])==1
|
||||
|
||||
|
||||
def test_registration_cannot_become_acceptance_even_if_auditor_accepts():
|
||||
value=candidate();value['messages'][0]['judgment']='任务已完成验收并完成交付。'
|
||||
result=run(value,content='任务登记完成,实际验收尚待核对。')
|
||||
assert result['messages']==[] and result['summary'] is None
|
||||
assert result['empty_reason']
|
||||
|
||||
|
||||
@pytest.mark.parametrize('bad',['task-13247 的完成时间为null。','任务登记完成时间为null,进度待核对。','任务状态为 undefined。','已提交会议纪要。\n另一条:请处理。'])
|
||||
def test_internal_fields_and_inline_lists_are_repaired_or_withheld(bad):
|
||||
value=candidate();value['messages'][0]['judgment']=bad
|
||||
assert run(value)['messages']==[]
|
||||
|
||||
|
||||
def test_same_person_cannot_be_split_between_progress_and_actions():
|
||||
value=candidate();value['messages'].append(copy.deepcopy(value['messages'][0]))
|
||||
value['messages'][1]['title']='负责人核对会议纪要'
|
||||
assert run(value)['messages']==[]
|
||||
|
||||
|
||||
def test_normal_progress_needs_no_invented_action():
|
||||
value=candidate();value['messages'][0]['suggestion']='';value['messages'][0]['priority']='progress'
|
||||
assert run(value)['messages'][0]['suggestion']==''
|
||||
|
||||
|
||||
def test_empty_action_word_is_not_a_useless_next_step():
|
||||
value=candidate();value['messages'][0]['suggestion']='无。'
|
||||
assert run(value)['messages'][0]['suggestion']==''
|
||||
|
||||
|
||||
def test_title_cannot_rename_the_project_to_its_owner():
|
||||
req=request('risk');req.evidence[0].entity='甲项目'
|
||||
def invoke(prompt,material,schema,**kwargs):
|
||||
if 'decisions' in schema['properties']:
|
||||
return {'decisions':[dict(index=p['index'],supported=True,reason='测试核对。') for p in material['points']]}
|
||||
return candidate()
|
||||
assert generate_preview(req,invoke=invoke)['messages']==[]
|
||||
|
||||
|
||||
def test_submission_is_not_supervisor_approval():
|
||||
value=candidate();value['messages'][0]['judgment']='已提交会议纪要并获主管确认。'
|
||||
assert run(value,content='已提交会议纪要,主管已经接收。')['messages']==[]
|
||||
|
||||
|
||||
def test_missing_completion_field_does_not_create_a_rectification_requirement():
|
||||
value=candidate();value['messages'][0]['suggestion']='请补充任务登记时间。'
|
||||
assert run(value,content='任务登记完成时间为空,实际结果待核对。')['messages']==[]
|
||||
|
||||
|
||||
def test_partial_audit_rebuilds_lead_from_accepted_fact():
|
||||
value=candidate();second=copy.deepcopy(value['messages'][0]);second['work']='李乙';value['messages'].append(second)
|
||||
result=run(value,decisions=lambda p:p['index']!=2)
|
||||
assert len(result['messages'])==1
|
||||
assert result['summary']['text']=='本期重点:纪要已提交,待核对'
|
||||
|
||||
|
||||
def test_missing_sources_never_calls_model_or_invents_conclusion():
|
||||
req=request();req.evidence=[]
|
||||
result=generate_preview(req,invoke=lambda *a,**kw:pytest.fail('No source needs no model'))
|
||||
assert result['messages']==[] and result['summary'] is None
|
||||
|
||||
|
||||
def test_citations_from_another_material_are_never_published():
|
||||
value=candidate();value['messages'][0]['basis']=[dict(excerpt_id='e999')]
|
||||
assert run(value)['messages']==[]
|
||||
|
||||
|
||||
def test_incomplete_audit_is_not_treated_as_approval():
|
||||
def invoke(prompt,material,schema,**kwargs):
|
||||
return dict(decisions=[]) if 'decisions' in schema['properties'] else candidate()
|
||||
with pytest.raises(ValueError,match='incomplete_brief_audit'):
|
||||
generate_preview(request(),invoke=invoke)
|
||||
Reference in New Issue
Block a user