提交记录修改docs/guide/guest-systems.md+15 −0看文件
修改docs/windows.md+2 −0看文件
修改internal/workbench/setup_progress.go+13 −0看文件
修改internal/workbench/setup_progress_test.go+14 −0看文件
修改scripts/ci-windows-build.ps1+3 −0看文件
修改scripts/guest-os/complete-windows-guest.ps1+9 −1看文件
修改scripts/guest-os/new-windows-test-vm.ps1+16 −6看文件
修改scripts/guest-os/setup-windows-guest.ps1+59 −7看文件
修改scripts/guest-os/windows-host-image.ps1+50 −0看文件
新增scripts/guest-os/windows-iso-setup.tests.ps1+119 −0看文件
修改ui/scripts/setup-progress-smoke.mjs+43 −0看文件
修改ui/src/guest-system-picker.jsx+1 −1看文件
修改ui/src/setup-progress.jsx+10 −3看文件
| @@ -108,6 +108,21 @@ Cage 会撤销临时管理员并关闭这台客机的首次设置入口。以后 | ||
| 108 | 108 | |
| 109 | 109 | Windows 客机的系统账户和应用登录独立保存。管理助手未连接或原客机配置变化时,Cage 会提示核对原环境;恢复助手或更新 Cage 不应重建账户、替换原系统盘或初始化个人目录。 |
| 110 | 110 | |
| 111 | 新增:### 使用 Windows 本机 ISO | |
| 112 | 新增: | |
| 113 | 新增:选择 Microsoft 官方 Windows 11 x64 ISO 后,在系统授权打开的安装窗口中设置客机初始本地管理员。默认名称为 `CageAdmin`,可以修改。请保存这个账户的密码,后续登录客机和继续安装时都需要使用。 | |
| 114 | 新增: | |
| 115 | 新增:Cage 将账户信息写入具有私有权限的安装应答盘,Windows 首次设置据此创建本地管理员并跳过联网账户引导。客机保持零常规 Hyper-V 网卡,完成组件置备后使用 Cage 网络通道。应答盘在确认客机已完成首次设置、可以通过管理员账户连接后清理。 | |
| 116 | 新增: | |
| 117 | 新增:1. 在“虚拟机连接”(VMConnect)窗口选择 Windows 版本、目标磁盘,确认许可并完成区域设置。本轮 PowerShell 创建窗口会自动关闭。 | |
| 118 | 新增:2. 使用安装前设置的本地管理员登录客机桌面,回到 Cage 点击“已进入桌面,继续安装”。 | |
| 119 | 新增:3. 确认系统授权,在 PowerShell 安装窗口再次输入客机管理员账户。保持该窗口开启,等待组件下载、安装和配置结束。Cage 会创建用于工作台的专用普通账户,并重启客机完成首次登录。 | |
| 120 | 新增:4. 回到 Cage 完成网络检查,再进入工作台。 | |
| 121 | 新增: | |
| 122 | 新增:已有客机继续使用原账户和系统盘。若安装由旧版本创建,使用当时创建的客机管理员继续。若仍停在 Windows 首次设置的强制联网页面,可以在 VMConnect 中按 `Shift+F10`,先检查 `%WINDIR%\System32\OOBE\BypassNRO.cmd` 是否存在。仅在该脚本存在时运行它,重启后选择离线继续并创建本地账户。各 Windows 构建提供的入口不同,缺少该脚本时应保留虚拟磁盘并记录 Windows 构建号,进一步核查该版本的离线设置方式。 | |
| 123 | 新增: | |
| 124 | 新增:安装卡片区分等待 Windows 首次设置、组件下载和组件配置。原用户注册助手失败时,操作详情会保留 `enrollment_pipe_listen_failed` 或 `enrollment_pipe_accept_failed` 及 Win32 错误码,便于定位继续安装的问题。 | |
| 125 | 新增: | |
| 111 | 126 | ## 下载量与磁盘空间 |
| 112 | 127 | |
| 113 | 128 | 系统镜像的下载大小和虚拟磁盘容量是两件事。Debian 基础镜像约 320–325 MiB,初始虚拟磁盘容量上限为 24 GiB;macOS 和 Windows 的安装介质与系统占用更大,具体以所选版本为准。创建前请为镜像、系统盘、开发工具、项目产物和更新备份留足空间。 |
| @@ -8,6 +8,8 @@ Cage 的 Windows 版本面向 Windows 10 22H2(内部版本 19045)和 Windows | ||
| 8 | 8 | |
| 9 | 9 | “自动匹配本机系统版本”匹配 Windows 发行版本、版本类型和语言,展示主机与客机补丁构建差异;安装中断后继续原记录与系统盘。当前已实测建机、首次启动与冷启动,修复后的最终工作台登记仍待复验。完整条件和流程见[客机系统指南](guide/guest-systems.md#自动匹配本机系统版本)。 |
| 10 | 10 | |
| 11 | 新增:使用本机 ISO 时,安装窗口会先收集客机本地管理员账户,用安装应答完成离线账户创建。进入客机桌面后回 Cage 继续安装,组件置备期间保持 PowerShell 安装窗口开启。具体步骤及旧安装接续见[使用 Windows 本机 ISO](guide/guest-systems.md#使用-windows-本机-iso)。 | |
| 12 | 新增: | |
| 11 | 13 | | 项目 | 要求 | |
| 12 | 14 | |---|---| |
| 13 | 15 | | 系统 | x64 Windows 10 22H2 或 Windows 11;不包含 Windows ARM64 与 32 位系统 | |
| @@ -76,9 +76,22 @@ func parseSetupProgress(line string) *SetupProgress { | ||
| 76 | 76 | return nil |
| 77 | 77 | } |
| 78 | 78 | p := &SetupProgress{System: fields[1]} |
| 79 | 新增: if fields[1] == "windows-11" { | |
| 80 | 新增: p.Operation = fields[2] | |
| 81 | 新增: } | |
| 79 | 82 | switch fields[2] { |
| 80 | 83 | case "restore": |
| 81 | 84 | p.Phase, p.Label = "packages", "正在安装 "+guestProgressName(fields[1])+" 系统" |
| 85 | 新增: case "account", "oobe", "credentials": | |
| 86 | 新增: if fields[1] != "windows-11" { | |
| 87 | 新增: return nil | |
| 88 | 新增: } | |
| 89 | 新增: p.Phase = "packages" | |
| 90 | 新增: p.Label = map[string]string{ | |
| 91 | 新增: "account": "请在安装窗口设置客机本地管理员", | |
| 92 | 新增: "oobe": "请在虚拟机连接窗口完成 Windows 首次设置", | |
| 93 | 新增: "credentials": "请在安装窗口输入客机管理员账户", | |
| 94 | 新增: }[fields[2]] | |
| 82 | 95 | case "media": |
| 83 | 96 | p.Phase, p.Label = "image", "正在下载并校验客机开发组件" |
| 84 | 97 | case "tools": |
| @@ -6,6 +6,20 @@ import ( | ||
| 6 | 6 | "time" |
| 7 | 7 | ) |
| 8 | 8 | |
| 9 | 新增:func TestWindowsInstallationInteractionStages(t *testing.T) { | |
| 10 | 新增: for _, stage := range []string{"account", "oobe", "credentials", "media", "tools", "services"} { | |
| 11 | 新增: progress := parseSetupProgress("CAGE_GUEST_STAGE windows-11 " + stage) | |
| 12 | 新增: if progress == nil || progress.System != "windows-11" || progress.Operation != stage || progress.Label == "" { | |
| 13 | 新增: t.Fatalf("Windows installation stage was lost: %s %+v", stage, progress) | |
| 14 | 新增: } | |
| 15 | 新增: } | |
| 16 | 新增: for _, system := range []string{"macos", "debian-13", "ubuntu-22.04"} { | |
| 17 | 新增: if parseSetupProgress("CAGE_GUEST_STAGE "+system+" oobe") != nil { | |
| 18 | 新增: t.Fatalf("Windows interaction stage accepted for %s", system) | |
| 19 | 新增: } | |
| 20 | 新增: } | |
| 21 | 新增:} | |
| 22 | 新增: | |
| 9 | 23 | // Child pipes may split a progress line across writes. A fallback mirror may |
| 10 | 24 | // restart from zero, and an absent Content-Length must stay indeterminate. |
| 11 | 25 | func TestSetupProgressFromChildOutput(t *testing.T) { |
| @@ -62,6 +62,9 @@ try { | ||
| 62 | 62 | } |
| 63 | 63 | & (Join-Path $PSScriptRoot 'build-windows.ps1') -Release:$Release |
| 64 | 64 | Invoke-BuildTool $windowsPowerShell @('-NoProfile', '-NonInteractive', '-File', 'scripts/guest-os/windows-host-enrollment.tests.ps1') |
| 65 | 新增: foreach ($test in @('windows-iso-setup.tests.ps1', 'windows-host-image.tests.ps1', 'new-windows-test-vm.tests.ps1')) { | |
| 66 | 新增: Invoke-BuildTool $windowsPowerShell @('-NoProfile', '-NonInteractive', '-File', "scripts/guest-os/$test") | |
| 67 | 新增: } | |
| 65 | 68 | Invoke-BuildTool 'go' @('test', './internal/guestos', '-run', '^TestWindowsHostEnrollment', '-count=1') |
| 66 | 69 | if (-not $Release) { |
| 67 | 70 | $windowsPowerShell = Join-Path ([Environment]::SystemDirectory) 'WindowsPowerShell/v1.0/powershell.exe' |
| @@ -199,9 +199,14 @@ try { | ||
| 199 | 199 | Publish-ReadyBinding |
| 200 | 200 | return |
| 201 | 201 | } |
| 202 | 删除: if (!$GuestAdministrator) { $GuestAdministrator=Get-Credential -Message 'Cage: enter an administrator account of the selected virtual Windows machine.' } | |
| 202 | 新增: if (!$GuestAdministrator) { | |
| 203 | 新增: Write-Output 'CAGE_GUEST_STAGE windows-11 credentials' | |
| 204 | 新增: $GuestAdministrator=Get-Credential -Message '先在虚拟机连接窗口完成 Windows 设置并登录桌面,再输入客机管理员账户。新建 ISO 安装请使用安装前设置的本地账户。请保持此 PowerShell 安装窗口开启。' | |
| 205 | 新增: } else { Write-Output 'CAGE_GUEST_STAGE windows-11 services' } | |
| 203 | 206 | if (!$GuestAdministrator) { throw 'Windows guest setup canceled.' } |
| 204 | 207 | $session=New-PSSession -VMId $VMId -Credential $GuestAdministrator |
| 208 | 新增: if ($choice.source.host.system -cne 'windows-11') { Remove-CageISOAnswer $vm $session $instance } | |
| 209 | 新增: Write-Output 'CAGE_GUEST_STAGE windows-11 services' | |
| 205 | 210 | $target=Invoke-Command -Session $session -FilePath (Join-Path $PSScriptRoot 'initialize-windows-workbench-user.ps1') -ArgumentList $VMId |
| 206 | 211 | $firstBoot=Join-Path $pairDirectory 'first-account-boot' |
| 207 | 212 | if (!$target.AlreadySignedIn -and (Test-Path -LiteralPath $firstBoot) -and [IO.File]::ReadAllText($firstBoot) -ne $target.BootID) { |
| @@ -218,10 +223,12 @@ try { | ||
| 218 | 223 | $packages=Get-Content -LiteralPath (Join-Path $payload 'windows-workbench-packages.json') -Raw | ConvertFrom-Json |
| 219 | 224 | $cli=Get-Content -LiteralPath (Join-Path $payload 'cli-dependencies.json') -Raw | ConvertFrom-Json |
| 220 | 225 | $files=@{} |
| 226 | 新增: Write-Output 'CAGE_GUEST_STAGE windows-11 media' | |
| 221 | 227 | foreach ($spec in @($packages.PSObject.Properties)+@($cli.PSObject.Properties)) { |
| 222 | 228 | $files[$spec.Name]=Get-PinnedPackage $spec.Value $cache |
| 223 | 229 | } |
| 224 | 230 | |
| 231 | 新增: Write-Output 'CAGE_GUEST_STAGE windows-11 tools' | |
| 225 | 232 | $scratch=Join-Path $workRoot ('stage-'+[guid]::NewGuid()) |
| 226 | 233 | $null=New-Item -ItemType Directory $scratch |
| 227 | 234 | $core=Join-Path $scratch 'core' |
| @@ -314,6 +321,7 @@ try { | ||
| 314 | 321 | } |
| 315 | 322 | |
| 316 | 323 | [IO.File]::WriteAllText($completionMarker,$target.SID) |
| 324 | 新增: Write-Output 'CAGE_GUEST_STAGE windows-11 services' | |
| 317 | 325 | Publish-ReadyBinding |
| 318 | 326 | } finally { |
| 319 | 327 | if ($session) { Remove-PSSession $session } |
| @@ -1,4 +1,4 @@ | ||
| 1 | 删除:#requires -Version 5.1 | |
| 1 | 新增:#requires -Version 5.1 | |
| 2 | 2 | <# |
| 3 | 3 | .SYNOPSIS |
| 4 | 4 | Create an offline Windows 11 x64 test VM on a local Hyper-V host. |
| @@ -10,6 +10,9 @@ disk and guest TPM state stay together after shutdown. Use the returned VMId | ||
| 10 | 10 | as -ExpectedVMId for claude-desktop-windows.ps1. -Start boots only this VM. |
| 11 | 11 | Windows Setup installs PowerShell 7 for all guest users. Supply -PowerShellZip |
| 12 | 12 | to use an existing copy of the pinned Microsoft archive on an offline host. |
| 13 | 新增:Manual ISO setup prompts for the guest's initial local administrator. Supply | |
| 14 | 新增:-GuestAdministrator to provide it directly. Windows Setup uses the protected | |
| 15 | 新增:answer DVD to create that account without a network connection. | |
| 13 | 16 | #> |
| 14 | 17 | [CmdletBinding(SupportsShouldProcess)] |
| 15 | 18 | param( |
| @@ -29,8 +32,8 @@ param( | ||
| 29 | 32 | ) |
| 30 | 33 | $ErrorActionPreference = 'Stop' |
| 31 | 34 | . (Join-Path $PSScriptRoot 'windows-guest-media.ps1') |
| 35 | 新增:. (Join-Path $PSScriptRoot 'windows-host-image.ps1') | |
| 32 | 36 | $fromHost = ![string]::IsNullOrEmpty($ImageEdition) |
| 33 | 删除:if ($fromHost) { . (Join-Path $PSScriptRoot 'windows-host-image.ps1') } | |
| 34 | 37 | |
| 35 | 38 | function Set-TestVMResources($VM, [int]$Processors, [long]$MemoryBytes) { |
| 36 | 39 | # New-VM can inherit Dynamic Memory with a 1 TiB maximum on a client host. |
| @@ -80,6 +83,15 @@ if ([IO.DriveInfo]::new($parent.Root.FullName).AvailableFreeSpace -lt $requiredF | ||
| 80 | 83 | } |
| 81 | 84 | if (!$PSCmdlet.ShouldProcess($directory, "Create offline Hyper-V VM '$Name' (start: $([bool]$Start))")) { return } |
| 82 | 85 | |
| 86 | 新增:if ($fromHost) { | |
| 87 | 新增: $answer = New-CageCloneAnswer $GuestAdministrator $ImageLanguage | |
| 88 | 新增:} else { | |
| 89 | 新增: if (!$GuestAdministrator) { | |
| 90 | 新增: $GuestAdministrator = Get-Credential -UserName 'CageAdmin' -Message '设置虚拟 Windows 的初始本地管理员和密码。安装后用此账户登录客机,并在 Cage 继续安装时再次输入。' | |
| 91 | 新增: } | |
| 92 | 新增: $answer = New-CageISOAnswer $GuestAdministrator | |
| 93 | 新增:} | |
| 94 | 新增: | |
| 83 | 95 | # Create with a protected ACL, then claim the requested name using a same-volume |
| 84 | 96 | # rename that fails atomically if another creation has already won. |
| 85 | 97 | $acl = [Security.AccessControl.DirectorySecurity]::new() |
| @@ -108,10 +120,8 @@ try { | ||
| 108 | 120 | [IO.Directory]::Move($staging, $directory) |
| 109 | 121 | $staged = $false |
| 110 | 122 | $claimed = $true |
| 111 | 删除: # On a normal install Windows Setup still asks for edition, disk, license | |
| 112 | 删除: # and account. The second DVD contributes only the guest development tools. | |
| 113 | 删除: $answer = [xml]'<unattend xmlns="urn:schemas-microsoft-com:unattend"><settings pass="specialize"/></unattend>' | |
| 114 | 删除: if ($fromHost) { $answer = New-CageCloneAnswer $GuestAdministrator $ImageLanguage } | |
| 123 | 新增: # The protected second DVD supplies the chosen local account and tools. | |
| 124 | 新增: # Windows Setup still asks for edition, disk, license and regional settings. | |
| 115 | 125 | New-WindowsGuestAnswerISO $toolsISO $answer $PowerShellZip |
| 116 | 126 | $ownsToolsISO = $true |
| 117 | 127 | $vm = New-VM -Name $Name -Generation 2 -MemoryStartupBytes ($MemoryGiB * 1GB) -NoVHD -Path $directory |
| @@ -1,4 +1,4 @@ | ||
| 1 | 删除:#requires -Version 5.1 | |
| 1 | 新增:#requires -Version 5.1 | |
| 2 | 2 | [CmdletBinding()] |
| 3 | 3 | param( |
| 4 | 4 | [Parameter(Mandatory)][string]$Profile, |
| @@ -17,6 +17,25 @@ $ProgressPreference='SilentlyContinue' | ||
| 17 | 17 | $identity=[Security.Principal.WindowsIdentity]::GetCurrent() |
| 18 | 18 | $principal=[Security.Principal.WindowsPrincipal]::new($identity) |
| 19 | 19 | . (Join-Path $PSScriptRoot 'windows-host-image.ps1') |
| 20 | 新增: | |
| 21 | 新增:function Wait-CageWindowsInstaller($Process, [string]$ProgressFile) { | |
| 22 | 新增: $lastStage = '' | |
| 23 | 新增: do { | |
| 24 | 新增: $exited = $Process.WaitForExit(250) | |
| 25 | 新增: $stage = '' | |
| 26 | 新增: $reader = $null | |
| 27 | 新增: try { | |
| 28 | 新增: $reader = [IO.StreamReader]::new([IO.File]::Open($ProgressFile, 'Open', 'Read', 'ReadWrite')) | |
| 29 | 新增: $stage = $reader.ReadToEnd() | |
| 30 | 新增: } catch [IO.IOException] { } | |
| 31 | 新增: finally { if ($reader) { $reader.Dispose() } } | |
| 32 | 新增: if ($stage -cmatch '^CAGE_GUEST_STAGE windows-11 (account|oobe|credentials|media|tools|services)$' -and $stage -cne $lastStage) { | |
| 33 | 新增: Write-Output $stage | |
| 34 | 新增: $lastStage = $stage | |
| 35 | 新增: } | |
| 36 | 新增: } while (!$exited) | |
| 37 | 新增:} | |
| 38 | 新增: | |
| 20 | 39 | if(!$principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)){ |
| 21 | 40 | if($identity.User.Value -cne $HostUserSID){throw 'Continue setup with the already authorized host user.'} |
| 22 | 41 | if($HostEnrollment){throw 'Original user enrollment must be created by this setup process.'} |
| @@ -34,20 +53,52 @@ if(!$principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) | ||
| 34 | 53 | } |
| 35 | 54 | # Preserve every selected installation argument across the one-time UAC |
| 36 | 55 | # boundary. Encoded data cannot become executable PowerShell syntax. |
| 37 | 删除: $parameters=@{Profile=$Profile;State=$State;InstallationID=$InstallationID.ToString('D');IsoPath=$IsoPath;ExpectedIsoSha256=$ExpectedIsoSha256;ManifestPath=$ManifestPath;ManifestSHA256=$ManifestSHA256;HostUserSID=$HostUserSID;HostEnrollment=$context} | |
| 56 | 新增: $progressFile=Join-Path ([IO.Path]::GetTempPath()) ('cage-windows-setup-'+[guid]::NewGuid().ToString('N')+'.stage') | |
| 57 | 新增: # Hold the new file without delete sharing across UAC. The elevated writer | |
| 58 | 新增: # opens this existing file once, so its path cannot be replaced mid-install. | |
| 59 | 新增: $progressHandle=[IO.File]::Open($progressFile,'CreateNew','ReadWrite','ReadWrite') | |
| 60 | 新增: $parameters=@{Profile=$Profile;State=$State;InstallationID=$InstallationID.ToString('D');IsoPath=$IsoPath;ExpectedIsoSha256=$ExpectedIsoSha256;ManifestPath=$ManifestPath;ManifestSHA256=$ManifestSHA256;HostUserSID=$HostUserSID;HostEnrollment=$context;ProgressFile=$progressFile} | |
| 38 | 61 | $payload=[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(($parameters|ConvertTo-Json -Depth 6 -Compress))) |
| 39 | 62 | $script=[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($PSCommandPath)) |
| 40 | 删除: $command='$ErrorActionPreference=''Stop'';$p=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('''+$payload+'''))|ConvertFrom-Json;$a=@{};$p.PSObject.Properties|ForEach-Object{$a[$_.Name]=$_.Value};$s=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('''+$script+'''));try{& $s @a;exit 0}catch{Write-Error $_;exit 1}' | |
| 63 | 新增: $command=@' | |
| 64 | 新增:$ErrorActionPreference='Stop' | |
| 65 | 新增:$p=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('__PARAMETERS__'))|ConvertFrom-Json | |
| 66 | 新增:$a=@{} | |
| 67 | 新增:$p.PSObject.Properties|ForEach-Object{$a[$_.Name]=$_.Value} | |
| 68 | 新增:$progressFile=$a.ProgressFile | |
| 69 | 新增:$a.Remove('ProgressFile') | |
| 70 | 新增:$s=[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('__SCRIPT__')) | |
| 71 | 新增:$progressStream=$null | |
| 72 | 新增:try { | |
| 73 | 新增: $progressStream=[IO.File]::Open($progressFile,'Open','Write','ReadWrite') | |
| 74 | 新增: & $s @a | ForEach-Object { | |
| 75 | 新增: $line=[string]$_ | |
| 76 | 新增: if ($line -cmatch '^CAGE_GUEST_STAGE windows-11 (account|oobe|credentials|media|tools|services)$') { | |
| 77 | 新增: $bytes=[Text.Encoding]::UTF8.GetBytes($line) | |
| 78 | 新增: $progressStream.Position=0 | |
| 79 | 新增: $progressStream.SetLength(0) | |
| 80 | 新增: $progressStream.Write($bytes,0,$bytes.Length) | |
| 81 | 新增: $progressStream.Flush() | |
| 82 | 新增: } | |
| 83 | 新增: Write-Output $_ | |
| 84 | 新增: } | |
| 85 | 新增: exit 0 | |
| 86 | 新增:} catch { Write-Error $_; exit 1 } | |
| 87 | 新增:finally { if ($progressStream) { $progressStream.Dispose() } } | |
| 88 | 新增:'@ | |
| 89 | 新增: $command=$command.Replace('__PARAMETERS__',$payload).Replace('__SCRIPT__',$script) | |
| 41 | 90 | $encoded=[Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($command)) |
| 42 | 91 | try{ |
| 43 | 92 | if($context){Wait-CageHostEnrollment $context $worker} |
| 44 | 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 |
| 45 | 94 | if($context){Set-CageHostEnrollmentAdmin $context $process} |
| 46 | 删除: $process.WaitForExit() | |
| 95 | 新增: Wait-CageWindowsInstaller $process $progressFile | |
| 47 | 96 | if($process.ExitCode -ne 0){throw 'Windows setup did not complete; existing VM and data were preserved.'} |
| 48 | 97 | }finally{ |
| 49 | 98 | if($context){try{Stop-CageHostEnrollment $context}catch{}} |
| 50 | 99 | if($worker){if(!$worker.WaitForExit(5000) -and [Cage.HostEnrollment.Native]::Started([uint32]$worker.Id) -eq [long]$context.WorkerStarted){$worker.Kill();$worker.WaitForExit()};$worker.Dispose()} |
| 100 | 新增: $progressHandle.Dispose() | |
| 101 | 新增: try { [IO.File]::Delete($progressFile) } catch [IO.IOException] { } | |
| 51 | 102 | } |
| 52 | 103 | return |
| 53 | 104 | } |
| @@ -100,6 +151,7 @@ if ($readyToProvision) { | ||
| 100 | 151 | if (!$vm.Count) { |
| 101 | 152 | $imageOptions = @{} |
| 102 | 153 | if ($fromHost) { $imageOptions = @{ ImageEdition=$owner.source.host.edition; ImageLanguage=$owner.source.host.language; ImageBuild=$owner.source.build; GuestAdministrator=$setupCredential } } |
| 154 | 新增: else { Write-Output 'CAGE_GUEST_STAGE windows-11 account' } | |
| 103 | 155 | $created=& (Join-Path $PSScriptRoot 'new-windows-guest.ps1') -Name $name -IsoPath $IsoPath -ExpectedIsoSha256 $ExpectedIsoSha256 -InstanceDirectory $instance -Confirm:$false @imageOptions |
| 104 | 156 | $vm=Hyper-V\Get-VM -Id $created.VMId |
| 105 | 157 | } elseif ($vm.Count -eq 1) { $vm=$vm[0] } |
| @@ -116,13 +168,13 @@ if ($readyToProvision) { | ||
| 116 | 168 | if ($vm.State -eq 'Off') { Hyper-V\Start-VM -VM $vm; $vm=Hyper-V\Get-VM -Id $vm.Id } |
| 117 | 169 | if ($vm.State -ne 'Running') { throw 'The private Windows guest is not running yet. Retry after its current operation.' } |
| 118 | 170 | if (!$readyToProvision -and !$fromHost) { |
| 119 | 删除: & (Join-Path ([Environment]::GetFolderPath('System')) 'vmconnect.exe') localhost $name | |
| 120 | 删除: Write-Output 'Complete Windows Setup, then continue installation in Cage and authenticate with the guest administrator.' | |
| 171 | 新增: Start-Process -FilePath (Join-Path ([Environment]::GetFolderPath('System')) 'vmconnect.exe') -ArgumentList @('localhost',$name) | |
| 172 | 新增: Write-Output 'CAGE_GUEST_STAGE windows-11 oobe' | |
| 173 | 新增: Write-Output '在虚拟机连接窗口完成 Windows 安装,用安装前设置的本地管理员登录桌面,再回 Cage 点击「已进入桌面,继续安装」。本轮 PowerShell 创建窗口会自动关闭。' | |
| 121 | 174 | return |
| 122 | 175 | } |
| 123 | 176 | $componentsReady = (Test-Path -LiteralPath (Join-Path $instance 'cage-workbench/pair/workbench-components-ready')) -and |
| 124 | 177 | (Test-Path -LiteralPath (Join-Path $instance 'cage-workbench/pair/windows-guest.json')) |
| 125 | 178 | if ($fromHost -and $setupCredential -and !$published -and !$componentsReady) { Wait-CageWindowsSetup $vm.Id $setupCredential } |
| 126 | 删除:Write-Output 'CAGE_GUEST_STAGE windows-11 tools' | |
| 127 | 179 | & (Join-Path $PSScriptRoot 'complete-windows-guest.ps1') -VMId $vm.Id -InstanceDirectory $instance -HostProfileDirectory $Profile -HostUserSID $HostUserSID -StateDirectory $state -HostEnrollment $HostEnrollment -ManifestPath $ManifestPath -ManifestSHA256 $ManifestSHA256 -GuestAdministrator $setupCredential |
| 128 | 180 | Write-Output 'CAGE_GUEST_STAGE windows-11 services' |
| @@ -1,5 +1,55 @@ | ||
| 1 | 1 | #requires -Version 5.1 |
| 2 | 2 | # Functions used only for a new private Windows guest disk. |
| 3 | 新增:function New-CageISOAnswer([pscredential]$Administrator) { | |
| 4 | 新增: if (!$Administrator -or $Administrator.UserName.Length -gt 20 -or | |
| 5 | 新增: $Administrator.UserName -match '["/\\\[\]:;|=,+*?<>@\x00-\x1f]' -or | |
| 6 | 新增: $Administrator.UserName.Trim() -cne $Administrator.UserName -or $Administrator.UserName.EndsWith('.') -or | |
| 7 | 新增: $Administrator.UserName -in @('Administrator', 'Guest', 'DefaultAccount', 'WDAGUtilityAccount', 'cagesetup') -or | |
| 8 | 新增: $Administrator.Password.Length -eq 0) { | |
| 9 | 新增: throw '请输入新的客机本地管理员名称和非空密码。用户名最多 20 个字符,请使用普通本地名称。' | |
| 10 | 新增: } | |
| 11 | 新增: $answer = [xml]@' | |
| 12 | 新增:<unattend xmlns="urn:schemas-microsoft-com:unattend" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"> | |
| 13 | 新增: <settings pass="specialize"/> | |
| 14 | 新增: <settings pass="oobeSystem"> | |
| 15 | 新增: <component name="Microsoft-Windows-Shell-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS"> | |
| 16 | 新增: <OOBE><HideOnlineAccountScreens>true</HideOnlineAccountScreens><HideWirelessSetupInOOBE>true</HideWirelessSetupInOOBE></OOBE> | |
| 17 | 新增: <UserAccounts><LocalAccounts><LocalAccount wcm:action="add"><Name/><Description>Cage ISO initial administrator</Description><Group>Administrators</Group><Password><Value/><PlainText>true</PlainText></Password></LocalAccount></LocalAccounts></UserAccounts> | |
| 18 | 新增: </component> | |
| 19 | 新增: </settings> | |
| 20 | 新增:</unattend> | |
| 21 | 新增:'@ | |
| 22 | 新增: $ns = [Xml.XmlNamespaceManager]::new($answer.NameTable) | |
| 23 | 新增: $ns.AddNamespace('u', 'urn:schemas-microsoft-com:unattend') | |
| 24 | 新增: $answer.SelectSingleNode('//u:LocalAccount/u:Name', $ns).InnerText = $Administrator.UserName | |
| 25 | 新增: $answer.SelectSingleNode('//u:LocalAccount/u:Password/u:Value', $ns).InnerText = $Administrator.GetNetworkCredential().Password | |
| 26 | 新增: return $answer | |
| 27 | 新增:} | |
| 28 | 新增: | |
| 29 | 新增:function Remove-CageISOAnswer($VM, $Session, [string]$InstanceDirectory) { | |
| 30 | 新增: Invoke-Command -Session $Session -ArgumentList $VM.Id -ScriptBlock { | |
| 31 | 新增: param($expected) | |
| 32 | 新增: if ([guid](Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters').VirtualMachineId -ne $expected) { throw 'wrong guest' } | |
| 33 | 新增: $setup = Get-ItemProperty 'HKLM:\SYSTEM\Setup' | |
| 34 | 新增: if ($setup.SystemSetupInProgress -ne 0 -or $setup.OOBEInProgress -ne 0 -or !(Test-Path 'C:\Program Files\PowerShell\7\pwsh.exe')) { | |
| 35 | 新增: throw '请在虚拟机连接窗口完成 Windows 首次设置并登录桌面,然后回 Cage 继续安装。' | |
| 36 | 新增: } | |
| 37 | 新增: foreach ($path in @('C:\Windows\Panther\Unattend.xml', 'C:\Windows\Panther\Unattend\Unattend.xml')) { | |
| 38 | 新增: if (!(Test-Path -LiteralPath $path -PathType Leaf)) { continue } | |
| 39 | 新增: try { $answer = [xml][IO.File]::ReadAllText($path) } | |
| 40 | 新增: catch { continue } # Preserve an unrecognized answer without logging its contents. | |
| 41 | 新增: $ns = [Xml.XmlNamespaceManager]::new($answer.NameTable) | |
| 42 | 新增: $ns.AddNamespace('u', 'urn:schemas-microsoft-com:unattend') | |
| 43 | 新增: if ($answer.SelectSingleNode('//u:LocalAccount[u:Description="Cage ISO initial administrator"]', $ns)) { | |
| 44 | 新增: Remove-Item -LiteralPath $path -Force | |
| 45 | 新增: } | |
| 46 | 新增: } | |
| 47 | 新增: } | |
| 48 | 新增: $answerPath = Join-Path $InstanceDirectory 'windows-guest-tools.iso' | |
| 49 | 新增: $VM | Hyper-V\Get-VMDvdDrive | Where-Object Path -eq $answerPath | Hyper-V\Remove-VMDvdDrive | |
| 50 | 新增: [IO.File]::Delete($answerPath) | |
| 51 | 新增:} | |
| 52 | 新增: | |
| 3 | 53 | function New-CageCloneAnswer([pscredential]$Administrator, [string]$Language) { |
| 4 | 54 | if (!$Administrator -or $Administrator.UserName -cne 'cagesetup' -or $Language -notmatch '^[a-zA-Z]{2,3}-[a-zA-Z0-9-]{2,12}$') { |
| 5 | 55 | throw 'The new guest setup identity or language is invalid.' |
| @@ -0,0 +1,119 @@ | ||
| 1 | 新增:#requires -Version 5.1 | |
| 2 | 新增:$ErrorActionPreference = 'Stop' | |
| 3 | 新增:. (Join-Path $PSScriptRoot 'windows-host-image.ps1') | |
| 4 | 新增:function Assert-Check([bool]$Condition, [string]$Message) { if (!$Condition) { throw $Message } } | |
| 5 | 新增:$credential = [pscredential]::new('CageAdmin', (ConvertTo-SecureString 'Test-only<&>"Account!123' -AsPlainText -Force)) | |
| 6 | 新增:$answer = New-CageISOAnswer $credential | |
| 7 | 新增:$ns = [Xml.XmlNamespaceManager]::new($answer.NameTable) | |
| 8 | 新增:$ns.AddNamespace('u', 'urn:schemas-microsoft-com:unattend') | |
| 9 | 新增:$roundtrip = [xml]$answer.OuterXml | |
| 10 | 新增:Assert-Check ($roundtrip.SelectSingleNode('//u:LocalAccount/u:Name', $ns).InnerText -ceq 'CageAdmin') 'Initial account name changed.' | |
| 11 | 新增:Assert-Check ($roundtrip.SelectSingleNode('//u:LocalAccount/u:Password/u:Value', $ns).InnerText -ceq $credential.GetNetworkCredential().Password) 'Password XML escaping changed the credential.' | |
| 12 | 新增:Assert-Check ($answer.SelectSingleNode('//u:LocalAccount/u:Group', $ns).InnerText -ceq 'Administrators') 'PowerShell Direct needs the initial administrator.' | |
| 13 | 新增:foreach ($setting in @('HideOnlineAccountScreens', 'HideWirelessSetupInOOBE')) { | |
| 14 | 新增: Assert-Check ($answer.SelectSingleNode('//u:OOBE/u:'+$setting, $ns).InnerText -ceq 'true') 'Offline OOBE settings are missing.' | |
| 15 | 新增:} | |
| 16 | 新增:Assert-Check ($answer.SelectNodes('//u:DiskConfiguration | //u:ImageInstall | //u:HideEULAPage | //u:AcceptEula | //u:ProductKey | //u:AutoLogon | //u:UILanguage | //u:SkipMachineOOBE', $ns).Count -eq 0) 'Manual ISO choices or administrator sign-in were overridden.' | |
| 17 | 新增:foreach ($name in @('Administrator', 'cagesetup', 'host\user', '[email protected]', 'abcdefghijklmnopqrstu')) { | |
| 18 | 新增: try { | |
| 19 | 新增: $null = New-CageISOAnswer ([pscredential]::new($name, $credential.Password)) | |
| 20 | 新增: throw 'Invalid account accepted' | |
| 21 | 新增: } catch { if ($_.Exception.Message -eq 'Invalid account accepted') { throw } } | |
| 22 | 新增:} | |
| 23 | 新增: | |
| 24 | 新增:# Execute the production branch which chooses the answer before creating a disk. | |
| 25 | 新增:$errors = $null | |
| 26 | 新增:$ast = [Management.Automation.Language.Parser]::ParseFile((Join-Path $PSScriptRoot 'new-windows-test-vm.ps1'), [ref]$null, [ref]$errors) | |
| 27 | 新增:Assert-Check ($errors.Count -eq 0) 'VM creation script failed to parse.' | |
| 28 | 新增:$selection = @($ast.EndBlock.Statements | Where-Object { $_.Extent.Text.StartsWith('if ($fromHost) {') })[0] | |
| 29 | 新增:Assert-Check ($null -ne $selection) 'Missing production answer selection.' | |
| 30 | 新增:$createAnswer = [scriptblock]::Create($selection.Extent.Text) | |
| 31 | 新增:$script:prompts = 0 | |
| 32 | 新增:function Get-Credential { param($UserName, $Message); $script:prompts++; return $credential } | |
| 33 | 新增:$fromHost = $false | |
| 34 | 新增:$GuestAdministrator = $null | |
| 35 | 新增:. $createAnswer | |
| 36 | 新增:Assert-Check ($script:prompts -eq 1 -and $answer.SelectNodes('//u:LocalAccount', $ns).Count -eq 1) 'The manual route did not collect an offline account.' | |
| 37 | 新增:. $createAnswer | |
| 38 | 新增:Assert-Check ($script:prompts -eq 1) 'An explicit credential prompted again.' | |
| 39 | 新增:$fromHost = $true | |
| 40 | 新增:$GuestAdministrator = [pscredential]::new('cagesetup', $credential.Password) | |
| 41 | 新增:$ImageLanguage = 'zh-CN' | |
| 42 | 新增:. $createAnswer | |
| 43 | 新增:Assert-Check ($answer.SelectSingleNode('//u:LocalAccount/u:Name', $ns).InnerText -ceq 'cagesetup') 'Clone setup account changed.' | |
| 44 | 新增:Assert-Check ($answer.SelectSingleNode('//u:UILanguage', $ns).InnerText -ceq 'zh-CN') 'Clone locale changed.' | |
| 45 | 新增: | |
| 46 | 新增:# The owner's progress reader accepts only known stages and reads the final | |
| 47 | 新增:# stage after process exit. Arbitrary child output never becomes UI content. | |
| 48 | 新增:$ast = [Management.Automation.Language.Parser]::ParseFile((Join-Path $PSScriptRoot 'setup-windows-guest.ps1'), [ref]$null, [ref]$errors) | |
| 49 | 新增:Assert-Check ($errors.Count -eq 0) 'Setup orchestration failed to parse.' | |
| 50 | 新增:$wait = $ast.Find({ param($node) $node -is [Management.Automation.Language.FunctionDefinitionAst] -and $node.Name -eq 'Wait-CageWindowsInstaller' }, $true) | |
| 51 | 新增:. ([scriptblock]::Create($wait.Extent.Text)) | |
| 52 | 新增:$progressFile = [IO.Path]::GetTempFileName() | |
| 53 | 新增:$heldProgress = [IO.File]::Open($progressFile, 'Open', 'ReadWrite', 'ReadWrite') | |
| 54 | 新增:$writer = [IO.File]::Open($progressFile, 'Open', 'Write', 'ReadWrite') | |
| 55 | 新增:try { | |
| 56 | 新增: $process = [pscustomobject]@{ Position = 0; Writer = $writer; Stages = @('CAGE_GUEST_STAGE windows-11 account', 'private diagnostic fixture', 'CAGE_GUEST_STAGE windows-11 media', 'CAGE_GUEST_STAGE windows-11 tools', 'CAGE_GUEST_STAGE windows-11 services', 'CAGE_GUEST_STAGE windows-11 oobe') } | |
| 57 | 新增: $process | Add-Member -MemberType ScriptMethod -Name WaitForExit -Value { | |
| 58 | 新增: param($Timeout) | |
| 59 | 新增: $bytes = [Text.Encoding]::UTF8.GetBytes($this.Stages[$this.Position]) | |
| 60 | 新增: $this.Writer.Position = 0 | |
| 61 | 新增: $this.Writer.SetLength(0) | |
| 62 | 新增: $this.Writer.Write($bytes, 0, $bytes.Length) | |
| 63 | 新增: $this.Writer.Flush() | |
| 64 | 新增: $this.Position++ | |
| 65 | 新增: return $this.Position -eq $this.Stages.Count | |
| 66 | 新增: } | |
| 67 | 新增: $stages = @(Wait-CageWindowsInstaller $process $progressFile) | |
| 68 | 新增: Assert-Check ($stages.Count -eq 5 -and $stages[-1] -ceq 'CAGE_GUEST_STAGE windows-11 oobe') 'Final progress or stage filtering failed.' | |
| 69 | 新增: $writer.Dispose() | |
| 70 | 新增: | |
| 71 | 新增: # Execute the exact encoded wrapper in a real child PowerShell process. | |
| 72 | 新增: # UAC itself is covered by native acceptance, while file sharing is exercised here. | |
| 73 | 新增: $wrapper = $ast.Find({ param($node) $node -is [Management.Automation.Language.AssignmentStatementAst] -and $node.Left.Extent.Text -eq '$command' -and $node.Right.Extent.Text.StartsWith("@'") }, $true) | |
| 74 | 新增: $literal = $wrapper.Right.Find({ param($node) $node -is [Management.Automation.Language.StringConstantExpressionAst] }, $true) | |
| 75 | 新增: $command = $literal.Value | |
| 76 | 新增: $fixtureScript = $progressFile+'.ps1' | |
| 77 | 新增: $stdout = $progressFile+'.stdout' | |
| 78 | 新增: $stderr = $progressFile+'.stderr' | |
| 79 | 新增: try { | |
| 80 | 新增: [IO.File]::WriteAllText($fixtureScript, "Write-Output 'CAGE_GUEST_STAGE windows-11 account'`nWrite-Output 'private diagnostic fixture'`nWrite-Output 'CAGE_GUEST_STAGE windows-11 oobe'") | |
| 81 | 新增: $payload = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes((@{ProgressFile=$progressFile}|ConvertTo-Json -Compress))) | |
| 82 | 新增: $scriptPath = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($fixtureScript)) | |
| 83 | 新增: $command = $command.Replace('__PARAMETERS__', $payload).Replace('__SCRIPT__', $scriptPath) | |
| 84 | 新增: $encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($command)) | |
| 85 | 新增: $child = Start-Process -FilePath (Get-Process -Id $PID).Path -ArgumentList @('-NoLogo','-NoProfile','-NonInteractive','-EncodedCommand',$encoded) -RedirectStandardOutput $stdout -RedirectStandardError $stderr -PassThru | |
| 86 | 新增: try { | |
| 87 | 新增: $forwarded = @(Wait-CageWindowsInstaller $child $progressFile) | |
| 88 | 新增: Assert-Check ($child.ExitCode -eq 0) ('Encoded installer wrapper failed. '+[IO.File]::ReadAllText($stderr)) | |
| 89 | 新增: Assert-Check ($forwarded[-1] -ceq 'CAGE_GUEST_STAGE windows-11 oobe') 'The actual child could not publish its final stage.' | |
| 90 | 新增: } finally { $child.Dispose() } | |
| 91 | 新增: } finally { | |
| 92 | 新增: foreach ($path in @($fixtureScript,$stdout,$stderr)) { [IO.File]::Delete($path) } | |
| 93 | 新增: } | |
| 94 | 新增:} finally { $writer.Dispose(); $heldProgress.Dispose(); [IO.File]::Delete($progressFile) } | |
| 95 | 新增: | |
| 96 | 新增:# An interrupted or unauthenticated guest retains its answer media. Successful | |
| 97 | 新增:# cleanup only removes the fixed tools ISO and preserves the original disk. | |
| 98 | 新增:$directory = Join-Path ([IO.Path]::GetTempPath()) ('cage-iso-answer-'+[guid]::NewGuid().ToString('N')) | |
| 99 | 新增:$null = [IO.Directory]::CreateDirectory($directory) | |
| 100 | 新增:try { | |
| 101 | 新增: $iso = Join-Path $directory 'windows-guest-tools.iso' | |
| 102 | 新增: $disk = Join-Path $directory 'system.vhdx' | |
| 103 | 新增: [IO.File]::WriteAllText($iso, 'private answer fixture') | |
| 104 | 新增: [IO.File]::WriteAllText($disk, 'existing personal disk fixture') | |
| 105 | 新增: $vm = [pscustomobject]@{ Id = [guid]::NewGuid() } | |
| 106 | 新增: $script:guestReady = $false | |
| 107 | 新增: $script:removedDVDs = @() | |
| 108 | 新增: function Invoke-Command { param($Session, $ArgumentList, $ScriptBlock); if (!$script:guestReady) { throw 'Guest setup incomplete' } } | |
| 109 | 新增: function Hyper-V\Get-VMDvdDrive { process { @([pscustomobject]@{Path=$iso}, [pscustomobject]@{Path='original-windows.iso'}) } } | |
| 110 | 新增: function Hyper-V\Remove-VMDvdDrive { process { $script:removedDVDs += $_.Path } } | |
| 111 | 新增: try { Remove-CageISOAnswer $vm 'session' $directory; throw 'Incomplete setup was accepted' } | |
| 112 | 新增: catch { if ($_.Exception.Message -cne 'Guest setup incomplete') { throw } } | |
| 113 | 新增: Assert-Check ((Test-Path -LiteralPath $iso) -and $script:removedDVDs.Count -eq 0) 'Unfinished setup lost its answer media.' | |
| 114 | 新增: $script:guestReady = $true | |
| 115 | 新增: Remove-CageISOAnswer $vm 'session' $directory | |
| 116 | 新增: Assert-Check (!(Test-Path -LiteralPath $iso) -and $script:removedDVDs.Count -eq 1 -and $script:removedDVDs[0] -eq $iso) 'Cleanup touched the wrong DVD.' | |
| 117 | 新增: Assert-Check ([IO.File]::ReadAllText($disk) -ceq 'existing personal disk fixture') 'Cleanup changed the retained disk.' | |
| 118 | 新增:} finally { [IO.Directory]::Delete($directory, $true) } | |
| 119 | 新增:Write-Output 'Passed manual ISO account/OOBE XML, retained manual choices, clone parity and elevated installer progress forwarding.' | |
| @@ -94,3 +94,46 @@ try { | ||
| 94 | 94 | console.log("PASS: native image bytes, percent, measured rate, refresh, separate verification, install stage, 375px layout and native retry."); |
| 95 | 95 | } finally {await browser.close();} |
| 96 | 96 | } |
| 97 | 新增: | |
| 98 | 新增:{ | |
| 99 | 新增: const { browser, page, state, errors } = await createWorkbench({ | |
| 100 | 新增: initialization: { required: true, tracked: true, started: true }, | |
| 101 | 新增: clientContext: { mode: "local", connection_id: "local", client_platform: "windows", server_platform: "windows" }, | |
| 102 | 新增: beforeNavigate: async (page, state) => { | |
| 103 | 新增: state.status.job = { id: "windows-install", kind: "guest-install", running: false, | |
| 104 | 新增: setup_progress: { system: "windows-11", phase: "packages", operation: "oobe", label: "请在虚拟机连接窗口完成 Windows 首次设置" } }; | |
| 105 | 新增: }, | |
| 106 | 新增: }); | |
| 107 | 新增: try { | |
| 108 | 新增: const panel = page.getByRole("region", { name: "环境安装进度" }); | |
| 109 | 新增: await panel.getByText(/虚拟机连接(VMConnect)窗口/).waitFor(); | |
| 110 | 新增: assert.equal(await panel.getByRole("progressbar").count(), 0); | |
| 111 | 新增: assert.equal(await panel.getByRole("button", { name: "停止安装" }).count(), 0); | |
| 112 | 新增: await page.reload(); | |
| 113 | 新增: const resume = panel.getByRole("button", { name: "已进入桌面,继续安装" }); | |
| 114 | 新增: await resume.waitFor(); | |
| 115 | 新增: let submitted; | |
| 116 | 新增: await page.route("**/api/start", route => { | |
| 117 | 新增: submitted = route.request().postDataJSON(); | |
| 118 | 新增: state.status.job = { ...state.status.job, running: true, | |
| 119 | 新增: setup_progress: { system: "windows-11", phase: "packages", operation: "credentials", label: "请在安装窗口输入客机管理员账户" } }; | |
| 120 | 新增: return route.fulfill({ json: state.status.job }); | |
| 121 | 新增: }); | |
| 122 | 新增: await resume.click(); | |
| 123 | 新增: await panel.getByText(/请保持该窗口开启/).waitFor(); | |
| 124 | 新增: assert.equal(submitted.guest_system, "windows-11"); | |
| 125 | 新增: assert.equal(await resume.count(), 0); | |
| 126 | 新增: for (const [operation, phase, label] of [["media", "image", "正在下载并校验客机开发组件"], ["tools", "tools", "正在安装客机应用和开发工具"], ["services", "services", "正在完成客机配置"]]) { | |
| 127 | 新增: state.status.job.setup_progress = { system: "windows-11", phase, operation, label }; | |
| 128 | 新增: await panel.getByRole("heading", { name: label }).waitFor(); | |
| 129 | 新增: await panel.getByText(/请保持 PowerShell 安装窗口开启/).waitFor(); | |
| 130 | 新增: } | |
| 131 | 新增: await page.setViewportSize({ width: 600, height: 650 }); | |
| 132 | 新增: assert.equal(await page.evaluate(() => document.documentElement.scrollWidth > innerWidth), false); | |
| 133 | 新增: if (process.env.CAGE_SETUP_WINDOWS_SCREENSHOT) await page.screenshot({ path: process.env.CAGE_SETUP_WINDOWS_SCREENSHOT, animations: "disabled" }); | |
| 134 | 新增: state.status.job.setup_progress = { system: "macos", phase: "tools", label: "正在安装客机应用和开发工具" }; | |
| 135 | 新增: await panel.getByText(/请保持 PowerShell 安装窗口开启/).waitFor({ state: "hidden" }); | |
| 136 | 新增: assert.deepEqual(errors, []); | |
| 137 | 新增: console.log("PASS: Windows OOBE resume, refresh, guest credentials, component phases and platform-specific guidance."); | |
| 138 | 新增: } finally { await browser.close(); } | |
| 139 | 新增:} | |
| @@ -114,7 +114,7 @@ export function GuestSystemPicker({ system, onChange, preserveOnUnmount = false, | ||
| 114 | 114 | </div>} |
| 115 | 115 | <small>客机账户和独立密码由 Cage 自动准备并加密保管,启动时自动登录。</small> |
| 116 | 116 | </> : <> |
| 117 | 删除: <small>Windows 11 x64 需要 Hyper-V 和至少 64 GiB 可用磁盘空间。宿主安装开发组件时需要同一 Windows 账户的管理员权限。完成 Windows 安装后,通过客机管理员确认一次,Cage 会创建专用普通账户并重启客机。</small> | |
| 117 | 新增: <small>Windows 11 x64 需要 Hyper-V 和至少 64 GiB 可用磁盘空间。安装前在授权窗口设置客机本地管理员,Cage 会生成离线账户应答。进入客机桌面后回 Cage 继续,使用该账户确认组件安装。Cage 随后创建专用普通账户并重启客机。</small> | |
| 118 | 118 | {!system.pending && <div> |
| 119 | 119 | <button type="button" onClick={() => reference("windows-media")}>从微软下载 ISO</button> |
| 120 | 120 | <button type="button" onClick={choose}>选择本机 ISO</button> |
| @@ -20,12 +20,15 @@ function bytes(value) { | ||
| 20 | 20 | export function SetupProgress({ job, onDetails, onStop, onRetry, disconnected }) { |
| 21 | 21 | const { phase, label, received, total, bytes_per_second, operation } = job.setup_progress; |
| 22 | 22 | const native = job.kind === "guest-install"; |
| 23 | 新增: const windows = native && job.setup_progress.system === "windows-11"; | |
| 23 | 24 | const stage = stages.find(([key]) => key === phase); |
| 24 | 25 | const Icon = stage?.[2] || Box; |
| 25 | 26 | const hasBytes = Number.isFinite(received) && received >= 0; |
| 26 | 27 | const knownSize = hasBytes && Number.isFinite(total) && total > 0 && received <= total; |
| 27 | 28 | const percent = knownSize ? Math.floor(received / total * 100) : null; |
| 28 | 29 | const failed = Boolean(job.error); |
| 30 | 新增: const waitingForWindows = windows && operation === "oobe"; | |
| 31 | 新增: const canContinue = failed || (waitingForWindows && !job.running); | |
| 29 | 32 | const meter = knownSize ? `${bytes(received)} / ${bytes(total)}` : hasBytes ? `已接收 ${bytes(received)}` : ""; |
| 30 | 33 | return <section className={`setup-progress${failed ? " setup-progress-failed" : ""}`} aria-label="环境安装进度"> |
| 31 | 34 | <ol className="setup-stages" aria-label="安装阶段"> |
| @@ -41,12 +44,16 @@ export function SetupProgress({ job, onDetails, onStop, onRetry, disconnected }) | ||
| 41 | 44 | </div> |
| 42 | 45 | {knownSize && <strong className="setup-transfer-number">{percent}<small>%</small></strong>} |
| 43 | 46 | </div> |
| 44 | 删除: {!failed && <div role="progressbar" aria-label={label || stage?.[1] || "当前操作"} | |
| 47 | 新增: {!failed && !waitingForWindows && <div role="progressbar" aria-label={label || stage?.[1] || "当前操作"} | |
| 45 | 48 | aria-valuemin={0} aria-valuemax={100} aria-valuenow={percent ?? undefined} |
| 46 | 49 | aria-valuetext={knownSize ? `${percent}%,${meter}` : meter || undefined} |
| 47 | 50 | className={knownSize ? "setup-meter" : "setup-meter setup-meter-active"}> |
| 48 | 51 | <span style={knownSize ? { width: `${received / total * 100}%` } : undefined} /> |
| 49 | 52 | </div>} |
| 53 | 新增: {windows && operation === "account" && <p className="setup-transfer-hint">为虚拟 Windows 设置新的本地管理员名称和密码。安装后用此账户登录客机,并在继续安装时再次输入。</p>} | |
| 54 | 新增: {waitingForWindows && <p className="setup-transfer-hint">在虚拟机连接(VMConnect)窗口选择 Windows 版本、磁盘和区域,使用安装前设置的本地管理员登录桌面,再回到 Cage 继续。本轮 PowerShell 创建窗口会自动关闭。</p>} | |
| 55 | 新增: {windows && operation === "credentials" && <p className="setup-transfer-hint">确认客机已登录桌面,在 PowerShell 安装窗口输入客机管理员账户。请保持该窗口开启,等待组件安装结束。</p>} | |
| 56 | 新增: {windows && ["media", "tools", "services"].includes(operation) && <p className="setup-transfer-hint">请保持 PowerShell 安装窗口开启,Cage 完成组件安装后会自动关闭。</p>} | |
| 50 | 57 | {failed && <> |
| 51 | 58 | <p className="setup-transfer-error" role="alert"><SafetyMessage message={job.error} /></p> |
| 52 | 59 | <p className="setup-transfer-hint">可手动继续安装,已保存的下载会尝试续传。</p> |
| @@ -54,8 +61,8 @@ export function SetupProgress({ job, onDetails, onStop, onRetry, disconnected }) | ||
| 54 | 61 | </div> |
| 55 | 62 | <div className="setup-transfer-actions"> |
| 56 | 63 | <button className="text-button" type="button" onClick={onDetails}>操作详情</button> |
| 57 | 删除: {failed | |
| 58 | 删除: ? <button type="button" className="primary" onClick={onRetry} disabled={disconnected}>继续安装</button> | |
| 64 | 新增: {canContinue | |
| 65 | 新增: ? <button type="button" className="primary" onClick={onRetry} disabled={disconnected}>{waitingForWindows && !failed ? "已进入桌面,继续安装" : "继续安装"}</button> | |
| 59 | 66 | : <button type="button" onClick={onStop} disabled={disconnected}>停止安装</button>} |
| 60 | 67 | </div> |
| 61 | 68 | </section>; |

