team-ljyzipelo

공개

러너 경로 검사와 도구 재사용 수정함

작성자
코노모리 카논
작성 시각
커밋
cc63769a9b8af7dca30d6e138153081812935816
부모
486cd84
이 시점의 파일 보기

변경된 파일 2개

+54-4
수정tests/ci/run_rust.py+11-4
@@ -31,8 +31,15 @@ def work_directory(root, name):
3131 cwd=root, text=True,
3232 ).strip()).resolve()
3333 project = common.parent if common.name == ".git" else root.resolve()
34삭제: base = project / "tests/work"
35삭제: base.mkdir(parents=True, exist_ok=True)
34추가: tests = project / "tests"
35추가: base = tests / "work"
36추가: if tests.is_symlink() or not tests.is_dir():
37추가: raise ValueError(f"안전한 작업 디렉터리가 필요함: {tests}")
38추가: if base.is_symlink() or (base.exists() and not base.is_dir()):
39추가: raise ValueError(f"안전한 작업 디렉터리가 필요함: {base}")
40추가: base.mkdir(mode=0o700, exist_ok=True)
41추가: if base.resolve() != base:
42추가: raise ValueError(f"안전한 작업 디렉터리가 필요함: {base}")
3643 path = base / name
3744 if path.is_symlink() or (path.exists() and not path.is_dir()):
3845 raise ValueError(f"안전한 작업 디렉터리가 필요함: {path}")
@@ -165,8 +172,8 @@ def prepare_tools(root):
165172 ["git", "rev-parse", "--path-format=absolute", "--git-common-dir"],
166173 cwd=root, text=True,
167174 ).strip())
168삭제: # 같은 저장소의 기본 worktree에 준비한 도구만 재사용함.
169삭제: if common.name == ".git" and common.parent != root:
175추가: # 같은 저장소의 기본 worktree에 준비한 도구를 재사용함.
176추가: if common.name == ".git":
170177 directories.append(common.parent / "tests/ci/tools")
171178 for tools in directories:
172179 if (tools / "rustup/toolchains/1.99.1-x86_64-unknown-linux-gnu").is_dir():
수정tests/ci/test_runner.py+43-0
@@ -24,6 +24,27 @@ class RunnerTests(unittest.TestCase):
2424 run_rust.work_directory(run_rust.ROOT, name)
2525 self.assertEqual(run_rust.work_directory(run_rust.ROOT, os.environ["ZIPELO_CI_JOB"]), TEST_WORK)
2626
27추가: def test_work_directory_rejects_symlinked_parents_before_creation(self):
28추가: for link_name in ("tests", "tests/work"):
29추가: with self.subTest(link_name=link_name), tempfile.TemporaryDirectory(
30추가: dir=TEST_WORK
31추가: ) as directory:
32추가: base = Path(directory)
33추가: project = base / "project"
34추가: project.mkdir()
35추가: outside = base / "outside"
36추가: outside.mkdir()
37추가: link = project / link_name
38추가: link.parent.mkdir(parents=True, exist_ok=True)
39추가: link.symlink_to(outside, target_is_directory=True)
40추가: with patch.object(
41추가: run_rust.subprocess, "check_output", return_value=str(project / ".git")
42추가: ):
43추가: with self.assertRaisesRegex(ValueError, "안전한 작업 디렉터리"):
44추가: run_rust.work_directory(project, "task")
45추가: self.assertFalse((outside / "task").exists())
46추가: self.assertFalse((outside / "work").exists())
47추가:
2748 def test_output_paths_reject_symlinks_outside_job(self):
2849 with tempfile.TemporaryDirectory(dir=TEST_WORK) as directory:
2950 work = Path(directory)
@@ -189,6 +210,28 @@ class RunnerTests(unittest.TestCase):
189210 str(binaries / "x86_64-w64-mingw32-gcc-posix"),
190211 )
191212
213추가: @unittest.skipUnless(sys.platform == "linux", "Linux MinGW 실행 파일 탐색 시험임")
214추가: def test_default_checkout_reuses_existing_setup_tools(self):
215추가: with tempfile.TemporaryDirectory(dir=TEST_WORK) as directory:
216추가: root = Path(directory)
217추가: tools = root / "tests/ci/tools"
218추가: binaries = tools / "mingw/usr/bin"
219추가: binaries.mkdir(parents=True)
220추가: executable = binaries / "x86_64-w64-mingw32-gcc-posix"
221추가: executable.write_text("#!/bin/sh\nexit 0\n")
222추가: executable.chmod(0o700)
223추가: rustup = tools / "rustup"
224추가: (rustup / "toolchains/1.99.1-x86_64-unknown-linux-gnu").mkdir(parents=True)
225추가: with (
226추가: patch.dict(run_rust.os.environ, {"PATH": ""}, clear=True),
227추가: patch.object(run_rust.subprocess, "check_output", return_value=str(root / ".git")),
228추가: ):
229추가: run_rust.prepare_tools(root)
230추가: self.assertEqual(run_rust.os.environ["RUSTUP_HOME"], str(rustup))
231추가: self.assertTrue(run_rust.os.environ["PATH"].startswith(str(binaries)))
232추가: self.assertEqual(run_rust.shutil.which("x86_64-w64-mingw32-gcc-posix"),
233추가: str(executable))
234추가:
192235 def test_local_bootstraps_missing_cross_tools_and_reloads_paths(self):
193236 for root in (Path("/repo"), PurePosixPath("/repo"), PureWindowsPath("C:/repo")):
194237 with self.subTest(root=root):