from __future__ import annotations from stewardship.context import build_context def test_context_selects_only_matching_topic(make_repo): repo = make_repo("positive/infra-lxd") result = build_context(repo, "container.deploy") bundle = result.bundle assert bundle["spec"]["intent"] == "container.deploy" assert bundle["spec"]["topics"] == ["topic:infra-lxd/container-deployment"] assert bundle["spec"]["documents"] == ["container-deployment-howto"] assert "operation:infra-lxd/container.inspect" in bundle["spec"]["operations"] def test_context_unrelated_intent_returns_empty_topics(make_repo): repo = make_repo("positive/infra-lxd") result = build_context(repo, "backup.restore") bundle = result.bundle assert bundle["spec"]["topics"] == [] assert bundle["spec"]["documents"] == [] def test_context_materialize_respects_budget_and_warns(make_repo): repo = make_repo("positive/infra-lxd") result = build_context(repo, "container.deploy", materialize=True, budget_bytes=5) assert result.truncated is True assert any("CONTEXT_BUDGET_TRUNCATED" in w for w in result.bundle["spec"]["warnings"]) assert result.materialized[0].bytes_used <= 5 def test_context_strict_mode_signaled_via_truncation_flag(make_repo): repo = make_repo("positive/infra-lxd") result = build_context(repo, "container.deploy", materialize=True, budget_bytes=0, strict=True) assert result.truncated is True