From 8a6278734a8dada063c7d8fb0814785ab7ff1df3 Mon Sep 17 00:00:00 2001 From: Peter van Tol Date: Thu, 1 Oct 2026 19:03:32 +0200 Subject: [PATCH] Expose non-dispatchable Mission Action frontier --- .../l3-action-frontier-producer-20261001.json | 16 +++ .../PARALLEL_ACTION_FRONTIER_PRODUCER_V1.md | 47 ++++++++ docs/roadmap/PARALLEL_ACTION_RUNTIME_V1.md | 6 + forge/action_frontier.py | 100 +++++++++++++++++ forge/api/parallel-action-peer-graph-v1.json | 54 +++++++++ forge/api/server-openapi-v1.json | 2 +- forge/api/server-postman-v1.json | 2 +- forge/operations_read_api.py | 9 ++ forge/parallel_action_contract.py | 103 ++++++++++++++++++ product-version.json | 2 +- tests/test_action_frontier.py | 55 ++++++++++ tests/test_operations_read_api.py | 29 +++++ tests/test_parallel_action_contract.py | 65 +++++++++++ 13 files changed, 487 insertions(+), 3 deletions(-) create mode 100644 .github/product-version-operations/l3-action-frontier-producer-20261001.json create mode 100644 docs/architecture/PARALLEL_ACTION_FRONTIER_PRODUCER_V1.md create mode 100644 forge/action_frontier.py create mode 100644 forge/api/parallel-action-peer-graph-v1.json create mode 100644 forge/parallel_action_contract.py create mode 100644 tests/test_action_frontier.py create mode 100644 tests/test_parallel_action_contract.py diff --git a/.github/product-version-operations/l3-action-frontier-producer-20261001.json b/.github/product-version-operations/l3-action-frontier-producer-20261001.json new file mode 100644 index 00000000..c0eed8ed --- /dev/null +++ b/.github/product-version-operations/l3-action-frontier-producer-20261001.json @@ -0,0 +1,16 @@ +{ + "baseline_version": "2.7.40", + "classification_rationale": "L3-FORGE-ACTION-FRONTIER-PRODUCER-V1-20261001", + "component": "product", + "event_lineage": "L3-FORGE-ACTION-FRONTIER-PRODUCER-V1-20261001", + "expected_head": "05b2a79eecfc162b8866c25ddd0dd66960626de3", + "operation_id": "l3-action-frontier-producer-20261001", + "policy_revision": "forge-bootstrap-release-cadence-v2", + "product": "forge", + "projection_paths": "product-version.json", + "release_class": "PATCH", + "requested_bump": "patch", + "requested_version": null, + "schema_version": "1", + "target_version": "2.7.41" +} diff --git a/docs/architecture/PARALLEL_ACTION_FRONTIER_PRODUCER_V1.md b/docs/architecture/PARALLEL_ACTION_FRONTIER_PRODUCER_V1.md new file mode 100644 index 00000000..1ddab96e --- /dev/null +++ b/docs/architecture/PARALLEL_ACTION_FRONTIER_PRODUCER_V1.md @@ -0,0 +1,47 @@ +# Parallel Action graph/frontier producer V1 + +This is a bounded `PA-F0` producer and read-only `PA-F2` projection subset. It +does not qualify the `PA-F1/F2/F3/FQ` runtime nodes or change the serial +Mission-3 execution path. Forge remains responsible for graph interpretation; +EP owns host admission, capacity, execution and evidence production. + +## Installed readback + +The authenticated Forge Server `GET /v1/missions/{mission_id}` response adds +`mission.action_frontier` with contract version `parallel-action-frontier/v1`. +It reads the same installed, read-only Mission snapshot as the existing +lifecycle/evidence projection. At most 256 stored Actions are accepted. Action +IDs and orders must be unique; every dependency must name a stored Action; and +cycles, malformed statuses or invalid revisions fail closed with +`MISSION_ACTION_GRAPH_INVALID`. Output order is stable by stored order and ID. + +`logical_frontier_action_ids` contains only stored `READY` Actions with no +hard predecessor. An Action with a completed predecessor still waits for +verified *edge-specific* evidence, which the current serial store cannot +prove. Failed or blocked predecessors block the dependent node. Every Action +reports `dispatchable: false` and `target_resolution: UNAVAILABLE` because the +current stored Action has no per-Action target binding. The response explicitly +reports `parallel_execution: NOT_QUALIFIED`. This is a planning/readback +classification, not authorization or proof of concurrent EP execution. + +## Peer compatibility vector + +The packaged +[`parallel-action-peer-graph-v1.json`](../../forge/api/parallel-action-peer-graph-v1.json) +is a synthetic `parallel-action-graph/v1` compatibility fixture: independent +Actions A/B target distinct repositories; Q names both predecessors and +repository-bound qualified-artifact digests. Forge's +`validate_peer_graph` checks the exact envelope, target fields, identifiers, +unique nodes/edges, predecessor existence, evidence digest format, evidence +repository match and cycles. It returns `dispatch_authorized: false` even for +a valid vector. An EP consumer can test parser/contract compatibility against +these bytes; the fixture is no credential, binding, grant, admission request, +execution receipt or proof that the current Forge runtime can materialize it. + +Before any actual parallel Action dispatch, Forge still needs durable +per-Action target/baseline/correlation state, verified predecessor predicates, +scope policy and guarded fan-out; EP needs its separately qualified admission, +resource isolation and multi-run evidence. Those remain under their owning +`PA-F1..FQ` and `PA-E0..EQ` dependencies. Installed HTTP readback and exact +artifact qualification for this producer are separate from public release or +production installation. diff --git a/docs/roadmap/PARALLEL_ACTION_RUNTIME_V1.md b/docs/roadmap/PARALLEL_ACTION_RUNTIME_V1.md index 89195192..d1374cb5 100644 --- a/docs/roadmap/PARALLEL_ACTION_RUNTIME_V1.md +++ b/docs/roadmap/PARALLEL_ACTION_RUNTIME_V1.md @@ -15,6 +15,12 @@ This is the implementation decomposition of the existing second Runtime mileston PA-F0 consumes the existing Living Mission Graph/Producer contract; no complete future policy/UI programme is required. PA-F1/F2 can progress using peer fixtures while EP qualifies execution. PA-F3 requires the exact used EP admission/resource/isolation slice, not merely a threadpool or two accepted rows. EP PA-EQ consumes PA-F0 contract fixtures, never PA-FQ, so there is no cross-product qualification cycle. +The [bounded graph/frontier producer](../architecture/PARALLEL_ACTION_FRONTIER_PRODUCER_V1.md) +supplies a versioned peer fixture and an installed logical readback subset. +Stored Actions still lack per-Action target and verified-edge evidence; the +readback marks dispatch and parallel execution unavailable. Its delivery does +not close full PA-F1/F2 or installed overlap qualification. + EP owns `docs/development/PARALLEL_ACTION_EXECUTION_V1_ROADMAP.md` and its JSON DAG. Same-Mission membership must not add an EP global mutex; real shared resources may legitimately serialize. First canary uses separate repositories/workspaces on one host, no full Agent fleet, Workspace or native subagent implementation dependency. Same-repository concurrent mutation remains separate stricter qualification. The serial Mission-3 loop and current reset maintenance task are not expanded. Implementation can be prepared in parallel with other roadmap lanes in isolated work; acceptance of this capability is separate from serial autonomy, not inferred from it. Any later prioritization/actual Mission allocation follows existing governance. No new Mission IDs, live grants, policy activation, CI gate activation, installed change or release is made by this documentation. diff --git a/forge/action_frontier.py b/forge/action_frontier.py new file mode 100644 index 00000000..210f7435 --- /dev/null +++ b/forge/action_frontier.py @@ -0,0 +1,100 @@ +"""Bounded, read-only logical Action frontier for an installed Mission. + +This projection never decides host admission. A stored Action has no durable +per-Action target or predecessor evidence predicate in the serial schema, so +the result must not be interpreted as a dispatchable parallel workset. +""" +from __future__ import annotations + +from collections.abc import Mapping, Sequence +from typing import Any + + +FRONTIER_CONTRACT_VERSION = "parallel-action-frontier/v1" +MAX_FRONTIER_ACTIONS = 256 +_STATUSES = frozenset({"READY", "ACTIVE", "WAITING_FOR_RESULT", "COMPLETE", "BLOCKED", "FAILED"}) + + +class ActionFrontierError(ValueError): + """The installed Action graph cannot be safely represented as a DAG.""" + + +def project_action_frontier(actions: Sequence[Mapping[str, Any]], *, mission_revision: int) -> dict[str, Any]: + """Return a deterministic logical frontier without claiming execution eligibility.""" + if len(actions) > MAX_FRONTIER_ACTIONS: + raise ActionFrontierError("Mission Action graph exceeds the bounded read limit") + if not isinstance(mission_revision, int) or isinstance(mission_revision, bool) or mission_revision < 1: + raise ActionFrontierError("Mission graph revision is invalid") + nodes: dict[str, dict[str, Any]] = {} + orders: set[int] = set() + for action in actions: + if not isinstance(action, Mapping): + raise ActionFrontierError("Mission Action record is invalid") + action_id = action.get("id") + order = action.get("order") + status = action.get("status") + edges = action.get("dependencies", ()) + if (not isinstance(action_id, str) or not action_id or action_id in nodes + or not isinstance(order, int) or isinstance(order, bool) or order < 1 or order in orders + or not isinstance(status, str) or status not in _STATUSES + or not isinstance(edges, (list, tuple)) + or any(not isinstance(edge, str) or not edge for edge in edges) + or len(edges) != len(set(edges))): + raise ActionFrontierError("Mission Action identity, order, status or edges are invalid") + orders.add(order) + nodes[action_id] = {"action_id": action_id, "order": order, "status": status, + "dependencies": tuple(edges)} + for node in nodes.values(): + if node["action_id"] in node["dependencies"] or any( + edge not in nodes for edge in node["dependencies"] + ): + raise ActionFrontierError("Mission Action graph has an unresolved edge") + active: set[str] = set() + complete: set[str] = set() + + def visit(action_id: str) -> None: + if action_id in active: + raise ActionFrontierError("Mission Action graph has a cycle") + if action_id in complete: + return + active.add(action_id) + for predecessor in nodes[action_id]["dependencies"]: + visit(predecessor) + active.remove(action_id) + complete.add(action_id) + + for action_id in nodes: + visit(action_id) + ordered = sorted(nodes.values(), key=lambda node: (node["order"], node["action_id"])) + frontier: list[str] = [] + projected: list[dict[str, Any]] = [] + for node in ordered: + dependencies = node["dependencies"] + if node["status"] != "READY": + logical_state = node["status"] + elif any(nodes[edge]["status"] in {"FAILED", "BLOCKED"} for edge in dependencies): + logical_state = "BLOCKED_BY_PREDECESSOR" + elif any(nodes[edge]["status"] != "COMPLETE" for edge in dependencies): + logical_state = "WAITING_FOR_PREDECESSOR" + elif dependencies: + # Serial storage does not bind a verified predicate to each edge. + logical_state = "WAITING_FOR_VERIFIED_EVIDENCE" + else: + logical_state = "LOGICALLY_ELIGIBLE" + frontier.append(node["action_id"]) + projected.append({ + "action_id": node["action_id"], "order": node["order"], "status": node["status"], + "dependencies": list(dependencies), "logical_state": logical_state, + "target_repository_id": None, "target_resolution": "UNAVAILABLE", + "dependency_evidence_resolution": "UNAVAILABLE" if dependencies else "NOT_REQUIRED", + "dispatchable": False, + }) + return { + "contract_version": FRONTIER_CONTRACT_VERSION, + "source_mission_revision": mission_revision, + "graph_kind": "STORED_ACTION_LOGICAL_DAG", + "logical_frontier_action_ids": frontier, + "actions": projected, + "parallel_execution": "NOT_QUALIFIED", + "read_only": True, + } diff --git a/forge/api/parallel-action-peer-graph-v1.json b/forge/api/parallel-action-peer-graph-v1.json new file mode 100644 index 00000000..018d68ff --- /dev/null +++ b/forge/api/parallel-action-peer-graph-v1.json @@ -0,0 +1,54 @@ +{ + "contract_version": "parallel-action-graph/v1", + "mission_id": "MISSION-FIXTURE-1", + "mission_revision": 1, + "actions": [ + { + "action_id": "ACTION-A", + "target": { + "ep_instance_id": "ep-fixture-1", + "project_id": "project-fixture-1", + "repository_id": "repository-a", + "baseline_revision": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + "dependencies": [] + }, + { + "action_id": "ACTION-B", + "target": { + "ep_instance_id": "ep-fixture-1", + "project_id": "project-fixture-1", + "repository_id": "repository-b", + "baseline_revision": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + }, + "dependencies": [] + }, + { + "action_id": "ACTION-Q", + "target": { + "ep_instance_id": "ep-fixture-1", + "project_id": "project-fixture-1", + "repository_id": "repository-a", + "baseline_revision": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + }, + "dependencies": [ + { + "predecessor_action_id": "ACTION-A", + "required_evidence": { + "kind": "QUALIFIED_ARTIFACT", + "repository_id": "repository-a", + "content_digest": "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + } + }, + { + "predecessor_action_id": "ACTION-B", + "required_evidence": { + "kind": "QUALIFIED_ARTIFACT", + "repository_id": "repository-b", + "content_digest": "sha256:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + } + } + ] + } + ] +} diff --git a/forge/api/server-openapi-v1.json b/forge/api/server-openapi-v1.json index 73e100b6..22295c28 100644 --- a/forge/api/server-openapi-v1.json +++ b/forge/api/server-openapi-v1.json @@ -289,7 +289,7 @@ }, "/v1/missions/{mission_id}": { "get": { - "summary": "Read Mission lifecycle and evidence lineage", + "summary": "Read Mission lifecycle, evidence lineage and non-dispatchable Action frontier", "responses": { "200": { "description": "Accepted JSON response" diff --git a/forge/api/server-postman-v1.json b/forge/api/server-postman-v1.json index 2b5abca0..dfe45d42 100644 --- a/forge/api/server-postman-v1.json +++ b/forge/api/server-postman-v1.json @@ -344,7 +344,7 @@ } }, { - "name": "Read Mission lifecycle and evidence lineage", + "name": "Read Mission lifecycle, evidence lineage and non-dispatchable Action frontier", "request": { "method": "GET", "header": [], diff --git a/forge/operations_read_api.py b/forge/operations_read_api.py index d0750534..71e5eb04 100644 --- a/forge/operations_read_api.py +++ b/forge/operations_read_api.py @@ -20,6 +20,7 @@ from urllib.parse import unquote, urlsplit from .__main__ import _status +from .action_frontier import ActionFrontierError, project_action_frontier from .execution_host_configuration import PeerConfigurationError, read_peer_configuration from .installed_health import InstalledHealthError, InstalledHealthSnapshotService from .mission_cli import _status_projection as mission_status_projection @@ -256,6 +257,14 @@ def mission_detail(self, mission_id: str) -> dict[str, Any]: "criterion_assessment_history": [_project_assessment(item) for item in state.completion_history], }, }) + try: + projection["action_frontier"] = project_action_frontier( + state.actions, mission_revision=state.revision, + ) + except ActionFrontierError: + raise OperationsProjectionError( + "MISSION_ACTION_GRAPH_INVALID", "Mission Action graph is inconsistent", status=409, + ) from None return _redact({ "api_version": API_VERSION, "availability": "AVAILABLE", diff --git a/forge/parallel_action_contract.py b/forge/parallel_action_contract.py new file mode 100644 index 00000000..a75001c4 --- /dev/null +++ b/forge/parallel_action_contract.py @@ -0,0 +1,103 @@ +"""Versioned, authority-free compatibility contract for parallel Action graphs. + +This validates a producer document for peer compatibility testing. It does not +resolve an EP binding, prove a grant, materialize Actions, or admit execution. +""" +from __future__ import annotations + +from collections.abc import Mapping +import re +from typing import Any + + +PEER_GRAPH_CONTRACT_VERSION = "parallel-action-graph/v1" +_IDENTIFIER = re.compile(r"[A-Za-z0-9][A-Za-z0-9._:-]{0,127}\Z") +_DIGEST = re.compile(r"sha256:[0-9a-f]{64}\Z") +_EVIDENCE_KINDS = frozenset({"QUALIFIED_ARTIFACT", "REPOSITORY_REVISION"}) + + +class ParallelActionContractError(ValueError): + """A peer compatibility graph is malformed or self-contradictory.""" + + +def _identifier(value: object) -> bool: + return isinstance(value, str) and _IDENTIFIER.fullmatch(value) is not None + + +def validate_peer_graph(document: Mapping[str, Any]) -> dict[str, Any]: + """Validate and canonicalize an explicit-target test vector, never a grant.""" + if (not isinstance(document, Mapping) + or set(document) != {"contract_version", "mission_id", "mission_revision", "actions"} + or document.get("contract_version") != PEER_GRAPH_CONTRACT_VERSION + or not _identifier(document.get("mission_id")) + or not isinstance(document.get("mission_revision"), int) + or isinstance(document["mission_revision"], bool) or document["mission_revision"] < 1 + or not isinstance(document.get("actions"), list) + or not 1 <= len(document["actions"]) <= 256): + raise ParallelActionContractError("parallel Action graph envelope is invalid") + actions: dict[str, dict[str, Any]] = {} + for item in document["actions"]: + if (not isinstance(item, Mapping) + or set(item) != {"action_id", "target", "dependencies"} + or not _identifier(item.get("action_id")) + or item["action_id"] in actions + or not isinstance(item.get("target"), Mapping) + or set(item["target"]) != { + "ep_instance_id", "project_id", "repository_id", "baseline_revision", + } + or any(not _identifier(item["target"].get(key)) for key in item["target"]) + or not isinstance(item.get("dependencies"), list)): + raise ParallelActionContractError("parallel Action or target is invalid") + dependencies: list[dict[str, Any]] = [] + seen: set[str] = set() + for edge in item["dependencies"]: + if (not isinstance(edge, Mapping) + or set(edge) != {"predecessor_action_id", "required_evidence"} + or not _identifier(edge.get("predecessor_action_id")) + or edge["predecessor_action_id"] == item["action_id"] + or edge["predecessor_action_id"] in seen + or not isinstance(edge.get("required_evidence"), Mapping) + or set(edge["required_evidence"]) != {"kind", "repository_id", "content_digest"} + or not isinstance(edge["required_evidence"].get("kind"), str) + or edge["required_evidence"]["kind"] not in _EVIDENCE_KINDS + or not _identifier(edge["required_evidence"].get("repository_id")) + or not isinstance(edge["required_evidence"].get("content_digest"), str) + or _DIGEST.fullmatch(edge["required_evidence"]["content_digest"]) is None): + raise ParallelActionContractError("parallel Action predecessor evidence is invalid") + seen.add(edge["predecessor_action_id"]) + dependencies.append({ + "predecessor_action_id": edge["predecessor_action_id"], + "required_evidence": dict(edge["required_evidence"]), + }) + actions[item["action_id"]] = { + "action_id": item["action_id"], "target": dict(item["target"]), + "dependencies": dependencies, + } + for action in actions.values(): + for edge in action["dependencies"]: + predecessor = actions.get(edge["predecessor_action_id"]) + if (predecessor is None or edge["required_evidence"]["repository_id"] + != predecessor["target"]["repository_id"]): + raise ParallelActionContractError("parallel Action evidence target is inconsistent") + visiting: set[str] = set() + visited: set[str] = set() + + def visit(action_id: str) -> None: + if action_id in visiting: + raise ParallelActionContractError("parallel Action graph has a cycle") + if action_id in visited: + return + visiting.add(action_id) + for edge in actions[action_id]["dependencies"]: + visit(edge["predecessor_action_id"]) + visiting.remove(action_id) + visited.add(action_id) + + for action_id in actions: + visit(action_id) + return { + "contract_version": PEER_GRAPH_CONTRACT_VERSION, + "mission_id": document["mission_id"], "mission_revision": document["mission_revision"], + "actions": [actions[key] for key in sorted(actions)], + "dispatch_authorized": False, + } diff --git a/product-version.json b/product-version.json index 5d209506..6ac6c40e 100644 --- a/product-version.json +++ b/product-version.json @@ -1,5 +1,5 @@ { "product": "forge", "schema_version": 1, - "version": "2.7.40" + "version": "2.7.41" } diff --git a/tests/test_action_frontier.py b/tests/test_action_frontier.py new file mode 100644 index 00000000..927fdc9a --- /dev/null +++ b/tests/test_action_frontier.py @@ -0,0 +1,55 @@ +"""Logical frontier validation does not promote stored Actions to executable work.""" +from __future__ import annotations + +import unittest + +from forge.action_frontier import ActionFrontierError, project_action_frontier + + +def action(order: int, action_id: str, *, status: str = "READY", + dependencies: tuple[str, ...] = ()) -> dict: + return {"order": order, "id": action_id, "status": status, "dependencies": dependencies} + + +class ActionFrontierTests(unittest.TestCase): + def test_zero_one_and_independent_multiple_actions_are_logical_only(self) -> None: + empty = project_action_frontier((), mission_revision=1) + self.assertEqual(empty["logical_frontier_action_ids"], []) + one = project_action_frontier((action(1, "A"),), mission_revision=2) + self.assertEqual(one["logical_frontier_action_ids"], ["A"]) + multiple = project_action_frontier((action(2, "B"), action(1, "A")), mission_revision=3) + self.assertEqual(multiple["logical_frontier_action_ids"], ["A", "B"]) + self.assertEqual([item["action_id"] for item in multiple["actions"]], ["A", "B"]) + self.assertTrue(all(not item["dispatchable"] for item in multiple["actions"])) + self.assertTrue(all(item["target_resolution"] == "UNAVAILABLE" for item in multiple["actions"])) + self.assertEqual(multiple["parallel_execution"], "NOT_QUALIFIED") + + def test_hard_edges_wait_for_completion_and_verified_evidence(self) -> None: + waiting = project_action_frontier((action(1, "A", status="ACTIVE"), + action(2, "B", dependencies=("A",))), mission_revision=1) + self.assertEqual(waiting["actions"][1]["logical_state"], "WAITING_FOR_PREDECESSOR") + completed = project_action_frontier((action(1, "A", status="COMPLETE"), + action(2, "B", dependencies=("A",))), mission_revision=2) + self.assertEqual(completed["actions"][1]["logical_state"], "WAITING_FOR_VERIFIED_EVIDENCE") + self.assertEqual(completed["logical_frontier_action_ids"], []) + failed = project_action_frontier((action(1, "A", status="FAILED"), + action(2, "B", dependencies=("A",))), mission_revision=3) + self.assertEqual(failed["actions"][1]["logical_state"], "BLOCKED_BY_PREDECESSOR") + + def test_malformed_or_cyclic_graph_fails_closed(self) -> None: + invalid = ( + (action(1, "A"), action(2, "A")), + (action(1, "A"), action(1, "B")), + (action(1, "A", dependencies=("B",)),), + (action(1, "A", dependencies=("B",)), action(2, "B", dependencies=("A",))), + (action(1, "A", dependencies=("A",)),), + (action(1, "A", status="UNKNOWN"),), + (action(1, "A", status=[]),), + ) + for graph in invalid: + with self.subTest(graph=graph), self.assertRaises(ActionFrontierError): + project_action_frontier(graph, mission_revision=1) + with self.assertRaises(ActionFrontierError): + project_action_frontier((action(1, "A"),) * 257, mission_revision=1) + with self.assertRaises(ActionFrontierError): + project_action_frontier((), mission_revision=0) diff --git a/tests/test_operations_read_api.py b/tests/test_operations_read_api.py index 0dee8582..75fc93ae 100644 --- a/tests/test_operations_read_api.py +++ b/tests/test_operations_read_api.py @@ -197,6 +197,26 @@ def test_multiple_missions_have_stable_order_without_claiming_runtime_parallelis ["MISSION-0042", "MISSION-0043"]) self.assertEqual([item["group"] for item in response.body["repository_scope"]["missions"]], ["ACTIVE", "ACTIVE"]) + def test_existing_mission_with_two_independent_actions_has_only_a_logical_frontier(self) -> None: + self.create_mission() + row = self.database._connection.execute( # noqa: SLF001 - controlled graph fixture + "SELECT document FROM mission_state WHERE mission_id='MISSION-0042'" + ).fetchone() + document = json.loads(row[0]) + document["actions"][1]["dependencies"] = [] + self.database._connection.execute( # noqa: SLF001 + "UPDATE mission_state SET document=? WHERE mission_id='MISSION-0042'", (json.dumps(document),) + ) + self.database._connection.commit() # noqa: SLF001 + before = self.snapshot() + response = self.api.handle("GET", "/v1/missions/MISSION-0042", "Bearer " + CREDENTIAL) + self.assertEqual(response.status, 200) + frontier = response.body["mission"]["action_frontier"] + self.assertEqual(frontier["logical_frontier_action_ids"], ["ACTION-0042-A", "ACTION-0042-B"]) + self.assertTrue(all(not item["dispatchable"] for item in frontier["actions"])) + self.assertEqual(frontier["parallel_execution"], "NOT_QUALIFIED") + self.assertEqual(self.snapshot(), before) + def test_same_repository_project_rebind_does_not_claim_mission_membership(self) -> None: old = self.configure_project() self.create_mission() @@ -234,6 +254,9 @@ def test_corrupt_mission_graph_does_not_claim_a_valid_roadmap(self) -> None: response = self.api.handle("GET", "/v1/projects/forge-project/roadmap", "Bearer " + CREDENTIAL) self.assertEqual(response.status, 409) self.assertEqual(response.body["error"]["code"], "PROJECT_DAG_INVALID") + mission_response = self.api.handle("GET", "/v1/missions/MISSION-0042", "Bearer " + CREDENTIAL) + self.assertEqual(mission_response.status, 409) + self.assertEqual(mission_response.body["error"]["code"], "MISSION_ACTION_GRAPH_INVALID") def test_mission_from_other_repository_is_not_attributed_to_project(self) -> None: self.configure_project() @@ -403,6 +426,12 @@ def test_mission_lineage_read_only(self) -> None: self.assertTrue(response.body["read_only"]) self.assertEqual(response.body["mission"]["mission_id"], "MISSION-0042") self.assertEqual(response.body["mission"]["action_ids"], ["ACTION-0042"]) + frontier = response.body["mission"]["action_frontier"] + self.assertEqual(frontier["contract_version"], "parallel-action-frontier/v1") + self.assertEqual(frontier["logical_frontier_action_ids"], ["ACTION-0042"]) + self.assertEqual(frontier["actions"][0]["target_resolution"], "UNAVAILABLE") + self.assertFalse(frontier["actions"][0]["dispatchable"]) + self.assertEqual(frontier["parallel_execution"], "NOT_QUALIFIED") self.assertEqual(response.body["mission"]["repository_revision"], "a" * 40) self.assertEqual(response.body["mission"]["execution_attempts"][0]["receipt_id"], "receipt-0042") redacted_values = "[REDACTED] [REDACTED] [REDACTED] https://[REDACTED]@example.test/resource" diff --git a/tests/test_parallel_action_contract.py b/tests/test_parallel_action_contract.py new file mode 100644 index 00000000..157151b9 --- /dev/null +++ b/tests/test_parallel_action_contract.py @@ -0,0 +1,65 @@ +"""PA-F0 peer fixture is a strict compatibility vector, never an execution grant.""" +from __future__ import annotations + +from copy import deepcopy +from importlib.resources import files +import json +import unittest + +from forge.parallel_action_contract import ParallelActionContractError, validate_peer_graph + + +def fixture() -> dict: + return json.loads(files("forge").joinpath("api/parallel-action-peer-graph-v1.json").read_text()) + + +class ParallelActionPeerContractTests(unittest.TestCase): + def test_packaged_two_target_fan_out_join_fixture_is_valid_and_authority_free(self) -> None: + result = validate_peer_graph(fixture()) + self.assertEqual([item["action_id"] for item in result["actions"]], + ["ACTION-A", "ACTION-B", "ACTION-Q"]) + self.assertEqual([item["target"]["repository_id"] for item in result["actions"][:2]], + ["repository-a", "repository-b"]) + self.assertEqual([item["predecessor_action_id"] for item in result["actions"][2]["dependencies"]], + ["ACTION-A", "ACTION-B"]) + self.assertFalse(result["dispatch_authorized"]) + + def test_wrong_target_duplicate_missing_or_cyclic_edge_fails_closed(self) -> None: + cases = [] + wrong_target = fixture() + wrong_target["actions"][2]["dependencies"][1]["required_evidence"]["repository_id"] = "repository-a" + cases.append(wrong_target) + duplicate = fixture() + duplicate["actions"][1]["action_id"] = "ACTION-A" + cases.append(duplicate) + missing = fixture() + missing["actions"][2]["dependencies"][0]["predecessor_action_id"] = "ACTION-MISSING" + cases.append(missing) + cyclic = fixture() + cyclic["actions"][0]["dependencies"] = [deepcopy(cyclic["actions"][2]["dependencies"][0])] + cyclic["actions"][0]["dependencies"][0]["predecessor_action_id"] = "ACTION-Q" + cases.append(cyclic) + for value in cases: + with self.subTest(value=value), self.assertRaises(ParallelActionContractError): + validate_peer_graph(value) + + def test_bad_envelope_target_and_evidence_are_rejected(self) -> None: + cases = [] + wrong_version = fixture() + wrong_version["contract_version"] = "parallel-action-graph/v2" + cases.append(wrong_version) + invented_grant = fixture() + invented_grant["dispatch_authorized"] = True + cases.append(invented_grant) + bad_target = fixture() + bad_target["actions"][0]["target"]["repository_id"] = "../other" + cases.append(bad_target) + bad_digest = fixture() + bad_digest["actions"][2]["dependencies"][0]["required_evidence"]["content_digest"] = "unknown" + cases.append(bad_digest) + bad_kind = fixture() + bad_kind["actions"][2]["dependencies"][0]["required_evidence"]["kind"] = [] + cases.append(bad_kind) + for value in cases: + with self.subTest(value=value), self.assertRaises(ParallelActionContractError): + validate_peer_graph(value)