Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@
An entitlement document can now list its cell-diagnostics collector (`<bands id>.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.
2 changes: 1 addition & 1 deletion docs/transport-entitlement.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 an applicable cell-support gate, `<bands id>.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-<index>.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -228,6 +230,109 @@ 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
# 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(context):
if context.node.id == victim:
raise RuntimeError("injected failure")
return original(context)

monkeypatch.setitem(vars(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)
Expand Down
Loading