Skip to content

Commit 51ba40d

Browse files
jmc-wanderclaude
andcommitted
Fix CI: tests now pass without .pact/ directory
- Add src/apprentice/ as fallback path in conftest.py for GitHub Actions - Add cli_models.py shim that re-exports from apprentice.cli.cli_models (avoids Pydantic strict-mode class identity mismatch) - Fix _get_cli_module_path() to use main.__module__ for correct patching 2064 passed, 0 failed in both local (.pact/) and CI (no .pact/) modes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 25f4086 commit 51ba40d

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/apprentice/cli_models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""Re-export CLI models from the canonical location.
2+
3+
This shim ensures that `from src.cli_models import ...` (used by composition
4+
modules) resolves to the *same* Pydantic classes that `apprentice.cli.cli`
5+
uses internally. Without this, Pydantic strict-mode rejects cross-module
6+
instances because the class objects differ.
7+
"""
8+
9+
from apprentice.cli.cli_models import * # noqa: F401,F403

tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
_project_root = Path(__file__).parent.parent
1212
_impls = _project_root / ".pact" / "implementations"
1313
_comps = _project_root / ".pact" / "compositions"
14+
_pkg = _project_root / "src" / "apprentice"
1415

1516
# Create a virtual 'src' package that lazily loads from implementations
1617
if "src" not in sys.modules:
@@ -32,6 +33,14 @@
3233
if src_str not in sys.path:
3334
sys.path.append(src_str)
3435

36+
# Fallback: add src/apprentice/ so tests work on CI where .pact/ doesn't exist
37+
if _pkg.is_dir():
38+
_pkg_str = str(_pkg)
39+
if _pkg_str not in sys.modules["src"].__path__:
40+
sys.modules["src"].__path__.append(_pkg_str)
41+
if _pkg_str not in sys.path:
42+
sys.path.append(_pkg_str)
43+
3544

3645
@pytest.fixture(autouse=True)
3746
def _wire_root_components(request):

tests/test_cli.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -741,11 +741,8 @@ class TestMain:
741741

742742
def _get_cli_module_path(self):
743743
"""Determine the module path for patching."""
744-
try:
745-
import src.cli
746-
return "src.cli"
747-
except ImportError:
748-
return "cli"
744+
# Use the actual module where main() is defined, not the re-export alias
745+
return main.__module__
749746

750747
def test_main_usage_error_no_args(self):
751748
"""main() returns exit code 2 on missing arguments (no subcommand)."""

0 commit comments

Comments
 (0)