from afk_developer.planner.plan_verifier import preflight_plan from afk_developer.planner.task_model import TaskNode, TaskPlan def _plan(*tasks: TaskNode) -> TaskPlan: return TaskPlan(project_name="example", goal="goal", intent="implement", tasks=list(tasks)) def test_task_node_infers_no_full_suite_as_scoped_pytest_policy() -> None: explicit = TaskNode( id="focused", title="Focused test task", description="Run only the named witness tests; no full suite from worker.", ) planner_rephrased = TaskNode( id="rephrased", title="Focused test task", description="Run only the named witness tests; do not run the full suite.", ) red_regression = TaskNode( id="red", title="Create a red witness", description="Create the exact direct witness.", red_regression_test_files=["tests/test_contract.py"], ) documentation = TaskNode( id="docs", title="Document the public API", description="Modify README.md only; invoke no pytest or Ruff command.", ) acceptance_only = TaskNode( id="acceptance-docs", title="Document the public API", description="Modify README.md only.", acceptance_criteria=["No pytest or Ruff command is invoked."], ) assert explicit.disallow_unscoped_pytest is True assert planner_rephrased.disallow_unscoped_pytest is True assert red_regression.disallow_unscoped_pytest is True assert documentation.disallow_unscoped_pytest is True assert acceptance_only.disallow_unscoped_pytest is True def test_preflight_persists_passing_evidence_for_an_executable_dag(): plan = _plan( TaskNode(id="one", title="One", description="first"), TaskNode(id="two", title="Two", description="second", dependencies=["one"]), ) evidence = preflight_plan(plan, maximum_task_count=2) assert evidence.passed assert evidence.task_count == 2 assert plan.preflight_evidence == evidence def test_preflight_rejects_unknown_dependencies(): plan = _plan(TaskNode(id="one", title="One", description="first", dependencies=["missing"])) evidence = preflight_plan(plan) assert not evidence.passed assert evidence.failures == ["Task one has unknown dependencies: missing."] def test_preflight_rejects_dependency_cycles(): plan = _plan( TaskNode(id="one", title="One", description="first", dependencies=["two"]), TaskNode(id="two", title="Two", description="second", dependencies=["one"]), ) evidence = preflight_plan(plan) assert not evidence.passed assert any("cycle" in failure for failure in evidence.failures) def test_preflight_rejects_plans_above_the_declared_cap(): plan = _plan( TaskNode(id="one", title="One", description="first"), TaskNode(id="two", title="Two", description="second"), ) evidence = preflight_plan(plan, maximum_task_count=1) assert not evidence.passed assert evidence.failures == ["Plan has 2 tasks; maximum is 1."] def test_preflight_requires_one_implementation_successor_for_red_tests(): plan = _plan( TaskNode( id="red-test", title="Add red test", description="test first", red_regression_test_files=["tests/test_red_regression.py"], ) ) evidence = preflight_plan(plan) assert not evidence.passed assert evidence.failures == [ "Red-regression task red-test must have exactly one dependent implementation task; found 0." ]