| """App 任务单确认流程纯逻辑测试(intent-understanding-layer 任务 12)。 |
| |
| 覆盖需求 5.4 / 5.7(确认门禁)、6.2(澄清短路)与新增 i18n 键的中英完整性(需求 8.4)。 |
| 不依赖运行中的 Streamlit。 |
| """ |
|
|
| from __future__ import annotations |
|
|
| import app as appmod |
| from kernel.task_sheet import AnalysisTaskSheet, ClarificationDecision, Intent |
| from services.i18n_service import I18nService |
|
|
|
|
| def test_sheet_is_confirmable_for_normal_sheet(): |
| sheet = AnalysisTaskSheet(intent=Intent.DESCRIPTIVE_SUMMARY, proposed_skill_id="descriptive_summary") |
| assert appmod.sheet_is_confirmable(sheet.to_dict()) is True |
|
|
|
|
| def test_sheet_not_confirmable_when_clarification(): |
| sheet = AnalysisTaskSheet( |
| intent=Intent.UNKNOWN, |
| clarification=ClarificationDecision(needed=True, reason_code="no_llm"), |
| ) |
| assert appmod.sheet_is_confirmable(sheet.to_dict()) is False |
|
|
|
|
| def test_sheet_not_confirmable_when_empty(): |
| assert appmod.sheet_is_confirmable(None) is False |
| assert appmod.sheet_is_confirmable({}) is False |
|
|
|
|
| def test_build_orchestrator_returns_instance(): |
| |
| from kernel.registry import SkillRegistry |
|
|
| class _Svc: |
| llm = None |
| audit = None |
| lang = "zh" |
|
|
| orch = appmod.build_orchestrator(SkillRegistry(), _Svc()) |
| assert orch is not None |
| assert hasattr(orch, "build_task_sheet") |
| assert hasattr(orch, "run_confirmed") |
|
|
|
|
| |
|
|
| _NEW_KEYS = [ |
| "task.sheet.title", "task.sheet.intro", "task.intent", |
| "task.intent.descriptive_summary", "task.intent.shelf_life_extrapolation", |
| "task.intent.unknown", "task.profile", "task.profile.no_stability", |
| "task.items", "task.items.none", "task.missing", |
| "task.btn.confirm", "task.btn.cancel", "task.confirm_required", |
| "understanding.clarify.no_llm", "understanding.clarify.intent_unknown", |
| "understanding.clarify.data_intent_mismatch", "understanding.clarify.error", |
| "understanding.clarify.title", "understanding.clarify.choose", |
| ] |
|
|
|
|
| def test_new_i18n_keys_present_in_both_languages(): |
| svc_i18n = I18nService() |
| for key in _NEW_KEYS: |
| for lang in ("zh", "en"): |
| assert svc_i18n.has(key, lang), f"缺失 i18n:{key} ({lang})" |
|
|
|
|
| def test_new_i18n_no_missing_for_english(): |
| svc_i18n = I18nService() |
| svc_i18n.set_language("en") |
| svc_i18n.clear_missing() |
| for key in _NEW_KEYS: |
| svc_i18n.t(key) |
| en_missing = {k: v for k, v in svc_i18n.missing_keys().items() if k[1] == "en"} |
| assert en_missing == {} |
|
|