Official Codebase of 3DCodeVerse
Python
bench: pin the invariant that stops --pin-plan from being decorative
gaoypeng8734326362a7
diff --git a/harness/tests/compare_bench/test_pin_plan.py b/harness/tests/compare_bench/test_pin_plan.pyindex 291373c9..60c3f3bf 100644--- a/harness/tests/compare_bench/test_pin_plan.py+++ b/harness/tests/compare_bench/test_pin_plan.py@@ -195,3 +195,56 @@ def test_a_generation_side_variant_env_is_permitted():from codeverse.tracks.plan_features import pin_plan_blockersassert pin_plan_blockers({"CV3D_SKILLS": "1", "CV3D_SKILLS_MAX": "1"}) == []+++# --------------------------------------------------------------------------- the key+# THE load-bearing invariant. `plan_once` seeds a plan whose stage-cache key is computed+# in bench/pin_plan.py; the arm that consumes it computes its key in+# tracks/lifecycle.BaseTrack.run. If those two expressions ever drift apart, the seeded+# plan is a cache MISS, both arms silently re-plan, and the rig reports "no effect" for a+# switch whose experiment it just deleted -- expensively, and with no error anywhere.+# Pinning that does not pin is worse than no pinning, because it looks like a result.++def _stage_call_inputs(path: Path, func: str) -> str:+ """The literal source of the ``inputs={...}`` argument of the ``plan`` stage call."""+ import ast++ tree = ast.parse(path.read_text())+ scope = next((n for n in ast.walk(tree)+ if isinstance(n, ast.FunctionDef) and n.name == func), None)+ assert scope is not None, f"{path.name} has no {func}()"+ for node in ast.walk(scope):+ if (isinstance(node, ast.Call)+ and getattr(node.func, "attr", "") == "stage"+ and node.args+ and isinstance(node.args[0], ast.Constant)+ and node.args[0].value == "plan"):+ for kw in node.keywords:+ if kw.arg == "inputs":+ return ast.dump(kw.value)+ raise AssertionError(f"{path.name}::{func} has no runner.stage('plan', ..., inputs=...) call")+++def test_the_seeded_plan_and_the_running_plan_share_one_stage_key():+ """`plan_once` and `BaseTrack.run` must key the plan stage by the same expression.++ The only legitimate difference is the receiver holding the track: `plan_once` keeps it+ in a local named `track`, `run` is a method and says `self`. Everything else -- the+ keys, the helper called on the spec, the attribute path -- must match exactly.+ """++ harness = Path(__file__).resolve().parents[2]+ seeded = _stage_call_inputs(harness / "bench" / "pin_plan.py", "plan_once")+ running = _stage_call_inputs(harness / "codeverse" / "tracks" / "lifecycle.py", "run")++ def norm(dump: str) -> str:+ return dump.replace("Name(id='self',", "Name(id='track',")++ assert norm(seeded) == norm(running), (+ "the pinned plan and the arm that consumes it no longer compute the same "+ "stage-cache key.\n pin_plan.plan_once: " + seeded+ + "\n lifecycle.run: " + running+ + "\nA seeded plan would be a cache MISS: both arms re-plan, neither is pinned, and "+ "the A/B reports 'no effect' for an experiment it silently deleted."+ )+ assert "plan_stage_inputs" in seeded, "the key stopped going through plan_stage_inputs"