| 1 | """Mount-vs-clone lane: variant command shapes, skip honesty, disk fields."""
|
| 2 |
|
| 3 | from __future__ import annotations
|
| 4 |
|
| 5 | import sys
|
| 6 | import tempfile
|
| 7 | import unittest
|
| 8 | from pathlib import Path
|
| 9 |
|
| 10 | sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
|
| 11 |
|
| 12 | import mount_vs_clone # noqa: E402
|
| 13 | from oakbench import rows as oakbench_rows # noqa: E402
|
| 14 |
|
| 15 | METADATA = {"bench_id": "test", "profile": "mount-vs-clone"}
|
| 16 |
|
| 17 |
|
| 18 | class AcquireCommandsTest(unittest.TestCase):
|
| 19 | def commands(self, variant: str) -> list[list[str]]:
|
| 20 | return mount_vs_clone.acquire_commands(
|
| 21 | variant, "oak", "git", "oak/bench-large-mirror",
|
| 22 | "https://github.com/oakdotspace/bench-large-mirror.git",
|
| 23 | Path("/tmp/dest"), "docs",
|
| 24 | )
|
| 25 |
|
| 26 | def test_single_command_variants(self) -> None:
|
| 27 | for variant in ("oak_mount", "git_clone_full", "git_clone_shallow", "git_clone_blobless"):
|
| 28 | self.assertEqual(len(self.commands(variant)), 1, variant)
|
| 29 |
|
| 30 | def test_sparse_task_pays_three_tool_calls(self) -> None:
|
| 31 | commands = self.commands("git_sparse_task")
|
| 32 | self.assertEqual(len(commands), 3)
|
| 33 | self.assertIn("--no-checkout", commands[0])
|
| 34 | self.assertIn("sparse-checkout", commands[1])
|
| 35 |
|
| 36 | def test_blobless_checkout_still_full_tree(self) -> None:
|
| 37 | # Documented gotcha: --filter=blob:none without --no-checkout hydrates
|
| 38 | # the full working tree; only git_sparse_task adds --no-checkout.
|
| 39 | (command,) = self.commands("git_clone_blobless")
|
| 40 | self.assertIn("--filter=blob:none", command)
|
| 41 | self.assertNotIn("--no-checkout", command)
|
| 42 |
|
| 43 | def test_unknown_variant_rejected(self) -> None:
|
| 44 | with self.assertRaises(SystemExit):
|
| 45 | self.commands("git_lfs")
|
| 46 |
|
| 47 |
|
| 48 | class SkipRowTest(unittest.TestCase):
|
| 49 | def test_skip_row_satisfies_mount_lane_contract(self) -> None:
|
| 50 | row = mount_vs_clone.skip_row(METADATA, "oak_mount", "oak", "acquire_cold", 0, "set OAK_BENCH_MIRROR_REPO")
|
| 51 | self.assertEqual(oakbench_rows.validate_rows([row], "mount"), [])
|
| 52 | self.assertEqual(row["returncode"], 77)
|
| 53 | self.assertTrue(row["skipped"])
|
| 54 |
|
| 55 |
|
| 56 | class FailureExitTest(unittest.TestCase):
|
| 57 | def test_real_failures_are_nonzero_but_skips_are_not(self) -> None:
|
| 58 | skip = mount_vs_clone.skip_row(
|
| 59 | METADATA, "oak_mount", "oak", "acquire_cold", 0, "set OAK_BENCH_MIRROR_REPO"
|
| 60 | )
|
| 61 | self.assertFalse(mount_vs_clone.rows_contain_failures([skip]))
|
| 62 |
|
| 63 | failed = {
|
| 64 | **mount_vs_clone.base_row(
|
| 65 | METADATA, "git_clone_full", "git", "acquire_cold", "acquire.first_read", 0
|
| 66 | ),
|
| 67 | "elapsed_ms": 1.0,
|
| 68 | "returncode": 1,
|
| 69 | }
|
| 70 | self.assertTrue(mount_vs_clone.rows_contain_failures([skip, failed]))
|
| 71 |
|
| 72 |
|
| 73 | class DiskRowFieldsTest(unittest.TestCase):
|
| 74 | def test_git_dest_splits_store_and_worktree(self) -> None:
|
| 75 | with tempfile.TemporaryDirectory() as tmp:
|
| 76 | dest = Path(tmp)
|
| 77 | (dest / ".git").mkdir()
|
| 78 | (dest / ".git" / "pack").write_bytes(b"x" * 4096)
|
| 79 | (dest / "README.md").write_bytes(b"y" * 1024)
|
| 80 | fields = mount_vs_clone.disk_row_fields(dest, "git_clone_full")
|
| 81 | self.assertIsNotNone(fields["vcs_store_allocated_bytes"])
|
| 82 | self.assertGreaterEqual(fields["worktree_allocated_bytes"], 0)
|
| 83 |
|
| 84 | def test_oak_dest_reports_unmeasured_store_as_null(self) -> None:
|
| 85 | with tempfile.TemporaryDirectory() as tmp:
|
| 86 | dest = Path(tmp)
|
| 87 | (dest / "README.md").write_bytes(b"y" * 1024)
|
| 88 | fields = mount_vs_clone.disk_row_fields(dest, "oak_mount")
|
| 89 | # Null means unmeasured (ADR-0002): oak's chunk store is not under
|
| 90 | # dest/.git and must never be reported as zero bytes.
|
| 91 | self.assertIsNone(fields["vcs_store_allocated_bytes"])
|
| 92 | self.assertIsNone(fields["oak_global_cache_bytes"])
|
| 93 | self.assertEqual(
|
| 94 | fields["oak_global_cache_state"],
|
| 95 | mount_vs_clone.OAK_CACHE_STATE_UNCHECKED,
|
| 96 | )
|
| 97 |
|
| 98 | def test_oak_acquire_rows_record_os_purge_and_unchecked_global_cache_state(self) -> None:
|
| 99 | self.assertEqual(
|
| 100 | mount_vs_clone.cache_state_fields(
|
| 101 | "oak_mount",
|
| 102 | {"attempted": True, "ok": True, "method": "darwin_purge", "error": None},
|
| 103 | ),
|
| 104 | {
|
| 105 | "requested_cache_state": "cold",
|
| 106 | "cache_state": "unknown",
|
| 107 | "cache_state_reason": f"fs_caches_purged: darwin_purge; {mount_vs_clone.OAK_CACHE_STATE_UNCHECKED}",
|
| 108 | "oak_global_cache_state": mount_vs_clone.OAK_CACHE_STATE_UNCHECKED,
|
| 109 | },
|
| 110 | )
|
| 111 | self.assertEqual(
|
| 112 | mount_vs_clone.cache_state_fields(
|
| 113 | "git_clone_full",
|
| 114 | {"attempted": True, "ok": True, "method": "darwin_purge", "error": None},
|
| 115 | ),
|
| 116 | {
|
| 117 | "requested_cache_state": "cold",
|
| 118 | "cache_state": "cold",
|
| 119 | "cache_state_reason": "fs_caches_purged: darwin_purge",
|
| 120 | },
|
| 121 | )
|
| 122 |
|
| 123 |
|
| 124 | class ScopedTaskFilesTest(unittest.TestCase):
|
| 125 | def test_deterministic_sorted_and_limited(self) -> None:
|
| 126 | with tempfile.TemporaryDirectory() as tmp:
|
| 127 | dest = Path(tmp)
|
| 128 | (dest / "docs" / "b").mkdir(parents=True)
|
| 129 | (dest / "docs" / "a").mkdir(parents=True)
|
| 130 | (dest / "docs" / "b" / "two.md").write_text("2")
|
| 131 | (dest / "docs" / "a" / "one.md").write_text("1")
|
| 132 | (dest / "docs" / "a" / "three.md").write_text("3")
|
| 133 | files = mount_vs_clone.scoped_task_files(dest, "docs", 2)
|
| 134 | self.assertEqual(files, ["docs/a/one.md", "docs/a/three.md"])
|
| 135 |
|
| 136 | def test_missing_prefix_returns_empty(self) -> None:
|
| 137 | with tempfile.TemporaryDirectory() as tmp:
|
| 138 | self.assertEqual(mount_vs_clone.scoped_task_files(Path(tmp), "docs", 5), [])
|
| 139 |
|
| 140 |
|
| 141 | class ManifestContentVerificationTest(unittest.TestCase):
|
| 142 | def test_manifest_hash_verifies_file_bytes(self) -> None:
|
| 143 | with tempfile.TemporaryDirectory() as tmp:
|
| 144 | dest = Path(tmp)
|
| 145 | (dest / "README.md").write_bytes(b"expected bytes\n")
|
| 146 | digest = mount_vs_clone.hashlib.sha256(b"expected bytes\n").hexdigest()
|
| 147 | manifest = mount_vs_clone.parse_manifest(f"{digest} README.md\n")
|
| 148 | fields = mount_vs_clone.content_verification_fields(dest, ["README.md"], manifest)
|
| 149 | self.assertTrue(fields["content_verified"])
|
| 150 | self.assertEqual(fields["content_check_status"], "passed")
|
| 151 | self.assertEqual(fields["content_verified_files"], 1)
|
| 152 |
|
| 153 | def test_manifest_mismatch_marks_row_failed(self) -> None:
|
| 154 | with tempfile.TemporaryDirectory() as tmp:
|
| 155 | dest = Path(tmp)
|
| 156 | (dest / "README.md").write_bytes(b"actual bytes\n")
|
| 157 | manifest = mount_vs_clone.parse_manifest(f"{'0' * 64} README.md\n")
|
| 158 | row = {
|
| 159 | **mount_vs_clone.base_row(METADATA, "oak_mount", "oak", "acquire_cold", "acquire.first_read", 0),
|
| 160 | "elapsed_ms": 1.0,
|
| 161 | "returncode": 0,
|
| 162 | }
|
| 163 | mount_vs_clone.apply_content_verification(
|
| 164 | row,
|
| 165 | mount_vs_clone.content_verification_fields(dest, ["README.md"], manifest),
|
| 166 | )
|
| 167 | self.assertEqual(row["returncode"], 1)
|
| 168 | self.assertFalse(row["content_verified"])
|
| 169 | self.assertEqual(row["content_check_status"], "failed")
|
| 170 |
|
| 171 | def test_scoped_read_requires_every_file_in_manifest(self) -> None:
|
| 172 | with tempfile.TemporaryDirectory() as tmp:
|
| 173 | dest = Path(tmp)
|
| 174 | (dest / "docs").mkdir()
|
| 175 | (dest / "docs" / "one.md").write_text("one")
|
| 176 | manifest = mount_vs_clone.parse_manifest(
|
| 177 | f"{mount_vs_clone.hashlib.sha256(b'one').hexdigest()} docs/one.md\n"
|
| 178 | )
|
| 179 | fields = mount_vs_clone.content_verification_fields(
|
| 180 | dest,
|
| 181 | ["docs/one.md", "docs/two.md"],
|
| 182 | manifest,
|
| 183 | )
|
| 184 | self.assertFalse(fields["content_verified"])
|
| 185 | self.assertEqual(fields["content_check_status"], "missing_manifest_entries")
|
| 186 | self.assertEqual(fields["content_missing_manifest_entries"], ["docs/two.md"])
|
| 187 |
|
| 188 |
|
| 189 | if __name__ == "__main__":
|
| 190 | unittest.main()
|