跳到主要内容

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

浏览文件

macos_settings_darwin_test.go

55 行 · 2.1 KB历史下载
1package guestos
2
3import (
4 "os"
5 "os/exec"
6 "path/filepath"
7 "strings"
8 "testing"
9)
10
11// Compile the real shared settings router without running maintenance or
12// touching user permissions. Both first setup and later maintenance use it.
13func TestMacSettingsRoutesOpenSpecificPermissionPanes(t *testing.T) {
14 dir := t.TempDir()
15 harness := `import AppKit
16struct Failure: Error { init(_ code: Int, _ reason: String) {} }
17func consoleUser() throws -> String { throw Failure(1,"unused") }
18func requireGuest() throws { throw Failure(1,"unused") }
19enum MacSetupPassword {
20 static func runStream() -> Never { fatalError("unused") }
21 static func passwordFocused(_ app: NSRunningApplication, window: CGRect) -> Bool { false }
22}
23@main struct Check {
24 @MainActor static func main() {
25 for purpose in ["projects", "screen", "input"] {
26 guard let url = MacMaintenance.settingsURL(for: purpose) else { exit(1) }
27 print("\(purpose) \(url.absoluteString)")
28 }
29 guard MacMaintenance.settingsURL(for: "untrusted") == nil else { exit(2) }
30 }
31}
32`
33 input := filepath.Join(dir, "check.swift")
34 if err := os.WriteFile(input, []byte(harness), 0600); err != nil {
35 t.Fatal(err)
36 }
37 program := filepath.Join(dir, "settings-check")
38 source := filepath.Join("..", "..", "scripts", "guest-os", "macos-maintenance.swift")
39 compile := exec.CommandContext(t.Context(), "xcrun", "swiftc", "-parse-as-library", source, input, "-o", program)
40 if output, err := compile.CombinedOutput(); err != nil {
41 t.Fatalf("compile settings router: %v\n%s", err, output)
42 }
43 output, err := exec.CommandContext(t.Context(), program).CombinedOutput()
44 if err != nil {
45 t.Fatalf("settings routes: %v\n%s", err, output)
46 }
47 want := []string{
48 "projects x-apple.systempreferences:com.apple.ExtensionsPreferences?extensionPointIdentifier=com.apple.fskit.fsmodule",
49 "screen x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture",
50 "input x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility",
51 }
52 if strings.TrimSpace(string(output)) != strings.Join(want, "\n") {
53 t.Fatalf("permission routes lost the specific destination: %s", output)
54 }
55}