GLOBALGRID2050 / EXPLORE CODE

Part of: Explore Code / Solar and storage design / solar-electrical-topology-analysis-engine-text-based / tests

Test Uncertainty and 5 more files

A test in the tests folder of Solar Electrical Topology Analysis Engine Text Based that uses SHA-256.

693 lines of Python from solar-electrical-topology-analysis-engine-text-based, in 6 files. Topic: Solar and storage design. Section 244 of 2044.

Cut 2026-12-06T03:07:51+00:00. A copy for reading; the repository at the stated commit is the source.

In the State lines below, domain stage, users and canonical status are rule-based first approximations from code and path evidence (rules explore-agent-rules-v1), not observed facts: the rules.

In this section

  1. Test Resistance Qualification Public API test · solar-electrical-topology-analysis-engine-text-based / tests/test_resistance_qualification_public_api.py lines 1–98
  2. Test Table String Assignment test · solar-electrical-topology-analysis-engine-text-based / tests/test_table_string_assignment.py lines 1–85
  3. Test Table String Validation test · solar-electrical-topology-analysis-engine-text-based / tests/test_table_string_validation.py lines 1–94
  4. Test Topology test · solar-electrical-topology-analysis-engine-text-based / tests/test_topology.py lines 1–93
  5. Test Ts005 Handoff test · solar-electrical-topology-analysis-engine-text-based / tests/test_ts005_handoff.py lines 1–95
  6. Test Uncertainty test · solar-electrical-topology-analysis-engine-text-based / tests/test_uncertainty.py lines 1–228

Test Resistance Qualification Public API

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_resistance_qualification_public_api.py · lines 1–98 of 98 · Entry point

What it does
It tests its inputs. Defines test_resistance_qualification_is_exposed_by_supported_package_api, test_resistance_qualification_exports_are_explicitly_provisional, test_generic_standard_records_remain_candidate_through_public_api, test_assessment_serialisation_is_exact_through_public_api. Uses libraries __future__, hashlib, json, pytest, 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.
Downstream impact
Used directly by 1 file: Build 025 Small Gates Workflow (solar-electrical-topology-analysis-engine-text-based).
What it achieves
Defines `test_resistance_qualification_is_exposed_by_supported_package_api`, `test_resistance_qualification_exports_are_explicitly_provisional`, `test_generic_standard_records_remain_candidate_through_public_api` 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__, hashlib, json, pytest, solar_topology, solar_topology.resistance_qualification, solar_topology.products
Used by
run by Build 025 Small Gates Workflow (workflow run)
Produces
test_resistance_qualification_is_exposed_by_supported_package_api, test_resistance_qualification_exports_are_explicitly_provisional, test_generic_standard_records_remain_candidate_through_public_api, test_assessment_serialisation_is_exact_through_public_api
Defines here
test_resistance_qualification_is_exposed_by_supported_package_api, test_resistance_qualification_exports_are_explicitly_provisional, test_generic_standard_records_remain_candidate_through_public_api, test_assessment_serialisation_is_exact_through_public_api
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_resistance_qualification_public_api.py:1-98 · blob 0bf3e3277d12770bd8f7bb929bfb76fd7db86820 · 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

import hashlib
import json

import pytest

import solar_topology as api
import solar_topology.resistance_qualification as qualification
from solar_topology.products import EXTERNAL_STRING_6MM2, FACTORY_LEAD_4MM2


PUBLIC_NAMES = (
    "RESISTANCE_QUALIFICATION_SCHEMA_VERSION",
    "ResistanceSourceAssessment",
    "ResistanceSourceStatus",
    "assess_resistance_source",
    "resistance_source_assessment_hash",
    "resistance_source_assessment_json",
    "resistance_source_assessment_payload",
)


def test_resistance_qualification_is_exposed_by_supported_package_api() -> None:
    assert api.RESISTANCE_QUALIFICATION_SCHEMA_VERSION == (
        qualification.RESISTANCE_QUALIFICATION_SCHEMA_VERSION
    )
    assert api.ResistanceSourceAssessment is qualification.ResistanceSourceAssessment
    assert api.ResistanceSourceStatus is qualification.ResistanceSourceStatus
    assert api.assess_resistance_source is qualification.assess_resistance_source
    assert (
        api.resistance_source_assessment_payload
        is qualification.resistance_source_assessment_payload
    )
    assert (
        api.resistance_source_assessment_json
        is qualification.resistance_source_assessment_json
    )
    assert (
        api.resistance_source_assessment_hash
        is qualification.resistance_source_assessment_hash
    )
    assert all(name in api.__all__ for name in PUBLIC_NAMES)


def test_resistance_qualification_exports_are_explicitly_provisional() -> None:
    for name in PUBLIC_NAMES:
        assert api.public_api_status(name) == api.ApiStatus.PROVISIONAL
        assert name in api.explicitly_classified_public_names()


def test_generic_standard_records_remain_candidate_through_public_api() -> None:
    for product in (FACTORY_LEAD_4MM2, EXTERNAL_STRING_6MM2):
        assessment = api.assess_resistance_source(product.resolved_resistance)

        assert assessment.status == api.ResistanceSourceStatus.CANDIDATE
        assert not assessment.promotable
        assert assessment.record_hash is not None
        assert assessment.record_hash.startswith("sha256:")
        assert assessment.reasons == (
            "SOURCE_REVISION_PLACEHOLDER",
            "VERIFICATION_NOT_VERIFIED",
        )
        with pytest.raises(ValueError, match="not verified"):
            assessment.require_verified()


def test_assessment_serialisation_is_exact_through_public_api() -> None:
    for product in (FACTORY_LEAD_4MM2, EXTERNAL_STRING_6MM2):
        assessment = api.assess_resistance_source(product.resolved_resistance)
        expected_payload = {
            "schema_version": assessment.schema_version,
            "record_hash": assessment.record_hash,
            "status": str(assessment.status),
            "reasons": list(assessment.reasons),
        }
        expected_json = json.dumps(
            expected_payload,
            sort_keys=True,
            separators=(",", ":"),
            ensure_ascii=False,
        )
        expected_hash = "sha256:" + hashlib.sha256(
            expected_json.encode("utf-8")
        ).hexdigest()

        assert api.resistance_source_assessment_payload(assessment) == expected_payload
        assert api.resistance_source_assessment_json(assessment) == expected_json
        assert api.resistance_source_assessment_hash(assessment) == expected_hash
        assert qualification.resistance_source_assessment_payload(
            assessment
        ) == expected_payload
        assert qualification.resistance_source_assessment_json(
            assessment
        ) == expected_json
        assert qualification.resistance_source_assessment_hash(
            assessment
        ) == expected_hash

Test Table String Assignment

A test in the tests folder of Solar Electrical Topology Analysis Engine Text Based that checks Geometry Authority.

testsolar-electrical-topology-analysis-engine-text-based / tests/test_table_string_assignment.py · lines 1–85 of 85 · Entry point

What it does
It tests its inputs. Defines 6 functions or classes, including _reference_assignment, test_reference_assignment_covers_all_720_modules_once, test_reference_assignment_has_one_free_terminal_per_polarity, test_reference_assignment_is_deterministic, test_reference_assignment_preserves_physical_placement_order. Uses libraries pytest, table_string_assignment.
Why it exists in the grid workflow
Domain stage sub33kv_design (path word 'string'): 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_reference_assignment_covers_all_720_modules_once`, `test_reference_assignment_has_one_free_terminal_per_polarity`, `test_reference_assignment_is_deterministic` and 2 more.
Why it matters
Run by Build 025 Small Gates Workflow.
Application
solar-electrical-topology-analysis-engine-text-based · tests · test
Uses
Geometry Authority (import), pytest, table_string_assignment
Used by
run by Build 025 Small Gates Workflow (workflow run)
Produces
test_reference_assignment_covers_all_720_modules_once, test_reference_assignment_has_one_free_terminal_per_polarity, test_reference_assignment_is_deterministic, test_reference_assignment_preserves_physical_placement_order, test_incompatible_string_dimensions_are_rejected
Defines here
_reference_assignment, test_reference_assignment_covers_all_720_modules_once, test_reference_assignment_has_one_free_terminal_per_polarity, test_reference_assignment_is_deterministic, test_reference_assignment_preserves_physical_placement_order, test_incompatible_string_dimensions_are_rejected
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_table_string_assignment.py:1-85 · blob 630d87ee5178e9e8cec4718ba687a9f0b3a90185 · 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
import pytest

from geometry_authority import reference_24_by_30_table
from table_string_assignment import assign_modules_to_strings


def _reference_assignment():
    geometry = reference_24_by_30_table()
    assignment = assign_modules_to_strings(
        geometry,
        string_count=24,
        modules_per_string=30,
    )
    return geometry, assignment


def test_reference_assignment_covers_all_720_modules_once() -> None:
    geometry, assignment = _reference_assignment()

    assigned_module_ids = tuple(
        module_id
        for string in assignment.strings
        for module_id in string.ordered_module_ids
    )
    geometry_module_ids = tuple(
        placement.module_id
        for placement in sorted(geometry.placements, key=lambda item: item.ordinal)
    )

    assert assignment.string_count == 24
    assert len(assignment.strings) == 24
    assert all(len(string.ordered_module_ids) == 30 for string in assignment.strings)
    assert len(assigned_module_ids) == 720
    assert len(set(assigned_module_ids)) == 720
    assert assigned_module_ids == geometry_module_ids


def test_reference_assignment_has_one_free_terminal_per_polarity() -> None:
    _, assignment = _reference_assignment()

    terminal_ids = []
    for string in assignment.strings:
        assert string.positive_free_terminal.string_id == string.string_id
        assert string.positive_free_terminal.polarity == "positive"
        assert string.negative_free_terminal.string_id == string.string_id
        assert string.negative_free_terminal.polarity == "negative"
        terminal_ids.extend(
            (
                string.positive_free_terminal.terminal_id,
                string.negative_free_terminal.terminal_id,
            )
        )

    assert len(terminal_ids) == 48
    assert len(set(terminal_ids)) == 48


def test_reference_assignment_is_deterministic() -> None:
    _, first = _reference_assignment()
    _, second = _reference_assignment()

    assert first == second
    assert first.assignment_hash == second.assignment_hash


def test_reference_assignment_preserves_physical_placement_order() -> None:
    _, assignment = _reference_assignment()

    assert assignment.strings[0].string_id == "TABLE-001-STR-001"
    assert assignment.strings[0].ordered_module_ids[0] == "TABLE-001-MOD-0001"
    assert assignment.strings[0].ordered_module_ids[-1] == "TABLE-001-MOD-0030"
    assert assignment.strings[-1].string_id == "TABLE-001-STR-024"
    assert assignment.strings[-1].ordered_module_ids[0] == "TABLE-001-MOD-0691"
    assert assignment.strings[-1].ordered_module_ids[-1] == "TABLE-001-MOD-0720"


def test_incompatible_string_dimensions_are_rejected() -> None:
    geometry = reference_24_by_30_table()

    with pytest.raises(ValueError, match="module_count"):
        assign_modules_to_strings(
            geometry,
            string_count=23,
            modules_per_string=30,
        )

Test Table String Validation

A test in the tests folder of Solar Electrical Topology Analysis Engine Text Based that checks Geometry Authority, using SHA-256.

testsolar-electrical-topology-analysis-engine-text-based / tests/test_table_string_validation.py · lines 1–94 of 94 · Entry point

What it does
It tests its inputs. Defines 6 functions or classes, including _reference_receipts, test_reference_assignment_passes_independent_validation, test_asserted_assignment_hash_is_independently_recalculated, test_cross_string_duplicate_and_omission_are_detected, test_geometry_binding_mismatch_is_detected. Uses libraries dataclasses, table_string_assignment, table_string_validation.
Why it exists in the grid workflow
Domain stage sub33kv_design (path word 'string'): 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_reference_assignment_passes_independent_validation`, `test_asserted_assignment_hash_is_independently_recalculated`, `test_cross_string_duplicate_and_omission_are_detected` and 2 more.
Why it matters
Run by Build 025 Small Gates Workflow.
Application
solar-electrical-topology-analysis-engine-text-based · tests · test
Uses
Geometry Authority (import), dataclasses, table_string_assignment, table_string_validation
Used by
run by Build 025 Small Gates Workflow (workflow run)
Produces
test_reference_assignment_passes_independent_validation, test_asserted_assignment_hash_is_independently_recalculated, test_cross_string_duplicate_and_omission_are_detected, test_geometry_binding_mismatch_is_detected, test_collapsed_free_terminal_identifiers_are_detected
Defines here
_reference_receipts, test_reference_assignment_passes_independent_validation, test_asserted_assignment_hash_is_independently_recalculated, test_cross_string_duplicate_and_omission_are_detected, test_geometry_binding_mismatch_is_detected, test_collapsed_free_terminal_identifiers_are_detected
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_table_string_validation.py:1-94 · blob 4d41c07b5e593fea694536f250d3eab84e5b6c54 · 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 geometry_authority import reference_24_by_30_table
from table_string_assignment import assign_modules_to_strings
from table_string_validation import validate_table_string_assignment


def _reference_receipts():
    geometry = reference_24_by_30_table()
    assignment = assign_modules_to_strings(
        geometry,
        string_count=24,
        modules_per_string=30,
    )
    return geometry, assignment


def test_reference_assignment_passes_independent_validation() -> None:
    geometry, assignment = _reference_receipts()

    result = validate_table_string_assignment(geometry, assignment)

    assert result.valid is True
    assert result.checked_string_count == 24
    assert result.checked_module_count == 720
    assert result.issues == ()


def test_asserted_assignment_hash_is_independently_recalculated() -> None:
    geometry, assignment = _reference_receipts()
    altered_assignment = replace(assignment, assignment_hash="sha256:not-the-content")

    result = validate_table_string_assignment(geometry, altered_assignment)

    assert result.valid is False
    assert {issue.code for issue in result.issues} == {"ASSIGNMENT_HASH_MISMATCH"}


def test_cross_string_duplicate_and_omission_are_detected() -> None:
    geometry, assignment = _reference_receipts()
    first = assignment.strings[0]
    second = assignment.strings[1]
    altered_second = replace(
        second,
        ordered_module_ids=(first.ordered_module_ids[0],) + second.ordered_module_ids[1:],
    )
    altered_assignment = replace(
        assignment,
        strings=(first, altered_second) + assignment.strings[2:],
    )

    result = validate_table_string_assignment(geometry, altered_assignment)
    issue_codes = {issue.code for issue in result.issues}

    assert result.valid is False
    assert "ASSIGNMENT_HASH_MISMATCH" in issue_codes
    assert "DUPLICATE_MODULE_ASSIGNMENT" in issue_codes
    assert "OMITTED_MODULES" in issue_codes
    assert "PHYSICAL_ORDER_MISMATCH" in issue_codes


def test_geometry_binding_mismatch_is_detected() -> None:
    geometry, assignment = _reference_receipts()
    altered_assignment = replace(assignment, geometry_hash="sha256:not-the-geometry")

    result = validate_table_string_assignment(geometry, altered_assignment)

    assert result.valid is False
    assert {issue.code for issue in result.issues} == {
        "ASSIGNMENT_HASH_MISMATCH",
        "GEOMETRY_HASH_MISMATCH",
    }


def test_collapsed_free_terminal_identifiers_are_detected() -> None:
    geometry, assignment = _reference_receipts()
    first = assignment.strings[0]
    altered_positive = replace(
        first.positive_free_terminal,
        terminal_id=first.negative_free_terminal.terminal_id,
    )
    altered_first = replace(first, positive_free_terminal=altered_positive)
    altered_assignment = replace(
        assignment,
        strings=(altered_first,) + assignment.strings[1:],
    )

    result = validate_table_string_assignment(geometry, altered_assignment)
    issue_codes = {issue.code for issue in result.issues}

    assert result.valid is False
    assert "ASSIGNMENT_HASH_MISMATCH" in issue_codes
    assert "COLLAPSED_FREE_TERMINALS" in issue_codes
    assert "DUPLICATE_FREE_TERMINAL_ID" in issue_codes

Test Topology

A test in the tests folder of Solar Electrical Topology Analysis Engine Text Based.

testsolar-electrical-topology-analysis-engine-text-based / tests/test_topology.py · lines 1–93 of 93 · Entry point

What it does
It tests its inputs. Defines 8 functions or classes, including test_default_structure_is_two_faces_with_five_five_two_bands_each, test_rank_slope_and_plan_projection_are_not_conflated, test_string_is_an_ordered_chain_of_typed_segments, test_coiled_surplus_has_zero_displacement_but_real_length, test_every_segment_has_formation_separation_and_provenance. Uses libraries math, pytest, solar_topology.topology.
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_default_structure_is_two_faces_with_five_five_two_bands_each`, `test_rank_slope_and_plan_projection_are_not_conflated`, `test_string_is_an_ordered_chain_of_typed_segments` and 5 more.
Why it matters
Run by Build 025 Small Gates Workflow.
Application
solar-electrical-topology-analysis-engine-text-based · tests · test
Uses
math, pytest, solar_topology.topology
Used by
run by Build 025 Small Gates Workflow (workflow run)
Produces
test_default_structure_is_two_faces_with_five_five_two_bands_each, test_rank_slope_and_plan_projection_are_not_conflated, test_string_is_an_ordered_chain_of_typed_segments, test_coiled_surplus_has_zero_displacement_but_real_length, test_every_segment_has_formation_separation_and_provenance, test_export_route_length_is_exact_segment_sum_and_derived, test_validation_fails_if_route_length_is_user_supplied, test_headless_scale_target_builds_without_renderer
Defines here
test_default_structure_is_two_faces_with_five_five_two_bands_each, test_rank_slope_and_plan_projection_are_not_conflated, test_string_is_an_ordered_chain_of_typed_segments, test_coiled_surplus_has_zero_displacement_but_real_length, test_every_segment_has_formation_separation_and_provenance, test_export_route_length_is_exact_segment_sum_and_derived, test_validation_fails_if_route_length_is_user_supplied, test_headless_scale_target_builds_without_renderer
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_topology.py:1-93 · blob 95be538c9f961de989e507b8dcc97426c6dd9c75 · 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
import math

import pytest

from solar_topology.topology import (
    FormationConfig,
    GeometryConfig,
    build_export,
    build_site_model,
    validate_no_user_route_lengths,
)


def test_default_structure_is_two_faces_with_five_five_two_bands_each():
    strings = build_site_model()
    assert len(strings) == 24
    assert sum(s.face == "E" for s in strings) == 12
    assert sum(s.face == "W" for s in strings) == 12
    assert all(s.module_count == 30 for s in strings)


def test_rank_slope_and_plan_projection_are_not_conflated():
    g = GeometryConfig(tilt_deg=10.0)
    slope_pitch = g.module_length_m + g.clamp_gap_m
    plan_pitch = slope_pitch * math.cos(math.radians(g.tilt_deg))
    assert slope_pitch == pytest.approx(2.404)
    assert plan_pitch < slope_pitch


def test_string_is_an_ordered_chain_of_typed_segments():
    string = build_site_model()[0]
    types = [s.segment_type for s in string.segments]
    assert types.count("module_interconnect") == 29
    assert types.count("coiled_surplus") == 60
    assert "along_rank_return" in types
    assert "across_table_transfer" in types
    assert "structure_drop" in types
    assert "surface_or_trench_run" in types
    assert [s.sequence_index for s in string.segments] == list(range(1, len(string.segments) + 1))


def test_coiled_surplus_has_zero_displacement_but_real_length():
    string = build_site_model()[0]
    coils = [s for s in string.segments if s.segment_type == "coiled_surplus"]
    assert coils
    assert all(s.geometric_displacement_m == pytest.approx(0.0) for s in coils)
    assert all(s.installed_conductor_length_m == pytest.approx(0.20) for s in coils)


def test_every_segment_has_formation_separation_and_provenance():
    string = build_site_model()[0]
    for segment in string.segments:
        assert segment.formation_type
        assert segment.conductor_separation_mm > 0
        assert segment.provenance
        assert segment.route_length_source == "derived_from_segment_geometry"


def test_export_route_length_is_exact_segment_sum_and_derived():
    geometry = GeometryConfig()
    formations = FormationConfig()
    export = build_export(build_site_model(geometry, formations), geometry, formations)
    validate_no_user_route_lengths(export)
    for string in export["strings"]:
        expected = sum(s["installed_conductor_length_m"] for s in string["segments"])
        assert string["route_length"]["value_m"] == pytest.approx(expected)
        assert string["route_length"]["source"] == "segment_list"
        assert string["route_length"]["provenance"] == "derived"


def test_validation_fails_if_route_length_is_user_supplied():
    geometry = GeometryConfig()
    formations = FormationConfig()
    export = build_export(build_site_model(geometry, formations), geometry, formations)
    export["strings"][0]["route_length"] = {
        "value_m": 999.0,
        "source": "user_input",
        "provenance": "user_overridden",
    }
    with pytest.raises(ValueError, match="was not derived"):
        validate_no_user_route_lengths(export)


def test_headless_scale_target_builds_without_renderer():
    # 24 strings per inverter × 792 inverter blocks = 19,008 strings.
    base = build_site_model()
    total_strings = len(base) * 792
    assert total_strings == 19008
    # The topology module imports no browser, canvas or mapping package.
    import solar_topology.topology as topology
    source_names = set(topology.__dict__)
    assert "canvas" not in source_names
    assert "maplibre" not in source_names

Test Ts005 Handoff

A test in the tests folder of Solar Electrical Topology Analysis Engine Text Based that checks Check Microbuild Plan and Run Microbuild, using SHA-256.

testsolar-electrical-topology-analysis-engine-text-based / tests/test_ts005_handoff.py · lines 1–95 of 95 · Entry point

What it does
It tests its inputs. Defines test_hostile_amnesia_reload_recovers_ts005_handoff, test_handoff_files_exist_and_bind_validated_receipt, test_handoff_exposes_unresolved_authority_without_inference, test_completed_programme_exposes_no_active_command. Uses libraries __future__, json, pathlib. Side effects: reads or writes files.
Why it exists in the grid workflow
Domain stage agent_infra (path word 'handoff'): AI-agent memory, coordination and code audit (the multi-agent journey named in Ventus Ltd's brief).
Inputs & outputs
In: JSON file programme-state.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 3 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_hostile_amnesia_reload_recovers_ts005_handoff`, `test_handoff_files_exist_and_bind_validated_receipt`, `test_handoff_exposes_unresolved_authority_without_inference` and 1 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
Check Microbuild Plan (import), Run Microbuild (import), __future__, json, pathlib
Used by
run by Run Microbuild (script call), run by Build 025 Small Gates Workflow (workflow run)
Produces
test_hostile_amnesia_reload_recovers_ts005_handoff, test_handoff_files_exist_and_bind_validated_receipt, test_handoff_exposes_unresolved_authority_without_inference, test_completed_programme_exposes_no_active_command
Defines here
test_hostile_amnesia_reload_recovers_ts005_handoff, test_handoff_files_exist_and_bind_validated_receipt, test_handoff_exposes_unresolved_authority_without_inference, test_completed_programme_exposes_no_active_command
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_ts005_handoff.py:1-95 · blob 9752718dcc64b1cb786eef3ac8dfbc1075db7200 · GitHub at these lines
State
achieves: name · context: readme_derived · stage: ingest · effects: filesystem · domain stage: agent_infra · users: ai_agent · canonical: production_core
from __future__ import annotations

import json
from pathlib import Path

from scripts.check_microbuild_plan import load_plan, validate_plan
from scripts.run_microbuild import active_command, active_test_id


ROOT = Path(__file__).resolve().parents[1]
EXPECTED_BLOCK_HASH = (
    "sha256:79f3d02a878e4fe6bd700d194c2b29e2500cd9511e23d469c34f3d8472f8a1f8"
)
TS005_CLOSURE = ROOT / "docs/trueself/20260801-ts-005-authoritative-slice-closure.md"


def test_hostile_amnesia_reload_recovers_ts005_handoff() -> None:
    programme = json.loads(
        (ROOT / "programme-state.json").read_text(encoding="utf-8")
    )
    plan = load_plan()
    summary = validate_plan(plan)
    handoff = plan["steps"][9]
    reference_command = plan["steps"][10]

    assert programme["active_gate"].startswith("TS-005")
    assert summary["programme_status"] == "completed"
    assert plan["active_step"] is None
    assert plan["next_step"] is None

    assert handoff["id"] == "MB-10"
    assert handoff["status"] == "passed"
    assert handoff["test_id"] == "ts005_handoff"
    assert handoff["evidence"]["result"] == "pass"
    assert handoff["evidence"]["test_id"] == "ts005_handoff"

    assert reference_command["title"] == "Reference-block command"
    assert reference_command["test_id"] == "reference_block_command"
    assert reference_command["status"] == "passed"

    block = programme["reference_inverter_block"]
    assert block["module_rated_power_wp"] == 660
    assert block["modules_per_string"] == 30
    assert block["strings"] == 24
    assert block["module_count"] == 720
    assert block["dc_nameplate_power_kwp"] == 475.2
    assert block["inverter_apparent_power_kva"] == 352
    assert block["dc_ac_nameplate_ratio"] == 1.35


def test_handoff_files_exist_and_bind_validated_receipt() -> None:
    programme = json.loads(
        (ROOT / "programme-state.json").read_text(encoding="utf-8")
    )
    spawn = ROOT / programme["current_quantum_spawn"]
    current_trueself = ROOT / programme["current_trueself"]

    assert spawn.is_file()
    assert current_trueself.is_file()
    assert TS005_CLOSURE.is_file()
    checkpoint_text = TS005_CLOSURE.read_text(encoding="utf-8")
    assert EXPECTED_BLOCK_HASH in checkpoint_text
    assert "Forty-seven equipment evidence items remain unresolved" in checkpoint_text
    assert "MB-10 — TS-005 hand-off proof" in checkpoint_text
    assert "TS-005 — First authoritative Studio slice" in checkpoint_text


def test_handoff_exposes_unresolved_authority_without_inference() -> None:
    programme = json.loads(
        (ROOT / "programme-state.json").read_text(encoding="utf-8")
    )
    limitations = "\n".join(programme["known_limitations"])

    for unresolved in (
        "47 unresolved",
        "Internal DC topology",
        "reverse-current blocking",
        "PCE backfeed",
    ):
        assert unresolved in limitations


def test_completed_programme_exposes_no_active_command() -> None:
    plan = load_plan()
    summary = validate_plan(plan)

    assert active_test_id() is None
    assert active_command() == ()
    assert plan["active_step"] == summary["active_step"] is None
    assert plan["steps"][9]["status"] == "passed"
    assert plan["steps"][9]["evidence"]["test_id"] == "ts005_handoff"
    assert plan["steps"][19]["status"] == "passed"
    assert plan["steps"][19]["evidence"]["test_id"] == (
        "end_to_end_authority_slice"
    )

Test Uncertainty

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_uncertainty.py · lines 1–228 of 228 · Entry point · pattern _model_and_traversal (shared by 3 files)

What it does
It tests its inputs. Defines 11 functions or classes, including _rows, _model_and_traversal, _evidence, _operating_state, _exact_operating_state. Uses libraries dataclasses, pytest, solar_topology.cartridges, solar_topology.circuit, solar_topology.circuit_adapters.
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_interval_requires_ordered_finite_values_and_units`, `test_uncertainty_contains_nominal_and_reports_voltage_drop_percentage`, `test_exact_uncertainty_collapses_to_nominal_across_module_counts` 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, pytest, solar_topology.cartridges, solar_topology.circuit, solar_topology.circuit_adapters, solar_topology.circuit_traversal, solar_topology.evidence, solar_topology.segments
Used by
run by Build 025 Small Gates Workflow (workflow run)
Produces
test_interval_requires_ordered_finite_values_and_units, test_uncertainty_contains_nominal_and_reports_voltage_drop_percentage, test_exact_uncertainty_collapses_to_nominal_across_module_counts, test_uncertainty_receipt_is_deterministic_under_source_row_reordering, test_uncertainty_rejects_unknown_segments_and_nominal_mismatch, test_invalid_operating_state_is_rejected
Defines here
_rows, _model_and_traversal, _evidence, _operating_state, _exact_operating_state, test_interval_requires_ordered_finite_values_and_units, test_uncertainty_contains_nominal_and_reports_voltage_drop_percentage, test_exact_uncertainty_collapses_to_nominal_across_module_counts, test_uncertainty_receipt_is_deterministic_under_source_row_reordering, test_uncertainty_rejects_unknown_segments_and_nominal_mismatch, test_invalid_operating_state_is_rejected
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_uncertainty.py:1-228 · blob e4bf1d4aefbfb8662e9c84cd5a65c432e900af7e · 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
import dataclasses

import pytest

from solar_topology.cartridges import SequentialCartridge
from solar_topology.circuit import EvidenceClass
from solar_topology.circuit_adapters import (
    adapt_segment_chain_to_circuit,
    circuit_boundary_terminal_ids,
    source_segment_ids,
)
from solar_topology.circuit_traversal import verify_ordered_circuit
from solar_topology.evidence import (
    VerificationState,
    canonical_evidence_descriptor,
)
from solar_topology.segments import TopologyInputs, archetype_strings
from solar_topology.uncertainty import (
    Interval,
    OperatingState,
    SegmentInputIntervals,
    calculate_complete_circuit_with_uncertainty,
    uncertainty_receipt_hash,
    uncertainty_receipt_json,
)


def _rows(modules=6):
    inputs = TopologyInputs(
        modules_per_string=modules,
        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 _model_and_traversal(rows):
    model = adapt_segment_chain_to_circuit(rows)
    start, end = circuit_boundary_terminal_ids(model)
    traversal = verify_ordered_circuit(
        model,
        start,
        end,
        expected_segment_ids=source_segment_ids(rows),
    )
    assert traversal.valid
    return model, traversal


def _evidence(source):
    return canonical_evidence_descriptor(
        EvidenceClass.MANUFACTURER_DECLARED,
        verification_state=VerificationState.CANDIDATE,
        source_reference=source,
    )


def _operating_state():
    return OperatingState(
        state_id="fixture:operating-state",
        current_a=Interval(16.0, 17.35, 18.0, "A"),
        current_evidence=_evidence("fixture:current"),
        string_vmp_v=Interval(1050.0, 1100.0, 1150.0, "V"),
        string_vmp_evidence=_evidence("fixture:vmp"),
    )


def _exact_operating_state():
    return OperatingState(
        state_id="fixture:exact-operating-state",
        current_a=Interval.exact(17.35, "A"),
        current_evidence=_evidence("fixture:exact-current"),
        string_vmp_v=Interval.exact(1100.0, "V"),
        string_vmp_evidence=_evidence("fixture:exact-vmp"),
    )


def test_interval_requires_ordered_finite_values_and_units():
    assert Interval.exact(10.0, "A") == Interval(10.0, 10.0, 10.0, "A")
    with pytest.raises(ValueError, match="lower <= nominal <= upper"):
        Interval(2.0, 1.0, 3.0, "A")
    with pytest.raises(ValueError, match="unit"):
        Interval(1.0, 1.0, 1.0, "")


def test_uncertainty_contains_nominal_and_reports_voltage_drop_percentage():
    rows = _rows()
    model, traversal = _model_and_traversal(rows)
    first = rows[0]
    overrides = {
        first.segment_id: SegmentInputIntervals(
            conductor_length_m=Interval(
                first.conductor_length_m * 0.98,
                first.conductor_length_m,
                first.conductor_length_m * 1.02,
                "m",
            ),
            r20_ohm_per_m=Interval(
                first.r20_ohm_per_m * 0.97,
                first.r20_ohm_per_m,
                first.r20_ohm_per_m * 1.03,
                "ohm/m",
            ),
            temperature_c=Interval(
                first.temperature_c - 5.0,
                first.temperature_c,
                first.temperature_c + 5.0,
                "degC",
            ),
            connector_resistance_ohm_each=Interval(
                first.connector_resistance_ohm_each * 0.9,
                first.connector_resistance_ohm_each,
                first.connector_resistance_ohm_each * 1.1,
                "ohm",
            ),
        )
    }

    receipt = calculate_complete_circuit_with_uncertainty(
        model,
        traversal,
        operating_state=_operating_state(),
        segment_intervals=overrides,
    )

    assert receipt.total_resistance_ohm.lower <= receipt.total_resistance_ohm.nominal
    assert receipt.total_resistance_ohm.nominal <= receipt.total_resistance_ohm.upper
    assert receipt.voltage_drop_v.nominal == pytest.approx(
        receipt.nominal_receipt.voltage_drop_v
    )
    assert receipt.resistive_loss_w.nominal == pytest.approx(
        receipt.nominal_receipt.resistive_loss_w
    )
    assert receipt.voltage_drop_percent.nominal == pytest.approx(
        100.0 * receipt.nominal_receipt.voltage_drop_v / 1100.0
    )
    assert receipt.voltage_drop_percent.lower < receipt.voltage_drop_percent.upper
    assert uncertainty_receipt_hash(receipt).startswith("sha256:")


@pytest.mark.parametrize("modules", range(1, 62))
def test_exact_uncertainty_collapses_to_nominal_across_module_counts(modules):
    rows = _rows(modules)
    model, traversal = _model_and_traversal(rows)

    receipt = calculate_complete_circuit_with_uncertainty(
        model,
        traversal,
        operating_state=_exact_operating_state(),
    )

    nominal = receipt.nominal_receipt
    assert receipt.total_resistance_ohm == Interval.exact(
        nominal.total_resistance_ohm,
        "ohm",
    )
    assert receipt.voltage_drop_v == Interval.exact(
        nominal.voltage_drop_v,
        "V",
    )
    assert receipt.resistive_loss_w == Interval.exact(
        nominal.resistive_loss_w,
        "W",
    )
    assert receipt.voltage_drop_percent.lower == receipt.voltage_drop_percent.nominal
    assert receipt.voltage_drop_percent.nominal == receipt.voltage_drop_percent.upper


def test_uncertainty_receipt_is_deterministic_under_source_row_reordering():
    rows = _rows()
    first_model, first_traversal = _model_and_traversal(rows)
    second_model, second_traversal = _model_and_traversal(tuple(reversed(rows)))

    first = calculate_complete_circuit_with_uncertainty(
        first_model,
        first_traversal,
        operating_state=_operating_state(),
    )
    second = calculate_complete_circuit_with_uncertainty(
        second_model,
        second_traversal,
        operating_state=_operating_state(),
    )

    assert uncertainty_receipt_json(first) == uncertainty_receipt_json(second)
    assert uncertainty_receipt_hash(first) == uncertainty_receipt_hash(second)


def test_uncertainty_rejects_unknown_segments_and_nominal_mismatch():
    rows = _rows()
    model, traversal = _model_and_traversal(rows)

    with pytest.raises(ValueError, match="unknown segments"):
        calculate_complete_circuit_with_uncertainty(
            model,
            traversal,
            operating_state=_operating_state(),
            segment_intervals={"missing": SegmentInputIntervals()},
        )

    first = rows[0]
    with pytest.raises(ValueError, match="nominal must equal canonical"):
        calculate_complete_circuit_with_uncertainty(
            model,
            traversal,
            operating_state=_operating_state(),
            segment_intervals={
                first.segment_id: SegmentInputIntervals(
                    conductor_length_m=Interval(
                        first.conductor_length_m,
                        first.conductor_length_m + 1.0,
                        first.conductor_length_m + 2.0,
                        "m",
                    )
                )
            },
        )


def test_invalid_operating_state_is_rejected():
    with pytest.raises(ValueError, match="strictly positive"):
        dataclasses.replace(
            _operating_state(),
            string_vmp_v=Interval(0.0, 1.0, 2.0, "V"),
        )