From 89217fcc9b265a51e79768149d8c2dfb561b6c6d Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Fri, 27 Nov 2026 18:52:34 +0400 Subject: [PATCH 01/11] Add failing tests for BE's release files and the spec release assembler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tracker 5b · 13. Tests, a fixture transport build folder and placeholder modules, so each test fails on an assertion: - the three files a spec country's build adds to the base three (source coverage, demographics, reform validation), on fixture calibration diagnostics and BE's spec; - an assembler that reads a transport build's output folder and writes the release directory microcosm-publish-release-build publishes; - a transport build recording its Microcosm commit, dirty flag and Python and package versions in build-status.json. Co-Authored-By: Claude Opus 5.5 --- .../microcosm/build/spec_release_assembly.py | 47 +++ .../src/microcosm/build/spec_release_files.py | 40 ++ .../src/microcosm/build/transport/cli.py | 21 + .../shared/test_spec_release_assembly.py | 316 +++++++++++++++ .../shared/test_spec_release_files.py | 230 +++++++++++ .../shared/test_transport_build_provenance.py | 86 +++++ .../shared/test_transport_composed_graph.py | 6 + test_support/microcosm_build/spec_release.py | 361 ++++++++++++++++++ 8 files changed, 1107 insertions(+) create mode 100644 packages/microcosm-build/src/microcosm/build/spec_release_assembly.py create mode 100644 packages/microcosm-build/src/microcosm/build/spec_release_files.py create mode 100644 packages/microcosm-build/tests/engine_free/shared/test_spec_release_assembly.py create mode 100644 packages/microcosm-build/tests/engine_free/shared/test_spec_release_files.py create mode 100644 packages/microcosm-build/tests/engine_free/shared/test_transport_build_provenance.py create mode 100644 test_support/microcosm_build/spec_release.py diff --git a/packages/microcosm-build/src/microcosm/build/spec_release_assembly.py b/packages/microcosm-build/src/microcosm/build/spec_release_assembly.py new file mode 100644 index 0000000000..7bb77b785b --- /dev/null +++ b/packages/microcosm-build/src/microcosm/build/spec_release_assembly.py @@ -0,0 +1,47 @@ +"""Assemble a spec country's transport build into a release build. + +Placeholder for tracker 5b · 13: the assembler is written in the next commit. +""" + +from __future__ import annotations + +import json +from collections.abc import Sequence +from dataclasses import dataclass +from pathlib import Path + +__all__ = [ + "AssembledRelease", + "SpecReleaseAssemblyError", + "assemble_spec_release", + "main", +] + + +class SpecReleaseAssemblyError(ValueError): + """The build cannot be assembled into a publishable release build.""" + + +@dataclass(frozen=True) +class AssembledRelease: + release: str + build: str + release_dir: Path + artifact_root: Path + publish_command: str + promote_command: str + + +def assemble_spec_release( + build_dir: Path | str, + *, + country: str, + out_dir: Path | str, + created_at: str | None = None, +) -> AssembledRelease: + return AssembledRelease("", "", Path(out_dir), Path(), "", "") + + +def main(argv: Sequence[str] | None = None) -> int: + print(json.dumps({"release_dir": "", "publish_command": "", "promote_command": ""})) + return 0 diff --git a/packages/microcosm-build/src/microcosm/build/spec_release_files.py b/packages/microcosm-build/src/microcosm/build/spec_release_files.py new file mode 100644 index 0000000000..28db89f3c8 --- /dev/null +++ b/packages/microcosm-build/src/microcosm/build/spec_release_files.py @@ -0,0 +1,40 @@ +"""The release files a spec country's build adds to the base three. + +Placeholder for tracker 5b · 13: the payload builders are written in the +next commit. +""" + +from __future__ import annotations + +from collections.abc import Mapping + +__all__ = [ + "demographics_payload", + "reform_validation_payload", + "source_coverage_payload", +] + + +def source_coverage_payload( + *, + country: str, + target_references: Mapping, + holdout_references: Mapping | None, + diagnostics: Mapping, + source_contract: Mapping[str, object], +) -> dict[str, object]: + return {} + + +def demographics_payload( + *, + country: str, + target_references: Mapping, + diagnostics: Mapping, + period: int, +) -> dict[str, object]: + return {} + + +def reform_validation_payload(*, country: str, period: int) -> dict[str, object]: + return {} diff --git a/packages/microcosm-build/src/microcosm/build/transport/cli.py b/packages/microcosm-build/src/microcosm/build/transport/cli.py index 5454feb4ca..ddff1fa8d0 100644 --- a/packages/microcosm-build/src/microcosm/build/transport/cli.py +++ b/packages/microcosm-build/src/microcosm/build/transport/cli.py @@ -86,6 +86,7 @@ __all__ = [ "EXPORT_FILENAME", + "TRANSPORT_RUNTIME_DISTRIBUTIONS", "PreparedTransportBuild", "execute_transport_graph", "main", @@ -93,6 +94,7 @@ "prepare_create_outputs", "prepare_transport_build", "through", + "transport_build_provenance", ] #: The skeleton's exported dataset, written under ``--out``. @@ -105,6 +107,25 @@ ) +#: The distributions whose versions a transport build records (tracker +#: 5b · 13). Placeholder: filled in the next commit. +TRANSPORT_RUNTIME_DISTRIBUTIONS: tuple[str, ...] = () + + +def transport_build_provenance( + *, checkout: str | Path | None = None +) -> dict[str, dict[str, object]]: + """Placeholder for tracker 5b · 13: written in the next commit.""" + return { + "code": { + "repository": "PolicyEngine/microcosm", + "git_commit": "", + "git_dirty": False, + }, + "runtime": {}, + } + + @dataclass(frozen=True) class PreparedTransportBuild: """A compiled-ready graph, its run registry and its local inputs.""" diff --git a/packages/microcosm-build/tests/engine_free/shared/test_spec_release_assembly.py b/packages/microcosm-build/tests/engine_free/shared/test_spec_release_assembly.py new file mode 100644 index 0000000000..d7a3cab10e --- /dev/null +++ b/packages/microcosm-build/tests/engine_free/shared/test_spec_release_assembly.py @@ -0,0 +1,316 @@ +"""Assembling a spec country's transport build into a release build (5b · 13). + +``microcosm.build.spec_release_assembly`` reads what a transport build wrote +under ``--out`` (its H5, export descriptor, calibration diagnostics, run +manifest and ``build-status.json``), as the UK national assembler reads its +candidate's outputs, and writes the release directory that +``microcosm-publish-release-build`` publishes: BE's six contract files, with +the H5 and its weights beside the build. These tests use fixture build +folders; no build runs and nothing reaches the Hub. +""" + +from __future__ import annotations + +import hashlib +import json +from pathlib import Path + +import numpy as np +import pytest + +from microcosm.build import release_publication +from microcosm.build.spec_release_assembly import ( + SpecReleaseAssemblyError, + assemble_spec_release, + main, +) +from microcosm.build.transport.cli import EXPORT_FILENAME +from microcosm.build.transport.compose import load_transport_spec +from microcosm.data.contract import BE_REQUIRED_RELEASE_FILES, validate_release_dir +from test_support.microcosm_build.emitter import FakeEmitterClient +from test_support.microcosm_build.spec_release import ( + BUILD_COMMIT, + BUILD_RUNTIME, + CLEAN_CODE, + FINISHED_STAMP, + GATE_NODES, + HOUSEHOLD_WEIGHTS, + demography_references, + write_transport_build_folder, +) + +CREATED_AT = "2026-12-02T08:00:00+00:00" +#: The files BE's release contract adds to the base three, by artifact key. +ADDED_FILES = { + "source_coverage": "source_coverage.json", + "demographics": "demographics.json", + "reform_validation": "reform_validation.json", +} + + +@pytest.fixture(scope="module") +def be_spec() -> dict: + return load_transport_spec("be") + + +def _sha256(path: Path) -> str: + return hashlib.sha256(path.read_bytes()).hexdigest() + + +def _read(path: Path) -> dict: + return json.loads(path.read_text()) + + +def _expected_build(be_spec: dict, period: int = 2026) -> str: + chronicle = be_spec["resources"]["chronicle_feed"]["source_commit"] + return f"microcosm-be-{period}-chronicle-{chronicle[:7]}-{FINISHED_STAMP}" + + +def test_a_be_build_assembles_into_its_release_with_all_six_files( + tmp_path: Path, be_spec: dict +) -> None: + build = write_transport_build_folder(tmp_path / "out") + releases = tmp_path / "releases" + + assembled = assemble_spec_release( + build.path, country="be", out_dir=releases, created_at=CREATED_AT + ) + + # The build's population year picks the release, and the build is named + # as BE's builder names it: year, Chronicle pin, when the run finished. + assert assembled.release == "microcosm-be-2026-national" + assert assembled.build == _expected_build(be_spec) + assert assembled.release_dir == releases / "microcosm-be-2026-national" + assert sorted(path.name for path in assembled.release_dir.iterdir()) == sorted( + BE_REQUIRED_RELEASE_FILES + ) + validate_release_dir(assembled.release_dir) + manifest = _read(assembled.release_dir / "release_manifest.json") + for key, filename in ADDED_FILES.items(): + assert manifest["artifacts"][key]["path"] == filename + assert manifest["artifacts"][key]["role"] == key + assert manifest["artifacts"][key]["sha256"] == _sha256( + assembled.release_dir / filename + ) + assert (manifest["release"], manifest["build"]) == ( + assembled.release, + assembled.build, + ) + assert manifest["default_datasets"] == {"national": "populace_be_2026"} + + +def test_the_dataset_and_its_weights_land_beside_the_build(tmp_path: Path) -> None: + build = write_transport_build_folder(tmp_path / "out") + + assembled = assemble_spec_release( + build.path, country="be", out_dir=tmp_path / "releases", created_at=CREATED_AT + ) + + # The publisher reads each declared file from the artifact root under + # the name the manifest gives it, as for the UK's candidate H5. + assert assembled.artifact_root == build.path + dataset = build.path / "populace_be_2026.h5" + assert dataset.read_bytes() == (build.path / EXPORT_FILENAME).read_bytes() + weights = np.load(build.path / "populace_be_2026_calibration.npz") + assert weights["household_weight"].tolist() == list(HOUSEHOLD_WEIGHTS) + assert weights["household_id"].tolist() == [1, 2, 3] + manifest = _read(assembled.release_dir / "release_manifest.json") + assert manifest["artifacts"]["populace_be_2026"]["sha256"] == _sha256(dataset) + assert manifest["artifacts"]["populace_be_2026"]["kind"] == "microdata" + assert manifest["artifacts"]["populace_be_2026_calibration"]["sha256"] == ( + _sha256(build.path / "populace_be_2026_calibration.npz") + ) + + +def test_the_build_manifest_records_what_the_build_ran_on( + tmp_path: Path, be_spec: dict +) -> None: + build = write_transport_build_folder(tmp_path / "out") + + assembled = assemble_spec_release( + build.path, country="be", out_dir=tmp_path / "releases", created_at=CREATED_AT + ) + + assert (assembled.release_dir / "build_manifest.json").is_file() + manifest = _read(assembled.release_dir / "build_manifest.json") + assert (manifest["release"], manifest["build"]) == ( + assembled.release, + assembled.build, + ) + assert manifest["code"] == CLEAN_CODE + assert manifest["build_sha"] == BUILD_COMMIT[:7] + assert manifest["runtime"] == BUILD_RUNTIME + packages = {name: version for name, version in BUILD_RUNTIME.items()} + python = packages.pop("python") + assert manifest["engines"] == { + "axiom_rules_engine": {"python": python, "packages": packages} + } + assert manifest["gates"]["outcomes"] == dict.fromkeys(GATE_NODES, "pass") + assert manifest["gates"]["known_failures"] == [] + assert manifest["population_year"] == 2026 + assert ( + manifest["chronicle"]["commit"] + == (be_spec["resources"]["chronicle_feed"]["source_commit"]) + ) + assert manifest["created_at"] == CREATED_AT + assert manifest["dataset"] == { + "filename": "populace_be_2026.h5", + "sha256": _sha256(build.path / EXPORT_FILENAME), + } + + +@pytest.fixture +def on_a_build_machine(monkeypatch) -> None: + """Run as on a machine that can reach the Hub, with a repository that has + switched to ``releases.json``: no pointer file is listed.""" + for name in ("HF_HUB_OFFLINE", "TRANSFORMERS_OFFLINE"): + monkeypatch.delenv(name, raising=False) + monkeypatch.setattr( + release_publication, "_repository_files", lambda _repository: [] + ) + + +@pytest.mark.usefixtures("on_a_build_machine") +def test_an_assembled_be_build_publishes_through_the_emitter( + tmp_path: Path, be_spec: dict +) -> None: + build = write_transport_build_folder(tmp_path / "out") + assembled = assemble_spec_release( + build.path, country="be", out_dir=tmp_path / "releases", created_at=CREATED_AT + ) + client = FakeEmitterClient() + assert assembled.release_dir.is_dir() + + outcome = release_publication.publish_release_build( + assembled.release_dir, artifact_root=assembled.artifact_root, client=client + ) + + (request,) = client.release_requests + assert ( + request.repository + == be_spec["resources"]["release_contract"]["hf"]["artifact_repo"] + ) + assert (request.release, request.build) == (assembled.release, assembled.build) + roles = {item.name: item.role for item in request.files} + for key, filename in ADDED_FILES.items(): + assert roles[filename] == key + assert roles["populace_be_2026.h5"] == "dataset" + assert roles["populace_be_2026_calibration.npz"] == "calibration_weights" + assert outcome.published and outcome.succeeded + + +@pytest.mark.parametrize( + ("folder_options", "refusal"), + [ + ({"not_yet_produced": ["The rent ageing ruling"]}, "still owes"), + ({"code": None}, "commit"), + ({"code": {**CLEAN_CODE, "git_dirty": True}}, "dirty"), + ({"code": {**CLEAN_CODE, "git_dirty": None}}, "dirty"), + ({"code": {**CLEAN_CODE, "git_commit": "abc1234"}}, "commit"), + ({"runtime": None}, "runtime"), + ({"runtime": {"python": "3.13.5"}}, "microcosm-data"), + ({"gate_outcome": "fail"}, "gate"), + ({"period": 2024}, "microcosm-be-2024-national"), + ], + ids=[ + "owed-outputs", + "no-code-record", + "dirty-checkout", + "unmeasured-checkout", + "short-commit", + "no-runtime-record", + "no-data-package-version", + "failed-gate", + "year-without-a-release", + ], +) +def test_assembly_refuses_a_build_it_cannot_publish_and_writes_nothing( + tmp_path: Path, folder_options: dict, refusal: str +) -> None: + build = write_transport_build_folder(tmp_path / "out", **folder_options) + releases = tmp_path / "releases" + before = sorted(path.name for path in build.path.iterdir()) + + with pytest.raises(SpecReleaseAssemblyError, match=refusal): + assemble_spec_release( + build.path, country="be", out_dir=releases, created_at=CREATED_AT + ) + + assert not releases.exists() or not any(releases.iterdir()) + assert sorted(path.name for path in build.path.iterdir()) == before + + +def test_assembly_refuses_a_dataset_that_changed_after_the_build( + tmp_path: Path, +) -> None: + build = write_transport_build_folder(tmp_path / "out") + dataset = build.path / EXPORT_FILENAME + dataset.write_bytes(dataset.read_bytes() + b"\0") + + with pytest.raises(SpecReleaseAssemblyError, match=EXPORT_FILENAME): + assemble_spec_release(build.path, country="be", out_dir=tmp_path / "releases") + + +def test_assembly_refuses_a_build_that_left_out_an_active_reference( + tmp_path: Path, +) -> None: + omitted = demography_references("be")[0]["name"] + build = write_transport_build_folder(tmp_path / "out", omit_targets=[omitted]) + + # The source coverage gate is a release gate: a hard-target reference the + # build did not calibrate stops the assembly. + with pytest.raises(SpecReleaseAssemblyError, match=omitted): + assemble_spec_release(build.path, country="be", out_dir=tmp_path / "releases") + + +def test_assembly_refuses_to_replace_an_earlier_assembly(tmp_path: Path) -> None: + build = write_transport_build_folder(tmp_path / "out") + releases = tmp_path / "releases" + assembled = assemble_spec_release(build.path, country="be", out_dir=releases) + assert (assembled.release_dir / "release_manifest.json").is_file() + manifest = (assembled.release_dir / "release_manifest.json").read_bytes() + + with pytest.raises(SpecReleaseAssemblyError, match="already exists"): + assemble_spec_release(build.path, country="be", out_dir=releases) + + assert (assembled.release_dir / "release_manifest.json").read_bytes() == manifest + + +def test_the_command_prints_the_publication_and_promotion_commands( + tmp_path: Path, capsys +) -> None: + build = write_transport_build_folder(tmp_path / "out") + releases = tmp_path / "releases" + + exit_code = main( + ["--build-dir", str(build.path), "--country", "be", "--out-dir", str(releases)] + ) + + assert exit_code == 0 + summary = json.loads(capsys.readouterr().out) + release_dir = releases / "microcosm-be-2026-national" + assert summary["release_dir"] == str(release_dir) + assert "microcosm-publish-release-build" in summary["publish_command"] + assert f"--artifact-root {build.path}" in summary["publish_command"] + assert "--promote" not in summary["publish_command"] + assert "--promote" in summary["promote_command"] + + +def test_the_command_exits_one_on_a_refused_build(tmp_path: Path, capsys) -> None: + build = write_transport_build_folder( + tmp_path / "out", not_yet_produced=["An owed output"] + ) + + exit_code = main( + [ + "--build-dir", + str(build.path), + "--country", + "be", + "--out-dir", + str(tmp_path / "releases"), + ] + ) + + assert exit_code == 1 + assert "still owes" in capsys.readouterr().err diff --git a/packages/microcosm-build/tests/engine_free/shared/test_spec_release_files.py b/packages/microcosm-build/tests/engine_free/shared/test_spec_release_files.py new file mode 100644 index 0000000000..c928719616 --- /dev/null +++ b/packages/microcosm-build/tests/engine_free/shared/test_spec_release_files.py @@ -0,0 +1,230 @@ +"""The three release files a spec country's build adds (tracker 5b · 13). + +BE's release contract requires ``source_coverage.json``, ``demographics.json`` +and ``reform_validation.json`` beside the three base files. These tests hold +their contents to what BE's spec declares and what the build's calibration +diagnostics record, on fixture diagnostics; no build runs. +""" + +from __future__ import annotations + +import pytest + +from microcosm.build.spec_release_files import ( + demographics_payload, + reform_validation_payload, + source_coverage_payload, +) +from microcosm.build.transport.compose import load_transport_spec +from test_support.microcosm_build.spec_release import ( + calibration_diagnostics, + demography_estimate, + demography_references, + demography_target, +) + +#: The fields of ``demographics.json``: the US file's, plus the country, the +#: cells it sums and whether they were calibrated. +DEMOGRAPHICS_FIELDS = { + "schema_version", + "country", + "period", + "measure", + "in_sample", + "total_population", + "benchmark_total_population", + "benchmark_source", + "age_bands", + "cells", +} +#: The fields of ``source_coverage.json``: the US file's, plus the country. +SOURCE_COVERAGE_FIELDS = { + "schema_version", + "classification", + "country", + "source_contract", + "gate", + "coverage_summary", + "hard_target_families", + "validation_only_families", + "source_gap_families", + "active_target_aliases", + "active_target_families", + "missing_hard_targets", + "reviewed_exclusions", + "validation_only_activated", +} + + +@pytest.fixture(scope="module") +def be_spec() -> dict: + return load_transport_spec("be") + + +def _source_coverage(be_spec: dict, diagnostics: dict) -> dict: + resources = be_spec["resources"] + return source_coverage_payload( + country="be", + target_references=resources["target_references"], + holdout_references=resources["holdout_references"], + diagnostics=diagnostics, + source_contract={"chronicle_commit": "a" * 40}, + ) + + +def test_demographics_reports_each_demography_cell_from_the_calibration_rows( + be_spec: dict, +) -> None: + references = demography_references("be") + payload = demographics_payload( + country="be", + target_references=be_spec["resources"]["target_references"], + diagnostics=calibration_diagnostics("be"), + period=2026, + ) + + assert DEMOGRAPHICS_FIELDS <= set(payload) + assert payload["schema_version"] == 1 + assert (payload["country"], payload["period"]) == ("be", 2026) + assert payload["measure"] == "person_weight" + # BE calibrates its demography, so the cells' fit is in-sample. + assert payload["in_sample"] is True + assert "Statbel" in payload["benchmark_source"] + cells = payload["cells"] + assert [cell["target"] for cell in cells] == [ref["name"] for ref in references] + first, selector = cells[0], references[0]["ledger_selector"] + assert first["geography_level"] == selector["geography_level"] + assert first["geography_id"] == selector["geography_id"] + assert first["dimensions"] == selector["dimension_values"] + assert first["population"] == pytest.approx(demography_estimate(0)) + assert first["benchmark"] == pytest.approx(demography_target(0)) + assert first["relative_error"] == pytest.approx(0.01) + populations = [demography_estimate(index) for index in range(len(references))] + benchmarks = [demography_target(index) for index in range(len(references))] + assert payload["total_population"] == pytest.approx(sum(populations)) + assert payload["benchmark_total_population"] == pytest.approx(sum(benchmarks)) + + +def test_demographics_sums_the_cells_into_age_bands_in_spec_order( + be_spec: dict, +) -> None: + references = demography_references("be") + payload = demographics_payload( + country="be", + target_references=be_spec["resources"]["target_references"], + diagnostics=calibration_diagnostics("be"), + period=2026, + ) + + assert DEMOGRAPHICS_FIELDS <= set(payload) + bands: dict[str, list[int]] = {} + for index, reference in enumerate(references): + band = reference["ledger_selector"]["dimension_values"]["person.age_band"] + bands.setdefault(band, []).append(index) + rows = payload["age_bands"] + assert [row["label"] for row in rows] == list(bands) + for row in rows: + indexes = bands[row["label"]] + assert row["population"] == pytest.approx( + sum(demography_estimate(index) for index in indexes) + ) + assert row["benchmark"] == pytest.approx( + sum(demography_target(index) for index in indexes) + ) + assert sum(row["share"] for row in rows) == pytest.approx(1.0) + assert sum(row["benchmark_share"] for row in rows) == pytest.approx(1.0) + + +def test_demographics_leaves_a_cell_the_build_did_not_calibrate_unmeasured( + be_spec: dict, +) -> None: + omitted = demography_references("be")[0]["name"] + payload = demographics_payload( + country="be", + target_references=be_spec["resources"]["target_references"], + diagnostics=calibration_diagnostics("be", omit=[omitted]), + period=2026, + ) + + assert DEMOGRAPHICS_FIELDS <= set(payload) + (cell,) = [cell for cell in payload["cells"] if cell["target"] == omitted] + assert (cell["population"], cell["benchmark"], cell["relative_error"]) == ( + None, + None, + None, + ) + # Without every cell the totals are unknown, not a partial sum. + assert payload["total_population"] is None + assert payload["benchmark_total_population"] is None + + +def test_source_coverage_lists_the_spec_families_by_role(be_spec: dict) -> None: + resources = be_spec["resources"] + payload = _source_coverage(be_spec, calibration_diagnostics("be")) + + assert SOURCE_COVERAGE_FIELDS <= set(payload) + assert payload["schema_version"] == 1 + assert payload["classification"] == "release_gate" + assert payload["country"] == "be" + assert payload["source_contract"]["name"] == "be_source_coverage" + assert payload["source_contract"]["chronicle_commit"] == "a" * 40 + assert payload["gate"] == { + "name": "be_source_coverage", + "passed": True, + "failures": [], + } + # Active calibration families are hard targets; families whose + # references are all parked are source gaps; held-out families are + # validation-only. + assert set(payload["hard_target_families"]) == {"statbel.demography"} + target_categories = set(resources["target_references"]["hierarchy"]["categories"]) + assert set(payload["source_gap_families"]) == target_categories - { + "statbel.demography" + } + assert set(payload["validation_only_families"]) == set( + resources["holdout_references"]["hierarchy"]["categories"] + ) + demography = payload["hard_target_families"]["statbel.demography"] + assert set(demography["package_aliases"]) == { + reference["name"] for reference in demography_references("be") + } + assert payload["missing_hard_targets"] == [] + + +def test_source_coverage_fails_when_the_build_left_out_an_active_reference( + be_spec: dict, +) -> None: + omitted = demography_references("be")[3]["name"] + payload = _source_coverage(be_spec, calibration_diagnostics("be", omit=[omitted])) + + assert SOURCE_COVERAGE_FIELDS <= set(payload) + assert payload["gate"]["passed"] is False + assert payload["missing_hard_targets"] == [omitted] + + +def test_source_coverage_fails_when_the_build_calibrated_a_held_out_reference( + be_spec: dict, +) -> None: + holdout = be_spec["resources"]["holdout_references"]["target_references"][0] + diagnostics = calibration_diagnostics("be") + row = dict(diagnostics["targets"][0]) + row["name"], row["target_name"] = f"{holdout['name']}@2026", holdout["name"] + diagnostics["targets"].append(row) + + payload = _source_coverage(be_spec, diagnostics) + + assert SOURCE_COVERAGE_FIELDS <= set(payload) + assert payload["gate"]["passed"] is False + assert holdout["category_id"] in payload["validation_only_activated"] + + +def test_reform_validation_carries_no_reforms_yet() -> None: + # No scored BE reform exists until microcosm#264; nothing was simulated. + assert reform_validation_payload(country="be", period=2026) == { + "schema_version": 1, + "country": "be", + "baseline_period": 2026, + "scoring_window": None, + "out_of_sample_simulated": False, + "reforms": [], + } diff --git a/packages/microcosm-build/tests/engine_free/shared/test_transport_build_provenance.py b/packages/microcosm-build/tests/engine_free/shared/test_transport_build_provenance.py new file mode 100644 index 0000000000..ea089e7b7b --- /dev/null +++ b/packages/microcosm-build/tests/engine_free/shared/test_transport_build_provenance.py @@ -0,0 +1,86 @@ +"""A transport build records the code and runtime it ran on (tracker 5b · 13). + +The release validator requires each build to record its Microcosm commit, +from a clean checkout, and its Python version. US and UK builds record them +while building, and their release steps read them from the build's records. +``build-status.json`` carries the same record for a transport build, so the +spec release assembler reads it there. +""" + +from __future__ import annotations + +import platform +import subprocess +from importlib import metadata +from pathlib import Path + +from microcosm.build.transport.cli import ( + TRANSPORT_RUNTIME_DISTRIBUTIONS, + transport_build_provenance, +) +from test_support.git_repositories import NO_BACKGROUND_MAINTENANCE + + +def _git(repository: Path, *arguments: str) -> str: + return subprocess.run( + ["git", *NO_BACKGROUND_MAINTENANCE, *arguments], + cwd=repository, + check=True, + capture_output=True, + text=True, + ).stdout.strip() + + +def _repository(root: Path) -> Path: + root.mkdir() + _git(root, "init", "--quiet") + _git(root, "config", "user.email", "fixture@example.com") + _git(root, "config", "user.name", "Fixture") + (root / "module.py").write_text("VALUE = 1\n") + _git(root, "add", "module.py") + _git(root, "commit", "--quiet", "-m", "Fixture commit") + return root + + +def test_a_clean_checkout_records_its_commit_as_clean(tmp_path: Path) -> None: + repository = _repository(tmp_path / "checkout") + + provenance = transport_build_provenance(checkout=repository) + + assert provenance["code"] == { + "repository": "PolicyEngine/microcosm", + "git_commit": _git(repository, "rev-parse", "HEAD"), + "git_dirty": False, + } + + +def test_a_tracked_change_records_the_checkout_as_dirty(tmp_path: Path) -> None: + repository = _repository(tmp_path / "checkout") + (repository / "module.py").write_text("VALUE = 2\n") + + provenance = transport_build_provenance(checkout=repository) + + assert provenance["code"]["git_dirty"] is True + + +def test_a_directory_outside_git_records_the_commit_as_unmeasured( + tmp_path: Path, +) -> None: + outside = tmp_path / "not-a-checkout" + outside.mkdir() + + provenance = transport_build_provenance(checkout=outside) + + # Unmeasured, never asserted clean: the assembler refuses it. + assert provenance["code"]["git_commit"] is None + assert provenance["code"]["git_dirty"] is None + + +def test_the_runtime_records_python_and_each_distribution(tmp_path: Path) -> None: + provenance = transport_build_provenance(checkout=tmp_path) + + runtime = provenance["runtime"] + assert runtime.get("python") == platform.python_version() + assert set(runtime) == {"python", *TRANSPORT_RUNTIME_DISTRIBUTIONS} + assert runtime["microcosm-build"] == metadata.version("microcosm-build") + assert "axiom-rules-engine" in TRANSPORT_RUNTIME_DISTRIBUTIONS diff --git a/packages/microcosm-build/tests/engine_free/shared/test_transport_composed_graph.py b/packages/microcosm-build/tests/engine_free/shared/test_transport_composed_graph.py index 916e014f8f..a5245c92ee 100644 --- a/packages/microcosm-build/tests/engine_free/shared/test_transport_composed_graph.py +++ b/packages/microcosm-build/tests/engine_free/shared/test_transport_composed_graph.py @@ -69,6 +69,7 @@ prepare_create_outputs, prepare_transport_build, through, + transport_build_provenance, ) from microcosm.build.transport.compose import ( TransportGraphConfig, @@ -2652,6 +2653,11 @@ def test_cli_checkpoints_write_only_under_out_and_resume_warm(composed, tmp_path assert {"graph", "skeleton_dataset", "calibration_diagnostics", "explorer"} <= set( status["produced"] ) + # The build records the code and runtime it ran on, for the release + # assembler (tracker 5b · 13). + provenance = transport_build_provenance() + assert status.get("code") == provenance["code"] + assert status.get("runtime") == provenance["runtime"] for name in ( "checkpoint-geography.json", "checkpoint-calibration.json", diff --git a/test_support/microcosm_build/spec_release.py b/test_support/microcosm_build/spec_release.py new file mode 100644 index 0000000000..353f3d9897 --- /dev/null +++ b/test_support/microcosm_build/spec_release.py @@ -0,0 +1,361 @@ +"""A spec country's transport build folder, for the release assembler's tests. + +:func:`write_transport_build_folder` writes the files that +``microcosm.build.transport.cli`` writes under ``--out`` and that the release +assembler (``microcosm.build.spec_release_assembly``) reads: the H5 the export +step writes, its export descriptor, the schema 9 calibration diagnostics, the +run manifest and ``build-status.json``. The tables, rows and receipts are +small and synthetic, and no graph runs. The calibration rows are the +country's executable demography references, read from its spec, so the +release files see the target names a build of that spec compiles. +""" + +from __future__ import annotations + +import json +from collections.abc import Mapping, Sequence +from dataclasses import dataclass +from pathlib import Path + +import numpy as np +import pandas as pd + +from microcosm.build.artifact_files import file_artifact +from microcosm.build.transport.cli import EXPORT_FILENAME +from microcosm.build.transport.compose import load_transport_spec +from microcosm.build.transport.terminal_kernels import ( + _EXPORT_KIND, + _content, +) +from microcosm.diagnostics import ( + CalibrationDiagnosticsV8, + catalog_calibration_diagnostics, +) +from microcosm.frame.adapters.axiom import AxiomEntityTableDataset +from microcosm.graph import ( + Capabilities, + Determinism, + KernelRole, + NodeReceipt, + RunManifest, + SeedSource, + StructuralDelta, +) + +#: The Microcosm commit a fixture build records that it ran at. +BUILD_COMMIT = "5fa48f07436a806ad75ff76fd22cfb8613bddbe0" +#: When a fixture build's run finished, and the build-ID stamp it gives. +FINISHED_AT = "2026-12-01T10:20:30+00:00" +FINISHED_STAMP = "20261201T102030Z" +#: The Python and package versions a fixture build records. +BUILD_RUNTIME = { + "python": "3.13.5", + "microcosm-build": "0.1.0", + "microcosm-data": "0.1.0", + "numpy": "2.4.6", + "pandas": "3.0.3", + "axiom-rules-engine": "0.4.0", +} +#: The code record of a fixture build run from a clean checkout. +CLEAN_CODE = { + "repository": "PolicyEngine/microcosm", + "git_commit": BUILD_COMMIT, + "git_dirty": False, +} +#: The node IDs of the fixture run's gates. +GATE_NODES = ("be.gates.battery", "be.export.readback") +#: A fixture build's household weights, one per household. +HOUSEHOLD_WEIGHTS = (1250.5, 980.25, 2010.0) + + +@dataclass(frozen=True) +class TransportBuildFolder: + """A fixture build folder and what a test needs to know about it.""" + + path: Path + country: str + period: int + demography_targets: tuple[str, ...] + + +def _executable(reference: Mapping) -> bool: + status = reference.get("metadata", {}).get("activation_status", "") + return status in {"", "active"} + + +def demography_references(country: str = "be") -> tuple[Mapping, ...]: + """The country's executable demography references, in spec order.""" + references = load_transport_spec(country)["resources"]["target_references"] + return tuple( + reference + for reference in references["target_references"] + if reference.get("family") == "demography" and _executable(reference) + ) + + +def _hierarchy(reference: Mapping, labels: Mapping) -> dict: + selector = reference["ledger_selector"] + category = labels["categories"][reference["category_id"]] + provider_id = category["provider_id"] + return { + "provider": { + "id": provider_id, + "label": labels["providers"][provider_id]["label"], + }, + "category": { + "id": reference["category_id"], + "label": category["label"], + "provider_id": provider_id, + }, + "geography": { + "id": selector["geography_id"], + "label": selector["geography_id"], + "level": selector["geography_level"], + }, + "dimensions": [ + { + "id": dimension, + "label": dimension, + "value_id": value, + "value_label": value, + } + for dimension, value in selector["dimension_values"].items() + ], + "target": {"id": reference["name"], "label": reference["name"]}, + } + + +def demography_target(index: int) -> float: + """The benchmark a fixture row gives the demography reference at ``index``.""" + return 100_000.0 + 1_000.0 * index + + +def demography_estimate(index: int) -> float: + """The calibrated estimate a fixture row gives the reference at ``index``.""" + return demography_target(index) * 1.01 + + +def calibration_diagnostics( + country: str = "be", + *, + period: int = 2026, + omit: Sequence[str] = (), +) -> dict: + """Schema 9 diagnostics with one row per executable demography reference. + + A reference ``omit`` names has no row, as if the build had not + calibrated it. + """ + labels = load_transport_spec(country)["resources"]["target_references"]["hierarchy"] + rows = [] + for index, reference in enumerate(demography_references(country)): + if reference["name"] in omit: + continue + target = demography_target(index) + rows.append( + { + "name": f"{reference['name']}@{period}", + "target_name": reference["name"], + "period": period, + "entity": reference["entity"], + "measure": {"kind": "column", "name": reference["measure"]}, + "filter": {"kind": "column", "name": reference["filter"]}, + "source": "Fixture Chronicle fact", + "metadata": {}, + "target": target, + "compiled_target": target, + "initial_estimate": target * 0.9, + "final_estimate": demography_estimate(index), + "relative_error": 0.01, + "within_tolerance": True, + "registry": { + "family": reference["family"], + "se": None, + "signed": False, + "notes": "", + }, + "hierarchy": _hierarchy(reference, labels), + } + ) + diagnostics = { + "schema_version": 8, + "weight_entity": "household", + "options": {"epochs": 120}, + "target_surface": { + "schema_version": 1, + "weight_entity": "household", + "n_targets": len(rows), + "n_records": len(HOUSEHOLD_WEIGHTS), + "constraint_matrix": { + "rows": len(rows), + "columns": len(HOUSEHOLD_WEIGHTS), + "nnz": len(rows), + }, + "sha256": "e" * 64, + "names_sha256": "b" * 64, + "values_sha256": "f" * 64, + }, + "target_registry": { + "country": country, + "version": "registryabc123", + "n_specs": len(rows), + }, + "loss_trajectory": [1.0, 0.5], + "skipped": [], + "targets": rows, + "l0_lambda": 0.0, + "n_nonzero": len(HOUSEHOLD_WEIGHTS), + "n_records": len(HOUSEHOLD_WEIGHTS), + "initial_loss": 1.0, + "final_loss": 0.5, + "fraction_within_10pct": 1.0, + "effective_sample_size": 2.5, + "realized_max_weight_ratio": 1.5, + "top_1pct_weight_share": 0.4, + "past_cap_census": None, + "diagnostic_warnings": [], + } + model = CalibrationDiagnosticsV8.model_validate(diagnostics) + return json.loads( + catalog_calibration_diagnostics(model).model_dump_json(exclude_defaults=True) + ) + + +def _tables() -> dict[str, pd.DataFrame]: + households = len(HOUSEHOLD_WEIGHTS) + return { + "household": pd.DataFrame( + { + "household_id": np.arange(1, households + 1, dtype=np.int64), + "household_weight": np.asarray(HOUSEHOLD_WEIGHTS, dtype=np.float64), + } + ), + "person": pd.DataFrame( + { + "person_id": np.arange(1, 2 * households + 1, dtype=np.int64), + "person_household_id": np.repeat( + np.arange(1, households + 1, dtype=np.int64), 2 + ), + "age": np.asarray([34, 5, 71, 68, 45, 17], dtype=np.int64), + } + ), + } + + +def export_descriptor(tables: Mapping[str, pd.DataFrame], period: int) -> dict: + """The descriptor ``export.prepare@1`` gives these tables.""" + entities = tuple(tables) + return { + "schema_version": 1, + "kind": _EXPORT_KIND, + **_content(tables, entities=entities, time_period=period), + "weight_entity": "household", + "weight_kind": "calibrated", + "bindings": {}, + "graph_only": ["strata", "metadata", "mass_log", "weight_kind"], + } + + +def _capabilities(role: KernelRole) -> Capabilities: + return Capabilities( + determinism=Determinism.DETERMINISTIC, + seed_source=SeedSource.NONE, + structural=StructuralDelta.NONE, + role=role, + dependencies=("numpy",), + ) + + +def run_manifest(country: str, *, gate_outcome: str = "pass") -> RunManifest: + """A run manifest whose gate nodes record ``gate_outcome``.""" + nodes = { + node_id: NodeReceipt( + key=f"{index:x}" * 64, + hit=False, + seed=0, + kernel_ref="gates.battery@1", + kernel_impl_hash="c" * 64, + capabilities=_capabilities(KernelRole.GATE), + receipt={"outcome": gate_outcome}, + ) + for index, node_id in enumerate(GATE_NODES, start=1) + } + nodes["be.calibrate"] = NodeReceipt( + key="d" * 64, + hit=False, + seed=0, + kernel_ref="calibrate.ordered_adam@1", + kernel_impl_hash="c" * 64, + capabilities=_capabilities(KernelRole.COMPUTE), + receipt={}, + ) + return RunManifest( + country=country, + nodes=nodes, + started_at="2026-12-01T09:00:00+00:00", + finished_at=FINISHED_AT, + host="fixture-host", + ) + + +def _write_json(path: Path, payload: object) -> None: + path.write_text(json.dumps(payload, indent=1) + "\n") + + +def write_transport_build_folder( + root: Path, + *, + country: str = "be", + period: int = 2026, + code: Mapping[str, object] | None = CLEAN_CODE, + runtime: Mapping[str, str] | None = BUILD_RUNTIME, + not_yet_produced: Sequence[str] = (), + gate_outcome: str = "pass", + omit_targets: Sequence[str] = (), +) -> TransportBuildFolder: + """Write a transport build folder under ``root`` and describe it. + + ``code`` and ``runtime`` are what ``build-status.json`` records the build + ran on (by default a clean checkout at :data:`BUILD_COMMIT`); None + leaves a record out, as a build before tracker 5b · 13 did. + ``not_yet_produced`` lists the outputs the build says it still owes, and + ``gate_outcome`` is every gate node's outcome. + """ + root.mkdir(parents=True, exist_ok=True) + tables = _tables() + dataset = root / EXPORT_FILENAME + AxiomEntityTableDataset(tables=tables, time_period=period).save(dataset) + _write_json(root / "export-descriptor.json", export_descriptor(tables, period)) + diagnostics_path = root / "calibration-diagnostics.json" + _write_json( + diagnostics_path, + calibration_diagnostics(country, period=period, omit=omit_targets), + ) + (root / "manifest.json").write_bytes( + run_manifest(country, gate_outcome=gate_outcome).to_json_bytes() + ) + status: dict[str, object] = { + "schema_version": 1, + "country": country, + "local_only": True, + "content_basis": "Transported donor support records reweighted to " + "destination facts; not observed destination microdata.", + "produced": { + "skeleton_dataset": file_artifact(dataset), + "calibration_diagnostics": file_artifact(diagnostics_path), + }, + "not_yet_produced": list(not_yet_produced), + } + if code is not None: + status["code"] = dict(code) + if runtime is not None: + status["runtime"] = dict(runtime) + _write_json(root / "build-status.json", status) + return TransportBuildFolder( + path=root, + country=country, + period=period, + demography_targets=tuple( + reference["name"] for reference in demography_references(country) + ), + ) From 317c0ffd89392cb46733323b5161ff147f399932 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Fri, 27 Nov 2026 19:01:16 +0400 Subject: [PATCH 02/11] Write BE's release files and assemble transport builds into release builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tracker 5b · 13 (microcosm#1800). A new BE build must carry the six files BE's release contract lists, and nothing wrote source_coverage.json, demographics.json or reform_validation.json, so no BE build could publish. - microcosm.build.spec_release_files builds the three files from the country's spec and the build's calibration diagnostics: source coverage with the US file's fields over the spec's target categories, the demography references' calibrated cells and age bands, and a reform validation with no reforms yet. - microcosm.build.spec_release_assembly (tools/assemble_spec_release_dir.py) reads a transport build's --out folder as the UK national assembler reads its candidate's outputs, refuses a build it cannot publish, writes the release directory with the H5 and its weights beside the build, validates it and prints the publish and promote commands. It uploads nothing. - A transport build's build-status.json records the Microcosm commit, whether the checkout was clean, and the Python and package versions. Co-Authored-By: Claude Opus 5.5 --- ...800-be-release-files-and-assembly.added.md | 7 + docs/agent-guide.md | 8 +- docs/release-contract.md | 23 + .../microcosm/build/spec_release_assembly.py | 802 +++++++++++++++++- .../src/microcosm/build/spec_release_files.py | 361 +++++++- .../src/microcosm/build/transport/cli.py | 81 +- tools/assemble_spec_release_dir.py | 6 + 7 files changed, 1268 insertions(+), 20 deletions(-) create mode 100644 changelog.d/1800-be-release-files-and-assembly.added.md create mode 100644 tools/assemble_spec_release_dir.py diff --git a/changelog.d/1800-be-release-files-and-assembly.added.md b/changelog.d/1800-be-release-files-and-assembly.added.md new file mode 100644 index 0000000000..3aad08ccf6 --- /dev/null +++ b/changelog.d/1800-be-release-files-and-assembly.added.md @@ -0,0 +1,7 @@ +A spec country's transport build can now be assembled into a release build that `microcosm-publish-release-build` publishes, with the three files BE's release contract adds to the base three (microcosm#1800). Until now nothing wrote `source_coverage.json`, `demographics.json` or `reform_validation.json` for BE, so no new BE build could pass the contract #1744 put in force. + +- **The release files.** `microcosm.build.spec_release_files` builds each from the country's spec and the build's calibration diagnostics, reading no population. `source_coverage.json` has the US file's fields under the contract name `be_source_coverage`: each target category with an executable calibration reference is a hard target, each whose references are all parked is a source gap, and each held-out category is validation-only; the check fails when the build left out an executable reference or calibrated a held-out one. `demographics.json` has the US file's fields for the spec's demography references (BE: Statbel population by NUTS1 region, sex and age band), with each cell's calibrated population and benchmark and their sums by age band; BE calibrates these cells, so the file reports in-sample fit (`in_sample` true). `reform_validation.json` lists no reforms and records `out_of_sample_simulated` false until scored BE reforms exist (microcosm#264). +- **The release step.** `tools/assemble_spec_release_dir.py --build-dir --country be` (`microcosm.build.spec_release_assembly`) reads what the transport build wrote, as the UK national assembler reads its candidate's outputs. It refuses a build that still owes outputs, records no clean Microcosm commit or no runtime, has an H5 or diagnostics file that changed after the build wrote it or an H5 that does not read back against its descriptor, has a gate that did not pass, or has a year with no release that publishes into build folders. It writes `releases//` with each file the release contract requires, puts the H5 (`populace_be_.h5`) and a weights file from its household table (`populace_be__calibration.npz`) beside the build, validates the directory with the release contract, and prints the publish and promote commands. It uploads nothing. The build is named `microcosm-be--chronicle--`. +- **Transport builds record what they ran on.** `build-status.json` now records the Microcosm commit, whether a tracked file differed from it, and the Python and package versions (`transport_build_provenance`), which the release contract requires of every build. + +Out of scope: a BE transport graph (BE's spec declares none yet, so no BE build runs through the release step until it does), scored BE reforms, and a BE registry entry or staging. diff --git a/docs/agent-guide.md b/docs/agent-guide.md index 45f8d6735f..6f61d63d1d 100644 --- a/docs/agent-guide.md +++ b/docs/agent-guide.md @@ -388,6 +388,10 @@ chooses the tier (certified, or `--evidence-release`), runs the release's post-export checks, places the build in that tier's release directory, writes the manifests and prints both commands (microcosm#1585 item 11). The ACS package stage prints both commands itself. +A spec country's transport build (BE's releases) goes through +`tools/assemble_spec_release_dir.py`, which reads the build's `--out` folder, +writes the release directory with the files the country's release contract +lists and prints both commands (microcosm#1800). `tools/preflight_us_release_gates.py` runs the US national release checks that need no calibration on the base before a build, and again with the finished build's `--release-manifest`. The emitter changes @@ -707,7 +711,9 @@ The transport build driver (`tools/build_transport.py`, a shim over `microcosm.build.transport.cli`) composes a country's graph from its `transport_graph.json` spec resource and runs it locally: every file it writes, including its `.graph-store`, lies under `--out`, and it has no -upload or staging path. Before it opens the store it refuses any link in an +upload or staging path. Its `build-status.json` records the Microcosm +commit, whether a tracked file differed from it, and the Python and package +versions the build ran on, which the release step reads. Before it opens the store it refuses any link in an existing store tree (the root, `objects`, `tmp` or a shard), because the store creates those directories by following links; it does not guard against links planted while a build is running. Activation checks run before diff --git a/docs/release-contract.md b/docs/release-contract.md index e768e5c378..70e32802f0 100644 --- a/docs/release-contract.md +++ b/docs/release-contract.md @@ -1123,6 +1123,29 @@ work. BE builder in this repository stages and the collector registers no BE staging repository; a BE build whose manifest records no staging is not refused for it. + - *BE's release files and release step* (microcosm#1800). A BE build's + three added files come from `microcosm.build.spec_release_files`, which + reads only the country's spec and the build's calibration diagnostics: + `source_coverage.json` has the US file's fields under the contract name + `be_source_coverage`, with the spec's target categories as its source + families; `demographics.json` has the US file's fields for the spec's + demography references, whose fit is in-sample because BE calibrates + them; and `reform_validation.json` lists no reforms, with + `out_of_sample_simulated` false, until microcosm#264. The release step + for a transport build, `tools/assemble_spec_release_dir.py` + (`microcosm.build.spec_release_assembly`), reads the build's `--out` + folder as the UK national assembler reads its candidate's outputs: + `build-status.json` (nothing owed; a clean Microcosm commit and the + runtime, which a transport build records there), the H5 read back + against its export descriptor, the calibration diagnostics and the run + manifest (every gate passed). It writes `//` with each + file the country's release contract requires, puts the H5 and a weights + file beside the build under the manifests' names, validates the + directory and prints the publish and promote commands; it uploads + nothing. The release is `microcosm---national` for the + export's year, and only a name `publishes_to_build_folder` admits is + taken. BE's spec declares no transport graph yet, so no BE build runs + through this step until it does. - *The first build of a new UK `k`* (2026-11-13). `validate_release_dir` refuses every layout of a local-area release until a registry entry names it, and `build_folder_identity` and `microcosm-publish-release-build` diff --git a/packages/microcosm-build/src/microcosm/build/spec_release_assembly.py b/packages/microcosm-build/src/microcosm/build/spec_release_assembly.py index 7bb77b785b..9675a1d9c8 100644 --- a/packages/microcosm-build/src/microcosm/build/spec_release_assembly.py +++ b/packages/microcosm-build/src/microcosm/build/spec_release_assembly.py @@ -1,22 +1,102 @@ """Assemble a spec country's transport build into a release build. -Placeholder for tracker 5b · 13: the assembler is written in the next commit. +The release step for a country whose builds run through the spec-driven +transport command (:mod:`microcosm.build.transport.cli`), as +``tools/assemble_uk_release_dir.py`` is for the UK national release and +``tools/certify_us_national_build.py`` for the US national one (tracker +5b · 13). Like them it reads the build's own outputs, here what the transport +command wrote under ``--out``: + +- ``build-status.json``: the outputs the build still owes (it refuses unless + there are none), the Microcosm commit and the Python and package versions + the build ran on, and the digests of the H5 and the diagnostics it wrote; +- ``skeleton.h5`` and ``export-descriptor.json``: the population, read back + against its descriptor, and its period and weight entity; +- ``calibration-diagnostics.json``: the calibration's diagnostics; +- ``manifest.json``: the run manifest, whose gate nodes must all have passed. + +From the country's spec it reads the release contract (the dataset file name, +the release repository and the required files), the target and holdout +references and the Chronicle pin. It then writes the release directory +``//``, holding each file the contract requires +(:mod:`microcosm.build.spec_release_files` writes the source coverage, the +demographics and the reform validation), puts the H5 and a weights file +beside the build under the names the manifests give them, validates the +directory with the release contract and prints the +``microcosm-publish-release-build`` commands that publish the build and then +make it current. Nothing is uploaded. + +The release is ``microcosm---national`` for the export's +period, refused unless :func:`microcosm.data.contract.publishes_to_build_folder` +admits it. The build is ``microcosm---chronicle--