oficina / equipo Public

Mac slice F: break the mac/claude test import cycle

Task 5 made internal/runner/mac import provider/claude, and task 7's
darwin policy tests import mac for the §4.2 list, so make vet failed
with an import cycle in test. The list (Paths and DenyList) moves to a
leaf package, internal/runner/mac/denylist; mac keeps its API through a
type alias and a forwarding DenyList, and the claude tests import the
leaf. The list stays single-sourced and behaviour is unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 1614ca81f5ad7bd83d55d1a67c403bb2bdf18e34 parent b9b568d
4 files changed, +70 −42
  • internal/runner/mac/denylist/denylist.go +54 −0
  • internal/runner/mac/profile.go +8 −34
  • internal/runner/provider/claude/answers_darwin_policy_test.go +6 −6
  • internal/runner/provider/claude/native.go +2 −2

CI cancelled — superseded by a newer push — run details

diff --git a/internal/runner/mac/denylist/denylist.go b/internal/runner/mac/denylist/denylist.go
new file mode 100644
index 00000000..17376cdf
--- /dev/null
+++ b/internal/runner/mac/denylist/denylist.go
@@ -0,0 +1,54 @@
+// Package denylist is the Mac runners spec §4.2 deny list: what no step
+// on a Mac may read or write. It is a leaf (standard library only) so
+// both the Mac worker (package mac, for its checks and Engineering
+// profiles) and the native permission port (provider/claude, whose
+// tests build darwin policies from it) share the one list, although mac
+// itself imports provider/claude.
+package denylist
+
+import (
+ "path/filepath"
+ "slices"
+)
+
+// Paths are the places the §4.2 deny list protects on this machine.
+type Paths struct {
+ // Home is the runner user's home (/Users/equipo-paul).
+ Home string
+ // StateDir holds the enrolment key, the steps and the relayed
+ // objects; AccountsRoot and SessionRoot the model sign-ins.
+ StateDir, AccountsRoot, SessionRoot string
+ // InstallDir is where the runner's binaries live (denied writes).
+ InstallDir string
+ // OtherHomes are every home under /Users but the runner user's.
+ OtherHomes []string
+ // UserTemp is the runner user's DARWIN_USER_TEMP_DIR, resolved and
+ // checked by UserTemp; "" when it was refused, and UserTempWhy says
+ // why. No checks profile is made without it: Xcode writes there
+ // whatever $TMPDIR says.
+ UserTemp, UserTempWhy string
+ // HomesUnknown: /Users could not be listed. Every profile then denies
+ // all of /Users, the runner's own home too, so no checks profile can
+ // be made (checks cannot run) rather than one that misses a home.
+ HomesUnknown bool
+}
+
+// DenyList is §4.2: what no step may read or write.
+func DenyList(p Paths) []string {
+ out := []string{p.StateDir, p.AccountsRoot, p.SessionRoot}
+ for _, rel := range []string{".ssh", ".aws", ".gnupg", ".config/op", "Library/Keychains"} {
+ out = append(out, filepath.Join(p.Home, rel))
+ }
+ out = append(out, p.OtherHomes...)
+ if p.HomesUnknown {
+ out = append(out, "/Users")
+ }
+ out = append(out, "/Volumes")
+ result := []string{}
+ for _, path := range out {
+ if path != "" && !slices.Contains(result, path) {
+ result = append(result, path)
+ }
+ }
+ return result
+}
diff --git a/internal/runner/mac/profile.go b/internal/runner/mac/profile.go
index c2db6d55..a6b65cfd 100644
--- a/internal/runner/mac/profile.go
+++ b/internal/runner/mac/profile.go
@@ -13,29 +13,14 @@ import (
"path/filepath"
"slices"
"strings"
+
+ "amadan.net/oficina/equipo/internal/runner/mac/denylist"
)
-// Paths are the places the §4.2 deny list protects on this machine.
-type Paths struct {
- // Home is the runner user's home (/Users/equipo-paul).
- Home string
- // StateDir holds the enrolment key, the steps and the relayed
- // objects; AccountsRoot and SessionRoot the model sign-ins.
- StateDir, AccountsRoot, SessionRoot string
- // InstallDir is where the runner's binaries live (denied writes).
- InstallDir string
- // OtherHomes are every home under /Users but the runner user's.
- OtherHomes []string
- // UserTemp is the runner user's DARWIN_USER_TEMP_DIR, resolved and
- // checked by UserTemp; "" when it was refused, and UserTempWhy says
- // why. No checks profile is made without it: Xcode writes there
- // whatever $TMPDIR says.
- UserTemp, UserTempWhy string
- // HomesUnknown: /Users could not be listed. Every profile then denies
- // all of /Users, the runner's own home too, so no checks profile can
- // be made (checks cannot run) rather than one that misses a home.
- HomesUnknown bool
-}
+// Paths are the places the §4.2 deny list protects on this machine
+// (denylist.Paths: the list lives in a leaf package so provider/claude
+// shares it too).
+type Paths = denylist.Paths
// Mach services a checks profile allows by default: what xcodebuild test
// against a simulator is expected to need. These are candidates until
@@ -54,19 +39,8 @@ var CheckMachServices = []string{
// denied one (srt's denyWrite wins over allowWrite).
var ErrProfile = errors.New("mac: srt profile refused")
-// DenyList is §4.2: what no step may read or write.
-func DenyList(p Paths) []string {
- out := []string{p.StateDir, p.AccountsRoot, p.SessionRoot}
- for _, rel := range []string{".ssh", ".aws", ".gnupg", ".config/op", "Library/Keychains"} {
- out = append(out, filepath.Join(p.Home, rel))
- }
- out = append(out, p.OtherHomes...)
- if p.HomesUnknown {
- out = append(out, "/Users")
- }
- out = append(out, "/Volumes")
- return compact(out)
-}
+// DenyList is §4.2: what no step may read or write (denylist.DenyList).
+func DenyList(p Paths) []string { return denylist.DenyList(p) }
// ChecksInput is one checks attempt: the tree (the exact candidate) and
// the attempt's scratch (TMPDIR, DerivedData of a synthesised gate).
diff --git a/internal/runner/provider/claude/answers_darwin_policy_test.go b/internal/runner/provider/claude/answers_darwin_policy_test.go
index 9cbbf68e..ee4d3a86 100644
--- a/internal/runner/provider/claude/answers_darwin_policy_test.go
+++ b/internal/runner/provider/claude/answers_darwin_policy_test.go
@@ -8,7 +8,7 @@ import (
"strings"
"testing"
- "amadan.net/oficina/equipo/internal/runner/mac"
+ "amadan.net/oficina/equipo/internal/runner/mac/denylist"
"amadan.net/oficina/equipo/internal/runner/provider"
)
@@ -23,7 +23,7 @@ type darwinRig struct {
research, other string
// jose and zoe are two more homes: José in NFC, Zoë in NFD.
jose, zoe string
- paths mac.Paths
+ paths denylist.Paths
policy provider.Policy
}
@@ -79,7 +79,7 @@ func newDarwinRig(t *testing.T) *darwinRig {
if err := os.Link(filepath.Join(r.outside, "hard"), filepath.Join(r.root, "hard")); err != nil {
t.Fatal(err)
}
- r.paths = mac.Paths{Home: r.home, StateDir: filepath.Join(r.home, ".equipo", "state"), AccountsRoot: filepath.Join(r.home, ".equipo", "accounts"), SessionRoot: filepath.Join(r.home, ".equipo", "sessions"), InstallDir: filepath.Join(r.home, ".equipo", "bin"), OtherHomes: []string{r.other, r.jose, r.zoe}}
+ r.paths = denylist.Paths{Home: r.home, StateDir: filepath.Join(r.home, ".equipo", "state"), AccountsRoot: filepath.Join(r.home, ".equipo", "accounts"), SessionRoot: filepath.Join(r.home, ".equipo", "sessions"), InstallDir: filepath.Join(r.home, ".equipo", "bin"), OtherHomes: []string{r.other, r.jose, r.zoe}}
r.policy = r.policyWith(r.root, r.research)
return r
}
@@ -90,7 +90,7 @@ func newDarwinRig(t *testing.T) *darwinRig {
// sandboxed with the generated deny rules.
func (r *darwinRig) policyWith(root, research string) provider.Policy {
r.t.Helper()
- denied := mac.DenyList(r.paths)
+ denied := denylist.DenyList(r.paths)
rules, err := NativeDenyRules(denied)
if err != nil {
r.t.Fatal(err)
@@ -257,11 +257,11 @@ func TestPermissionRefusesEscapes(t *testing.T) {
}
// TestPermissionDeniedPathsGenerated: the CLI's own deny rules name each
-// §4.2 path (mac.DenyList, shared with checks) as Tool(/<path>) and
+// §4.2 path (denylist.DenyList, shared with checks) as Tool(/<path>) and
// Tool(/<path>/**) for all five native file tools.
func TestPermissionDeniedPathsGenerated(t *testing.T) {
r := newDarwinRig(t)
- denied := mac.DenyList(r.paths)
+ denied := denylist.DenyList(r.paths)
if len(denied) < 9 {
t.Fatalf("deny list %v", denied)
}
diff --git a/internal/runner/provider/claude/native.go b/internal/runner/provider/claude/native.go
index 47ad8fb4..04d3b9bf 100644
--- a/internal/runner/provider/claude/native.go
+++ b/internal/runner/provider/claude/native.go
@@ -25,7 +25,7 @@ import (
// are what keep its native Read, Edit, Write, Glob and Grep inside the
// worktree. The roots become policy fields, every requested path is
// resolved against the real filesystem before it is answered, and the
-// policy's denied paths (the §4.2 list, mac.DenyList) are checked again
+// policy's denied paths (the §4.2 list, denylist.DenyList) are checked again
// after resolution.
const (
@@ -63,7 +63,7 @@ var nativeFileTools = []string{"Read", "Write", "Edit", "Glob", "Grep"}
// Grep (the CLI reads "//" as an absolute path). A path that is not
// absolute and clean, or that the rule syntax would read as a pattern,
// is refused. Linux renders its settings with this; a darwin policy
-// passes the §4.2 list (mac.DenyList) and the connection's homes.
+// passes the §4.2 list (denylist.DenyList) and the connection's homes.
func NativeDenyRules(paths []string) ([]string, error) {
var out []string
for _, path := range paths {