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>
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
"""The report reads the run context alone and lists the uploads, never their raw text (ADR 0018)."""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pandas as pd
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
from app import report # noqa: E402
|
||||
|
||||
CASE = ROOT.parent / "workflows" / "cases" / "azure-crucible-kab-dev-cmdb"
|
||||
SOURCE = (CASE / "context.yaml").read_text() + "\n\n---\n\n" + pd.read_csv(CASE / "cmdb-export.csv").to_string()
|
||||
|
||||
|
||||
def data(**extra):
|
||||
return {"engagement_id": "E", "run_id": "R", "provider": "azure", "verdict": "pass", "source_documents": SOURCE,
|
||||
**extra}
|
||||
|
||||
|
||||
def test_the_context_section_holds_only_the_context_file():
|
||||
md = report.render(data())
|
||||
assert "CP1 live Azure trial, crucible-kab-dev with CMDB" in md
|
||||
assert "NOTE TO AI AGENT" not in md and "CI0010009" not in md
|
||||
assert "Uploaded files" in md and "cmdb-export.csv" in md
|
||||
|
||||
|
||||
def test_cmdb_files_and_injections_are_shown():
|
||||
md = report.render(data(cmdb_sources=[{"file": "cmdb-export.csv", "sheet": None, "rows": 12, "cis": 12,
|
||||
"skipped": 0}],
|
||||
cmdb_injections=["CI0010001 (cmdb-export.csv row 0): short_description"]))
|
||||
assert "## CMDB files read" in md and "CI0010001 (cmdb-export.csv row 0)" in md
|
||||
html = report.render_html(data(cmdb_sources=[{"file": "cmdb-export.csv", "rows": 12, "cis": 12, "skipped": 0}]))
|
||||
assert "CMDB exports read" in html and "NOTE TO AI AGENT" not in html
|
||||
|
||||
|
||||
def test_drift_names_the_asset_and_the_cmdb_record():
|
||||
drift = [{"drift_id": "DR-001", "type": "stale_attribute", "canonical_id": "CI-002", "ci_ref": "CI0010002",
|
||||
"field": "location", "discovered_value": "eastus", "cmdb_value": "eastus2", "suggested_action": "update_attribute"}]
|
||||
for page in (report.render(data(drift_items=drift)), report.render_html(data(drift_items=drift))):
|
||||
assert "CI-002" in page and "CI0010002" in page and "eastus2" in page
|
||||
|
||||
|
||||
def test_the_shared_reader_is_the_planners():
|
||||
planner = ROOT.parent / "cp1-discovery-planner-agent" / "app" / "run_context.py"
|
||||
assert (ROOT / "app" / "run_context.py").read_text() == planner.read_text()
|
||||
|
||||
|
||||
GRAPH = {
|
||||
"records": [{"canonical_id": "CI-001", "hostname": "pe"}, {"canonical_id": "CI-002", "hostname": "pg"}],
|
||||
"nodes": [{"id": "CI-001", "kind": "resource", "name": "pe"}, {"id": "CI-002", "kind": "resource", "name": "pg"},
|
||||
{"id": "/subscriptions/s/resourceGroups/net/providers/Microsoft.Network/virtualNetworks/v/subnets/pe-subnet",
|
||||
"kind": "external", "name": "pe-subnet", "type": "microsoft.network/virtualnetworks/subnets",
|
||||
"container": "/subscriptions/s/resourcegroups/net", "referenced_by": ["CI-001"]},
|
||||
{"id": "cmdb:CI0010008", "kind": "ci", "ci_ref": "CI0010008", "name": "crucible-kab-dev-pg-pe"}],
|
||||
"edges": [{"edge_id": "E-001", "source": "CI-001", "target": "CI-002", "type": "app_to_db"},
|
||||
{"edge_id": "E-002", "source": "CI-001", "type": "network_attachment",
|
||||
"target": "/subscriptions/s/resourceGroups/net/providers/Microsoft.Network/virtualNetworks/v/subnets/pe-subnet"},
|
||||
{"edge_id": "E-003", "source": "cmdb:CI0010008", "target": "CI-001", "type": "represents"}],
|
||||
"graph_comparison": [{"result": "confirmed", "parent_ci": "CI0010008", "child_ci": "CI0010002",
|
||||
"source_resource": "/x/pe", "target_resource": "/x/pg"},
|
||||
{"result": "discovered_only", "parent_ci": "CI0010002", "child_ci": "CI0010008"}],
|
||||
"dangling": [{"parent": "CI0010001", "child": "CI0099999", "type_raw": "Depends on::Used by", "unresolved": ["child"]}],
|
||||
}
|
||||
|
||||
|
||||
def test_one_graph_is_drawn_by_node_kind():
|
||||
md = report.render(data(**GRAPH))
|
||||
assert 'n3{{"CI0010008 crucible-kab-dev-pg-pe"}}' in md or '{{"CI0010008 crucible-kab-dev-pg-pe"}}' in md
|
||||
assert "-.->|represents|" in md and "classDef external stroke-dasharray" in md
|
||||
assert "## Dependencies outside this discovery" in md and "/subscriptions/s/resourcegroups/net" in md
|
||||
|
||||
|
||||
def test_the_cmdb_comparison_and_dangling_relationships_are_shown():
|
||||
md = report.render(data(**GRAPH))
|
||||
assert "Confirmed by the cloud" in md and "Missing from the CMDB" in md and "CI0099999" in md
|
||||
deps = md.split("## Dependencies\n", 1)[1].split("\n## ", 1)[0]
|
||||
assert "represents" not in deps # links between a CI and its resource aren't dependencies
|
||||
html = report.render_html(data(**GRAPH))
|
||||
assert "Your CMDB's relationships against what the cloud shows" in html or "Your CMDB's relationships" in html
|
||||
|
||||
|
||||
APPS = {"applications": [{"application_id": "APP-001", "name": "KAB Platform", "basis": "cmdb_business_service",
|
||||
"members": ["CI-001", "CI-002", "CI-003"], "owner": "Platform Engineering",
|
||||
"review_required": True, "review_reasons": ["Joined by its Application tag 'AppName1'"]}],
|
||||
"asset_owners": [{"canonical_id": "CI-001", "owner": "Platform Engineering", "source": "cmdb"}],
|
||||
"ungrouped_assets": ["CI-009"]}
|
||||
|
||||
|
||||
def test_applications_and_owners_are_shown_for_review():
|
||||
"""ADR 0021: the Engagement Lead sees each application, how it was grouped, and what needs review."""
|
||||
built = report.build(data(**APPS, records=[{"canonical_id": "CI-001", "hostname": "aks", "facts": {}}]))
|
||||
table = next(t for t in built["tables"] if t["title"] == "Applications")
|
||||
assert table["rows"][0][:5] == ["APP-001", "KAB Platform", "CMDB business service", 3, "Platform Engineering"]
|
||||
assert "AppName1" in table["rows"][0][5]
|
||||
assert table["rows"][1][1] == "Not grouped" and table["rows"][1][5] == "CI-009"
|
||||
inventory = next(t for t in built["tables"] if t["title"] == "Inventory")
|
||||
assert inventory["rows"][0][5] == "Platform Engineering"
|
||||
assert ("Application groups", ["KAB Platform"]) in built["review"]
|
||||
titles = [t["title"] for t in built["tables"]]
|
||||
assert titles.index("Applications") == titles.index("Inventory") + 1
|
||||
assert "KAB Platform" in report.render_html(data(**APPS))
|
||||
|
||||
|
||||
def test_a_run_without_applications_has_no_applications_section():
|
||||
assert "Applications" not in [t["title"] for t in report.build(data())["tables"]]
|
||||
Reference in New Issue
Block a user