2026-05-11 02:15:47 +02:00
|
|
|
"""Foundation Phase 4 smoke gate — final package layout."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import importlib
|
|
|
|
|
import inspect
|
|
|
|
|
import subprocess
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
from roboco.api import deps as api_deps
|
2026-06-03 06:35:03 +02:00
|
|
|
from roboco.api.routes.v1 import _role_dep as v1_role_dep
|
2026-05-11 02:15:47 +02:00
|
|
|
|
|
|
|
|
|
2026-06-14 13:43:46 +02:00
|
|
|
def test_lifecycle_module_lives_in_foundation() -> None:
|
2026-05-11 02:15:47 +02:00
|
|
|
"""Canonical import path is foundation.policy.lifecycle."""
|
|
|
|
|
lifecycle = importlib.import_module("roboco.foundation.policy.lifecycle")
|
|
|
|
|
assert hasattr(lifecycle, "Role")
|
|
|
|
|
assert hasattr(lifecycle, "Status")
|
|
|
|
|
assert hasattr(lifecycle, "_INTENT_VERBS")
|
|
|
|
|
|
|
|
|
|
|
2026-06-14 13:43:46 +02:00
|
|
|
def test_legacy_lifecycle_package_removed() -> None:
|
2026-05-11 02:15:47 +02:00
|
|
|
"""Legacy roboco.lifecycle package is gone."""
|
|
|
|
|
with pytest.raises(ModuleNotFoundError):
|
|
|
|
|
importlib.import_module("roboco.lifecycle")
|
|
|
|
|
|
|
|
|
|
|
2026-06-14 13:43:46 +02:00
|
|
|
def test_legacy_lifecycle_spec_module_removed() -> None:
|
2026-05-11 02:15:47 +02:00
|
|
|
with pytest.raises(ModuleNotFoundError):
|
|
|
|
|
importlib.import_module("roboco.lifecycle.spec")
|
|
|
|
|
|
|
|
|
|
|
2026-06-14 13:43:46 +02:00
|
|
|
def test_foundation_policy_complete() -> None:
|
2026-05-11 02:15:47 +02:00
|
|
|
"""All 6 policy domains exist in foundation."""
|
|
|
|
|
for mod in (
|
|
|
|
|
"lifecycle",
|
|
|
|
|
"tracing",
|
|
|
|
|
"journaling",
|
|
|
|
|
"task_completeness",
|
|
|
|
|
"communications",
|
|
|
|
|
"agent_loop",
|
|
|
|
|
):
|
|
|
|
|
importlib.import_module(f"roboco.foundation.policy.{mod}")
|
|
|
|
|
|
|
|
|
|
|
2026-06-14 13:43:46 +02:00
|
|
|
def test_no_lifecycle_imports_in_production() -> None:
|
2026-05-11 02:15:47 +02:00
|
|
|
"""Production code (roboco/) imports from foundation directly, no legacy paths."""
|
|
|
|
|
proc = subprocess.run(
|
|
|
|
|
[
|
|
|
|
|
"grep",
|
|
|
|
|
"-rn",
|
|
|
|
|
"from roboco.lifecycle\\|import roboco.lifecycle",
|
|
|
|
|
"roboco/",
|
|
|
|
|
"--include=*.py",
|
|
|
|
|
],
|
|
|
|
|
capture_output=True,
|
|
|
|
|
text=True,
|
|
|
|
|
check=False,
|
|
|
|
|
)
|
|
|
|
|
suspicious = []
|
|
|
|
|
for line in proc.stdout.splitlines():
|
|
|
|
|
if not line:
|
|
|
|
|
continue
|
|
|
|
|
# Allow docstring/comment mentions (the line contains 'lifecycle' but
|
|
|
|
|
# not as an actual import statement). A bare-bones filter:
|
|
|
|
|
suspicious.append(line)
|
|
|
|
|
assert suspicious == [], f"legacy lifecycle imports remain: {suspicious}"
|
|
|
|
|
|
|
|
|
|
|
2026-06-14 13:43:46 +02:00
|
|
|
def test_route_guard_role_sets_derive_from_foundation() -> None:
|
2026-06-03 06:35:03 +02:00
|
|
|
"""api/deps.py + v1/_role_dep.py use foundation Role-set composition."""
|
2026-05-11 02:15:47 +02:00
|
|
|
deps_src = inspect.getsource(api_deps)
|
2026-06-03 06:35:03 +02:00
|
|
|
role_dep_src = inspect.getsource(v1_role_dep)
|
2026-05-11 02:15:47 +02:00
|
|
|
assert (
|
|
|
|
|
"from roboco.foundation.identity" in deps_src
|
|
|
|
|
or "from roboco.foundation import" in deps_src
|
|
|
|
|
)
|
|
|
|
|
assert "Role." in role_dep_src # uses Role enum members, not raw strings
|
|
|
|
|
|
|
|
|
|
|
2026-06-14 13:43:46 +02:00
|
|
|
def test_make_foundation_check_target_exists() -> None:
|
2026-05-11 02:15:47 +02:00
|
|
|
"""Drift gate target is present in Makefile."""
|
|
|
|
|
makefile = Path("Makefile").read_text(encoding="utf-8")
|
|
|
|
|
assert "foundation-check:" in makefile
|