From 840511888036d37a88198e74d09045f8e8ab43ad Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Fri, 20 Nov 2026 07:35:54 +0000 Subject: [PATCH 1/2] Let an entitlement document place its cell-diagnostics checkpoint The entitlement extension always appended the cell-diagnostics collector after the document's checkpoints, and composition refuses duplicate checkpoints, so a document could not list the collector itself. A document that lists a gate battery as a checkpoint then ran the collector inside that battery's checkpoint, and a raise there lost the collector's manifest. The extension now appends the collector only when the document does not list it. A document that omits it keeps it as the final checkpoint. Co-Authored-By: Claude Fable 5.2 --- ...port-entitlement-checkpoint-order.fixed.md | 1 + docs/transport-entitlement.md | 2 +- .../microcosm/build/transport/entitlement.py | 6 +- .../test_transport_entitlement_graph.py | 105 +++++++++++++++++- 4 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 changelog.d/transport-entitlement-checkpoint-order.fixed.md diff --git a/changelog.d/transport-entitlement-checkpoint-order.fixed.md b/changelog.d/transport-entitlement-checkpoint-order.fixed.md new file mode 100644 index 0000000000..f6b85e078b --- /dev/null +++ b/changelog.d/transport-entitlement-checkpoint-order.fixed.md @@ -0,0 +1 @@ +An entitlement document can now list its cell-diagnostics collector (`.cell_diagnostics`) among its own checkpoints, for example ahead of the gate battery it feeds, so the collector's checkpoint manifest is written before that battery's checkpoint runs. Listing it used to stop composition with "Extension checkpoints must name distinct nodes.", because the extension always appended the collector as a final checkpoint. A document that does not list it keeps it as the final checkpoint. diff --git a/docs/transport-entitlement.md b/docs/transport-entitlement.md index 4f67cb24a4..efd4a6cf7d 100644 --- a/docs/transport-entitlement.md +++ b/docs/transport-entitlement.md @@ -15,7 +15,7 @@ driver install it automatically. Its fields are: | `scenario_gap`, `variant_gap` | Gap producer id templates for the two tiers. | | `bands` | `id`, `population`, `baseline_scenario`; all declared scenario gaps become typed inputs. | | `package` | Final skeleton receipt `id`, bands `artifact_name`, optional additional `inputs` in the ordinary artifact-edge grammar. | -| `sources`, `checkpoints` | Additional sources with new names and ordered pre-export endpoints. The bands node is the default checkpoint. | +| `sources`, `checkpoints` | Additional sources with new names and ordered pre-export endpoints. The bands node is the default checkpoint. With a cell-support gate, `.cell_diagnostics` is also a checkpoint: the final one unless the document lists it. | Activation checks resource selections in the common nodes and each scenario's selected nodes, using the entitlement factory's row selection. A scenario's diff --git a/packages/microcosm-build/src/microcosm/build/transport/entitlement.py b/packages/microcosm-build/src/microcosm/build/transport/entitlement.py index 473bfad892..40ed67f541 100644 --- a/packages/microcosm-build/src/microcosm/build/transport/entitlement.py +++ b/packages/microcosm-build/src/microcosm/build/transport/entitlement.py @@ -676,7 +676,11 @@ def entitlement_extension(spec: Mapping) -> TransportExtension: "cell_diagnostics", collector, "cell_diagnostics", CELL_DIAGNOSTICS_TYPE ) ) - checkpoints += (collector,) + # A document may place the collector among its own checkpoints, for + # example ahead of the gate battery it feeds; otherwise it is the + # last checkpoint. + if collector not in checkpoints: + checkpoints += (collector,) screen_gate = cell_contract[0] for row in transport_resource(spec, "transport_graph")["nodes"]: if ( diff --git a/packages/microcosm-build/tests/engine_free/shared/test_transport_entitlement_graph.py b/packages/microcosm-build/tests/engine_free/shared/test_transport_entitlement_graph.py index e49d97ea1a..ca0d71d615 100644 --- a/packages/microcosm-build/tests/engine_free/shared/test_transport_entitlement_graph.py +++ b/packages/microcosm-build/tests/engine_free/shared/test_transport_entitlement_graph.py @@ -17,8 +17,10 @@ from hypothesis import HealthCheck, example, given, settings from hypothesis import strategies as st +from microcosm.build.transport.cli import execute_transport_graph from microcosm.build.transport.compose import ( compose_transport_graph, + transport_endpoints, validate_transport_activation, ) from microcosm.build.transport.entitlement import _gate_evidence, entitlement_extension @@ -29,7 +31,7 @@ reporting_cell_declarations, ) from microcosm.frame.concepts import SOURCE_HOUSEHOLD_ID_COLUMN -from microcosm.graph import compile_graph, graph_to_json +from microcosm.graph import NodeRejectedError, compile_graph, graph_to_json from microcosm.graph.keys import node_key, source_content_key from test_support.microcosm_build.transport_entitlement import ( AS_INPUTS, @@ -228,6 +230,107 @@ def test_cell_support_graph_adds_diagnostics_to_explicit_gap_output_declarations ) +COLLECTOR = "nz.as.bands.cell_diagnostics" + + +def _with_checkpoints(fixture, checkpoints): + spec = copy.deepcopy(fixture.spec) + spec["resources"]["entitlement_graph"]["checkpoints"] = list(checkpoints) + return fixture.reprepare(spec) + + +def test_cell_support_collector_is_the_last_checkpoint_when_the_document_omits_it( + tmp_path, +): + fixture = _cell_support_fixture(tmp_path) + assert entitlement_extension(fixture.spec).checkpoints == ( + "nz.as.bands", + "nz.validate.wff_tripwire", + COLLECTOR, + ) + + +def test_cell_support_collector_keeps_the_place_its_document_gives_it(tmp_path): + order = ("nz.as.bands", COLLECTOR, "nz.validate.wff_tripwire") + fixture = _with_checkpoints(_cell_support_fixture(tmp_path), order) + assert entitlement_extension(fixture.spec).checkpoints == order + endpoints = transport_endpoints(fixture.spec, extensions=fixture.config.extensions) + assert endpoints["checkpoints"] == order + assert COLLECTOR in {node.id for node in fixture.graph().nodes} + + +@pytest.mark.parametrize("later", ["nz.validate.wff_tripwire", "nz.gates.terminal"]) +def test_cell_support_checkpoints_run_in_the_declared_order(tmp_path, later): + """Each checkpoint computes its node and none that the document lists later. + + The tripwire case pins which endpoint each manifest index holds. The + battery case also pins the run order, because the battery reads the + collector. + """ + order = ("nz.as.bands", COLLECTOR, later) + fixture = _with_checkpoints(_cell_support_fixture(tmp_path), order) + out = tmp_path / "out" + execute_transport_graph( + fixture.graph(), + fixture.registry, + fixture.sources, + out=out, + endpoints=transport_endpoints( + fixture.spec, extensions=fixture.config.extensions + ), + ) + assert sorted(path.name for path in out.glob("checkpoint-extension-*.json")) == [ + f"checkpoint-extension-{index}.json" for index in range(len(order)) + ] + for index, checkpoint in enumerate(order): + path = out / f"checkpoint-extension-{index}.json" + nodes = json.loads(path.read_text())["nodes"] + assert nodes[checkpoint]["hit"] is False + assert not set(order[index + 1 :]) & set(nodes) + + +def test_cell_support_collector_manifest_survives_a_raise_in_the_battery_checkpoint( + tmp_path, monkeypatch +): + """Listed ahead of the gate battery, the collector's manifest is on disk + before a node that only the battery's checkpoint runs can raise.""" + order = ("nz.as.bands", COLLECTOR, "nz.gates.terminal") + fixture = _with_checkpoints(_cell_support_fixture(tmp_path), order) + graph = fixture.graph() + victim = "nz.calibration.diagnostics" + compiled = compile_graph(graph) + ancestors, frontier = {COLLECTOR}, [COLLECTOR] + while frontier: + fresh = set(compiled.predecessors[frontier.pop()]) - ancestors + ancestors |= fresh + frontier += fresh + assert victim not in ancestors + kernel = type(fixture.registry.kernels.get(graph.node(victim).kernel)) + original = kernel.run + + def run(self, context): + if context.node.id == victim: + raise RuntimeError("injected failure") + return original(self, context) + + monkeypatch.setattr(kernel, "run", run) + out = tmp_path / "out" + with pytest.raises(NodeRejectedError, match="injected failure"): + execute_transport_graph( + graph, + fixture.registry, + fixture.sources, + out=out, + endpoints=transport_endpoints( + fixture.spec, extensions=fixture.config.extensions + ), + ) + nodes = json.loads((out / "checkpoint-extension-1.json").read_text())["nodes"] + assert nodes[COLLECTOR]["hit"] is False + assert victim not in nodes + assert not (out / "checkpoint-extension-2.json").exists() + + def _with_cell_target(fixture, **overrides): """Return the fixture's spec with a tracked cell-target gate appended.""" spec = copy.deepcopy(fixture.spec) From bfb783af58db295b9d945ced309474f5b26947b8 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Fri, 20 Nov 2026 17:45:40 +0000 Subject: [PATCH 2/2] Patch the registered kernel instance in the checkpoint failure test Other test files patch the shared diagnostics kernel instance, and their teardown leaves an instance attribute that shadows a class patch. Run after them, the failure-injection test never raised. It now patches the instance for the length of the test. The docs sentence names an applicable cell-support gate and says how checkpoint manifests are named. Co-Authored-By: Claude Fable 5.2 --- docs/transport-entitlement.md | 2 +- .../shared/test_transport_entitlement_graph.py | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/transport-entitlement.md b/docs/transport-entitlement.md index efd4a6cf7d..eb8d01f55f 100644 --- a/docs/transport-entitlement.md +++ b/docs/transport-entitlement.md @@ -15,7 +15,7 @@ driver install it automatically. Its fields are: | `scenario_gap`, `variant_gap` | Gap producer id templates for the two tiers. | | `bands` | `id`, `population`, `baseline_scenario`; all declared scenario gaps become typed inputs. | | `package` | Final skeleton receipt `id`, bands `artifact_name`, optional additional `inputs` in the ordinary artifact-edge grammar. | -| `sources`, `checkpoints` | Additional sources with new names and ordered pre-export endpoints. The bands node is the default checkpoint. With a cell-support gate, `.cell_diagnostics` is also a checkpoint: the final one unless the document lists it. | +| `sources`, `checkpoints` | Additional sources with new names and ordered pre-export endpoints. The bands node is the default checkpoint. With an applicable cell-support gate, `.cell_diagnostics` is also a checkpoint: the final one unless the document lists it. The run writes one manifest per checkpoint in the listed order, named `checkpoint-extension-.json`. | Activation checks resource selections in the common nodes and each scenario's selected nodes, using the entitlement factory's row selection. A scenario's diff --git a/packages/microcosm-build/tests/engine_free/shared/test_transport_entitlement_graph.py b/packages/microcosm-build/tests/engine_free/shared/test_transport_entitlement_graph.py index ca0d71d615..9cfea4bd58 100644 --- a/packages/microcosm-build/tests/engine_free/shared/test_transport_entitlement_graph.py +++ b/packages/microcosm-build/tests/engine_free/shared/test_transport_entitlement_graph.py @@ -305,15 +305,17 @@ def test_cell_support_collector_manifest_survives_a_raise_in_the_battery_checkpo ancestors |= fresh frontier += fresh assert victim not in ancestors - kernel = type(fixture.registry.kernels.get(graph.node(victim).kernel)) + # Patch the registered instance, which other tests also patch: an + # instance attribute left by their teardown would shadow a class patch. + kernel = fixture.registry.kernels.get(graph.node(victim).kernel) original = kernel.run - def run(self, context): + def run(context): if context.node.id == victim: raise RuntimeError("injected failure") - return original(self, context) + return original(context) - monkeypatch.setattr(kernel, "run", run) + monkeypatch.setitem(vars(kernel), "run", run) out = tmp_path / "out" with pytest.raises(NodeRejectedError, match="injected failure"): execute_transport_graph(