Spaces:
Sleeping
Sleeping
Normalize challenge target paths
Browse filesFiles changed (3)
5 unmodified lines6789101112136 unmodified lines2021222324252627285 unmodified linesimport osfrom collections.abc import Callablefrom architect.graph import build_graphPIPELINE_ENV = "CHALLENGE_PIPELINE"LEGACY_PIPELINE = "legacy"6 unmodified linesdef build_selected_graph(progress_callback: Callable[[int, str], None] | None = None):variant = get_challenge_pipeline_variant()if variant == BUG_FIRST_PIPELINE:# Bug-first implementation is added separately after replay coverage.return build_graph(progress_callback=progress_callback)return build_graph(progress_callback=progress_callback)5 unmodified lines678910116 unmodified lines18192021222324252627285 unmodified linesimport osfrom collections.abc import CallablePIPELINE_ENV = "CHALLENGE_PIPELINE"LEGACY_PIPELINE = "legacy"6 unmodified linesdef build_selected_graph(progress_callback: Callable[[int, str], None] | None = None):from architect.graph import build_graphvariant = get_challenge_pipeline_variant()if variant == BUG_FIRST_PIPELINE:# 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 lines380381382383384385386379 unmodified linesresult = graph.invoke(initial_state)workspace_path = result["clone_path"]target_file_rel = result.get("target_file", "")actual_sabotaged_code = result.get("sabotaged_code", "")workspace_root = Path(workspace_path).resolve()if target_file_rel:379 unmodified lines380381382383384385386387388389390391392393394395396397379 unmodified linesresult = graph.invoke(initial_state)workspace_path = result["clone_path"]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_pathtry: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 excactual_sabotaged_code = result.get("sabotaged_code", "")workspace_root = Path(workspace_path).resolve()if target_file_rel:
59 unmodified lines6061626364656667686970717259 unmodified linesself.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["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["original_code"], "def broken(): return 1\n")self.assertEqual(private_state["public_tests"], [{"args": "()", "expected": "1"}])def test_round_creates_identical_isolated_workspaces_and_verifies_hashes(self):with tempfile.TemporaryDirectory() as root, patch.object(repo_cloner, "WORKSPACES_DIR", root):59 unmodified lines60616263646566676869707172737475767759 unmodified linesself.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