Spaces:
Sleeping
Sleeping
Normalize challenge target paths
Browse filesFiles changed (3)
5 unmodified lines678910910116 unmodified lines1819202122232425252627285 unmodified linesimport osfrom collections.abc import Callable
from architect.graph import build_graph
PIPELINE_ENV = "CHALLENGE_PIPELINE"LEGACY_PIPELINE = "legacy"6 unmodified lines
def build_selected_graph(progress_callback: Callable[[int, str], None] | None = None): from architect.graph import build_graph
variant = get_challenge_pipeline_variant() if variant == BUG_FIRST_PIPELINE: # Bug-first implementation is added separately after replay coverage. # Bug-first behavior is selected inside architect nodes from the environment flag. return build_graph(progress_callback=progress_callback) return build_graph(progress_callback=progress_callback)
379 unmodified lines380381382383383384385386387388389390391392393394395396397379 unmodified lines result = graph.invoke(initial_state)
workspace_path = result["clone_path"] target_file_rel = result.get("target_file", "") workspace_root = Path(workspace_path).resolve() target_file_rel = "" target_file_value = str(result.get("target_file") or "") if target_file_value: target_path = Path(target_file_value) if not target_path.is_absolute(): target_path = workspace_root / target_path try: target_path = target_path.resolve(strict=True) target_file_rel = target_path.relative_to(workspace_root).as_posix() except (FileNotFoundError, OSError, ValueError) as exc: raise ValueError("Generated challenge target file is outside the workspace or unavailable") from exc actual_sabotaged_code = result.get("sabotaged_code", "") workspace_root = Path(workspace_path).resolve() if target_file_rel:59 unmodified lines60616263646566676869707172737475767759 unmodified lines self.assertEqual(workspace_path.parent, Path(root)) self.assertTrue((workspace_path / "challenge_state.json").is_file()) state = json.loads((workspace_path / "challenge_state.json").read_text(encoding="utf-8")) self.assertEqual(state["target_file"], "sample.py") self.assertEqual(state["sabotaged_code"], "def broken(): return None\n") self.assertNotIn("original_code", state) self.assertNotIn("public_tests", state) with patch.object(repo_cloner, "WORKSPACES_DIR", root): private_state = json.loads((private_workspace_dir(workspace_path) / "challenge_state.json").read_text(encoding="utf-8")) self.assertEqual(private_state["target_file"], "sample.py") self.assertEqual(private_state["original_code"], "def broken(): return 1\n") self.assertEqual(private_state["public_tests"], [{"args": "()", "expected": "1"}]) with patch.object(repo_cloner, "WORKSPACES_DIR", root): workspace = ChallengeWorkspace(str(workspace_path)) self.assertEqual(workspace.target_file, "sample.py")
def test_round_creates_identical_isolated_workspaces_and_verifies_hashes(self): with tempfile.TemporaryDirectory() as root, patch.object(repo_cloner, "WORKSPACES_DIR", root):architect/bug_first_pipeline.py+3-3
challenge_runtime.py+12-1
test_challenge_runtime.py+5