summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_models.py83
-rw-r--r--tests/test_pipeline.py8
2 files changed, 88 insertions, 3 deletions
diff --git a/tests/test_models.py b/tests/test_models.py
index 71dc854..d19b536 100644
--- a/tests/test_models.py
+++ b/tests/test_models.py
@@ -3,7 +3,12 @@ from __future__ import annotations
import pytest
from pydantic import ValidationError
-from gap_pipeline.models import JudgeVerdict, KernelCandidate, KernelPlan
+from gap_pipeline.models import (
+ JudgeVerdict,
+ KernelCandidate,
+ KernelPlan,
+ ProofPlanDAG,
+)
def test_valid_plan_and_candidate(plan_dict: dict, candidate_dict: dict) -> None:
@@ -38,3 +43,79 @@ def test_accept_verdict_cannot_report_blocking_issue() -> None:
step_by_step_check="checked",
blocking_issues="an error",
)
+
+
+def test_path_dag_is_derived_from_ordered_plan(plan_dict: dict) -> None:
+ dag = ProofPlanDAG.from_plan(KernelPlan.model_validate(plan_dict))
+ assert [node.node_id for node in dag.nodes] == ["n1", "n2"]
+ assert dag.nodes[0].dependencies == []
+ assert dag.nodes[1].dependencies == ["n1"]
+ assert dag.terminal_node_id == "n2"
+ assert dag.method_labels_payload()[0].startswith("n1: ")
+
+
+def test_dag_rejects_cycle() -> None:
+ with pytest.raises(ValidationError, match="cycle"):
+ ProofPlanDAG.model_validate(
+ {
+ "nodes": [
+ {
+ "node_id": "n1",
+ "method_label": "first",
+ "dependencies": ["n2"],
+ },
+ {
+ "node_id": "n2",
+ "method_label": "second",
+ "dependencies": ["n1"],
+ },
+ ],
+ "terminal_node_id": "n2",
+ }
+ )
+
+
+def test_path_dag_rejects_skipped_dependency() -> None:
+ with pytest.raises(ValidationError, match="lead to the terminal"):
+ ProofPlanDAG.model_validate(
+ {
+ "nodes": [
+ {
+ "node_id": "n1",
+ "method_label": "first",
+ "dependencies": [],
+ },
+ {
+ "node_id": "n2",
+ "method_label": "second",
+ "dependencies": [],
+ },
+ ],
+ "terminal_node_id": "n2",
+ }
+ )
+
+
+def test_judge_verdict_requires_every_dag_node(plan_dict: dict) -> None:
+ dag = ProofPlanDAG.from_plan(KernelPlan.model_validate(plan_dict))
+ verdict = JudgeVerdict(
+ verdict="accept",
+ step_by_step_check="n1 is valid; n2 is valid",
+ )
+ assert verdict.validate_coverage(dag) is verdict
+
+ with pytest.raises(ValueError, match="does not cover DAG nodes.*n2"):
+ JudgeVerdict(
+ verdict="accept",
+ step_by_step_check="n1 is valid",
+ ).validate_coverage(dag)
+
+
+def test_dag_labels_must_match_prompt_a_plan(plan_dict: dict) -> None:
+ plan = KernelPlan.model_validate(plan_dict)
+ dag = ProofPlanDAG.from_plan(plan)
+ changed_plan = plan.model_copy(
+ update={"core_steps": ["a different method", plan.core_steps[1]]}
+ )
+ with pytest.raises(ValueError, match="must equal Prompt-A core_steps"):
+ dag.validate_plan(changed_plan)
diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py
index 864e967..04c3ea9 100644
--- a/tests/test_pipeline.py
+++ b/tests/test_pipeline.py
@@ -13,7 +13,7 @@ from conftest import changed_candidate
def accept_review() -> dict[str, str]:
return {
"verdict": "accept",
- "step_by_step_check": "every method label is instantiated",
+ "step_by_step_check": "n1 passes; n2 passes",
"blocking_issues": "",
"patch_suggestion": "",
}
@@ -22,7 +22,9 @@ def accept_review() -> dict[str, str]:
def reject_review(iteration: int) -> dict[str, str]:
return {
"verdict": "reject",
- "step_by_step_check": f"terminal step fails at iteration {iteration}",
+ "step_by_step_check": (
+ f"n1 passes; n2 terminal step fails at iteration {iteration}"
+ ),
"blocking_issues": "terminal algebra is incorrect",
"patch_suggestion": "correct the terminal algebra",
}
@@ -76,6 +78,8 @@ def test_two_consecutive_unanimous_passes_accept(
final_path = tmp_path / "items" / item.item_id / "final.json"
final = json.loads(final_path.read_text())
assert final["accepted_candidate_sha256"]
+ assert final["proof_dag"]["structure"] == "path"
+ assert final["proof_dag"]["terminal_node_id"] == "n2"
assert len(list((final_path.parent / "calls").glob("*.json"))) == 12