From d1081e1c7db7c8d25ded5f0d5311c377b9671dbc Mon Sep 17 00:00:00 2001 From: Koji AGAWA Date: Sat, 17 Oct 2026 16:47:52 +0900 Subject: [PATCH 1/3] fix(apple): preserve tmpfs mount options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Render structured tmpfs mounts using Apple container's native --tmpfs syntax. Retain octal modes, exact byte capacities, Docker size suffixes and zero-as-unset defaults, boolean spellings, and last-option-wins precedence. Reject unsupported or unrepresentable input rather than dropping restrictions. Explicit runArgs, other mount types and other providers keep their existing paths. Validate with Apple unit/race tests, devcontainer/config tests, CI-parity lint, and a real Apple container 1.5.0 probe for modes, page-exact capacities and write rejection. A minimal workspace now starts with generated file/terminal secret mounts and the requested permissions. The full unit suite is not green in six unchanged packages; focused baseline runs reproduce two failures. Complete user-configured tmpfs workspace validation also remains blocked by Apple 1.5.0 rejecting embedded equals in metadata labels. ## Evidence Apple 1.5.0 rejects tmpfs-mode as an unknown --mount directive. The runtime probe observes modes 755/700/1770 and tmpfs block counts 1/257 at 4096 bytes per block; it also checks size suffixes, zero defaults, boolean aliases, duplicate settings and read-only write rejection. The separate label parser failure reproduces with -l probe.key=a=b and is outside this fix. ## Transcript - U1: > $dig にapple containerのworkaroundがある。これをprovider側修正としてPRする案 - A: Read the consumer wrapper and current Apple driver. The wrapper translates Docker tmpfs-mode mount directives into Apple --tmpfs options. Asked whether the provider fix should cover generated secrets mounts, all structured tmpfs mounts, or raw runArgs. - U2: > A or B, apple containerの仕様とdocker仕様の差異が原典で確実ならB - Selection: Q1 / B > 利用者定義のtmpfsも含め、mode・size・read-onlyの変換まで保証する。対応仕様と検証範囲が広がる。 - A: Checked Apple container 1.5.0 parser source and Docker primary documentation/implementation. Adopted the conditional B scope after confirming mode, size and read-only representations; selected --tmpfs to avoid Apple --mount size rounding. Asked for the validation scope. - U3: > A - Selection: Q2 / A > 最小devcontainerで、wrapperなしの起動、mode・size・read-only、secrets用mountを検証する。 - A: Accepted a public minimal devcontainer validation scope. Proposed preserving structured tmpfs semantics while excluding raw runArgs rewriting, consumer changes, DinD remounts and other providers; limited execution to local changes, validation and PR preparation. - U4: > A - Selection: Q3 / A > この内容で確定し、実装依頼promptを作る。 - A: Produced a self-contained implementation request for the agreed scope. No push or PR creation was authorized. - U5: > ジック - A: Asked whether the short message meant execution. - U6: > 実行 - A: Fetched origin and confirmed the current task branch matched main. Applied repository and observability guidance; classified the changed argument conversion as a deterministic local path using existing errors and runtime evidence. Implemented structured tmpfs conversion, Docker byte/suffix and zero-default semantics, explicit input validation and regression/runtime tests. An independent reviewer found true-spelling and duplicate-option differences; fixed them using sequential typed parsing and added unit/runtime cases. Delta review had no actionable findings. Apple unit/race tests, relevant devcontainer/config tests, CI-parity lint and real Apple 1.5.0 probes pass. A minimal isolated workspace with dummy mounted and attached secrets starts; guest tmpfs modes and dummy file presence were checked. User-defined tmpfs metadata still hits an independent Apple label parser error on embedded equals, reproduced directly. The full CLI suite failed six unchanged packages; a baseline source overlay reproduced tunnelserver ignore-policy and Docker image inspection failures, while the other four focused groups passed. Removed all task containers, isolated homes/dummy stores, fixture, binaries and temporary HTTP server; retained local review/test artifacts and the public PR draft. The staged diff exactly matches the reviewed snapshot. No remote writes were performed. Co-authored-by: Codex --- pkg/driver/apple/lifecycle.go | 7 +- pkg/driver/apple/runargs.go | 113 +++++++++++++-- pkg/driver/apple/runargs_integration_test.go | 114 +++++++++++++++ pkg/driver/apple/runargs_test.go | 143 ++++++++++++++++++- 4 files changed, 361 insertions(+), 16 deletions(-) create mode 100644 pkg/driver/apple/runargs_integration_test.go diff --git a/pkg/driver/apple/lifecycle.go b/pkg/driver/apple/lifecycle.go index 47477d0369..a20aece9de 100644 --- a/pkg/driver/apple/lifecycle.go +++ b/pkg/driver/apple/lifecycle.go @@ -147,7 +147,10 @@ func (d *appleDriver) RunImageDevContainer( return err } - args := d.buildRunArgs(params) + args, err := d.buildRunArgs(params) + if err != nil { + return fmt.Errorf("build apple container arguments: %w", err) + } writer := log.Writer(log.LevelInfo) defer func() { _ = writer.Close() }() @@ -156,7 +159,7 @@ func (d *appleDriver) RunImageDevContainer( "running apple container command: command=%s, args=%s", d.command, redactArgs(args), ) - err := d.Apple.RunWithDir(ctx, params.LocalWorkspaceFolder, args, + err = d.Apple.RunWithDir(ctx, params.LocalWorkspaceFolder, args, apple.Streams{Stdout: writer, Stderr: writer}) if err != nil { return fmt.Errorf("failed to start dev container: %w", err) diff --git a/pkg/driver/apple/runargs.go b/pkg/driver/apple/runargs.go index 8213e1fe20..429b60f1c1 100644 --- a/pkg/driver/apple/runargs.go +++ b/pkg/driver/apple/runargs.go @@ -9,11 +9,18 @@ import ( "github.com/devsy-org/devsy/pkg/devcontainer/config" "github.com/devsy-org/devsy/pkg/driver" "github.com/devsy-org/devsy/pkg/log" + "github.com/docker/cli/opts" ) +type tmpfsMountOptions struct { + size opts.MemBytes + mode uint64 + readOnly bool +} + // buildRunArgs assembles `container run` args, emitting only flags Apple supports // (Docker/Podman-only flags like --security-opt/--gpus/--userns are omitted). -func (d *appleDriver) buildRunArgs(params *driver.RunImageDevContainerParams) []string { +func (d *appleDriver) buildRunArgs(params *driver.RunImageDevContainerParams) ([]string, error) { args := []string{"run", "-d"} if d.Rosetta { @@ -22,12 +29,19 @@ func (d *appleDriver) buildRunArgs(params *driver.RunImageDevContainerParams) [] warnUnsupportedGPU(params.ParsedConfig) args = d.addPorts(args, params.ParsedConfig) - args = d.addWorkspaceMount(args, params.Options) + var err error + args, err = d.addWorkspaceMount(args, params.Options) + if err != nil { + return nil, err + } args = addUser(args, params.Options) args = addEnv(args, params.Options) args = addInit(args, params.Options) args = addCapabilities(args, params.Options) - args = addMounts(args, params.Options) + args, err = addMounts(args, params.Options) + if err != nil { + return nil, err + } args = d.addLabels(args, params.WorkspaceID, params.Options) args = append(args, params.ParsedConfig.RunArgs...) args = addPlatform(args, params.ParsedConfig, params.Options) @@ -35,7 +49,7 @@ func (d *appleDriver) buildRunArgs(params *driver.RunImageDevContainerParams) [] args = append(args, params.Options.Image) args = append(args, params.Options.Cmd...) - return args + return args, nil } func (d *appleDriver) addPorts(args []string, parsedConfig *config.DevContainerConfig) []string { @@ -49,11 +63,14 @@ func (d *appleDriver) addPorts(args []string, parsedConfig *config.DevContainerC return args } -func (d *appleDriver) addWorkspaceMount(args []string, options *driver.RunOptions) []string { - if options.WorkspaceMount != nil { - args = append(args, "--mount", cleanMount(options.WorkspaceMount.String())) +func (d *appleDriver) addWorkspaceMount( + args []string, + options *driver.RunOptions, +) ([]string, error) { + if options.WorkspaceMount == nil { + return args, nil } - return args + return appendMount(args, options.WorkspaceMount) } func addUser(args []string, options *driver.RunOptions) []string { @@ -84,7 +101,7 @@ func addCapabilities(args []string, options *driver.RunOptions) []string { return args } -func addMounts(args []string, options *driver.RunOptions) []string { +func addMounts(args []string, options *driver.RunOptions) ([]string, error) { for _, mount := range options.Mounts { if mount.Type == "bind" && mount.Source != "" { if _, err := os.Stat(mount.Source); os.IsNotExist(err) { @@ -92,9 +109,83 @@ func addMounts(args []string, options *driver.RunOptions) []string { continue } } - args = append(args, "--mount", cleanMount(mount.String())) + var err error + args, err = appendMount(args, mount) + if err != nil { + return nil, err + } + } + return args, nil +} + +func appendMount(args []string, mount *config.Mount) ([]string, error) { + if mount.Type != driver.MountTypeTmpfs { + return append(args, "--mount", cleanMount(mount.String())), nil + } + if mount.Source != "" { + return nil, fmt.Errorf("apple tmpfs mount cannot specify a source") + } + if !strings.HasPrefix(mount.Target, "/") || strings.Contains(mount.Target, ":") { + return nil, fmt.Errorf( + "apple tmpfs mount requires an absolute target without a colon: %q", + mount.Target, + ) + } + opts, err := tmpfsOptions(mount) + if err != nil { + return nil, err + } + spec := mount.Target + if len(opts) > 0 { + spec += ":" + strings.Join(opts, ",") + } + return append(args, "--tmpfs", spec), nil +} + +func tmpfsOptions(mount *config.Mount) ([]string, error) { + var parsed tmpfsMountOptions + for _, option := range mount.Other { + if err := parsed.set(option); err != nil { + return nil, fmt.Errorf("invalid apple tmpfs mount option: %w", err) + } + } + // Apple's --mount size parser rounds through MiB; --tmpfs preserves bytes. + // Docker treats zero size/mode as unset, unlike Linux's explicit zero options. + options := []string{} + if parsed.size.Value() != 0 { + options = append(options, "size="+strconv.FormatInt(parsed.size.Value(), 10)) + } + if parsed.mode != 0 { + options = append(options, "mode="+strconv.FormatUint(parsed.mode, 8)) + } + if parsed.readOnly { + options = append(options, "ro") + } + return options, nil +} + +func (o *tmpfsMountOptions) set(option string) error { + key, value, hasValue := strings.Cut(strings.TrimSpace(option), "=") + value = strings.TrimSpace(value) + switch strings.ToLower(key) { + case "tmpfs-size": + return o.size.Set(value) + case "tmpfs-mode": + var err error + o.mode, err = strconv.ParseUint(value, 8, 32) + return err + case "readonly", "ro": + if !hasValue { + value = "true" + } + var err error + o.readOnly, err = strconv.ParseBool(value) + return err + case "consistency", "bind-create-src": + return nil + default: + return fmt.Errorf("unsupported option %q", key) } - return args } func (d *appleDriver) addLabels( diff --git a/pkg/driver/apple/runargs_integration_test.go b/pkg/driver/apple/runargs_integration_test.go new file mode 100644 index 0000000000..44654a5cf1 --- /dev/null +++ b/pkg/driver/apple/runargs_integration_test.go @@ -0,0 +1,114 @@ +package apple + +import ( + "bytes" + "context" + "fmt" + "os" + "testing" + "time" + + "github.com/devsy-org/devsy/pkg/apple" + "github.com/devsy-org/devsy/pkg/devcontainer/config" + "github.com/devsy-org/devsy/pkg/driver" + "github.com/stretchr/testify/require" +) + +func TestTmpfsMountsIntegration(t *testing.T) { + if os.Getenv("DEVSY_APPLE_E2E") != "1" { + t.Skip("set DEVSY_APPLE_E2E=1 to run against a real container CLI") + } + ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second) + defer cancel() + helper := &apple.AppleHelper{Command: "container"} + name := fmt.Sprintf("devsy-tmpfs-%d", time.Now().UnixNano()) + params := tmpfsIntegrationParams(name) + args, err := (&appleDriver{}).buildRunArgs(params) + require.NoError(t, err) + t.Cleanup(func() { + cleanupCtx, cleanupCancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cleanupCancel() + found, findErr := helper.FindContainerByID(cleanupCtx, []string{name}) + require.NoError(t, findErr) + if found != nil { + _ = helper.Stop(cleanupCtx, name) + require.NoError(t, helper.Remove(cleanupCtx, name)) + } + }) + var out bytes.Buffer + err = helper.Run(ctx, args, apple.Streams{Stdout: &out, Stderr: &out}) + require.NoError(t, err, out.String()) + out.Reset() + err = helper.Run( + ctx, + []string{"exec", name, "sh", "-c", tmpfsIntegrationOracle}, + apple.Streams{Stdout: &out, Stderr: &out}, + ) + require.NoError(t, err, out.String()) + t.Log(out.String()) +} + +func tmpfsIntegrationParams(name string) *driver.RunImageDevContainerParams { + return &driver.RunImageDevContainerParams{ + WorkspaceID: name, + ParsedConfig: &config.DevContainerConfig{ + NonComposeBase: config.NonComposeBase{ + RunArgs: []string{"--name", name, "--cpus", "1", "--memory", "256M"}, + }, + }, + Options: &driver.RunOptions{ + Image: "ubuntu:24.04", Entrypoint: "/bin/sh", Cmd: []string{"-c", "sleep 120"}, + Mounts: []*config.Mount{ + { + Type: driver.MountTypeTmpfs, + Target: config.SecretsMountDir, + Other: []string{"tmpfs-mode=0755"}, + }, + { + Type: driver.MountTypeTmpfs, + Target: config.SecretsEnvDir, + Other: []string{"tmpfs-mode=0700"}, + }, + { + Type: "tmpfs", + Target: "/probe-small", + Other: []string{"tmpfs-size=4096", "tmpfs-mode=0777", "tmpfs-mode=1770"}, + }, + { + Type: driver.MountTypeTmpfs, + Target: "/probe-size", + Other: []string{"tmpfs-size=1048576", "tmpfs-size=1052672"}, + }, + {Type: driver.MountTypeTmpfs, Target: "/probe-ro", Other: []string{"readonly=t"}}, + { + Type: "tmpfs", + Target: "/probe-default", + Other: []string{"tmpfs-size=0", "tmpfs-mode=0000", "readonly", "ro=false"}, + }, + { + Type: driver.MountTypeTmpfs, + Target: "/probe-suffix", + Other: []string{"tmpfs-size=1mb"}, + }, + }, + }, + } +} + +const tmpfsIntegrationOracle = `set -eu +stat -c '%n %a' /run/secrets /run/devsy/secrets-env /probe-small +stat -f -c '%n %T %S %b' /probe-small /probe-size +test "$(stat -c %a /run/secrets)" = 755 +test "$(stat -c %a /run/devsy/secrets-env)" = 700 +test "$(stat -c %a /probe-small)" = 1770 +test "$(stat -c %a /probe-default)" = 1777 +test "$(stat -f -c '%S:%b' /probe-suffix)" = 4096:256 +for p in /run/secrets /run/devsy/secrets-env /probe-small /probe-size /probe-ro; do + test "$(stat -f -c %T "$p")" = tmpfs +done +test "$(stat -f -c '%S:%b' /probe-small)" = 4096:1 +test "$(stat -f -c '%S:%b' /probe-size)" = 4096:257 +touch /probe-small/writable /probe-default/writable +if touch /probe-ro/forbidden 2>/dev/null; then exit 1; fi +echo 'tmpfs permissions, sizes and read-only mount verified' +` diff --git a/pkg/driver/apple/runargs_test.go b/pkg/driver/apple/runargs_test.go index d02837b114..5d76398465 100644 --- a/pkg/driver/apple/runargs_test.go +++ b/pkg/driver/apple/runargs_test.go @@ -7,8 +7,11 @@ import ( "github.com/devsy-org/devsy/pkg/devcontainer/config" "github.com/devsy-org/devsy/pkg/driver" "github.com/devsy-org/devsy/pkg/types" + "github.com/stretchr/testify/require" ) +const testTmpfsTarget = "/scratch" + func TestBuildRunArgs(t *testing.T) { d := &appleDriver{IDLabels: []string{"dev.containers.id"}} init := true @@ -30,7 +33,8 @@ func TestBuildRunArgs(t *testing.T) { }, } - args := d.buildRunArgs(params) + args, err := d.buildRunArgs(params) + require.NoError(t, err) joined := strings.Join(args, " ") for _, want := range []string{ @@ -66,12 +70,14 @@ func TestBuildRunArgsRosetta(t *testing.T) { Options: &driver.RunOptions{Image: testImageRef}, } - off := (&appleDriver{}).buildRunArgs(params) + off, err := (&appleDriver{}).buildRunArgs(params) + require.NoError(t, err) if strings.Contains(strings.Join(off, " "), "--rosetta") { t.Errorf("--rosetta must not be present when Rosetta is disabled: %v", off) } - on := (&appleDriver{Rosetta: true}).buildRunArgs(params) + on, err := (&appleDriver{Rosetta: true}).buildRunArgs(params) + require.NoError(t, err) if !strings.Contains(strings.Join(on, " "), "--rosetta") { t.Errorf("--rosetta must be present when Rosetta is enabled: %v", on) } @@ -105,3 +111,134 @@ func TestRedactArgs(t *testing.T) { } } } + +func TestBuildRunArgsTmpfs(t *testing.T) { + tests := tmpfsRunArgsCases() + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + mount := config.ParseMount(tt.mount) + params := &driver.RunImageDevContainerParams{ + ParsedConfig: &config.DevContainerConfig{}, + Options: &driver.RunOptions{ + Image: testImageRef, + Mounts: []*config.Mount{&mount}, + }, + } + args, err := (&appleDriver{}).buildRunArgs(params) + require.NoError(t, err) + require.Equal( + t, + []string{"--tmpfs", tt.want}, + args[2:4], + ) + }) + } +} + +func tmpfsRunArgsCases() []struct{ name, mount, want string } { + return []struct{ name, mount, want string }{ + { + "secret files", + "type=tmpfs,target=/run/secrets,tmpfs-mode=0755", + "/run/secrets:mode=755", + }, + { + "secret environment", + "type=tmpfs,target=/run/devsy/secrets-env,tmpfs-mode=0700", + "/run/devsy/secrets-env:mode=700", + }, + {"size below MiB", "type=tmpfs,target=/scratch,tmpfs-size=4096", "/scratch:size=4096"}, + { + "size not whole MiB", + "type=tmpfs,target=/scratch,tmpfs-size=1052672", + "/scratch:size=1052672", + }, + { + "combined", + "type=tmpfs,target=/scratch,tmpfs-size=1052672,tmpfs-mode=1770,readonly", + "/scratch:size=1052672,mode=1770,ro", + }, + {"ro alias", "type=tmpfs,target=/scratch,ro", testTmpfsTarget + ":ro"}, + {"Docker short true", "type=tmpfs,target=/scratch,readonly=t", testTmpfsTarget + ":ro"}, + {"Docker uppercase true", "type=tmpfs,target=/scratch,readonly=T", testTmpfsTarget + ":ro"}, + { + "last mode wins", + "type=tmpfs,target=/scratch,tmpfs-mode=0777,tmpfs-mode=0700", + "/scratch:mode=700", + }, + { + "last size wins", + "type=tmpfs,target=/scratch,tmpfs-size=1048576,tmpfs-size=4096", + "/scratch:size=4096", + }, + {"last readonly wins", "type=tmpfs,target=/scratch,readonly,ro=false", testTmpfsTarget}, + {"writable", "type=tmpfs,target=/scratch,readonly=false", testTmpfsTarget}, + {"defaults", "type=tmpfs,target=/scratch", testTmpfsTarget}, + { + "Desktop options", + "type=tmpfs,target=/scratch,consistency=cached,bind-create-src=true", + "/scratch", + }, + { + "Docker zero defaults", + "type=tmpfs,target=/scratch,tmpfs-mode=0000,tmpfs-size=0", + "/scratch", + }, + { + "Docker size suffix", + "type=tmpfs,target=/scratch,tmpfs-size=1mb", + "/scratch:size=1048576", + }, + } +} + +func TestBuildRunArgsRejectsInvalidTmpfs(t *testing.T) { + for _, spec := range []string{ + "type=tmpfs,source=bad,target=/scratch", + "type=tmpfs,target=relative", + "type=tmpfs,target=/scratch:other", + "type=tmpfs,target=/scratch,tmpfs-mode", + "type=tmpfs,target=/scratch,tmpfs-size=", + "type=tmpfs,target=/scratch,unsupported=true", + "type=tmpfs,target=/scratch,tmpfs-size=-1", + "type=tmpfs,target=/scratch,tmpfs-size=oops", + "type=tmpfs,target=/scratch,tmpfs-mode=0899", + "type=tmpfs,target=/scratch,readonly=oops", + } { + t.Run(spec, func(t *testing.T) { + mount := config.ParseMount(spec) + params := &driver.RunImageDevContainerParams{ + ParsedConfig: &config.DevContainerConfig{}, + Options: &driver.RunOptions{ + Image: testImageRef, + Mounts: []*config.Mount{&mount}, + }, + } + args, err := (&appleDriver{}).buildRunArgs(params) + require.Error(t, err) + require.Nil(t, args) + }) + } +} + +func TestBuildRunArgsPreservesRunArgs(t *testing.T) { + raw := []string{ + "--tmpfs", + "/native:mode=0700", + "--mount", + "type=tmpfs,target=/native-mount,mode=0755", + } + params := &driver.RunImageDevContainerParams{ + ParsedConfig: &config.DevContainerConfig{ + NonComposeBase: config.NonComposeBase{RunArgs: raw}, + }, + Options: &driver.RunOptions{Image: testImageRef}, + } + args, err := (&appleDriver{}).buildRunArgs(params) + require.NoError(t, err) + require.Equal( + t, + append(append([]string{"run", "-d", "-l", "dev.containers.id="}, raw...), testImageRef), + args, + ) +} From 12e80be37a2c8207967f287aa1aef8f3a5495d3e Mon Sep 17 00:00:00 2001 From: Koji AGAWA Date: Sun, 18 Oct 2026 09:11:23 +0900 Subject: [PATCH 2/3] fix(apple): delegate tmpfs parsing to container CLI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Keep --mount and translate only Docker's tmpfs-mode= and tmpfs-size= directive names to Apple's mode= and size=. Preserve values, directive order and unknown forms so the native CLI owns their interpretation across versions. Remove host-side value parsing, whole-mount admission checks, --tmpfs lowering and the added buildRunArgs error return. Keep existing Docker Desktop cleanup, other mount types and explicit runArgs behavior unchanged. Apple driver/config race tests and CI-parity lint pass. A real Apple 1.5.0 --mount test verifies generated secret directory permissions, native mode/size, duplicate size selection and read-only behavior. Fresh independent review has no actionable findings. Full workspace secret injection was not rerun in this follow-up; native size rounding and metadata-label limitations remain documented in the prepared PR text. ## Transcript - U1: > atty303にpush - A: Pushed the existing signed tmpfs change to atty303/apple and verified that the remote ref matched d1081e1c7. No PR was created. - U2: > orcaのenv4 workspaceで起動した。修正が実際に利用されているか確認して - A: Read-only inspection matched the selected Orca worktree to its Apple workspace. Host and guest used v0.0.0-atty.4 revision 04d22c429, which includes the original fix; its runargs source blob matched d1081e1c7. Saved driver path was container, and live tmpfs permissions were 0755 and 0700. No workspace settings were changed. - U3: > この修正が有効でありPRできると判断するか? - A: Judged the original secrets-startup fix suitable for a PR with explicit native-label and unrelated full-suite validation limits. - U4: > func (d *appleDriver) buildRunArgs(params *driver.RunImageDevContainerParams) ([]string, error) { > errorを追加したのは必須なの? - A: Explained that the error return was introduced by added host-side validation rather than required by the original syntax mismatch. - U5: > 解析失敗をerrorにする必要ある? 解析できなかったら変換せずにパスしたほうが元の挙動を維持できてPRとして安全じゃない? - A: Agreed that native CLI interpretation is safer than a new Devsy refusal condition. Initially proposed whole-mount pass-through. - U6: > 「解析できないエラー」これが今後containerの更新に対しても常に妥当であることを保証できるか? - A: Acknowledged that a local parser cannot classify future CLI input validity and must not become a compatibility gate. - U7: > 修正して - A: Started the requested follow-up in the current branch, fetched origin, and reproduced the rejection regression. Removed the public argument-generation error path. A preliminary pass-through implementation and runtime checks were subsequently superseded by the clarified minimal contract. - U8: > 解析できない指定が一つでもあれば ← なんで? 解析できたものだけ変換すればいいだろう? - A: Acknowledged that whole-mount gating came from changing the CLI flag. Explored per-directive conversion while retaining the native mount path; that intermediate variant was not committed. - U9: > 最大限container cliに解析を任せ、確実にサポートしていないことがわかる形式を変換するのが目的だ。理解しているか? - A: Removed independent value parsing and admission checks. Final implementation maps only exact tmpfs-mode= and tmpfs-size= names to native mode= and size= in structured tmpfs mounts, preserving raw values, order and unknown directives. Native CLI semantics include units, duplicates, malformed values and zero values. - U10: > > --mount から --tmpfs へ切り替える実装 > > これ必要なの? --mountのままtmpfs指定を変換できないの? - A: Confirmed that --mount supports mode and size directly and retained that flag. Restored buildRunArgs and its callers to []string, removed Docker-value emulation, and updated PR text around native parsing ownership and its known size/label limitations. - U11: > それがこちらの意図する最小PRだ - A: Final source adds only directive-name translation to the pre-fix production path. Apple/config race tests, CI-parity lint and real Apple 1.5.0 --mount tests pass. Tests cover opaque values, duplicates, unknown directives and input immutability; runtime checks cover secret directory modes, native size/mode, last size selection and read-only writes. Fresh independent review found no actionable issues. Integration resources were cleaned up. The reviewed diff matches the staged snapshot. Existing env4 and installed binaries were not changed; no push or PR creation was performed for this follow-up. Co-authored-by: Codex --- pkg/driver/apple/lifecycle.go | 7 +- pkg/driver/apple/runargs.go | 120 ++++------------ pkg/driver/apple/runargs_integration_test.go | 43 ++---- pkg/driver/apple/runargs_test.go | 142 ++++++------------- 4 files changed, 86 insertions(+), 226 deletions(-) diff --git a/pkg/driver/apple/lifecycle.go b/pkg/driver/apple/lifecycle.go index a20aece9de..47477d0369 100644 --- a/pkg/driver/apple/lifecycle.go +++ b/pkg/driver/apple/lifecycle.go @@ -147,10 +147,7 @@ func (d *appleDriver) RunImageDevContainer( return err } - args, err := d.buildRunArgs(params) - if err != nil { - return fmt.Errorf("build apple container arguments: %w", err) - } + args := d.buildRunArgs(params) writer := log.Writer(log.LevelInfo) defer func() { _ = writer.Close() }() @@ -159,7 +156,7 @@ func (d *appleDriver) RunImageDevContainer( "running apple container command: command=%s, args=%s", d.command, redactArgs(args), ) - err = d.Apple.RunWithDir(ctx, params.LocalWorkspaceFolder, args, + err := d.Apple.RunWithDir(ctx, params.LocalWorkspaceFolder, args, apple.Streams{Stdout: writer, Stderr: writer}) if err != nil { return fmt.Errorf("failed to start dev container: %w", err) diff --git a/pkg/driver/apple/runargs.go b/pkg/driver/apple/runargs.go index 429b60f1c1..9c3f46faec 100644 --- a/pkg/driver/apple/runargs.go +++ b/pkg/driver/apple/runargs.go @@ -9,18 +9,11 @@ import ( "github.com/devsy-org/devsy/pkg/devcontainer/config" "github.com/devsy-org/devsy/pkg/driver" "github.com/devsy-org/devsy/pkg/log" - "github.com/docker/cli/opts" ) -type tmpfsMountOptions struct { - size opts.MemBytes - mode uint64 - readOnly bool -} - // buildRunArgs assembles `container run` args, emitting only flags Apple supports // (Docker/Podman-only flags like --security-opt/--gpus/--userns are omitted). -func (d *appleDriver) buildRunArgs(params *driver.RunImageDevContainerParams) ([]string, error) { +func (d *appleDriver) buildRunArgs(params *driver.RunImageDevContainerParams) []string { args := []string{"run", "-d"} if d.Rosetta { @@ -29,19 +22,12 @@ func (d *appleDriver) buildRunArgs(params *driver.RunImageDevContainerParams) ([ warnUnsupportedGPU(params.ParsedConfig) args = d.addPorts(args, params.ParsedConfig) - var err error - args, err = d.addWorkspaceMount(args, params.Options) - if err != nil { - return nil, err - } + args = d.addWorkspaceMount(args, params.Options) args = addUser(args, params.Options) args = addEnv(args, params.Options) args = addInit(args, params.Options) args = addCapabilities(args, params.Options) - args, err = addMounts(args, params.Options) - if err != nil { - return nil, err - } + args = addMounts(args, params.Options) args = d.addLabels(args, params.WorkspaceID, params.Options) args = append(args, params.ParsedConfig.RunArgs...) args = addPlatform(args, params.ParsedConfig, params.Options) @@ -49,7 +35,7 @@ func (d *appleDriver) buildRunArgs(params *driver.RunImageDevContainerParams) ([ args = append(args, params.Options.Image) args = append(args, params.Options.Cmd...) - return args, nil + return args } func (d *appleDriver) addPorts(args []string, parsedConfig *config.DevContainerConfig) []string { @@ -63,14 +49,11 @@ func (d *appleDriver) addPorts(args []string, parsedConfig *config.DevContainerC return args } -func (d *appleDriver) addWorkspaceMount( - args []string, - options *driver.RunOptions, -) ([]string, error) { - if options.WorkspaceMount == nil { - return args, nil +func (d *appleDriver) addWorkspaceMount(args []string, options *driver.RunOptions) []string { + if options.WorkspaceMount != nil { + args = appendMount(args, options.WorkspaceMount) } - return appendMount(args, options.WorkspaceMount) + return args } func addUser(args []string, options *driver.RunOptions) []string { @@ -101,7 +84,7 @@ func addCapabilities(args []string, options *driver.RunOptions) []string { return args } -func addMounts(args []string, options *driver.RunOptions) ([]string, error) { +func addMounts(args []string, options *driver.RunOptions) []string { for _, mount := range options.Mounts { if mount.Type == "bind" && mount.Source != "" { if _, err := os.Stat(mount.Source); os.IsNotExist(err) { @@ -109,83 +92,30 @@ func addMounts(args []string, options *driver.RunOptions) ([]string, error) { continue } } - var err error - args, err = appendMount(args, mount) - if err != nil { - return nil, err - } - } - return args, nil -} - -func appendMount(args []string, mount *config.Mount) ([]string, error) { - if mount.Type != driver.MountTypeTmpfs { - return append(args, "--mount", cleanMount(mount.String())), nil + args = appendMount(args, mount) } - if mount.Source != "" { - return nil, fmt.Errorf("apple tmpfs mount cannot specify a source") - } - if !strings.HasPrefix(mount.Target, "/") || strings.Contains(mount.Target, ":") { - return nil, fmt.Errorf( - "apple tmpfs mount requires an absolute target without a colon: %q", - mount.Target, - ) - } - opts, err := tmpfsOptions(mount) - if err != nil { - return nil, err - } - spec := mount.Target - if len(opts) > 0 { - spec += ":" + strings.Join(opts, ",") - } - return append(args, "--tmpfs", spec), nil + return args } -func tmpfsOptions(mount *config.Mount) ([]string, error) { - var parsed tmpfsMountOptions - for _, option := range mount.Other { - if err := parsed.set(option); err != nil { - return nil, fmt.Errorf("invalid apple tmpfs mount option: %w", err) +func appendMount(args []string, mount *config.Mount) []string { + translated := *mount + if mount.Type == driver.MountTypeTmpfs { + translated.Other = make([]string, len(mount.Other)) + for i, option := range mount.Other { + translated.Other[i] = nativeTmpfsOption(option) } } - // Apple's --mount size parser rounds through MiB; --tmpfs preserves bytes. - // Docker treats zero size/mode as unset, unlike Linux's explicit zero options. - options := []string{} - if parsed.size.Value() != 0 { - options = append(options, "size="+strconv.FormatInt(parsed.size.Value(), 10)) - } - if parsed.mode != 0 { - options = append(options, "mode="+strconv.FormatUint(parsed.mode, 8)) - } - if parsed.readOnly { - options = append(options, "ro") - } - return options, nil + return append(args, "--mount", cleanMount(translated.String())) } -func (o *tmpfsMountOptions) set(option string) error { - key, value, hasValue := strings.Cut(strings.TrimSpace(option), "=") - value = strings.TrimSpace(value) - switch strings.ToLower(key) { - case "tmpfs-size": - return o.size.Set(value) - case "tmpfs-mode": - var err error - o.mode, err = strconv.ParseUint(value, 8, 32) - return err - case "readonly", "ro": - if !hasValue { - value = "true" - } - var err error - o.readOnly, err = strconv.ParseBool(value) - return err - case "consistency", "bind-create-src": - return nil - default: - return fmt.Errorf("unsupported option %q", key) +func nativeTmpfsOption(option string) string { + if value, ok := strings.CutPrefix(option, "tmpfs-mode="); ok { + return "mode=" + value + } + if value, ok := strings.CutPrefix(option, "tmpfs-size="); ok { + return "size=" + value } + return option } func (d *appleDriver) addLabels( diff --git a/pkg/driver/apple/runargs_integration_test.go b/pkg/driver/apple/runargs_integration_test.go index 44654a5cf1..216cbde40c 100644 --- a/pkg/driver/apple/runargs_integration_test.go +++ b/pkg/driver/apple/runargs_integration_test.go @@ -23,8 +23,7 @@ func TestTmpfsMountsIntegration(t *testing.T) { helper := &apple.AppleHelper{Command: "container"} name := fmt.Sprintf("devsy-tmpfs-%d", time.Now().UnixNano()) params := tmpfsIntegrationParams(name) - args, err := (&appleDriver{}).buildRunArgs(params) - require.NoError(t, err) + args := (&appleDriver{}).buildRunArgs(params) t.Cleanup(func() { cleanupCtx, cleanupCancel := context.WithTimeout(context.Background(), 30*time.Second) defer cleanupCancel() @@ -36,7 +35,7 @@ func TestTmpfsMountsIntegration(t *testing.T) { } }) var out bytes.Buffer - err = helper.Run(ctx, args, apple.Streams{Stdout: &out, Stderr: &out}) + err := helper.Run(ctx, args, apple.Streams{Stdout: &out, Stderr: &out}) require.NoError(t, err, out.String()) out.Reset() err = helper.Run( @@ -69,46 +68,34 @@ func tmpfsIntegrationParams(name string) *driver.RunImageDevContainerParams { Target: config.SecretsEnvDir, Other: []string{"tmpfs-mode=0700"}, }, - { - Type: "tmpfs", - Target: "/probe-small", - Other: []string{"tmpfs-size=4096", "tmpfs-mode=0777", "tmpfs-mode=1770"}, - }, { Type: driver.MountTypeTmpfs, - Target: "/probe-size", - Other: []string{"tmpfs-size=1048576", "tmpfs-size=1052672"}, - }, - {Type: driver.MountTypeTmpfs, Target: "/probe-ro", Other: []string{"readonly=t"}}, - { - Type: "tmpfs", - Target: "/probe-default", - Other: []string{"tmpfs-size=0", "tmpfs-mode=0000", "readonly", "ro=false"}, + Target: "/probe-native", + Other: []string{"mode=0700", "size=1M"}, }, { Type: driver.MountTypeTmpfs, - Target: "/probe-suffix", - Other: []string{"tmpfs-size=1mb"}, + Target: "/probe-size", + Other: []string{"tmpfs-size=1M", "tmpfs-size=2M"}, }, + {Type: driver.MountTypeTmpfs, Target: "/probe-ro", Other: []string{"readonly"}}, }, }, } } const tmpfsIntegrationOracle = `set -eu -stat -c '%n %a' /run/secrets /run/devsy/secrets-env /probe-small -stat -f -c '%n %T %S %b' /probe-small /probe-size +stat -c '%n %a' /run/secrets /run/devsy/secrets-env /probe-native +stat -f -c '%n %T %S %b' /probe-native /probe-size test "$(stat -c %a /run/secrets)" = 755 test "$(stat -c %a /run/devsy/secrets-env)" = 700 -test "$(stat -c %a /probe-small)" = 1770 -test "$(stat -c %a /probe-default)" = 1777 -test "$(stat -f -c '%S:%b' /probe-suffix)" = 4096:256 -for p in /run/secrets /run/devsy/secrets-env /probe-small /probe-size /probe-ro; do +test "$(stat -c %a /probe-native)" = 700 +for p in /run/secrets /run/devsy/secrets-env /probe-native /probe-size /probe-ro; do test "$(stat -f -c %T "$p")" = tmpfs done -test "$(stat -f -c '%S:%b' /probe-small)" = 4096:1 -test "$(stat -f -c '%S:%b' /probe-size)" = 4096:257 -touch /probe-small/writable /probe-default/writable +test "$(stat -f -c '%S:%b' /probe-native)" = 4096:256 +test "$(stat -f -c '%S:%b' /probe-size)" = 4096:512 +touch /probe-native/writable if touch /probe-ro/forbidden 2>/dev/null; then exit 1; fi -echo 'tmpfs permissions, sizes and read-only mount verified' +echo 'native CLI tmpfs mount behavior verified' ` diff --git a/pkg/driver/apple/runargs_test.go b/pkg/driver/apple/runargs_test.go index 5d76398465..d7c51ce8eb 100644 --- a/pkg/driver/apple/runargs_test.go +++ b/pkg/driver/apple/runargs_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" ) -const testTmpfsTarget = "/scratch" +const testMountFlag = "--mount" func TestBuildRunArgs(t *testing.T) { d := &appleDriver{IDLabels: []string{"dev.containers.id"}} @@ -33,8 +33,7 @@ func TestBuildRunArgs(t *testing.T) { }, } - args, err := d.buildRunArgs(params) - require.NoError(t, err) + args := d.buildRunArgs(params) joined := strings.Join(args, " ") for _, want := range []string{ @@ -70,14 +69,12 @@ func TestBuildRunArgsRosetta(t *testing.T) { Options: &driver.RunOptions{Image: testImageRef}, } - off, err := (&appleDriver{}).buildRunArgs(params) - require.NoError(t, err) + off := (&appleDriver{}).buildRunArgs(params) if strings.Contains(strings.Join(off, " "), "--rosetta") { t.Errorf("--rosetta must not be present when Rosetta is disabled: %v", off) } - on, err := (&appleDriver{Rosetta: true}).buildRunArgs(params) - require.NoError(t, err) + on := (&appleDriver{Rosetta: true}).buildRunArgs(params) if !strings.Contains(strings.Join(on, " "), "--rosetta") { t.Errorf("--rosetta must be present when Rosetta is enabled: %v", on) } @@ -113,10 +110,24 @@ func TestRedactArgs(t *testing.T) { } func TestBuildRunArgsTmpfs(t *testing.T) { - tests := tmpfsRunArgsCases() - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + for _, tt := range []struct{ mount, want string }{ + {"type=tmpfs,target=/run/secrets,tmpfs-mode=0755", "type=tmpfs,dst=/run/secrets,mode=0755"}, + {"type=tmpfs,target=/run/devsy/secrets-env,tmpfs-mode=0700", "type=tmpfs,dst=/run/devsy/secrets-env,mode=0700"}, + {"type=tmpfs,target=/scratch,tmpfs-size=4096", "type=tmpfs,dst=/scratch,size=4096"}, + { + "type=tmpfs,target=/scratch,tmpfs-mode=0700,future-option=enabled", + "type=tmpfs,dst=/scratch,mode=0700,future-option=enabled", + }, + {"type=tmpfs,target=/scratch,tmpfs-size=oops,tmpfs-mode=invalid", "type=tmpfs,dst=/scratch,size=oops,mode=invalid"}, + { + "type=tmpfs,target=/scratch,tmpfs-mode=0777,tmpfs-mode=0700,readonly=false", + "type=tmpfs,dst=/scratch,mode=0777,mode=0700,readonly=false", + }, + {"type=tmpfs,target=/scratch,tmpfs-size=0,tmpfs-mode=0000", "type=tmpfs,dst=/scratch,size=0,mode=0000"}, + } { + t.Run(tt.mount, func(t *testing.T) { mount := config.ParseMount(tt.mount) + original := mount.String() params := &driver.RunImageDevContainerParams{ ParsedConfig: &config.DevContainerConfig{}, Options: &driver.RunOptions{ @@ -124,99 +135,24 @@ func TestBuildRunArgsTmpfs(t *testing.T) { Mounts: []*config.Mount{&mount}, }, } - args, err := (&appleDriver{}).buildRunArgs(params) - require.NoError(t, err) - require.Equal( - t, - []string{"--tmpfs", tt.want}, - args[2:4], - ) + args := (&appleDriver{}).buildRunArgs(params) + require.Equal(t, []string{testMountFlag, tt.want}, args[2:4]) + require.Equal(t, original, mount.String()) }) } } -func tmpfsRunArgsCases() []struct{ name, mount, want string } { - return []struct{ name, mount, want string }{ - { - "secret files", - "type=tmpfs,target=/run/secrets,tmpfs-mode=0755", - "/run/secrets:mode=755", - }, - { - "secret environment", - "type=tmpfs,target=/run/devsy/secrets-env,tmpfs-mode=0700", - "/run/devsy/secrets-env:mode=700", - }, - {"size below MiB", "type=tmpfs,target=/scratch,tmpfs-size=4096", "/scratch:size=4096"}, - { - "size not whole MiB", - "type=tmpfs,target=/scratch,tmpfs-size=1052672", - "/scratch:size=1052672", - }, - { - "combined", - "type=tmpfs,target=/scratch,tmpfs-size=1052672,tmpfs-mode=1770,readonly", - "/scratch:size=1052672,mode=1770,ro", - }, - {"ro alias", "type=tmpfs,target=/scratch,ro", testTmpfsTarget + ":ro"}, - {"Docker short true", "type=tmpfs,target=/scratch,readonly=t", testTmpfsTarget + ":ro"}, - {"Docker uppercase true", "type=tmpfs,target=/scratch,readonly=T", testTmpfsTarget + ":ro"}, - { - "last mode wins", - "type=tmpfs,target=/scratch,tmpfs-mode=0777,tmpfs-mode=0700", - "/scratch:mode=700", - }, - { - "last size wins", - "type=tmpfs,target=/scratch,tmpfs-size=1048576,tmpfs-size=4096", - "/scratch:size=4096", - }, - {"last readonly wins", "type=tmpfs,target=/scratch,readonly,ro=false", testTmpfsTarget}, - {"writable", "type=tmpfs,target=/scratch,readonly=false", testTmpfsTarget}, - {"defaults", "type=tmpfs,target=/scratch", testTmpfsTarget}, - { - "Desktop options", - "type=tmpfs,target=/scratch,consistency=cached,bind-create-src=true", - "/scratch", - }, - { - "Docker zero defaults", - "type=tmpfs,target=/scratch,tmpfs-mode=0000,tmpfs-size=0", - "/scratch", - }, - { - "Docker size suffix", - "type=tmpfs,target=/scratch,tmpfs-size=1mb", - "/scratch:size=1048576", - }, - } -} - -func TestBuildRunArgsRejectsInvalidTmpfs(t *testing.T) { +func TestBuildRunArgsPreservesOtherMountDirectives(t *testing.T) { for _, spec := range []string{ - "type=tmpfs,source=bad,target=/scratch", - "type=tmpfs,target=relative", - "type=tmpfs,target=/scratch:other", - "type=tmpfs,target=/scratch,tmpfs-mode", - "type=tmpfs,target=/scratch,tmpfs-size=", - "type=tmpfs,target=/scratch,unsupported=true", - "type=tmpfs,target=/scratch,tmpfs-size=-1", - "type=tmpfs,target=/scratch,tmpfs-size=oops", - "type=tmpfs,target=/scratch,tmpfs-mode=0899", - "type=tmpfs,target=/scratch,readonly=oops", + "type=tmpfs,source=bad,target=/scratch", "type=tmpfs,target=relative", "type=tmpfs,target=/scratch:other", + "type=tmpfs,target=/scratch,tmpfs-mode", "type=tmpfs,target=/scratch,mode=0700,size=1M", + "type=tmpfs,target=/scratch,future-option=enabled", "type=tmpfs,target=/scratch,consistency", + "type=tmpfs,target=/scratch,Consistency=cached", "type=tmpfs,target=/scratch,bind-create-src", + "type=volume,source=volume,target=/scratch,tmpfs-mode=0700", } { t.Run(spec, func(t *testing.T) { mount := config.ParseMount(spec) - params := &driver.RunImageDevContainerParams{ - ParsedConfig: &config.DevContainerConfig{}, - Options: &driver.RunOptions{ - Image: testImageRef, - Mounts: []*config.Mount{&mount}, - }, - } - args, err := (&appleDriver{}).buildRunArgs(params) - require.Error(t, err) - require.Nil(t, args) + require.Equal(t, []string{testMountFlag, mount.String()}, appendMount(nil, &mount)) }) } } @@ -225,7 +161,7 @@ func TestBuildRunArgsPreservesRunArgs(t *testing.T) { raw := []string{ "--tmpfs", "/native:mode=0700", - "--mount", + testMountFlag, "type=tmpfs,target=/native-mount,mode=0755", } params := &driver.RunImageDevContainerParams{ @@ -234,11 +170,21 @@ func TestBuildRunArgsPreservesRunArgs(t *testing.T) { }, Options: &driver.RunOptions{Image: testImageRef}, } - args, err := (&appleDriver{}).buildRunArgs(params) - require.NoError(t, err) + args := (&appleDriver{}).buildRunArgs(params) require.Equal( t, append(append([]string{"run", "-d", "-l", "dev.containers.id="}, raw...), testImageRef), args, ) } + +func TestAppendMountKeepsLegacyCleaningOnFallback(t *testing.T) { + mount := config.ParseMount( + "type=tmpfs,target=/scratch,mode=0700,consistency=cached,bind-create-src=true", + ) + require.Equal( + t, + []string{testMountFlag, "type=tmpfs,dst=/scratch,mode=0700"}, + appendMount(nil, &mount), + ) +} From 1abe961e96d5228e621c2924caece274d4e0b54f Mon Sep 17 00:00:00 2001 From: Samuel K Date: Sun, 18 Oct 2026 12:13:13 -0600 Subject: [PATCH 3/3] fix(apple): limit tmpfs translation to mode and harden tests --- pkg/devcontainer/single_test.go | 9 +- pkg/driver/apple/runargs.go | 8 +- pkg/driver/apple/runargs_integration_test.go | 84 +++++++++++---- pkg/driver/apple/runargs_test.go | 104 ++++++++++++++++--- 4 files changed, 166 insertions(+), 39 deletions(-) diff --git a/pkg/devcontainer/single_test.go b/pkg/devcontainer/single_test.go index 869064faf5..b80611bf0c 100644 --- a/pkg/devcontainer/single_test.go +++ b/pkg/devcontainer/single_test.go @@ -205,9 +205,11 @@ func TestSecretsEnvironmentTmpfsMount(t *testing.T) { if err != nil { t.Fatal("create secret environment mount") } - if mount == nil || mount.Type != "tmpfs" || mount.Target != config.SecretsEnvDir { - t.Error("secret environment mount is not configured for the protected directory") - } + require.NotNil(t, mount) + require.Equal(t, "tmpfs", mount.Type) + require.Equal(t, config.SecretsEnvDir, mount.Target) + // Docker syntax is the shared contract; the Apple driver translates it. + require.Equal(t, []string{"tmpfs-mode=0700"}, mount.Other) if _, err := secretsEnvironmentTmpfsMount(true, false); err == nil { t.Error("unsupported tmpfs provider was allowed to store workspace secrets") } @@ -223,6 +225,7 @@ func TestWithSecretsMountUsesCurrentUpRequest(t *testing.T) { require.Len(t, mounts, 1) require.Equal(t, config.SecretsMountDir, mounts[0].Target) require.Equal(t, "tmpfs", mounts[0].Type) + require.Equal(t, []string{"tmpfs-mode=0755"}, mounts[0].Other) mounts, err = r.withSecretsMount(nil, false) require.NoError(t, err) diff --git a/pkg/driver/apple/runargs.go b/pkg/driver/apple/runargs.go index 9c3f46faec..102b791745 100644 --- a/pkg/driver/apple/runargs.go +++ b/pkg/driver/apple/runargs.go @@ -97,6 +97,11 @@ func addMounts(args []string, options *driver.RunOptions) []string { return args } +// appendMount formats a mount for `container run --mount`. Docker spells the +// tmpfs permission option "tmpfs-mode"; Apple's CLI rejects it and expects +// "mode". "tmpfs-size" is deliberately not translated: container 1.5.0 rounds +// sub-MiB sizes to zero (an uncapped mount), so the Docker spelling is left +// as is and the CLI refuses it instead of silently dropping the cap. func appendMount(args []string, mount *config.Mount) []string { translated := *mount if mount.Type == driver.MountTypeTmpfs { @@ -112,9 +117,6 @@ func nativeTmpfsOption(option string) string { if value, ok := strings.CutPrefix(option, "tmpfs-mode="); ok { return "mode=" + value } - if value, ok := strings.CutPrefix(option, "tmpfs-size="); ok { - return "size=" + value - } return option } diff --git a/pkg/driver/apple/runargs_integration_test.go b/pkg/driver/apple/runargs_integration_test.go index 216cbde40c..6f5ba6cc09 100644 --- a/pkg/driver/apple/runargs_integration_test.go +++ b/pkg/driver/apple/runargs_integration_test.go @@ -14,29 +14,40 @@ import ( "github.com/stretchr/testify/require" ) +const tmpfsIntegrationImage = "ghcr.io/devsy-org/test-images/base:ubuntu" + +// TestTmpfsMountsIntegration starts a container with the tmpfs mounts Devsy +// generates for secrets and checks the native CLI accepts and honors them. +// It is gated behind DEVSY_APPLE_E2E=1 (Apple silicon, macOS 26+, `container` +// installed) and never runs in normal CI. func TestTmpfsMountsIntegration(t *testing.T) { if os.Getenv("DEVSY_APPLE_E2E") != "1" { t.Skip("set DEVSY_APPLE_E2E=1 to run against a real container CLI") } - ctx, cancel := context.WithTimeout(context.Background(), 90*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() helper := &apple.AppleHelper{Command: "container"} - name := fmt.Sprintf("devsy-tmpfs-%d", time.Now().UnixNano()) - params := tmpfsIntegrationParams(name) - args := (&appleDriver{}).buildRunArgs(params) - t.Cleanup(func() { - cleanupCtx, cleanupCancel := context.WithTimeout(context.Background(), 30*time.Second) - defer cleanupCancel() - found, findErr := helper.FindContainerByID(cleanupCtx, []string{name}) - require.NoError(t, findErr) - if found != nil { - _ = helper.Stop(cleanupCtx, name) - require.NoError(t, helper.Remove(cleanupCtx, name)) - } - }) + require.NoError(t, helper.EnsureSystemRunning(ctx)) + var out bytes.Buffer - err := helper.Run(ctx, args, apple.Streams{Stdout: &out, Stderr: &out}) + err := helper.Pull(ctx, apple.PullOptions{ + Image: tmpfsIntegrationImage, + Stdout: &out, + Stderr: &out, + }) + require.NoError(t, err, out.String()) + + name := fmt.Sprintf("devsy-tmpfs-%d", time.Now().UnixNano()) + label := "devsy.e2e.tmpfs=" + name + // Registered before run so a partially created container is still removed. + t.Cleanup(func() { cleanupTmpfsProbe(t, helper, name, label) }) + + args := (&appleDriver{}).buildRunArgs(tmpfsIntegrationParams(name, label)) + out.Reset() + err = helper.Run(ctx, args, apple.Streams{Stdout: &out, Stderr: &out}) require.NoError(t, err, out.String()) + require.NoError(t, helper.WaitContainerRunning(ctx, name)) + out.Reset() err = helper.Run( ctx, @@ -47,7 +58,30 @@ func TestTmpfsMountsIntegration(t *testing.T) { t.Log(out.String()) } -func tmpfsIntegrationParams(name string) *driver.RunImageDevContainerParams { +// cleanupTmpfsProbe removes the probe container if it exists. Failures are +// reported with t.Errorf so they never replace the first failing assertion, +// and a container that was never created is not an error. +func cleanupTmpfsProbe(t *testing.T, helper *apple.AppleHelper, name, label string) { + t.Helper() + ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) + defer cancel() + found, err := helper.FindDevContainer(ctx, []string{label}) + if err != nil { + t.Errorf("list probe container %s: %v", name, err) + return + } + if found == nil { + return + } + if err := helper.Stop(ctx, name); err != nil { + t.Logf("stop probe container %s: %v", name, err) + } + if err := helper.Remove(ctx, name); err != nil { + t.Errorf("remove probe container %s: %v", name, err) + } +} + +func tmpfsIntegrationParams(name, label string) *driver.RunImageDevContainerParams { return &driver.RunImageDevContainerParams{ WorkspaceID: name, ParsedConfig: &config.DevContainerConfig{ @@ -56,8 +90,12 @@ func tmpfsIntegrationParams(name string) *driver.RunImageDevContainerParams { }, }, Options: &driver.RunOptions{ - Image: "ubuntu:24.04", Entrypoint: "/bin/sh", Cmd: []string{"-c", "sleep 120"}, + Image: tmpfsIntegrationImage, + Entrypoint: "/bin/sh", + Cmd: []string{"-c", "sleep 120"}, + Labels: []string{label}, Mounts: []*config.Mount{ + // Docker-style options exactly as the shared secret mounts emit them. { Type: driver.MountTypeTmpfs, Target: config.SecretsMountDir, @@ -68,6 +106,8 @@ func tmpfsIntegrationParams(name string) *driver.RunImageDevContainerParams { Target: config.SecretsEnvDir, Other: []string{"tmpfs-mode=0700"}, }, + // Native options pass through unchanged. Whole-MiB sizes only: + // container 1.5.0 turns smaller sizes into zero (uncapped). { Type: driver.MountTypeTmpfs, Target: "/probe-native", @@ -76,7 +116,7 @@ func tmpfsIntegrationParams(name string) *driver.RunImageDevContainerParams { { Type: driver.MountTypeTmpfs, Target: "/probe-size", - Other: []string{"tmpfs-size=1M", "tmpfs-size=2M"}, + Other: []string{"size=2M"}, }, {Type: driver.MountTypeTmpfs, Target: "/probe-ro", Other: []string{"readonly"}}, }, @@ -84,17 +124,19 @@ func tmpfsIntegrationParams(name string) *driver.RunImageDevContainerParams { } } +// Capacity is block size times block count, so the check does not depend on +// the guest page geometry. const tmpfsIntegrationOracle = `set -eu +bytes() { echo $(( $(stat -f -c %S "$1") * $(stat -f -c %b "$1") )); } stat -c '%n %a' /run/secrets /run/devsy/secrets-env /probe-native -stat -f -c '%n %T %S %b' /probe-native /probe-size test "$(stat -c %a /run/secrets)" = 755 test "$(stat -c %a /run/devsy/secrets-env)" = 700 test "$(stat -c %a /probe-native)" = 700 for p in /run/secrets /run/devsy/secrets-env /probe-native /probe-size /probe-ro; do test "$(stat -f -c %T "$p")" = tmpfs done -test "$(stat -f -c '%S:%b' /probe-native)" = 4096:256 -test "$(stat -f -c '%S:%b' /probe-size)" = 4096:512 +test "$(bytes /probe-native)" = 1048576 +test "$(bytes /probe-size)" = 2097152 touch /probe-native/writable if touch /probe-ro/forbidden 2>/dev/null; then exit 1; fi echo 'native CLI tmpfs mount behavior verified' diff --git a/pkg/driver/apple/runargs_test.go b/pkg/driver/apple/runargs_test.go index d7c51ce8eb..a1765b66f7 100644 --- a/pkg/driver/apple/runargs_test.go +++ b/pkg/driver/apple/runargs_test.go @@ -109,39 +109,119 @@ func TestRedactArgs(t *testing.T) { } } +// mountArgs returns every value that follows a --mount flag, so tests assert +// mount contents independent of unrelated flag ordering. +func mountArgs(args []string) []string { + var mounts []string + for i := range len(args) - 1 { + if args[i] == testMountFlag { + mounts = append(mounts, args[i+1]) + } + } + return mounts +} + +func runArgsWithMounts( + workspace *config.Mount, + mounts ...*config.Mount, +) []string { + return (&appleDriver{}).buildRunArgs(&driver.RunImageDevContainerParams{ + ParsedConfig: &config.DevContainerConfig{}, + Options: &driver.RunOptions{ + Image: testImageRef, + WorkspaceMount: workspace, + Mounts: mounts, + }, + }) +} + func TestBuildRunArgsTmpfs(t *testing.T) { for _, tt := range []struct{ mount, want string }{ {"type=tmpfs,target=/run/secrets,tmpfs-mode=0755", "type=tmpfs,dst=/run/secrets,mode=0755"}, {"type=tmpfs,target=/run/devsy/secrets-env,tmpfs-mode=0700", "type=tmpfs,dst=/run/devsy/secrets-env,mode=0700"}, - {"type=tmpfs,target=/scratch,tmpfs-size=4096", "type=tmpfs,dst=/scratch,size=4096"}, { "type=tmpfs,target=/scratch,tmpfs-mode=0700,future-option=enabled", "type=tmpfs,dst=/scratch,mode=0700,future-option=enabled", }, - {"type=tmpfs,target=/scratch,tmpfs-size=oops,tmpfs-mode=invalid", "type=tmpfs,dst=/scratch,size=oops,mode=invalid"}, + {"type=tmpfs,target=/scratch,tmpfs-mode=invalid", "type=tmpfs,dst=/scratch,mode=invalid"}, { "type=tmpfs,target=/scratch,tmpfs-mode=0777,tmpfs-mode=0700,readonly=false", "type=tmpfs,dst=/scratch,mode=0777,mode=0700,readonly=false", }, - {"type=tmpfs,target=/scratch,tmpfs-size=0,tmpfs-mode=0000", "type=tmpfs,dst=/scratch,size=0,mode=0000"}, + {"type=tmpfs,target=/scratch,tmpfs-mode=0000", "type=tmpfs,dst=/scratch,mode=0000"}, } { t.Run(tt.mount, func(t *testing.T) { mount := config.ParseMount(tt.mount) original := mount.String() - params := &driver.RunImageDevContainerParams{ - ParsedConfig: &config.DevContainerConfig{}, - Options: &driver.RunOptions{ - Image: testImageRef, - Mounts: []*config.Mount{&mount}, - }, - } - args := (&appleDriver{}).buildRunArgs(params) - require.Equal(t, []string{testMountFlag, tt.want}, args[2:4]) + originalOther := append([]string(nil), mount.Other...) + args := runArgsWithMounts(nil, &mount) + require.Equal(t, []string{tt.want}, mountArgs(args)) require.Equal(t, original, mount.String()) + require.Equal(t, originalOther, mount.Other) }) } } +// tmpfs-size is not translated: Apple container 1.5.0 turns sub-MiB sizes into +// zero (uncapped), so a Docker-style size must reach the CLI unchanged and be +// rejected there. A native size= is the user's own CLI syntax. +func TestBuildRunArgsLeavesTmpfsSizeUntranslated(t *testing.T) { + for _, tt := range []struct{ mount, want string }{ + {"type=tmpfs,target=/scratch,tmpfs-size=4096", "type=tmpfs,dst=/scratch,tmpfs-size=4096"}, + { + "type=tmpfs,target=/scratch,tmpfs-size=1M,tmpfs-mode=0700", + "type=tmpfs,dst=/scratch,tmpfs-size=1M,mode=0700", + }, + {"type=tmpfs,target=/scratch,size=2M", "type=tmpfs,dst=/scratch,size=2M"}, + } { + t.Run(tt.mount, func(t *testing.T) { + mount := config.ParseMount(tt.mount) + require.Equal(t, []string{tt.want}, mountArgs(runArgsWithMounts(nil, &mount))) + }) + } +} + +func TestBuildRunArgsTmpfsWorkspaceMount(t *testing.T) { + workspace := config.ParseMount("type=tmpfs,target=/workspaces/app,tmpfs-mode=0700") + original := workspace.String() + originalOther := append([]string(nil), workspace.Other...) + + args := runArgsWithMounts(&workspace) + + require.Equal(t, []string{"type=tmpfs,dst=/workspaces/app,mode=0700"}, mountArgs(args)) + require.Equal(t, original, workspace.String()) + require.Equal(t, originalOther, workspace.Other) +} + +func TestBuildRunArgsWorkspaceAndMountsBothTranslated(t *testing.T) { + workspace := config.ParseMount("type=tmpfs,target=/workspaces/app,tmpfs-mode=0700") + secrets := config.ParseMount("type=tmpfs,target=/run/secrets,tmpfs-mode=0755") + require.Equal( + t, + []string{ + "type=tmpfs,dst=/workspaces/app,mode=0700", + "type=tmpfs,dst=/run/secrets,mode=0755", + }, + mountArgs(runArgsWithMounts(&workspace, &secrets)), + ) +} + +func TestBuildRunArgsBindWorkspaceMountIsNotTranslated(t *testing.T) { + workspace := config.Mount{ + Type: "bind", + Source: t.TempDir(), + Target: "/workspaces/app", + Other: []string{"tmpfs-mode=0700", "consistency=cached"}, + } + args := runArgsWithMounts(&workspace) + // tmpfs-mode is only translated for tmpfs; consistency= is still cleaned. + require.Equal( + t, + []string{"type=bind,src=" + workspace.Source + ",dst=/workspaces/app,tmpfs-mode=0700"}, + mountArgs(args), + ) +} + func TestBuildRunArgsPreservesOtherMountDirectives(t *testing.T) { for _, spec := range []string{ "type=tmpfs,source=bad,target=/scratch", "type=tmpfs,target=relative", "type=tmpfs,target=/scratch:other",