提交记录修改desktop/windows.tests/Program.cs+37 −0看文件
修改desktop/windows/Backend.cs+30 −0看文件
修改desktop/windows/MainWindow.cs+35 −7看文件
修改internal/workbench/agent_transport_test.go+1 −1看文件
修改internal/workbench/diagnostics_guest_test.go+4 −0看文件
修改internal/workbench/macos_attachments_test.go+4 −0看文件
修改internal/workbench/macos_guest_test.go+2 −1看文件
修改scripts/ci-windows-build.ps1+13 −11看文件
修改scripts/windows-common.ps1+16 −0看文件
修改scripts/windows-workbench-smoke.test.ps1+16 −0看文件
| @@ -1,5 +1,12 @@ | ||
| 1 | 1 | using Cage.Windows; |
| 2 | 2 | |
| 3 | 新增:if (args is ["smoke-wait", var smokeRelease]) | |
| 4 | 新增:{ | |
| 5 | 新增: using var deadline = new CancellationTokenSource(TimeSpan.FromSeconds(10)); | |
| 6 | 新增: while (!File.Exists(smokeRelease)) await Task.Delay(20, deadline.Token); | |
| 7 | 新增: return; | |
| 8 | 新增:} | |
| 9 | 新增: | |
| 3 | 10 | if (args is ["app-update", "check" or "download"]) |
| 4 | 11 | { |
| 5 | 12 | File.AppendAllText(Path.Combine(Backend.Root, "retry-invocations"), "x"); |
| @@ -175,6 +182,36 @@ try | ||
| 175 | 182 | var executable = Path.Combine(nativeResources, "cage.exe"); |
| 176 | 183 | File.Copy(Environment.ProcessPath!, executable, true); |
| 177 | 184 | if (!OperatingSystem.IsWindows()) File.SetUnixFileMode(executable, File.GetUnixFileMode(Environment.ProcessPath!)); |
| 185 | 新增: var release = Path.Combine(integration, "smoke-release"); | |
| 186 | 新增: using (var owned = System.Diagnostics.Process.Start(Backend.StartInfo(executable, "smoke-wait", release))!) | |
| 187 | 新增: { | |
| 188 | 新增: var record = Path.Combine(Backend.Root, "control.json"); | |
| 189 | 新增: Directory.CreateDirectory(Backend.Root); | |
| 190 | 新增: var controllers = new List<System.Diagnostics.Process>(); | |
| 191 | 新增: try | |
| 192 | 新增: { | |
| 193 | 新增: File.WriteAllText(record, System.Text.Json.JsonSerializer.Serialize(new { pid = Environment.ProcessId })); | |
| 194 | 新增: var foreignRejected = false; | |
| 195 | 新增: try { Backend.CaptureSmokeControllers(); } catch (IOException) { foreignRejected = true; } | |
| 196 | 新增: Check(foreignRejected, "smoke captured a controller outside its application executable"); | |
| 197 | 新增: File.WriteAllText(record, System.Text.Json.JsonSerializer.Serialize(new { pid = owned.Id })); | |
| 198 | 新增: controllers = Backend.CaptureSmokeControllers(); | |
| 199 | 新增: Check(controllers.Count == 1 && !controllers[0].HasExited, "smoke did not pin its live controller"); | |
| 200 | 新增: var exit = controllers[0].WaitForExitAsync(); | |
| 201 | 新增: Check(!exit.IsCompleted, "smoke considered a still-running controller stopped"); | |
| 202 | 新增: File.WriteAllText(release, "release owned child"); | |
| 203 | 新增: await exit.WaitAsync(TimeSpan.FromSeconds(5)); | |
| 204 | 新增: Check(controllers[0].HasExited, "smoke did not observe actual controller exit"); | |
| 205 | 新增: } | |
| 206 | 新增: finally | |
| 207 | 新增: { | |
| 208 | 新增: File.WriteAllText(release, "release owned child"); | |
| 209 | 新增: if (!owned.WaitForExit(5000)) { owned.Kill(); owned.WaitForExit(); } | |
| 210 | 新增: foreach (var controller in controllers) controller.Dispose(); | |
| 211 | 新增: File.Delete(record); | |
| 212 | 新增: } | |
| 213 | 新增: } | |
| 214 | 新增: Console.WriteLine("Windows smoke shutdown: actual controller handle pinned, foreign executable rejected, process exit observed."); | |
| 178 | 215 | var retryAt = DateTimeOffset.UtcNow.AddHours(1).ToString("yyyy-MM-dd'T'HH:mm:ss'Z'"); |
| 179 | 216 | Directory.CreateDirectory(Backend.Root); |
| 180 | 217 | Environment.SetEnvironmentVariable("CAGE_UPDATE_RETRY_AT", retryAt); |
| @@ -13,6 +13,36 @@ internal static class Backend | ||
| 13 | 13 | public static string Root => Path.GetDirectoryName(ConfigPath)!; |
| 14 | 14 | public static string Executable => Path.Combine(AppContext.BaseDirectory, "resources", "cage.exe"); |
| 15 | 15 | |
| 16 | 新增: public static List<Process> CaptureSmokeControllers() | |
| 17 | 新增: { | |
| 18 | 新增: var processes = new List<Process>(); | |
| 19 | 新增: try | |
| 20 | 新增: { | |
| 21 | 新增: foreach (var profile in new[] { Root, Path.Combine(Root, "desktop-entry") }) | |
| 22 | 新增: { | |
| 23 | 新增: var record = Path.Combine(profile, "control.json"); | |
| 24 | 新增: if (!File.Exists(record)) continue; | |
| 25 | 新增: using var data = JsonDocument.Parse(File.ReadAllText(record)); | |
| 26 | 新增: Process process; | |
| 27 | 新增: try { process = Process.GetProcessById(data.RootElement.GetProperty("pid").GetInt32()); } | |
| 28 | 新增: catch (ArgumentException) { continue; } // It already exited. | |
| 29 | 新增: try | |
| 30 | 新增: { | |
| 31 | 新增: // Pin the actual process handle before requesting shutdown. | |
| 32 | 新增: // A released profile lock alone does not release its image. | |
| 33 | 新增: _ = process.SafeHandle; | |
| 34 | 新增: if (process.HasExited) { process.Dispose(); continue; } | |
| 35 | 新增: if (!string.Equals(Path.GetFullPath(process.MainModule!.FileName), Path.GetFullPath(Executable), StringComparison.OrdinalIgnoreCase)) | |
| 36 | 新增: throw new IOException("自检后台身份与当前应用不符,未等待其他程序"); | |
| 37 | 新增: processes.Add(process); | |
| 38 | 新增: } | |
| 39 | 新增: catch { process.Dispose(); throw; } | |
| 40 | 新增: } | |
| 41 | 新增: return processes; | |
| 42 | 新增: } | |
| 43 | 新增: catch { foreach (var process in processes) process.Dispose(); throw; } | |
| 44 | 新增: } | |
| 45 | 新增: | |
| 16 | 46 | public static ProcessStartInfo StartInfo(string executable, params string[] arguments) |
| 17 | 47 | { |
| 18 | 48 | var start = new ProcessStartInfo(executable) { |
| @@ -143,7 +143,7 @@ internal sealed class MainWindow : Form | ||
| 143 | 143 | } |
| 144 | 144 | private async void Script(string script) |
| 145 | 145 | { |
| 146 | 删除: if (web.CoreWebView2 == null || IsDisposed) return; | |
| 146 | 新增: if (web.IsDisposed || web.CoreWebView2 == null || IsDisposed) return; | |
| 147 | 147 | try { await web.ExecuteScriptAsync(script); } |
| 148 | 148 | catch (InvalidOperationException) { } |
| 149 | 149 | catch (System.Runtime.InteropServices.COMException) { } |
| @@ -217,6 +217,11 @@ internal sealed class MainWindow : Form | ||
| 217 | 217 | if (Program.SmokeOutput == null || completingSmoke) return; |
| 218 | 218 | completingSmoke = true; |
| 219 | 219 | JsonElement? page = null; |
| 220 | 新增: var pageURL = web.Source?.GetLeftPart(UriPartial.Path); | |
| 221 | 新增: var environment = web.CoreWebView2?.Environment; | |
| 222 | 新增: var webviewVersion = environment?.BrowserVersionString; | |
| 223 | 新增: using var shutdown = CancellationTokenSource.CreateLinkedTokenSource(lifetime.Token); | |
| 224 | 新增: shutdown.CancelAfter(TimeSpan.FromSeconds(20)); | |
| 220 | 225 | var errors = new List<string>(); |
| 221 | 226 | if (failure != null) errors.Add(failure); |
| 222 | 227 | try |
| @@ -232,17 +237,40 @@ internal sealed class MainWindow : Form | ||
| 232 | 237 | } |
| 233 | 238 | catch (Exception error) { errors.Add("无法保存工作台画面:" + error.Message); } |
| 234 | 239 | } |
| 235 | 删除: var (exit, data) = await Backend.Json(["prepare-update", "--json"], lifetime.Token, TimeSpan.FromSeconds(20)); | |
| 236 | 删除: if (exit != 0 || data.Text("status") != "prepared") throw new IOException("自检结束时无法确认后台已停止"); | |
| 240 | 新增: var controllers = Backend.CaptureSmokeControllers(); | |
| 241 | 新增: try | |
| 242 | 新增: { | |
| 243 | 新增: if (nativeBridgeReady) smokePhase = "stopping_backend"; | |
| 244 | 新增: var (exit, data) = await Backend.Json(["prepare-update", "--json"], shutdown.Token, TimeSpan.FromSeconds(20)); | |
| 245 | 新增: if (exit != 0 || data.Text("status") != "prepared") throw new IOException("自检结束时无法确认后台已停止"); | |
| 246 | 新增: await Task.WhenAll(controllers.Select(process => process.WaitForExitAsync(shutdown.Token))); | |
| 247 | 新增: } | |
| 248 | 新增: finally { foreach (var process in controllers) process.Dispose(); } | |
| 237 | 249 | } |
| 238 | 250 | catch (Exception error) { errors.Add(error.Message); } |
| 251 | 新增: // WebView2 releases its processes asynchronously after Dispose. Its | |
| 252 | 新增: // browser can retain the app's working directory until this event. | |
| 253 | 新增: if (environment != null) | |
| 254 | 新增: { | |
| 255 | 新增: var exited = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); | |
| 256 | 新增: void BrowserExited(object? sender, CoreWebView2BrowserProcessExitedEventArgs args) => exited.TrySetResult(); | |
| 257 | 新增: environment.BrowserProcessExited += BrowserExited; | |
| 258 | 新增: try | |
| 259 | 新增: { | |
| 260 | 新增: if (nativeBridgeReady) smokePhase = "stopping_browser"; | |
| 261 | 新增: web.Dispose(); | |
| 262 | 新增: await exited.Task.WaitAsync(shutdown.Token); | |
| 263 | 新增: } | |
| 264 | 新增: catch (Exception error) { errors.Add("自检浏览器尚未退出:" + error.Message); } | |
| 265 | 新增: finally { environment.BrowserProcessExited -= BrowserExited; } | |
| 266 | 新增: } | |
| 239 | 267 | try |
| 240 | 268 | { |
| 269 | 新增: if (nativeBridgeReady && errors.Count == 0) smokePhase = "completed"; | |
| 241 | 270 | File.WriteAllText(Program.SmokeOutput, JsonSerializer.Serialize(new { |
| 242 | 271 | success = nativeBridgeReady && errors.Count == 0, nativeBridgeReady, version = AppUpdater.Version, |
| 243 | 272 | phase = smokePhase, nativeStatus = message.Text, errors, page, |
| 244 | 删除: pageURL = web.Source?.GetLeftPart(UriPartial.Path), | |
| 245 | 删除: webviewVersion = web.CoreWebView2?.Environment.BrowserVersionString, | |
| 273 | 新增: pageURL, webviewVersion, | |
| 246 | 274 | windowBounds = Bounds, workingArea = Screen.FromHandle(Handle).WorkingArea, deviceDpi = DeviceDpi, |
| 247 | 275 | nativeMenuBar = MainMenuStrip != null, |
| 248 | 276 | })); |
| @@ -480,12 +508,12 @@ internal sealed class MainWindow : Form | ||
| 480 | 508 | case "quitNow": result = true; allowQuit = true; BeginInvoke(Close); break; |
| 481 | 509 | default: throw new InvalidDataException("未知原生操作"); |
| 482 | 510 | } |
| 483 | 删除: web.CoreWebView2.PostWebMessageAsJson(JsonSerializer.Serialize(new { id, result })); | |
| 511 | 新增: if (!web.IsDisposed) web.CoreWebView2.PostWebMessageAsJson(JsonSerializer.Serialize(new { id, result })); | |
| 484 | 512 | } |
| 485 | 513 | catch (Exception error) |
| 486 | 514 | { |
| 487 | 515 | _ = Backend.Report(error.ToString()); |
| 488 | 删除: if (id.Length != 0 && !IsDisposed) web.CoreWebView2.PostWebMessageAsJson(JsonSerializer.Serialize(new { id, error = error.Message })); | |
| 516 | 新增: if (id.Length != 0 && !IsDisposed && !web.IsDisposed) web.CoreWebView2.PostWebMessageAsJson(JsonSerializer.Serialize(new { id, error = error.Message })); | |
| 489 | 517 | } |
| 490 | 518 | } |
| 491 | 519 | |
| @@ -163,7 +163,7 @@ func TestAgentDesktopConfigurationUsesExplicitSelection(t *testing.T) { | ||
| 163 | 163 | if err != nil { |
| 164 | 164 | t.Fatal(err) |
| 165 | 165 | } |
| 166 | 删除: if err := os.WriteFile(filepath.Join(filepath.Dir(path), "control.json"), record, 0600); err != nil { | |
| 166 | 新增: if err := writePrivate(filepath.Join(filepath.Dir(path), "control.json"), json.RawMessage(record)); err != nil { | |
| 167 | 167 | t.Fatal(err) |
| 168 | 168 | } |
| 169 | 169 | lock, err := openControllerLock(filepath.Dir(path), os.O_CREATE|os.O_RDWR) |
| @@ -6,12 +6,16 @@ import ( | ||
| 6 | 6 | "os" |
| 7 | 7 | "os/exec" |
| 8 | 8 | "path/filepath" |
| 9 | 新增: "runtime" | |
| 9 | 10 | "strings" |
| 10 | 11 | "testing" |
| 11 | 12 | "time" |
| 12 | 13 | ) |
| 13 | 14 | |
| 14 | 15 | func TestMacOSGuestDiagnosticCollectorBoundsAndFilters(t *testing.T) { |
| 16 | 新增: if runtime.GOOS == "windows" { | |
| 17 | 新增: t.Skip("macOS guest collector requires POSIX directory descriptors and file ownership") | |
| 18 | 新增: } | |
| 15 | 19 | if _, err := exec.LookPath("uv"); err != nil { |
| 16 | 20 | t.Skip("uv is required for the guest collector") |
| 17 | 21 | } |
| @@ -6,6 +6,7 @@ import ( | ||
| 6 | 6 | "os" |
| 7 | 7 | "os/exec" |
| 8 | 8 | "path/filepath" |
| 9 | 新增: "runtime" | |
| 9 | 10 | "strings" |
| 10 | 11 | "testing" |
| 11 | 12 | |
| @@ -28,6 +29,9 @@ func TestMacOSAttachmentPathRejectsOtherUsersAndEscapes(t *testing.T) { | ||
| 28 | 29 | } |
| 29 | 30 | |
| 30 | 31 | func TestMacOSTerminalUsesSharedAttachmentReceiver(t *testing.T) { |
| 32 | 新增: if runtime.GOOS == "windows" { | |
| 33 | 新增: t.Skip("shared macOS/Linux guest receiver requires POSIX UnixStreamServer") | |
| 34 | 新增: } | |
| 31 | 35 | if _, err := exec.LookPath("uv"); err != nil { |
| 32 | 36 | t.Skip("uv is required for the shared Python receiver") |
| 33 | 37 | } |
| @@ -9,6 +9,7 @@ import ( | ||
| 9 | 9 | "os" |
| 10 | 10 | "path/filepath" |
| 11 | 11 | "slices" |
| 12 | 新增: "strconv" | |
| 12 | 13 | "strings" |
| 13 | 14 | "testing" |
| 14 | 15 | |
| @@ -36,7 +37,7 @@ func TestMacOSConnectionIgnoresSSHConfigOverrides(t *testing.T) { | ||
| 36 | 37 | t.Errorf("untrusted override %q used", value) |
| 37 | 38 | } |
| 38 | 39 | } |
| 39 | 删除: if !strings.Contains(strings.Join(cmd.Args, " "), filepath.Join(s.profile, "macos-known-hosts")) { | |
| 40 | 新增: if !slices.Contains(cmd.Args, "UserKnownHostsFile="+strconv.Quote(filepath.Join(s.profile, "macos-known-hosts"))) { | |
| 40 | 41 | t.Fatal("missing profile-scoped host key") |
| 41 | 42 | } |
| 42 | 43 | for _, bad := range []string{"", "Port 0", "Port 65536", "Port 22\nPort 23", "Port 22 -o Anything"} { |
| @@ -66,18 +66,20 @@ try { | ||
| 66 | 66 | '-GuestToolsDirectory', "$repository/_output/windows-amd64/app/resources/guest-os") |
| 67 | 67 | } |
| 68 | 68 | Invoke-BuildTool 'dotnet' @('run', '--project', 'desktop/windows.tests/Cage.Windows.Tests.csproj') |
| 69 | 删除: Invoke-BuildTool 'go' @('test', './internal/workbench', './internal/appupdate', './internal/host', './internal/managedproxy', './internal/env', './internal/paths', './internal/mounts') | |
| 70 | 删除: # Exercise a second volume when the runner keeps its workspace and temp on different drives. | |
| 71 | 删除: if ($env:GITHUB_WORKSPACE -and -not $env:CAGE_TEST_STORAGE_VOLUME -and | |
| 72 | 删除: [IO.Path]::GetPathRoot($env:GITHUB_WORKSPACE) -ne [IO.Path]::GetPathRoot([IO.Path]::GetTempPath())) { | |
| 73 | 删除: $env:CAGE_TEST_STORAGE_VOLUME = $env:GITHUB_WORKSPACE | |
| 69 | 新增: Invoke-InIsolatedTestTemp { | |
| 70 | 新增: Invoke-BuildTool 'go' @('test', './internal/workbench', './internal/appupdate', './internal/host', './internal/managedproxy', './internal/env', './internal/paths', './internal/mounts') | |
| 71 | 新增: # Exercise a second volume when the runner keeps its workspace and temp on different drives. | |
| 72 | 新增: if ($env:GITHUB_WORKSPACE -and -not $env:CAGE_TEST_STORAGE_VOLUME -and | |
| 73 | 新增: [IO.Path]::GetPathRoot($env:GITHUB_WORKSPACE) -ne [IO.Path]::GetPathRoot([IO.Path]::GetTempPath())) { | |
| 74 | 新增: $env:CAGE_TEST_STORAGE_VOLUME = $env:GITHUB_WORKSPACE | |
| 75 | 新增: } | |
| 76 | 新增: Invoke-BuildTool 'go' @('test', './internal/cage', '-run', 'Test(Storage|Gate|ProxyRevision|ConfigChange|JobStop|CONNECT|SOCKS|DNS|RejectHostLAN|Credentials|ProxyHostname|SafetyReport|Renew)') | |
| 77 | 新增: Invoke-BuildTool 'go' @('test', './internal/vm', '-run', 'Test(NetworkConfined|WindowsQEMUIdentity)') | |
| 78 | 新增: Invoke-BuildTool 'go' @('test', 'github.com/lima-vm/lima/v2/pkg/driver/qemu', '-run', 'Test(WindowsFirmwareArgument|WindowsPackagedFirmwareBeatsOldUserCopy|WHPXQEMU64Features|WindowsCPUResolution)$') | |
| 79 | 新增: Invoke-BuildTool 'go' @('test', 'github.com/lima-vm/lima/v2/pkg/hostagent', '-run', '^TestResourceProbeCommand$') | |
| 80 | 新增: Invoke-BuildTool 'go' @('test', 'github.com/lima-vm/lima/v2/pkg/networks/usernet', '-run', 'TestNetstackWindowsNativeSocketPaths') | |
| 81 | 新增: Invoke-BuildTool 'go' @('vet', './cmd/cage', './internal/cage', './internal/workbench', './internal/appupdate', './internal/host') | |
| 74 | 82 | } |
| 75 | 删除: Invoke-BuildTool 'go' @('test', './internal/cage', '-run', 'Test(Storage|Gate|ProxyRevision|ConfigChange|JobStop|CONNECT|SOCKS|DNS|RejectHostLAN|Credentials|ProxyHostname|SafetyReport|Renew)') | |
| 76 | 删除: Invoke-BuildTool 'go' @('test', './internal/vm', '-run', 'Test(NetworkConfined|WindowsQEMUIdentity)') | |
| 77 | 删除: Invoke-BuildTool 'go' @('test', 'github.com/lima-vm/lima/v2/pkg/driver/qemu', '-run', 'Test(WindowsFirmwareArgument|WindowsPackagedFirmwareBeatsOldUserCopy|WHPXQEMU64Features|WindowsCPUResolution)$') | |
| 78 | 删除: Invoke-BuildTool 'go' @('test', 'github.com/lima-vm/lima/v2/pkg/hostagent', '-run', '^TestResourceProbeCommand$') | |
| 79 | 删除: Invoke-BuildTool 'go' @('test', 'github.com/lima-vm/lima/v2/pkg/networks/usernet', '-run', 'TestNetstackWindowsNativeSocketPaths') | |
| 80 | 删除: Invoke-BuildTool 'go' @('vet', './cmd/cage', './internal/cage', './internal/workbench', './internal/appupdate', './internal/host') | |
| 81 | 83 | $packageArguments = @{ Release = $Release; SkipBuild = $true } |
| 82 | 84 | if ($Release) { $packageArguments.QemuSourceArchive = $qemuSource } |
| 83 | 85 | & (Join-Path $PSScriptRoot 'package-windows.ps1') @packageArguments |
| @@ -14,6 +14,22 @@ function Get-WindowsWorkbenchTestBase { | ||
| 14 | 14 | return [IO.Path]::GetTempPath() |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 新增:function Invoke-InIsolatedTestTemp { | |
| 18 | 新增: param([Parameter(Mandatory)][scriptblock]$Checks) | |
| 19 | 新增: # Windows' default temp is inside AppData, which must remain protected | |
| 20 | 新增: # against project sharing. Put test projects in the runner's own temp. | |
| 21 | 新增: $directory = Join-Path (Get-WindowsWorkbenchTestBase) ('cage-go-tests-' + [guid]::NewGuid().ToString('N')) | |
| 22 | 新增: New-Item -ItemType Directory -Path $directory | Out-Null | |
| 23 | 新增: $savedTemp = $env:TEMP; $savedTmp = $env:TMP | |
| 24 | 新增: try { | |
| 25 | 新增: $env:TEMP = $directory; $env:TMP = $directory | |
| 26 | 新增: & $Checks | |
| 27 | 新增: } finally { | |
| 28 | 新增: $env:TEMP = $savedTemp; $env:TMP = $savedTmp | |
| 29 | 新增: Remove-Item -LiteralPath $directory -Recurse -Force -ErrorAction SilentlyContinue | |
| 30 | 新增: } | |
| 31 | 新增:} | |
| 32 | 新增: | |
| 17 | 33 | function ConvertTo-SmokeSafeText { |
| 18 | 34 | param($Value) |
| 19 | 35 | if ($Value -isnot [string]) { return '' } |
| @@ -7,6 +7,22 @@ function Assert-SmokeContract([bool]$Condition, [string]$Message) { if (-not $Co | ||
| 7 | 7 | try { |
| 8 | 8 | $env:RUNNER_TEMP = Join-Path $directory 'runner-temp' |
| 9 | 9 | Assert-SmokeContract ((Get-WindowsWorkbenchTestBase) -eq [IO.Path]::GetFullPath($env:RUNNER_TEMP)) 'CI report directory ignores RUNNER_TEMP.' |
| 10 | 新增: $savedTemp = $env:TEMP; $savedTmp = $env:TMP | |
| 11 | 新增: $envFile = Join-Path $directory 'child-env.json' | |
| 12 | 新增: $envScript = Join-Path $directory 'child-env.ps1' | |
| 13 | 新增: [IO.File]::WriteAllText($envScript, '@{temp=$env:TEMP;tmp=$env:TMP} | ConvertTo-Json | Set-Content -LiteralPath $args[0]') | |
| 14 | 新增: $failed = $false | |
| 15 | 新增: try { | |
| 16 | 新增: Invoke-InIsolatedTestTemp { | |
| 17 | 新增: Invoke-BuildTool (Get-Process -Id $PID).Path @('-NoProfile','-NonInteractive','-File',$envScript,$envFile) | |
| 18 | 新增: throw 'injected test failure' | |
| 19 | 新增: } | |
| 20 | 新增: } catch { $failed = $_.Exception.Message -eq 'injected test failure' } | |
| 21 | 新增: $childEnv = Get-Content -LiteralPath $envFile -Raw | ConvertFrom-Json | |
| 22 | 新增: Assert-SmokeContract $failed 'Isolated test temp swallowed its test failure.' | |
| 23 | 新增: Assert-SmokeContract ($childEnv.temp -eq $childEnv.tmp -and (Split-Path $childEnv.temp -Parent) -eq $env:RUNNER_TEMP) 'Child tests did not inherit the isolated runner temp.' | |
| 24 | 新增: Assert-SmokeContract ($env:TEMP -eq $savedTemp -and $env:TMP -eq $savedTmp) 'Failed tests changed the caller temp environment.' | |
| 25 | 新增: Assert-SmokeContract (-not (Test-Path -LiteralPath $childEnv.temp)) 'Owned test temp was not cleaned.' | |
| 10 | 26 | Remove-Item Env:RUNNER_TEMP -ErrorAction SilentlyContinue |
| 11 | 27 | Assert-SmokeContract ((Get-WindowsWorkbenchTestBase) -eq [IO.Path]::GetTempPath()) 'Local report directory lost its OS temp fallback.' |
| 12 | 28 | $report = Join-Path $directory 'smoke.json' |

