|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import io |
3 | 4 | import sys |
| 5 | +import tarfile |
| 6 | +import subprocess |
4 | 7 |
|
5 | 8 |
|
6 | 9 | def test_run_checked_times_out_fail_loud(tmp_path) -> None: |
@@ -156,6 +159,50 @@ def test_stream_repo_dirs_yields_extracted_src_without_tar(tmp_path) -> None: |
156 | 159 | assert yielded == [("repo", root / "repo" / "_src")] |
157 | 160 |
|
158 | 161 |
|
| 162 | +def test_stream_repo_subtrees_skips_legacy_file_directory_conflict( |
| 163 | + tmp_path, |
| 164 | + monkeypatch, |
| 165 | + capsys, |
| 166 | +) -> None: |
| 167 | + import streaming_reindex |
| 168 | + |
| 169 | + tar_path = tmp_path / "source.tar" |
| 170 | + zst_path = tmp_path / "source.tar.zst" |
| 171 | + with tarfile.open(tar_path, "w") as tf: |
| 172 | + child_info = tarfile.TarInfo("cpp_all/repo/conflict/child.txt") |
| 173 | + child_payload = b"child creates the conflict directory\n" |
| 174 | + child_info.size = len(child_payload) |
| 175 | + child_info.mode = 0o644 |
| 176 | + tf.addfile(child_info, io.BytesIO(child_payload)) |
| 177 | + |
| 178 | + file_info = tarfile.TarInfo("cpp_all/repo/conflict") |
| 179 | + payload = b"this cannot be materialized over a directory\n" |
| 180 | + file_info.size = len(payload) |
| 181 | + file_info.mode = 0o644 |
| 182 | + tf.addfile(file_info, io.BytesIO(payload)) |
| 183 | + |
| 184 | + good_info = tarfile.TarInfo("cpp_all/repo/good.cpp") |
| 185 | + good_payload = b"int good;\n" |
| 186 | + good_info.size = len(good_payload) |
| 187 | + good_info.mode = 0o644 |
| 188 | + tf.addfile(good_info, io.BytesIO(good_payload)) |
| 189 | + |
| 190 | + subprocess.run(["zstd", "-q", "-f", str(tar_path), "-o", str(zst_path)], check=True) |
| 191 | + monkeypatch.setattr(streaming_reindex, "TARBALL", zst_path) |
| 192 | + |
| 193 | + yielded = list( |
| 194 | + streaming_reindex.stream_repo_subtrees( |
| 195 | + tmp_path / "work", |
| 196 | + lambda repo: repo == "repo", |
| 197 | + ) |
| 198 | + ) |
| 199 | + |
| 200 | + assert yielded == [("repo", tmp_path / "work" / "repo" / "_src")] |
| 201 | + assert (tmp_path / "work" / "repo" / "_src" / "conflict").is_dir() |
| 202 | + assert (tmp_path / "work" / "repo" / "_src" / "good.cpp").read_text() == "int good;\n" |
| 203 | + assert "skip tar file" in capsys.readouterr().err |
| 204 | + |
| 205 | + |
159 | 206 | def test_populate_source_cache_only_materializes_cache(tmp_path, monkeypatch) -> None: |
160 | 207 | import streaming_reindex |
161 | 208 |
|
|
0 commit comments