Files
cp1-agents/individual-agents/ALZ-F01: Discovery Workflow Agent/cp1-discovery-critic-agent/tests/test_coverage.py
Jonathan Boniface 9e503885cc ALZ-F01 Discovery: package step, value scorecard, application grouping, cases
- New cp1-discovery-package-agent (ADR 0020): one package per reviewed run, every part
  hashed (sha256 over canonical JSON), with a manifest and a value scorecard.
- Applications grouped CMDB -> tag -> resource group with a judged model fallback (ADR 0021):
  CMDB 0.7.0 carries ownership, dependency mapping 0.6.0 groups, report 0.9.0 shows them.
- Critic 0.6.1 accepts the producers' enums; build_workflow.py refuses a consumer enum
  narrower than its producer's.
- Code hooks, sub-agents and tests for the inventory, CMDB, dependency, planner and critic
  agents; the report and Well-Architected review agents; ADRs 0012-0021.
- Workflow cases with value bars and run limits; run evaluation and usage collection scripts;
  the run context template and the field-by-field review for ADR 0016.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 22:13:25 +00:00

58 lines
3.4 KiB
Python

"""The critic's own coverage count for a live run (ADR 0017), against stand-in listings (no runtime)."""
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))
from app import coverage # noqa: E402
RG = "/subscriptions/s/resourceGroups/g/providers/"
ROWS = [{"id": RG + "Microsoft.KeyVault/vaults/kv-a", "type": "microsoft.keyvault/vaults", "location": "eastus"},
{"id": RG + "Microsoft.Storage/storageAccounts/sa1", "type": "microsoft.storage/storageaccounts", "location": "eastus"},
{"id": RG + "Microsoft.Network/networkInterfaces/nic1", "type": "microsoft.network/networkinterfaces", "location": "eastus"},
{"id": RG + "Microsoft.EventGrid/systemTopics/t1", "type": "microsoft.eventgrid/systemtopics", "location": "eastus"}]
def call_with(rows, fail=False):
def call(tool, args):
assert tool == "azure_list_resources"
if fail:
return {"success": False, "error": {"message": "403"}}
return {"success": True, "data": {"items": rows, "next_page_token": None, "evidence_ref": "sha256:x"}}
return call
def test_an_unscanned_resource_is_a_coverage_gap():
payload = {"provider": "azure", "findings": [{"scope_entry_id": RG + "Microsoft.Storage/storageAccounts/sa1"}],
"coverage_gaps": [{"scope_entry_id": RG + "Microsoft.EventGrid/systemTopics/t1"}]}
live = coverage.live_scope(payload, call_with(ROWS))
assert (live["listed"], live["scope_entries"], live["folded"], live["covered"]) == (4, 3, 1, 2)
assert live["coverage_gaps"] == [RG + "Microsoft.KeyVault/vaults/kv-a"] and live["coverage_gap_count"] == 1
def test_azure_ids_match_whatever_their_case():
payload = {"provider": "azure", "findings": [{"scope_entry_id": r["id"].upper()} for r in ROWS]}
assert coverage.live_scope(payload, call_with(ROWS))["coverage_gap_count"] == 0
def test_a_failed_listing_is_reported_not_passed():
live = coverage.live_scope({"provider": "azure", "findings": []}, call_with(ROWS, fail=True))
assert live["listing_issues"] and live["scope_entries"] == 0
def test_every_recorded_dependency_is_checked_against_the_graph():
rg = "/subscriptions/s/resourceGroups/g/providers/"
pe, pg = rg + "Microsoft.Network/privateEndpoints/pe", rg + "Microsoft.DBforPostgreSQL/flexibleServers/pg"
subnet = "/subscriptions/s/resourceGroups/net/providers/Microsoft.Network/virtualNetworks/v/subnets/s"
nic, ip = rg + "Microsoft.Network/networkInterfaces/pe.nic", "/subscriptions/s/resourceGroups/n/providers/Microsoft.Network/publicIPAddresses/ip"
payload = {"provider": "azure",
"records": [{"canonical_id": "CI-001", "scope_entry_id": pe}, {"canonical_id": "CI-002", "scope_entry_id": pg}],
"findings": [{"scope_entry_id": pe, "dependencies": [pg, subnet, nic, pe]},
{"scope_entry_id": pg, "dependencies": [ip]}],
"edges": [{"source": "CI-001", "target": "CI-002"}, {"source": "CI-001", "target": subnet.upper()}],
"nodes": [{"id": subnet, "kind": "external"}],
"folded_dependencies": [{"source": "CI-001", "target": nic}]}
result = coverage.live_dependencies(payload)
assert (result["recorded"], result["edges"], result["to_external_nodes"], result["folded"]) == (4, 2, 1, 1)
assert result["missing"] == [f"{pg} -> {ip}"] and result["missing_count"] == 1