跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

0027-vz-offscreen-macos-display.patch

114 行 · 4.4 KB历史下载
1diff --git a/pkg/driver/vz/vm_darwin.go b/pkg/driver/vz/vm_darwin.go
2index b737325..410cbf2 100644
3--- a/pkg/driver/vz/vm_darwin.go
4+++ b/pkg/driver/vz/vm_darwin.go
5@@ -629,7 +629,7 @@ func attachDisks(ctx context.Context, inst *limatype.Instance, vmConfig *vz.Virt
6
7 func attachDisplay(inst *limatype.Instance, vmConfig *vz.VirtualMachineConfiguration) error {
8 switch *inst.Config.Video.Display {
9- case "vz", "default":
10+ case "vz", "default", "offscreen":
11 var graphicsDeviceConfiguration vz.GraphicsDeviceConfiguration
12 if *inst.Config.OS == limatype.DARWIN {
13 var err error
14diff --git a/pkg/driver/vz/vz_driver_darwin.go b/pkg/driver/vz/vz_driver_darwin.go
15index 0430da1..364aa17 100644
16--- a/pkg/driver/vz/vz_driver_darwin.go
17+++ b/pkg/driver/vz/vz_driver_darwin.go
18@@ -339,9 +339,9 @@ func validateConfig(cfg *limatype.LimaYAML) error {
19 }
20
21 switch videoDisplay := *cfg.Video.Display; videoDisplay {
22- case "vz", "default", "none":
23+ case "vz", "default", "none", "offscreen":
24 default:
25- logrus.Warnf("field `video.display` must be `vz`, `default`, or `none` for VZ driver , got %#q", videoDisplay)
26+ logrus.Warnf("field `video.display` must be `vz`, `default`, `none`, or `offscreen` for VZ driver, got %#q", videoDisplay)
27 }
28 var vzOpts limatype.VZOpts
29 if err := limayaml.Convert(cfg.VMOpts[limatype.VZ], &vzOpts, "vmOpts.vz"); err != nil {
30diff --git a/pkg/driver/vz/vz_driver_darwin_test.go b/pkg/driver/vz/vz_driver_darwin_test.go
31index e751919..20eaa71 100644
32--- a/pkg/driver/vz/vz_driver_darwin_test.go
33+++ b/pkg/driver/vz/vz_driver_darwin_test.go
34@@ -9,15 +9,34 @@ import (
35 "errors"
36 "os"
37 "path/filepath"
38+ "runtime"
39 "testing"
40 "time"
41
42 "gotest.tools/v3/assert"
43
44+ applevz "github.com/Code-Hex/vz/v3"
45 "github.com/lima-vm/lima/v2/pkg/limatype"
46 "github.com/lima-vm/lima/v2/pkg/limatype/filenames"
47 )
48
49+func TestOffscreenGuestDisplay(t *testing.T) {
50+ if runtime.GOARCH != "arm64" {
51+ t.Skip("macOS guests require Apple Silicon")
52+ }
53+ inst := &limatype.Instance{Config: &limatype.LimaYAML{OS: new(limatype.DARWIN)}}
54+ inst.Config.Video.Display = new("offscreen")
55+ boot, err := newMacOSBootLoader()
56+ assert.NilError(t, err)
57+ config, err := applevz.NewVirtualMachineConfiguration(boot, 2, 4<<30)
58+ assert.NilError(t, err)
59+ assert.NilError(t, attachDisplay(inst, config))
60+
61+ driver := &LimaVzDriver{Instance: inst}
62+ assert.Equal(t, driver.Info(t.Context()).Features.CanRunGUI, false)
63+ assert.ErrorContains(t, driver.RunGUI(t.Context()), "RunGUI is not supported")
64+}
65+
66 func TestWaitForStopped(t *testing.T) {
67 t.Run("returns nil after the VM has stopped", func(t *testing.T) {
68 l := &LimaVzDriver{machine: &virtualMachineWrapper{}}
69diff --git a/pkg/limayaml/validate.go b/pkg/limayaml/validate.go
70index 33cefd5..e03a841 100644
71--- a/pkg/limayaml/validate.go
72+++ b/pkg/limayaml/validate.go
73@@ -64,6 +64,10 @@ func Validate(y *limatype.LimaYAML, warn bool) error {
74 errs = errors.Join(errs, fmt.Errorf("field `arch` must be one of %v; got %#q", limatype.ArchTypes, *y.Arch))
75 }
76
77+ if y.Video.Display != nil && *y.Video.Display == "offscreen" && (*y.OS != limatype.DARWIN || y.VMType == nil || *y.VMType != limatype.VZ) {
78+ errs = errors.Join(errs, errors.New("video.display offscreen requires a macOS guest with the VZ driver"))
79+ }
80+
81 if y.User.Shell != nil {
82 shell := *y.User.Shell
83 if *y.OS == limatype.WINDOWS {
84diff --git a/pkg/limayaml/validate_test.go b/pkg/limayaml/validate_test.go
85index 8040c29..79e9f88 100644
86--- a/pkg/limayaml/validate_test.go
87+++ b/pkg/limayaml/validate_test.go
88@@ -23,6 +23,26 @@ func TestValidateEmpty(t *testing.T) {
89 assert.Error(t, err, "field `images` must be set")
90 }
91
92+func TestOffscreenDisplayRequiresMacOSAndVZ(t *testing.T) {
93+ for _, tc := range []struct{ os, driver string }{
94+ {limatype.DARWIN, limatype.VZ},
95+ {limatype.LINUX, limatype.VZ},
96+ {limatype.DARWIN, limatype.QEMU},
97+ } {
98+ t.Run(tc.os+"-"+tc.driver, func(t *testing.T) {
99+ body := fmt.Sprintf("os: %s\nvmType: %s\nvideo: {display: offscreen}\nimages: [{location: /}]\n", tc.os, tc.driver)
100+ y, err := Load(t.Context(), []byte(body), "lima.yaml")
101+ assert.NilError(t, err)
102+ err = Validate(y, false)
103+ if tc.os == limatype.DARWIN && tc.driver == limatype.VZ {
104+ assert.NilError(t, err)
105+ } else {
106+ assert.ErrorContains(t, err, "offscreen requires a macOS guest")
107+ }
108+ })
109+ }
110+}
111+
112 func TestValidateMinimumLimaVersion(t *testing.T) {
113 images := `images: [{"location": "/"}]`
114