Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/format_bench/shards.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _hardlink_tree(source: Path, destination: Path) -> None:

def _mkdir_private_tree(destination: Path) -> None:
missing: list[Path] = []
current = destination
current = destination.parent
while not current.exists():
missing.append(current)
parent = current.parent
Expand All @@ -152,6 +152,10 @@ def _mkdir_private_tree(destination: Path) -> None:
# parent creation before the private output leaf exists.
for directory in reversed(missing):
directory.mkdir(mode=0o700)
# LLM contract: OUTPUT_ABSENT -> OUTPUT_CREATED | COLLISION_REJECTED.
# The final leaf stays exclusive even if another process creates it after
# merge validation but before publication begins.
destination.mkdir(mode=0o700)


def _copy_run_files(base_run: Path, output_run: Path) -> None:
Expand Down
12 changes: 11 additions & 1 deletion tests/test_shards.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pytest

from format_bench.shards import merge_equivalence_shards
from format_bench.shards import _mkdir_private_tree, merge_equivalence_shards


def _write(path: Path, value: object) -> None:
Expand Down Expand Up @@ -111,6 +111,16 @@ def _shard_results(pair: str, name: str) -> dict:
}


def test_private_output_tree_rejects_race_created_leaf(tmp_path: Path) -> None:
output = tmp_path / "missing" / "nested" / "merged"
output.mkdir(parents=True)

with pytest.raises(FileExistsError):
_mkdir_private_tree(output)

assert list(output.iterdir()) == []


@pytest.mark.skipif(os.name != "posix", reason="POSIX directory-mode contract")
@pytest.mark.parametrize("mask", (0o002, 0o000))
def test_merge_equivalence_shards_reuses_artifacts_and_unions_results(
Expand Down
Loading