The backup is procured and proven, so the loop runs on real evidence. - data/actuals/2026-08.json: first real observation. database 0.6365 GB, stored 0.0066 GB over 8 objects, backup success 1/1, restore RTO 1.08 min. Five proxies null, each with a named owner in measurement_gaps. - data/thresholds/platform-audit-storage.json + tools/thresholds.py: budget variance, abnormal growth, stale backup, unused commitment. Fail-closed — an unmeasured value is reported as unmeasured, never as within. - financial_exchange.py gains a usage mode emitting technical_usage records to fin-hub, with measurement gaps carried through and no infrastructure amount: fin-hub owns the booked fact and a null is never sent as 0.00. - observation schema 0.2 allows null cost and usage proxies; variance.py fails closed rather than reporting a 100% favourable variance on a missing amount. - platform-audit-storage: ordered -> active, commissioned 2026-08-14, on operational fact rather than on the purchase. The optimization case is now approved by the founder. That needed a schema change: Host Europe never supplied written terms, so options gained excluded/exclusion_reason. Previously an unevaluable alternative blocked its case forever, leaving the record claiming no decision while the bucket was in production. An excluded option keeps its unknowns and must say what would bring it back. August produces no variance and should not: the decision forecast starts at 2026-09, so August is a commissioning baseline. Threshold run is 2 within, 1 not applicable, 6 unmeasured, 0 breaches. Also fixes a pre-existing test failure: reef-storage consumers_actual is now rapp-postgres, which the assertion still expected to be empty. 136 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
216 lines
10 KiB
Python
216 lines
10 KiB
Python
import sys
|
|
import unittest
|
|
from datetime import date
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parents[1] / "tools"))
|
|
from entities import REQUIRED_ENTITY_IDS
|
|
from portfolio_report import (
|
|
build,
|
|
cost_section,
|
|
lifecycle_section,
|
|
renewals_section,
|
|
risk_section,
|
|
utilization_section,
|
|
)
|
|
|
|
ROOT = Path(__file__).parents[1]
|
|
TODAY = date(2026, 8, 14)
|
|
|
|
|
|
def resource(rid="resource:test", **overrides):
|
|
result = {
|
|
"id": rid,
|
|
"status": "active",
|
|
"location": {"failure_domains": ["provider:test"]},
|
|
"capacity": [
|
|
{"metric": "cpu", "value": 4, "unit": "vCPU", "kind": "usable", "observed_at": "2026-08-11"},
|
|
{"metric": "cpu_usage", "value": 1, "unit": "vCPU", "kind": "observed", "observed_at": "2026-08-11"},
|
|
],
|
|
"ownership": {"owner": "test-owner", "allocation": {"mode": "dedicated"}},
|
|
"cost": {"price_evidence": "quote#1", "billing_model": "fixed"},
|
|
"lifecycle": {"renews_on": None, "cancel_by": None},
|
|
}
|
|
result.update(overrides)
|
|
return result
|
|
|
|
|
|
class UtilizationTest(unittest.TestCase):
|
|
def test_paired_metrics_produce_a_ratio_and_a_signal(self):
|
|
section = utilization_section([resource()])
|
|
metric = section["measured"][0]["metrics"][0]
|
|
self.assertEqual(0.25, metric["ratio"])
|
|
self.assertEqual("idle", metric["signal"])
|
|
self.assertEqual(["resource:test"], section["idle"])
|
|
|
|
def test_saturated_capacity_is_flagged_separately(self):
|
|
record = resource()
|
|
record["capacity"][1]["value"] = 3.8
|
|
section = utilization_section([record])
|
|
self.assertEqual(["resource:test"], section["saturated"])
|
|
self.assertEqual([], section["idle"])
|
|
|
|
def test_unpaired_capacity_is_reported_as_unmeasured_not_omitted(self):
|
|
record = resource(capacity=[{"metric": "cpu", "value": 4, "unit": "vCPU", "kind": "usable"}])
|
|
section = utilization_section([record])
|
|
self.assertEqual([], section["measured"])
|
|
self.assertEqual("resource:test", section["unmeasured"][0]["resource_id"])
|
|
|
|
def test_zero_provisioned_capacity_does_not_divide_by_zero(self):
|
|
record = resource()
|
|
record["capacity"][0]["value"] = 0
|
|
self.assertEqual([], utilization_section([record])["measured"])
|
|
|
|
|
|
class CostTest(unittest.TestCase):
|
|
def test_portfolio_spend_is_unknown_rather_than_a_partial_sum(self):
|
|
section = cost_section([resource(), resource("resource:b", cost={"price_evidence": None, "billing_model": "unknown"})])
|
|
self.assertIsNone(section["known_monthly_spend_eur"])
|
|
self.assertEqual(1, len(section["unpriced"]))
|
|
self.assertIn("not computable", section["spend_note"])
|
|
|
|
def test_unattributed_resources_are_named_not_spread(self):
|
|
record = resource("resource:shared", ownership={"owner": "o", "allocation": {"mode": "unattributed"}})
|
|
section = cost_section([record])
|
|
self.assertEqual(["resource:shared"], [r["resource_id"] for r in section["unattributed_allocation"]])
|
|
|
|
|
|
class RenewalTest(unittest.TestCase):
|
|
def test_dates_inside_the_horizon_are_reported_with_days_remaining(self):
|
|
record = resource(lifecycle={"renews_on": "2026-09-01", "cancel_by": None})
|
|
section = renewals_section([record], TODAY)
|
|
self.assertEqual(18, section["approaching"][0]["days_remaining"])
|
|
|
|
def test_dates_beyond_the_horizon_are_not_reported(self):
|
|
record = resource(lifecycle={"renews_on": "2027-09-01", "cancel_by": None})
|
|
self.assertEqual([], renewals_section([record], TODAY)["approaching"])
|
|
|
|
def test_active_resource_without_dates_is_a_named_gap(self):
|
|
section = renewals_section([resource()], TODAY)
|
|
self.assertEqual("resource:test", section["undated"][0]["resource_id"])
|
|
|
|
def test_retired_resource_without_dates_is_not_a_gap(self):
|
|
self.assertEqual([], renewals_section([resource(status="retired")], TODAY)["undated"])
|
|
|
|
|
|
class RiskTest(unittest.TestCase):
|
|
def test_shared_failure_domain_is_flagged_above_two_resources(self):
|
|
records = [resource(f"resource:{i}") for i in range(3)]
|
|
risks = risk_section(records, utilization_section(records), cost_section(records))
|
|
kinds = {risk["kind"] for risk in risks}
|
|
self.assertIn("concentrated_failure_domain", kinds)
|
|
|
|
def test_two_resources_sharing_a_domain_is_not_yet_a_concentration_risk(self):
|
|
records = [resource(f"resource:{i}") for i in range(2)]
|
|
risks = risk_section(records, utilization_section(records), cost_section(records))
|
|
self.assertNotIn("concentrated_failure_domain", {risk["kind"] for risk in risks})
|
|
|
|
|
|
class LifecycleTest(unittest.TestCase):
|
|
def test_states_are_counted_and_unowned_resources_named(self):
|
|
records = [resource(), resource("resource:b", status="proposed",
|
|
ownership={"owner": None, "allocation": {"mode": "dedicated"}})]
|
|
section = lifecycle_section(records)
|
|
self.assertEqual({"active": 1, "proposed": 1}, section["by_status"])
|
|
self.assertEqual(["resource:b"], section["without_owner"])
|
|
|
|
|
|
class LivePortfolioTest(unittest.TestCase):
|
|
"""The report must render from the real committed portfolio, not fixtures."""
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.report = build(ROOT, TODAY)
|
|
|
|
def test_report_covers_every_registered_resource(self):
|
|
self.assertEqual(7, self.report["resource_count"])
|
|
self.assertEqual([], self.report["lifecycle"]["without_owner"])
|
|
|
|
def test_every_service_group_from_discovery_is_present(self):
|
|
groups = {row["group"] for row in self.report["coverage"]["groups"]}
|
|
self.assertEqual(
|
|
{"helix-forge", "coulomb-social", "shared-railiance", "representative-tenant"}, groups
|
|
)
|
|
|
|
def test_spend_is_reported_unknown_while_no_booked_cost_exists(self):
|
|
self.assertIsNone(self.report["cost"]["known_monthly_spend_eur"])
|
|
self.assertTrue(self.report["cost"]["unpriced"])
|
|
|
|
def test_host_concentration_is_surfaced_as_a_risk(self):
|
|
concentrations = [r for r in self.report["risks"] if r["kind"] == "concentrated_failure_domain"]
|
|
self.assertIn("host:railiance01", " ".join(r["detail"] for r in concentrations))
|
|
|
|
def test_idle_cluster_capacity_is_surfaced(self):
|
|
self.assertIn("resource:railiance:reef-railiance:k3s", self.report["utilization"]["idle"])
|
|
|
|
def test_missing_contract_dates_are_surfaced_rather_than_read_as_no_commitments(self):
|
|
self.assertTrue(self.report["renewals"]["undated"])
|
|
|
|
def test_optimization_cases_are_listed_with_their_state(self):
|
|
cases = self.report["optimization"]["cases"]
|
|
self.assertEqual(2, len(cases))
|
|
states = {c["case_id"]: c["state"] for c in cases}
|
|
# The storage case was decided and executed on 2026-08-14; the cluster
|
|
# rightsizing case is still blocked on delegated evidence.
|
|
self.assertEqual("approved", states["opt:platform-audit-storage:2026-08"])
|
|
self.assertEqual("blocked_on_evidence", states["opt:reef-railiance-k3s:2026-08"])
|
|
self.assertEqual(["opt:reef-railiance-k3s:2026-08"], self.report["optimization"]["undecided"])
|
|
self.assertTrue(self.report["optimization"]["blocked_on_evidence"])
|
|
|
|
def test_next_actions_name_an_owning_repository_for_each_gap(self):
|
|
self.assertTrue(self.report["next_actions"])
|
|
for action in self.report["next_actions"]:
|
|
self.assertIn(":", action)
|
|
|
|
def test_report_is_deterministic_for_a_fixed_date(self):
|
|
self.assertEqual(self.report, build(ROOT, TODAY))
|
|
|
|
def test_every_financial_entity_is_listed_and_unattributed_cost_is_named(self):
|
|
ids = [row["financial_entity_id"] for row in self.report["entities"]["entities"]]
|
|
self.assertEqual(list(REQUIRED_ENTITY_IDS), ids)
|
|
self.assertIsNone(self.report["entities"]["known_monthly_spend_eur"])
|
|
unattributed = {row["resource_id"] for row in self.report["entities"]["unattributed_resources"]}
|
|
self.assertIn("resource:hosteurope:railiance01", unattributed)
|
|
coulomb = next(row for row in self.report["entities"]["entities"] if row["financial_entity_id"] == "entity:coulomb")
|
|
self.assertIn("resource:tenant:coulomb:coulomb-social", coulomb["dedicated_resources"])
|
|
self.assertTrue(coulomb["shared_shares"])
|
|
self.assertIsNone(coulomb["consumption_mode"])
|
|
|
|
|
|
class DeliveredEvidenceTest(unittest.TestCase):
|
|
"""RAILIANCE-WP-0016 delivered apps-pg evidence; partial delivery must not
|
|
read as full coverage."""
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.report = build(ROOT, TODAY)
|
|
|
|
def test_delivered_gap_leaves_the_open_list(self):
|
|
owners = {gap["owner"] for gap in self.report["coverage"]["unresolved_gaps"]}
|
|
self.assertNotIn("railiance-platform", owners)
|
|
|
|
def test_delivered_gap_stays_visible_with_its_interface(self):
|
|
delivered = self.report["coverage"]["delivered_gaps"]
|
|
self.assertEqual(1, len(delivered))
|
|
self.assertEqual("railiance-platform", delivered[0]["owner"])
|
|
self.assertTrue(delivered[0]["interface"])
|
|
|
|
def test_residual_unknowns_still_produce_next_actions(self):
|
|
residuals = [a for a in self.report["next_actions"] if "delivered, still open" in a]
|
|
self.assertEqual(3, len(residuals))
|
|
|
|
def test_apps_pg_is_now_measurable_and_idle(self):
|
|
self.assertIn("resource:railiance:apps-pg", self.report["utilization"]["idle"])
|
|
unmeasured = {row["resource_id"] for row in self.report["utilization"]["unmeasured"]}
|
|
self.assertNotIn("resource:railiance:apps-pg", unmeasured)
|
|
|
|
def test_apps_pg_cost_is_now_attributed_but_still_unpriced(self):
|
|
unattributed = {row["resource_id"] for row in self.report["cost"]["unattributed_allocation"]}
|
|
self.assertNotIn("resource:railiance:apps-pg", unattributed)
|
|
unpriced = {row["resource_id"] for row in self.report["cost"]["unpriced"]}
|
|
self.assertIn("resource:railiance:apps-pg", unpriced)
|
|
self.assertIsNone(self.report["cost"]["known_monthly_spend_eur"])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|