from coordination_engine.project_driver import ( NotProjectDriverError, ResidualDriverError, actionable_demand, build_driver_case, repo_is_project, workplan_is_residual, ) HFACT = { "repos": { "prj": { "id": "prj", "slug": "prj-helixforge-factory", "category": "project", "repo_flavor": "project", }, "key": {"id": "key", "slug": "key-cape", "category": "product"}, "glas": {"id": "glas", "slug": "glas-harness", "category": "tooling"}, "infd": {"id": "infd", "slug": "informed-decision", "category": "product"}, }, "plans": [ { "id": "ed4fe524", "slug": "hfact-wp-0001", "title": "Establish the internal HelixForge software factory on Railiance", "status": "active", "flavor": "implementation", "repo_id": "prj", "depends_on": [{"workplan_id": "key-wp"}], "related": ["GLAS-WP-0012", "INFD-WP-0001", "KEY-WP-0013"], }, { "id": "key-wp", "slug": "key-wp-0013", "title": "Approval-engine resource audience", "status": "blocked", "flavor": "implementation", "repo_id": "key", }, { "id": "glas-wp", "slug": "glas-wp-0012", "title": "Prove the first local rein profile", "status": "blocked", "repo_id": "glas", }, { "id": "infd-wp", "slug": "infd-wp-0001", "title": "Founding specs", "status": "active", "flavor": "planning", "repo_id": "infd", }, { "id": "leftover", "slug": "hfact-wp-0099", "title": "Factory leftover", "status": "proposed", "flavor": "residual", "repo_id": "prj", }, ], } def test_hfact_builds_driver_case_with_implementers_and_depends_on_commitments(): case = build_driver_case(HFACT, "ed4fe524") assert case["scenario_type"] == "project_driver" assert case["driver_repo"] == "prj-helixforge-factory" assert case["driver_workplan_id"] == "ed4fe524" assert case["actionable"] is True repos = {row["repo"] for row in case["implementers"]} assert "key-cape" in repos assert "glas-harness" in repos assert "informed-decision" in repos assert "prj-helixforge-factory" not in repos assert case["commitments"] assert case["commitments"][0]["kind"] == "completion" assert case["commitments"][0]["obligor_workplan_id"] == "key-wp" assert case["commitments"][0]["beneficiary_workplan_id"] == "ed4fe524" assert case["commitments"][0]["state"] == "active" def test_residual_is_refused_as_driver_and_is_not_actionable_demand(): leftover = next(p for p in HFACT["plans"] if p["id"] == "leftover") assert workplan_is_residual(leftover) assert actionable_demand(leftover) is False try: build_driver_case(HFACT, "leftover") raise AssertionError("residual must not drive a case") except ResidualDriverError: pass def test_product_workplan_is_not_a_project_driver(): assert repo_is_project(HFACT["repos"]["key"]) is False try: build_driver_case(HFACT, "key-wp") raise AssertionError("product plan must not be a driver") except NotProjectDriverError: pass def test_auto_selects_open_project_plan_and_skips_residual(): case = build_driver_case(HFACT) assert case["driver_workplan_id"] == "ed4fe524"