提交记录修改.github/workflows/windows-build.yml+16 −3看文件
修改.github/workflows/windows-signing-check.yml+9 −2看文件
修改desktop/linux/test-smoke.mjs+17 −2看文件
修改scripts/build-qemu-windows.ps1+1 −1看文件
修改scripts/bundle-qemu-sources.sh+5 −3看文件
修改scripts/bundle-qemu-sources.test.mjs+2 −1看文件
修改scripts/check-windows-signing.ps1+9 −3看文件
修改scripts/ci-windows-build.ps1+1 −0看文件
修改scripts/esigner.mjs+18 −5看文件
修改scripts/esigner.test.mjs+14 −1看文件
修改scripts/prepare-qemu-release.ps1+3 −2看文件
修改scripts/windows-common.ps1+44 −7看文件
新增scripts/windows-workbench-smoke.test.ps1+55 −0看文件
| @@ -60,7 +60,19 @@ jobs: | ||
| 60 | 60 | mingw-w64-ucrt-x86_64-ninja |
| 61 | 61 | mingw-w64-ucrt-x86_64-python |
| 62 | 62 | mingw-w64-ucrt-x86_64-pkgconf |
| 63 | 删除: - uses: actions/cache@v4 | |
| 63 | 新增: - uses: actions/cache/restore@v4 | |
| 64 | 新增: id: qemu_cache | |
| 65 | 新增: with: | |
| 66 | 新增: path: _output/windows-deps | |
| 67 | 新增: key: cage-windows-deps-${{ hashFiles('packaging/windows/dependencies.json', 'patches/qemu/**', 'scripts/build-qemu-windows.*') }} | |
| 68 | 新增: restore-keys: cage-windows-deps- | |
| 69 | 新增: - name: Build and verify QEMU runtime before application acceptance | |
| 70 | 新增: env: | |
| 71 | 新增: CAGE_MSYS2_ROOT: ${{ steps.msys2.outputs.msys2-location }} | |
| 72 | 新增: run: ./scripts/build-qemu-windows.ps1 | |
| 73 | 新增: - name: Preserve only the completed verified runtime cache | |
| 74 | 新增: if: steps.qemu_cache.outputs.cache-hit != 'true' | |
| 75 | 新增: uses: actions/cache/save@v4 | |
| 64 | 76 | with: |
| 65 | 77 | path: _output/windows-deps |
| 66 | 78 | key: cage-windows-deps-${{ hashFiles('packaging/windows/dependencies.json', 'patches/qemu/**', 'scripts/build-qemu-windows.*') }} |
| @@ -132,7 +144,8 @@ jobs: | ||
| 132 | 144 | id: qemu_cache |
| 133 | 145 | with: |
| 134 | 146 | path: _output/windows-deps |
| 135 | 删除: key: cage-windows-deps-${{ hashFiles('packaging/windows/dependencies.json', 'patches/qemu/**', 'scripts/build-qemu-windows.*', 'scripts/bundle-qemu-sources.sh') }} | |
| 147 | 新增: restore-keys: cage-windows-deps- | |
| 148 | 新增: key: cage-windows-deps-${{ hashFiles('packaging/windows/dependencies.json', 'patches/qemu/**', 'scripts/build-qemu-windows.*') }} | |
| 136 | 149 | - name: Build and verify QEMU runtime and package identity |
| 137 | 150 | id: qemu_build |
| 138 | 151 | env: |
| @@ -148,7 +161,7 @@ jobs: | ||
| 148 | 161 | uses: actions/cache/save@v4 |
| 149 | 162 | with: |
| 150 | 163 | 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') }} | |
| 164 | 新增: key: cage-windows-deps-${{ hashFiles('packaging/windows/dependencies.json', 'patches/qemu/**', 'scripts/build-qemu-windows.*') }} | |
| 152 | 165 | - uses: actions/cache/restore@v4 |
| 153 | 166 | id: qemu_sources |
| 154 | 167 | with: |
| @@ -1,6 +1,12 @@ | ||
| 1 | 1 | name: Verify Windows cloud signing without a release |
| 2 | 2 | on: |
| 3 | 3 | workflow_dispatch: |
| 4 | 新增: inputs: | |
| 5 | 新增: mode: | |
| 6 | 新增: description: Sign a disposable probe, or only read credential information without signing | |
| 7 | 新增: type: choice | |
| 8 | 新增: options: [sign, credential-info] | |
| 9 | 新增: default: sign | |
| 4 | 10 | permissions: |
| 5 | 11 | contents: read |
| 6 | 12 | concurrency: |
| @@ -24,7 +30,7 @@ jobs: | ||
| 24 | 30 | with: |
| 25 | 31 | distribution: temurin |
| 26 | 32 | java-version: '21' |
| 27 | 删除: - name: Sign one disposable executable and verify Windows trust | |
| 33 | 新增: - name: Run the selected signing verification or read-only diagnosis | |
| 28 | 34 | shell: pwsh |
| 29 | 35 | env: |
| 30 | 36 | CAGE_WINDOWS_SIGNING_PROVIDER: ${{ vars.CAGE_WINDOWS_SIGNING_PROVIDER }} |
| @@ -33,7 +39,8 @@ jobs: | ||
| 33 | 39 | CAGE_ESIGNER_CREDENTIAL_ID: ${{ secrets.CAGE_ESIGNER_CREDENTIAL_ID }} |
| 34 | 40 | CAGE_ESIGNER_CERTIFICATE_SERIAL: ${{ vars.CAGE_ESIGNER_CERTIFICATE_SERIAL }} |
| 35 | 41 | CAGE_ESIGNER_TOTP_SECRET: ${{ secrets.CAGE_ESIGNER_TOTP_SECRET }} |
| 36 | 删除: run: ./scripts/check-windows-signing.ps1 | |
| 42 | 新增: CAGE_SIGNING_CHECK_MODE: ${{ inputs.mode }} | |
| 43 | 新增: run: ./scripts/check-windows-signing.ps1 -Mode $env:CAGE_SIGNING_CHECK_MODE | |
| 37 | 44 | - name: Preserve verification facts only |
| 38 | 45 | if: always() |
| 39 | 46 | uses: actions/upload-artifact@v4 |
| @@ -133,9 +133,24 @@ try { | ||
| 133 | 133 | console.error(error.message); |
| 134 | 134 | } finally { |
| 135 | 135 | try { |
| 136 | 删除: const stopped = parseBackend(await execute(backend, ['prepare-update', '--json'])); | |
| 136 | 新增: const cleanupRun = await execute(backend, ['prepare-update', '--json']); | |
| 137 | 新增: if (cleanupRun.code !== 0) { | |
| 138 | 新增: // prepare-update returns only status/message. Never log desktop's | |
| 139 | 新增: // entry JSON or arbitrary stdout, which can contain a session URL. | |
| 140 | 新增: let message = ''; | |
| 141 | 新增: try { | |
| 142 | 新增: const response = JSON.parse(cleanupRun.stdout); | |
| 143 | 新增: if (typeof response.message === 'string') message = response.message.slice(0, 500); | |
| 144 | 新增: } catch { /* Keep malformed or non-JSON output private. */ } | |
| 145 | 新增: console.error(`Cleanup prepare-update failed (exit ${cleanupRun.code}, signal ${cleanupRun.signal || 'none'}): ${message}`); | |
| 146 | 新增: } | |
| 147 | 新增: const stopped = parseBackend(cleanupRun); | |
| 137 | 148 | clean = stopped.status === 'prepared'; |
| 138 | 删除: } catch { /* Preserve the fixture until a remaining controller can be stopped. */ } | |
| 149 | 新增: if (!clean) console.error(`Cleanup prepare-update returned ${stopped.status || 'unknown status'}.`); | |
| 150 | 新增: } catch (error) { | |
| 151 | 新增: console.error(`Cleanup could not confirm controller exit: ${error.message}`); | |
| 152 | 新增: // Preserve the fixture until a remaining controller can be stopped. | |
| 153 | 新增: } | |
| 139 | 154 | if (clean) await rm(root, { recursive: true, force: true }); |
| 140 | 155 | else { console.error(`Cleanup incomplete; isolated profile retained at ${root}`); result = 1; } |
| 141 | 156 | } |
| @@ -14,7 +14,7 @@ $DependencyCache = [IO.Path]::GetFullPath($DependencyCache) | ||
| 14 | 14 | $OutputDirectory = [IO.Path]::GetFullPath($OutputDirectory) |
| 15 | 15 | $dependencies = Get-Content (Join-Path $repository 'packaging/windows/dependencies.json') -Raw | ConvertFrom-Json |
| 16 | 16 | $patchDirectory = Join-Path $repository 'patches/qemu' |
| 17 | 删除:$inputs = @((Join-Path $PSScriptRoot 'build-qemu-windows.sh'), (Join-Path $PSScriptRoot 'bundle-qemu-sources.sh'), $PSCommandPath) + @(Get-ChildItem $patchDirectory -Filter '*.patch' | Sort-Object Name | ForEach-Object FullName) | |
| 17 | 新增:$inputs = @((Join-Path $PSScriptRoot 'build-qemu-windows.sh'), $PSCommandPath) + @(Get-ChildItem $patchDirectory -Filter '*.patch' | Sort-Object Name | ForEach-Object FullName) | |
| 18 | 18 | $fingerprintText = $dependencies.qemuSource.hash + $dependencies.qemuKeycodemap.hash + (($inputs | ForEach-Object { (Get-FileHash $_ -Algorithm SHA256).Hash }) -join '') |
| 19 | 19 | $fingerprint = [Convert]::ToHexString([Security.Cryptography.SHA256]::HashData([Text.Encoding]::UTF8.GetBytes($fingerprintText))) |
| 20 | 20 | $manifestPath = Join-Path $OutputDirectory 'cage-build.json' |
| @@ -4,7 +4,9 @@ set -euo pipefail | ||
| 4 | 4 | repository=$(cygpath -u "$1") |
| 5 | 5 | runtime=$(cygpath -u "$2") |
| 6 | 6 | archive=$(cygpath -u "$3") |
| 7 | 删除:commit=$(node -p "JSON.parse(require('fs').readFileSync(process.argv[1])).qemuSource.commit" "$repository/packaging/windows/dependencies.json") | |
| 7 | 新增:node_command=${CAGE_NODE:-node} | |
| 8 | 新增:if [[ -n ${CAGE_NODE:-} ]]; then node_command=$(cygpath -u "$CAGE_NODE"); fi | |
| 9 | 新增:commit=$("$node_command" -p "JSON.parse(require('fs').readFileSync(process.argv[1])).qemuSource.commit" "$repository/packaging/windows/dependencies.json") | |
| 8 | 10 | [[ $commit =~ ^[a-f0-9]{40}$ && -s "$runtime/build-source-packages.txt" ]] || { echo 'QEMU source/package identity is missing.' >&2; exit 1; } |
| 9 | 11 | stage=$(mktemp -d) |
| 10 | 12 | trap 'rm -rf "$stage"' EXIT |
| @@ -30,8 +32,8 @@ if grep -Eq '^[-+U]' "$stage/source/firmware-revisions.txt"; then echo 'Firmware | ||
| 30 | 32 | cp "$runtime/build-source-packages.txt" "$runtime/build-packages.txt" "$runtime/cage-build.json" "$stage/source/cage/" |
| 31 | 33 | cp "$repository/scripts/build-qemu-windows.sh" "$repository/scripts/build-qemu-windows.ps1" "$repository/scripts/bundle-qemu-sources.sh" "$stage/source/cage/" |
| 32 | 34 | cp -R "$repository/patches/qemu" "$stage/source/cage/patches" |
| 33 | 删除:keymap_url=$(node -p "JSON.parse(require('fs').readFileSync(process.argv[1])).qemuKeycodemap.url" "$repository/packaging/windows/dependencies.json") | |
| 34 | 删除:keymap_hash=$(node -p "JSON.parse(require('fs').readFileSync(process.argv[1])).qemuKeycodemap.hash" "$repository/packaging/windows/dependencies.json") | |
| 35 | 新增:keymap_url=$("$node_command" -p "JSON.parse(require('fs').readFileSync(process.argv[1])).qemuKeycodemap.url" "$repository/packaging/windows/dependencies.json") | |
| 36 | 新增:keymap_hash=$("$node_command" -p "JSON.parse(require('fs').readFileSync(process.argv[1])).qemuKeycodemap.hash" "$repository/packaging/windows/dependencies.json") | |
| 35 | 37 | curl --fail --location --retry 3 -o "$stage/source/keycodemapdb.tar.gz" "$keymap_url" |
| 36 | 38 | printf '%s %s\n' "$keymap_hash" "$stage/source/keycodemapdb.tar.gz" | sha256sum -c - |
| 37 | 39 | while read -r base version; do |
| @@ -18,13 +18,14 @@ test('source collector includes pinned firmware and authenticated package source | ||
| 18 | 18 | await writeFile(join(repository,'patches/qemu/fixture.patch'),'fixture patch'); |
| 19 | 19 | const command=async(name,body)=>{const path=join(bin,name);await writeFile(path,'#!/bin/bash\nset -e\n'+body+'\n');await chmod(path,0o755)}; |
| 20 | 20 | await command('cygpath','printf "%s\\n" "$2"'); |
| 21 | 新增: await command('node','echo "The collector must use the explicit CAGE_NODE path" >&2; exit 99'); | |
| 21 | 22 | await command('git',`if [[ "$*" == *' init '* ]];then mkdir -p "\${@: -1}/.git";fi |
| 22 | 23 | if [[ "$*" == *rev-parse* ]];then printf '${sha}\\n';fi |
| 23 | 24 | if [[ "$*" == *'submodule update'* ]];then for ((i=1;i<=$#;i++));do if [[ "\${!i}" == -C ]];then j=$((i+1));q="\${!j}";fi;done;mkdir -p "$q/roms/seabios";echo 'firmware code' > "$q/roms/seabios/code.c";echo 'gitdir: private' > "$q/roms/seabios/.git";fi |
| 24 | 25 | if [[ "$*" == *'submodule status'* ]];then printf ' ${sha} roms/seabios\\n';fi`); |
| 25 | 26 | await command('curl',`while [[ $# -gt 0 ]];do if [[ "$1" == -o ]];then shift;destination=$1;fi;shift;done;printf '${content.replaceAll('\n','\\n')}' > "$destination"`); |
| 26 | 27 | await command('pacman-key','printf "%s\\n" "$*" >> "$SOURCE_TEST_VERIFICATIONS"'); |
| 27 | 删除: execFileSync('bash',[collector,repository,runtime,artifact],{env:{...process.env,PATH:bin+':'+process.env.PATH,SOURCE_TEST_VERIFICATIONS:join(root,'verified')},stdio:'pipe'}); | |
| 28 | 新增: execFileSync('bash',[collector,repository,runtime,artifact],{env:{...process.env,PATH:bin+':'+process.env.PATH,CAGE_NODE:process.execPath,SOURCE_TEST_VERIFICATIONS:join(root,'verified')},stdio:'pipe'}); | |
| 28 | 29 | const listing=execFileSync('tar',['-tzf',artifact],{encoding:'utf8'}); |
| 29 | 30 | for(const path of ['source/firmware-revisions.txt','source/qemu/roms/seabios/code.c','source/packages/mingw-w64-fixture-1.2.3-1.src.tar.zst','source/cage/patches/fixture.patch','source/SHA256SUMS'])assert.ok(listing.includes(path),path); |
| 30 | 31 | assert.ok(!listing.includes('/.git')); |
| @@ -1,14 +1,20 @@ | ||
| 1 | 1 | #requires -Version 7.0 |
| 2 | 删除:# One real signature on a disposable PE file. No package, version or release writes. | |
| 2 | 新增:# Explicit signing or read-only credential verification. No package, version or release writes. | |
| 3 | 3 | [CmdletBinding()] |
| 4 | 删除:param() | |
| 4 | 新增:param([ValidateSet('sign', 'credential-info')][string]$Mode = 'sign') | |
| 5 | 5 | . (Join-Path $PSScriptRoot 'windows-common.ps1') |
| 6 | 6 | if (-not $IsWindows) { throw 'This verification requires Windows trust APIs.' } |
| 7 | 7 | if ($env:GITHUB_ACTIONS -ne 'true' -or $env:GITHUB_EVENT_NAME -ne 'workflow_dispatch' -or |
| 8 | 删除: $env:GITHUB_REPOSITORY -ne 'Lee-xeo/Claude-Cage' -or $env:GITHUB_REF -ne 'refs/heads/main') { | |
| 8 | 新增: $env:GITHUB_REPOSITORY -ne 'Lee-xeo/Claude-Cage' -or | |
| 9 | 新增: $env:GITHUB_REF -ne 'refs/heads/main') { | |
| 9 | 10 | throw 'Run the explicit main-branch signing verification workflow.' |
| 10 | 11 | } |
| 11 | 12 | if ($env:CAGE_WINDOWS_SIGNING_PROVIDER -ne 'esigner') { throw 'Select esigner for this verification.' } |
| 13 | 新增:if ($Mode -eq 'credential-info') { | |
| 14 | 新增: try { Invoke-BuildTool 'node' @((Join-Path $PSScriptRoot 'esigner.mjs'), 'diagnose') } | |
| 15 | 新增: finally { Remove-Item Env:CAGE_ESIGNER_PASSWORD, Env:CAGE_ESIGNER_TOTP_SECRET -ErrorAction SilentlyContinue } | |
| 16 | 新增: return | |
| 17 | 新增:} | |
| 12 | 18 | foreach ($name in @('CAGE_ESIGNER_USERNAME', 'CAGE_ESIGNER_PASSWORD', 'CAGE_ESIGNER_CREDENTIAL_ID', 'CAGE_ESIGNER_CERTIFICATE_SERIAL', 'CAGE_ESIGNER_TOTP_SECRET')) { |
| 13 | 19 | if (-not [Environment]::GetEnvironmentVariable($name)) { throw "Missing cage-release setting: $name" } |
| 14 | 20 | } |
| @@ -49,6 +49,7 @@ try { | ||
| 49 | 49 | $env:PATH = (Join-Path $env:RUNNER_TEMP 'nsis-3.13') + [IO.Path]::PathSeparator + $env:PATH |
| 50 | 50 | Invoke-BuildTool 'node' @('scripts/check-version.mjs') |
| 51 | 51 | Invoke-BuildTool 'node' @('--test', 'internal/cage/browser-clipboard.test.mjs', 'scripts/windows-native-bridge.test.mjs') |
| 52 | 新增: Invoke-BuildTool (Get-BuildCommand @('pwsh.exe', 'pwsh')) @('-NoProfile', '-NonInteractive', '-File', 'scripts/windows-workbench-smoke.test.ps1') | |
| 52 | 53 | $windowsPowerShell = Join-Path ([Environment]::SystemDirectory) 'WindowsPowerShell/v1.0/powershell.exe' |
| 53 | 54 | & (Join-Path $PSScriptRoot 'test-windows-installation-files.ps1') -HelperShell $windowsPowerShell |
| 54 | 55 | if ($Release) { |
| @@ -185,18 +185,29 @@ export async function invokeSigning({ invoke, outputPath, pause = ms => new Prom | ||
| 185 | 185 | } |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 新增:// Diagnostic output is an allowlist. Never return vendor JSON, identities, | |
| 189 | 新增:// certificate data, tokens or free-form error messages to CI logs. | |
| 190 | 新增:export function credentialDiagnostic(error) { | |
| 191 | 新增: if (!error) return { operation: 'credential_info', success: true, stage: 'csc-credential-info', exitCode: 0, error: '' }; | |
| 192 | 新增: const match = /^CodeSignTool failed \(exit ([0-9]{1,3})\)/.exec(error.message); | |
| 193 | 新增: const exitCode = match && Number(match[1]) <= 255 ? Number(match[1]) : null; | |
| 194 | 新增: const code = /"error"\s*:\s*"([a-z_]+)"/.exec(error.message)?.[1]; | |
| 195 | 新增: const allowed = ['server_error', 'invalid_grant', 'invalid_client', 'access_denied', 'unauthorized', 'invalid_request']; | |
| 196 | 新增: return { operation: 'credential_info', success: false, stage: exitCode === 1 ? 'oauth-token' : exitCode === 2 ? 'csc-credential-info' : 'client', exitCode, error: allowed.includes(code) ? code : 'unclassified' }; | |
| 197 | 新增:} | |
| 198 | 新增: | |
| 188 | 199 | async function main(argv) { |
| 189 | 200 | const [command, input, flag, destination] = argv; |
| 190 | 201 | if (command === 'install' && argv.length === 1) { console.log(`Verified CodeSignTool ${pin.version}: ${await installTool()}`); return; } |
| 191 | 删除: if (!['info', 'sign'].includes(command) || (command === 'info' && argv.length !== 1) || | |
| 202 | 新增: if (!['info', 'diagnose', 'sign'].includes(command) || (['info', 'diagnose'].includes(command) && argv.length !== 1) || | |
| 192 | 203 | (command === 'sign' && (argv.length !== 4 || flag !== '--output-dir'))) { |
| 193 | 删除: throw new Error('Usage: node scripts/esigner.mjs install | info | sign INPUT.exe --output-dir DIRECTORY'); | |
| 204 | 新增: throw new Error('Usage: node scripts/esigner.mjs install | info | diagnose | sign INPUT.exe --output-dir DIRECTORY'); | |
| 194 | 205 | } |
| 195 | 206 | if (command === 'sign') await assertWindowsExecutable(resolve(input)); |
| 196 | 207 | const directory = await installTool(); |
| 197 | 208 | const auth = await credentials(); |
| 198 | 209 | if (command === 'sign' && !auth.totp && !process.stdin.isTTY) throw new Error('Non-interactive signing requires CAGE_ESIGNER_TOTP_SECRET.'); |
| 199 | 删除: const args = [command === 'info' ? 'credential_info' : 'sign', `-username=${auth.username}`, `-password=${auth.password}`, `-credential_id=${auth.credential}`]; | |
| 210 | 新增: const args = [command === 'sign' ? 'sign' : 'credential_info', `-username=${auth.username}`, `-password=${auth.password}`, `-credential_id=${auth.credential}`]; | |
| 200 | 211 | let staged, output, vendor; |
| 201 | 212 | try { |
| 202 | 213 | if (command === 'sign') { |
| @@ -219,13 +230,15 @@ async function main(argv) { | ||
| 219 | 230 | if (!bytes.length || hash(bytes) === hash(await readFile(resolve(input)))) throw new Error('CodeSignTool did not produce a changed signed file.'); |
| 220 | 231 | await copyFile(signed, output, (await import('node:fs')).constants.COPYFILE_EXCL); |
| 221 | 232 | console.log(`Signed copy: ${output}\nWindows trust and publisher verification are still required.`); |
| 222 | 删除: } else console.log(result.trim()); | |
| 233 | 新增: } else if (command === 'diagnose') console.log(JSON.stringify(credentialDiagnostic())); | |
| 234 | 新增: else console.log(result.trim()); | |
| 223 | 235 | } finally { if (staged) await rm(staged, { recursive: true, force: true }); } |
| 224 | 236 | } |
| 225 | 237 | |
| 226 | 238 | if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) { |
| 227 | 239 | main(process.argv.slice(2)).catch(error => { |
| 228 | 删除: console.error(redact(error.message, secretNames.map(name => process.env[name]))); | |
| 240 | 新增: if (process.argv[2] === 'diagnose') console.error(JSON.stringify(credentialDiagnostic(error))); | |
| 241 | 新增: else console.error(redact(error.message, secretNames.map(name => process.env[name]))); | |
| 229 | 242 | process.exitCode = 1; |
| 230 | 243 | }); |
| 231 | 244 | } |
| @@ -5,13 +5,26 @@ 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, invokeSigning, javaArgument, prepareVendorInput, redact, verifyTool } from './esigner.mjs'; | |
| 8 | 新增:import { assertWindowsExecutable, credentialDiagnostic, 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('read-only credential diagnosis emits only fixed stage, exit and error classifications', () => { | |
| 16 | 新增: assert.deepEqual(credentialDiagnostic(), { operation: 'credential_info', success: true, stage: 'csc-credential-info', exitCode: 0, error: '' }); | |
| 17 | 新增: for (const [code, stage] of [[1, 'oauth-token'], [2, 'csc-credential-info'], [3, 'client']]) { | |
| 18 | 新增: const result = credentialDiagnostic(new Error(`CodeSignTool failed (exit ${code}). Error: {"error":"server_error","token":"private-token","username":"private-user","credential_id":"private-id"}`)); | |
| 19 | 新增: assert.deepEqual(result, { operation: 'credential_info', success: false, stage, exitCode: code, error: 'server_error' }); | |
| 20 | 新增: assert.ok(!JSON.stringify(result).includes('private')); | |
| 21 | 新增: } | |
| 22 | 新增: const unknown = credentialDiagnostic(new Error('private-user private-id private-token {"error":"private_password"}')); | |
| 23 | 新增: assert.equal(unknown.error, 'unclassified'); | |
| 24 | 新增: assert.equal(unknown.exitCode, null); | |
| 25 | 新增: assert.ok(!JSON.stringify(unknown).includes('private')); | |
| 26 | 新增:}); | |
| 27 | 新增: | |
| 15 | 28 | test('signing retries only declared server errors without output and remains bounded', async t => { |
| 16 | 29 | const root = await mkdtemp(join(tmpdir(), 'cage-sign-retry-')); |
| 17 | 30 | t.after(() => rm(root, { recursive: true, force: true })); |
| @@ -24,12 +24,13 @@ if ((Test-Path -LiteralPath $record) -and (Test-Path -LiteralPath $archive)) { | ||
| 24 | 24 | return |
| 25 | 25 | } |
| 26 | 26 | New-Item -ItemType Directory -Path $directory -Force | Out-Null |
| 27 | 删除:$savedMsystem, $savedChere = $env:MSYSTEM, $env:CHERE_INVOKING | |
| 27 | 新增:$savedMsystem, $savedChere, $savedNode = $env:MSYSTEM, $env:CHERE_INVOKING, $env:CAGE_NODE | |
| 28 | 28 | try { |
| 29 | 29 | $env:MSYSTEM = 'UCRT64'; $env:CHERE_INVOKING = '1' |
| 30 | 新增: $env:CAGE_NODE = Get-BuildCommand @('node.exe', 'node') | |
| 30 | 31 | Invoke-BuildTool (Join-Path $MsysDirectory 'usr/bin/bash.exe') @('-l', |
| 31 | 32 | (Join-Path $PSScriptRoot 'bundle-qemu-sources.sh'), $repository, $runtime, $archive) |
| 32 | 删除:} finally { $env:MSYSTEM = $savedMsystem; $env:CHERE_INVOKING = $savedChere } | |
| 33 | 新增:} finally { $env:MSYSTEM = $savedMsystem; $env:CHERE_INVOKING = $savedChere; $env:CAGE_NODE = $savedNode } | |
| 33 | 34 | $identity = @{ schema = 1; fingerprint = $runtimeIdentity.fingerprint; collectorHash = $collectorHash; sha256 = (Get-FileHash -LiteralPath $archive -Algorithm SHA256).Hash } |
| 34 | 35 | $identity | ConvertTo-Json | Set-Content -LiteralPath "$record.partial" -Encoding utf8 |
| 35 | 36 | Move-Item -LiteralPath "$record.partial" -Destination $record -Force |
| @@ -9,10 +9,52 @@ function Invoke-BuildTool { | ||
| 9 | 9 | if ($LASTEXITCODE -ne 0) { throw "$Tool failed with exit code $LASTEXITCODE" } |
| 10 | 10 | } |
| 11 | 11 | |
| 12 | 新增:function Get-WindowsWorkbenchTestBase { | |
| 13 | 新增: if ($env:RUNNER_TEMP) { return [IO.Path]::GetFullPath($env:RUNNER_TEMP) } | |
| 14 | 新增: return [IO.Path]::GetTempPath() | |
| 15 | 新增:} | |
| 16 | 新增: | |
| 17 | 新增:function ConvertTo-SmokeSafeText { | |
| 18 | 新增: param($Value) | |
| 19 | 新增: if ($Value -isnot [string]) { return '' } | |
| 20 | 新增: $text = [regex]::Replace($Value, 'https?://[^\s"''<>]+', { | |
| 21 | 新增: param($match) | |
| 22 | 新增: try { return ([Uri]$match.Value).GetLeftPart([UriPartial]::Path) } | |
| 23 | 新增: catch { return '[URL omitted]' } | |
| 24 | 新增: }) | |
| 25 | 新增: $text = $text -replace '[?#][^\s"''<>)]*', '[redacted]' | |
| 26 | 新增: return $text.Substring(0, [Math]::Min(768, $text.Length)) | |
| 27 | 新增:} | |
| 28 | 新增: | |
| 29 | 新增:function Assert-WindowsWorkbenchReport { | |
| 30 | 新增: param([int]$ExitCode, [string]$Report) | |
| 31 | 新增: if (-not (Test-Path -LiteralPath $Report -PathType Leaf)) { throw "Cage workbench acceptance failed ($ExitCode). No smoke report: $Report" } | |
| 32 | 新增: if ((Get-Item -LiteralPath $Report).Length -gt 65536) { throw 'Cage smoke report exceeds the bounded diagnostic size.' } | |
| 33 | 新增: $result = Get-Content -LiteralPath $Report -Raw | ConvertFrom-Json -AsHashtable | |
| 34 | 新增: $safe = @{ phase = ConvertTo-SmokeSafeText $result['phase']; nativeStatus = ConvertTo-SmokeSafeText $result['nativeStatus']; jsErrors = @() } | |
| 35 | 新增: if ($result['page'] -is [System.Collections.IDictionary] -and $result['page']['errors']) { | |
| 36 | 新增: $safe.jsErrors = @($result['page']['errors'] | Select-Object -First 8 | ForEach-Object { | |
| 37 | 新增: if ($_ -isnot [System.Collections.IDictionary]) { return } | |
| 38 | 新增: @{ | |
| 39 | 新增: type = ConvertTo-SmokeSafeText $_['type'] | |
| 40 | 新增: source = if ($_['source'] -is [string] -and $_['source'].StartsWith('/')) { ConvertTo-SmokeSafeText $_['source'] } else { '' } | |
| 41 | 新增: message = ConvertTo-SmokeSafeText $_['message'] | |
| 42 | 新增: stack = @($_['stack'] | Select-Object -First 6 | ForEach-Object { ConvertTo-SmokeSafeText $_ }) | |
| 43 | 新增: } | |
| 44 | 新增: }) | |
| 45 | 新增: } | |
| 46 | 新增: # Log only these already-bounded fields, even when the process failed. Do | |
| 47 | 新增: # not print launch entries, page URLs, account data or the raw report. | |
| 48 | 新增: Write-Host ('Cage smoke diagnostic: ' + ($safe | ConvertTo-Json -Depth 6 -Compress)) | |
| 49 | 新增: if ($ExitCode -ne 0 -or $result['success'] -ne $true -or $result['nativeBridgeReady'] -ne $true) { | |
| 50 | 新增: throw "Cage workbench/bridge acceptance failed ($ExitCode), phase $($safe.phase): $($safe.nativeStatus). Diagnostics: $Report" | |
| 51 | 新增: } | |
| 52 | 新增:} | |
| 53 | 新增: | |
| 12 | 54 | function Assert-WindowsWorkbench { |
| 13 | 55 | param([Parameter(Mandatory)][string]$AppDirectory) |
| 14 | 56 | if (-not $IsWindows) { throw 'Workbench acceptance requires Windows.' } |
| 15 | 删除: $testRoot = Join-Path ([IO.Path]::GetTempPath()) ('cage-build-ui-' + [guid]::NewGuid().ToString('N')) | |
| 57 | 新增: $testRoot = Join-Path (Get-WindowsWorkbenchTestBase) ('cage-build-ui-' + [guid]::NewGuid().ToString('N')) | |
| 16 | 58 | New-Item -ItemType Directory -Path $testRoot -Force | Out-Null |
| 17 | 59 | $report = Join-Path $testRoot 'smoke.json' |
| 18 | 60 | $start = [Diagnostics.ProcessStartInfo]::new((Join-Path $AppDirectory 'Cage.exe')) |
| @@ -25,12 +67,7 @@ function Assert-WindowsWorkbench { | ||
| 25 | 67 | $passed = $false |
| 26 | 68 | try { |
| 27 | 69 | if (-not $window.WaitForExit(180000)) { throw "Cage workbench acceptance timed out. Diagnostics retained at $testRoot" } |
| 28 | 删除: if ($window.ExitCode -ne 0 -or -not (Test-Path -LiteralPath $report)) { throw "Cage workbench acceptance failed. Diagnostics retained at $testRoot" } | |
| 29 | 删除: $result = Get-Content -LiteralPath $report -Raw | ConvertFrom-Json | |
| 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 | 删除: } | |
| 70 | 新增: Assert-WindowsWorkbenchReport -ExitCode $window.ExitCode -Report $report | |
| 34 | 71 | $passed = $true |
| 35 | 72 | } finally { |
| 36 | 73 | if (-not $window.HasExited) { $window.Kill($true); $window.WaitForExit() } |
| @@ -0,0 +1,55 @@ | ||
| 1 | 新增:# Cross-platform regression for the real smoke-report and CI artifact contract. | |
| 2 | 新增:. (Join-Path $PSScriptRoot 'windows-common.ps1') | |
| 3 | 新增:$directory = Join-Path ([IO.Path]::GetTempPath()) ('cage-smoke-contract-' + [guid]::NewGuid().ToString('N')) | |
| 4 | 新增:New-Item -ItemType Directory -Path $directory | Out-Null | |
| 5 | 新增:$savedRunnerTemp = $env:RUNNER_TEMP | |
| 6 | 新增:function Assert-SmokeContract([bool]$Condition, [string]$Message) { if (-not $Condition) { throw $Message } } | |
| 7 | 新增:try { | |
| 8 | 新增: $env:RUNNER_TEMP = Join-Path $directory 'runner-temp' | |
| 9 | 新增: Assert-SmokeContract ((Get-WindowsWorkbenchTestBase) -eq [IO.Path]::GetFullPath($env:RUNNER_TEMP)) 'CI report directory ignores RUNNER_TEMP.' | |
| 10 | 新增: Remove-Item Env:RUNNER_TEMP -ErrorAction SilentlyContinue | |
| 11 | 新增: Assert-SmokeContract ((Get-WindowsWorkbenchTestBase) -eq [IO.Path]::GetTempPath()) 'Local report directory lost its OS temp fallback.' | |
| 12 | 新增: $report = Join-Path $directory 'smoke.json' | |
| 13 | 新增: $fixture = Join-Path $directory 'fixture.json' | |
| 14 | 新增: $childScript = Join-Path $directory 'child.ps1' | |
| 15 | 新增: [IO.File]::WriteAllText($childScript, '[IO.File]::Copy($args[0],$args[1],$true); exit 17') | |
| 16 | 新增: @{ | |
| 17 | 新增: success = $false; nativeBridgeReady = $false; phase = 'loading_workbench' | |
| 18 | 新增: nativeStatus = 'failed http://localhost:1234/?token=private-token#private-fragment' | |
| 19 | 新增: entryJSON = 'private-entry'; pageURL = 'http://localhost:1234/#private-launch' | |
| 20 | 新增: page = @{ text = 'private-page-body'; errors = @( | |
| 21 | 新增: @{ type = 'module-load'; source = '/missing.js?session=private-query#private-fragment' }, | |
| 22 | 新增: @{ type = 'error'; source = '/main.js'; message = 'syntax error'; stack = @('at http://localhost:1234/main.js?session=private-query#private-fragment') } | |
| 23 | 新增: ) } | |
| 24 | 新增: } | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath $fixture | |
| 25 | 新增: $start = [Diagnostics.ProcessStartInfo]::new((Get-Process -Id $PID).Path) | |
| 26 | 新增: $start.UseShellExecute = $false | |
| 27 | 新增: foreach ($argument in @('-NoProfile','-NonInteractive','-File',$childScript,$fixture,$report)) { $start.ArgumentList.Add($argument) } | |
| 28 | 新增: $child = [Diagnostics.Process]::Start($start) | |
| 29 | 新增: try { | |
| 30 | 新增: $child.WaitForExit() | |
| 31 | 新增: Assert-SmokeContract ($child.ExitCode -eq 17) 'Failure fixture did not exit unsuccessfully.' | |
| 32 | 新增: $failed = $false | |
| 33 | 新增: $captured = & { | |
| 34 | 新增: try { Assert-WindowsWorkbenchReport -ExitCode $child.ExitCode -Report $report } | |
| 35 | 新增: catch { $script:observedFailure = $_.Exception.Message; Write-Output ('Rejected smoke: ' + $_.Exception.Message) } | |
| 36 | 新增: } 6>&1 | |
| 37 | 新增: $text = ($captured | ForEach-Object { $_.ToString() }) -join "`n" | |
| 38 | 新增: Assert-SmokeContract ($observedFailure -like '*loading_workbench*') 'Failure report was not parsed before rejecting its process exit.' | |
| 39 | 新增: foreach ($expected in @('loading_workbench', 'module-load', '/missing.js', 'syntax error')) { | |
| 40 | 新增: Assert-SmokeContract ($text.Contains($expected)) "Missing safe smoke evidence: $expected" | |
| 41 | 新增: } | |
| 42 | 新增: foreach ($private in @('private-token','private-fragment','private-query','private-entry','private-launch','private-page-body')) { | |
| 43 | 新增: Assert-SmokeContract (-not $text.Contains($private)) "Private smoke field leaked: $private" | |
| 44 | 新增: } | |
| 45 | 新增: } finally { $child.Dispose() } | |
| 46 | 新增: [IO.File]::WriteAllText($report, '{"success":true,"nativeBridgeReady":true}') | |
| 47 | 新增: Assert-WindowsWorkbenchReport -ExitCode 0 -Report $report | |
| 48 | 新增: $rejected = $false | |
| 49 | 新增: try { Assert-WindowsWorkbenchReport -ExitCode 17 -Report $report } catch { $rejected = $true } | |
| 50 | 新增: Assert-SmokeContract $rejected 'Nonzero child exit was accepted because its report said success.' | |
| 51 | 新增: Write-Output 'PASS: RUNNER_TEMP/local selection, real failed child with existing diagnostic, safe evidence logging, and success/exit contract.' | |
| 52 | 新增:} finally { | |
| 53 | 新增: $env:RUNNER_TEMP = $savedRunnerTemp | |
| 54 | 新增: Remove-Item -LiteralPath $directory -Recurse | |
| 55 | 新增:} | |

