"""Titles may name each signed period/scope without promoting a partial scope.""" import sys,unittest from pathlib import Path sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'scripts')) import nao_native_answer as n from nao_history_report import _history_title_is_scope_safe class ReportTitleScopeRoleTests(unittest.TestCase): def setUp(self): self.sections=[{'sourceTurnId':'sep','period':{'year':2026,'month':9},'filters':{'department':'消费电子产业部','group':'消费电子-3C'}}, {'sourceTurnId':'aug','period':{'year':2026,'month':8},'filters':{}}] self.snapshot={'sections':self.sections,'historySources':[{'turnId':'sep'},{'turnId':'aug'}]} self.report={'facts':[{'id':'F'+str(i),'kind':'product','text':'正式报废排名事实','label':'产品', 'scope':s,'validity':{'verified':True,'basis':'protocol_history_snapshot'}} for i,s in enumerate(self.sections,1)]} self.context={'_historyTitleExcludedScopeLiterals':['消费电子产业部','消费电子-3C']} def valid(self,title): return n._verified_content_title(title,self.report,'生成报告',n._content_title_guide(self.report,self.context)) def test_period_scoped_full_organization_labels_can_omit_display_separators(self): for title in ('2026年8月全公司与9月消费电子3C产品不良Top规格报告', '2026年9月消费电子-3C与8月全公司产品不良规格报告'): with self.subTest(title=title): self.assertEqual(self.valid(title),title) self.assertEqual(_history_title_is_scope_safe(title,self.snapshot,'生成报告'),title) def test_partial_scope_cannot_be_promoted_or_attached_to_wrong_period(self): for title in ('2026年8—9月消费电子3C质量报告','2026年9月消费电子3C质量报告', '2026年9月全公司与8月消费电子3C质量报告','2026年8月全公司消费电子3C与9月质量报告', '2026年8月全公司与9月3C产品报告','2026年8月全公司与9月消费电子产业部报告'): with self.subTest(title=title):self.assertIsNone(self.valid(title)) def test_generic_multi_scope_title_and_common_scope_still_work(self): self.assertTrue(self.valid('2026年8月及9月产品规格报废榜单汇总')) self.report['facts']=self.report['facts'][:1];self.snapshot['sections']=self.sections[:1];self.snapshot['historySources']=[{'turnId':'sep'}] self.context={'_historyTitleExcludedScopeLiterals':[]} self.assertTrue(self.valid('消费电子3C产品质量报告')) def test_product_identifier_characters_are_not_normalized_as_scope_aliases(self): self.sections[0]['filters']={'product':'型号3-C'};self.report['facts'][0]['verifiedIdentifiers']=[{'value':'型号3-C','field':'product'}] self.context={'_historyTitleExcludedScopeLiterals':['型号3-C']} self.assertIsNone(self.valid('2026年8月全公司与9月型号3C质量报告')) def test_native_nonhistory_guide_does_not_expand_scope_payload(self): self.assertNotIn('scopeContexts',n._content_title_guide(self.report,{})) def test_unavailable_scope_and_explicit_exclusion_cannot_gain_a_title_alias(self): self.context['_historyTitleExcludedScopeLiterals'].append('未提供范围') self.assertIsNone(self.valid('2026年8月全公司与9月未提供范围质量报告')) self.sections[0]['filters']['exclusions']={'department':['排除部门']} self.assertIsNone(self.valid('2026年8月全公司与9月排除部门质量报告')) if __name__=='__main__':unittest.main()