Evan's Blog
EvanZhu0721 / 公开仓库

SBMS

镜像已同步

SBMS complete the calculation rules for the default logical desktop topology relationship and the physical dimensions of the displays in the Windows multi-screen collaboration system.

上游 GitHub
READ-ONLY MIRROR

README、源码与 Release 已保存到本站;源码视图固定到 commit bd87fa1e。

main/ root / installer/tests
bd87fa1e· 固定源码快照
installer/tests/maintenance-compensation.Tests.ps15.3 KB
1$ErrorActionPreference = 'Stop'
2Set-StrictMode -Version Latest
3
4$maintenanceScript = [IO.Path]::GetFullPath(
5 (Join-Path $PSScriptRoot '..\maintenance.ps1')
6)
7
8Describe 'Install and uninstall compensation contracts' {
9 BeforeAll {
10 $loadRoot = Join-Path $TestDrive 'load-root'
11 New-Item -ItemType Directory -Path $loadRoot -Force | Out-Null
12
13 # Load the real orchestration functions without running the dispatcher.
14 $maintenanceSource = [IO.File]::ReadAllText(
15 $maintenanceScript,
16 [Text.Encoding]::UTF8
17 )
18 $dispatchMarker = 'switch ($Action) {'
19 $dispatchIndex = $maintenanceSource.LastIndexOf(
20 $dispatchMarker,
21 [StringComparison]::Ordinal
22 )
23 if ($dispatchIndex -lt 0) {
24 throw 'maintenance.ps1 action dispatcher was not found.'
25 }
26 $definitions = $maintenanceSource.Substring(0, $dispatchIndex)
27 . ([scriptblock]::Create($definitions)) `
28 -Action Stop `
29 -InstallRoot $loadRoot
30 }
31
32 BeforeEach {
33 $script:events = New-Object System.Collections.ArrayList
34 $script:driverScan = 0
35
36 Mock Assert-InstallIdentity {
37 [pscustomobject]@{ Sid = 'S-1-5-21-test' }
38 }
39 Mock Get-OwnedTaskSnapshots {
40 @(
41 [pscustomobject]@{
42 Path = '\SBMS\'
43 Name = 'old-task'
44 Xml = '<Task />'
45 WasRunning = $true
46 }
47 )
48 }
49 Mock Remove-SbmsTask {
50 [void]$script:events.Add('remove-task')
51 }
52 Mock Find-SbmsDriverPackages {
53 $script:driverScan++
54 if ($script:driverScan -eq 1) {
55 [IO.FileInfo]'C:\Windows\INF\oem-old.inf'
56 }
57 else {
58 [IO.FileInfo]'C:\Windows\INF\oem-old.inf'
59 [IO.FileInfo]'C:\Windows\INF\oem-new.inf'
60 }
61 }
62 Mock Install-SbmsDriver {
63 [void]$script:events.Add('install-driver')
64 }
65 Mock Install-SbmsTask {
66 [void]$script:events.Add('install-task')
67 throw 'startup registration failed'
68 }
69 Mock Remove-DriverPackages {
70 param($Packages)
71 [void]$script:events.Add(
72 'remove-driver:' + (($Packages | ForEach-Object Name) -join ',')
73 )
74 }
75 Mock Restore-SbmsTasks {
76 [void]$script:events.Add('restore-task')
77 }
78 Mock Find-ObsoleteSbmsDriverPackages { @() }
79 }
80
81 It 'removes only newly added drivers and restores the previous task after install failure' {
82 $caught = $null
83 try {
84 Install-Sbms
85 }
86 catch {
87 $caught = $_
88 }
89
90 $caught | Should Not BeNullOrEmpty
91 $caught.Exception.Message | Should Be 'startup registration failed'
92 ($script:events -join '|') | Should Be (
93 'remove-task|install-driver|install-task|remove-task|' +
94 'remove-driver:oem-new.inf|restore-task'
95 )
96 Assert-MockCalled Remove-DriverPackages -Times 1 -Exactly
97 Assert-MockCalled Restore-SbmsTasks -Times 1 -Exactly
98 }
99
100 It 'reports both failures when install task restoration also fails' {
101 Mock Restore-SbmsTasks {
102 throw 'task restore failed'
103 }
104
105 $caught = $null
106 try {
107 Install-Sbms
108 }
109 catch {
110 $caught = $_
111 }
112
113 $caught | Should Not BeNullOrEmpty
114 $caught.Exception.Message |
115 Should Match 'startup registration failed.*Startup-task compensation also failed.*task restore failed'
116 }
117
118 It 'reinstalls the driver before restoring tasks after uninstall failure' {
119 Mock Test-UninstallPreflight {
120 [void]$script:events.Add('preflight')
121 }
122 Mock Stop-Sbms {
123 [void]$script:events.Add('stop')
124 }
125 Mock Remove-SbmsDriver {
126 [void]$script:events.Add('remove-driver')
127 throw 'driver removal failed'
128 }
129 Mock Install-SbmsDriver {
130 [void]$script:events.Add('restore-driver')
131 }
132 Mock Restore-SbmsTasks {
133 [void]$script:events.Add('restore-task')
134 }
135
136 $caught = $null
137 try {
138 Uninstall-Sbms
139 }
140 catch {
141 $caught = $_
142 }
143
144 $caught | Should Not BeNullOrEmpty
145 $caught.Exception.Message |
146 Should Match 'driver removal failed.*External state was restored; application files were retained\.'
147 ($script:events -join '|') | Should Be (
148 'preflight|stop|remove-task|remove-driver|' +
149 'restore-driver|restore-task'
150 )
151 }
152
153 It 'reports both failures when uninstall compensation fails' {
154 Mock Test-UninstallPreflight {}
155 Mock Stop-Sbms {}
156 Mock Remove-SbmsDriver {
157 throw 'driver removal failed'
158 }
159 Mock Install-SbmsDriver {
160 throw 'driver restore failed'
161 }
162
163 $caught = $null
164 try {
165 Uninstall-Sbms
166 }
167 catch {
168 $caught = $_
169 }
170
171 $caught | Should Not BeNullOrEmpty
172 $caught.Exception.Message |
173 Should Match 'driver removal failed.*Compensation also failed.*driver restore failed'
174 }
175}
176