In this section
- Test Authority Bundle test · solar-electrical-topology-analysis-engine-text-based / tests/test_authority_bundle.py lines 1–168
- Test Batch 011 013 test · solar-electrical-topology-analysis-engine-text-based / tests/test_batch_011_013.py lines 1–150
- Test Build023 Topology Invariants test · solar-electrical-topology-analysis-engine-text-based / tests/test_build023_topology_invariants.py lines 1–188
- Test Build023 Topology Receipt test · solar-electrical-topology-analysis-engine-text-based / tests/test_build023_topology_receipt.py lines 1–69
- Test Build024 Kernel Authority test · solar-electrical-topology-analysis-engine-text-based / tests/test_build024_kernel_authority.py lines 1–113
Test Authority Bundle
A test in the tests folder of Solar Electrical Topology Analysis Engine Text Based that checks Build Authority Bundle and Validate Authority Bundle, using SHA-256.
testsolar-electrical-topology-analysis-engine-text-based / tests/test_authority_bundle.py · lines 1–168 of 168 · Entry point
- What it does
- It tests its inputs. Defines 9 functions or classes, including test_authority_bundle_regeneration_matches_committed_file_exactly, test_authority_bundle_regeneration_candidate_matches_generator, test_authority_bundle_regeneration_binds_receipts_and_hash, test_bundle_schema_accepts_canonical_reference_authority, test_bundle_schema_rejects_missing_authority_hashes. Uses libraries __future__, copy, 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: JSON file reference-inverter-block.json.
- Downstream impact
- Used directly by 2 files: Run Microbuild (solar-electrical-topology-analysis-engine-text-based); Build 025 Small Gates Workflow (solar-electrical-topology-analysis-engine-text-based). Reached from 4 other entry points, including Microbuild Worker Workflow (solar-electrical-topology-analysis-engine-text-based); Test Microbuild Runner (solar-electrical-topology-analysis-engine-text-based); Test Microbuild Workflow (solar-electrical-topology-analysis-engine-text-based).
- What it achieves
- Defines `test_authority_bundle_regeneration_matches_committed_file_exactly`, `test_authority_bundle_regeneration_candidate_matches_generator`, `test_authority_bundle_regeneration_binds_receipts_and_hash` and 6 more.
- Why it matters
- Run by Run Microbuild and Build 025 Small Gates Workflow.
- Application
- solar-electrical-topology-analysis-engine-text-based · tests · test
- Uses
- Build Authority Bundle (import), Validate Authority Bundle (import), __future__, copy, hashlib, json, pathlib, pytest, solar_topology
- Used by
- run by Run Microbuild (script call), run by Build 025 Small Gates Workflow (workflow run)
- Produces
- test_authority_bundle_regeneration_matches_committed_file_exactly, test_authority_bundle_regeneration_candidate_matches_generator, test_authority_bundle_regeneration_binds_receipts_and_hash, test_bundle_schema_accepts_canonical_reference_authority, test_bundle_schema_rejects_missing_authority_hashes, test_bundle_schema_rejects_invented_input_evidence, test_bundle_schema_rejects_changed_product_boundary_arithmetic, test_bundle_schema_rejects_tampered_response_hash, test_bundle_schema_rejects_broken_child_hash_binding
- Defines here
- test_authority_bundle_regeneration_matches_committed_file_exactly, test_authority_bundle_regeneration_candidate_matches_generator, test_authority_bundle_regeneration_binds_receipts_and_hash, test_bundle_schema_accepts_canonical_reference_authority, test_bundle_schema_rejects_missing_authority_hashes, test_bundle_schema_rejects_invented_input_evidence, test_bundle_schema_rejects_changed_product_boundary_arithmetic, test_bundle_schema_rejects_tampered_response_hash, test_bundle_schema_rejects_broken_child_hash_binding
- 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 tests/test_authority_bundle.py:1-168 · blob e1259ba9bd9567520d2743d8c2fef52bffc1ddb6 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: ingest · effects: filesystem · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
from __future__ import annotations
from copy import deepcopy
import hashlib
import json
from pathlib import Path
import pytest
import solar_topology as topology
from scripts.build_authority_bundle import (
AUTHORITY_BUNDLE_PATH,
authority_response_json,
authority_response_payload,
canonical_json,
)
from scripts.validate_authority_bundle import (
AUTHORITY_RESPONSE_SCHEMA_PATH,
AuthorityBundleValidationError,
load_json_object,
validate_authority_bundle_file,
validate_authority_bundle_payload,
)
ROOT = Path(__file__).resolve().parents[1]
CANDIDATE_PATH = (
ROOT / ".microbuild" / "candidates" / "reference-inverter-block.json"
)
def test_authority_bundle_regeneration_matches_committed_file_exactly() -> None:
committed = AUTHORITY_BUNDLE_PATH.read_text(encoding="utf-8")
expected = authority_response_json() + "\n"
assert committed == expected
def test_authority_bundle_regeneration_candidate_matches_generator() -> None:
assert CANDIDATE_PATH.is_file()
assert CANDIDATE_PATH.read_text(encoding="utf-8") == (
authority_response_json() + "\n"
)
def test_authority_bundle_regeneration_binds_receipts_and_hash() -> None:
payload = authority_response_payload()
authority = topology.build_reference_inverter_block()
basis = dict(payload)
response_hash = basis.pop("response_hash")
recomputed = "sha256:" + hashlib.sha256(
canonical_json(basis).encode("utf-8")
).hexdigest()
assert response_hash == recomputed
assert payload["strategy"] == "leapfrog"
block = payload["inverter_block"]
build025 = payload["build025"]
binding = block["table_receipts"][0]
child = authority.table_receipts[0]
assert binding["build025_receipt_hash"] == build025["receipt_hash"]
assert binding["build025_receipt_hash"] == child.receipt_hash
assert binding["geometry_hash"] == build025["geometry"]["geometry_hash"]
assert binding["geometry_hash"] == child.geometry.geometry_hash
assert binding["routing_hash"] == child.routing.routing_hash
assert build025["routing"]["table_id"] == child.routing.table_id
assert json.loads(authority_response_json()) == payload
def test_bundle_schema_accepts_canonical_reference_authority() -> None:
schema = load_json_object(AUTHORITY_RESPONSE_SCHEMA_PATH)
summary = validate_authority_bundle_file()
assert schema["$schema"] == "https://json-schema.org/draft/2020-12/schema"
assert schema["properties"]["schema_version"]["const"] == (
"globalgrid2050.solar-dc.authority-response.v1"
)
assert summary["pass"] is True
assert summary["strategy"] == "leapfrog"
assert summary["module_count"] == 720
assert summary["string_count"] == 24
assert summary["modules_per_string"] == 30
assert summary["dc_nameplate_power_kwp"] == 475.2
assert summary["inverter_apparent_power_kva"] == 352.0
assert summary["evidence_state"] == "incomplete_evidence"
assert summary["missing_evidence_count"] == 47
@pytest.mark.parametrize(
"path",
(
("response_hash",),
("inverter_block", "receipt_hash"),
("build025", "receipt_hash"),
("inverter_block", "table_receipts", 0, "routing_hash"),
),
)
def test_bundle_schema_rejects_missing_authority_hashes(
path: tuple[str | int, ...],
) -> None:
payload = deepcopy(authority_response_payload())
target: object = payload
for part in path[:-1]:
target = target[part] # type: ignore[index]
del target[path[-1]] # type: ignore[index]
with pytest.raises(AuthorityBundleValidationError, match="missing required fields"):
validate_authority_bundle_payload(payload)
@pytest.mark.parametrize(
("field", "invented"),
(
("mppt_count", 12),
("mppt_count_verification_state", "verified"),
("mppt_mapping_verification_states", ["verified"]),
("internal_dc_topology", "common_bus"),
("reverse_current_blocking", "present"),
("pce_backfeed_current_a", 1.0),
("routing_fixture_mppt_labels_are_equipment_evidence", True),
),
)
def test_bundle_schema_rejects_invented_input_evidence(
field: str,
invented: object,
) -> None:
payload = deepcopy(authority_response_payload())
payload["inverter_block"]["input_authority"][field] = invented
with pytest.raises(AuthorityBundleValidationError):
validate_authority_bundle_payload(payload)
def test_bundle_schema_rejects_changed_product_boundary_arithmetic() -> None:
payload = deepcopy(authority_response_payload())
payload["inverter_block"]["product_boundary"][
"dc_nameplate_power_kwp"
] = 475.3
with pytest.raises(
AuthorityBundleValidationError,
match="dc_nameplate_power_kwp must equal 475.2",
):
validate_authority_bundle_payload(payload)
def test_bundle_schema_rejects_tampered_response_hash() -> None:
payload = deepcopy(authority_response_payload())
payload["response_hash"] = "sha256:" + "0" * 64
with pytest.raises(AuthorityBundleValidationError, match="response_hash"):
validate_authority_bundle_payload(payload)
def test_bundle_schema_rejects_broken_child_hash_binding() -> None:
payload = deepcopy(authority_response_payload())
payload["inverter_block"]["table_receipts"][0]["routing_hash"] = (
"sha256:" + "1" * 64
)
basis = dict(payload)
basis.pop("response_hash")
payload["response_hash"] = "sha256:" + hashlib.sha256(
canonical_json(basis).encode("utf-8")
).hexdigest()
with pytest.raises(AuthorityBundleValidationError, match="routing hash binding"):
validate_authority_bundle_payload(payload)Test Batch 011 013
A test in the tests folder of Solar Electrical Topology Analysis Engine Text Based that uses SHA-256.
testsolar-electrical-topology-analysis-engine-text-based / tests/test_batch_011_013.py · lines 1–150 of 150 · Entry point · pattern _rows (shared by 11 files)
- What it does
- It tests its inputs. Defines 8 functions or classes, including _rows, _public_source, test_duckdb_round_trip_and_parquet_are_deterministic, test_duckdb_primary_key_rejects_duplicate_rows, test_evidence_register_requires_strong_evidence_for_satisfied_status. Uses libraries dataclasses, duckdb, pytest, solar_topology.cartridges, solar_topology.circuit. Side effects: uses storage (browser storage, DuckDB or Parquet).
- 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: Parquet file segments.parquet; DuckDB queries.
- Downstream impact
- Used directly by 1 file: Build 025 Small Gates Workflow (solar-electrical-topology-analysis-engine-text-based).
- What it achieves
- Defines `test_duckdb_round_trip_and_parquet_are_deterministic`, `test_duckdb_primary_key_rejects_duplicate_rows`, `test_evidence_register_requires_strong_evidence_for_satisfied_status` and 3 more.
- Why it matters
- Run by Build 025 Small Gates Workflow.
- Application
- solar-electrical-topology-analysis-engine-text-based · tests · test
- Uses
- dataclasses, duckdb, pytest, solar_topology.cartridges, solar_topology.circuit, solar_topology.duckdb_segments, solar_topology.evidence, solar_topology.evidence_boundary
- Used by
- run by Build 025 Small Gates Workflow (workflow run)
- Produces
- test_duckdb_round_trip_and_parquet_are_deterministic, test_duckdb_primary_key_rejects_duplicate_rows, test_evidence_register_requires_strong_evidence_for_satisfied_status, test_public_evidence_register_blocks_restricted_source, test_geometry_receipt_is_deterministic_and_segment_based, test_geometry_receipt_rejects_mixed_strings_and_index_gaps
- Defines here
- _rows, _public_source, test_duckdb_round_trip_and_parquet_are_deterministic, test_duckdb_primary_key_rejects_duplicate_rows, test_evidence_register_requires_strong_evidence_for_satisfied_status, test_public_evidence_register_blocks_restricted_source, test_geometry_receipt_is_deterministic_and_segment_based, test_geometry_receipt_rejects_mixed_strings_and_index_gaps
- 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 tests/test_batch_011_013.py:1-150 · blob 3e664254374110c29faa929c2bd44ddca7720010 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: ingest · effects: storage · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
from dataclasses import replace
import duckdb
import pytest
from solar_topology.cartridges import SequentialCartridge
from solar_topology.circuit import EvidenceClass
from solar_topology.duckdb_segments import (
export_segment_parquet,
read_segment_parquet,
read_segment_rows,
segment_rows_hash,
write_segment_rows,
)
from solar_topology.evidence import canonical_evidence_descriptor
from solar_topology.evidence_boundary import (
EvidenceSource,
PublicationPermission,
RightsStatus,
)
from solar_topology.evidence_register import (
EvidenceMaturity,
EvidenceRegisterEntry,
RequirementStatus,
build_evidence_register,
evidence_register_hash,
)
from solar_topology.geometry_receipts import (
calculate_geometry_receipt,
geometry_receipt_hash,
)
from solar_topology.identifiers import EntityLevel, project_id
from solar_topology.segments import TopologyInputs, archetype_strings
def _rows():
inputs = TopologyInputs(
modules_per_string=6,
inverter_count=1,
total_site_string_count=24,
positive_factory_lead_m=1.4,
negative_factory_lead_m=1.4,
)
definition = archetype_strings(inputs)[0]
return SequentialCartridge().build_segments(inputs, definition)
def _public_source(source_id="public-layout"):
return EvidenceSource(
source_id=source_id,
descriptor=canonical_evidence_descriptor(EvidenceClass.PUBLIC_OBSERVATION),
rights_status=RightsStatus.PUBLIC,
publication_permission=PublicationPermission.PUBLIC,
)
def test_duckdb_round_trip_and_parquet_are_deterministic(tmp_path):
rows = _rows()
connection = duckdb.connect(":memory:")
assert write_segment_rows(connection, reversed(rows)) == len(rows)
restored = read_segment_rows(connection)
assert restored == tuple(rows)
assert segment_rows_hash(restored) == segment_rows_hash(rows)
path = export_segment_parquet(connection, tmp_path / "segments.parquet")
from_parquet = read_segment_parquet(path)
assert from_parquet == tuple(rows)
assert segment_rows_hash(from_parquet) == segment_rows_hash(rows)
def test_duckdb_primary_key_rejects_duplicate_rows():
rows = _rows()
connection = duckdb.connect(":memory:")
write_segment_rows(connection, rows)
with pytest.raises(duckdb.ConstraintException):
write_segment_rows(connection, rows)
def test_evidence_register_requires_strong_evidence_for_satisfied_status():
project = project_id("public-study")
site = project.child(EntityLevel.SITE, "site-one")
source = _public_source()
entry = EvidenceRegisterEntry(
requirement_id="ER-E-001",
subject_identifier=site,
requirement_text="Record the publicly observable site topology.",
source_ids=(source.source_id,),
maturity=EvidenceMaturity.OBSERVED,
status=RequirementStatus.SATISFIED,
)
register = build_evidence_register(
"register-one", [entry], {source.source_id: source}, public_export=True
)
assert evidence_register_hash(register).startswith("sha256:")
with pytest.raises(ValueError, match="stronger evidence"):
replace(entry, maturity=EvidenceMaturity.ASSUMED)
def test_public_evidence_register_blocks_restricted_source():
project = project_id("public-study")
site = project.child(EntityLevel.SITE, "site-one")
restricted = EvidenceSource(
source_id="nda-sld",
descriptor=canonical_evidence_descriptor(EvidenceClass.EXTERNAL_REFERENCE),
rights_status=RightsStatus.CONFIDENTIAL_NDA,
publication_permission=PublicationPermission.INTERNAL_ONLY,
)
entry = EvidenceRegisterEntry(
requirement_id="ER-E-002",
subject_identifier=site,
requirement_text="Verify internal single-line diagram details.",
source_ids=(restricted.source_id,),
maturity=EvidenceMaturity.OBSERVED,
status=RequirementStatus.PARTIAL,
remaining_risk="Not independently supportable from public evidence.",
)
with pytest.raises(PermissionError, match="restricted evidence"):
build_evidence_register(
"public-register",
[entry],
{restricted.source_id: restricted},
public_export=True,
)
def test_geometry_receipt_is_deterministic_and_segment_based():
rows = _rows()
first = calculate_geometry_receipt(rows)
second = calculate_geometry_receipt(reversed(rows))
assert first == second
assert geometry_receipt_hash(first) == geometry_receipt_hash(second)
expected = sum(
row.conductor_length_m * row.separation_mm / 1000 * row.loop_parameter_weight
for row in rows
)
assert first.loop_area_m2 == pytest.approx(expected)
assert 0 <= first.paired_route_fraction <= 1
def test_geometry_receipt_rejects_mixed_strings_and_index_gaps():
rows = list(_rows())
with pytest.raises(ValueError, match="one run, topology and string"):
calculate_geometry_receipt(
[rows[0], replace(rows[1], string_id="different-string")]
)
with pytest.raises(ValueError, match="contiguous"):
calculate_geometry_receipt(
[rows[0], replace(rows[1], segment_index=3)]
)Test Build023 Topology Invariants
A test in the tests folder of Solar Electrical Topology Analysis Engine Text Based.
testsolar-electrical-topology-analysis-engine-text-based / tests/test_build023_topology_invariants.py · lines 1–188 of 188 · Entry point · pattern _terminal (shared by 2 files)
- What it does
- It tests its inputs. Defines 9 functions or classes, including _terminal, _object, _valid_path, test_valid_model_requires_independent_validation_and_complete_traversal, test_payload_and_traversal_do_not_trust_input_tuple_order. Uses libraries __future__, solar_topology.circuit, solar_topology.circuit_traversal, solar_topology.circuit_validation.
- Why it exists in the grid workflow
- Domain stage sub33kv_design (path word 'topology'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary.
- Downstream impact
- Used directly by 1 file: Build 025 Small Gates Workflow (solar-electrical-topology-analysis-engine-text-based).
- What it achieves
- Defines `test_valid_model_requires_independent_validation_and_complete_traversal`, `test_payload_and_traversal_do_not_trust_input_tuple_order`, `test_duplicate_identifiers_are_blocking` and 3 more.
- Why it matters
- Run by Build 025 Small Gates Workflow.
- Application
- solar-electrical-topology-analysis-engine-text-based · tests · test
- Uses
- __future__, solar_topology.circuit, solar_topology.circuit_traversal, solar_topology.circuit_validation
- Used by
- run by Build 025 Small Gates Workflow (workflow run)
- Produces
- test_valid_model_requires_independent_validation_and_complete_traversal, test_payload_and_traversal_do_not_trust_input_tuple_order, test_duplicate_identifiers_are_blocking, test_missing_endpoint_blocks_traversal_before_graph_walk, test_branch_and_disconnected_island_are_explicit_failures, test_segment_reference_cannot_substitute_for_terminal_connectivity
- Defines here
- _terminal, _object, _valid_path, test_valid_model_requires_independent_validation_and_complete_traversal, test_payload_and_traversal_do_not_trust_input_tuple_order, test_duplicate_identifiers_are_blocking, test_missing_endpoint_blocks_traversal_before_graph_walk, test_branch_and_disconnected_island_are_explicit_failures, test_segment_reference_cannot_substitute_for_terminal_connectivity
- 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 tests/test_build023_topology_invariants.py:1-188 · blob bfb5eb3e92520591cfb5e1ca4374db3d6d7269e1 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
from __future__ import annotations
from solar_topology.circuit import (
CircuitModel,
Connection,
ConnectionKind,
EvidenceClass,
ObjectKind,
PhysicalObject,
Terminal,
TerminalPolarity,
canonical_circuit_json,
)
from solar_topology.circuit_traversal import verify_ordered_circuit
from solar_topology.circuit_validation import validate_circuit_model
def _terminal(object_id: str, suffix: str, polarity: TerminalPolarity) -> Terminal:
return Terminal(
terminal_id=f"{object_id}:{suffix}",
object_id=object_id,
polarity=polarity,
max_connections=2,
evidence_class=EvidenceClass.USER_CREATED,
)
def _object(object_id: str, left: Terminal, right: Terminal) -> PhysicalObject:
return PhysicalObject(
object_id=object_id,
kind=ObjectKind.MODULE,
terminals=(left, right),
evidence_class=EvidenceClass.USER_CREATED,
)
def _valid_path() -> CircuitModel:
a_left = _terminal("a", "left", TerminalPolarity.POSITIVE)
a_right = _terminal("a", "right", TerminalPolarity.NEGATIVE)
b_left = _terminal("b", "left", TerminalPolarity.POSITIVE)
b_right = _terminal("b", "right", TerminalPolarity.NEGATIVE)
return CircuitModel(
model_id="build023-path",
objects=(
_object("a", a_left, a_right),
_object("b", b_left, b_right),
),
connections=(
Connection(
connection_id="c1",
from_terminal_id=a_left.terminal_id,
to_terminal_id=a_right.terminal_id,
kind=ConnectionKind.INTERNAL,
segment_id="segment-a",
evidence_class=EvidenceClass.USER_CREATED,
),
Connection(
connection_id="c2",
from_terminal_id=a_right.terminal_id,
to_terminal_id=b_left.terminal_id,
evidence_class=EvidenceClass.USER_CREATED,
),
Connection(
connection_id="c3",
from_terminal_id=b_left.terminal_id,
to_terminal_id=b_right.terminal_id,
kind=ConnectionKind.INTERNAL,
segment_id="segment-b",
evidence_class=EvidenceClass.USER_CREATED,
),
),
)
def test_valid_model_requires_independent_validation_and_complete_traversal() -> None:
model = _valid_path()
validation = validate_circuit_model(model)
assert validation.valid, validation.issues
traversal = verify_ordered_circuit(
model,
"a:left",
"b:right",
expected_segment_ids=("segment-a", "segment-b"),
)
assert traversal.valid, traversal.issues
assert traversal.ordered_terminal_ids == (
"a:left",
"a:right",
"b:left",
"b:right",
)
assert traversal.ordered_connection_ids == ("c1", "c2", "c3")
def test_payload_and_traversal_do_not_trust_input_tuple_order() -> None:
model = _valid_path()
reordered = CircuitModel(
model_id=model.model_id,
objects=tuple(reversed(model.objects)),
connections=tuple(reversed(model.connections)),
)
assert canonical_circuit_json(model) == canonical_circuit_json(reordered)
traversal = verify_ordered_circuit(reordered, "a:left", "b:right")
assert traversal.valid
assert traversal.ordered_connection_ids == ("c1", "c2", "c3")
def test_duplicate_identifiers_are_blocking() -> None:
model = _valid_path()
duplicate = CircuitModel(
model_id=model.model_id,
objects=model.objects + (model.objects[0],),
connections=model.connections,
)
result = validate_circuit_model(duplicate)
assert not result.valid
assert "DUPLICATE_OBJECT_ID" in result.error_codes
assert "DUPLICATE_TERMINAL_ID" in result.error_codes
def test_missing_endpoint_blocks_traversal_before_graph_walk() -> None:
model = _valid_path()
broken = CircuitModel(
model_id=model.model_id,
objects=model.objects,
connections=model.connections
+ (
Connection(
connection_id="missing-endpoint",
from_terminal_id="b:right",
to_terminal_id="ghost:terminal",
),
),
)
validation = validate_circuit_model(broken)
assert not validation.valid
traversal = verify_ordered_circuit(broken, "a:left", "b:right")
assert traversal.error_codes == ("CIRCUIT_VALIDATION_FAILED",)
def test_branch_and_disconnected_island_are_explicit_failures() -> None:
model = _valid_path()
c_left = _terminal("c", "left", TerminalPolarity.POSITIVE)
c_right = _terminal("c", "right", TerminalPolarity.NEGATIVE)
branched = CircuitModel(
model_id=model.model_id,
objects=model.objects + (_object("c", c_left, c_right),),
connections=model.connections
+ (
Connection(
connection_id="branch",
from_terminal_id="a:right",
to_terminal_id="c:left",
),
Connection(
connection_id="c-internal",
from_terminal_id="c:left",
to_terminal_id="c:right",
kind=ConnectionKind.INTERNAL,
segment_id="segment-c",
),
),
)
traversal = verify_ordered_circuit(branched, "a:left", "b:right")
assert not traversal.valid
assert "CIRCUIT_VALIDATION_FAILED" in traversal.error_codes or "BRANCH_DETECTED" in traversal.error_codes
def test_segment_reference_cannot_substitute_for_terminal_connectivity() -> None:
model = _valid_path()
bad = CircuitModel(
model_id=model.model_id,
objects=model.objects,
connections=(
Connection(
connection_id="c1",
from_terminal_id="a:left",
to_terminal_id="a:right",
kind=ConnectionKind.ELECTRICAL,
segment_id="segment-a",
),
*model.connections[1:],
),
)
traversal = verify_ordered_circuit(bad, "a:left", "b:right")
assert not traversal.valid
assert "SEGMENT_REFERENCE_NOT_INTERNAL" in traversal.error_codesTest Build023 Topology Receipt
A test in the tests folder of Solar Electrical Topology Analysis Engine Text Based that uses SHA-256.
testsolar-electrical-topology-analysis-engine-text-based / tests/test_build023_topology_receipt.py · lines 1–69 of 69 · Entry point
- What it does
- It tests its inputs. Defines _model, test_receipt_is_issued_only_for_complete_valid_topology, test_receipt_rejects_foreign_model_identity, test_receipt_rejects_stale_circuit_hash, test_receipt_rejects_tampered_order. Uses libraries __future__, dataclasses, pytest, solar_topology.circuit, solar_topology.topology_authority.
- Why it exists in the grid workflow
- Domain stage sub33kv_design (path word 'topology'): inside-the-fence electrical and civil design below 33kV, which Ventus Ltd states is within its commercial execution boundary.
- Downstream impact
- Used directly by 1 file: Build 025 Small Gates Workflow (solar-electrical-topology-analysis-engine-text-based).
- What it achieves
- Defines `test_receipt_is_issued_only_for_complete_valid_topology`, `test_receipt_rejects_foreign_model_identity`, `test_receipt_rejects_stale_circuit_hash` and 1 more.
- Why it matters
- Run by Build 025 Small Gates Workflow.
- Application
- solar-electrical-topology-analysis-engine-text-based · tests · test
- Uses
- __future__, dataclasses, pytest, solar_topology.circuit, solar_topology.topology_authority
- Used by
- run by Build 025 Small Gates Workflow (workflow run)
- Produces
- test_receipt_is_issued_only_for_complete_valid_topology, test_receipt_rejects_foreign_model_identity, test_receipt_rejects_stale_circuit_hash, test_receipt_rejects_tampered_order
- Defines here
- _model, test_receipt_is_issued_only_for_complete_valid_topology, test_receipt_rejects_foreign_model_identity, test_receipt_rejects_stale_circuit_hash, test_receipt_rejects_tampered_order
- 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 tests/test_build023_topology_receipt.py:1-69 · blob 62c39189c05fa76405f6eac5656133338c59884c · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
from __future__ import annotations
from dataclasses import replace
import pytest
from solar_topology.circuit import (
CircuitModel,
Connection,
ConnectionKind,
ObjectKind,
PhysicalObject,
Terminal,
TerminalPolarity,
)
from solar_topology.topology_authority import (
issue_topology_receipt,
require_topology_receipt,
)
def _model(model_id: str = "receipt-model") -> CircuitModel:
t1 = Terminal("left", "wire", TerminalPolarity.POSITIVE)
t2 = Terminal("right", "wire", TerminalPolarity.NEGATIVE)
wire = PhysicalObject("wire", ObjectKind.FIELD_CONDUCTOR, (t1, t2))
edge = Connection(
"wire-internal",
"left",
"right",
kind=ConnectionKind.INTERNAL,
segment_id="wire-segment",
)
return CircuitModel(model_id=model_id, objects=(wire,), connections=(edge,))
def test_receipt_is_issued_only_for_complete_valid_topology() -> None:
model = _model()
receipt = issue_topology_receipt(
model,
"left",
"right",
expected_segment_ids=("wire-segment",),
)
assert receipt.circuit_hash.startswith("sha256:")
assert receipt.ordered_terminal_ids == ("left", "right")
require_topology_receipt(model, receipt)
def test_receipt_rejects_foreign_model_identity() -> None:
model = _model()
receipt = issue_topology_receipt(model, "left", "right")
with pytest.raises(ValueError, match="model_id"):
require_topology_receipt(_model("other-model"), receipt)
def test_receipt_rejects_stale_circuit_hash() -> None:
model = _model()
receipt = issue_topology_receipt(model, "left", "right")
stale = replace(receipt, circuit_hash="sha256:" + "0" * 64)
with pytest.raises(ValueError, match="stale"):
require_topology_receipt(model, stale)
def test_receipt_rejects_tampered_order() -> None:
model = _model()
receipt = issue_topology_receipt(model, "left", "right")
tampered = replace(receipt, ordered_terminal_ids=("right", "left"))
with pytest.raises(ValueError, match="terminal order"):
require_topology_receipt(model, tampered)Test Build024 Kernel Authority
A test in the tests folder of Solar Electrical Topology Analysis Engine Text Based that uses SHA-256.
testsolar-electrical-topology-analysis-engine-text-based / tests/test_build024_kernel_authority.py · lines 1–113 of 113 · Entry point · pattern _receipt (shared by 2 files)
- What it does
- It tests its inputs. Defines 7 functions or classes, including _evidence, _resistance_evidence, _receipt, test_consistent_receipt_is_authoritative_and_hashed, test_modified_total_is_rejected. Uses libraries dataclasses, solar_topology.calculation_receipts, solar_topology.circuit, solar_topology.evidence, solar_topology.kernel_authority.
- 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.
- Downstream impact
- Used directly by 1 file: Build 025 Small Gates Workflow (solar-electrical-topology-analysis-engine-text-based).
- What it achieves
- Defines `test_consistent_receipt_is_authoritative_and_hashed`, `test_modified_total_is_rejected`, `test_modified_formula_contract_is_rejected` and 1 more.
- Why it matters
- Run by Build 025 Small Gates Workflow.
- Application
- solar-electrical-topology-analysis-engine-text-based · tests · test
- Uses
- dataclasses, solar_topology.calculation_receipts, solar_topology.circuit, solar_topology.evidence, solar_topology.kernel_authority, solar_topology.resistance_evidence
- Used by
- run by Build 025 Small Gates Workflow (workflow run)
- Produces
- test_consistent_receipt_is_authoritative_and_hashed, test_modified_total_is_rejected, test_modified_formula_contract_is_rejected, test_invalid_type_is_rejected_without_hash
- Defines here
- _evidence, _resistance_evidence, _receipt, test_consistent_receipt_is_authoritative_and_hashed, test_modified_total_is_rejected, test_modified_formula_contract_is_rejected, test_invalid_type_is_rejected_without_hash
- 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 tests/test_build024_kernel_authority.py:1-113 · blob 8265f95cc974e0352fa8388ea15a3716194baa36 · GitHub at these lines
- State
- achieves: name · context: readme_derived · stage: transform · effects: none found · domain stage: sub33kv_design · users: EPC_contractor, ICP_grid_engineer · canonical: production_core
from dataclasses import replace
from solar_topology.calculation_receipts import (
OrderedCircuitCalculationReceipt,
SegmentCalculationResult,
)
from solar_topology.circuit import EvidenceClass
from solar_topology.evidence import EvidenceDescriptor, VerificationState
from solar_topology.kernel_authority import (
KernelAuthorityStatus,
assess_steady_state_receipt,
)
from solar_topology.resistance_evidence import (
ResistanceBasis,
ResistanceValueKind,
ResolvedConductorResistance,
resistance_records_hash,
)
def _evidence() -> EvidenceDescriptor:
return EvidenceDescriptor(
evidence_class=EvidenceClass.MANUFACTURER_DECLARED,
verification_state=VerificationState.VERIFIED,
source_reference="fixture",
source_vocabulary="build024",
source_value="declared",
)
def _resistance_evidence() -> ResolvedConductorResistance:
return ResolvedConductorResistance(
product_id="product-1",
r20_ohm_per_m=0.003,
basis=ResistanceBasis.MANUFACTURER_DECLARED,
value_kind=ResistanceValueKind.MANUFACTURER_NOMINAL,
source_reference="fixture-resistance",
source_revision="build024-v1",
verification_state="verified",
)
def _receipt() -> OrderedCircuitCalculationReceipt:
evidence = _evidence()
resistance = _resistance_evidence()
segment = SegmentCalculationResult(
segment_id="segment-1",
segment_type="external_positive",
conductor_product_id="product-1",
conductor_length_m=10.0,
r20_ohm_per_m=0.003,
resistance_evidence=resistance,
temperature_c=20.0,
conductor_resistance_ohm=0.03,
connector_count=2,
connector_resistance_ohm_each=0.001,
connector_resistance_ohm=0.002,
total_resistance_ohm=0.032,
voltage_drop_v=0.32,
resistive_loss_w=3.2,
source_evidence=evidence,
)
return OrderedCircuitCalculationReceipt(
receipt_id="CALC:fixture",
circuit_model_id="model-1",
validated_circuit_hash="sha256:" + "a" * 64,
traversal_schema_version="globalgrid2050.solar-dc.ordered-traversal.v10.1",
ordered_terminal_ids=("t1", "t2"),
ordered_connection_ids=("c1",),
ordered_segment_ids=("segment-1",),
current_a=10.0,
current_evidence=evidence,
segment_results=(segment,),
total_conductor_length_m=10.0,
total_conductor_resistance_ohm=0.03,
total_connector_resistance_ohm=0.002,
total_resistance_ohm=0.032,
voltage_drop_v=0.32,
resistive_loss_w=3.2,
resistance_evidence_set_hash=resistance_records_hash((resistance,)),
input_evidence_floor=EvidenceClass.MANUFACTURER_DECLARED,
)
def test_consistent_receipt_is_authoritative_and_hashed() -> None:
assessment = assess_steady_state_receipt(_receipt())
assert assessment.status == KernelAuthorityStatus.AUTHORITATIVE
assert assessment.authoritative
assert assessment.receipt_hash is not None
assert assessment.receipt_hash.startswith("sha256:")
assessment.require_authoritative()
def test_modified_total_is_rejected() -> None:
assessment = assess_steady_state_receipt(
replace(_receipt(), total_resistance_ohm=0.031)
)
assert assessment.status == KernelAuthorityStatus.REJECTED
assert "TOTAL_RESISTANCE_MISMATCH" in assessment.reasons
def test_modified_formula_contract_is_rejected() -> None:
assessment = assess_steady_state_receipt(
replace(_receipt(), formula_ids=("wrong",))
)
assert "FORMULA_CONTRACT_MISMATCH" in assessment.reasons
def test_invalid_type_is_rejected_without_hash() -> None:
assessment = assess_steady_state_receipt(object())
assert assessment.status == KernelAuthorityStatus.REJECTED
assert assessment.receipt_hash is None
assert assessment.reasons == ("INVALID_RECEIPT_TYPE",)