Merge pull request #67 from Lee-xeo/codex/ci-platform-fixtures
修复主线 Linux 容器测试与 Windows 安装接续检查
- 作者
- Shihao Li
- 时间
- 2026/11/11 17:25
- 提交
- 28abdb0
这是一个合并提交,下面是和第一个上一提交相比的改动。
修复主线 Linux 容器测试与 Windows 安装接续检查
这是一个合并提交,下面是和第一个上一提交相比的改动。
| @@ -29,12 +29,12 @@ jobs: | ||
| 29 | 29 | image: ubuntu:22.04 |
| 30 | 30 | # docker-default AppArmor denies bubblewrap's private mount namespace. |
| 31 | 31 | # Relax only this disposable outer container; WebKit keeps its sandbox. |
| 32 | 删除: options: --security-opt seccomp=unconfined --security-opt systempaths=unconfined --security-opt apparmor=unconfined | |
| 32 | 新增: options: --init --security-opt seccomp=unconfined --security-opt systempaths=unconfined --security-opt apparmor=unconfined | |
| 33 | 33 | steps: |
| 34 | 34 | - name: Install build and test dependencies |
| 35 | 35 | run: | |
| 36 | 36 | apt-get update |
| 37 | 删除: DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential pkg-config libgtk-3-dev libwebkit2gtk-4.1-dev libjson-glib-dev dpkg-dev curl ca-certificates git software-properties-common qemu-system-x86 qemu-utils ovmf openssh-client iproute2 dbus-x11 xvfb xauth fonts-noto-cjk zsh sudo | |
| 37 | 新增: DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential pkg-config libgtk-3-dev libwebkit2gtk-4.1-dev libjson-glib-dev dpkg-dev curl ca-certificates git software-properties-common qemu-system-x86 qemu-utils ovmf openssh-client iproute2 dbus-x11 xvfb xauth fonts-noto-cjk zsh sudo tzdata | |
| 38 | 38 | # The supported 22.04 ABI predates safe.bareRepository. Use the Git |
| 39 | 39 | # project's documented Ubuntu packages, preserving the runtime gate. |
| 40 | 40 | add-apt-repository -y ppa:git-core/ppa |
| @@ -18,10 +18,15 @@ func TestDesktopResizeScriptAppliesTheViewersDensity(t *testing.T) { | ||
| 18 | 18 | if runtime.GOOS != "linux" || err != nil { |
| 19 | 19 | t.Skip("the script identifies its settings manager through /proc") |
| 20 | 20 | } |
| 21 | 删除: // Go's temporary directory can be mounted noexec; the stand-ins must run. | |
| 22 | 删除: root, err := os.MkdirTemp("/dev/shm", "cage-resize-") | |
| 21 | 新增: // go test already executes its test binary from this filesystem. Both | |
| 22 | 新增: // TMPDIR and /dev/shm can be mounted noexec independently of the Go build directory. | |
| 23 | 新增: executable, err := os.Executable() | |
| 23 | 24 | if err != nil { |
| 24 | 删除: root = t.TempDir() | |
| 25 | 新增: t.Fatal(err) | |
| 26 | 新增: } | |
| 27 | 新增: root, err := os.MkdirTemp(filepath.Dir(executable), "cage-resize-") | |
| 28 | 新增: if err != nil { | |
| 29 | 新增: t.Fatal(err) | |
| 25 | 30 | } |
| 26 | 31 | t.Cleanup(func() { os.RemoveAll(root) }) |
| 27 | 32 | desktop, phone, bin := filepath.Join(root, "desktop"), filepath.Join(root, "phone"), filepath.Join(root, "bin") |
| @@ -40,9 +45,10 @@ func TestDesktopResizeScriptAppliesTheViewersDensity(t *testing.T) { | ||
| 40 | 45 | data, _ := os.ReadFile(path) |
| 41 | 46 | return string(data) |
| 42 | 47 | } |
| 43 | 删除: write(filepath.Join(bin, "xrandr"), "#!/bin/sh\necho \"$*\" >> "+filepath.Join(root, "modes")+"\n", 0o700) | |
| 48 | 新增: t.Setenv("CAGE_RESIZE_FIXTURE", root) | |
| 49 | 新增: write(filepath.Join(bin, "xrandr"), "#!/bin/sh\necho \"$*\" >> \"$CAGE_RESIZE_FIXTURE/modes\"\n", 0o700) | |
| 44 | 50 | // The script signals a process named xsettingsd. |
| 45 | 删除: write(filepath.Join(bin, "xsettingsd"), "#!/bin/sh\ntrap 'echo reload >> "+filepath.Join(root, "reloads")+"' HUP\nwhile :; do sleep 1 & wait $!; done\n", 0o700) | |
| 51 | 新增: write(filepath.Join(bin, "xsettingsd"), "#!/bin/sh\ntrap 'echo reload >> \"$CAGE_RESIZE_FIXTURE/reloads\"' HUP\nwhile :; do sleep 1 & wait $!; done\n", 0o700) | |
| 46 | 52 | resize := func(scale string) string { |
| 47 | 53 | t.Helper() |
| 48 | 54 | script := strings.NewReplacer("/run/cage-desktop", desktop, "/run/cage-phone-desktop", phone).Replace(desktopResizeScript(1000, 800, scale)) |
| @@ -91,6 +91,8 @@ finally { if ($progressStream) { $progressStream.Dispose() } } | ||
| 91 | 91 | try{ |
| 92 | 92 | if($context){Wait-CageHostEnrollment $context $worker} |
| 93 | 93 | $process=Start-Process -FilePath (Join-Path ([Environment]::GetFolderPath('System')) 'WindowsPowerShell/v1.0/powershell.exe') -ArgumentList @('-NoLogo','-NoProfile','-ExecutionPolicy','RemoteSigned','-EncodedCommand',$encoded) -Verb RunAs -PassThru |
| 94 | 新增: # Windows PowerShell 5.1 must retain a handle before waiting to read ExitCode. | |
| 95 | 新增: $null=$process.Handle | |
| 94 | 96 | if($context){Set-CageHostEnrollmentAdmin $context $process} |
| 95 | 97 | Wait-CageWindowsInstaller $process $progressFile |
| 96 | 98 | if($process.ExitCode -ne 0){throw 'Windows setup did not complete; existing VM and data were preserved.'} |
| @@ -19,6 +19,7 @@ public static class Native { | ||
| 19 | 19 | [DllImport("kernel32.dll",SetLastError=true)] public static extern bool GetNamedPipeServerProcessId(SafePipeHandle pipe,out uint pid); |
| 20 | 20 | [DllImport("kernel32.dll",SetLastError=true)] static extern bool GetProcessTimes(IntPtr process,out FileTime created,out FileTime exited,out FileTime kernel,out FileTime user); |
| 21 | 21 | [DllImport("kernel32.dll",CharSet=CharSet.Unicode,ExactSpelling=true,SetLastError=true)] static extern bool QueryFullProcessImageNameW(IntPtr process,uint flags,StringBuilder image,ref uint size); |
| 22 | 新增: [DllImport("kernel32.dll",CharSet=CharSet.Unicode,ExactSpelling=true,SetLastError=true)] static extern uint GetLongPathNameW(string path,StringBuilder expanded,uint capacity); | |
| 22 | 23 | [DllImport("advapi32.dll",SetLastError=true)] static extern bool OpenProcessToken(IntPtr process,uint access,out IntPtr token); |
| 23 | 24 | [DllImport("advapi32.dll",SetLastError=true)] static extern bool GetTokenInformation(IntPtr token,int kind,IntPtr data,uint bytes,out uint needed); |
| 24 | 25 | [DllImport("ntdll.dll")] static extern int NtQueryInformationProcess(IntPtr process,int kind,out Basic basic,uint bytes,out uint needed); |
| @@ -30,6 +31,17 @@ public static class Native { | ||
| 30 | 31 | var p=OpenProcess(0x1000,false,pid);if(p==IntPtr.Zero)throw new InvalidOperationException("enrollment_peer_invalid"); |
| 31 | 32 | try {var value=new StringBuilder(32768);uint n=(uint)value.Capacity;if(!QueryFullProcessImageNameW(p,0,value,ref n))throw new InvalidOperationException("enrollment_peer_invalid");return value.ToString();}finally{CloseHandle(p);} |
| 32 | 33 | } |
| 34 | 新增: static string LongPath(string path) { | |
| 35 | 新增: var expanded=new StringBuilder(32768); | |
| 36 | 新增: uint n=GetLongPathNameW(path,expanded,(uint)expanded.Capacity); | |
| 37 | 新增: if(n==0||n>=expanded.Capacity)throw new InvalidOperationException("enrollment_image_path_unavailable"); | |
| 38 | 新增: return expanded.ToString(); | |
| 39 | 新增: } | |
| 40 | 新增: public static bool SameImagePath(string actual,string expected) { | |
| 41 | 新增: if(string.Equals(actual,expected,StringComparison.OrdinalIgnoreCase))return true; | |
| 42 | 新增: // The kernel may report an 8.3 path for a process started by a long path. | |
| 43 | 新增: return string.Equals(LongPath(actual),LongPath(expected),StringComparison.OrdinalIgnoreCase); | |
| 44 | 新增: } | |
| 33 | 45 | public static uint Parent(uint pid) { |
| 34 | 46 | var p=OpenProcess(0x1000,false,pid);if(p==IntPtr.Zero)throw new InvalidOperationException("enrollment_peer_invalid"); |
| 35 | 47 | try {Basic value;uint n;if(NtQueryInformationProcess(p,0,out value,(uint)Marshal.SizeOf(typeof(Basic)),out n)!=0)throw new InvalidOperationException("enrollment_peer_invalid");return checked((uint)value.Parent.ToInt64());}finally{CloseHandle(p);} |
| @@ -49,7 +61,7 @@ function Assert-CageHostEnrollmentPeer($Context,$Stream) { | ||
| 49 | 61 | [uint32]$serverPID=0 |
| 50 | 62 | if(![Cage.HostEnrollment.Native]::GetNamedPipeServerProcessId($Stream.SafePipeHandle,[ref]$serverPID) -or $serverPID -ne $Context.WorkerPID){throw 'The original host enrollment peer could not be verified.'} |
| 51 | 63 | if([Cage.HostEnrollment.Native]::Started($serverPID) -ne [long]$Context.WorkerStarted -or |
| 52 | 删除: [Cage.HostEnrollment.Native]::Image($serverPID) -ine $Context.WorkerExe -or | |
| 64 | 新增: ![Cage.HostEnrollment.Native]::SameImagePath([Cage.HostEnrollment.Native]::Image($serverPID),$Context.WorkerExe) -or | |
| 53 | 65 | [Cage.HostEnrollment.Native]::UserSID($serverPID) -cne $Context.HostSID -or |
| 54 | 66 | [Cage.HostEnrollment.Native]::Parent($serverPID) -ne $Context.OwnerPID -or |
| 55 | 67 | [Cage.HostEnrollment.Native]::Started([uint32]$Context.OwnerPID) -ne [long]$Context.OwnerStarted -or |
| @@ -84,6 +84,7 @@ try { | ||
| 84 | 84 | $encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($command)) |
| 85 | 85 | $child = Start-Process -FilePath (Get-Process -Id $PID).Path -ArgumentList @('-NoLogo','-NoProfile','-NonInteractive','-EncodedCommand',$encoded) -RedirectStandardOutput $stdout -RedirectStandardError $stderr -PassThru |
| 86 | 86 | try { |
| 87 | 新增: $null = $child.Handle | |
| 87 | 88 | $forwarded = @(Wait-CageWindowsInstaller $child $progressFile) |
| 88 | 89 | Assert-Check ($child.ExitCode -eq 0) ('Encoded installer wrapper failed. '+[IO.File]::ReadAllText($stderr)) |
| 89 | 90 | Assert-Check ($forwarded[-1] -ceq 'CAGE_GUEST_STAGE windows-11 oobe') 'The actual child could not publish its final stage.' |