"""测试目标上下文注入。""" from app.modules.runtime.goals import build_goals_context def test_build_goals_context_with_active_goals(): """生成了 Active Goals 系统提示片段。""" goals = [ { "title": "学习 Python", "level": "long_term", "status": "active", "priority": 80, "progress": 0.5, }, { "title": "完成项目文档", "level": "task", "status": "active", "priority": 60, "progress": 0.0, "parent_id": "goal_1", }, ] result = build_goals_context(goals) assert "学习 Python" in result assert "任务目标" in result or "task" in result or "长期目标" in result assert result.startswith("当前活跃目标:") or "当前" in result def test_build_goals_context_empty(): assert build_goals_context([]) == "" def test_build_goals_context_sorts_by_priority(): """按优先级降序排列输出。""" goals = [ {"title": "low", "level": "task", "status": "active", "priority": 10, "progress": 0.0}, { "title": "high", "level": "long_term", "status": "active", "priority": 90, "progress": 0.5, }, ] result = build_goals_context(goals) high_idx = result.index("high") low_idx = result.index("low") assert high_idx < low_idx # high priority first