提交记录修改.github/workflows/windows-build.yml+49 −3看文件
修改desktop/windows/MainWindow.cs+71 −6看文件
修改desktop/windows/Program.cs+8 −1看文件
修改scripts/agent-cli-smoke.mjs+1 −1看文件
修改scripts/build-windows.ps1+4 −1看文件
修改scripts/ci-windows-build.ps1+4 −10看文件
修改scripts/esigner.mjs+19 −1看文件
修改scripts/esigner.test.mjs+23 −1看文件
新增scripts/prepare-qemu-release.ps1+36 −0看文件
修改scripts/windows-common.ps1+24 −1看文件
| @@ -81,7 +81,10 @@ jobs: | ||
| 81 | 81 | uses: actions/upload-artifact@v4 |
| 82 | 82 | with: |
| 83 | 83 | name: ${{ inputs.artifact_name }}-${{ matrix.os }}-reports |
| 84 | 删除: path: ${{ runner.temp }}/cage-smoke-*.json | |
| 84 | 新增: path: | | |
| 85 | 新增: ${{ runner.temp }}/cage-smoke-*.json | |
| 86 | 新增: ${{ runner.temp }}/cage-build-ui-*/smoke.json | |
| 87 | 新增: ${{ runner.temp }}/cage-build-ui-*/*.png | |
| 85 | 88 | if-no-files-found: ignore |
| 86 | 89 | overwrite: true |
| 87 | 90 | retention-days: 14 |
| @@ -125,10 +128,42 @@ jobs: | ||
| 125 | 128 | mingw-w64-ucrt-x86_64-ninja |
| 126 | 129 | mingw-w64-ucrt-x86_64-python |
| 127 | 130 | mingw-w64-ucrt-x86_64-pkgconf |
| 128 | 删除: - uses: actions/cache@v4 | |
| 131 | 新增: - uses: actions/cache/restore@v4 | |
| 132 | 新增: id: qemu_cache | |
| 129 | 133 | with: |
| 130 | 134 | path: _output/windows-deps |
| 131 | 删除: key: cage-windows-deps-${{ hashFiles('packaging/windows/dependencies.json', 'patches/qemu/**', 'scripts/build-qemu-windows.*') }} | |
| 135 | 新增: key: cage-windows-deps-${{ hashFiles('packaging/windows/dependencies.json', 'patches/qemu/**', 'scripts/build-qemu-windows.*', 'scripts/bundle-qemu-sources.sh') }} | |
| 136 | 新增: - name: Build and verify QEMU runtime and package identity | |
| 137 | 新增: id: qemu_build | |
| 138 | 新增: env: | |
| 139 | 新增: CAGE_MSYS2_ROOT: ${{ steps.msys2.outputs.msys2-location }} | |
| 140 | 新增: run: | | |
| 141 | 新增: ./scripts/build-qemu-windows.ps1 | |
| 142 | 新增: $identity = Get-Content '_output/windows-deps/qemu-cage/cage-build.json' -Raw | ConvertFrom-Json | |
| 143 | 新增: "fingerprint=$($identity.fingerprint)" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| 144 | 新增: $collectorHash = (Get-FileHash 'scripts/bundle-qemu-sources.sh' -Algorithm SHA256).Hash + (Get-FileHash 'scripts/prepare-qemu-release.ps1' -Algorithm SHA256).Hash | |
| 145 | 新增: "collector=$collectorHash" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 | |
| 146 | 新增: - name: Preserve only the completed verified runtime cache | |
| 147 | 新增: if: steps.qemu_cache.outputs.cache-hit != 'true' | |
| 148 | 新增: uses: actions/cache/save@v4 | |
| 149 | 新增: with: | |
| 150 | 新增: path: _output/windows-deps | |
| 151 | 新增: key: cage-windows-deps-${{ hashFiles('packaging/windows/dependencies.json', 'patches/qemu/**', 'scripts/build-qemu-windows.*', 'scripts/bundle-qemu-sources.sh') }} | |
| 152 | 新增: - uses: actions/cache/restore@v4 | |
| 153 | 新增: id: qemu_sources | |
| 154 | 新增: with: | |
| 155 | 新增: path: _output/windows-qemu-sources | |
| 156 | 新增: key: cage-qemu-sources-${{ steps.qemu_build.outputs.fingerprint }}-${{ steps.qemu_build.outputs.collector }} | |
| 157 | 新增: - name: Collect and verify corresponding sources before signing | |
| 158 | 新增: env: | |
| 159 | 新增: CAGE_MSYS2_ROOT: ${{ steps.msys2.outputs.msys2-location }} | |
| 160 | 新增: run: ./scripts/prepare-qemu-release.ps1 | |
| 161 | 新增: - name: Preserve only the completed verified source cache | |
| 162 | 新增: if: steps.qemu_sources.outputs.cache-hit != 'true' | |
| 163 | 新增: uses: actions/cache/save@v4 | |
| 164 | 新增: with: | |
| 165 | 新增: path: _output/windows-qemu-sources | |
| 166 | 新增: key: cage-qemu-sources-${{ steps.qemu_build.outputs.fingerprint }}-${{ steps.qemu_build.outputs.collector }} | |
| 132 | 167 | - uses: actions/setup-java@v4 |
| 133 | 168 | with: |
| 134 | 169 | distribution: temurin |
| @@ -159,4 +194,15 @@ jobs: | ||
| 159 | 194 | if-no-files-found: error |
| 160 | 195 | overwrite: true |
| 161 | 196 | retention-days: 14 |
| 197 | 新增: - name: Preserve public release acceptance reports | |
| 198 | 新增: if: always() | |
| 199 | 新增: uses: actions/upload-artifact@v4 | |
| 200 | 新增: with: | |
| 201 | 新增: name: ${{ inputs.artifact_name }}-reports | |
| 202 | 新增: path: | | |
| 203 | 新增: ${{ runner.temp }}/cage-smoke-*.json | |
| 204 | 新增: ${{ runner.temp }}/cage-build-ui-*/smoke.json | |
| 205 | 新增: ${{ runner.temp }}/cage-build-ui-*/*.png | |
| 206 | 新增: if-no-files-found: ignore | |
| 207 | 新增: retention-days: 14 | |
| 162 | 208 | # The caller owns publication. This workflow has no repository write access. |
| @@ -17,6 +17,8 @@ internal sealed class MainWindow : Form | ||
| 17 | 17 | private readonly AppUpdater updater; |
| 18 | 18 | private int expectedPort; |
| 19 | 19 | private bool controllerNeedsUpdate, allowQuit, bootstrapping, webFailed; |
| 20 | 新增: private bool completingSmoke; | |
| 21 | 新增: private string smokePhase = "starting"; | |
| 20 | 22 | private readonly CancellationTokenSource lifetime = new(); |
| 21 | 23 | private readonly Dictionary<string, (string[] Paths, DateTime Expires)> fileSelections = new(); |
| 22 | 24 | |
| @@ -154,6 +156,7 @@ internal sealed class MainWindow : Form | ||
| 154 | 156 | |
| 155 | 157 | private async Task Initialize(bool recreate = false) |
| 156 | 158 | { |
| 159 | 新增: smokePhase = "initializing_webview"; | |
| 157 | 160 | retry.Enabled = false; |
| 158 | 161 | try |
| 159 | 162 | { |
| @@ -165,6 +168,7 @@ internal sealed class MainWindow : Form | ||
| 165 | 168 | } |
| 166 | 169 | var environment = await CoreWebView2Environment.CreateAsync(null, Path.Combine(Backend.Root, "webview2")); |
| 167 | 170 | await web.EnsureCoreWebView2Async(environment); |
| 171 | 新增: smokePhase = "webview_initialized"; | |
| 168 | 172 | var core = web.CoreWebView2; |
| 169 | 173 | core.Settings.AreDevToolsEnabled = false; core.Settings.AreDefaultContextMenusEnabled = false; |
| 170 | 174 | core.Settings.IsStatusBarEnabled = false; core.Settings.IsZoomControlEnabled = false; |
| @@ -189,6 +193,7 @@ internal sealed class MainWindow : Form | ||
| 189 | 193 | status.Hide(); web.Show(); web.Focus(); PublishVisibility(); |
| 190 | 194 | }; |
| 191 | 195 | await core.AddScriptToExecuteOnDocumentCreatedAsync(BridgeScript); |
| 196 | 新增: if (Program.SmokeOutput != null) await core.AddScriptToExecuteOnDocumentCreatedAsync(SmokeDiagnosticsScript); | |
| 192 | 197 | webFailed = false; |
| 193 | 198 | await Bootstrap(); |
| 194 | 199 | } |
| @@ -203,20 +208,41 @@ internal sealed class MainWindow : Form | ||
| 203 | 208 | |
| 204 | 209 | private async Task SmokeDeadline() |
| 205 | 210 | { |
| 206 | 删除: try { await Task.Delay(TimeSpan.FromSeconds(120), lifetime.Token); allowQuit = true; Close(); } | |
| 211 | 新增: try { await Task.Delay(TimeSpan.FromSeconds(120), lifetime.Token); await CompleteSmoke(false, "工作台未在自检期限内确认就绪"); } | |
| 207 | 212 | catch (OperationCanceledException) { } |
| 208 | 213 | } |
| 209 | 214 | |
| 210 | 删除: private async Task CompleteSmoke() | |
| 215 | 新增: private async Task CompleteSmoke(bool nativeBridgeReady = true, string? failure = null) | |
| 211 | 216 | { |
| 212 | 删除: if (Program.SmokeOutput == null) return; | |
| 217 | 新增: if (Program.SmokeOutput == null || completingSmoke) return; | |
| 218 | 新增: completingSmoke = true; | |
| 219 | 新增: JsonElement? page = null; | |
| 220 | 新增: var errors = new List<string>(); | |
| 221 | 新增: if (failure != null) errors.Add(failure); | |
| 213 | 222 | try |
| 214 | 223 | { |
| 215 | 删除: var (exit, data) = await Backend.Json(["prepare-update", "--json"], lifetime.Token); | |
| 224 | 新增: if (!nativeBridgeReady && web.CoreWebView2 != null) | |
| 225 | 新增: { | |
| 226 | 新增: try | |
| 227 | 新增: { | |
| 228 | 新增: var snapshot = await web.CoreWebView2.ExecuteScriptAsync("({title:document.title,ready:document.readyState,text:(document.body?.innerText||'').slice(0,4096),errors:window.__cageSmokeErrors||[]})"); | |
| 229 | 新增: page = JsonDocument.Parse(snapshot).RootElement.Clone(); | |
| 230 | 新增: await using var capture = File.Create(Path.ChangeExtension(Program.SmokeOutput, ".png")); | |
| 231 | 新增: await web.CoreWebView2.CapturePreviewAsync(CoreWebView2CapturePreviewImageFormat.Png, capture); | |
| 232 | 新增: } | |
| 233 | 新增: catch (Exception error) { errors.Add("无法保存工作台画面:" + error.Message); } | |
| 234 | 新增: } | |
| 235 | 新增: var (exit, data) = await Backend.Json(["prepare-update", "--json"], lifetime.Token, TimeSpan.FromSeconds(20)); | |
| 216 | 236 | if (exit != 0 || data.Text("status") != "prepared") throw new IOException("自检结束时无法确认后台已停止"); |
| 237 | 新增: } | |
| 238 | 新增: catch (Exception error) { errors.Add(error.Message); } | |
| 239 | 新增: try | |
| 240 | 新增: { | |
| 217 | 241 | File.WriteAllText(Program.SmokeOutput, JsonSerializer.Serialize(new { |
| 218 | 删除: success = true, nativeBridgeReady = true, version = AppUpdater.Version, | |
| 219 | 删除: webviewVersion = web.CoreWebView2.Environment.BrowserVersionString, | |
| 242 | 新增: success = nativeBridgeReady && errors.Count == 0, nativeBridgeReady, version = AppUpdater.Version, | |
| 243 | 新增: phase = smokePhase, nativeStatus = message.Text, errors, page, | |
| 244 | 新增: pageURL = web.Source?.GetLeftPart(UriPartial.Path), | |
| 245 | 新增: webviewVersion = web.CoreWebView2?.Environment.BrowserVersionString, | |
| 220 | 246 | windowBounds = Bounds, workingArea = Screen.FromHandle(Handle).WorkingArea, deviceDpi = DeviceDpi, |
| 221 | 247 | nativeMenuBar = MainMenuStrip != null, |
| 222 | 248 | })); |
| @@ -233,7 +259,9 @@ internal sealed class MainWindow : Form | ||
| 233 | 259 | retry.Hide(); existing.Hide(); complete.Hide(); |
| 234 | 260 | try |
| 235 | 261 | { |
| 262 | 新增: smokePhase = "starting_backend"; | |
| 236 | 263 | var (exit, data) = await Backend.Json(["desktop", "--json", ..options], lifetime.Token); |
| 264 | 新增: smokePhase = "backend_returned"; | |
| 237 | 265 | if (exit != 0) throw new IOException(data.Text("message") is { Length: > 0 } detail ? detail : "工作台未能启动"); |
| 238 | 266 | controllerNeedsUpdate = data.Text("status") != "ready"; |
| 239 | 267 | if (data.Text("status") == "upgrade_pending") |
| @@ -241,6 +269,7 @@ internal sealed class MainWindow : Form | ||
| 241 | 269 | message.Text = data.Text("message"); existing.Show(); complete.Show(); return; |
| 242 | 270 | } |
| 243 | 271 | var entry = UpdatePolicy.Entry(data.Text("url")); expectedPort = entry.Port; |
| 272 | 新增: smokePhase = "loading_workbench"; | |
| 244 | 273 | Text = controllerNeedsUpdate ? "Cage(更新待完成)" : "Cage"; |
| 245 | 274 | web.CoreWebView2.Navigate(entry.AbsoluteUri); |
| 246 | 275 | } |
| @@ -460,6 +489,42 @@ internal sealed class MainWindow : Form | ||
| 460 | 489 | } |
| 461 | 490 | } |
| 462 | 491 | |
| 492 | 新增: private const string SmokeDiagnosticsScript = """ | |
| 493 | 新增: (() => { | |
| 494 | 新增: if (window !== window.top || location.protocol !== 'http:' || location.hostname !== 'localhost') return; | |
| 495 | 新增: const errors = []; | |
| 496 | 新增: Object.defineProperty(window, '__cageSmokeErrors', { value: errors }); | |
| 497 | 新增: const ownPath = value => { | |
| 498 | 新增: try { const url = new URL(value, location.href); return url.origin === location.origin ? url.pathname : ''; } | |
| 499 | 新增: catch { return ''; } | |
| 500 | 新增: }; | |
| 501 | 新增: const scrub = value => { | |
| 502 | 新增: let text = String(value || ''); | |
| 503 | 新增: for (const input of document.querySelectorAll('input,textarea')) | |
| 504 | 新增: if (input.value) text = text.split(input.value).join('[form-value]'); | |
| 505 | 新增: return text.replace(/https?:\/\/[^\s"'<>`]+/g, value => ownPath(value) || '[external]') | |
| 506 | 新增: .replace(/[?#][^\s"'<>)]*/g, '[redacted]').slice(0, 768); | |
| 507 | 新增: }; | |
| 508 | 新增: const stack = error => String(error?.stack || '').split('\n').slice(1) | |
| 509 | 新增: .filter(line => line.includes(location.origin + '/')).slice(0, 6).map(scrub); | |
| 510 | 新增: const record = value => { if (errors.length < 8) errors.push(value); }; | |
| 511 | 新增: addEventListener('error', event => { | |
| 512 | 新增: if (event.target instanceof HTMLScriptElement || event.target instanceof HTMLLinkElement) { | |
| 513 | 新增: const source = ownPath(event.target.src || event.target.href); | |
| 514 | 新增: if (source) record({ type: 'module-load', source }); | |
| 515 | 新增: return; | |
| 516 | 新增: } | |
| 517 | 新增: const source = ownPath(event.filename || location.href); | |
| 518 | 新增: if (source) record({ type: 'error', source, message: scrub(event.message), stack: stack(event.error) }); | |
| 519 | 新增: }, true); | |
| 520 | 新增: addEventListener('unhandledrejection', event => { | |
| 521 | 新增: const frames = stack(event.reason); | |
| 522 | 新增: // Primitive/cross-origin rejections are counted without exporting arbitrary values. | |
| 523 | 新增: record({ type: 'unhandledrejection', message: frames.length ? scrub(event.reason?.message) : 'Unhandled rejection', stack: frames }); | |
| 524 | 新增: }); | |
| 525 | 新增: })(); | |
| 526 | 新增: """; | |
| 527 | 新增: | |
| 463 | 528 | private const string BridgeScript = """ |
| 464 | 529 | (() => { |
| 465 | 530 | if (window !== window.top || location.protocol !== 'http:' || location.hostname !== 'localhost') return; |
| @@ -2,6 +2,7 @@ using System.IO.Pipes; | ||
| 2 | 2 | using System.Security.Cryptography; |
| 3 | 3 | using System.Security.Principal; |
| 4 | 4 | using System.Text; |
| 5 | 新增:using System.Text.Json; | |
| 5 | 6 | using System.Runtime.InteropServices; |
| 6 | 7 | |
| 7 | 8 | namespace Cage.Windows; |
| @@ -67,6 +68,12 @@ internal static class Program | ||
| 67 | 68 | } |
| 68 | 69 | }); |
| 69 | 70 | Application.Run(form); cancellation.Cancel(); |
| 70 | 删除: return SmokeOutput == null || File.Exists(SmokeOutput) ? 0 : 1; | |
| 71 | 新增: if (SmokeOutput == null) return 0; | |
| 72 | 新增: try | |
| 73 | 新增: { | |
| 74 | 新增: using var report = JsonDocument.Parse(File.ReadAllText(SmokeOutput)); | |
| 75 | 新增: return report.RootElement.TryGetProperty("success", out var success) && success.ValueKind == JsonValueKind.True ? 0 : 1; | |
| 76 | 新增: } | |
| 77 | 新增: catch (Exception error) when (error is IOException or UnauthorizedAccessException or JsonException) { return 1; } | |
| 71 | 78 | } |
| 72 | 79 | } |
| @@ -34,7 +34,7 @@ try { | ||
| 34 | 34 | call(['service.start']); |
| 35 | 35 | assert.equal(JSON.parse(await readFile(join(profile, 'profile', 'control.json'), 'utf8')).pid, controllerPID); |
| 36 | 36 | assert.equal(call(['call', 'settings.get'], undefined, 3).error.code, 'account_locked'); |
| 37 | 删除: call(['call', 'account.create', '--input', '-'], { username: 'Agent acceptance', password: 'Ephemeral-Test-Password-123!', confirm_password: 'Ephemeral-Test-Password-123!' }); | |
| 37 | 新增: call(['call', 'account.create', '--input', '-'], { username: 'agent_acceptance', password: 'Ephemeral-Test-Password-123!', confirm_password: 'Ephemeral-Test-Password-123!' }); | |
| 38 | 38 | const before = call(['call', 'settings.get']).data; |
| 39 | 39 | const patch = { balanced_display: !before.balanced_display }; |
| 40 | 40 | call(['call', 'settings.patch', '--input', '-'], { patch, dry_run: true }); |
| @@ -197,5 +197,8 @@ try { | ||
| 197 | 197 | } finally { |
| 198 | 198 | Pop-Location |
| 199 | 199 | $env:GOOS = $savedGoOS; $env:GOARCH = $savedGoArch; $env:CGO_ENABLED = $savedCGO |
| 200 | 删除: if (Test-Path -LiteralPath $stage) { Remove-Item -LiteralPath $stage -Recurse -Force } | |
| 200 | 新增: if (Test-Path -LiteralPath $stage) { | |
| 201 | 新增: try { Remove-Item -LiteralPath $stage -Recurse -Force -ErrorAction Stop } | |
| 202 | 新增: catch { Write-Warning "Temporary build files remain at $stage. Cleanup did not complete: $($_.Exception.Message)" } | |
| 203 | 新增: } | |
| 201 | 204 | } |
| @@ -51,17 +51,11 @@ try { | ||
| 51 | 51 | Invoke-BuildTool 'node' @('--test', 'internal/cage/browser-clipboard.test.mjs', 'scripts/windows-native-bridge.test.mjs') |
| 52 | 52 | $windowsPowerShell = Join-Path ([Environment]::SystemDirectory) 'WindowsPowerShell/v1.0/powershell.exe' |
| 53 | 53 | & (Join-Path $PSScriptRoot 'test-windows-installation-files.ps1') -HelperShell $windowsPowerShell |
| 54 | 删除: & (Join-Path $PSScriptRoot 'build-windows.ps1') -Release:$Release | |
| 55 | 54 | if ($Release) { |
| 56 | 删除: $qemuSource = Join-Path $env:RUNNER_TEMP 'qemu-windows-full-source.tar.gz' | |
| 57 | 删除: $savedMsystem, $savedChere = $env:MSYSTEM, $env:CHERE_INVOKING | |
| 58 | 删除: try { | |
| 59 | 删除: $env:MSYSTEM = 'UCRT64'; $env:CHERE_INVOKING = '1' | |
| 60 | 删除: Invoke-BuildTool (Join-Path $env:CAGE_MSYS2_ROOT 'usr/bin/bash.exe') @('-l', | |
| 61 | 删除: (Join-Path $PSScriptRoot 'bundle-qemu-sources.sh'), $repository, | |
| 62 | 删除: (Join-Path $repository '_output/windows-deps/qemu-cage'), $qemuSource) | |
| 63 | 删除: } finally { $env:MSYSTEM = $savedMsystem; $env:CHERE_INVOKING = $savedChere } | |
| 55 | 新增: & (Join-Path $PSScriptRoot 'prepare-qemu-release.ps1') | |
| 56 | 新增: $qemuSource = Join-Path $repository '_output/windows-qemu-sources/full-source.tar.gz' | |
| 64 | 57 | } |
| 58 | 新增: & (Join-Path $PSScriptRoot 'build-windows.ps1') -Release:$Release | |
| 65 | 59 | if (-not $Release) { |
| 66 | 60 | $windowsPowerShell = Join-Path ([Environment]::SystemDirectory) 'WindowsPowerShell/v1.0/powershell.exe' |
| 67 | 61 | foreach ($test in @('install-guest-powershell.tests.ps1', 'windows-evaluation.tests.ps1')) { |
| @@ -101,7 +95,7 @@ try { | ||
| 101 | 95 | Remove-Item "Cert:\CurrentUser\My\$($imported.Thumbprint)" -Force -ErrorAction SilentlyContinue |
| 102 | 96 | } |
| 103 | 97 | } |
| 104 | 删除: if ($qemuSource) { Remove-Item -LiteralPath $qemuSource -Force -ErrorAction SilentlyContinue } | |
| 98 | 新增: # Verified QEMU sources remain in the build cache; packaging copies them separately. | |
| 105 | 99 | $env:PATH = $savedPath |
| 106 | 100 | $env:CAGE_WINDOWS_CERT_SHA1 = $savedCertificate |
| 107 | 101 | Remove-Item Env:CAGE_ESIGNER_PASSWORD, Env:CAGE_ESIGNER_TOTP_SECRET -ErrorAction SilentlyContinue |
| @@ -168,6 +168,23 @@ async function credentials() { | ||
| 168 | 168 | return { username, password, credential, totp: process.env.CAGE_ESIGNER_TOTP_SECRET }; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 新增:// A provider-declared server error is a definite failure. Timeouts, OTP and | |
| 172 | 新增:// authentication errors are not retried. Any output proceeds to the caller's | |
| 173 | 新增:// existing Authenticode verification; it must never trigger another signature. | |
| 174 | 新增:export async function invokeSigning({ invoke, outputPath, pause = ms => new Promise(done => setTimeout(done, ms)) }) { | |
| 175 | 新增: for (let attempt = 0; attempt < 3; attempt++) { | |
| 176 | 新增: try { return await invoke(); } | |
| 177 | 新增: catch (error) { | |
| 178 | 新增: try { await access(outputPath); return ''; } | |
| 179 | 新增: catch (outputError) { if (outputError.code !== 'ENOENT') throw error; } | |
| 180 | 新增: const uncertainOrRejected = /timeout|timed out|abort|cancel|invalid_grant|invalid_client|access_denied|unauthorized|(?:otp|totp|authentication|authorization|credential|password)[^\n]*(?:invalid|expired|failed|rejected)/i.test(error.message); | |
| 181 | 新增: if (attempt === 2 || uncertainOrRejected || !/^CodeSignTool failed \(exit 11\)/.test(error.message) || !/"error"\s*:\s*"server_error"/.test(error.message)) throw error; | |
| 182 | 新增: console.error(`Signing service returned server_error; retrying in ${(attempt + 1) * 15} seconds.`); | |
| 183 | 新增: await pause((attempt + 1) * 15000); | |
| 184 | 新增: } | |
| 185 | 新增: } | |
| 186 | 新增:} | |
| 187 | 新增: | |
| 171 | 188 | async function main(argv) { |
| 172 | 189 | const [command, input, flag, destination] = argv; |
| 173 | 190 | if (command === 'install' && argv.length === 1) { console.log(`Verified CodeSignTool ${pin.version}: ${await installTool()}`); return; } |
| @@ -193,8 +210,9 @@ async function main(argv) { | ||
| 193 | 210 | args.push(`-input_file_path=${vendor.path}`, `-output_dir_path=${vendor.output}`); |
| 194 | 211 | if (auth.totp) args.push(`-totp_secret=${auth.totp}`); |
| 195 | 212 | } |
| 196 | 删除: const result = await invokeJava({ jar: join(directory, pin.jar), config: join(directory, configPath), arguments: args, | |
| 213 | 新增: const invoke = () => invokeJava({ jar: join(directory, pin.jar), config: join(directory, configPath), arguments: args, | |
| 197 | 214 | otp: signal => prompt('Current six-digit authenticator code', true, signal), secrets: [auth.password, auth.totp] }); |
| 215 | 新增: const result = command === 'sign' ? await invokeSigning({ invoke, outputPath: join(vendor.output, basename(vendor.path)) }) : await invoke(); | |
| 198 | 216 | if (command === 'sign') { |
| 199 | 217 | const signed = join(vendor.output, basename(vendor.path)); |
| 200 | 218 | const bytes = await readFile(signed); |
| @@ -5,13 +5,35 @@ import { join } from 'node:path'; | ||
| 5 | 5 | import { tmpdir } from 'node:os'; |
| 6 | 6 | import { fileURLToPath } from 'node:url'; |
| 7 | 7 | import { test } from 'node:test'; |
| 8 | 删除:import { assertWindowsExecutable, invokeJava, javaArgument, prepareVendorInput, redact, verifyTool } from './esigner.mjs'; | |
| 8 | 新增:import { assertWindowsExecutable, invokeJava, invokeSigning, javaArgument, prepareVendorInput, redact, verifyTool } from './esigner.mjs'; | |
| 9 | 9 | |
| 10 | 10 | test('Java arguments reject line injection and redact overlapping secrets', () => { |
| 11 | 11 | for (const value of ['line\nbreak', 'line\rbreak', 'a\0b']) assert.throws(() => javaArgument(value)); |
| 12 | 12 | assert.equal(redact('secret-long and secret', ['secret', 'secret-long']), '[redacted] and [redacted]'); |
| 13 | 13 | }); |
| 14 | 14 | |
| 15 | 新增:test('signing retries only declared server errors without output and remains bounded', async t => { | |
| 16 | 新增: const root = await mkdtemp(join(tmpdir(), 'cage-sign-retry-')); | |
| 17 | 新增: t.after(() => rm(root, { recursive: true, force: true })); | |
| 18 | 新增: const outputPath = join(root, 'signed.exe'), delays = []; | |
| 19 | 新增: const failure = () => new Error('CodeSignTool failed (exit 11). Error: {"error":"server_error"}'); | |
| 20 | 新增: let count = 0; | |
| 21 | 新增: assert.equal(await invokeSigning({ outputPath, pause: async ms => delays.push(ms), invoke: async () => { if (++count < 3) throw failure(); return 'signed'; } }), 'signed'); | |
| 22 | 新增: assert.deepEqual(delays, [15000, 30000]); | |
| 23 | 新增: count = 0; | |
| 24 | 新增: await assert.rejects(invokeSigning({ outputPath, pause: async () => {}, invoke: async () => { count++; throw failure(); } }), /server_error/); | |
| 25 | 新增: assert.equal(count, 3); | |
| 26 | 新增: for (const message of ['OTP rejected', 'authentication failed', 'timeout', 'CodeSignTool failed (exit 1). server_error', `${failure().message}\nOTP rejected`, `${failure().message}\ntimeout`]) { | |
| 27 | 新增: count = 0; | |
| 28 | 新增: await assert.rejects(invokeSigning({ outputPath, pause: async () => assert.fail('must not wait'), invoke: async () => { count++; throw new Error(message); } })); | |
| 29 | 新增: assert.equal(count, 1); | |
| 30 | 新增: } | |
| 31 | 新增: count = 0; | |
| 32 | 新增: await invokeSigning({ outputPath, pause: async () => assert.fail('output requires trust verification, never another signature'), invoke: async () => { count++; await writeFile(outputPath, 'candidate output'); throw failure(); } }); | |
| 33 | 新增: assert.equal(count, 1); | |
| 34 | 新增: assert.equal(await readFile(outputPath, 'utf8'), 'candidate output'); | |
| 35 | 新增:}); | |
| 36 | 新增: | |
| 15 | 37 | test('a real JVM receives quoted Unicode arguments, no secrets in process arguments, and OTP through stdin', async t => { |
| 16 | 38 | const temp = await mkdtemp(join(tmpdir(), 'cage-esigner-test-')); |
| 17 | 39 | t.after(() => rm(temp, { recursive: true, force: true })); |
| @@ -0,0 +1,36 @@ | ||
| 1 | 新增:#requires -Version 7.0 | |
| 2 | 新增:[CmdletBinding()] | |
| 3 | 新增:param([string]$MsysDirectory = $env:CAGE_MSYS2_ROOT) | |
| 4 | 新增:. (Join-Path $PSScriptRoot 'windows-common.ps1') | |
| 5 | 新增:if (-not $IsWindows) { throw 'Prepare the corresponding runtime sources on Windows.' } | |
| 6 | 新增:$repository = Split-Path $PSScriptRoot -Parent | |
| 7 | 新增:if (-not $MsysDirectory) { | |
| 8 | 新增: $MsysDirectory = @('C:\msys64', 'D:\msys64') | Where-Object { Test-Path (Join-Path $_ 'ucrt64/bin/pkg-config.exe') } | Select-Object -First 1 | |
| 9 | 新增:} | |
| 10 | 新增:if (-not $MsysDirectory) { throw 'Set CAGE_MSYS2_ROOT to the MSYS2 UCRT64 build environment.' } | |
| 11 | 新增:$runtime = Join-Path $repository '_output/windows-deps/qemu-cage' | |
| 12 | 新增:& (Join-Path $PSScriptRoot 'build-qemu-windows.ps1') -OutputDirectory $runtime -MsysDirectory $MsysDirectory | |
| 13 | 新增:$runtimeIdentity = Get-Content (Join-Path $runtime 'cage-build.json') -Raw | ConvertFrom-Json | |
| 14 | 新增:$collectorHash = (Get-FileHash -LiteralPath (Join-Path $PSScriptRoot 'bundle-qemu-sources.sh') -Algorithm SHA256).Hash + (Get-FileHash -LiteralPath $PSCommandPath -Algorithm SHA256).Hash | |
| 15 | 新增:$directory = Join-Path $repository '_output/windows-qemu-sources' | |
| 16 | 新增:$archive = Join-Path $directory 'full-source.tar.gz' | |
| 17 | 新增:$record = Join-Path $directory 'source-identity.json' | |
| 18 | 新增:if ((Test-Path -LiteralPath $record) -and (Test-Path -LiteralPath $archive)) { | |
| 19 | 新增: $identity = Get-Content -LiteralPath $record -Raw | ConvertFrom-Json | |
| 20 | 新增: if ($identity.schema -ne 1 -or $identity.fingerprint -ne $runtimeIdentity.fingerprint -or $identity.collectorHash -ne $collectorHash -or $identity.sha256 -ne (Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash) { | |
| 21 | 新增: throw 'Cached QEMU sources differ from their verified runtime identity.' | |
| 22 | 新增: } | |
| 23 | 新增: Write-Host 'Verified cached QEMU corresponding sources.' | |
| 24 | 新增: return | |
| 25 | 新增:} | |
| 26 | 新增:New-Item -ItemType Directory -Path $directory -Force | Out-Null | |
| 27 | 新增:$savedMsystem, $savedChere = $env:MSYSTEM, $env:CHERE_INVOKING | |
| 28 | 新增:try { | |
| 29 | 新增: $env:MSYSTEM = 'UCRT64'; $env:CHERE_INVOKING = '1' | |
| 30 | 新增: Invoke-BuildTool (Join-Path $MsysDirectory 'usr/bin/bash.exe') @('-l', | |
| 31 | 新增: (Join-Path $PSScriptRoot 'bundle-qemu-sources.sh'), $repository, $runtime, $archive) | |
| 32 | 新增:} finally { $env:MSYSTEM = $savedMsystem; $env:CHERE_INVOKING = $savedChere } | |
| 33 | 新增:$identity = @{ schema = 1; fingerprint = $runtimeIdentity.fingerprint; collectorHash = $collectorHash; sha256 = (Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash } | |
| 34 | 新增:$identity | ConvertTo-Json | Set-Content -LiteralPath "$record.partial" -Encoding utf8 | |
| 35 | 新增:Move-Item -LiteralPath "$record.partial" -Destination $record -Force | |
| 36 | 新增:Write-Host 'Collected and verified QEMU corresponding sources before application signing.' | |
| @@ -27,11 +27,34 @@ function Assert-WindowsWorkbench { | ||
| 27 | 27 | if (-not $window.WaitForExit(180000)) { throw "Cage workbench acceptance timed out. Diagnostics retained at $testRoot" } |
| 28 | 28 | if ($window.ExitCode -ne 0 -or -not (Test-Path -LiteralPath $report)) { throw "Cage workbench acceptance failed. Diagnostics retained at $testRoot" } |
| 29 | 29 | $result = Get-Content -LiteralPath $report -Raw | ConvertFrom-Json |
| 30 | 删除: if ($result.success -ne $true -or $result.nativeBridgeReady -ne $true) { throw "Cage workbench/bridge acceptance failed. Diagnostics retained at $testRoot" } | |
| 30 | 新增: if ($result.success -ne $true -or $result.nativeBridgeReady -ne $true) { | |
| 31 | 新增: $detail = if ($result.PSObject.Properties.Name -contains 'nativeStatus') { $result.nativeStatus } else { 'No native status was recorded.' } | |
| 32 | 新增: throw "Cage workbench/bridge acceptance failed: $detail Diagnostics retained at $testRoot" | |
| 33 | 新增: } | |
| 31 | 34 | $passed = $true |
| 32 | 35 | } finally { |
| 33 | 36 | if (-not $window.HasExited) { $window.Kill($true); $window.WaitForExit() } |
| 34 | 37 | $window.Dispose() |
| 38 | 新增: if (-not $passed) { | |
| 39 | 新增: # Close only this test's authenticated controller. Killing every | |
| 40 | 新增: # cage.exe could terminate another installed application or VM. | |
| 41 | 新增: try { | |
| 42 | 新增: $cleanup = [Diagnostics.ProcessStartInfo]::new((Join-Path $AppDirectory 'resources/cage.exe')) | |
| 43 | 新增: $cleanup.UseShellExecute = $false | |
| 44 | 新增: $cleanup.CreateNoWindow = $true | |
| 45 | 新增: $cleanup.RedirectStandardOutput = $true | |
| 46 | 新增: $cleanup.RedirectStandardError = $true | |
| 47 | 新增: $cleanup.Environment['CLAUDE_CAGE_CONFIG'] = Join-Path $testRoot 'profile/config.json' | |
| 48 | 新增: $cleanup.ArgumentList.Add('prepare-update'); $cleanup.ArgumentList.Add('--json') | |
| 49 | 新增: $controller = [Diagnostics.Process]::Start($cleanup) | |
| 50 | 新增: try { | |
| 51 | 新增: $stdout = $controller.StandardOutput.ReadToEndAsync() | |
| 52 | 新增: $stderr = $controller.StandardError.ReadToEndAsync() | |
| 53 | 新增: if (-not $controller.WaitForExit(20000)) { $controller.Kill($true); $controller.WaitForExit() } | |
| 54 | 新增: if ($controller.ExitCode -ne 0) { Write-Warning 'The isolated smoke controller did not confirm shutdown; its profile is retained.' } | |
| 55 | 新增: } finally { $controller.Dispose() } | |
| 56 | 新增: } catch { Write-Warning "Isolated smoke cleanup failed: $($_.Exception.Message)" } | |
| 57 | 新增: } | |
| 35 | 58 | # A successful smoke report is written only after the isolated backend |
| 36 | 59 | # confirms shutdown. Failed profiles remain available for diagnosis. |
| 37 | 60 | if ($passed) { Remove-Item -LiteralPath $testRoot -Recurse -Force -ErrorAction SilentlyContinue } |

