|
6 | 6 | from fast_agent.agents.agent_types import AgentConfig |
7 | 7 | from fast_agent.agents.mcp_agent import McpAgent |
8 | 8 | from fast_agent.context import Context |
9 | | -from fast_agent.skills.registry import SkillRegistry |
| 9 | +from fast_agent.skills.registry import SkillRegistry, format_skills_for_prompt |
10 | 10 |
|
11 | 11 |
|
12 | 12 | def create_skill(directory: Path, name: str, description: str = "desc", body: str = "Body") -> None: |
@@ -89,3 +89,32 @@ async def test_agent_skills_missing_placeholder_warns(tmp_path: Path) -> None: |
89 | 89 |
|
90 | 90 | mock_warning.assert_called_once() |
91 | 91 | assert "system prompt does not include {{agentSkills}}" in mock_warning.call_args[0][0] |
| 92 | + |
| 93 | + |
| 94 | +def test_skills_absolute_dir_outside_cwd(tmp_path: Path) -> None: |
| 95 | + """When skills dir is outside base_dir, absolute paths should be used in prompts.""" |
| 96 | + # Create skills in tmp_path (simulates /tmp/foo) |
| 97 | + skills_root = tmp_path / "external_skills" |
| 98 | + create_skill(skills_root, "external", description="External skill") |
| 99 | + |
| 100 | + # Use a different base_dir that doesn't contain skills_root |
| 101 | + base_dir = tmp_path / "workspace" |
| 102 | + base_dir.mkdir() |
| 103 | + |
| 104 | + # Create registry with base_dir different from skills directory |
| 105 | + registry = SkillRegistry(base_dir=base_dir, override_directory=skills_root) |
| 106 | + manifests = registry.load_manifests() |
| 107 | + |
| 108 | + assert len(manifests) == 1 |
| 109 | + manifest = manifests[0] |
| 110 | + |
| 111 | + # relative_path should be None since skills_root is outside base_dir |
| 112 | + assert manifest.relative_path is None |
| 113 | + |
| 114 | + # The absolute path should still be set |
| 115 | + assert manifest.path is not None |
| 116 | + assert manifest.path.is_absolute() |
| 117 | + |
| 118 | + # format_skills_for_prompt should use the absolute path |
| 119 | + prompt = format_skills_for_prompt(manifests) |
| 120 | + assert f'path="{manifest.path}"' in prompt |
0 commit comments