- 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>
114 lines
4.5 KiB
Python
114 lines
4.5 KiB
Python
"""The upload split into the run context and its listed files, as parse_assessment_files renders them (ADR 0018)."""
|
|
import io
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pandas as pd
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT))
|
|
from app import run_context as rc # noqa: E402
|
|
|
|
CASE = ROOT.parent / "workflows" / "cases" / "azure-crucible-kab-dev-cmdb"
|
|
SEP = "\n\n---\n\n"
|
|
|
|
|
|
def rendered_csv(path):
|
|
return pd.read_csv(path).to_string() # what data_file_processing.parse_csv hands on
|
|
|
|
|
|
def rendered_xlsx(frames):
|
|
buffer = io.BytesIO()
|
|
with pd.ExcelWriter(buffer) as writer:
|
|
for name, frame in frames.items():
|
|
frame.to_excel(writer, sheet_name=name, index=False)
|
|
parts = []
|
|
for name, frame in pd.read_excel(io.BytesIO(buffer.getvalue()), sheet_name=None).items():
|
|
parts += [f"=== Sheet: {name} ===", frame.to_string(), ""]
|
|
return "\n".join(parts) # data_file_processing.parse_excel
|
|
|
|
|
|
def upload(*files):
|
|
return SEP.join(files)
|
|
|
|
|
|
FULL_CONTEXT = (CASE / "context.yaml").read_text()
|
|
# The case lists a CI export and a relationship export; most tests here need a context with one listed upload.
|
|
CONTEXT = FULL_CONTEXT.replace(""" - name: cmdb-relationships.csv
|
|
source: cmdb_relationships
|
|
format: servicenow_cmdb_rel_ci_csv
|
|
taken: 2026-11-04
|
|
""", "")
|
|
assert CONTEXT != FULL_CONTEXT
|
|
|
|
|
|
def test_a_context_alone_reads_as_before():
|
|
single = (ROOT.parent / "workflows" / "cases" / "azure-crucible-kab-dev" / "context.yaml").read_text()
|
|
out = rc.split(single)
|
|
assert out["context"]["workflow_inputs"]["provider"] == "azure" and out["uploads"] == []
|
|
assert rc.context_section(single)["sources"]["cmdb"] == "not available"
|
|
|
|
|
|
def test_a_csv_after_the_context_leaves_the_context_readable():
|
|
text = upload(CONTEXT, rendered_csv(CASE / "cmdb-export.csv"))
|
|
out = rc.split(text)
|
|
assert out["context"]["plan"]["name"].endswith("with CMDB")
|
|
[cmdb] = rc.uploads_from(text, "cmdb")
|
|
[table] = rc.tables(cmdb)
|
|
assert table["sheet"] is None and "object_id" in table["header"] and len(table["rows"]) == 12
|
|
assert table["rows"][0][0] == 0 and "CI0010001" in table["rows"][0][1]
|
|
assert table["rows"][11][0] == 11 and "Retired" in table["rows"][11][1]
|
|
|
|
|
|
def test_two_files_in_order_and_an_xlsx_has_one_table_per_sheet():
|
|
ctx = CONTEXT.replace("uploads:\n", "uploads:\n - {name: assets.xlsx, source: cmdb}\n")
|
|
sheets = rendered_xlsx({"Servers": pd.DataFrame({"Name": ["a", "b"], "Env": ["prod", "dev"]}),
|
|
"Cloud": pd.DataFrame({"Id": ["/subscriptions/s/x"], "Env": ["dev"]})})
|
|
text = upload(ctx, sheets, rendered_csv(CASE / "cmdb-export.csv"))
|
|
names = [u["name"] for u in rc.uploads_from(text, "cmdb")]
|
|
assert names == ["assets.xlsx", "cmdb-export.csv"]
|
|
tables = rc.tables(rc.uploads_from(text, "cmdb")[0])
|
|
assert [(t["sheet"], len(t["rows"])) for t in tables] == [("Servers", 2), ("Cloud", 1)]
|
|
assert "Env" in tables[1]["header"]
|
|
|
|
|
|
def test_a_separator_inside_the_last_upload_is_kept():
|
|
text = upload(CONTEXT, "h\n0 a" + SEP + "1 b")
|
|
assert rc.split(text)["uploads"][0]["text"] == "h\n0 a" + SEP + "1 b"
|
|
|
|
|
|
def test_a_listed_upload_that_never_arrived_is_unreadable():
|
|
[cmdb] = rc.uploads_from(CONTEXT, "cmdb")
|
|
assert cmdb["text"] is None
|
|
with pytest.raises(rc.UploadUnreadable, match="not uploaded"):
|
|
rc.tables(cmdb)
|
|
|
|
|
|
def test_a_platform_parse_error_is_unreadable():
|
|
[cmdb] = rc.uploads_from(upload(CONTEXT, "CSV parsing error: bad line 3"), "cmdb")
|
|
with pytest.raises(rc.UploadUnreadable, match="could not parse"):
|
|
rc.tables(cmdb)
|
|
|
|
|
|
def test_an_empty_export_has_no_rows():
|
|
[cmdb] = rc.uploads_from(upload(CONTEXT, pd.DataFrame(columns=["a", "b"]).to_string()), "cmdb")
|
|
assert rc.tables(cmdb)[0]["rows"] == []
|
|
|
|
|
|
def test_a_raw_csv_is_numbered_by_position():
|
|
[cmdb] = rc.uploads_from(upload(CONTEXT, "id,name\n123,a\n456,b"), "cmdb")
|
|
assert rc.tables(cmdb)[0]["rows"] == [(0, "123,a"), (1, "456,b")]
|
|
|
|
|
|
def test_a_text_brief_is_not_a_context():
|
|
assert rc.split("Meridian brief\n\nSome text.")["context"] == {}
|
|
|
|
|
|
def test_the_case_lists_two_cmdb_uploads_in_order():
|
|
rels = " sys_id parent child\n0 R1 CI1 CI2"
|
|
text = upload(FULL_CONTEXT, rendered_csv(CASE / "cmdb-export.csv"), rels)
|
|
assert [u["name"] for u in rc.split(text)["uploads"]] == ["cmdb-export.csv", "cmdb-relationships.csv"]
|
|
[rel] = rc.uploads_from(text, "cmdb_relationships")
|
|
assert rc.tables(rel)[0]["rows"] == [(0, "0 R1 CI1 CI2")]
|