File size: 2,660 Bytes
0e6887b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""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():
    # 用最小 stub registry/svc 即可构造编排器(不触发 LLM)。
    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")


# —— 新增 i18n 键的中英完整性(需求 8.4)——

_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 == {}