oficina / equipo Public

Merge branch 'mac-xcode-log' into main

Merge mac-xcode-log: result bundles and SwiftPM config in scratch

Every xcodebuild action in the checks gate, P2 and P6 writes its
result bundle under the attempt scratch, and srt gates set
XDG_CONFIG_HOME there so SwiftPM's ~/.swiftpm moves too. No profile
paths added. Hosted CI passed on 296bd08.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev fcd713cfe034895a4ece997b7ec91e11ffd07f14 parent aebf560parent 296bd08
8 files changed, +67 −18
  • internal/runner/mac/caps_test.go +1 −1
  • internal/runner/mac/gate.go +9 −2
  • internal/runner/mac/gate_test.go +7 −2
  • internal/runner/mac/p2why_test.go +1 −1
  • internal/runner/mac/probe.go +10 −7
  • internal/runner/mac/probe_test.go +7 −1
  • internal/runner/mac/xcode.go +18 −3
  • internal/runner/mac/xcode_test.go +14 −1

CI cancelled — superseded by a newer push — run details

diff --git a/internal/runner/mac/caps_test.go b/internal/runner/mac/caps_test.go
index 0095a317..5b80c8f1 100644
--- a/internal/runner/mac/caps_test.go
+++ b/internal/runner/mac/caps_test.go
@@ -96,7 +96,7 @@ func TestXcodeGate(t *testing.T) {
sims := ParseSimulators(mustRead(t, "testdata/simctl-devices.json"))
tree := woodstarTree(t, "Woodstar.xcodeproj/xcshareddata/xcschemes/Woodstar.xcscheme", "Woodstar/Swipe.swift")
argv, ok, reason := XcodeGate(tree, sims)
- want := `exec /usr/bin/xcodebuild test -project 'Woodstar.xcodeproj' -scheme 'Woodstar' -destination 'platform=iOS Simulator,id=8F0A1E2B-3D4F-4A5B-9C6D-7E8F90A1B2C3' -derivedDataPath "$TMPDIR/DerivedData" -clonedSourcePackagesDirPath "$TMPDIR/SourcePackages" -packageCachePath "$TMPDIR/PackageCache" CODE_SIGNING_ALLOWED=NO`
+ want := `exec /usr/bin/xcodebuild test -project 'Woodstar.xcodeproj' -scheme 'Woodstar' -destination 'platform=iOS Simulator,id=8F0A1E2B-3D4F-4A5B-9C6D-7E8F90A1B2C3' -derivedDataPath "$TMPDIR/DerivedData" -clonedSourcePackagesDirPath "$TMPDIR/SourcePackages" -packageCachePath "$TMPDIR/PackageCache" -resultBundlePath "$TMPDIR/Results/checks.xcresult" CODE_SIGNING_ALLOWED=NO`
if !ok || reason != "" || !slices.Equal(argv, []string{"/bin/bash", "-c", want}) {
t.Fatalf("%v %v %q", argv, ok, reason)
}
diff --git a/internal/runner/mac/gate.go b/internal/runner/mac/gate.go
index 7545f8c8..f72645ad 100644
--- a/internal/runner/mac/gate.go
+++ b/internal/runner/mac/gate.go
@@ -37,8 +37,8 @@ type Gate struct {
// Settings writes the attempt's srt settings for a tree and scratch.
Settings func(tree, attempt string) ([]byte, error)
// Env is the gate's whole environment but TMPDIR, EQUIPO_ATTEMPT and
- // EQUIPO_GATE_STATUS (and under srt CLAUDE_CODE_TMPDIR), which the
- // run adds.
+ // EQUIPO_GATE_STATUS (and under srt CLAUDE_CODE_TMPDIR and
+ // XDG_CONFIG_HOME), which the run adds.
Env []string
// Caffeinate keeps the Mac awake while a gate runs
// (/usr/bin/caffeinate); "" does not.
@@ -117,6 +117,13 @@ func (g *Gate) Run(ctx context.Context, attempt, dir string, argv []string, limi
// keep it this attempt's scratch, which the profile already lets
// the gate write and the run removes.
cmd.Env = append(cmd.Env, "CLAUDE_CODE_TMPDIR="+scratch)
+ // SwiftPM keeps ~/.swiftpm (links to its security, configuration
+ // and cache folders, and a lock it takes) at $XDG_CONFIG_HOME/
+ // swiftpm when that is set (dotSwiftPM in SwiftPM's Basics), and
+ // removes and remakes the security link on every resolve: under
+ // srt that is a write to the real home, which the profile
+ // refuses. In the attempt's scratch it is the attempt's alone.
+ cmd.Env = append(cmd.Env, "XDG_CONFIG_HOME="+filepath.Join(scratch, "config"))
}
if g.ScratchHome {
cmd.Env = append(cmd.Env, "HOME="+scratch)
diff --git a/internal/runner/mac/gate_test.go b/internal/runner/mac/gate_test.go
index 51075be4..f528c1d4 100644
--- a/internal/runner/mac/gate_test.go
+++ b/internal/runner/mac/gate_test.go
@@ -127,10 +127,15 @@ func TestGateEnvironmentFromScratch(t *testing.T) {
// other user's /tmp/claude decides whether it can write.
func TestGateKeepsTMPDIRUnderSRT(t *testing.T) {
g, dir := gateFixture(t, true)
- res, _ := run(g, dir, "checks-c-2", time.Minute, `echo "$TMPDIR"`)
- if res.Code != 0 || !strings.HasPrefix(res.Output, filepath.Dir(dir)+"/attempt-") {
+ res, _ := run(g, dir, "checks-c-2", time.Minute, `echo "$TMPDIR"; echo "$XDG_CONFIG_HOME"`)
+ lines := strings.Split(res.Output, "\n")
+ if res.Code != 0 || len(lines) != 2 || !strings.HasPrefix(lines[0], filepath.Dir(dir)+"/attempt-") {
t.Fatalf("TMPDIR under srt: %+v", res)
}
+ // SwiftPM's ~/.swiftpm goes to the attempt's scratch too.
+ if lines[1] != lines[0]+"/config" {
+ t.Fatalf("XDG_CONFIG_HOME under srt: %+v", res)
+ }
}
// Cancel and timeout: SIGTERM to the group, SIGKILL after the grace, a
diff --git a/internal/runner/mac/p2why_test.go b/internal/runner/mac/p2why_test.go
index a4859361..6ead65e4 100644
--- a/internal/runner/mac/p2why_test.go
+++ b/internal/runner/mac/p2why_test.go
@@ -202,7 +202,7 @@ func TestP2Script(t *testing.T) {
}
last = i
}
- if strings.Count(s, "-skipPackagePluginValidation") != 3 || strings.Count(s, XcodeWrites) != 5 || strings.Contains(s, "http") {
+ if strings.Count(s, "-skipPackagePluginValidation") != 3 || strings.Count(s, XcodeWrites) != 5 || strings.Count(s, `-resultBundlePath "$TMPDIR/Results/`) != 4 || strings.Contains(s, "http") {
t.Fatalf("script %s", s)
}
}
diff --git a/internal/runner/mac/probe.go b/internal/runner/mac/probe.go
index 0bf8ebd8..78b4ab37 100644
--- a/internal/runner/mac/probe.go
+++ b/internal/runner/mac/probe.go
@@ -387,18 +387,21 @@ func p2Detail(groups map[string][]string, total int, srtRan, ended bool, why str
// writes only into the attempt's scratch (XcodeWrites), as checks do;
// the script phase's target is built through its shared scheme because
// xcodebuild takes -derivedDataPath only for a scheme, and SYMROOT and
-// OBJROOT stay in scratch too should a build fall back to them.
+// OBJROOT stay in scratch too should a build fall back to them. Each
+// action has its own result bundle there (XcodeResult).
func p2Script(xb, xcrun, udid string) string {
dest := quote("platform=iOS Simulator,id=" + udid)
- pkg := ` -scheme "$s" ` + XcodeWrites + ` -skipPackagePluginValidation`
+ pkg := func(step string) string {
+ return ` -scheme "$s" ` + XcodeWrites + ` ` + XcodeResult(step) + ` -skipPackagePluginValidation`
+ }
return `phase() { p=$1; shift; "$@"; c=$?; echo "EQUIPO-PHASE $p $c"; return $c; }
-(cd project && phase script-build ` + xb + ` -project Hostile.xcodeproj -scheme HostileScript -configuration Debug build ` + XcodeWrites + ` SYMROOT="$TMPDIR/sym" OBJROOT="$TMPDIR/obj"); a=$?
+(cd project && phase script-build ` + xb + ` -project Hostile.xcodeproj -scheme HostileScript -configuration Debug build ` + XcodeWrites + ` ` + XcodeResult("script-build") + ` SYMROOT="$TMPDIR/sym" OBJROOT="$TMPDIR/obj"); a=$?
cd package || exit 1
s=Hostile-Package; ` + xb + ` -list ` + XcodeWrites + ` 2>/dev/null | grep -q Hostile-Package || s=Hostile
-phase package-resolve ` + xb + ` -resolvePackageDependencies` + pkg + ` &&
-phase test-build ` + xb + ` build-for-testing -destination ` + dest + pkg + ` &&
+phase package-resolve ` + xb + ` -resolvePackageDependencies` + pkg("package-resolve") + ` &&
+phase test-build ` + xb + ` build-for-testing -destination ` + dest + pkg("test-build") + ` &&
phase simulator-boot ` + xcrun + ` simctl bootstatus ` + quote(udid) + ` -b &&
-phase test-run ` + xb + ` test-without-building -destination ` + dest + ` -only-testing:HostileTests/HostileTests/testHostile` + pkg + `
+phase test-run ` + xb + ` test-without-building -destination ` + dest + ` -only-testing:HostileTests/HostileTests/testHostile` + pkg("test-run") + `
b=$?
[ "$a" = 0 ] && [ "$b" = 0 ]`
}
@@ -675,7 +678,7 @@ func probeP6(ctx context.Context, h ProbeHost, caps wire.Capabilities, srtRan bo
// attempt's scratch as P2's and the checks' are.
func p6Script(xb, destination string) string {
return `cd package && s=Hostile-Package; ` + xb + ` -list ` + XcodeWrites + ` 2>/dev/null | grep -q Hostile-Package || s=Hostile
-exec ` + xb + ` test -scheme "$s" -destination ` + quote(destination) + ` -only-testing:HostileTests/HostileTests/testWait ` + XcodeWrites + ` -skipPackagePluginValidation`
+exec ` + xb + ` test -scheme "$s" -destination ` + quote(destination) + ` -only-testing:HostileTests/HostileTests/testWait ` + XcodeWrites + ` ` + XcodeResult("wait") + ` -skipPackagePluginValidation`
}
// processNames are this user's processes by name (basename), counted.
diff --git a/internal/runner/mac/probe_test.go b/internal/runner/mac/probe_test.go
index 4084b907..e7b56cd9 100644
--- a/internal/runner/mac/probe_test.go
+++ b/internal/runner/mac/probe_test.go
@@ -24,12 +24,18 @@ import (
// FAKE_*_FAIL fails a step the way it fails on a Mac. A call that would
// write Xcode's derived data, package checkouts or package caches
// anywhere but the gate's TMPDIR fails as the Studio's P2 did under srt
-// (exit 65, the PIF cache's "workspace" folder not writable).
+// (exit 65, the PIF cache's "workspace" folder not writable); an action
+// without its result bundle there fails as the default bundle in
+// DARWIN_USER_TEMP_DIR did, and a resolve whose SwiftPM config folder
+// ($XDG_CONFIG_HOME, else ~/.swiftpm) is not in TMPDIR as ~/.swiftpm
+// did (exit 74).
const fakeXcodebuild = `#!/bin/bash
noise() { [ -n "$FAKE_NOISE" ] && for i in $(seq 1 300); do echo "CompileSwift normal arm64 step $i"; done; true; }
for f in -derivedDataPath -clonedSourcePackagesDirPath -packageCachePath; do
case " $* " in *" $f $TMPDIR/"*) ;; *) echo "error: Could not compute dependency graph: Error Domain=NSCocoaErrorDomain Code=513 (no permission to save in the folder workspace; $f not in TMPDIR)"; echo "** BUILD FAILED **"; exit 65 ;; esac
done
+case " $* " in *" -list "*|*" -resultBundlePath $TMPDIR/Results/"*) ;; *) echo "xcodebuild[1] Error saving log: Error Domain=NSCocoaErrorDomain Code=513 (ResultBundle in DARWIN_USER_TEMP_DIR: Operation not permitted)"; echo "** BUILD FAILED **"; exit 65 ;; esac
+case "$*" in *-resolvePackageDependencies*) case "$XDG_CONFIG_HOME" in "$TMPDIR"/*) ;; *) echo "xcodebuild: error: Could not resolve package dependencies:"; echo " .swiftpm/security: Operation not permitted"; exit 74 ;; esac ;; esac
case "$*" in
*-list*) echo " Schemes:"; echo " Hostile-Package"; exit 0 ;;
*HostileScript*)
diff --git a/internal/runner/mac/xcode.go b/internal/runner/mac/xcode.go
index 65ddb5de..dbba4665 100644
--- a/internal/runner/mac/xcode.go
+++ b/internal/runner/mac/xcode.go
@@ -77,10 +77,21 @@ func XcodeGate(tree string, sims []wire.Simulator) (argv []string, ok bool, reas
return nil, true, "checks_unavailable"
}
cmd := "exec /usr/bin/xcodebuild test " + flag + " " + quote(container) + " -scheme " + quote(scheme) +
- " -destination " + quote("platform=iOS Simulator,id="+sim.UDID) + " " + XcodeWrites + " CODE_SIGNING_ALLOWED=NO"
+ " -destination " + quote("platform=iOS Simulator,id="+sim.UDID) + " " + XcodeWrites + " " + XcodeResult("checks") + " CODE_SIGNING_ALLOWED=NO"
return []string{"/bin/bash", "-c", cmd}, true, ""
}
+// XcodeResult names an xcodebuild action's result bundle in the
+// attempt's scratch. Without it xcodebuild stages one as
+// ResultBundle_<date>.xcresult in the user's DARWIN_USER_TEMP_DIR
+// (/private/var/folders/<..>/T, from confstr, not $TMPDIR), which the
+// checks profile does not let it write: the Studio's sandbox log
+// showed those denials. The path must not exist yet, so each action in
+// one attempt has its own name; xcodebuild makes the folders.
+func XcodeResult(name string) string {
+ return `-resultBundlePath "$TMPDIR/Results/` + name + `.xcresult"`
+}
+
// XcodeWrites sends what xcodebuild writes for itself into the
// attempt's scratch ($TMPDIR: the gate's, which the checks profile lets
// it write and the run removes), not the runner user's ~/Library. Every
@@ -88,14 +99,18 @@ func XcodeGate(tree string, sims []wire.Simulator) (argv []string, ok bool, reas
// proves the way checks build.
// - -derivedDataPath: build products and intermediates, XCBuildData
// with its PIF cache (the "workspace" folder P2's script build could
-// not write under srt), the module cache, logs and a test's result
-// bundle.
+// not write under srt), the module cache and the activity logs.
+// The result bundle is XcodeResult's.
// - -clonedSourcePackagesDirPath: the packages' checkouts and
// workspace state (inside DerivedData by default; named so no
// default can move them).
// - -packageCachePath: SwiftPM's caches (~/Library/Caches/
// org.swift.swiftpm by default), in xcodebuild since Xcode 13.
//
+// SwiftPM's ~/.swiftpm (its security, configuration and cache links,
+// and the lock it takes there) moves with XDG_CONFIG_HOME, which a
+// sandboxed gate sets to the attempt's scratch (Gate.Run).
+//
// xcodebuild applies -derivedDataPath to an action on a scheme, so a
// target is built through its scheme.
const XcodeWrites = `-derivedDataPath "$TMPDIR/DerivedData" -clonedSourcePackagesDirPath "$TMPDIR/SourcePackages" -packageCachePath "$TMPDIR/PackageCache"`
diff --git a/internal/runner/mac/xcode_test.go b/internal/runner/mac/xcode_test.go
index 261349f3..4c9071c5 100644
--- a/internal/runner/mac/xcode_test.go
+++ b/internal/runner/mac/xcode_test.go
@@ -29,12 +29,25 @@ func TestXcodeWritesStayInScratch(t *testing.T) {
}
for name, s := range scripts {
calls := 0
+ bundles := map[string]bool{}
for _, seg := range regexp.MustCompile(`&&|\|\||[;|\n()]`).Split(s, -1) {
if !strings.Contains(seg, "xcodebuild") {
continue
}
calls++
- for _, flag := range []string{"-derivedDataPath", "-clonedSourcePackagesDirPath", "-packageCachePath"} {
+ flags := []string{"-derivedDataPath", "-clonedSourcePackagesDirPath", "-packageCachePath"}
+ if !strings.Contains(seg, " -list ") {
+ // An action's result bundle: its own, in scratch, never
+ // the default one in DARWIN_USER_TEMP_DIR.
+ flags = append(flags, "-resultBundlePath")
+ b := regexp.MustCompile(`-resultBundlePath ("[^"]*")`).FindStringSubmatch(seg)
+ if b == nil || bundles[b[1]] {
+ t.Errorf("%s: no result bundle of its own in %q", name, seg)
+ } else {
+ bundles[b[1]] = true
+ }
+ }
+ for _, flag := range flags {
if !strings.Contains(seg, flag+` "$TMPDIR/`) {
t.Errorf("%s: %s not in the attempt's scratch in %q", name, flag, seg)
}