feat(fase1): dimension IR + admits, MAF-free guard extended (F1)
This commit is contained in:
parent
254e3da1d8
commit
a44256a994
3 changed files with 135 additions and 8 deletions
|
|
@ -9,10 +9,17 @@ No ``agent_framework``/``mcp`` import is allowed in ``okf`` — guarded by ``tes
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from portfolio_optimiser import okf
|
||||
|
||||
# Framework-neutral, D7-portable modules that must never import MAF/mcp (C2:
|
||||
# the guard previously scanned only okf.py; dimension.py is now covered too).
|
||||
_MAF_FREE_MODULES = ["okf.py", "dimension.py"]
|
||||
|
||||
BUNDLE_DIR = Path(__file__).resolve().parents[1] / "shared" / "examples" / "bygg-energi-mikro"
|
||||
|
||||
|
||||
|
|
@ -162,14 +169,14 @@ def test_link_in_index_is_idempotent(tmp_path) -> None:
|
|||
assert body.count("(promoted-verdict-x.md)") == 1
|
||||
|
||||
|
||||
def test_okf_is_maf_free() -> None:
|
||||
"""D7 portability: ``okf.py`` IMPORTS no ``agent_framework`` / ``mcp`` (the docstring may name
|
||||
them to document the constraint, exactly as ``retrieval.py`` does) — checked via the AST, not a
|
||||
raw substring, so the prose claim doesn't trip the guard."""
|
||||
import ast
|
||||
|
||||
@pytest.mark.parametrize("module_name", _MAF_FREE_MODULES)
|
||||
def test_okf_is_maf_free(module_name: str) -> None:
|
||||
"""D7 portability: each framework-neutral module IMPORTS no ``agent_framework`` / ``mcp`` (a
|
||||
docstring may name them to document the constraint, exactly as ``retrieval.py`` does) — checked
|
||||
via the AST, not a raw substring, so the prose claim doesn't trip the guard. Parametrized over
|
||||
``_MAF_FREE_MODULES`` so ``dimension.py`` is guarded alongside ``okf.py`` (C2)."""
|
||||
src = (
|
||||
Path(__file__).resolve().parents[1] / "src" / "portfolio_optimiser" / "okf.py"
|
||||
Path(__file__).resolve().parents[1] / "src" / "portfolio_optimiser" / module_name
|
||||
).read_text(encoding="utf-8")
|
||||
imported: list[str] = []
|
||||
for node in ast.walk(ast.parse(src)):
|
||||
|
|
@ -178,4 +185,4 @@ def test_okf_is_maf_free() -> None:
|
|||
elif isinstance(node, ast.ImportFrom):
|
||||
imported.append(node.module or "")
|
||||
forbidden = [m for m in imported if m.split(".")[0] in {"agent_framework", "mcp"}]
|
||||
assert forbidden == [], f"okf.py must not import MAF/mcp, found: {forbidden}"
|
||||
assert forbidden == [], f"{module_name} must not import MAF/mcp, found: {forbidden}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue