Skip to content

Commit 760328a

Browse files
test(cli): decouple run_handlers tests from tutorial path
Use a tmp_path YAML fixture rendered from a minimal inline template instead of reading examples/tutorials/.../manifest.yaml, so the test survives tutorial renames or removals while still exercising the real AgentManifest.from_yaml loader. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent f41703c commit 760328a

1 file changed

Lines changed: 32 additions & 14 deletions

File tree

tests/lib/cli/test_run_handlers.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,45 @@
22

33
from __future__ import annotations
44

5+
from pathlib import Path
6+
57
import pytest
68

79
from agentex.lib.cli.handlers.run_handlers import create_agent_environment
810
from agentex.lib.sdk.config.agent_manifest import AgentManifest
911

12+
_MANIFEST_TEMPLATE = """\
13+
build:
14+
context:
15+
root: .
16+
dockerfile: Dockerfile
17+
18+
local_development:
19+
agent:
20+
port: 8000
21+
host_address: host.docker.internal
22+
{redis_line}
23+
24+
agent:
25+
acp_type: async
26+
name: test-agent
27+
description: Fixture manifest for run_handlers tests.
28+
"""
1029

11-
@pytest.fixture
12-
def manifest_path() -> str:
13-
"""A real tutorial manifest with acp_type=async and default redis_enabled."""
14-
return "examples/tutorials/10_async/00_base/110_pydantic_ai/manifest.yaml"
30+
31+
def _write_manifest(tmp_path: Path, redis_enabled: bool | None) -> AgentManifest:
32+
"""Write a minimal manifest with the requested redis_enabled value (or omit for default)."""
33+
redis_line = "" if redis_enabled is None else f" redis_enabled: {str(redis_enabled).lower()}"
34+
manifest_path = tmp_path / "manifest.yaml"
35+
manifest_path.write_text(_MANIFEST_TEMPLATE.format(redis_line=redis_line))
36+
return AgentManifest.from_yaml(file_path=str(manifest_path))
1537

1638

1739
class TestCreateAgentEnvironmentRedisGating:
18-
def test_default_seeds_redis_url(self, manifest_path: str, monkeypatch: pytest.MonkeyPatch):
40+
def test_default_seeds_redis_url(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
1941
"""With redis_enabled unset (default true), CLI seeds the localhost REDIS_URL."""
2042
monkeypatch.delenv("REDIS_URL", raising=False)
21-
manifest = AgentManifest.from_yaml(file_path=manifest_path)
43+
manifest = _write_manifest(tmp_path, redis_enabled=None)
2244
assert manifest.local_development is not None
2345
assert manifest.local_development.redis_enabled is True
2446

@@ -27,26 +49,22 @@ def test_default_seeds_redis_url(self, manifest_path: str, monkeypatch: pytest.M
2749
assert env.get("REDIS_URL") == "redis://localhost:6379"
2850

2951
def test_opt_out_clears_redis_url_when_parent_env_clean(
30-
self, manifest_path: str, monkeypatch: pytest.MonkeyPatch
52+
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
3153
):
3254
"""With redis_enabled=false and no parent REDIS_URL, REDIS_URL is absent."""
3355
monkeypatch.delenv("REDIS_URL", raising=False)
34-
manifest = AgentManifest.from_yaml(file_path=manifest_path)
35-
assert manifest.local_development is not None
36-
manifest.local_development.redis_enabled = False
56+
manifest = _write_manifest(tmp_path, redis_enabled=False)
3757

3858
env = create_agent_environment(manifest)
3959

4060
assert "REDIS_URL" not in env
4161

4262
def test_opt_out_clears_redis_url_when_parent_env_has_one(
43-
self, manifest_path: str, monkeypatch: pytest.MonkeyPatch
63+
self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
4464
):
4565
"""With redis_enabled=false, a stale parent-shell REDIS_URL must not leak through."""
4666
monkeypatch.setenv("REDIS_URL", "redis://leftover.from.parent.shell:6379")
47-
manifest = AgentManifest.from_yaml(file_path=manifest_path)
48-
assert manifest.local_development is not None
49-
manifest.local_development.redis_enabled = False
67+
manifest = _write_manifest(tmp_path, redis_enabled=False)
5068

5169
env = create_agent_environment(manifest)
5270

0 commit comments

Comments
 (0)