In this section
- Run V10 Validation storage · solar-electrical-topology-analysis-engine-text-based / scripts/run_v10_validation.py lines 1–180
- Sync Programme State storage · solar-electrical-topology-analysis-engine-text-based / scripts/sync_programme_state.py lines 1–317
Run V10 Validation
A Python command-line tool in the scripts folder of Solar Electrical Topology Analysis Engine Text Based that runs command (`run_command`).
storagesolar-electrical-topology-analysis-engine-text-based / scripts/run_v10_validation.py · lines 1–180 of 180 · Entry point · pattern markdown_report (shared by 2 files)
- What it does
- Defines utc_now, run_command, markdown_report, main. Uses libraries __future__, datetime, json, os, pathlib. Side effects: reads or writes files; starts processes.
- Why it exists in the grid workflow
- Domain stage sub33kv_design (repository name word 'solar'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary.
- Inputs & outputs
- In: JSON file V10_VALIDATION_LATEST.json.
- Downstream impact
- Used directly by 2 files: Run Ts004 Integration (solar-electrical-topology-analysis-engine-text-based); V10 Validation Workflow (solar-electrical-topology-analysis-engine-text-based). Reached from 6 other entry points, including Build 025 Small Gates Workflow (solar-electrical-topology-analysis-engine-text-based); Microbuild Worker Workflow (solar-electrical-topology-analysis-engine-text-based); Run Microbuild (solar-electrical-topology-analysis-engine-text-based).
- What it achieves
- It is built from the utc now helper (`utc_now`) and the markdown report helper (`markdown_report`). Run all declared V10 execution gates and write artifact-ready evidence.
- Why it matters
- Run by Run Ts004 Integration and V10 Validation Workflow.
- Application
- solar-electrical-topology-analysis-engine-text-based · scripts · Python CLI
- Uses
- V8 Model Test (script call), Run Tests (script call), Validate Clean Wheel (script call), __future__, datetime, json, os, pathlib, subprocess, sys, time
- Used by
- run by Run Ts004 Integration (script call), run by V10 Validation Workflow (workflow run)
- Produces
- utc_now, run_command, markdown_report, main
- Defines here
- utc_now, run_command, markdown_report, main
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- solar-electrical-topology-analysis-engine-text-based@d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9 scripts/run_v10_validation.py:1-180 · blob 56abd22e0d9ec77ee424ef1943a11de9ecbbda9b · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: filesystem, process · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
#!/usr/bin/env python3
"""Run all declared V10 execution gates and write artifact-ready evidence."""
from __future__ import annotations
from datetime import datetime, timezone
import json
import os
from pathlib import Path
import subprocess
import sys
import time
ROOT = Path(__file__).resolve().parents[1]
REPORT_DIR = ROOT / "v10-development" / "recovery" / "validation"
JSON_PATH = REPORT_DIR / "V10_VALIDATION_LATEST.json"
MARKDOWN_PATH = REPORT_DIR / "V10_VALIDATION_LATEST.md"
MAX_OUTPUT_CHARS = 30_000
COMMANDS = (
(
"python",
[sys.executable, "-m", "pytest", "-q"],
ROOT,
),
(
"v8",
["node", "--test", "tests/v8-model.test.js"],
ROOT,
),
(
"v9",
["node", "v9-sandbox/debug/run-tests.mjs"],
ROOT,
),
(
"v10-javascript",
["npm", "test"],
ROOT / "v10-development",
),
(
"clean-wheel",
[sys.executable, "scripts/validate_clean_wheel.py"],
ROOT,
),
)
def utc_now() -> str:
return (
datetime.now(timezone.utc)
.replace(microsecond=0)
.isoformat()
.replace("+00:00", "Z")
)
def run_command(name: str, command: list[str], cwd: Path) -> dict:
started = time.monotonic()
try:
completed = subprocess.run(
command,
cwd=cwd,
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
check=False,
)
return_code = completed.returncode
output = completed.stdout or ""
except OSError as exc:
return_code = 127
output = f"unable to execute command: {exc}"
duration_seconds = round(time.monotonic() - started, 3)
if len(output) > MAX_OUTPUT_CHARS:
output = (
output[:MAX_OUTPUT_CHARS]
+ "\n...[output truncated by validation receipt]...\n"
)
return {
"name": name,
"command": command,
"cwd": str(cwd.relative_to(ROOT)),
"return_code": return_code,
"pass": return_code == 0,
"duration_seconds": duration_seconds,
"output": output,
}
def markdown_report(payload: dict) -> str:
lines = [
"# V10 Validation Execution Envelope",
"",
f"Generated UTC: `{payload['generated_utc']}` ",
f"Repository head: `{payload['git_sha']}` ",
f"Overall result: `{'PASS' if payload['pass'] else 'FAIL'}` ",
f"Schema version: `{payload['schema_version']}`",
"",
"## Declared suites",
"",
]
for result in payload["results"]:
lines.extend(
[
f"### {result['name']}",
"",
f"Result: `{'PASS' if result['pass'] else 'FAIL'}` ",
f"Return code: `{result['return_code']}` ",
f"Duration: `{result['duration_seconds']} s` ",
f"Working directory: `{result['cwd'] or '.'}` ",
"Command:",
"",
"```text",
" ".join(result["command"]),
"```",
"",
"Output:",
"",
"```text",
result["output"].rstrip(),
"```",
"",
]
)
lines.extend(
[
"## Gate",
"",
(
"All declared Python, V8, V9, V10 JavaScript and clean-wheel suites passed."
if payload["pass"]
else "One or more declared suites failed; authority promotion is blocked."
),
"",
"This execution envelope records one run. It does not change deterministic engineering receipts or promote an implementation by itself.",
"",
]
)
return "\n".join(lines)
def main() -> int:
REPORT_DIR.mkdir(parents=True, exist_ok=True)
results = [
run_command(name, list(command), cwd)
for name, command, cwd in COMMANDS
]
payload = {
"schema_version": "globalgrid2050.v10-validation-execution-envelope.v2",
"generated_utc": utc_now(),
"repository": "Ventusltd/solar-electrical-topology-analysis-engine-text-based",
"git_sha": os.environ.get("GITHUB_SHA", "local-or-unknown"),
"pass": all(result["pass"] for result in results),
"results": results,
}
JSON_PATH.write_text(
json.dumps(payload, indent=2, sort_keys=True) + "\n",
encoding="utf-8",
)
MARKDOWN_PATH.write_text(markdown_report(payload), encoding="utf-8")
print(
json.dumps(
{
"pass": payload["pass"],
"reports": [str(MARKDOWN_PATH), str(JSON_PATH)],
}
)
)
return 0 if payload["pass"] else 1
if __name__ == "__main__":
raise SystemExit(main())Sync Programme State
A Python command-line tool in the scripts folder of Solar Electrical Topology Analysis Engine Text Based that reads programme state schema, using SHA-256.
storagesolar-electrical-topology-analysis-engine-text-based / scripts/sync_programme_state.py · lines 1–317 of 317 · Entry point · pattern check_outputs (shared by 2 files)
- What it does
- It loads programme state schema. Defines 13 functions or classes, including load_json, decimal, require, validate_state, suite_rows. Uses libraries __future__, argparse, decimal, html, json. Side effects: reads or writes files.
- Why it exists in the grid workflow
- Domain stage sub33kv_design (repository name word 'solar'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary.
- Inputs & outputs
- In: JSON file programme-state.json; JSON file programme-state.schema.json; command-line arguments.
- Downstream impact
- Used directly by 3 files: Run Ts004 Integration (solar-electrical-topology-analysis-engine-text-based); Programme State Sync Workflow (solar-electrical-topology-analysis-engine-text-based); V10 Validation Workflow (solar-electrical-topology-analysis-engine-text-based). Reached from 6 other entry points, including Build 025 Small Gates Workflow (solar-electrical-topology-analysis-engine-text-based); Microbuild Worker Workflow (solar-electrical-topology-analysis-engine-text-based); Run Microbuild (solar-electrical-topology-analysis-engine-text-based).
- What it achieves
- It loads JSON (`load_json`), validates state (`validate_state`) and renders readme block (`render_readme_block`). Validate `programme-state.json` and keep public status projections in sync. Its code works with 352 kVA. It accepts `--check` and `--write`.
- Why it matters
- Run by Run Ts004 Integration, Programme State Sync Workflow and V10 Validation Workflow.
- Application
- solar-electrical-topology-analysis-engine-text-based · scripts · Python CLI
- Uses
- __future__, argparse, decimal, html, json, pathlib, re, sys
- Used by
- run by Run Ts004 Integration (script call), run by Programme State Sync Workflow (workflow run), run by V10 Validation Workflow (workflow run)
- Produces
- load_json, decimal, require, validate_state, suite_rows, render_readme_block, sync_readme, list_items, render_dashboard, expected_outputs, write_outputs, check_outputs
- Defines here
- load_json, decimal, require, validate_state, suite_rows, render_readme_block, sync_readme, list_items, render_dashboard, expected_outputs, write_outputs, check_outputs, main
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- solar-electrical-topology-analysis-engine-text-based@d3b4c497144c2c9b3e8f0e82117e7e9abe4672b9 scripts/sync_programme_state.py:1-317 · blob 76eb8b97a9c88962d948ac556a921dccb1055bf5 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: output · effects: filesystem · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
#!/usr/bin/env python3
"""Validate programme-state.json and keep public status projections in sync."""
from __future__ import annotations
import argparse
from decimal import Decimal
import html
import json
from pathlib import Path
import re
import sys
import tomllib
from typing import Any
ROOT = Path(__file__).resolve().parents[1]
MANIFEST_PATH = ROOT / "programme-state.json"
SCHEMA_PATH = ROOT / "schemas" / "programme-state.schema.json"
README_PATH = ROOT / "README.md"
DASHBOARD_PATH = ROOT / "progress-dashboard.html"
README_START = "<!-- PROGRAMME-STATE:START -->"
README_END = "<!-- PROGRAMME-STATE:END -->"
SCHEMA_VERSION = "globalgrid2050.solar-dc.programme-state.v1"
SHA40 = re.compile(r"^[0-9a-f]{40}$")
SHA256 = re.compile(r"^sha256:[0-9a-f]{64}$")
def load_json(path: Path) -> dict[str, Any]:
payload = json.loads(path.read_text(encoding="utf-8"))
if not isinstance(payload, dict):
raise ValueError(f"{path.name} must contain one JSON object")
return payload
def decimal(value: object) -> Decimal:
return Decimal(str(value))
def require(condition: bool, message: str) -> None:
if not condition:
raise ValueError(message)
def validate_state(state: dict[str, Any]) -> None:
"""Validate semantic invariants not expressible as simple field types."""
schema = load_json(SCHEMA_PATH)
require(
schema.get("$schema") == "https://json-schema.org/draft/2020-12/schema",
"programme-state schema must declare JSON Schema 2020-12",
)
require(state.get("schema_version") == SCHEMA_VERSION, "wrong schema_version")
required = tuple(schema.get("required", ()))
missing = [name for name in required if name not in state]
require(not missing, f"programme state missing required fields: {missing}")
allowed = set(schema.get("properties", {}))
unexpected = sorted(set(state) - allowed)
require(not unexpected, f"programme state has unexpected fields: {unexpected}")
require(SHA40.fullmatch(str(state["validated_commit"])) is not None, "invalid validated_commit")
validation = state["validation"]
require(isinstance(validation, dict), "validation must be an object")
require(SHA40.fullmatch(str(validation["merge_test_sha"])) is not None, "invalid merge_test_sha")
require(SHA256.fullmatch(str(validation["comparison_hash"])) is not None, "invalid comparison_hash")
suites = validation["suites"]
require(isinstance(suites, list) and suites, "validation suites must be non-empty")
names = [str(item["name"]) for item in suites]
require(len(names) == len(set(names)), "validation suite names must be unique")
for item in suites:
passed = int(item["passed"])
total = int(item["total"])
require(total > 0, f"suite total must be positive: {item['name']}")
require(passed == total, f"current manifest may declare only passing suites: {item['name']}")
pyproject = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8"))
package_version = pyproject["project"]["version"]
require(state["package_version"] == package_version, "package_version differs from pyproject.toml")
block = state["reference_inverter_block"]
modules_per_string = int(block["modules_per_string"])
strings = int(block["strings"])
module_power_wp = decimal(block["module_rated_power_wp"])
inverter_kva = decimal(block["inverter_apparent_power_kva"])
expected_modules = modules_per_string * strings
expected_string_kwp = module_power_wp * modules_per_string / Decimal(1000)
expected_dc_kwp = expected_string_kwp * strings
expected_ratio = expected_dc_kwp / inverter_kva
require(int(block["module_count"]) == expected_modules, "reference module_count arithmetic failed")
require(decimal(block["string_rated_power_kwp"]) == expected_string_kwp, "reference string power arithmetic failed")
require(decimal(block["dc_nameplate_power_kwp"]) == expected_dc_kwp, "reference DC power arithmetic failed")
require(decimal(block["dc_ac_nameplate_ratio"]) == expected_ratio, "reference DC/AC ratio arithmetic failed")
require(block["module_technology"] == "bifacial", "reference module technology must be bifacial")
require(expected_modules == 720, "reference fixture must contain 720 modules")
require(expected_dc_kwp == Decimal("475.2"), "reference fixture must equal 475.2 kWp DC")
require(inverter_kva == Decimal("352"), "reference inverter must equal 352 kVA")
capability_groups = state["capabilities"]
seen: set[str] = set()
for group_name in ("canonical", "provisional", "historical"):
group = capability_groups[group_name]
require(isinstance(group, list) and group, f"capability group {group_name} must be non-empty")
overlap = seen.intersection(group)
require(not overlap, f"capability classifications overlap: {sorted(overlap)}")
seen.update(group)
require("percentage" in state["progress_policy"].lower(), "progress policy must address numerical percentage claims")
prohibited = {"weighted_programme_progress", "progress_percent", "completion_percentage"}
require(not prohibited.intersection(state), "manual progress percentage field is prohibited")
require((ROOT / state["current_quantum_spawn"]).is_file(), "current Quantum Spawn path does not exist")
require((ROOT / state["current_trueself"]).is_file(), "current Trueself path does not exist")
require(
state["generated_outputs"] == [
"README.md programme-state block",
"progress-dashboard.html",
],
"generated_outputs contract changed",
)
def suite_rows(state: dict[str, Any]) -> str:
return "\n".join(
f"| {item['name']} | {item['passed']} / {item['total']} | PASS |"
for item in state["validation"]["suites"]
)
def render_readme_block(state: dict[str, Any]) -> str:
block = state["reference_inverter_block"]
return f"""{README_START}
## Current programme state
This block is generated from [`programme-state.json`](programme-state.json). CI fails if the manifest, this status block or [`progress-dashboard.html`](progress-dashboard.html) drift apart.
| Field | Current authority |
|---|---|
| Build | **{state['current_build']}** |
| Stage | {state['programme_stage']} |
| Package | `{state['package_version']}` |
| Last validated engineering commit | `{state['validated_commit']}` |
| Active gate | **{state['active_gate']}** |
| Next single goal | **{state['next_single_goal']}** |
### First complete product boundary
```text
{block['module_rated_power_wp']} Wp bifacial modules × {block['modules_per_string']} modules/string × {block['strings']} strings
= {block['module_count']} modules
= {block['dc_nameplate_power_kwp']} kWp DC
= one {block['inverter_apparent_power_kva']} kVA inverter block
DC/AC nameplate ratio = {block['dc_ac_nameplate_ratio']}
```
### Latest declared validation envelope
| Suite | Result | State |
|---|---:|---|
{suite_rows(state)}
Comparison hash: `{state['validation']['comparison_hash']}`
**Progress policy:** {state['progress_policy']}
{README_END}"""
def sync_readme(existing: str, block: str) -> str:
if README_START in existing or README_END in existing:
require(
existing.count(README_START) == 1 and existing.count(README_END) == 1,
"README programme-state markers are malformed",
)
start = existing.index(README_START)
end = existing.index(README_END) + len(README_END)
return existing[:start] + block + existing[end:]
lines = existing.splitlines()
require(lines and lines[0].startswith("# "), "README must start with a title")
return "\n".join([lines[0], "", block, "", *lines[1:]]).rstrip() + "\n"
def list_items(items: list[str], css_class: str = "") -> str:
class_attr = f' class="{css_class}"' if css_class else ""
return "\n".join(f"<li{class_attr}>{html.escape(item)}</li>" for item in items)
def render_dashboard(state: dict[str, Any]) -> str:
block = state["reference_inverter_block"]
validation = state["validation"]
suites = "\n".join(
"<article class=\"card\"><span>{}</span><strong>{} / {}</strong><small>PASS</small></article>".format(
html.escape(str(item["name"])), item["passed"], item["total"]
)
for item in validation["suites"]
)
canonical = list_items(state["capabilities"]["canonical"], "canonical")
provisional = list_items(state["capabilities"]["provisional"], "provisional")
historical = list_items(state["capabilities"]["historical"], "historical")
limitations = list_items(state["known_limitations"], "limitation")
return f"""<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="description" content="Generated engineering programme state for the Solar Electrical Topology Analysis Engine.">
<title>Solar Topology Engine · Programme Truth</title>
<style>
:root{{color-scheme:dark;--bg:#05090d;--panel:#0b151d;--line:#254052;--text:#edf8fd;--muted:#91a9b8;--good:#55dfa0;--active:#43cfff;--warn:#ffc95e;--historic:#a9a1d6}}
*{{box-sizing:border-box}}body{{margin:0;background:radial-gradient(circle at 12% 0,#14364d 0,var(--bg) 42%);color:var(--text);font:15px/1.55 system-ui,-apple-system,"Segoe UI",sans-serif}}header,main,footer{{max-width:1180px;margin:auto;padding:24px}}header{{padding-top:42px}}h1{{font-size:clamp(34px,7vw,68px);line-height:1;margin:.16em 0}}h2{{margin:32px 0 10px}}.kicker{{color:var(--active);font … [line shortened here: 1,582 characters; full line on GitHub]
</style>
</head>
<body>
<header>
<div class="kicker">GLOBALGRID2050 · GENERATED PROGRAMME STATE</div>
<h1>Solar Topology Engine</h1>
<p class="muted">This page is generated from <a href="./programme-state.json">programme-state.json</a>. It contains no manually maintained completion percentage.</p>
<div class="pills">
<div class="pill"><small>Current build</small><strong>{html.escape(state['current_build'])}</strong></div>
<div class="pill"><small>Package</small><strong>{html.escape(state['package_version'])}</strong></div>
<div class="pill"><small>Active gate</small><strong>{html.escape(state['active_gate'])}</strong></div>
<div class="pill"><small>Next single goal</small><strong>{html.escape(state['next_single_goal'])}</strong></div>
</div>
</header>
<main>
<h2>First complete product boundary</h2>
<section class="panel boundary">{block['module_rated_power_wp']} Wp bifacial modules × {block['modules_per_string']} modules/string × {block['strings']} strings
= {block['module_count']} modules
= {block['dc_nameplate_power_kwp']} kWp DC
= one {block['inverter_apparent_power_kva']} kVA inverter block
DC/AC nameplate ratio = {block['dc_ac_nameplate_ratio']}</section>
<h2>Latest declared validation envelope</h2>
<section class="grid">{suites}</section>
<p class="muted">Workflow run <code>{validation['run_id']}</code> · artefact <code>{validation['artifact_id']}</code> · validated engineering commit <code>{state['validated_commit']}</code></p>
<p class="muted">Comparison hash <code>{validation['comparison_hash']}</code></p>
<h2>Capability authority</h2>
<section class="columns">
<div class="panel"><h3>Canonical</h3><ul>{canonical}</ul></div>
<div class="panel"><h3>Provisional</h3><ul>{provisional}</ul></div>
<div class="panel"><h3>Historical workbenches</h3><ul>{historical}</ul></div>
</section>
<h2>Known limitations</h2>
<section class="panel"><ul>{limitations}</ul></section>
<h2>Progress policy</h2>
<section class="panel policy">{html.escape(state['progress_policy'])}</section>
<h2>Continuity</h2>
<section class="panel">
<p>Current Quantum Spawn: <code>{html.escape(state['current_quantum_spawn'])}</code></p>
<p>Current Trueself checkpoint: <code>{html.escape(state['current_trueself'])}</code></p>
<p>Restore point: <code>{html.escape(state['restore_point'])}</code></p>
</section>
</main>
<footer>Generated deterministically by <code>scripts/sync_programme_state.py</code>. Engineering outputs remain evidence-qualified and are not a project-specific approval or compliance certificate.</footer>
</body>
</html>
"""
def expected_outputs(state: dict[str, Any]) -> tuple[str, str]:
readme = README_PATH.read_text(encoding="utf-8")
expected_readme = sync_readme(readme, render_readme_block(state))
expected_dashboard = render_dashboard(state)
return expected_readme, expected_dashboard
def write_outputs(state: dict[str, Any]) -> None:
expected_readme, expected_dashboard = expected_outputs(state)
README_PATH.write_text(expected_readme, encoding="utf-8")
DASHBOARD_PATH.write_text(expected_dashboard, encoding="utf-8")
def check_outputs(state: dict[str, Any]) -> None:
current_readme = README_PATH.read_text(encoding="utf-8")
current_dashboard = DASHBOARD_PATH.read_text(encoding="utf-8")
expected_readme, expected_dashboard = expected_outputs(state)
failures = []
if current_readme != expected_readme:
failures.append("README.md programme-state block")
if current_dashboard != expected_dashboard:
failures.append("progress-dashboard.html")
if failures:
raise ValueError(
"programme-state drift detected in: " + ", ".join(failures)
+ "; run python scripts/sync_programme_state.py --write"
)
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser()
mode = parser.add_mutually_exclusive_group()
mode.add_argument("--check", action="store_true", help="fail when generated outputs drift")
mode.add_argument("--write", action="store_true", help="rewrite generated outputs")
args = parser.parse_args(argv)
state = load_json(MANIFEST_PATH)
validate_state(state)
if args.write:
write_outputs(state)
print("programme state validated and generated outputs written")
else:
check_outputs(state)
print("programme state validated; generated outputs are in sync")
return 0
if __name__ == "__main__":
try:
raise SystemExit(main())
except ValueError as exc:
print(f"programme-state error: {exc}", file=sys.stderr)
raise SystemExit(1) from exc