跳到主要内容

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

浏览文件

provision-claude-offline-windows.tests.ps1

62 行 · 4.5 KB历史下载
1#requires -Version 5.1
2$ErrorActionPreference = 'Stop'
3$errors = $null
4$ast = [Management.Automation.Language.Parser]::ParseFile((Join-Path $PSScriptRoot 'provision-claude-offline-windows.ps1'), [ref]$null, [ref]$errors)
5if ($errors.Count) { throw $errors[0] }
6foreach ($f in $ast.FindAll({param($n) $n -is [Management.Automation.Language.FunctionDefinitionAst]},$false)) {
7 . ([scriptblock]::Create($f.Extent.Text))
8}
9function Reject([scriptblock]$operation, [string]$reason) {
10 try { $null = & $operation } catch { if ($_.Exception.Message.Contains($reason)) { return }; throw }
11 throw "Expected rejection: $reason"
12}
13$root = [IO.Path]::GetTempPath().TrimEnd([IO.Path]::DirectorySeparatorChar)
14$diskFile = Join-Path $root 'system.vhdx'
15$id = [guid]::NewGuid()
16$vm = [pscustomobject]@{Id=$id; State='Off'; Generation=2; ConfigurationLocation=$root}
17$receipt = [pscustomobject]@{VMId=$id; Edition='EnterpriseEval'; Disk=$diskFile; InstanceDirectory=$root}
18$drive = @([pscustomobject]@{Path=$diskFile})
19$vhd = [pscustomobject]@{Path=$diskFile; VhdFormat='VHDX'; VhdType='Dynamic'; ParentPath=$null; Attached=$false; DiskNumber=17}
20Assert-CageOfflineTarget $vm $drive @() $vhd $receipt $root $id
21Reject { Assert-CageOfflineTarget $vm $drive @() $vhd $receipt $root ([guid]::NewGuid()) } 'do not match'
22Reject { Assert-CageOfflineTarget $vm $drive @('checkpoint') $vhd $receipt $root $id } 'standalone'
23$vm.State='Running'; Reject { Assert-CageOfflineTarget $vm $drive @() $vhd $receipt $root $id } 'stopped'
24$vm.State='Off'; $vhd.ParentPath='parent'; Reject { Assert-CageOfflineTarget $vm $drive @() $vhd $receipt $root $id } 'standalone'
25$vhd.ParentPath=$null; $vhd.Attached=$true; Reject { Assert-CageOfflineTarget $vm $drive @() $vhd $receipt $root $id } 'unattached'
26$disk = [pscustomobject]@{Number=17; IsBoot=$false; IsSystem=$false; IsOffline=$false; IsReadOnly=$false; PartitionStyle='GPT'}
27Assert-MountedGuestDisk $disk $vhd $diskFile
28foreach ($property in @('IsBoot','IsSystem','IsOffline','IsReadOnly')) {
29 $disk.$property=$true; Reject { Assert-MountedGuestDisk $disk $vhd $diskFile } 'guest GPT disk'; $disk.$property=$false
30}
31$vhd.DiskNumber=99; Reject { Assert-MountedGuestDisk $disk $vhd $diskFile } 'guest GPT disk'
32$vhd.DiskNumber=17; Reject { Assert-MountedGuestDisk $disk $vhd 'unrelated.vhdx' } 'guest GPT disk'
33$part = [pscustomobject]@{GptType='{EBD0A0A2-B9E5-4433-87C0-68B6B72699C7}';DiskNumber=17;PartitionNumber=3;IsBoot=$false;IsSystem=$false}
34$recovery = [pscustomobject]@{GptType='{DE94BBA4-06D1-4D40-A16A-BFD50179D6AC}';DiskNumber=17;PartitionNumber=4;IsBoot=$false;IsSystem=$false}
35if ((Select-GuestWindowsPartition @($part,$recovery) 17).PartitionNumber -ne 3) { throw 'Wrong guest partition' }
36Reject { Select-GuestWindowsPartition @($part,$part) 17 } 'exactly one'
37Reject { Select-GuestWindowsPartition @($part) 5 } 'exactly one'
38
39$script:expectedImage = Join-Path $root 'isolated-guest-mount'
40$script:fullName = 'Claude_4.23118.0.0_x64__pzs8sxrjxfjjc'
41$script:provisioned = @()
42$script:writes=0
43$image = @{Path=$script:expectedImage; ScratchDirectory=(Join-Path $root 'qa-scratch'); LogPath=(Join-Path $root 'qa.log'); ErrorAction='Stop'}
44function Get-AppxProvisionedPackage {
45 param($Path,$ScratchDirectory,$LogPath,$ErrorAction,[switch]$Online)
46 if ($Path -ne $script:expectedImage -or $Online -or !$ScratchDirectory -or !$LogPath) { throw 'Incorrect DISM target' }
47 $script:provisioned
48}
49function Add-AppxProvisionedPackage {
50 param($Path,$PackagePath,[switch]$SkipLicense,$Regions,$ScratchDirectory,$LogPath,$ErrorAction,[switch]$Online)
51 if ($Path -ne $script:expectedImage -or $Online -or $Regions -ne 'all' -or !$ScratchDirectory -or !$LogPath) { throw 'Incorrect DISM write target' }
52 $script:writes++
53 if ($PackagePath -eq 'fixture.msix') { $script:provisioned=@([pscustomobject]@{DisplayName='Claude';PackageName=$script:fullName}) }
54}
55Reject { Install-OfflineClaude $image 'missing-readback.msix' $script:fullName } 'did not list'
56$first=Install-OfflineClaude $image 'fixture.msix' $script:fullName
57$second=Install-OfflineClaude $image 'fixture.msix' $script:fullName
58if ($first.AlreadyProvisioned -or !$second.AlreadyProvisioned -or $script:writes -ne 2) { throw 'Unexpected repeat provision' }
59$script:provisioned[0].PackageName='Claude_wrong_publisher'
60Reject { Install-OfflineClaude $image 'fixture.msix' $script:fullName } 'preserved'
61if ($script:writes -ne 2) { throw 'Different package was overwritten' }
62Write-Output 'Passed offline VM, disk, partition and DISM target guards, exact readback, idempotence and foreign package preservation (simulated).'