diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..3a67f125 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,8 @@ +# An administrator must require code-owner approval and grant the team explicit write access. +/.github/ @openclaw/release-managers-openclaw +/scripts/ @openclaw/release-managers-openclaw +/release-policy.json @openclaw/release-managers-openclaw +/Directory.Build.* @openclaw/release-managers-openclaw +/Directory.Packages.props @openclaw/release-managers-openclaw +/global.json @openclaw/release-managers-openclaw +/src/OpenClaw.Launcher/Package.appxmanifest @openclaw/release-managers-openclaw diff --git a/.github/workflows/gateway-msix.yml b/.github/workflows/gateway-msix.yml index 4a368648..a11e9ac5 100644 --- a/.github/workflows/gateway-msix.yml +++ b/.github/workflows/gateway-msix.yml @@ -271,10 +271,7 @@ jobs: - name: Test Microsoft Store submission shell: pwsh run: | - ./scripts/Test-Submit-MicrosoftStore.Tests.ps1 - ./scripts/Test-StoreFlightSubmission.Tests.ps1 - ./scripts/Test-StoreSubmissionSource.Tests.ps1 - ./scripts/Test-StoreSubmissionWorkflow.Tests.ps1 + ./scripts/Test-Request-MicrosoftStorePublish.Tests.ps1 - name: Test signing workflow configuration shell: pwsh diff --git a/.github/workflows/submit-microsoft-store.yml b/.github/workflows/submit-microsoft-store.yml index 2eb43906..85dbbe77 100644 --- a/.github/workflows/submit-microsoft-store.yml +++ b/.github/workflows/submit-microsoft-store.yml @@ -1,4 +1,4 @@ -name: Submit Microsoft Store +name: Request Microsoft Store publication on: workflow_dispatch: @@ -8,210 +8,48 @@ on: type: string required: true channel: - description: Store destination (must match the release type) + description: Store destination (must match the qualified release type) type: choice options: [production, development] default: production required: true - workflow_run: - workflows: [Build OpenClaw Gateway MSIX] - types: [completed] permissions: contents: read - actions: read concurrency: - group: microsoft-store-submission + group: microsoft-store-request cancel-in-progress: false jobs: - source: + request: if: >- github.repository == 'openclaw/openclaw-windows-packaging' && - github.ref == 'refs/heads/main' && - (github.event_name == 'workflow_dispatch' || - ((vars.MSSTORE_ENABLED == 'true' || vars.MSSTORE_DEVELOPMENT_ENABLED == 'true') && github.event.workflow_run.conclusion == 'success')) + github.ref == 'refs/heads/main' runs-on: ubuntu-latest - outputs: - eligible: ${{ steps.source.outputs.eligible }} - channel: ${{ steps.source.outputs.channel }} - artifact_id: ${{ steps.source.outputs.artifact_id }} - bundle_name: ${{ steps.source.outputs.bundle_name }} - bundle_sha256: ${{ steps.source.outputs.bundle_sha256 }} steps: - - uses: actions/checkout@v7 - with: - persist-credentials: false - - name: Resolve authorized release artifact - id: source - shell: pwsh - env: - GH_TOKEN: ${{ github.token }} - REQUESTED_CHANNEL: ${{ inputs.channel || 'auto' }} - PRODUCTION_ENABLED: ${{ vars.MSSTORE_ENABLED }} - DEVELOPMENT_ENABLED: ${{ vars.MSSTORE_DEVELOPMENT_ENABLED }} - SOURCE_RUN_ID: ${{ inputs.run_id || github.event.workflow_run.id }} - run: | - $source = ./scripts/Get-StoreSubmissionSource.ps1 -RunId $env:SOURCE_RUN_ID -Channel $env:REQUESTED_CHANNEL - if ($null -eq $source) { - if ($env:GITHUB_EVENT_NAME -eq 'workflow_dispatch') { throw 'The selected run is not an eligible Store release.' } - 'eligible=false' >> $env:GITHUB_OUTPUT - exit 0 - } - $enabled = if ($source.channel -ceq 'development') { $env:DEVELOPMENT_ENABLED } else { $env:PRODUCTION_ENABLED } - if ($env:GITHUB_EVENT_NAME -ne 'workflow_dispatch' -and $enabled -cne 'true') { - 'eligible=false' >> $env:GITHUB_OUTPUT - exit 0 - } - "channel=$($source.channel)" >> $env:GITHUB_OUTPUT - 'eligible=true' >> $env:GITHUB_OUTPUT - "artifact_id=$($source.artifactId)" >> $env:GITHUB_OUTPUT - "bundle_name=$($source.bundleName)" >> $env:GITHUB_OUTPUT - "bundle_sha256=$($source.bundleSha256)" >> $env:GITHUB_OUTPUT - "Store source: run $env:SOURCE_RUN_ID, artifact $($source.artifactId), bundle $($source.bundleName)" >> $env:GITHUB_STEP_SUMMARY - - submit-microsoft-store: - needs: source - if: needs.source.outputs.eligible == 'true' - runs-on: ubuntu-latest - environment: microsoft-store - timeout-minutes: 60 - permissions: - contents: read - actions: read - id-token: write - steps: - - name: Check out repository - uses: actions/checkout@v7 - with: - persist-credentials: false - - - name: Download verified Store bundle - uses: actions/download-artifact@v8 - with: - artifact-ids: ${{ needs.source.outputs.artifact_id }} - run-id: ${{ inputs.run_id || github.event.workflow_run.id }} - github-token: ${{ github.token }} - merge-multiple: true - path: store - - - name: Validate Microsoft Store environment - shell: pwsh - env: - MSSTORE_TENANT_ID: ${{ vars.MSSTORE_TENANT_ID }} - MSSTORE_CLIENT_ID: ${{ vars.MSSTORE_CLIENT_ID }} - MSSTORE_APPLICATION_ID: ${{ vars.MSSTORE_APPLICATION_ID }} - STORE_CHANNEL: ${{ needs.source.outputs.channel }} - MSSTORE_DEVELOPMENT_FLIGHT_ID: ${{ vars.MSSTORE_DEVELOPMENT_FLIGHT_ID }} - run: | - if ($env:STORE_CHANNEL -ceq 'development') { - $flightId = [guid]::Empty - if (-not [guid]::TryParse($env:MSSTORE_DEVELOPMENT_FLIGHT_ID, [ref]$flightId)) { - throw 'The microsoft-store environment is missing a valid MSSTORE_DEVELOPMENT_FLIGHT_ID.' - } - } - foreach ($name in @( - 'MSSTORE_TENANT_ID' - 'MSSTORE_CLIENT_ID' - 'MSSTORE_APPLICATION_ID' - )) { - if ([string]::IsNullOrWhiteSpace([Environment]::GetEnvironmentVariable($name))) { - throw "The microsoft-store environment is missing $name." - } - } - foreach ($name in @('MSSTORE_TENANT_ID', 'MSSTORE_CLIENT_ID')) { - $value = [Environment]::GetEnvironmentVariable($name) - $parsed = [guid]::Empty - if (-not [guid]::TryParse($value, [ref]$parsed)) { - throw "$name must be a GUID." - } - } - - name: Request short-lived Microsoft Store assertion - id: oidc - shell: pwsh - run: | - $policy = Get-Content -LiteralPath .\store-submission.json -Raw | - ConvertFrom-Json - $requestUrl = $env:ACTIONS_ID_TOKEN_REQUEST_URL - $requestToken = $env:ACTIONS_ID_TOKEN_REQUEST_TOKEN - if ([string]::IsNullOrWhiteSpace($requestUrl) -or - [string]::IsNullOrWhiteSpace($requestToken)) { - throw 'GitHub did not provide an OIDC token endpoint.' - } - $oidcRequestUri = .\scripts\New-GitHubOidcRequestUri.ps1 ` - -RequestUri $requestUrl ` - -Audience ([string]$policy.oidcAudience) - $response = Invoke-RestMethod ` - -Headers @{ Authorization = "Bearer $requestToken" } ` - -Uri $oidcRequestUri - $assertion = [string]$response.value - if ([string]::IsNullOrWhiteSpace($assertion)) { - throw 'GitHub returned an empty OIDC assertion.' - } - Write-Output "::add-mask::$assertion" - $assertionPath = Join-Path $env:RUNNER_TEMP 'msstore-assertion.jwt' - [IO.File]::WriteAllText($assertionPath, $assertion) - & chmod 600 $assertionPath - if ($LASTEXITCODE -ne 0) { - throw 'Unable to restrict the OIDC assertion file permissions.' - } - "assertion_path=$assertionPath" >> $env:GITHUB_OUTPUT - - - name: Submit bundle and commit Store update - shell: pwsh - env: - MSSTORE_TENANT_ID: ${{ vars.MSSTORE_TENANT_ID }} - MSSTORE_CLIENT_ID: ${{ vars.MSSTORE_CLIENT_ID }} - MSSTORE_APPLICATION_ID: ${{ vars.MSSTORE_APPLICATION_ID }} - STORE_CHANNEL: ${{ needs.source.outputs.channel }} - MSSTORE_DEVELOPMENT_FLIGHT_ID: ${{ vars.MSSTORE_DEVELOPMENT_FLIGHT_ID }} - MSSTORE_ASSERTION_FILE: ${{ steps.oidc.outputs.assertion_path }} - EXPECTED_BUNDLE_NAME: ${{ needs.source.outputs.bundle_name }} - EXPECTED_BUNDLE_SHA256: ${{ needs.source.outputs.bundle_sha256 }} - run: | - $identityDocument = Get-Content ./release-policy.json -Raw | ConvertFrom-Json - $identityName = [string]$identityDocument.packageIdentityName - $publisher = [string]$identityDocument.publisher - $bundle = @(Get-ChildItem ./store -File -Filter *.msixbundle) - if ($bundle.Count -ne 1 -or $bundle[0].Name -cne $env:EXPECTED_BUNDLE_NAME) { - throw 'Downloaded Store artifact must contain the selected bundle.' - } - if ($env:EXPECTED_BUNDLE_SHA256 -cnotmatch '^[0-9a-f]{64}$' -or - (Get-FileHash $bundle[0].FullName -Algorithm SHA256).Hash.ToLowerInvariant() -cne $env:EXPECTED_BUNDLE_SHA256) { - throw 'Store bundle does not match the release witness.' - } - $destination = @{ Channel = $env:STORE_CHANNEL } - if ($env:STORE_CHANNEL -ceq 'development') { $destination.FlightId = $env:MSSTORE_DEVELOPMENT_FLIGHT_ID } - .\scripts\Submit-MicrosoftStore.ps1 @destination ` - -BundlePath $bundle[0].FullName ` - -ApplicationId $env:MSSTORE_APPLICATION_ID ` - -PackageIdentityName $identityName -Publisher $publisher ` - -TenantId $env:MSSTORE_TENANT_ID ` - -ClientId $env:MSSTORE_CLIENT_ID ` - -ClientAssertionFile $env:MSSTORE_ASSERTION_FILE ` - -PolicyPath .\store-submission.json ` - -EvidencePath .\evidence\store-submission.json - - - name: Upload Store submission evidence - if: ${{ always() }} - continue-on-error: true - uses: actions/upload-artifact@v7 - with: - name: openclaw-gateway-store-submission-evidence - path: evidence/store-submission.json - if-no-files-found: error - retention-days: 90 - - - name: Remove short-lived assertion - if: ${{ always() }} - shell: pwsh - env: - MSSTORE_ASSERTION_FILE: ${{ steps.oidc.outputs.assertion_path }} - run: | - if (-not [string]::IsNullOrWhiteSpace($env:MSSTORE_ASSERTION_FILE)) { - Remove-Item ` - -LiteralPath $env:MSSTORE_ASSERTION_FILE ` - -Force ` - -ErrorAction SilentlyContinue - } + - name: Check out request adapter + uses: actions/checkout@v7 + with: + persist-credentials: false + + - name: Mint request-only release token + id: release-token + uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 + with: + app-id: 2729701 + private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} + owner: openclaw + repositories: releases + permission-actions: write + + - name: Request release-manager-approved Store publication + shell: pwsh + env: + GH_TOKEN: ${{ steps.release-token.outputs.token }} + SOURCE_RUN_ID: ${{ inputs.run_id }} + STORE_CHANNEL: ${{ inputs.channel }} + run: | + $request = ./scripts/Request-MicrosoftStorePublish.ps1 -RunId $env:SOURCE_RUN_ID -Channel $env:STORE_CHANNEL + "Store $($request.channel) publication requested for Gateway source run $($request.sourceRunId)." >> $env:GITHUB_STEP_SUMMARY + 'Follow [Windows Store publication](https://github.com/openclaw/releases/actions/workflows/windows-store-publish.yml) for release-manager approval and the Store receipt. This request is not Store acceptance.' >> $env:GITHUB_STEP_SUMMARY diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e398de20..fe69e63e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -85,7 +85,7 @@ or package version logic: .\scripts\Test-WorkflowSigningConfiguration.ps1 .\scripts\Test-MSIXUpgradeMatrix.Tests.ps1 .\scripts\Test-WorkflowPackageVersion.Tests.ps1 -.\scripts\Test-Submit-MicrosoftStore.Tests.ps1 +.\scripts\Test-Request-MicrosoftStorePublish.Tests.ps1 .\scripts\Test-GitHooks.Tests.ps1 ``` @@ -455,6 +455,13 @@ Three project skills in `.github\skills\` support this work: ## Pull requests +Release automation, its dependencies, and package identity inputs are owned by +`@openclaw/release-managers-openclaw` in `.github\CODEOWNERS`. Administrators must +grant the team explicit write access and enforce code-owner approval on `main`; +the file alone does not protect changes. Store publication additionally needs the +central environment and exclusive federation described in the +[Store cutover guide](docs/microsoft-store.md#activate-the-centralized-publisher). + Use the pull request template. Title the PR `type: user-facing description`, where `type` is one of `feat`, `fix`, `improve`, `refactor`, `docs`, or `chore`. Describe the outcome rather than the diff --git a/docs/local-development.md b/docs/local-development.md index 58a4c385..4b800b2d 100644 --- a/docs/local-development.md +++ b/docs/local-development.md @@ -517,6 +517,8 @@ Run PowerShell policy suites by owning surface rather than indiscriminately: `Test-WorkflowSigningConfiguration.ps1` for source capture, retry context, cache routing, and selected-build outcomes, `Test-MSIXUpgradeMatrix.Tests.ps1` for parallel upgrade scenario selection, +`Test-Request-MicrosoftStorePublish.Tests.ps1` for the request-only central Store +handoff (synthetic command fixtures, never a live dispatch), `Test-Deploy-LocalPackage.Tests.ps1` for the loose-registration flow, and `Test-Sign-TestMSIX.Tests.ps1` for test signing. The Node input suite requires Node.js and npm; its local fixture exercises the approved OpenClaw install hook, diff --git a/docs/microsoft-store.md b/docs/microsoft-store.md index baf931c3..9bdae1ec 100644 --- a/docs/microsoft-store.md +++ b/docs/microsoft-store.md @@ -1,159 +1,137 @@ -# Submit a release to Microsoft Store - -Use this guide to submit an already validated release bundle, retry a failed -Store delivery without rebuilding, or enable automatic Store delivery. This -workflow does not change signing, release approval, or install/upgrade acceptance. -GitHub releases and the existing unsigned Store artifact handoff remain available. - -## Configure the publishing identity - -1. Link the correct Microsoft Entra tenant to Partner Center. Add a dedicated - Entra application to Partner Center with the **Manager (Windows)** role. - The Store product must already have a completed, published first submission - and completed age ratings. Do not reuse the Azure code-signing identity. -2. Add one federated credential to that Entra application: - - Issuer: `https://token.actions.githubusercontent.com` - - Audience: `api://AzureADTokenExchange` - - Subject: `repo:openclaw@252820863/openclaw-windows-packaging@1347889239:environment:microsoft-store` - Verify the repository's current OIDC subject configuration before provisioning; - immutable-subject settings affect the exact subject. The dedicated application - must have no client secrets, certificates, or other federated writers. -3. In the repository's **Settings > Environments > microsoft-store**, set these - environment variables (not secrets): - - `MSSTORE_TENANT_ID`: Entra tenant GUID. - - `MSSTORE_CLIENT_ID`: dedicated application's client GUID. - - `MSSTORE_APPLICATION_ID`: Partner Center Store product ID, not the client GUID. -4. Allow deployments from the `main` **branch** in this environment. The submission - workflow always runs trusted main code, including when it consumes a tag's - bundle. Restrict the environment to main, and configure release-owner approval - if required by your publishing policy. Tag-only protection will block this job. -5. Leave the repository variable `MSSTORE_ENABLED` unset until the first manual - submission and the required Store install/upgrade acceptance have succeeded. - No persistent Store password is required. - -## Submit manually - -Merge the workflow onto main first. Select the successful run ID for a main-branch **Build OpenClaw Gateway MSIX** dispatch in `store` or `official` mode. -The ID is the number after `/actions/runs/` in its URL. The source run must have -completed successfully and retained its unexpired authorized Store bundle. - -From **Actions > Submit Microsoft Store > Run workflow**, select `main` and -enter `run_id`. The equivalent CLI command is: +# Request Gateway publication to Microsoft Store + +The packaging repository builds and retains the authorized Gateway Store bundle. +Store publication runs only in `openclaw/releases`, where a release manager must +approve the exact candidate before the job can request a Microsoft Store token. +The local **Request Microsoft Store publication** workflow is a manual recovery +adapter; it cannot upload or commit a Store submission. + +## Activate the centralized publisher + +Land and configure the centralized publisher before merging the request-only +cutover. Its workflow is +[`windows-store-publish.yml`](https://github.com/openclaw/releases/blob/main/.github/workflows/windows-store-publish.yml), +and its [publishing guide](https://github.com/openclaw/releases/blob/main/docs/windows-store-publishing.md) +owns approval, identity policy, source authorization, Store receipts, and recovery. +Those links require the coordinated central change to land first. + +An administrator must complete and verify these separate changes: + +1. In `openclaw/releases`, configure the `microsoft-store-gateway` environment + for the exact `main` branch, require + `@openclaw/release-managers-openclaw` approval, and disable administrator + deployment bypass. Keep the central source-validation job credential-free; + only the approved publisher job may request Store OIDC tokens. +2. Grant that team explicit repository write access and enforce code-owner review + on `main` in both repositories, including new commits after approval and the + workflow, publisher dependencies, identity policies, and CODEOWNERS itself. + This repository's CODEOWNERS file declares the owners; it does not enable or + enforce a GitHub branch rule. +3. Install the existing release GitHub App (ID `2729701`) for `openclaw/releases` + with Actions write access. Make its existing `GH_APP_PRIVATE_KEY` available + to this repository's manual request workflow. The minted token is scoped to + the `releases` repository and Actions write; it does not grant Store access. +4. Move the dedicated Gateway Partner Center application's federation to the + central Gateway environment. Verify the exact subject against the central + repository's current OIDC subject configuration. Remove the old packaging + `microsoft-store` federated credential and any other publishing writer; an + old trusted workflow revision otherwise remains a bypass. Keep the dedicated + Store application separate from the unchanged Azure sideload-signing identity. +5. Move the Gateway flight GUID into the central repository variable + `MSSTORE_GATEWAY_DEVELOPMENT_FLIGHT_ID`. After manual qualification, use the + central `MSSTORE_GATEWAY_DEVELOPMENT_ENABLED` activation flag. Remove obsolete + native Store environment variables and both `MSSTORE_ENABLED` and + `MSSTORE_DEVELOPMENT_ENABLED` toggles after the cutover. Do not start a legacy publisher while + changing its cloud trust, and reconcile any in-flight submission first. + +No new PAT or persistent Store client secret is required. GitHub App availability, +team permissions, environment review rules, branch rules, and exclusive Entra +federation are administrative prerequisites, not guarantees made by this YAML. +The centralized implementation and these settings are a merge/cutover dependency; +this document does not claim they have already been activated. + +## Request publication manually + +Choose the successful run ID for a canonical main-branch **Build OpenClaw Gateway +MSIX** dispatch in `store` or `official` mode. It must have completed successfully +and retained the unexpired `openclaw-gateway-msix-store-submission-` +bundle and `store-release-source-` witness. The +central publisher independently authorizes the run and validates the exact bundle; +the request adapter does not make an eligibility decision. + +From **Actions > Request Microsoft Store publication > Run workflow**, select +`main`, enter `run_id`, and select `production` for stable or `development` for +a published beta. The equivalent Development-flight command is: ```powershell gh workflow run submit-microsoft-store.yml ` --repo openclaw/openclaw-windows-packaging --ref main ` - -f run_id=RELEASE_RUN_ID + -f run_id=RELEASE_RUN_ID -f channel=development ``` -Manual dispatch deliberately does not require `MSSTORE_ENABLED`. It uses the same -source checks, protected environment, OIDC identity, and publisher as automatic -submission. It never rebuilds a package or republishes the GitHub release. +This sends `{product: gateway, run_id: RELEASE_RUN_ID, channel, automatic: false}` to the standalone central +workflow on `main`. Follow the central run for its source commit, version, +run/attempt, and bundle hash, then release-manager approval and Store receipt. +A successful request means GitHub accepted the request, not that Microsoft +accepted a bundle or completed certification. No package is rebuilt, no GitHub +release is republished, and no Store token is minted here. -Only the multi-architecture Store `.msixbundle` is uploaded. The publisher checks -its identity against repository policy and the actual Partner Center product -before creating a draft. It preserves listing, pricing, availability, and other -product metadata while replacing the packages with the selected bundle. +## Automatic requests and recovery -## Enable automatic delivery +This repository has no `workflow_run` Store trigger and no automatic-publication +variable. Gateway's upstream release tooling can request the centralized publisher +after building the exact released source; it must not also dispatch this manual +recovery adapter for the same candidate. Manual recovery and automatic callers +share the central publisher's approval and replay policy, not a second local +publisher. -After the manual rehearsal and release acceptance, set the **repository** Actions -variable `MSSTORE_ENABLED` to `true`. It must be repository-scoped because the -source job checks it before entering the protected environment. Successful eligible -release runs then trigger **Submit Microsoft Store** through `workflow_run`. -PRs, ordinary main builds, failed runs, and unrelated prereleases do not submit. Ineligible -automatic runs are skipped; selecting an ineligible run manually fails explicitly. +## Development flight -Remove the variable or set it to `false` to pause future automatic submissions. -This does not cancel a submission already in progress. Both manual and automatic -runs share one concurrency group and never cancel an active Store upload. +The coordinated core release handoff requests `channel=production` after stable +builds and `channel=development` after beta builds, with `automatic=true`. +Beta builds use `official` mode and publish their signed GitHub prerelease before +retaining the separate unsigned Store bundle and attempt-bound witness. +The central publisher checks that published prerelease and keeps Development +delivery in its configured flight, never in the public production submission. +Both destinations require release-manager approval. A Store flight is an opt-in +update path for enrolled Microsoft Store accounts, not a separate public `/beta` +listing; sideload GitHub packages retain their separate identity. + +Before activating automatic Development delivery, finish or explicitly resolve +the initial flight draft, qualify a manual submission, and verify certification +plus a tester's Store install/upgrade and retained data. Leave the central +activation flag unset until then. Its +[administrator guide](https://github.com/openclaw/releases/blob/main/docs/windows-store-publishing.md) +owns the flight GUID, activation, approval policy, and API execution. No new Store +credential or per-flight federation is introduced by this adapter. ## Verify and recover -A successful submission means Partner Center returned `CommitStarted`, not that -certification or public rollout has finished. Retain the Store workflow URL and -its 90-day submission evidence artifact. The evidence includes the bundle SHA-256, -product ID, exact submission ID, metadata hashes, and commit acceptance. Follow -certification and publication in Partner Center before declaring Store delivery -complete. The current policy requests a 100% package rollout and preserves the -product's publication mode, including manual or scheduled publication. - -Before dispatch, finish or explicitly discard any existing draft in Partner -Center. Automation rejects existing drafts and never replaces them. Do not edit -an API-created draft in the portal while automation runs. A failure before commit -can remove only the draft created by this run. A lost or ambiguous commit response -preserves that draft: inspect Partner Center before retrying. Never blindly rerun -a submission that may already have been accepted. If the release artifact expired, -use the release process to produce and validate a new candidate. - -See Microsoft's [submission API](https://learn.microsoft.com/en-us/windows/uwp/monetize/manage-app-submissions) -and [application identity resource](https://learn.microsoft.com/en-us/windows/uwp/monetize/get-app-data). - -## Development flight - -The same protected publisher sends published beta Gateway MSIX GitHub prereleases -to a **Development** package flight, never to the public production submission. -Stable releases still use the production destination and its separate activation flag. - -1. In Partner Center, create a known-user group named **OpenClaw Development - Testers**. Add each tester's Microsoft account email address, which must be the - account they use in Microsoft Store. -2. From the product overview, create a **Development** package flight and select - that group. Flights belong to a product: Companion and Gateway require their - own flight even when they share the tester group. -3. Set `MSSTORE_DEVELOPMENT_FLIGHT_ID` in the existing `microsoft-store` - environment to the flight GUID. This is not the numeric submission ID in the - portal URL. Use the Store API's - [list flights](https://learn.microsoft.com/en-us/windows/uwp/monetize/get-flights-for-an-app) - response to verify the GUID, product and group. -4. Finish the portal-created initial draft with a qualified Store bundle before - using automation, or explicitly discard that draft. The publisher refuses - to adopt or delete a pre-existing draft, including an empty initial one. -5. After this workflow lands on main, manually dispatch **Submit Microsoft - Store**, specifying the eligible release `run_id` and `channel=development`. - Selecting a stable run for Development, or a preview run for production, fails. -6. Verify certification, flight publication and a tester's actual Store - install/upgrade. Then set the **repository** variable - `MSSTORE_DEVELOPMENT_ENABLED=true`. Leave it unset or `false` until that proof. - Production's `MSSTORE_ENABLED` remains independent. - -Testers install/update the normal Store listing while signed into the enrolled -Microsoft account; there is no separate public preview listing. Enrollment and -certification can take time. Leaving a flight does not downgrade an installed -newer package: wait for production to catch up or follow the documented -data-preserving recovery guidance for the product. - -Both channels share the existing submission concurrency group and OIDC -application. No new credential or broader GitHub environment access is needed. -The evidence records `channel` and `flightId`. Flight submissions preserve the -flight's publishing settings, replace only its packages, and do not edit the -production listing or its draft. A first API-created flight submission preserves -the new draft's defaults when no published flight baseline exists. - -## Source binding - -The source must be the canonical main release workflow's successful manual -dispatch. Its `openclaw-gateway-msix-store-submission-` bundle and -`store-release-source-` witness must both be unexpired. The witness -binds the run, current attempt, packaging commit, release channel, exact bundle -filename and SHA-256. Old runs without this witness are not eligible. -Development additionally requires the matching published GitHub prerelease and -tag commit; run `official` mode with `publish_release=true`. Stable Store-only -dispatches remain eligible for production. Signed sideload bundles are never -Store inputs. - -### Store package versions - -Store packages use `year.month.(10000 + github.run_number).0` for both stable -and preview releases. The year and month come from the captured release -identity, not the payload compatibility pin or wall clock. The offset exceeds -all versions from the previous scheme (third component at most 9999). The -workflow run number orders releases within a month; retries retain the same -number and immutable source snapshot. A previous month's stable release can -remain below a next-month flight; leaving the flight does not downgrade it. - -Run numbers must be 1 through 55534. Exhaustion fails explicitly; do not reset, -wrap, or rename the release workflow to reset its counter. A future allocation -migration must preserve installed-package ordering. Independent Store and -sideload composition keeps each binary's compiled CLI version consistent with -its manifest. GitHub sideload version numbering does not change. +Before retrying an uncertain request, inspect the central runs and Partner Center +state. A central receipt containing `CommitStarted` proves commit acceptance, +not certification or public availability. Preserve the central workflow URL and +submission evidence, and follow certification in Partner Center. Do not blindly +retry an accepted or ambiguous submission, overwrite an existing draft, or edit +an API-created draft while the publisher runs. If the source artifact expired, +produce and validate a new candidate using the +[release process](release-process.md). + +The unsigned multi-architecture Store bundle and its build/upgrade evidence remain +owned by this repository. Signed sideload release assets are not Store inputs. +The packaging repository no longer contains a Store API engine, Store submission +policy, or Store source authorizer; centrally reviewed code owns those decisions. + +## Store package versions + +Store bundles keep the builder's shared stable/beta sequence: +`year.month.(10000 + github.run_number).0`. The year and month come from the +captured release identity, not the payload compatibility pin or wall clock. +Run numbers must stay within `1..55534`; retries reuse the same allocated version. +Do not reset or rename the release workflow to reset its counter. The offset +keeps these packages above the earlier source-derived range; leaving a newer +flight does not downgrade an installation to an older production package. + +[`Get-WorkflowPackageVersion.ps1`](../scripts/Get-WorkflowPackageVersion.ps1) +owns allocation and bounds. Store and sideload composition remain independent +so compiled CLI versions match their manifests. The central publisher neither +allocates another version nor rebuilds these bundles. diff --git a/docs/release-process.md b/docs/release-process.md index 6cea060f..ef59895a 100644 --- a/docs/release-process.md +++ b/docs/release-process.md @@ -312,10 +312,12 @@ authorized disposition is backed by actual platform denial evidence. Cache deletion, dispatch, alert disposition, signing, and publication are separate authorized operations, not part of local implementation validation. -## Automated Store submission - -See [Microsoft Store submission](microsoft-store.md) for protected OIDC setup, -manual submission, the Development tester group and flight, automatic activation, -and recovery. Production uses `MSSTORE_ENABLED`; Development uses the independent -`MSSTORE_DEVELOPMENT_ENABLED` flag. Neither flag substitutes for first-submission -certification and tester install/upgrade proof. +## Store publication requests + +See [Microsoft Store publication](microsoft-store.md) for the central approval +cutover, manual requests, the Development tester group/flight, activation, and +recovery. The coordinated upstream handoff requests production for stable and +Development for beta. The central publisher owns activation and release-manager +approval; this repository keeps only a manual request adapter, not a Store API +engine or automatic trigger. Development activation still requires manual +submission, certification, and tester install/upgrade proof. diff --git a/scripts/Get-StoreSubmissionSource.ps1 b/scripts/Get-StoreSubmissionSource.ps1 deleted file mode 100644 index 1993a220..00000000 --- a/scripts/Get-StoreSubmissionSource.ps1 +++ /dev/null @@ -1,82 +0,0 @@ -[CmdletBinding()] -param( - [Parameter(Mandatory)][ValidatePattern('^[1-9][0-9]*$')][string]$RunId, - [ValidateSet('auto', 'production', 'development')][string]$Channel = 'production', - [scriptblock]$ApiInvoker, - [scriptblock]$DownloadInvoker -) -Set-StrictMode -Version Latest -$ErrorActionPreference = 'Stop' -$Channel = $Channel.ToLowerInvariant() -$repository = 'openclaw/openclaw-windows-packaging' -if ($null -eq $ApiInvoker) { - $ApiInvoker = { - param($Path) - $json = & gh api --paginate --slurp "repos/$repository/$Path" - if ($LASTEXITCODE -ne 0) { throw 'Unable to read Store source provenance from GitHub.' } - return @($json | ConvertFrom-Json) - } -} -if ($null -eq $DownloadInvoker) { - $DownloadInvoker = { - param($Name, $Directory) - & gh run download $RunId --repo $repository --name $Name --dir $Directory - if ($LASTEXITCODE -ne 0) { throw 'Unable to download Store release witness.' } - } -} -$run = @(& $ApiInvoker "actions/runs/$RunId")[0] - -if ($run.path -cne '.github/workflows/gateway-msix.yml' -or - $run.event -cne 'workflow_dispatch' -or $run.head_branch -cne 'main') { return $null } -if ($run.repository.full_name -cne $repository -or $run.head_repository.full_name -cne $repository -or - [string]$run.id -cne $RunId -or $run.status -cne 'completed' -or $run.conclusion -cne 'success') { - throw 'Store submission requires a successful completed run in the canonical repository.' -} -$pages = @(& $ApiInvoker "actions/runs/$RunId/artifacts?per_page=100") -$artifacts = @($pages | ForEach-Object { $_.artifacts }) -$selected = @($artifacts | Where-Object name -CEQ "openclaw-gateway-msix-store-submission-$($run.run_attempt)") -if ($selected.Count -eq 0) { return $null } -if ($selected.Count -ne 1 -or $selected[0].expired) { throw 'Store bundle artifact is ambiguous or expired.' } -$witnessName = "store-release-source-$($run.run_attempt)" -$witnessArtifacts = @($artifacts | Where-Object name -CEQ $witnessName) -if ($witnessArtifacts.Count -ne 1 -or $witnessArtifacts[0].expired) { - throw 'The release run has no current, unexpired Store release witness.' -} -$directory = Join-Path ([IO.Path]::GetTempPath()) "store-source-$([guid]::NewGuid().ToString('N'))" -New-Item $directory -ItemType Directory | Out-Null -try { - & $DownloadInvoker $witnessName $directory | Out-Null - $witness = Get-Content (Join-Path $directory 'store-source.json') -Raw | ConvertFrom-Json - if ([string]$witness.runId -cne $RunId -or [int]$witness.runAttempt -ne [int]$run.run_attempt -or - $witness.packagingCommit -cne $run.head_sha -or $witness.packagingCommit -cnotmatch '^[0-9a-f]{40}$' -or - $witness.releaseChannel -cnotin @('stable', 'beta') -or - $witness.bundleSha256 -cnotmatch '^[0-9a-f]{64}$') { - throw 'Store release witness does not match this run and attempt.' - } - $preview = $witness.releaseChannel -cne 'stable' - $tagPattern = if ($preview) { - '^v[0-9]{4}\.[0-9]+\.[0-9]+-' + $witness.releaseChannel + '\.[1-9][0-9]*-msix\.[0-9]$' - } else { '^v[0-9]{4}\.[0-9]+\.[0-9]+(?:-[2-9])?-msix\.[0-9]$' } - if ($witness.releaseTag -cnotmatch $tagPattern -or - $witness.bundleName -cne "OpenClawGateway-$($witness.releaseTag.Substring(1))-store.msixbundle") { - throw 'Store release witness contains an invalid release identity or bundle name.' - } - $selectedChannel = if ($preview) { 'development' } else { 'production' } - if ($Channel -cne 'auto' -and $Channel -cne $selectedChannel) { return $null } - if ($preview) { - $release = @(& $ApiInvoker "releases/tags/$($witness.releaseTag)")[0] - $commit = @(& $ApiInvoker "commits/$($witness.releaseTag)")[0] - if ($release.draft -or -not $release.prerelease -or -not $release.published_at -or - $release.tag_name -cne $witness.releaseTag -or $commit.sha -cne $run.head_sha) { - throw 'Development delivery requires the published GitHub prerelease at this packaging commit.' - } - } - $bundleName = [string]$witness.bundleName - $bundleSha256 = [string]$witness.bundleSha256 -} finally { Remove-Item $directory -Recurse -Force } -[pscustomobject]@{ - channel = $selectedChannel - artifactId = [string]$selected[0].id - bundleName = $bundleName - bundleSha256 = $bundleSha256 -} diff --git a/scripts/New-GitHubOidcRequestUri.ps1 b/scripts/New-GitHubOidcRequestUri.ps1 deleted file mode 100644 index 303af7f3..00000000 --- a/scripts/New-GitHubOidcRequestUri.ps1 +++ /dev/null @@ -1,28 +0,0 @@ -[CmdletBinding()] -param( - [Parameter(Mandatory)] - [uri]$RequestUri, - - [Parameter(Mandatory)] - [string]$Audience -) - -Set-StrictMode -Version Latest -$ErrorActionPreference = 'Stop' - -if (-not $RequestUri.IsAbsoluteUri) { - throw 'The GitHub OIDC request URI must be absolute.' -} -if ([string]::IsNullOrWhiteSpace($Audience)) { - throw 'The GitHub OIDC audience must not be empty.' -} - -$requestText = $RequestUri.AbsoluteUri -$separator = if ($requestText.Contains('?')) { - if ($requestText.EndsWith('?') -or $requestText.EndsWith('&')) { '' } else { '&' } -} -else { - '?' -} - -"${requestText}${separator}audience=$([Uri]::EscapeDataString($Audience))" diff --git a/scripts/Request-MicrosoftStorePublish.ps1 b/scripts/Request-MicrosoftStorePublish.ps1 new file mode 100644 index 00000000..6816ad40 --- /dev/null +++ b/scripts/Request-MicrosoftStorePublish.ps1 @@ -0,0 +1,43 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory)][ValidatePattern('\A[1-9][0-9]*\z')][string]$RunId, + [ValidateSet('production', 'development')][string]$Channel = 'production', + [string]$Repository = $env:GITHUB_REPOSITORY, + [string]$GitHubRef = $env:GITHUB_REF, + [string]$EventName = $env:GITHUB_EVENT_NAME, + [scriptblock]$CommandInvoker +) + +Set-StrictMode -Version Latest +$ErrorActionPreference = 'Stop' +$Channel = $Channel.ToLowerInvariant() + +if ($Repository -cne 'openclaw/openclaw-windows-packaging' -or + $GitHubRef -cne 'refs/heads/main' -or + $EventName -cne 'workflow_dispatch') { + throw 'Store publication requests require a manual dispatch from the canonical main branch.' +} + +if ($null -eq $CommandInvoker) { + $CommandInvoker = { + param([string[]]$CommandArguments) + & gh @CommandArguments + if ($LASTEXITCODE -ne 0) { + throw 'Store publication request was not confirmed. Inspect openclaw/releases before retrying.' + } + } +} + +$commandArguments = @( + 'workflow', 'run', 'windows-store-publish.yml', + '--repo', 'openclaw/releases', '--ref', 'main', + '-f', 'product=gateway', '-f', "run_id=$RunId", '-f', "channel=$Channel", '-f', 'automatic=false' +) +& $CommandInvoker $commandArguments | Out-Null + +[pscustomobject]@{ + product = 'gateway' + sourceRunId = $RunId + channel = $Channel + status = 'requested' +} diff --git a/scripts/Submit-MicrosoftStore.ps1 b/scripts/Submit-MicrosoftStore.ps1 deleted file mode 100644 index e4c7d2a3..00000000 --- a/scripts/Submit-MicrosoftStore.ps1 +++ /dev/null @@ -1,466 +0,0 @@ -[CmdletBinding()] -param( - [Parameter(Mandatory)][string]$BundlePath, - [Parameter(Mandatory)][string]$ApplicationId, - [ValidateSet('production', 'development')][string]$Channel = 'production', - [string]$FlightId, - [Parameter(Mandatory)][string]$PackageIdentityName, - [Parameter(Mandatory)][string]$Publisher, - [Parameter(Mandatory)][guid]$TenantId, - [Parameter(Mandatory)][guid]$ClientId, - [Parameter(Mandatory)][string]$ClientAssertionFile, - [string]$PolicyPath = (Join-Path (Split-Path $PSScriptRoot -Parent) 'store-submission.json'), - [string]$EvidencePath, - [scriptblock]$HttpInvoker, - [scriptblock]$UploadInvoker -) - -Set-StrictMode -Version Latest -$ErrorActionPreference = 'Stop' -$Channel = $Channel.ToLowerInvariant() -$isFlight = $Channel -ceq 'development' -$parsedFlightId = [guid]::Empty -if ($isFlight -and -not [guid]::TryParse($FlightId, [ref]$parsedFlightId)) { - throw 'Development submission requires the configured flight ID.' -} -if (-not $isFlight -and -not [string]::IsNullOrWhiteSpace($FlightId)) { - throw 'Production submission must not specify a flight ID.' -} -$packagesProperty = if ($isFlight) { 'FlightPackages' } else { 'ApplicationPackages' } -$pendingProperty = if ($isFlight) { 'PendingFlightSubmission' } else { 'PendingApplicationSubmission' } -$publishedProperty = if ($isFlight) { 'LastPublishedFlightSubmission' } else { 'LastPublishedApplicationSubmission' } - -function Assert-NonEmptyValue { - param([Parameter(Mandatory)][string]$Name, [AllowEmptyString()][string]$Value) - if ([string]::IsNullOrWhiteSpace($Value)) { throw "$Name must not be empty." } -} - -function Get-RequiredProperty { - param([Parameter(Mandatory)][object]$Object, [Parameter(Mandatory)][string]$Name) - $property = $Object.PSObject.Properties[$Name] - if ($null -eq $property) { throw "Store response is missing '$Name'." } - return $property.Value -} - -function ConvertTo-CanonicalValue { - param([AllowNull()][object]$Value) - if ($null -eq $Value -or $Value -is [string] -or $Value -is [ValueType]) { return $Value } - if ($Value -is [Collections.IDictionary]) { - $dictionary = [ordered]@{} - foreach ($key in @($Value.Keys | Sort-Object)) { - $dictionary[[string]$key] = ConvertTo-CanonicalValue $Value[$key] - } - return $dictionary - } - if ($Value -is [Collections.IEnumerable]) { - $items = @($Value | ForEach-Object { ConvertTo-CanonicalValue $_ }) - return ,$items - } - $properties = [ordered]@{} - foreach ($property in @($Value.PSObject.Properties | Sort-Object Name)) { - $properties[$property.Name] = ConvertTo-CanonicalValue $property.Value - } - return $properties -} - -function Get-SubmissionMetadata { - param([Parameter(Mandatory)][psobject]$Submission) - $metadata = [ordered]@{} - $metadataNames = if ($isFlight) { @('TargetPublishMode', 'TargetPublishDate', 'NotesForCertification') } else { @( - 'ApplicationCategory', 'Pricing', 'Visibility', 'TargetPublishMode', - 'TargetPublishDate', 'Listings', 'HardwarePreferences', - 'AutomaticBackupEnabled', 'CanInstallOnRemovableMedia', 'IsGameDvrEnabled', - 'GamingOptions', 'HasExternalInAppProducts', 'MeetAccessibilityGuidelines', - 'NotesForCertification', 'EnterpriseLicensing', - 'AllowMicrosoftDecideAppAvailabilityToFutureDeviceFamilies', - 'AllowTargetFutureDeviceFamilies', 'Trailers' - ) } - foreach ($name in $metadataNames) { - # Conditional metadata is omitted by valid Store responses. Preserve it - # when applicable, without requiring an Immediate submission's date. - if ($name -eq 'TargetPublishDate' -and $Submission.TargetPublishMode -ne 'SpecificDate') { continue } - $property = $Submission.PSObject.Properties[$name] - if ($name -in @('ApplicationCategory', 'Pricing', 'Visibility', 'TargetPublishMode', 'Listings', 'TargetPublishDate')) { - $metadata[$name] = ConvertTo-CanonicalValue (Get-RequiredProperty $Submission $name) - } else { - $metadata[$name] = if ($null -eq $property) { $null } else { ConvertTo-CanonicalValue $property.Value } - } - if ($name -eq 'Pricing' -and $null -ne $metadata[$name]) { - # Partner Center owns this read-only account capability, not the submission's prices. - $metadata[$name].Remove('isAdvancedPricingModel') - } - } - return $metadata -} - -function Get-SubmissionMetadataHash { - param([Parameter(Mandatory)][psobject]$Submission) - $json = Get-SubmissionMetadata $Submission | ConvertTo-Json -Depth 100 -Compress - $hash = [Security.Cryptography.SHA256]::HashData([Text.Encoding]::UTF8.GetBytes($json)) - return [Convert]::ToHexString($hash).ToLowerInvariant() -} - -function Get-ChangedMetadataPaths { - param([AllowNull()][object]$Expected, [AllowNull()][object]$Actual, [string]$Path = '') - if ($Expected -is [Collections.IDictionary] -and $Actual -is [Collections.IDictionary]) { - $keys = @(@($Expected.Keys) + @($Actual.Keys) | Sort-Object -Unique -CaseSensitive) - foreach ($key in $keys) { - $childPath = if ($Path) { "$Path.$key" } else { [string]$key } - if (@($Expected.Keys) -cnotcontains $key -or @($Actual.Keys) -cnotcontains $key) { - $childPath - } else { - Get-ChangedMetadataPaths $Expected[$key] $Actual[$key] $childPath - } - } - return - } - if ($Expected -is [Array] -and $Actual -is [Array]) { - for ($index = 0; $index -lt [Math]::Max($Expected.Count, $Actual.Count); $index++) { - $childPath = "${Path}[$index]" - if ($index -ge $Expected.Count -or $index -ge $Actual.Count) { - $childPath - } else { - Get-ChangedMetadataPaths $Expected[$index] $Actual[$index] $childPath - } - } - return - } - $expectedJson = ConvertTo-Json -InputObject $Expected -Depth 100 -Compress - $actualJson = ConvertTo-Json -InputObject $Actual -Depth 100 -Compress - if ($expectedJson -cne $actualJson) { $Path } -} - -function Get-SubmissionMutationHash { - param([Parameter(Mandatory)][psobject]$Submission) - # Partner Center owns package IDs, architecture, version and upload status. - # Compare only our requested files/actions and editable delivery settings. - $packages = @(foreach ($package in @(Get-RequiredProperty $Submission $packagesProperty)) { - $status = [string](Get-RequiredProperty $package 'FileStatus') - if ($status -notin @('PendingUpload', 'Uploaded', 'PendingDelete')) { throw 'Unexpected Store package status.' } - [ordered]@{ - FileName = [string](Get-RequiredProperty $package 'FileName') - Action = if ($status -eq 'PendingDelete') { 'delete' } else { 'upload' } - MinimumDirectXVersion = if ($null -ne $package.PSObject.Properties['minimumDirectXVersion']) { $package.PSObject.Properties['minimumDirectXVersion'].Value } else { $null } - MinimumSystemRam = if ($null -ne $package.PSObject.Properties['minimumSystemRam']) { $package.PSObject.Properties['minimumSystemRam'].Value } else { $null } - } - }) - $delivery = ConvertTo-CanonicalValue (Get-RequiredProperty $Submission 'PackageDeliveryOptions') - if ($null -ne $delivery -and $null -ne $delivery['PackageRollout']) { - $delivery['PackageRollout'].Remove('PackageRolloutStatus') - $delivery['PackageRollout'].Remove('FallbackSubmissionId') - } - $mutationState = [ordered]@{ - ApplicationPackages = @($packages | Sort-Object { $_.FileName }) - PackageDeliveryOptions = $delivery - } - $json = $mutationState | ConvertTo-Json -Depth 100 -Compress - $hash = [Security.Cryptography.SHA256]::HashData([Text.Encoding]::UTF8.GetBytes($json)) - return [Convert]::ToHexString($hash).ToLowerInvariant() -} - -Assert-NonEmptyValue -Name 'ApplicationId' -Value $ApplicationId -if (-not (Test-Path -LiteralPath $BundlePath -PathType Leaf)) { - throw "MSIX bundle does not exist: $BundlePath" -} -$resolvedBundle = (Resolve-Path -LiteralPath $BundlePath).Path -if ([IO.Path]::GetExtension($resolvedBundle) -cne '.msixbundle') { - throw "Store submission requires one .msixbundle: $resolvedBundle" -} -if ((Get-Item -LiteralPath $resolvedBundle).Length -eq 0) { throw "MSIX bundle is empty: $resolvedBundle" } -$bundleArchive = [IO.Compression.ZipFile]::OpenRead($resolvedBundle) -try { - $manifestEntry = $bundleArchive.GetEntry('AppxMetadata/AppxBundleManifest.xml') - if ($null -eq $manifestEntry) { throw 'Bundle manifest is missing.' } - $reader = [IO.StreamReader]::new($manifestEntry.Open()) - try { [xml]$manifest = $reader.ReadToEnd() } finally { $reader.Dispose() } - if ([string]$manifest.Bundle.Identity.Name -cne $PackageIdentityName -or - [string]$manifest.Bundle.Identity.Publisher -cne $Publisher) { - throw 'Bundle does not match the approved Store package identity.' - } -} finally { $bundleArchive.Dispose() } - -if (-not (Test-Path -LiteralPath $ClientAssertionFile -PathType Leaf)) { - throw "OIDC client assertion file does not exist: $ClientAssertionFile" -} -$assertion = [IO.File]::ReadAllText((Resolve-Path -LiteralPath $ClientAssertionFile).Path).Trim() -if ([string]::IsNullOrWhiteSpace($assertion)) { throw 'OIDC client assertion file is empty.' } -if (-not (Test-Path -LiteralPath $PolicyPath -PathType Leaf)) { - throw "Store submission policy does not exist: $PolicyPath" -} -try { $policy = Get-Content -LiteralPath $PolicyPath -Raw | ConvertFrom-Json } -catch { throw "Unable to parse Store submission policy: $($_.Exception.Message)" } - -$requiredProperties = @( - 'schemaVersion', 'environment', 'oidcAudience', 'apiBaseUri', 'oauthScope', - 'commitSubmission', 'submissionWriterPolicy', 'pendingSubmissionPolicy', 'failedDraftPolicy', - 'packageRolloutPercentage', 'uploadTimeoutSeconds', 'minimumAccessTokenLifetimeSeconds' -) -foreach ($property in $requiredProperties) { - if ($policy.PSObject.Properties.Name -notcontains $property) { - throw "Store submission policy is missing '$property'." - } -} -if ([int]$policy.schemaVersion -ne 1 -or [string]$policy.environment -cne 'microsoft-store' -or - [string]$policy.oidcAudience -cne 'api://AzureADTokenExchange') { - throw 'Store submission policy has an unsupported identity boundary.' -} -if ([string]$policy.apiBaseUri -cne 'https://manage.devcenter.microsoft.com' -or - [string]$policy.oauthScope -cne 'https://manage.devcenter.microsoft.com/.default') { - throw 'Store submission policy has an unsupported API boundary.' -} -if ([bool]$policy.commitSubmission -ne $true -or - [string]$policy.submissionWriterPolicy -cne 'exclusive-github-environment' -or - [string]$policy.pendingSubmissionPolicy -cne 'reject' -or - [string]$policy.failedDraftPolicy -cne 'delete-owned-before-commit') { - throw 'Store submission policy must commit safely and reject unowned drafts.' -} -$rollout = [float]$policy.packageRolloutPercentage -$uploadTimeout = [long]$policy.uploadTimeoutSeconds -$minimumLifetime = [long]$policy.minimumAccessTokenLifetimeSeconds -if ($rollout -lt 0 -or $rollout -gt 100) { throw 'Store package rollout percentage must be between 0 and 100.' } -if ($uploadTimeout -lt 100 -or $uploadTimeout -gt 100000 -or - $minimumLifetime -lt ($uploadTimeout + 300)) { - throw 'Store access-token lifetime must cover upload timeout plus five minutes.' -} - -if ($null -eq $HttpInvoker) { - $HttpInvoker = { - param($Method, $Uri, $Headers, $Body, $ContentType) - $parameters = @{ Method = $Method; Uri = $Uri; ErrorAction = 'Stop' } - if ($null -ne $Headers) { $parameters.Headers = $Headers } - if ($null -ne $Body) { $parameters.Body = $Body } - if (-not [string]::IsNullOrWhiteSpace($ContentType)) { $parameters.ContentType = $ContentType } - Invoke-RestMethod @parameters - } -} -if ($null -eq $UploadInvoker) { - $UploadInvoker = { - param($Uri, $Path, $TimeoutSeconds) - Invoke-WebRequest -Method Put -Uri $Uri -InFile $Path -TimeoutSec $TimeoutSeconds ` - -ContentType 'application/zip' -Headers @{ 'x-ms-blob-type' = 'BlockBlob' } | Out-Null - } -} - -$tokenEndpoint = "https://login.microsoftonline.com/$TenantId/oauth2/v2.0/token" -$tokenResponse = & $HttpInvoker 'Post' $tokenEndpoint $null ([ordered]@{ - client_id = $ClientId.ToString() - scope = [string]$policy.oauthScope - client_assertion = $assertion - client_assertion_type = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer' - grant_type = 'client_credentials' -}) 'application/x-www-form-urlencoded' -$accessToken = [string](Get-RequiredProperty $tokenResponse 'access_token') -$expiresIn = [long](Get-RequiredProperty $tokenResponse 'expires_in') -if ([string]::IsNullOrWhiteSpace($accessToken) -or $expiresIn -lt $minimumLifetime) { - throw 'Microsoft Store access token is missing or too short-lived for the upload.' -} -if ($env:GITHUB_ACTIONS -eq 'true') { Write-Output "::add-mask::$accessToken" } - -$apiBase = [string]$policy.apiBaseUri -$encodedApplicationId = [Uri]::EscapeDataString($ApplicationId) -$applicationPath = "/v1.0/my/applications/$encodedApplicationId" -$targetPath = if ($isFlight) { "$applicationPath/flights/$([Uri]::EscapeDataString($FlightId))" } else { $applicationPath } -$apiHeaders = @{ Authorization = "Bearer $accessToken"; TenantId = $TenantId.ToString() } -function Invoke-StoreApi { - param( - [Parameter(Mandatory)][string]$Method, - [Parameter(Mandatory)][string]$Path, - [AllowNull()][object]$Body = $null - ) - $json = if ($null -eq $Body) { $null } else { $Body | ConvertTo-Json -Depth 100 -Compress } - return & $HttpInvoker $Method ($apiBase + $Path) $apiHeaders $json 'application/json' -} -function Assert-OwnedDraft { - param([Parameter(Mandatory)][string]$SubmissionId) - $target = Invoke-StoreApi -Method Get -Path $targetPath - if ($isFlight -and [string](Get-RequiredProperty $target 'FlightId') -cne $FlightId) { - throw 'Store returned a different flight.' - } - $pending = Get-RequiredProperty $target $pendingProperty - if ($null -eq $pending -or [string](Get-RequiredProperty $pending 'Id') -cne $SubmissionId) { - throw 'The Store pending submission is no longer the automation-owned draft.' - } -} - -$draftId = $null -$committed = $false -$draftDeletionAllowed = $true -$temporaryDirectory = $null -try { - $application = Invoke-StoreApi -Method Get -Path "/v1.0/my/applications/$encodedApplicationId" - if ([string](Get-RequiredProperty $application 'Id') -cne $ApplicationId) { - throw 'Microsoft Store application preflight returned the wrong product.' - } - if ([string](Get-RequiredProperty $application 'PackageIdentityName') -cne $PackageIdentityName -or - [string](Get-RequiredProperty $application 'PublisherName') -cne $Publisher) { - throw 'Microsoft Store product does not match the approved package identity.' - } - $target = $application - if ($isFlight) { - $target = Invoke-StoreApi -Method Get -Path $targetPath - if ([string](Get-RequiredProperty $target 'FlightId') -cne $FlightId) { - throw 'Store returned a different flight.' - } - if (@(Get-RequiredProperty $target 'GroupIds').Count -eq 0) { - throw 'The development flight must have a tester group.' - } - } - $pendingSubmission = $target.PSObject.Properties[$pendingProperty] - if ($null -ne $pendingSubmission -and $null -ne $pendingSubmission.Value) { - throw 'Partner Center already has a pending submission; automation will not replace it.' - } - $publishedInfo = $target.PSObject.Properties[$publishedProperty] - $publishedId = '' - $publishedMetadataHash = '' - if ($null -ne $publishedInfo -and $null -ne $publishedInfo.Value) { - $publishedId = [string](Get-RequiredProperty $publishedInfo.Value 'Id') - Assert-NonEmptyValue -Name 'Published submission ID' -Value $publishedId - $encodedPublishedId = [Uri]::EscapeDataString($publishedId) - $published = Invoke-StoreApi -Method Get -Path "$targetPath/submissions/$encodedPublishedId" - $publishedMetadataHash = Get-SubmissionMetadataHash $published - } elseif (-not $isFlight) { - throw 'The Partner Center product must have a published submission.' - } - - $draft = Invoke-StoreApi -Method Post ` - -Path $(if ($isFlight) { "$targetPath/submissions" } else { "$targetPath/submissions?isMinimalResponse=true" }) - $draftId = [string](Get-RequiredProperty $draft 'Id') - Assert-NonEmptyValue -Name 'Draft submission ID' -Value $draftId - $encodedDraftId = [Uri]::EscapeDataString($draftId) - Assert-OwnedDraft -SubmissionId $draftId - $draft = Invoke-StoreApi -Method Get ` - -Path "$targetPath/submissions/$encodedDraftId" - if ([string](Get-RequiredProperty $draft 'Id') -cne $draftId) { - throw 'Store returned a different draft than the automation created.' - } - $uploadUri = [string](Get-RequiredProperty $draft 'FileUploadUrl') - Assert-NonEmptyValue -Name 'Draft upload URL' -Value $uploadUri - - if ($isFlight -and [string](Get-RequiredProperty $draft 'FlightId') -cne $FlightId) { - throw 'Store returned a submission for a different flight.' - } - # A first flight has no published baseline; preserve its freshly created settings. - if (-not $publishedMetadataHash) { - $published = $draft | ConvertTo-Json -Depth 100 | ConvertFrom-Json - $publishedMetadataHash = Get-SubmissionMetadataHash $published - } - $packages = @(Get-RequiredProperty $draft $packagesProperty) - foreach ($package in $packages) { $package.FileStatus = 'PendingDelete' } - $packages += [pscustomobject]@{ - FileName = [IO.Path]::GetFileName($resolvedBundle) - FileStatus = 'PendingUpload' - minimumDirectXVersion = 'None' - minimumSystemRam = 'None' - } - $draft.$packagesProperty = $packages - $deliveryOptions = Get-RequiredProperty $draft 'PackageDeliveryOptions' - if ($null -ne $deliveryOptions) { - $packageRollout = Get-RequiredProperty $deliveryOptions 'PackageRollout' - if ($null -ne $packageRollout) { - # Even a 100% gradual rollout needs manual finalization before the next submission. - $packageRollout.IsPackageRollout = $rollout -lt 100 - $packageRollout.PackageRolloutPercentage = $rollout - } - } - - $draftMutationHash = Get-SubmissionMutationHash $draft - $draft = Invoke-StoreApi -Method Put ` - -Path "$targetPath/submissions/$encodedDraftId" ` - -Body $draft - if ([string](Get-RequiredProperty $draft 'Id') -cne $draftId) { - throw 'Store updated a different draft than the automation owns.' - } - Assert-OwnedDraft -SubmissionId $draftId - - $temporaryDirectory = Join-Path ([IO.Path]::GetTempPath()) ( - "openclaw-store-upload-$([guid]::NewGuid().ToString('N'))") - $uploadDirectory = Join-Path $temporaryDirectory 'payload' - $uploadArchive = Join-Path $temporaryDirectory 'Upload.zip' - New-Item -ItemType Directory -Path $uploadDirectory -Force | Out-Null - Copy-Item -LiteralPath $resolvedBundle -Destination $uploadDirectory - [IO.Compression.ZipFile]::CreateFromDirectory($uploadDirectory, $uploadArchive) - & $UploadInvoker $uploadUri $uploadArchive $uploadTimeout - - Assert-OwnedDraft -SubmissionId $draftId - $verifiedDraft = Invoke-StoreApi -Method Get ` - -Path "$targetPath/submissions/$encodedDraftId" - if ([string](Get-RequiredProperty $verifiedDraft 'Id') -cne $draftId) { - throw 'Store verification returned an unowned draft.' - } - if ($isFlight -and [string](Get-RequiredProperty $verifiedDraft 'FlightId') -cne $FlightId) { - throw 'Store verification returned a different flight.' - } - $draftMetadataHash = Get-SubmissionMetadataHash $verifiedDraft - if ($draftMetadataHash -cne $publishedMetadataHash) { - $changedPaths = @(Get-ChangedMetadataPaths (Get-SubmissionMetadata $published) (Get-SubmissionMetadata $verifiedDraft)) - # Paths identify the rejected fields without exposing metadata values. - $fields = @($changedPaths | Select-Object -First 20) -join ', ' - $more = if ($changedPaths.Count -gt 20) { " (+$($changedPaths.Count - 20) more)" } else { '' } - throw "The Store draft did not preserve published product metadata. Changed fields: $fields$more." - } - $verifiedMutationHash = Get-SubmissionMutationHash $verifiedDraft - if ($verifiedMutationHash -cne $draftMutationHash) { - throw 'The Store draft package mutation state changed after upload.' - } - Assert-OwnedDraft -SubmissionId $draftId - # Once the commit request leaves this process, a transport failure is - # ambiguous: Partner Center may have accepted it even if no response - # arrived. Never delete that submission unless Partner Center explicitly - # reports a terminal rejection. - $draftDeletionAllowed = $false - $commit = Invoke-StoreApi -Method Post ` - -Path "$targetPath/submissions/$encodedDraftId/Commit" - $commitStatus = [string](Get-RequiredProperty $commit 'Status') - if ($commitStatus -cne 'CommitStarted') { - if ($commitStatus -cin @('CommitFailed', 'Canceled')) { - $draftDeletionAllowed = $true - } - throw "Store did not accept the submission commit: $commitStatus" - } - $committed = $true - - if (-not [string]::IsNullOrWhiteSpace($EvidencePath)) { - $resolvedEvidence = [IO.Path]::GetFullPath($EvidencePath) - New-Item -Path (Split-Path $resolvedEvidence -Parent) -ItemType Directory -Force | Out-Null - [ordered]@{ - schemaVersion = 1 - applicationId = $ApplicationId - channel = $Channel - flightId = $FlightId - bundleFileName = [IO.Path]::GetFileName($resolvedBundle) - bundleSha256 = (Get-FileHash -LiteralPath $resolvedBundle -Algorithm SHA256).Hash.ToLowerInvariant() - publishedSubmissionId = $publishedId - draftSubmissionId = $draftId - publishedMetadataSha256 = $publishedMetadataHash - draftMetadataSha256 = $draftMetadataHash - preparedMutationSha256 = $draftMutationHash - verifiedMutationSha256 = $verifiedMutationHash - commitStatus = $commitStatus - packageRolloutPercentage = $rollout - submittedAtUtc = [DateTimeOffset]::UtcNow.ToString('O') - } | ConvertTo-Json | Set-Content -LiteralPath $resolvedEvidence -Encoding utf8 - } -} -catch { - $failure = $_ - if ($draftDeletionAllowed -and -not $committed -and - -not [string]::IsNullOrWhiteSpace($draftId)) { - try { - $encodedDraftId = [Uri]::EscapeDataString($draftId) - Invoke-StoreApi -Method Delete ` - -Path "$targetPath/submissions/$encodedDraftId" | - Out-Null - } - catch { - Write-Warning "Could not delete automation-owned draft '$draftId': $($_.Exception.Message)" - } - } - throw $failure -} -finally { - if ($null -ne $temporaryDirectory) { - Remove-Item -LiteralPath $temporaryDirectory -Recurse -Force -ErrorAction SilentlyContinue - } - $assertion = $null - $accessToken = $null -} diff --git a/scripts/Test-Request-MicrosoftStorePublish.Tests.ps1 b/scripts/Test-Request-MicrosoftStorePublish.Tests.ps1 new file mode 100644 index 00000000..96e9c42b --- /dev/null +++ b/scripts/Test-Request-MicrosoftStorePublish.Tests.ps1 @@ -0,0 +1,97 @@ +[CmdletBinding()] +param() + +Set-StrictMode -Version Latest +$ErrorActionPreference = 'Stop' +$scriptPath = Join-Path $PSScriptRoot 'Request-MicrosoftStorePublish.ps1' +$script:checks = 0 +$fixture = [pscustomobject]@{ calls = @() } +$capture = { + param([string[]]$CommandArguments) + $fixture.calls += ,$CommandArguments +}.GetNewClosure() +$canonical = @{ + RunId = '123' + Repository = 'openclaw/openclaw-windows-packaging' + GitHubRef = 'refs/heads/main' + EventName = 'workflow_dispatch' + CommandInvoker = $capture +} + +function Assert-Rejected { + param([hashtable]$Parameters) + $fixture.calls = @() + $rejected = $false + try { & $scriptPath @Parameters | Out-Null } + catch { $rejected = $true } + if (-not $rejected -or $fixture.calls.Count -ne 0) { + throw 'An invalid request reached the external command boundary.' + } + $script:checks++ +} + +$result = & $scriptPath @canonical +$expected = @( + 'workflow', 'run', 'windows-store-publish.yml', + '--repo', 'openclaw/releases', '--ref', 'main', + '-f', 'product=gateway', '-f', 'run_id=123', '-f', 'channel=production', '-f', 'automatic=false' +) +if ($fixture.calls.Count -ne 1 -or + ($fixture.calls[0] | ConvertTo-Json -Compress) -cne ($expected | ConvertTo-Json -Compress)) { + throw 'The request did not dispatch exactly the fixed central workflow and source run.' +} +if ($result.product -cne 'gateway' -or $result.sourceRunId -cne '123' -or $result.status -cne 'requested' -or $result.channel -cne 'production') { + throw 'A request must report request acceptance, not Microsoft Store acceptance.' +} +$script:checks++ + +foreach ($channel in @('development', 'Development', 'DEVELOPMENT')) { + $parameters = $canonical.Clone() + $parameters.Channel = $channel + $fixture.calls = @() + $result = & $scriptPath @parameters + $expectedDevelopment = @( + 'workflow', 'run', 'windows-store-publish.yml', + '--repo', 'openclaw/releases', '--ref', 'main', + '-f', 'product=gateway', '-f', 'run_id=123', '-f', 'channel=development', '-f', 'automatic=false' + ) + if ($fixture.calls.Count -ne 1 -or + ($fixture.calls[0] | ConvertTo-Json -Compress) -cne ($expectedDevelopment | ConvertTo-Json -Compress) -or + $result.channel -cne 'development') { throw 'The request did not preserve the Development destination.' } + $script:checks++ +} + +foreach ($runId in @('0', '-1', '01', '1.0', '1e2', ' 123', '123 ', "123`n", '123;command', '')) { + $parameters = $canonical.Clone() + $parameters.RunId = $runId + Assert-Rejected $parameters +} +foreach ($channel in @('beta', 'development;command')) { + $parameters = $canonical.Clone() + $parameters.Channel = $channel + Assert-Rejected $parameters +} +foreach ($override in @( + @{ Repository = 'fork/openclaw-windows-packaging' }, + @{ GitHubRef = 'refs/heads/patch' }, + @{ GitHubRef = 'refs/tags/main' }, + @{ EventName = 'workflow_run' }, + @{ EventName = 'pull_request' } +)) { + $parameters = $canonical.Clone() + foreach ($key in $override.Keys) { $parameters[$key] = $override[$key] } + Assert-Rejected $parameters +} + +$parameters = $canonical.Clone() +$parameters.CommandInvoker = { throw 'Synthetic dispatch failure.' } +$failed = $false +try { & $scriptPath @parameters | Out-Null } +catch { + if ($_.Exception.Message -cne 'Synthetic dispatch failure.') { throw } + $failed = $true +} +if (-not $failed) { throw 'A failed dispatch was reported as accepted.' } +$script:checks++ + +Write-Host "Store publication requests: $script:checks scenarios passed." diff --git a/scripts/Test-StoreFlightSubmission.Tests.ps1 b/scripts/Test-StoreFlightSubmission.Tests.ps1 deleted file mode 100644 index 4aeca05b..00000000 --- a/scripts/Test-StoreFlightSubmission.Tests.ps1 +++ /dev/null @@ -1,149 +0,0 @@ -[CmdletBinding()] -param() -Set-StrictMode -Version Latest -$ErrorActionPreference = 'Stop' -$root = Join-Path ([IO.Path]::GetTempPath()) "store-flight-$([guid]::NewGuid().ToString('N'))" -$flightId = '33333333-3333-3333-3333-333333333333' -$applicationPath = 'https://manage.devcenter.microsoft.com/v1.0/my/applications/TESTPRODUCT' -$flightPath = "$applicationPath/flights/$flightId" -function Copy-Fixture($Value) { $Value | ConvertTo-Json -Depth 100 | ConvertFrom-Json } -function Reset-Fixture { - $global:StoreFlightTest_calls = [Collections.Generic.List[string]]::new() - $global:StoreFlightTest_pending = $null - $global:StoreFlightTest_scenario = '' - $global:StoreFlightTest_published = [pscustomobject]@{ - Id = 'published'; FlightId = $flightId; FlightPackages = @() - TargetPublishMode = 'Immediate'; NotesForCertification = 'Fixture instructions' - PackageDeliveryOptions = [pscustomobject]@{ - PackageRollout = [pscustomobject]@{ IsPackageRollout = $false; PackageRolloutPercentage = 0 } - } - FileUploadUrl = 'https://example.invalid/upload' - } -} -$http = { - param($Method, $Uri, $Headers, $Body, $ContentType) - $applicationPath = 'https://manage.devcenter.microsoft.com/v1.0/my/applications/TESTPRODUCT' - $flightPath = "$applicationPath/flights/33333333-3333-3333-3333-333333333333" - $global:StoreFlightTest_calls.Add("$Method $Uri") - if ($Uri -like 'https://login.microsoftonline.com/*') { - return [pscustomobject]@{ access_token = 'fixture'; expires_in = 3600 } - } - if ($Method -eq 'Get' -and $Uri -ceq $applicationPath) { - return [pscustomobject]@{ - Id = 'TESTPRODUCT'; PackageIdentityName = 'Test.Product'; PublisherName = 'CN=Test' - # A production draft must neither block nor become a flight target. - PendingApplicationSubmission = [pscustomobject]@{ Id = 'unrelated-production-draft' } - } - } - if ($Method -eq 'Get' -and $Uri -ceq $flightPath) { - return [pscustomobject]@{ - FlightId = if ($global:StoreFlightTest_scenario -eq 'wrong-flight') { 'wrong' } else { $flightId } - GroupIds = if ($global:StoreFlightTest_scenario -eq 'no-group') { @() } else { @('testers') } - PendingFlightSubmission = if ($global:StoreFlightTest_pending) { [pscustomobject]@{ Id = $global:StoreFlightTest_pending } } else { $null } - LastPublishedFlightSubmission = if ($global:StoreFlightTest_scenario -eq 'first-flight') { $null } else { [pscustomobject]@{ Id = 'published' } } - } - } - if ($Method -eq 'Get' -and $Uri -ceq "$flightPath/submissions/published") { return Copy-Fixture $global:StoreFlightTest_published } - if ($Method -eq 'Post' -and $Uri -ceq "$flightPath/submissions") { - $global:StoreFlightTest_draft = Copy-Fixture $global:StoreFlightTest_published - $global:StoreFlightTest_draft.Id = 'owned' - $global:StoreFlightTest_pending = 'owned' - return Copy-Fixture $global:StoreFlightTest_draft - } - if ($Method -eq 'Get' -and $Uri -ceq "$flightPath/submissions/owned") { return Copy-Fixture $global:StoreFlightTest_draft } - if ($Method -eq 'Put' -and $Uri -ceq "$flightPath/submissions/owned") { - $global:StoreFlightTest_draft = $Body | ConvertFrom-Json - if ($global:StoreFlightTest_draft.PSObject.Properties.Name -contains 'ApplicationPackages' -or - @($global:StoreFlightTest_draft.FlightPackages).Count -ne 1 -or - $global:StoreFlightTest_draft.FlightPackages[0].FileName -cne 'fixture.msixbundle') { - throw 'Flight upload used the wrong package contract.' - } - return Copy-Fixture $global:StoreFlightTest_draft - } - if ($Method -eq 'Post' -and $Uri -ceq "$flightPath/submissions/owned/Commit") { - if ($global:StoreFlightTest_scenario -eq 'lost-commit') { throw 'Lost commit response.' } - $global:StoreFlightTest_pending = $null - return [pscustomobject]@{ Status = 'CommitStarted' } - } - if ($Method -eq 'Delete' -and $Uri -ceq "$flightPath/submissions/owned") { $global:StoreFlightTest_pending = $null; return } - throw "Unexpected request: $Method $Uri" -} -$upload = { - param($Uri, $Path, $TimeoutSeconds) - if ($Uri -cne 'https://example.invalid/upload' -or -not (Test-Path $Path)) { throw 'Invalid upload.' } - switch ($global:StoreFlightTest_scenario) { - 'metadata-drift' { $global:StoreFlightTest_draft.NotesForCertification = 'changed' } - 'wrong-submission-flight' { $global:StoreFlightTest_draft.FlightId = 'wrong' } - 'replaced-draft' { $global:StoreFlightTest_pending = 'foreign' } - 'package-drift' { $global:StoreFlightTest_draft.FlightPackages[0].FileName = 'changed.msixbundle' } - } -} -function Invoke-Fixture([string]$Channel = 'development', [string]$Id = $flightId) { - $parameters = @{ - BundlePath = Join-Path $root 'fixture.msixbundle' - ApplicationId = 'TESTPRODUCT'; PackageIdentityName = 'Test.Product'; Publisher = 'CN=Test' - Channel = $Channel; FlightId = $Id - TenantId = '11111111-1111-1111-1111-111111111111' - ClientId = '22222222-2222-2222-2222-222222222222' - ClientAssertionFile = Join-Path $root 'assertion' - EvidencePath = Join-Path $root 'evidence.json' - HttpInvoker = $http; UploadInvoker = $upload - } - & (Join-Path $PSScriptRoot 'Submit-MicrosoftStore.ps1') @parameters -} -function Assert-Rejected([scriptblock]$Action, [string]$Pattern) { - try { & $Action } catch { if ($_.Exception.Message -notmatch $Pattern) { throw }; return } - throw "Expected rejection: $Pattern" -} -try { - New-Item (Join-Path $root 'bundle/AppxMetadata') -ItemType Directory -Force | Out-Null - [IO.File]::WriteAllText((Join-Path $root 'bundle/AppxMetadata/AppxBundleManifest.xml'), - '') - [IO.Compression.ZipFile]::CreateFromDirectory((Join-Path $root 'bundle'), (Join-Path $root 'fixture.msixbundle')) - [IO.File]::WriteAllText((Join-Path $root 'assertion'), 'fixture-assertion') - foreach ($case in @('', 'first-flight', 'Development', 'DEVELOPMENT')) { - Reset-Fixture - $global:StoreFlightTest_scenario = $case - Invoke-Fixture -Channel $(if ($case -in @('Development', 'DEVELOPMENT')) { $case } else { 'development' }) - $evidence = Get-Content (Join-Path $root 'evidence.json') -Raw | ConvertFrom-Json - if ($evidence.channel -cne 'development' -or $evidence.flightId -cne $flightId -or - $evidence.commitStatus -cne 'CommitStarted' -or $global:StoreFlightTest_pending) { throw 'Missing flight commit receipt.' } - if ($global:StoreFlightTest_calls -match '/applications/TESTPRODUCT/submissions') { throw 'Flight touched production submissions.' } - } - foreach ($case in @( - @{ Name = 'wrong-flight'; Error = 'different flight' }, - @{ Name = 'no-group'; Error = 'tester group' }, - @{ Name = 'metadata-drift'; Error = 'preserve published product metadata' }, - @{ Name = 'wrong-submission-flight'; Error = 'different flight' }, - @{ Name = 'package-drift'; Error = 'mutation state changed' }, - @{ Name = 'replaced-draft'; Error = 'no longer the automation-owned' }, - @{ Name = 'lost-commit'; Error = 'Lost commit response' } - )) { - Reset-Fixture - $global:StoreFlightTest_scenario = $case.Name - Assert-Rejected { Invoke-Fixture } $case.Error - if ($case.Name -eq 'lost-commit' -and ($global:StoreFlightTest_pending -cne 'owned' -or $global:StoreFlightTest_calls -match '^Delete ')) { - throw 'Ambiguous flight commit was deleted.' - } - if ($case.Name -ne 'lost-commit' -and $global:StoreFlightTest_calls -match '/Commit$') { throw 'Invalid flight reached commit.' } - } - Reset-Fixture - $global:StoreFlightTest_pending = 'foreign' - Assert-Rejected { Invoke-Fixture } 'already has a pending' - if ($global:StoreFlightTest_pending -cne 'foreign' -or $global:StoreFlightTest_calls -match '^Post .*flights|^Delete ') { throw 'Foreign draft changed.' } - Reset-Fixture - Assert-Rejected { Invoke-Fixture -Id '' } 'requires the configured flight' - Assert-Rejected { Invoke-Fixture -Channel production } 'must not specify a flight' - if ($global:StoreFlightTest_calls.Count) { throw 'Invalid destination reached authentication.' } - foreach ($channel in @('Development', 'DEVELOPMENT')) { - Assert-Rejected { Invoke-Fixture -Channel $channel -Id '' } 'requires the configured flight' - } - foreach ($channel in @('Production', 'PRODUCTION')) { - Assert-Rejected { Invoke-Fixture -Channel $channel } 'must not specify a flight' - } - if ($global:StoreFlightTest_calls.Count) { throw 'Case-variant destination reached authentication.' } - Write-Host 'Store flight submission: 18 scenarios passed.' -} finally { - Get-Variable -Scope Global -Name StoreFlightTest_* | Remove-Variable -Scope Global - Remove-Item $root -Recurse -Force -ErrorAction SilentlyContinue -} diff --git a/scripts/Test-StoreSubmissionSource.Tests.ps1 b/scripts/Test-StoreSubmissionSource.Tests.ps1 deleted file mode 100644 index d53c8e6f..00000000 --- a/scripts/Test-StoreSubmissionSource.Tests.ps1 +++ /dev/null @@ -1,131 +0,0 @@ -[CmdletBinding()] -param() -Set-StrictMode -Version Latest -$ErrorActionPreference = 'Stop' -$scriptPath = Join-Path $PSScriptRoot 'Get-StoreSubmissionSource.ps1' -$repository = 'openclaw/openclaw-windows-packaging' -$script:checks = 0 -function Assert-Fails([scriptblock]$Action, [string]$Pattern) { - try { & $Action } catch { - if ($_.Exception.Message -notmatch $Pattern) { throw } - $script:checks++ - return - } - throw "Expected rejection: $Pattern" -} -function Reset-Fixture { - $global:StoreSourceTest_run = [pscustomobject]@{ - id = 123; status = 'completed'; conclusion = 'success'; run_attempt = 2 - repository = [pscustomobject]@{ full_name = $repository } - head_repository = [pscustomobject]@{ full_name = $repository } - path = '.github/workflows/gateway-msix.yml'; event = 'workflow_dispatch'; head_branch = 'main'; head_sha = ('a' * 40) - } - $global:StoreSourceTest_artifacts = @( - [pscustomobject]@{ id = 456; name = 'openclaw-gateway-msix-store-submission-2'; expired = $false } - [pscustomobject]@{ id = 789; name = 'store-release-source-2'; expired = $false } - ) - $global:StoreSourceTest_witness = [ordered]@{ - runId = '123'; runAttempt = 2; packagingCommit = ('a' * 40) - releaseTag = 'v2026.11.1-msix.0'; releaseChannel = 'stable' - bundleName = 'OpenClawGateway-2026.11.1-msix.0-store.msixbundle'; bundleSha256 = ('b' * 64) - } - $global:StoreSourceTest_release = [pscustomobject]@{ - draft = $false; prerelease = $true; published_at = '2026-11-05' - tag_name = 'v2026.11.1-beta.1-msix.0' - } - $global:StoreSourceTest_commit = [pscustomobject]@{ sha = ('a' * 40) } -} -$api = { - param($Path) - switch -Wildcard ($Path) { - 'actions/runs/123' { return $global:StoreSourceTest_run } - 'actions/runs/123/artifacts*' { return [pscustomobject]@{ artifacts = $global:StoreSourceTest_artifacts } } - 'releases/tags/*' { return $global:StoreSourceTest_release } - 'commits/*' { return $global:StoreSourceTest_commit } - default { throw "Unexpected API path: $Path" } - } -} -$download = { - param($Name, $Directory) - if ($Name -cne 'store-release-source-2') { throw 'Unexpected witness download.' } - [IO.File]::WriteAllText((Join-Path $Directory 'store-source.json'), ($global:StoreSourceTest_witness | ConvertTo-Json)) -} -function Invoke-Source([string]$Channel = 'auto') { & $scriptPath -RunId 123 -Channel $Channel -ApiInvoker $api -DownloadInvoker $download } -Reset-Fixture -$result = Invoke-Source -if ($result.artifactId -cne '456') { throw 'Authorized release selected the wrong artifact.' } -$script:checks++ - -foreach ($channel in @('beta')) { - Reset-Fixture - $global:StoreSourceTest_witness.releaseChannel = $channel - $global:StoreSourceTest_witness.releaseTag = "v2026.11.1-$channel.1-msix.0" - $global:StoreSourceTest_witness.bundleName = "OpenClawGateway-2026.11.1-$channel.1-msix.0-store.msixbundle" - $global:StoreSourceTest_release.tag_name = $global:StoreSourceTest_witness.releaseTag - $result = Invoke-Source - if ($result.channel -cne 'development' -or $result.bundleSha256 -cne ('b' * 64)) { throw 'Preview destination or hash drifted.' } - if ($null -ne (Invoke-Source production)) { throw 'Preview reached production.' } - if ((Invoke-Source development).channel -cne 'development') { throw 'Manual development selection failed.' } - foreach ($selection in @('Auto', 'AUTO', 'Development', 'DEVELOPMENT')) { - if ((Invoke-Source $selection).channel -cne 'development') { throw 'Case-variant preview selection failed.' } - $script:checks++ - } - $script:checks += 3 - $global:StoreSourceTest_release.prerelease = $false - Assert-Fails { Invoke-Source } 'published GitHub prerelease' - $global:StoreSourceTest_release.prerelease = $true - $global:StoreSourceTest_commit.sha = ('c' * 40) - Assert-Fails { Invoke-Source } 'published GitHub prerelease' -} -Reset-Fixture -if ($null -ne (Invoke-Source development)) { throw 'Stable release reached Development.' } -$script:checks++ -foreach ($field in @('runId', 'runAttempt', 'packagingCommit', 'releaseChannel', 'bundleSha256')) { - Reset-Fixture - $global:StoreSourceTest_witness[$field] = if ($field -eq 'runAttempt') { 1 } else { 'invalid' } - Assert-Fails { Invoke-Source } 'does not match' -} -foreach ($field in @('releaseTag', 'bundleName')) { - Reset-Fixture - $global:StoreSourceTest_witness[$field] = '../invalid' - Assert-Fails { Invoke-Source } 'invalid release identity' -} -Reset-Fixture -$global:StoreSourceTest_artifacts[1].expired = $true -Assert-Fails { Invoke-Source } 'Store release witness' -Reset-Fixture -$global:StoreSourceTest_artifacts = @($global:StoreSourceTest_artifacts[0]) -Assert-Fails { Invoke-Source } 'Store release witness' -foreach ($field in @('conclusion', 'status')) { - Reset-Fixture - $global:StoreSourceTest_run.$field = 'failure' - Assert-Fails { Invoke-Source } 'successful completed run' -} -Reset-Fixture -$global:StoreSourceTest_run.head_repository.full_name = 'fork/untrusted' -Assert-Fails { Invoke-Source } 'canonical repository' -Reset-Fixture -$global:StoreSourceTest_run.event = 'pull_request' -$global:StoreSourceTest_run.head_repository.full_name = 'fork/untrusted' -if ($null -ne (Invoke-Source)) { throw 'A fork PR was not skipped.' } -$script:checks++ -foreach ($field in @('path', 'event', 'head_branch')) { - Reset-Fixture - $global:StoreSourceTest_run.$field = 'pull_request' - if ($null -ne (Invoke-Source)) { throw "Untrusted $field was eligible." } - $script:checks++ -} -Reset-Fixture -$global:StoreSourceTest_artifacts[0].expired = $true -Assert-Fails { Invoke-Source } 'ambiguous or expired' -Reset-Fixture -$global:StoreSourceTest_artifacts += $global:StoreSourceTest_artifacts[0] -Assert-Fails { Invoke-Source } 'ambiguous or expired' -Reset-Fixture -$global:StoreSourceTest_artifacts = @() -if ($null -ne (Invoke-Source)) { throw 'A run without an authorized bundle was eligible.' } -$script:checks++ - -Write-Host "Store source authorization: $script:checks scenarios passed." - -Get-Variable -Name StoreSourceTest_* -Scope Global | Remove-Variable -Scope Global diff --git a/scripts/Test-StoreSubmissionWorkflow.Tests.ps1 b/scripts/Test-StoreSubmissionWorkflow.Tests.ps1 deleted file mode 100644 index 693dcb72..00000000 --- a/scripts/Test-StoreSubmissionWorkflow.Tests.ps1 +++ /dev/null @@ -1,75 +0,0 @@ -[CmdletBinding()] -param() -Set-StrictMode -Version Latest -$ErrorActionPreference = 'Stop' -$root = Split-Path $PSScriptRoot -Parent -$workflow = Get-Content (Join-Path $root '.github/workflows/submit-microsoft-store.yml') -Raw -$step = [regex]::Match($workflow, '(?ms)^ - name: Submit bundle and commit Store update\r?\n.*?^ run: \|\r?\n(?