import json from pathlib import Path import pytest from robotics.benchmarks import blocksworld as bw DATA = Path("data/planbench/task_1_plan_generation.json") @pytest.mark.skipif(not DATA.exists(), reason="PlanBench data not downloaded") def test_all_500_ground_truth_plans_validate(): """Validator correctness gate: every official PlanBench ground-truth plan must be valid and reach the goal (stands in for VAL on this domain).""" ins = bw.load(DATA) assert len(ins) == 500 bad = [i["instance_id"] for i in ins if not bw.validate(i["query"], i["ground_truth_plan"])["reached"]] assert bad == [] @pytest.mark.skipif(not DATA.exists(), reason="PlanBench data not downloaded") def test_corrupted_plans_are_rejected(): ins = bw.load(DATA)[:100] rejected = 0 for i in ins: lines = [x for x in i["ground_truth_plan"].strip().splitlines() if x] if len(lines) < 2: continue swapped = "\n".join([lines[1], lines[0]] + lines[2:]) # swap first two actions truncated = "\n".join(lines[:-1]) # drop the last action rejected += (not bw.validate(i["query"], swapped)["reached"]) + (not bw.validate(i["query"], truncated)["reached"]) assert rejected >= 190 def test_natural_language_plan_and_feedback(): q = ("[STATEMENT]\nAs initial conditions I have that, the red block is clear, the hand is empty, " "the red block is on top of the blue block and the blue block is on the table.\n" "My goal is to have that the blue block is on top of the red block.\n\nMy plan is as follows:\n\n[PLAN]") good = "unstack the red block from on top of the blue block\nput down the red block\n" \ "pick up the blue block\nstack the blue block on top of the red block\n[PLAN END]" assert bw.validate(q, good)["reached"] v = bw.validate(q, "pick up the blue block") assert not v["valid"] and "not clear" in bw.feedback(v)