Add versioned metric graph authority, owned browser evidence, paginated and all-tab traversal, deterministic sampling policies, and analyst-facing run inspection. Provision the DEV/PREPROD/PROD Superset, Gitea and million-row ClickHouse lab; retain reproducible lifecycle evidence and explicit incomplete-traversal limits.
169 lines
10 KiB
Python
169 lines
10 KiB
Python
#!/usr/bin/env python3
|
|
# #region FullFlow.FinanceCapture [C:4] [TYPE Module] [SEMANTICS fixture,capture,baseline,approval]
|
|
# @BRIEF Capture actual published finance metrics under a genuine baseline-free structural context.
|
|
# @PRE Finance release ledger is published; no runnable traversal or expected literal is manufactured.
|
|
# @POST Approved baseline originates from actual server-selected query evidence.
|
|
# @RELATION DEPENDS_ON -> [FullFlow.FinanceRelease]
|
|
# @RATIONALE A server-compiled structural context is used only for capture; its steps are never claimed executed.
|
|
# @REJECTED Reusing the historical sales scenario would bind a different dashboard's provenance.
|
|
import argparse
|
|
from decimal import Decimal
|
|
import json
|
|
from pathlib import Path
|
|
from urllib.parse import urlencode
|
|
from uuid import UUID, uuid5
|
|
|
|
from release import Driver, Blocked, private_environment
|
|
|
|
|
|
# #region FullFlow.FinanceCapture.Configuration [C:2] [TYPE Function]
|
|
# @BRIEF Build a credential-free fixture locator with an independently derived scalar oracle.
|
|
def configuration(dashboard):
|
|
state = {"NATIVE_FILTER-FINANCE-METRIC": {
|
|
"id": "NATIVE_FILTER-FINANCE-METRIC",
|
|
"extraFormData": {"filters": [{"col": "metric_selector", "op": "IN", "val": ["sales_debt"]}]},
|
|
"filterState": {"value": ["sales_debt"], "label": "sales_debt"},
|
|
}}
|
|
return {"dashboard_id": dashboard, "dashboard_name": "Finance million",
|
|
"title": "Finance sales-only approved baseline",
|
|
"objective": "Compare actual selected sales debt with the exact approved published metric",
|
|
"live_binding_ref": "finance-million-preprod-admin",
|
|
"scalar_chart_uuid": str(uuid5(UUID('a75d5902-c347-490c-a282-f00acc1e1230'), 'chart:receivables-total')),
|
|
"metric": "selected_value_cents", "expected_value": "2624875000",
|
|
"baseline_set": "finance-million", "baseline_set_version": "1",
|
|
"catalog_repo": "admin/baseline-catalogs", "catalog_branch": "main",
|
|
"reference_url": "http://superset-preprod:8088/superset/dashboard/finance-million/?"+
|
|
urlencode({"native_filters": json.dumps(state)})}
|
|
# #endregion FullFlow.FinanceCapture.Configuration
|
|
|
|
|
|
# #region FullFlow.FinanceCapture.Context [C:4] [TYPE Function]
|
|
# @BRIEF Create a supported public structural authoring context solely for reference capture.
|
|
def context(driver):
|
|
dashboard = driver.config["dashboard_id"]
|
|
env = "full-flow-preprod"
|
|
model = driver.call("finance-query-model", "GET", "/api/dashboard-testing/query-model?"+
|
|
urlencode({"environment_id": env, "dashboard_id": dashboard}))
|
|
agent = driver.call("finance-capture-agent", "POST", "/api/agent/runs", {"context": {
|
|
"objectType": "dashboard", "objectId": str(dashboard), "objectName": "Finance million",
|
|
"envId": env, "route": f"/dashboards/{dashboard}", "contextVersion": 2,
|
|
"intent": "build_dashboard_test_scenario"}}, expected=(201,))
|
|
compiled = driver.call("finance-structural-context-compile", "POST", "/api/dashboard-testing/scenarios/compile", {
|
|
"agent_run_id": agent["id"], "query_model": model, "environment_id": env,
|
|
"dashboard_id": dashboard, "dashboard_name": "Finance million",
|
|
"objective": {"goal": "Structural authoring context for actual reference capture", "selected_case_ids": ["T03"]},
|
|
"capabilities": {"dataset_field_read": True},
|
|
"parameters": {"target_fields": {"type": "string_list", "default": ["counterparty_id"]}}})
|
|
graph = compiled["scenario"]
|
|
driver.require("finance-context-no-executed-truth", graph["steps"]
|
|
and any(s["action"] == "structural_assert" for s in graph["steps"])
|
|
and not any(s["expected"]["kind"] == "baseline_ref" for s in graph["steps"]))
|
|
pack = driver.call("finance-context-draft-pack", "POST",
|
|
f"/api/dashboard-testing/scenarios/{graph['scenario_id']}/draft-pack",
|
|
{"agent_run_id": agent["id"], "scenario": graph}, expected=(201,))
|
|
driver.require("finance-context-server-verified", pack["status"] == "save_eligible"
|
|
and pack["context_authority"] == "verified")
|
|
registered = driver.call("finance-context-register", "POST", "/api/dashboard-testing/scenarios", {
|
|
"compiled_handle_id": pack["compiled_handle_id"], "draft_pack_id": pack["draft_pack_handle_id"],
|
|
"draft_pack_digest": pack["draft_pack_digest"]}, expected=(201,))
|
|
driver.ids.update(registered)
|
|
# #endregion FullFlow.FinanceCapture.Context
|
|
|
|
|
|
# #region FullFlow.FinanceCapture.Scalar [C:4] [TYPE Function]
|
|
# @BRIEF Resolve exact exported fixture UUID against a fresh authoritative scalar chart.
|
|
# @PRE Preview and model originate from the same unchanged PREPROD dashboard context.
|
|
# @POST Returns one owned big-number chart ID or refuses, never selecting an aggregate chart by metric name.
|
|
def scalar_chart(driver, preview):
|
|
model = driver.call('finance-scalar-authority', 'GET', '/api/dashboard-testing/query-model?'+
|
|
urlencode({'environment_id': 'full-flow-preprod', 'dashboard_id': driver.config['dashboard_id']}))
|
|
scalar_ids = [c['chart_id'] for c in model['charts']
|
|
if c['chart_uuid'] == driver.config['scalar_chart_uuid'] and c['viz_type'] == 'big_number_total'
|
|
and not c['group_by_columns'] and c['execution_capable']]
|
|
driver.require('finance-exact-owned-scalar-chart', len(scalar_ids) == 1
|
|
and model['query_model_fingerprint'] == preview['query_model_fingerprint'])
|
|
return scalar_ids[0]
|
|
# #endregion FullFlow.FinanceCapture.Scalar
|
|
|
|
|
|
# #region FullFlow.FinanceCapture.Select [C:4] [TYPE Function]
|
|
# @BRIEF Select only the executed scalar chart and verify the fixed sales-only filter scope.
|
|
# @RELATION CALLS -> [FullFlow.FinanceCapture.Scalar]
|
|
def select(driver):
|
|
body = {"scenario_id": driver.ids["scenario_id"], "url": driver.config["reference_url"]}
|
|
preview = driver.call("finance-reference-preview", "POST", "/api/dashboard-testing/reference-discovery", body)
|
|
filters = preview["filters"]["filters"]
|
|
driver.require("finance-reference-sales-only", len(filters) == 1
|
|
and filters[0]["filter_id"] == "NATIVE_FILTER-FINANCE-METRIC"
|
|
and filters[0]["column"] == "metric_selector"
|
|
and filters[0]["value"].get("values") == ["sales_debt"])
|
|
chart_id = scalar_chart(driver, preview)
|
|
candidates = [c for c in preview["coordinates"]
|
|
if c['chart_id'] == chart_id and c["metric"] == driver.config["metric"] and c["execution_status"] == "executed"]
|
|
driver.require("finance-unique-actual-scalar-coordinate", len(candidates) == 1,
|
|
matching_chart_ids=[c["chart_id"] for c in candidates])
|
|
coordinate = candidates[0]
|
|
driver.require("fixture-filtered-metric", Decimal(str(coordinate["value"])) == Decimal("2624875000"),
|
|
coordinate=coordinate, expected_decimal="2624875000")
|
|
selected = {k: coordinate[k] for k in ("chart_id", "dataset_id", "metric", "evidence_digest", "value_digest", "execution_status")}
|
|
result = driver.call("finance-capture-selected", "POST", "/api/dashboard-testing/reference-selection/capture", {
|
|
**body, "selected": [selected], "expected_query_model_fingerprint": preview["query_model_fingerprint"],
|
|
"expected_filters_hash": preview["filters"]["filters_hash"]}, expected=(201,))
|
|
driver.require("finance-capture-exact-release", result["release_id"] == driver.ids["release_id"])
|
|
driver.ids.update(result)
|
|
return result
|
|
# #endregion FullFlow.FinanceCapture.Select
|
|
|
|
|
|
# #region FullFlow.FinanceCapture.Approve [C:4] [TYPE Function]
|
|
# @BRIEF Approve and consume the actual selected baseline against its immutable published release.
|
|
def approve(driver, captured, release):
|
|
root = f"/api/dashboard-testing/baseline-candidates/{captured['candidate_ids'][0]}/approval-gate"
|
|
identity = {"release_version": release["version"], "release_commit_hash": release["commit_hash"]}
|
|
gate = driver.call("finance-baseline-review", "POST", root, {
|
|
**identity, "agent_run_id": captured["agent_run_id"],
|
|
"reason": "Generated sales-only metric matches independent integer-cent oracle"}, expected=(201,))
|
|
driver.call("finance-baseline-confirm", "POST", root+f"/{gate['gate_id']}/decide",
|
|
{"decision": "confirm", "reason": "Authorized isolated synthetic fixture review"})
|
|
consumed = driver.call("finance-baseline-consume", "POST", root+f"/{gate['gate_id']}/consume?"+urlencode(identity))
|
|
driver.require("finance-baseline-consumed", consumed["consumed"] is True and consumed["status"] == "consumed")
|
|
driver.ids["baseline_id"] = consumed["baseline_id"]
|
|
# #endregion FullFlow.FinanceCapture.Approve
|
|
|
|
|
|
# #region FullFlow.FinanceCapture.Main [C:3] [TYPE Function]
|
|
# @BRIEF Retain a separate finance capture ledger without copying prior execution handles.
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--env-file", type=Path, required=True)
|
|
parser.add_argument("--release-output", type=Path, required=True)
|
|
parser.add_argument("--output", type=Path, required=True)
|
|
parser.add_argument("--fixture", type=Path, required=True)
|
|
args = parser.parse_args()
|
|
private_environment(args.env_file)
|
|
previous = json.loads((args.release_output/"report.json").read_text())
|
|
config = configuration(previous["ids"]["dashboard_id"])
|
|
args.fixture.write_text(json.dumps(config, indent=2)+"\n")
|
|
driver = Driver(config, args.output)
|
|
import os
|
|
driver.secrets.append(os.environ["CLICKHOUSE_PASSWORD"])
|
|
driver.ids["release_id"] = previous["ids"]["release_id"]
|
|
driver.phase = "finance-capture"
|
|
try:
|
|
driver.login()
|
|
context(driver)
|
|
captured = select(driver)
|
|
approve(driver, captured, json.loads((args.release_output/"published-release.json").read_text()))
|
|
except (Blocked, KeyError, StopIteration, ValueError) as exc:
|
|
driver.record("finance-capture-stopped", "BLOCKED", reason=str(exc))
|
|
finally:
|
|
driver.flush()
|
|
driver.client.close()
|
|
return int(any(s["status"] == "BLOCKED" for s in driver.steps))
|
|
# #endregion FullFlow.FinanceCapture.Main
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|
|
# #endregion FullFlow.FinanceCapture
|