Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
fe97ed3
Evaluate battery entries at their stages and assemble the phase
juaristi22 Nov 13, 2026
8f5b2ca
Prove the record-without-enforce posture with tests
juaristi22 Nov 13, 2026
fdde559
Lift the UK gate scoping and re-minting binding into the battery
juaristi22 Nov 13, 2026
8444a53
Load a country's gates.json alone, and read its resources by country
juaristi22 Nov 13, 2026
dfe1b31
Accept synthetic_smoke in the exact-k UK schema-4 report checker
juaristi22 Nov 13, 2026
c704201
Document the shared battery APIs and correct the UK entry count
juaristi22 Nov 13, 2026
ee31b0a
Add changelog fragments for the shared battery pieces and the checker…
juaristi22 Nov 13, 2026
fea4234
Check a named blocker against the run's posture
juaristi22 Nov 14, 2026
fbdb498
Say that stage-assembled phases are for the executor only for now
juaristi22 Nov 14, 2026
f3ecc79
Pin the attestation's own copy of synthetic_smoke
juaristi22 Nov 14, 2026
fd3ad06
Evaluate stage entries through the run, and name the entries that nev…
juaristi22 Nov 15, 2026
5575ac8
Test each refusal in evaluate_entries and load_gates_manifest
juaristi22 Nov 15, 2026
a860d3d
Test the run's block refusal with a later phase's entry
juaristi22 Nov 15, 2026
da67e41
Refuse a phase that marks unreached an entry the run evaluated
juaristi22 Nov 15, 2026
3870461
Evaluate each stage entry once and record its own outcome
juaristi22 Nov 16, 2026
7fb0bab
Carry a stage's outcome into the report until its phase is recorded
juaristi22 Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The gate battery gains the shared pieces a country needs to adopt it tool by tool: stage-level evaluation (`evaluate_entries`, `blocking_outcomes` and `assemble_phase_report`), the UK's scoping and re-minting binding lifted into shared code (`scoped_gate_manifest` and `EvaluatorBinding`), and a narrow `load_gates_manifest` with a per-country `country_resource` (microcosm#1585 item 11).
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The exact-k UK schema-4 gate-report checker now accepts the `synthetic_smoke` field the executor writes into every report's body and attestation, which made it refuse every report the executor writes, and requires that field to be false (microcosm#1585 item 11).
143 changes: 116 additions & 27 deletions docs/gate-battery-contract.md

Large diffs are not rendered by default.

96 changes: 96 additions & 0 deletions packages/microcosm-build/src/microcosm/build/country_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from dataclasses import dataclass, field
from functools import cache
from importlib import resources as importlib_resources
from importlib.resources.abc import Traversable
from pathlib import Path, PurePosixPath
from types import MappingProxyType
from typing import Any
Expand Down Expand Up @@ -73,9 +74,11 @@
"GeographySpineSpec",
"ReleaseContractManifest",
"ResolvedCountrySpec",
"country_resource",
"country_stage_plan",
"load_country_take_up_contract_projection",
"load_country_spec",
"load_gates_manifest",
]

#: Resource kinds admitted by the binding ``resource_manifest.schema.json``.
Expand Down Expand Up @@ -2157,6 +2160,99 @@ def load_normalized(row: CountryResourceRow) -> Mapping[str, Any]:
return projection


def country_resource(country: str, name: str) -> Traversable:
"""The packaged resource ``name`` of ``country``'s spec package.

``microcosm/build/<country>/<name>``, read through
:mod:`importlib.resources` so it resolves the same from a wheel as from
the source tree. It reads no ``country_package.json``: the closed resource
inventory is :func:`load_country_spec`'s to enforce. Bindings read the
registers their declared ``*_resource`` parameters name through here.

Raises:
ValueError: If ``country`` is not a lowercase ASCII country code.
"""

if not (country.isascii() and country.isalpha() and country.islower()):
raise ValueError(
f"country must be a lowercase ASCII country code, got {country!r}."
)
return importlib_resources.files(f"microcosm.build.{country}").joinpath(name)


def load_gates_manifest(country: str | Path) -> GatesManifest:
"""Load and validate only the country's ``gates.json``.

The narrow seam for a build tool that needs its gate policy and nothing
else, as the US tools will (microcosm#1585 item 11). Like
:func:`load_country_take_up_contract_projection`, it reads
``country_package.json`` only to find the declared row, then parses that
one file with the validator :func:`load_country_spec` uses
(:meth:`GatesManifest.from_mapping`). It runs no bundle load, file-closure
check or validation of any other resource, so an edit elsewhere in the
package cannot break a tool's gates, and it returns the manifest
``load_country_spec(country).gates`` returns.

Args:
country: A country code (resolved inside ``microcosm.build``) or a
path to a country package directory.

Raises:
FileNotFoundError: If the package or its declared ``gates.json`` is
missing.
ValueError: If the package declares no ``legacy_json`` ``gates.json``
row, the file resolves outside the package or is not a file
holding a JSON mapping, or the manifest is malformed.
"""

if isinstance(country, Path):
root = country
else:
root = Path(str(importlib_resources.files("microcosm.build").joinpath(country)))
package_path = root / "country_package.json"
if not package_path.exists():
raise FileNotFoundError(f"No country package at {package_path}.")
package = _require_mapping(
json.loads(package_path.read_text(encoding="utf-8")),
context="country_package.json",
)
declared_country = _require_non_empty_string(
package.get("country"), field_name="country", context="country_package.json"
)
if declared_country != root.name:
raise ValueError(
f"country_package.json declares country {declared_country!r} but "
f"lives in directory {root.name!r}."
)
rows = [
row
for row in _resolve_country_resource_rows(package.get("resources", []))
if row.path == "gates.json"
]
if not rows or rows[0].kind != "legacy_json":
raise ValueError(
f"{root.name}: country_package.json declares no legacy_json "
"gates.json resource."
)
# The same checks, in the same order, as the full loader's resource loop.
resource_path = _country_resource_path(root, "gates.json")
if not resource_path.exists():
raise FileNotFoundError(
f"{root.name}: declared resource 'gates.json' is missing."
)
if not resource_path.resolve().is_relative_to(root.resolve()):
raise ValueError(
f"{root.name}: declared resource 'gates.json' resolves outside the "
"country package."
)
if not resource_path.is_file():
raise ValueError(f"{root.name}: declared resource 'gates.json' is not a file.")
payload = _require_mapping(
json.loads(resource_path.read_text(encoding="utf-8")), context="gates.json"
)
return GatesManifest.from_mapping(payload, country=declared_country)


def load_country_spec(country: str | Path) -> ResolvedCountrySpec:
"""Load and validate the ``country`` package.

Expand Down
Loading
Loading