跳到主要内容

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

浏览文件

maintenance_windows_test.go

57 行 · 2.2 KB历史下载
1//go:build windows
2
3package guestos
4
5import (
6 "context"
7 "errors"
8 "os"
9 "os/exec"
10 "path/filepath"
11 "strings"
12 "testing"
13 "time"
14
15 "github.com/sylvinus/agent-vm/internal/diagnostics"
16)
17
18func TestWindowsHostRepairPreservesProcessOutput(t *testing.T) {
19 profile := t.TempDir()
20 if err := BindWindowsProfile(profile, windowsBindingFixture(profile)); err != nil {
21 t.Fatal(err)
22 }
23 kit := nativeManifestKit(t, Windows11)
24 script := `param([string]$Profile,[string]$ManifestPath,[string]$ManifestSHA256,[switch]$HostOnly)
25$ErrorActionPreference='Stop'
26[Console]::OutputEncoding=[Text.UTF8Encoding]::new($false)
27if (!$HostOnly -or (Get-FileHash -LiteralPath $ManifestPath -Algorithm SHA256).Hash -ne $ManifestSHA256) { exit 38 }
28Write-Output 'repair-fixture-stdout'
29[Console]::Error.WriteLine('repair-fixture-service-registration-failed token=repair-fixture-secret')
30exit 37
31`
32 if err := os.WriteFile(filepath.Join(kit, "maintain-windows-workbench.ps1"), []byte(script), 0600); err != nil {
33 t.Fatal(err)
34 }
35 var stdout, stderr strings.Builder
36 out := diagnostics.NewStream(nil, "storage-recovery", "info", func(line string) { stdout.WriteString(line) })
37 errOut := diagnostics.NewStream(nil, "storage-recovery", "warn", func(line string) { stderr.WriteString(line) })
38 ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
39 defer cancel()
40 err := RepairWindowsHostManager(ctx, profile, kit, out, errOut)
41 _ = out.Close()
42 _ = errOut.Close()
43 var exit *exec.ExitError
44 if !errors.As(err, &exit) || exit.ExitCode() != 37 {
45 t.Fatalf("repair lost the original process result: %v", err)
46 }
47 if !strings.Contains(stdout.String(), "repair-fixture-stdout") || !strings.Contains(stderr.String(), "repair-fixture-service-registration-failed") {
48 t.Fatalf("repair output did not reach the shared diagnostic streams: stdout=%q stderr=%q", stdout.String(), stderr.String())
49 }
50 if strings.Contains(stderr.String(), "repair-fixture-secret") || !strings.Contains(stderr.String(), "[redacted]") {
51 t.Fatal("repair output bypassed diagnostic redaction")
52 }
53 remaining, err := filepath.Glob(filepath.Join(profile, "native-host-repair-*.json"))
54 if err != nil || len(remaining) != 0 {
55 t.Fatalf("repair manifest was retained after failure: %v %v", remaining, err)
56 }
57}