Copy asset catalogs into an Xcode worker.

actool does not follow a symlinked .xcassets, so the worker build fails
with a missing AppIcon and a mutant that still compiles is reported
killed. Copy the catalog, including resources that were themselves
links, and keep linking other files.

Proved by the worker overlay test and a stand-in xcodebuild that
rejects a symlinked catalog. 127 passed, 1 skipped.

Co-authored-by: Robert C. Martin <[email protected]>
This commit is contained in:
Cursor Agent
2026-11-26 02:49:35 +00:00
co-authored by Robert C. Martin
parent b1d53b0085
commit 0cfa995431
3 changed files with 130 additions and 9 deletions
+1 -1
View File
@@ -37,7 +37,7 @@ Exit `0` when every executed mutant was killed. Exit `2` when the baseline tests
Mutants of one file run at the same time. The default is one worker per core. `--max-workers` sets the cap. The run uses the smaller of that cap, the number of cores, and the number of selected sites. Files are still taken one at a time. Mutants of one file run at the same time. The default is one worker per core. `--max-workers` sets the cap. The run uses the smaller of that cap, the number of cores, and the number of selected sites. Files are still taken one at a time.
Each worker is a directory under `target/mutation-workers`. The file being mutated is a private copy. A module that reaches that file through a relative import is copied too, so Node resolves the import to the private copy. The rest of the tree is linked. The original files stay as they are. The overlay is removed when that file's mutants finish. Each worker is a directory under `target/mutation-workers`. The file being mutated is a private copy. A module that reaches that file through a relative import is copied too, so Node resolves the import to the private copy. The rest of the tree is linked. An Xcode project, workspace, or asset catalog is copied: xcodebuild realpaths a project symlink, and actool will not follow a symlinked catalog. The original files stay as they are. The overlay is removed when that file's mutants finish.
The baseline still runs once, in the real tree, before any worker starts. The mutant command then runs inside the worker, in the same directory it would have used in the real tree, so a relative path such as `src` or `./pkg` refers to the overlay. A copy left under `target/mutator-backup/` by an interrupted older run is restored before a non-scan run. The baseline still runs once, in the real tree, before any worker starts. The mutant command then runs inside the worker, in the same directory it would have used in the real tree, so a relative path such as `src` or `./pkg` refers to the overlay. A copy left under `target/mutator-backup/` by an interrupted older run is restored before a non-scan run.
+15 -8
View File
@@ -1,10 +1,12 @@
"""Run mutants in symlink overlays, the way clj-mutate runs its workers. """Run mutants in symlink overlays, the way clj-mutate runs its workers.
Each worker is a directory under target/mutation-workers. Project files are Each worker is a directory under target/mutation-workers. Project files are
linked in. An Xcode project or workspace is copied instead, because xcodebuild linked in. An Xcode project, workspace, or asset catalog is copied instead.
realpaths a symlink and would compile the original tree. The file under test xcodebuild realpaths a project symlink and would compile the original tree.
is a private copy, so workers can mutate it at the same time without touching actool does not follow a symlinked catalog, so a mutant that still compiles
the original tree. The overlay is removed when the file's mutants finish. is reported killed. The file under test is a private copy, so workers can
mutate it at the same time without touching the original tree. The overlay
is removed when the file's mutants finish.
""" """
from __future__ import annotations from __future__ import annotations
@@ -143,10 +145,15 @@ def _copy_configs(worker: Path, root: Path, relative: str) -> None:
(worker / name).write_bytes(source.read_bytes()) (worker / name).write_bytes(source.read_bytes())
def _xcode_bundle(path: Path) -> bool: def _copied_bundle(path: Path) -> bool:
"""An Xcode project or workspace. xcodebuild realpaths it before compiling.""" """A directory the build realpaths or will not follow as a link.
return path.suffix in {".xcodeproj", ".xcworkspace"} and path.is_dir() A file that merely ends in one of these suffixes stays a link. So does a
directory that only contains a catalog: opening the catalog follows that
parent link and sees the real tree.
"""
return path.is_dir() and path.suffix in {".xcodeproj", ".xcworkspace", ".xcassets"}
def _copy_bundle(source: Path, destination: Path) -> None: def _copy_bundle(source: Path, destination: Path) -> None:
@@ -174,7 +181,7 @@ def _link_children(worker_dir: Path, real_dir: Path, skip: set[str]) -> None:
destination = worker_dir / child.name destination = worker_dir / child.name
if destination.exists() or destination.is_symlink(): if destination.exists() or destination.is_symlink():
continue continue
if _xcode_bundle(child): if _copied_bundle(child):
_copy_bundle(child, destination) _copy_bundle(child, destination)
continue continue
symlink(destination, child) symlink(destination, child)
+114
View File
@@ -283,6 +283,44 @@ def test_a_worker_copies_an_xcode_bundle_and_links_a_file_with_that_suffix(tmp_p
assert linked.read_text(encoding="utf-8") == "not a bundle\n" assert linked.read_text(encoding="utf-8") == "not a bundle\n"
def test_a_worker_copies_an_asset_catalog_and_keeps_safe_links(tmp_path):
from mutator.workers import create_workers, new_run_dir
root = tmp_path / "ios"
source = _write(root / "DungeonDoor" / "Core" / "AppConfig.swift", "func body() -> Int { 1 }\n")
_write(root / "DungeonDoor.xcodeproj" / "project.pbxproj", "path = DungeonDoor/Core/AppConfig.swift;\n")
shared = tmp_path / "shared-icon"
_write(shared / "AppIcon.png", "png-bytes")
catalog = root / "DungeonDoor" / "Assets.xcassets"
_write(catalog / "AccentColor.colorset" / "Contents.json", '{"color":"accent"}\n')
(catalog / "AppIcon.appiconset").symlink_to(shared)
_write(root / "DungeonDoor" / "Notes.xcassets", "not a catalog\n")
_write(root / "DungeonDoor" / "Preview" / "readme.txt", "preview\n")
_write(root / "Docs" / "readme.txt", "notes\n")
worker = create_workers(
new_run_dir(root),
root,
"DungeonDoor/Core/AppConfig.swift",
source.read_bytes(),
1,
)[0]
copied = worker / "DungeonDoor" / "Assets.xcassets"
icon = copied / "AppIcon.appiconset" / "AppIcon.png"
accent = copied / "AccentColor.colorset" / "Contents.json"
assert copied.is_dir() and not copied.is_symlink()
assert (copied / "AppIcon.appiconset").is_dir()
assert not (copied / "AppIcon.appiconset").is_symlink()
assert icon.is_file() and not icon.is_symlink()
assert icon.read_text(encoding="utf-8") == "png-bytes"
assert accent.is_file() and not accent.is_symlink()
assert accent.read_text(encoding="utf-8") == '{"color":"accent"}\n'
assert (worker / "DungeonDoor" / "Notes.xcassets").is_symlink()
assert (worker / "DungeonDoor" / "Preview").is_symlink()
assert (worker / "Docs").is_symlink()
assert (catalog / "AppIcon.appiconset").is_symlink()
assert (shared / "AppIcon.png").read_text(encoding="utf-8") == "png-bytes"
def test_a_worker_does_not_share_swift_build_directories(tmp_path): def test_a_worker_does_not_share_swift_build_directories(tmp_path):
from mutator.workers import create_workers, new_run_dir from mutator.workers import create_workers, new_run_dir
@@ -426,6 +464,42 @@ if ">=" in body or "!(" in body:
raise SystemExit(0) raise SystemExit(0)
""" """
# actool rejects a symlinked catalog, then the build dies even when the mutant
# still compiles. A real catalog with AppIcon and AccentColor is accepted.
_CATALOG_BUILD = """#!/usr/bin/env python3
import os
import sys
from pathlib import Path
cwd = Path.cwd()
log = Path(os.environ["XCODE_LOG"])
found = []
for dirpath, dirnames, _filenames in os.walk(cwd):
for name in list(dirnames):
if name.endswith(".xcassets"):
found.append(Path(dirpath) / name)
dirnames.remove(name)
broken = []
for catalog in found:
icon = catalog / "AppIcon.appiconset" / "AppIcon.png"
accent = catalog / "AccentColor.colorset" / "Contents.json"
if catalog.is_symlink() or not icon.is_file() or not accent.is_file():
broken.append(str(catalog))
with log.open("a", encoding="utf-8") as handle:
handle.write(str(cwd) + "\\n")
handle.write("broken " + str(len(broken)) + "\\n")
handle.write("---\\n")
if not found or broken:
catalog = broken[0] if broken else str(cwd)
sys.stderr.write(
catalog
+ ': error: None of the input catalogs contained a matching '
+ 'stickers icon set, app icon set, or icon stack named "AppIcon".\\n'
)
raise SystemExit(65)
raise SystemExit(0)
"""
def _labels(output: str, description: str) -> list[str]: def _labels(output: str, description: str) -> list[str]:
return [line.split()[0] for line in output.splitlines() if description in line] return [line.split()[0] for line in output.splitlines() if description in line]
@@ -533,6 +607,46 @@ def test_a_failing_xcodebuild_baseline_records_no_kills(tmp_path, monkeypatch, c
assert not (root / ".metrics" / "mutate").exists() assert not (root / ".metrics" / "mutate").exists()
def test_a_compiling_mutant_survives_when_the_worker_catalog_is_real(tmp_path, monkeypatch, capsys):
bin_dir = tmp_path / "bin"
log = tmp_path / "xcode.log"
bin_dir.mkdir()
tool = bin_dir / "xcodebuild"
tool.write_text(_CATALOG_BUILD, encoding="utf-8")
tool.chmod(0o755)
monkeypatch.setenv("PATH", f"{bin_dir}{os.pathsep}{os.environ.get('PATH', '')}")
monkeypatch.setenv("XCODE_LOG", str(log))
root = tmp_path / "ios"
source = _write(root / "DungeonDoor" / "Core" / "AppConfig.swift", _IOS_BODY)
project = root / "DungeonDoor.xcodeproj"
_write(project / "project.pbxproj", "path = DungeonDoor/Core/AppConfig.swift;\n")
_write(project / "xcshareddata" / "xcschemes" / "DungeonDoor.xcscheme", "<Scheme/>\n")
catalog = root / "DungeonDoor" / "Assets.xcassets"
_write(catalog / "AppIcon.appiconset" / "AppIcon.png", "png-bytes")
_write(catalog / "AccentColor.colorset" / "Contents.json", '{"color":"accent"}\n')
code = run(
[
"--no-coverage",
"--root",
str(root),
"--max-workers",
"1",
"--xcode-destination",
"platform=iOS Simulator,name=iPhone 17",
]
)
captured = capsys.readouterr()
text = log.read_text(encoding="utf-8")
assert code == 3
assert "SURVIVED" in captured.out
assert "KILLED" not in captured.out
assert "mutation-workers" in text
assert "broken 0" in text
assert "broken 1" not in text
assert source.read_text(encoding="utf-8") == _IOS_BODY
assert catalog.is_dir() and not catalog.is_symlink()
def test_scan_marks_a_swift_line_uncovered_when_llvm_cov_did_not_hit_it(tmp_path, capsys): def test_scan_marks_a_swift_line_uncovered_when_llvm_cov_did_not_hit_it(tmp_path, capsys):
import json import json