In this section
- Microbuild Evidence storage · solar-electrical-topology-analysis-engine-text-based / scripts/microbuild_evidence.py lines 1–181
- Reference Block Command transform · solar-electrical-topology-analysis-engine-text-based / scripts/reference_block_command.py lines 1–47
- Run Authority Slice ingest · solar-electrical-topology-analysis-engine-text-based / scripts/run_authority_slice.py lines 1–238
- Run Microbuild other · solar-electrical-topology-analysis-engine-text-based / scripts/run_microbuild.py lines 1–108
- Run Ts004 Integration ingest · solar-electrical-topology-analysis-engine-text-based / scripts/run_ts004_integration.py lines 1–85
Microbuild Evidence
A Python command-line tool in the scripts folder of Solar Electrical Topology Analysis Engine Text Based that works with evidence validation error (`EvidenceValidationError`) and evidence core payload (`evidence_core_payload`), using SHA-256.
storagesolar-electrical-topology-analysis-engine-text-based / scripts/microbuild_evidence.py · lines 1–181 of 181 · Entry point · pattern EvidenceValidationError (shared by 2 files)
- What it does
- Defines 11 functions or classes, including EvidenceValidationError, require, canonical_json, evidence_core_payload, microbuild_evidence_hash. Uses libraries __future__, argparse, hashlib, json, pathlib. 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: command-line arguments.
- Downstream impact
- Used directly by 5 files: Advance Microbuild (solar-electrical-topology-analysis-engine-text-based); Test Microbuild Advancement (solar-electrical-topology-analysis-engine-text-based); Test Microbuild Evidence (solar-electrical-topology-analysis-engine-text-based); Test Microbuild Workflow (solar-electrical-topology-analysis-engine-text-based); and 1 more. Reached from 4 other entry points, including Build 025 Small Gates Workflow (solar-electrical-topology-analysis-engine-text-based); Run Microbuild (solar-electrical-topology-analysis-engine-text-based); Test Microbuild Runner (solar-electrical-topology-analysis-engine-text-based).
- What it achieves
- It writes evidence (`write_evidence`) and is built from the evidence validation error class (`EvidenceValidationError`) and the require step (`require`). Create deterministic microbuild evidence with separate runtime metadata. It accepts `--plan`, `--tested-commit` and `--result`.
- Why it matters
- Imported by Advance Microbuild. Run by Microbuild Worker Workflow. Checked by 3 tests, including Test Microbuild Advancement.
- Application
- solar-electrical-topology-analysis-engine-text-based · scripts · Python CLI
- Uses
- Check Microbuild Plan (import), __future__, argparse, hashlib, json, pathlib, re, typing
- Used by
- imported by Advance Microbuild (import), imported by Test Microbuild Advancement (import), imported by Test Microbuild Evidence (import), run by Test Microbuild Workflow (script call), run by Microbuild Worker Workflow (workflow run)
- Produces
- EvidenceValidationError, require, canonical_json, evidence_core_payload, microbuild_evidence_hash, microbuild_evidence_payload, microbuild_evidence_json, evidence_from_active_plan, write_evidence, main
- Defines here
- EvidenceValidationError, require, canonical_json, evidence_core_payload, microbuild_evidence_hash, _runtime_id, microbuild_evidence_payload, microbuild_evidence_json, evidence_from_active_plan, write_evidence, 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/microbuild_evidence.py:1-181 · blob 0eb7583e2a317e97f09cf97f6c6c3ed5c98475bd · 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
"""Create deterministic microbuild evidence with separate runtime metadata."""
from __future__ import annotations
import argparse
import hashlib
import json
from pathlib import Path
import re
from typing import Any
try:
from scripts.check_microbuild_plan import DEFAULT_PLAN_PATH, load_plan, validate_plan
except ModuleNotFoundError: # Direct execution from the scripts directory.
from check_microbuild_plan import DEFAULT_PLAN_PATH, load_plan, validate_plan
MICROBUILD_EVIDENCE_SCHEMA_VERSION = (
"globalgrid2050.solar-dc.microbuild-evidence.v1"
)
STEP_ID = re.compile(r"^MB-(0[1-9]|1[0-9]|20)$")
TEST_ID = re.compile(r"^[a-z][a-z0-9_]*$")
SHA40 = re.compile(r"^[0-9a-f]{40}$")
RESULTS = {"pass", "fail"}
class EvidenceValidationError(ValueError):
"""Microbuild evidence is incomplete or malformed."""
def require(condition: bool, message: str) -> None:
if not condition:
raise EvidenceValidationError(message)
def canonical_json(payload: object) -> str:
return json.dumps(
payload,
sort_keys=True,
separators=(",", ":"),
ensure_ascii=False,
)
def evidence_core_payload(
*,
step_id: str,
manifest_revision: int,
tested_commit: str,
test_id: str,
result: str,
) -> dict[str, object]:
require(STEP_ID.fullmatch(step_id) is not None, "invalid step_id")
require(
isinstance(manifest_revision, int) and manifest_revision > 0,
"manifest_revision must be positive",
)
require(SHA40.fullmatch(tested_commit) is not None, "invalid tested_commit")
require(TEST_ID.fullmatch(test_id) is not None, "invalid test_id")
require(result in RESULTS, "result must be pass or fail")
return {
"schema_version": MICROBUILD_EVIDENCE_SCHEMA_VERSION,
"step_id": step_id,
"manifest_revision": manifest_revision,
"tested_commit": tested_commit,
"test_id": test_id,
"result": result,
}
def microbuild_evidence_hash(core: dict[str, object]) -> str:
expected = {
"schema_version",
"step_id",
"manifest_revision",
"tested_commit",
"test_id",
"result",
}
require(set(core) == expected, "evidence core fields changed")
digest = hashlib.sha256(canonical_json(core).encode("utf-8")).hexdigest()
return f"sha256:{digest}"
def _runtime_id(value: int | None, name: str) -> int | None:
if value is None:
return None
require(isinstance(value, int) and value > 0, f"{name} must be positive")
return value
def microbuild_evidence_payload(
*,
step_id: str,
manifest_revision: int,
tested_commit: str,
test_id: str,
result: str,
workflow_run_id: int | None = None,
artifact_id: int | None = None,
) -> dict[str, object]:
core = evidence_core_payload(
step_id=step_id,
manifest_revision=manifest_revision,
tested_commit=tested_commit,
test_id=test_id,
result=result,
)
return {
"core": core,
"evidence_hash": microbuild_evidence_hash(core),
"runtime": {
"workflow_run_id": _runtime_id(workflow_run_id, "workflow_run_id"),
"artifact_id": _runtime_id(artifact_id, "artifact_id"),
},
}
def microbuild_evidence_json(**kwargs: Any) -> str:
return canonical_json(microbuild_evidence_payload(**kwargs))
def evidence_from_active_plan(
*,
tested_commit: str,
result: str,
workflow_run_id: int | None = None,
artifact_id: int | None = None,
plan_path: Path = DEFAULT_PLAN_PATH,
) -> dict[str, object]:
summary = validate_plan(load_plan(plan_path))
require(
summary["programme_status"] != "completed",
"completed programme has no active step",
)
step_id = summary["active_step"]
test_id = summary["active_test_id"]
require(isinstance(step_id, str), "active step identifier must be text")
require(isinstance(test_id, str), "active test identifier must be text")
return microbuild_evidence_payload(
step_id=step_id,
manifest_revision=int(summary["manifest_revision"]),
tested_commit=tested_commit,
test_id=test_id,
result=result,
workflow_run_id=workflow_run_id,
artifact_id=artifact_id,
)
def write_evidence(path: Path, payload: dict[str, object]) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(canonical_json(payload) + "\n", encoding="utf-8")
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--plan", type=Path, default=DEFAULT_PLAN_PATH)
parser.add_argument("--tested-commit", required=True)
parser.add_argument("--result", choices=sorted(RESULTS), required=True)
parser.add_argument("--workflow-run-id", type=int)
parser.add_argument("--artifact-id", type=int)
parser.add_argument("--output", type=Path)
args = parser.parse_args()
payload = evidence_from_active_plan(
tested_commit=args.tested_commit,
result=args.result,
workflow_run_id=args.workflow_run_id,
artifact_id=args.artifact_id,
plan_path=args.plan,
)
if args.output is not None:
write_evidence(args.output, payload)
print(canonical_json(payload))
return 0
if __name__ == "__main__":
raise SystemExit(main())Reference Block Command
A Python command-line tool in the scripts folder of Solar Electrical Topology Analysis Engine Text Based that builds parser (`build_parser`). It is built from the reference block JSON helper (`reference_block_json`).
transformsolar-electrical-topology-analysis-engine-text-based / scripts/reference_block_command.py · lines 1–47 of 47 · Entry point · pattern build_parser (shared by 5 files)
- What it does
- It calculates its inputs. Defines reference_block_json, build_parser, main. Uses libraries __future__, argparse, sys, solar_topology.
- 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: command-line arguments.
- Downstream impact
- Used directly by 2 files: Build Authority Bundle (solar-electrical-topology-analysis-engine-text-based); Test Reference Block Command (solar-electrical-topology-analysis-engine-text-based). Reached from 14 other entry points, including Authority Bundle Sync Workflow (solar-electrical-topology-analysis-engine-text-based); Build 025 Small Gates Workflow (solar-electrical-topology-analysis-engine-text-based); Microbuild Worker Workflow (solar-electrical-topology-analysis-engine-text-based).
- What it achieves
- Print a versioned authoritative reference inverter-block response. It accepts `--strategy` and `--version`.
- Why it matters
- Imported by Build Authority Bundle. Checked by Test Reference Block Command.
- Application
- solar-electrical-topology-analysis-engine-text-based · scripts · Python CLI
- Uses
- __future__, argparse, sys, solar_topology
- Used by
- imported by Build Authority Bundle (import), imported by Test Reference Block Command (import)
- Produces
- reference_block_json, build_parser, main
- Defines here
- reference_block_json, build_parser, 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/reference_block_command.py:1-47 · blob 189b907a13c4c4a6856e331b52812ff268ce1d5d · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: transform · effects: none found · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
#!/usr/bin/env python3
"""Print a versioned authoritative reference inverter-block response."""
from __future__ import annotations
import argparse
import sys
import solar_topology as topology
REFERENCE_BLOCK_COMMAND_VERSION = (
"globalgrid2050.solar-dc.reference-block-command.v1"
)
def reference_block_json(strategy: str = "leapfrog") -> str:
receipt = topology.build_reference_inverter_block(strategy=strategy)
topology.validate_inverter_block_receipt(receipt)
return topology.inverter_block_json(receipt)
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description="Emit authoritative reference inverter-block JSON.",
)
parser.add_argument(
"--strategy",
choices=("leapfrog", "sequential"),
default="leapfrog",
)
parser.add_argument(
"--version",
action="version",
version=REFERENCE_BLOCK_COMMAND_VERSION,
)
return parser
def main(argv: list[str] | None = None) -> int:
args = build_parser().parse_args(argv)
sys.stdout.write(reference_block_json(args.strategy) + "\n")
return 0
if __name__ == "__main__":
raise SystemExit(main())Run Authority Slice
A Python command-line tool in the scripts folder of Solar Electrical Topology Analysis Engine Text Based that fetches reference inverter block and solar, using SHA-256.
ingestsolar-electrical-topology-analysis-engine-text-based / scripts/run_authority_slice.py · lines 1–238 of 238 · Entry point · pattern running_bridge (shared by 2 files)
- What it does
- It fetches reference inverter block and solar. Defines 11 functions or classes, including AuthoritySliceError, require, _sha256, command_response_bytes, running_bridge. Uses libraries __future__, argparse, contextlib, hashlib, json. Side effects: reads or writes files; makes network requests; 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. Domain terms in the code: solar.
- Inputs & outputs
- In: JSON file reference-inverter-block.json; command-line arguments.
- Downstream impact
- Used directly by 1 file: Test End to End Authority Slice (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 fetches bytes (`fetch_bytes`), runs browser checks (`run_browser_checks`) and runs clean wheel check (`run_clean_wheel_check`). Exercise the complete command-to-bridge-to-Studio authority slice. It accepts `--strategy`, `--skip-browser-checks` and `--skip-clean-wheel`.
- Why it matters
- Checked by Test End to End Authority Slice.
- Application
- solar-electrical-topology-analysis-engine-text-based · scripts · Python CLI
- Uses
- Build Authority Bundle (import), Local Authority Bridge (import), Validate Authority Bundle (import), Validate Inverter Block Wheel (script call), __future__, argparse, contextlib, hashlib, json, pathlib, subprocess, sys
- Used by
- imported by Test End to End Authority Slice (import)
- Produces
- AuthoritySliceError, require, command_response_bytes, running_bridge, fetch_bytes, run_browser_checks, run_clean_wheel_check, run_authority_slice, build_parser, main
- Defines here
- AuthoritySliceError, require, _sha256, command_response_bytes, running_bridge, fetch_bytes, run_browser_checks, run_clean_wheel_check, run_authority_slice, build_parser, 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_authority_slice.py:1-238 · blob 3d5eab8ea1a6c743e0fc410b7ace12c04c7dbec7 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: ingest · effects: filesystem, network, process · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
#!/usr/bin/env python3
"""Exercise the complete command-to-bridge-to-Studio authority slice."""
from __future__ import annotations
import argparse
from contextlib import contextmanager
import hashlib
import json
from pathlib import Path
import subprocess
import sys
from threading import Thread
from typing import Iterator
from urllib.parse import urljoin
from urllib.request import urlopen
try:
from scripts.build_authority_bundle import AUTHORITY_BUNDLE_PATH, canonical_json
from scripts.local_authority_bridge import (
AUTHORITY_BUNDLE_ROUTE,
STUDIO_ROUTE,
create_server,
)
from scripts.validate_authority_bundle import validate_authority_bundle_payload
except ModuleNotFoundError: # Direct execution from the scripts directory.
from build_authority_bundle import AUTHORITY_BUNDLE_PATH, canonical_json
from local_authority_bridge import (
AUTHORITY_BUNDLE_ROUTE,
STUDIO_ROUTE,
create_server,
)
from validate_authority_bundle import validate_authority_bundle_payload
ROOT = Path(__file__).resolve().parents[1]
AUTHORITY_SLICE_VERSION = "globalgrid2050.solar-dc.authority-slice.v1"
STUDIO_AUTHORITY_TEST = (
ROOT / "v10-development" / "tests" / "studio-authority.test.mjs"
)
STUDIO_EVIDENCE_TEST = (
ROOT / "v10-development" / "tests" / "studio-authority-evidence.test.mjs"
)
BROWSER_MODES = ("mode", "bundle", "geometry", "evidence")
class AuthoritySliceError(RuntimeError):
"""The end-to-end authority slice is incomplete or inconsistent."""
def require(condition: bool, message: str) -> None:
if not condition:
raise AuthoritySliceError(message)
def _sha256(data: bytes) -> str:
return "sha256:" + hashlib.sha256(data).hexdigest()
def command_response_bytes(strategy: str = "leapfrog") -> bytes:
"""Run the repository command rather than calling its implementation directly."""
completed = subprocess.run(
[
sys.executable,
"scripts/build_authority_bundle.py",
"--strategy",
strategy,
],
cwd=ROOT,
check=True,
capture_output=True,
)
require(not completed.stderr, "authority command wrote unexpected stderr")
return completed.stdout
@contextmanager
def running_bridge(*, strategy: str = "leapfrog") -> Iterator[str]:
server = create_server(host="127.0.0.1", port=0, strategy=strategy)
thread = Thread(target=server.serve_forever, daemon=True)
thread.start()
host, port = server.server_address[:2]
try:
yield f"http://{host}:{port}"
finally:
server.shutdown()
thread.join(timeout=5)
server.server_close()
def fetch_bytes(url: str) -> bytes:
with urlopen(url, timeout=15) as response:
return response.read()
def run_browser_checks() -> tuple[str, ...]:
completed_modes: list[str] = []
for mode in BROWSER_MODES:
command = (
["node", str(STUDIO_EVIDENCE_TEST)]
if mode == "evidence"
else ["node", str(STUDIO_AUTHORITY_TEST), mode]
)
subprocess.run(command, cwd=ROOT, check=True)
completed_modes.append(mode)
return tuple(completed_modes)
def run_clean_wheel_check() -> None:
subprocess.run(
[sys.executable, "scripts/validate_inverter_block_wheel.py"],
cwd=ROOT,
check=True,
)
def run_authority_slice(
*,
strategy: str = "leapfrog",
browser_checks: bool = True,
clean_wheel: bool = True,
) -> dict[str, object]:
"""Run one complete reference authority journey and return its evidence summary."""
require(strategy == "leapfrog", "the committed reference slice is leapfrog")
command_bytes = command_response_bytes(strategy)
committed_bytes = AUTHORITY_BUNDLE_PATH.read_bytes()
require(
command_bytes == committed_bytes,
"command response differs from the committed authority bundle",
)
with running_bridge(strategy=strategy) as base:
bridge_bundle_url = base + AUTHORITY_BUNDLE_ROUTE
resolved_bundle_url = urljoin(
base + STUDIO_ROUTE,
"../../authority-bundles/reference-inverter-block.json",
)
require(
resolved_bundle_url == bridge_bundle_url,
"Studio relative authority-bundle URL does not resolve to the bridge",
)
bridge_bytes = fetch_bytes(bridge_bundle_url)
studio_html = fetch_bytes(base + STUDIO_ROUTE)
authority_view = fetch_bytes(
base + "/v10-development/authority/authority-view.js"
)
authority_evidence = fetch_bytes(
base + "/v10-development/authority/authority-evidence.js"
)
require(
bridge_bytes == command_bytes,
"bridge response differs from the command response",
)
require(
b"SOLAR DC TOPOLOGY STUDIO" in studio_html,
"Studio shell was not served by the bridge",
)
require(
b"AUTHORITY_BUNDLE_URL" in authority_view,
"Studio authority projection does not declare its bundle source",
)
require(
b"authorityEvidence" in authority_evidence,
"Studio evidence projection was not served by the bridge",
)
payload = json.loads(bridge_bytes)
validation = validate_authority_bundle_payload(payload)
require(validation["pass"] is True, "authority bundle validation did not pass")
completed_browser_modes: tuple[str, ...] = ()
if browser_checks:
completed_browser_modes = run_browser_checks()
if clean_wheel:
run_clean_wheel_check()
boundary = payload["inverter_block"]["product_boundary"]
return {
"schema_version": AUTHORITY_SLICE_VERSION,
"pass": True,
"strategy": strategy,
"response_hash": payload["response_hash"],
"response_bytes_sha256": _sha256(bridge_bytes),
"command_equals_bridge": command_bytes == bridge_bytes,
"bridge_equals_committed_bundle": bridge_bytes == committed_bytes,
"studio_route": STUDIO_ROUTE,
"authority_bundle_route": AUTHORITY_BUNDLE_ROUTE,
"module_count": boundary["module_count"],
"string_count": boundary["string_count"],
"modules_per_string": boundary["modules_per_string"],
"dc_nameplate_power_kwp": boundary["dc_nameplate_power_kwp"],
"inverter_apparent_power_kva": boundary["inverter_apparent_power_kva"],
"browser_modes": list(completed_browser_modes),
"clean_wheel": clean_wheel,
"equipment_evidence_state": payload["inverter_block"][
"equipment_evidence"
]["state"],
}
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description="Run the complete authoritative reference-block slice.",
)
parser.add_argument(
"--strategy",
choices=("leapfrog",),
default="leapfrog",
)
parser.add_argument("--skip-browser-checks", action="store_true")
parser.add_argument("--skip-clean-wheel", action="store_true")
parser.add_argument(
"--version",
action="version",
version=AUTHORITY_SLICE_VERSION,
)
return parser
def main(argv: list[str] | None = None) -> int:
args = build_parser().parse_args(argv)
try:
summary = run_authority_slice(
strategy=args.strategy,
browser_checks=not args.skip_browser_checks,
clean_wheel=not args.skip_clean_wheel,
)
except (OSError, subprocess.CalledProcessError, json.JSONDecodeError, AuthoritySliceError) as exc:
raise SystemExit(f"authority slice failed: {exc}") from exc
print(canonical_json(summary))
return 0
if __name__ == "__main__":
raise SystemExit(main())Run Microbuild
A Python command-line tool in the scripts folder of Solar Electrical Topology Analysis Engine Text Based that works with active command (`active_command`).
othersolar-electrical-topology-analysis-engine-text-based / scripts/run_microbuild.py · lines 1–108 of 108 · Entry point · pattern execute (shared by 7 files)
- What it does
- Defines 6 functions or classes, including UnknownTestIdentifier, command_for_test, active_test_id, active_command, execute. Uses libraries __future__, argparse, json, pathlib, subprocess. 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: command-line arguments.
- Downstream impact
- Used directly by 4 files: Test Microbuild Runner (solar-electrical-topology-analysis-engine-text-based); Test Microbuild Workflow (solar-electrical-topology-analysis-engine-text-based); Test Ts005 Handoff (solar-electrical-topology-analysis-engine-text-based); Microbuild Worker Workflow (solar-electrical-topology-analysis-engine-text-based). Reached from 1 other entry point, including Build 025 Small Gates Workflow (solar-electrical-topology-analysis-engine-text-based).
- What it achieves
- It is built from the unknown test identifier class (`UnknownTestIdentifier`), the command for test helper (`command_for_test`) and the active test id helper (`active_test_id`). Select and optionally execute one repository-controlled microbuild test. It accepts `--plan`, `--test-id` and `--execute`.
- Why it matters
- Run by Microbuild Worker Workflow. Checked by 3 tests, including Test Microbuild Runner.
- Application
- solar-electrical-topology-analysis-engine-text-based · scripts · Python CLI
- Uses
- Check Microbuild Plan (import), Validate Inverter Block Wheel (script call), Run Ts004 Integration (script call), Studio Authority Test (script call), Studio Authority Evidence Test (script call), Test Microbuild Plan (script call), Test Microbuild Runner (script call), Test Microbuild Workflow (script call), and 8 more, __future__, argparse, json, pathlib, subprocess, sys, typing
- Used by
- imported by Test Microbuild Runner (import), run by Test Microbuild Workflow (script call), imported by Test Ts005 Handoff (import), run by Microbuild Worker Workflow (workflow run)
- Produces
- UnknownTestIdentifier, command_for_test, active_test_id, active_command, execute, main
- Defines here
- UnknownTestIdentifier, command_for_test, active_test_id, active_command, execute, 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_microbuild.py:1-108 · blob 5b49fb8019700415bc3ebfa9e32fc638e5641e34 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: ingest · effects: filesystem, process · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
#!/usr/bin/env python3
"""Select and optionally execute one repository-controlled microbuild test."""
from __future__ import annotations
import argparse
import json
from pathlib import Path
import subprocess
import sys
from typing import Sequence
try:
from scripts.check_microbuild_plan import (
DEFAULT_PLAN_PATH,
load_plan,
validate_plan,
)
except ModuleNotFoundError: # Direct execution from the scripts directory.
from check_microbuild_plan import DEFAULT_PLAN_PATH, load_plan, validate_plan
ROOT = Path(__file__).resolve().parents[1]
# Manifest data may select these identifiers, but may never supply commands.
TEST_COMMANDS: dict[str, tuple[str, ...]] = {
"manifest_contract": (sys.executable, "-m", "pytest", "-q", "tests/test_microbuild_plan.py"),
"runner_contract": (sys.executable, "-m", "pytest", "-q", "tests/test_microbuild_runner.py"),
"workflow_contract": (sys.executable, "-m", "pytest", "-q", "tests/test_microbuild_workflow.py"),
"clean_wheel_inverter_block": (sys.executable, "scripts/validate_inverter_block_wheel.py"),
"microbuild_evidence": (sys.executable, "-m", "pytest", "-q", "tests/test_microbuild_evidence.py"),
"advancement_preview": (sys.executable, "-m", "pytest", "-q", "tests/test_microbuild_advancement.py", "-k", "preview"),
"advancement_refusal": (sys.executable, "-m", "pytest", "-q", "tests/test_microbuild_advancement.py", "-k", "refus"),
"ts004_integration": (sys.executable, "scripts/run_ts004_integration.py"),
"ts004_programme_projection": (sys.executable, "-m", "pytest", "-q", "tests/test_programme_state.py"),
"ts005_handoff": (sys.executable, "-m", "pytest", "-q", "tests/test_ts005_handoff.py"),
"reference_block_command": (sys.executable, "-m", "pytest", "-q", "tests/test_reference_block_command.py", "-k", "reference_block"),
"command_contract": (sys.executable, "-m", "pytest", "-q", "tests/test_reference_block_command.py", "-k", "contract"),
"authority_bundle": (sys.executable, "-m", "pytest", "-q", "tests/test_authority_bundle.py", "-k", "regeneration"),
"bundle_schema": (sys.executable, "-m", "pytest", "-q", "tests/test_authority_bundle.py", "-k", "schema"),
"studio_mode_separation": ("node", "v10-development/tests/studio-authority.test.mjs", "mode"),
"authority_bundle_render": ("node", "v10-development/tests/studio-authority.test.mjs", "bundle"),
"authority_geometry_render": ("node", "v10-development/tests/studio-authority.test.mjs", "geometry"),
"authority_evidence_render": ("node", "v10-development/tests/studio-authority-evidence.test.mjs"),
"local_authority_bridge": (sys.executable, "-m", "pytest", "-q", "tests/test_local_authority_bridge.py"),
"end_to_end_authority_slice": (sys.executable, "-m", "pytest", "-q", "tests/test_end_to_end_authority_slice.py"),
}
class UnknownTestIdentifier(ValueError):
"""The manifest requested a test outside the repository allowlist."""
def command_for_test(test_id: str) -> tuple[str, ...]:
try:
return TEST_COMMANDS[test_id]
except KeyError as exc:
raise UnknownTestIdentifier(f"unknown microbuild test id: {test_id}") from exc
def active_test_id(plan_path: Path = DEFAULT_PLAN_PATH) -> str | None:
summary = validate_plan(load_plan(plan_path))
test_id = summary["active_test_id"]
if test_id is None:
return None
if not isinstance(test_id, str):
raise TypeError("active test identifier must be text or null")
return test_id
def active_command(plan_path: Path = DEFAULT_PLAN_PATH) -> tuple[str, ...]:
test_id = active_test_id(plan_path)
return () if test_id is None else command_for_test(test_id)
def execute(command: Sequence[str]) -> int:
if not command:
return 0
completed = subprocess.run(tuple(command), cwd=ROOT, check=False)
return completed.returncode
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--plan", type=Path, default=DEFAULT_PLAN_PATH)
parser.add_argument("--test-id")
parser.add_argument("--execute", action="store_true")
args = parser.parse_args()
selected = args.test_id or active_test_id(args.plan)
if selected is None:
payload = {
"programme_status": "completed",
"test_id": None,
"command": [],
}
print(json.dumps(payload, sort_keys=True))
return 0
command = command_for_test(selected)
if not args.execute:
print(json.dumps({"test_id": selected, "command": list(command)}, sort_keys=True))
return 0
return execute(command)
if __name__ == "__main__":
raise SystemExit(main())Run Ts004 Integration
A Python command-line tool in the scripts folder of Solar Electrical Topology Analysis Engine Text Based that reads validation. It runs gate (`run_gate`).
ingestsolar-electrical-topology-analysis-engine-text-based / scripts/run_ts004_integration.py · lines 1–85 of 85 · Entry point · pattern run_gate (shared by 2 files)
- What it does
- It loads validation. Defines _print_declared_suite_failures, run_gate, main. Uses libraries __future__, json, pathlib, subprocess, sys. 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 1 file: Run Microbuild (solar-electrical-topology-analysis-engine-text-based). Reached from 5 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); Test Microbuild Runner (solar-electrical-topology-analysis-engine-text-based).
- What it achieves
- Run the complete TS-004 integration envelope from repository authority.
- Why it matters
- Run by Run Microbuild.
- Application
- solar-electrical-topology-analysis-engine-text-based · scripts · Python CLI
- Uses
- Check Capsule Links (script call), Sync Programme State (script call), Run V10 Validation (script call), Validate Clean Wheel (script call), Validate Inverter Block Wheel (script call), __future__, json, pathlib, subprocess, sys
- Used by
- run by Run Microbuild (script call)
- Produces
- run_gate, main
- Defines here
- _print_declared_suite_failures, run_gate, 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_ts004_integration.py:1-85 · blob 03dc1a383e55738d1feec3993e5832b316e00d27 · GitHub at these lines
- State
- achieves: comment · context: readme_derived · stage: ingest · effects: filesystem, process · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
#!/usr/bin/env python3
"""Run the complete TS-004 integration envelope from repository authority."""
from __future__ import annotations
import json
from pathlib import Path
import subprocess
import sys
ROOT = Path(__file__).resolve().parents[1]
TS004_INTEGRATION_SCHEMA_VERSION = (
"globalgrid2050.solar-dc.ts004-integration.v1"
)
V10_RESULT = (
ROOT
/ "v10-development"
/ "recovery"
/ "validation"
/ "V10_VALIDATION_LATEST.json"
)
GATES: tuple[tuple[str, tuple[str, ...]], ...] = (
(
"capsule_links",
(sys.executable, "scripts/check_capsule_links.py", "--check"),
),
(
"programme_state",
(sys.executable, "scripts/sync_programme_state.py", "--check"),
),
(
"declared_suites",
(sys.executable, "scripts/run_v10_validation.py"),
),
(
"established_clean_wheel",
(sys.executable, "scripts/validate_clean_wheel.py"),
),
(
"inverter_block_clean_wheel",
(sys.executable, "scripts/validate_inverter_block_wheel.py"),
),
)
def _print_declared_suite_failures() -> None:
if not V10_RESULT.is_file():
print("declared-suite receipt was not written", file=sys.stderr)
return
payload = json.loads(V10_RESULT.read_text(encoding="utf-8"))
for result in payload.get("results", []):
if result.get("pass"):
continue
print(
f"DECLARED SUITE FAILURE: {result.get('name')} "
f"return_code={result.get('return_code')}",
file=sys.stderr,
)
print(str(result.get("output", "")).rstrip(), file=sys.stderr)
def run_gate(name: str, command: tuple[str, ...]) -> dict[str, object]:
completed = subprocess.run(command, cwd=ROOT, check=False)
if completed.returncode != 0:
if name == "declared_suites":
_print_declared_suite_failures()
raise RuntimeError(f"TS-004 integration gate failed: {name}")
return {"name": name, "pass": True}
def main() -> int:
results = [run_gate(name, command) for name, command in GATES]
payload = {
"schema_version": TS004_INTEGRATION_SCHEMA_VERSION,
"pass": True,
"gates": results,
}
print(json.dumps(payload, sort_keys=True, separators=(",", ":")))
return 0
if __name__ == "__main__":
raise SystemExit(main())