Computer use CLI for AI agents
Rust accessibilityaccessibility-apiai-agentsautomationclicomputer-usecomputer-use-agentcomputer-use-agentsdesktop-automationmacosmcprust
fix: automate verified native package releases
Lahfirc34d1b256a68
diff --git a/.github/workflows/homebrew.yml b/.github/workflows/homebrew.ymlindex b5fd79a48..f4f6884f8 100644--- a/.github/workflows/homebrew.yml+++ b/.github/workflows/homebrew.yml@@ -3,9 +3,9 @@ name: Homebrewon:push:branches: [main]- paths: ["Formula/**", ".github/workflows/homebrew.yml"]+ paths: ["Formula/**", "tests/native-install/homebrew.sh", ".github/workflows/homebrew.yml"]pull_request:- paths: ["Formula/**", ".github/workflows/homebrew.yml"]+ paths: ["Formula/**", "tests/native-install/homebrew.sh", ".github/workflows/homebrew.yml"]workflow_dispatch:permissions:@@ -13,8 +13,12 @@ permissions:jobs:install:- name: Fresh Homebrew install- runs-on: macos-latest+ name: Fresh Homebrew install (${{ matrix.os }})+ strategy:+ fail-fast: false+ matrix:+ os: [macos-latest, ubuntu-24.04, ubuntu-24.04-arm]+ runs-on: ${{ matrix.os }}timeout-minutes: 15env:HOMEBREW_NO_AUTO_UPDATE: "1"@@ -23,13 +27,10 @@ jobs:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1with:persist-credentials: false- - name: Install and test native formula+ - name: Enable runner Homebrewrun: |- set -euo pipefail- brew tap-new lahfir/agent-desktop-ci- cp Formula/agent-desktop.rb "$(brew --repo lahfir/agent-desktop-ci)/Formula/agent-desktop.rb"- brew install lahfir/agent-desktop-ci/agent-desktop- brew test lahfir/agent-desktop-ci/agent-desktop- formula_prefix=$(brew --prefix lahfir/agent-desktop-ci/agent-desktop)- env -i HOME="$HOME" PATH=/usr/bin:/bin "$formula_prefix/bin/agent-desktop" version- test -x "$formula_prefix/bin/agent-desktop-macos-helper"+ if [ "$RUNNER_OS" = Linux ]; then+ echo /home/linuxbrew/.linuxbrew/bin >> "$GITHUB_PATH"+ fi+ - name: Install and test native formula+ run: bash tests/native-install/homebrew.shdiff --git a/.github/workflows/release-packages.yml b/.github/workflows/release-packages.ymlnew file mode 100644index 000000000..e7ea941af--- /dev/null+++ b/.github/workflows/release-packages.yml@@ -0,0 +1,48 @@+name: Update release packages++on:+ workflow_call:+ inputs:+ version:+ required: true+ type: string++permissions: {}++jobs:+ update:+ if: github.ref == 'refs/heads/main'+ runs-on: ubuntu-latest+ timeout-minutes: 15+ permissions:+ contents: write+ pull-requests: write+ actions: write+ attestations: read+ steps:+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1+ with:+ ref: main+ persist-credentials: false+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020+ with:+ node-version: '24'+ package-manager-cache: false+ - name: Verify published release and generate package metadata+ env:+ GH_TOKEN: ${{ github.token }}+ GH_REPO: ${{ github.repository }}+ VERSION: ${{ inputs.version }}+ run: |+ test "$(node scripts/release-version.js)" = "$VERSION"+ archives="$RUNNER_TEMP/release-packages"+ gh release download "v$VERSION" --dir "$archives" --pattern 'checksums.txt' --pattern 'agent-desktop-v*.tar.gz'+ gh attestation verify "$archives/checksums.txt" --repo "$GH_REPO" \+ --signer-workflow "$GH_REPO/.github/workflows/release.yml" \+ --source-ref refs/heads/main --deny-self-hosted-runners+ node scripts/update-release-packages.js "$archives"+ - name: Open package update PR and run checks+ env:+ GH_TOKEN: ${{ github.token }}+ GH_REPO: ${{ github.repository }}+ run: bash scripts/open-release-package-pr.shdiff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex f983ac5ef..9b920679d 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -832,54 +832,18 @@ jobs:run: npm publish --access publicworking-directory: npm- publish-skills:- name: Publish Skills to ClawHub+ update-packages:needs: [check-release, publish-github]- if: needs.check-release.outputs.should_release == 'true'- runs-on: ubuntu-latest- timeout-minutes: 10+ if: >-+ !cancelled() && needs.check-release.result == 'success' &&+ (needs.publish-github.result == 'success' ||+ (needs.check-release.outputs.should_release == 'false' &&+ needs.check-release.outputs.needs_github_release == 'false'))permissions:- contents: read- steps:- - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1- with:- persist-credentials: false- fetch-depth: 0- ref: ${{ github.sha }}-- - name: Verify and select release source- shell: bash- env:- RELEASE_SOURCE_SHA: ${{ needs.check-release.outputs.source_sha }}- RELEASE_WORKFLOW_SHA: ${{ github.sha }}- run: bash scripts/checkout-release-source.sh-- - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0- with:- node-version: '24'-- - name: Install ClawHub CLI- run: npm i -g clawhub-- - name: Authenticate with ClawHub- run: clawhub login --token "$CLAWHUB_TOKEN" --no-browser- env:- CLAWHUB_TOKEN: ${{ secrets.CLAWHUB_TOKEN }}-- - name: Publish all skills to ClawHub- run: |- set -euo pipefail- SOURCE_COMMIT="$(git rev-parse HEAD)"- for skill_dir in skills/*; do- [ -d "$skill_dir" ] || continue- [ -f "$skill_dir/SKILL.md" ] || continue- slug="$(basename "$skill_dir")"- clawhub publish "$skill_dir" \- --slug "$slug" \- --changelog "Release ${{ needs.check-release.outputs.tag_name }}" \- --tags latest \- --source-repo "${GITHUB_REPOSITORY}" \- --source-commit "$SOURCE_COMMIT" \- --source-ref "${{ needs.check-release.outputs.tag_name }}" \- --source-path "$skill_dir"- done+ contents: write+ pull-requests: write+ actions: write+ attestations: read+ uses: ./.github/workflows/release-packages.yml+ with:+ version: ${{ needs.check-release.outputs.version }}diff --git a/.github/workflows/scoop.yml b/.github/workflows/scoop.ymlnew file mode 100644index 000000000..ee3819bc6--- /dev/null+++ b/.github/workflows/scoop.yml@@ -0,0 +1,36 @@+name: Scoop++on:+ push:+ branches: [main]+ paths: ["bucket/**", "tests/native-install/scoop.ps1", ".github/workflows/scoop.yml"]+ pull_request:+ paths: ["bucket/**", "tests/native-install/scoop.ps1", ".github/workflows/scoop.yml"]+ workflow_dispatch:++permissions:+ contents: read++jobs:+ install:+ name: Fresh Scoop install (${{ matrix.os }})+ strategy:+ fail-fast: false+ matrix:+ os: [windows-latest, windows-11-arm]+ runs-on: ${{ matrix.os }}+ timeout-minutes: 15+ steps:+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1+ with:+ persist-credentials: false+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1+ with:+ repository: ScoopInstaller/Scoop+ ref: e6aa3b366bdee8ed138c1e0f7b85192ebdd35d0f+ path: .test-scoop/apps/scoop/current+ persist-credentials: false+ - name: Install and test native manifest+ shell: powershell+ run: |+ & tests/native-install/scoop.ps1 -ScoopRoot "$PWD/.test-scoop" -Manifest "$PWD/bucket/agent-desktop.json"diff --git a/.github/workflows/supply-chain.yml b/.github/workflows/supply-chain.ymlindex 1dfa8bd7c..75f036932 100644--- a/.github/workflows/supply-chain.yml+++ b/.github/workflows/supply-chain.yml@@ -40,11 +40,9 @@ jobs:run: node scripts/check-npm-package.js- name: Cargo dependency policy- uses: EmbarkStudios/cargo-deny-action@3c6349835b2b7b196a839186cb8b78e02f7b5f25 # v2.1.1- with:- command: check- arguments: --locked- command-arguments: advisories licenses bans sources+ run: |+ cargo install --locked cargo-deny --version 0.20.2+ cargo deny --locked check advisories licenses bans sources- name: Secret and privacy scanenv:@@ -64,11 +62,4 @@ jobs:./gitleaks git . --log-opts=HEAD --config .gitleaks.toml --redact --no-banner --exit-code 1- name: Workflow security audit- uses: zizmorcore/zizmor-action@cc914d7f3750a2d13d75c7f184a1060aa0e9d482 # v0.6.4- with:- version: 1.25.2- persona: regular- min-severity: medium- min-confidence: high- advanced-security: false- inputs: .github/workflows+ run: pipx run --spec zizmor==1.25.2 zizmor --persona regular --min-severity medium --min-confidence high .github/workflowsdiff --git a/.gitleaks.toml b/.gitleaks.tomlindex f89b018e3..76761f91a 100644--- a/.gitleaks.toml+++ b/.gitleaks.toml@@ -28,6 +28,7 @@ regexes = ['''(?i)^[A-Za-z]:\\Users\\(name|user|username|you|youruser|runner|me|someone)(\\|$)''','''(?i)^/Users/(DevUser|BuildUser)$''','''(?i)^/home/alice(-other)?$''',+ '''^/home/linuxbrew$''',][[rules]]diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e93151aa7..750920345 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -369,14 +369,14 @@### Bug Fixes-* add clawhub login step before sync in CI ([208af12](https://github.com/lahfir/agent-desktop/commit/208af12459fea2255e1c80b8cdc9ac420316d769))+* fix skill publication authentication in CI ([208af12](https://github.com/lahfir/agent-desktop/commit/208af12459fea2255e1c80b8cdc9ac420316d769))## [0.1.9](https://github.com/lahfir/agent-desktop/compare/v0.1.8...v0.1.9) (2026-03-03)### Features-* scalable skill architecture with ClawHub auto-publishing ([#14](https://github.com/lahfir/agent-desktop/issues/14)) ([9766520](https://github.com/lahfir/agent-desktop/commit/97665203a464e605bc9b156ec90029c5909399be))+* scalable skill architecture with publication automation ([#14](https://github.com/lahfir/agent-desktop/issues/14)) ([9766520](https://github.com/lahfir/agent-desktop/commit/97665203a464e605bc9b156ec90029c5909399be))## [0.1.8](https://github.com/lahfir/agent-desktop/compare/v0.1.7...v0.1.8) (2026-03-01)diff --git a/Formula/agent-desktop.rb b/Formula/agent-desktop.rbindex a72edb58b..ca4b42f67 100644--- a/Formula/agent-desktop.rb+++ b/Formula/agent-desktop.rb@@ -4,20 +4,36 @@ class AgentDesktop < Formulaversion "0.11.1"license "Apache-2.0"- depends_on macos: :ventura+ on_macos do+ depends_on macos: :ventura- on_arm do- url "https://github.com/lahfir/agent-desktop/releases/download/v0.11.1/agent-desktop-v0.11.1-aarch64-apple-darwin.tar.gz"- sha256 "666671bd944fb88bf5b5668589f2bd653cd3a01942035260b454736879ff8779"+ on_arm do+ url "https://github.com/lahfir/agent-desktop/releases/download/v0.11.1/agent-desktop-v0.11.1-aarch64-apple-darwin.tar.gz"+ sha256 "666671bd944fb88bf5b5668589f2bd653cd3a01942035260b454736879ff8779"+ end++ on_intel do+ url "https://github.com/lahfir/agent-desktop/releases/download/v0.11.1/agent-desktop-v0.11.1-x86_64-apple-darwin.tar.gz"+ sha256 "32aedc30a787e8ec71ddec758128b30762a31a6ae9833099a5bc1288be302cf9"+ endend- on_intel do- url "https://github.com/lahfir/agent-desktop/releases/download/v0.11.1/agent-desktop-v0.11.1-x86_64-apple-darwin.tar.gz"- sha256 "32aedc30a787e8ec71ddec758128b30762a31a6ae9833099a5bc1288be302cf9"+ on_linux do+ on_arm do+ url "https://github.com/lahfir/agent-desktop/releases/download/v0.11.1/agent-desktop-v0.11.1-aarch64-unknown-linux-gnu.tar.gz"+ sha256 "cdf02e3b3b08f812af28ea477fee9bd72f78fe87a9888768a0750d60bb4dd509"+ end++ on_intel do+ url "https://github.com/lahfir/agent-desktop/releases/download/v0.11.1/agent-desktop-v0.11.1-x86_64-unknown-linux-gnu.tar.gz"+ sha256 "89674d626b3e15536e8084ac883d2507ca2f67d187f7e0b138305f371fb25138"+ endenddef install- bin.install "agent-desktop", "agent-desktop-macos-helper"+ bin.install "agent-desktop"+ bin.install "agent-desktop-macos-helper" if OS.mac?+ bin.install "agent-desktop-linux-clipboard-owner" if OS.linux?endtest do@@ -25,7 +41,7 @@ class AgentDesktop < Formularesponse = JSON.parse(shell_output("#{bin}/agent-desktop version"))assert_equal true, response.fetch("ok")assert_equal version.to_s, response.fetch("data").fetch("version")- assert_equal "macos", response.fetch("data").fetch("os")- assert_path_exists bin/"agent-desktop-macos-helper"+ assert_equal OS.mac? ? "macos" : "linux", response.fetch("data").fetch("os")+ assert_path_exists bin/(OS.mac? ? "agent-desktop-macos-helper" : "agent-desktop-linux-clipboard-owner")endenddiff --git a/README.md b/README.mdindex 08d29ec0d..57f9c619f 100644--- a/README.md+++ b/README.md@@ -4,7 +4,7 @@<p align="center"><a href="https://github.com/lahfir/agent-desktop/actions/workflows/ci.yml?query=branch%3Amain"><img src="https://img.shields.io/github/actions/workflow/status/lahfir/agent-desktop/ci.yml?branch=main&style=for-the-badge" alt="CI status"></a> <a href="https://github.com/lahfir/agent-desktop/releases"><img src="https://img.shields.io/github/v/release/lahfir/agent-desktop?include_prereleases&style=for-the-badge" alt="GitHub release"></a> <a href="https://www.npmjs.com/package/agent-desktop"><img src="https://img.shields.io/npm/v/agent-desktop?label=npm&style=for-the-badge" alt="npm version"></a>- <a href="https://clawhub.ai/lahfir/agent-desktop"><img src="https://img.shields.io/badge/ClawHub-skill-f97316?style=for-the-badge" alt="ClawHub skill"></a> <a href="https://skills.sh/lahfir/agent-desktop/agent-desktop"><img src="https://img.shields.io/badge/skills.sh-listed-8b5cf6?style=for-the-badge" alt="skills.sh listing"></a> <a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache--2.0-blue.svg?style=for-the-badge" alt="Apache-2.0 License"></a>+ <a href="https://skills.sh/lahfir/agent-desktop/agent-desktop"><img src="https://img.shields.io/badge/skills.sh-listed-8b5cf6?style=for-the-badge" alt="skills.sh listing"></a> <a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache--2.0-blue.svg?style=for-the-badge" alt="Apache-2.0 License"></a></p><p align="center"><video src="https://github.com/user-attachments/assets/9b2c9f8c-a49d-4b69-b6cf-11d9e0d40ceb" controls width="800"></video></p>@@ -17,18 +17,39 @@ Snapshots, clipboard reads, screenshots, command output and debug artifacts can## Installation+Use a native package manager for a direct executable with no runtime wrapper or npm postinstall step.++**macOS and Linux** ([Homebrew](https://brew.sh)):+```bash-npm install -g agent-desktop-agent-desktop status # platform, permissions, supported surfaces+brew tap lahfir/agent-desktop https://github.com/lahfir/agent-desktop.git+brew install lahfir/agent-desktop/agent-desktop+```++**Windows** ([Scoop](https://scoop.sh)):++```powershell+scoop bucket add agent-desktop https://github.com/lahfir/agent-desktop.git+scoop install agent-desktop/agent-desktop```-The package works on macOS, Windows and Linux, on x64 and ARM64. Then check what your OS needs:+Homebrew links the native executable; Scoop adds its native executable directory to PATH without creating a shim.+Both select the matching x64 or ARM64 release and verify its pinned SHA-256. Run `agent-desktop version` to check+installation. If an older npm install appears first on PATH, uninstall it with its original package manager.-- **macOS** needs Accessibility permission: `agent-desktop permissions --guide`. See [permissions](docs/install.md#permissions).-- **Windows** needs no grant for apps at your terminal's integrity level. See [permissions](docs/install.md#permissions).-- **Linux** needs the user's graphical session with `at-spi2-core`. See [permissions](docs/install.md#permissions).+- **macOS** needs Accessibility permission: `agent-desktop permissions --guide`.+- **Windows** needs no grant for apps at your terminal's integrity level.+- **Linux** needs the user's graphical session with `at-spi2-core`.++See [installation and permissions](docs/install.md) for upgrades, release archives, and building from source.+**npm** remains supported on all three platforms:++```bash+npm install -g agent-desktop+```-The npm package bundles the native binaries and helpers for all six platform and architecture combinations, so installation also works with scripts blocked. When postinstall runs, POSIX commands link directly to the native binary and owned Windows npm/Yarn commands call the executable directly; blocked scripts and some package managers retain a launcher. To verify a release archive's origin, run `gh attestation verify`; see [docs/install.md](docs/install.md#release-archives). Building from source is covered in [docs/install.md](docs/install.md#from-source).+Bun, Yarn and pnpm can install the same `agent-desktop` package. Some npm-family paths retain their package+manager's launcher; the native packages above provide direct execution.## Quick startdiff --git a/bucket/agent-desktop.json b/bucket/agent-desktop.jsonnew file mode 100644index 000000000..8b9a05b22--- /dev/null+++ b/bucket/agent-desktop.json@@ -0,0 +1,17 @@+{+ "version": "0.11.1",+ "description": "Native accessibility-based desktop automation for agents",+ "homepage": "https://github.com/lahfir/agent-desktop",+ "license": "Apache-2.0",+ "architecture": {+ "64bit": {+ "url": "https://github.com/lahfir/agent-desktop/releases/download/v0.11.1/agent-desktop-v0.11.1-x86_64-pc-windows-msvc.tar.gz",+ "hash": "524c378e1afc7762f6e49b61cf58d45cbf0d54fecec618b2a1fd0d6fb282afe2"+ },+ "arm64": {+ "url": "https://github.com/lahfir/agent-desktop/releases/download/v0.11.1/agent-desktop-v0.11.1-aarch64-pc-windows-msvc.tar.gz",+ "hash": "d879c4130015d5d8a6d0c2c3935ca0d04c58624dc65259788785e6dd07f0fd8e"+ }+ },+ "env_add_path": "."+}diff --git a/docs/faq.md b/docs/faq.mdindex f04d2f784..fcab51041 100644--- a/docs/faq.md+++ b/docs/faq.md@@ -84,7 +84,6 @@ Public probe captures retain technical environment details such as OS versions a| Resource | Link ||----------|------|| **Repository** | [github.com/lahfir/agent-desktop](https://github.com/lahfir/agent-desktop) |-| **ClawHub Skill** | [clawhub.ai/lahfir/agent-desktop](https://clawhub.ai/lahfir/agent-desktop) || **skills.sh Listing** | [skills.sh/lahfir/agent-desktop/agent-desktop](https://skills.sh/lahfir/agent-desktop/agent-desktop) || **npm Package** | [npmjs.com/package/agent-desktop](https://www.npmjs.com/package/agent-desktop) || **CI Status** | [GitHub Actions](https://github.com/lahfir/agent-desktop/actions/workflows/ci.yml?query=branch%3Amain) |diff --git a/docs/install.md b/docs/install.mdindex 28e75f5bc..77fad1674 100644--- a/docs/install.md+++ b/docs/install.md@@ -1,12 +1,42 @@# Installing agent-desktop-The npm package works on macOS, Windows and Linux, on x64 and ARM64:+Native packages are the default on macOS, Windows and Linux, on x64 and ARM64. They install the released+executable without a JavaScript launcher or an agent-desktop postinstall script.++## macOS and Linux: Homebrew++With [Homebrew](https://brew.sh) installed:```bash-npm install -g agent-desktop-agent-desktop status # platform, permissions, supported surfaces+brew tap lahfir/agent-desktop https://github.com/lahfir/agent-desktop.git+brew install lahfir/agent-desktop/agent-desktop+agent-desktop version```+Homebrew creates a symlink to the native executable and installs its platform helper beside it. Upgrade with+`brew update && brew upgrade lahfir/agent-desktop/agent-desktop`; uninstall with+`brew uninstall lahfir/agent-desktop/agent-desktop`.++## Windows: Scoop++With [Scoop](https://scoop.sh) installed, run in a non-administrator PowerShell:++```powershell+scoop bucket add agent-desktop https://github.com/lahfir/agent-desktop.git+scoop install agent-desktop/agent-desktop+agent-desktop version+(Get-Command agent-desktop).Source+```++The command resolves to `apps\agent-desktop\current\agent-desktop.exe`. Scoop manages the `current` directory+junction and adds it to PATH. This package creates no `.cmd`, `.ps1`, or executable shim and has no install hooks.+Upgrade with `scoop update; scoop update agent-desktop`; uninstall with `scoop uninstall agent-desktop`.++Both managers check the archive against a SHA-256 pinned in the repository. The manual release workflow reads+`Cargo.toml` and opens a package-update PR using the published archives and their verified checksums. If a prior npm-family installation shadows the native command, uninstall+it through the manager that installed it, then open a new terminal. Check resolution with `command -v agent-desktop`+on macOS/Linux or `Get-Command agent-desktop` on Windows.+## Blocked install scriptsThe npm package includes the native binaries and helpers. With install scripts blocked, its launcher selects thediff --git a/scripts/check-gitleaks-policy.mjs b/scripts/check-gitleaks-policy.mjsindex 1b88da766..a040f515e 100644--- a/scripts/check-gitleaks-policy.mjs+++ b/scripts/check-gitleaks-policy.mjs@@ -36,7 +36,7 @@ function git(root, args) {}const benign = scan({- "paths.txt": ["/home/example-user/docs\n/Users/runner/work/project\n"].join(""),+ "paths.txt": ["/home/example-user/docs\n/Users/runner/work/project\n/home/linuxbrew/.linuxbrew/bin\n"].join(""),"addresses.txt": [@@ -50,9 +50,11 @@ const benign = scan({});assert.equal(benign.length, 0, `benign privacy examples triggered: ${benign.map((f) => f.RuleID).join(", ")}`);-const boundary = scan({ "paths.txt": ["/home/example-user", "2/docs\n"].join("") });-assert.ok(boundary.some((finding) => finding.RuleID === "ad-home-directory-path"),- "a username extending a documented placeholder was allowlisted");+for (const prefix of ["/home/example-user", "/home/linuxbrew"]) {+ const boundary = scan({ "paths.txt": `${prefix}2/docs\n` });+ assert.ok(boundary.some((finding) => finding.RuleID === "ad-home-directory-path"),+ "a username extending a documented placeholder was allowlisted");+}const findings = scan({"Cargo.lock": `token = ${credential}\n`,diff --git a/scripts/check-npm-package.js b/scripts/check-npm-package.jsindex e7cdfb2ae..bcb5f4609 100644--- a/scripts/check-npm-package.js+++ b/scripts/check-npm-package.js@@ -292,9 +292,6 @@ function selfTest() {' with:',' package-manager-cache: false',' - run: npm publish --access public',- ' publish-skills:',- ' steps:',- ' - run: echo skills','',].join('\n');diff --git a/scripts/check-release-consistency.sh b/scripts/check-release-consistency.shindex 2cdf94079..34d2ca56b 100755--- a/scripts/check-release-consistency.sh+++ b/scripts/check-release-consistency.sh@@ -9,15 +9,6 @@ fail() {exit 1}-read_toml_version() {- sed -n 's/^version *= *"\([^"]*\)".*/\1/p' Cargo.toml | head -1-}--read_json_version() {- local file="$1"- sed -n 's/.*"version" *: *"\([^"]*\)".*/\1/p' "$file" | head -1-}-lock_version_for() {local package="$1"awk -v target="$package" '@@ -49,14 +40,7 @@ lock_version_for() {' Cargo.lock}-workspace_version="$(read_toml_version)"-npm_version="$(read_json_version npm/package.json)"--[[ -n "$workspace_version" ]] || fail "could not read workspace version from Cargo.toml"-[[ -n "$npm_version" ]] || fail "could not read npm package version"--[[ "$npm_version" == "$workspace_version" ]] \- || fail "npm/package.json version ${npm_version} does not match Cargo.toml ${workspace_version}"+workspace_version="$(node scripts/release-version.js)"packages=(agent-desktopdiff --git a/scripts/open-release-package-pr.sh b/scripts/open-release-package-pr.shnew file mode 100644index 000000000..a925b591e--- /dev/null+++ b/scripts/open-release-package-pr.sh@@ -0,0 +1,32 @@+#!/usr/bin/env bash+set -euo pipefail++VERSION=$(node scripts/release-version.js)+BRANCH="release/packages-v${VERSION}"+git add -- Formula/agent-desktop.rb bucket/agent-desktop.json npm/package.json+if git diff --cached --quiet; then+ exit 0+fi++git switch -c "$BRANCH"+git config user.name "$(gh api "users/${GITHUB_ACTOR}" --jq '.name // .login')"+git config user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"+git commit -m "chore: update packages to ${VERSION}"+gh auth setup-git+REMOTE_SHA=$(git ls-remote --heads origin "refs/heads/$BRANCH" | cut -f1)+git push --force-with-lease="refs/heads/$BRANCH:$REMOTE_SHA" origin "HEAD:refs/heads/$BRANCH"++PR=$(gh pr list --head "$BRANCH" --base main --state open --json number --jq '.[0].number // empty')+if [ -z "$PR" ]; then+ BODY=$(mktemp)+ cat > "$BODY" <<'EOF'+Update native package definitions and npm source metadata from the published release.+All CLI archive hashes and the checksum manifest's release-workflow attestation were verified.+Repository and native installation checks run on this branch. Merge after review and green checks.+EOF+ gh pr create --base main --head "$BRANCH" \+ --title "chore: update packages to ${VERSION}" --body-file "$BODY"+fi+for workflow in ci.yml supply-chain.yml codeql.yml homebrew.yml scoop.yml; do+ gh workflow run "$workflow" --ref "$BRANCH"+donediff --git a/scripts/prepare-release.sh b/scripts/prepare-release.shindex db9f76490..37ecc576a 100644--- a/scripts/prepare-release.sh+++ b/scripts/prepare-release.sh@@ -1,11 +1,7 @@#!/usr/bin/env bashset -euo pipefailbash scripts/check-release-consistency.sh-VERSION=$(node -p "require('./npm/package.json').version")-if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then- echo "Invalid version: ${VERSION}" >&2- exit 1-fi+VERSION=$(node "$(dirname "${BASH_SOURCE[0]}")/release-version.js")TAG_NAME="v${VERSION}"NPM_VERSION=$(npm view agent-desktop version 2>/dev/null || echo "0.0.0")SHOULD_RELEASE=false@@ -20,7 +16,7 @@ SOURCE_SHA=$(git rev-parse HEAD)if [ "$SHOULD_RELEASE" = true ] || [ "$NEEDS_GITHUB_RELEASE" = true ]; thenif git rev-parse --verify "refs/tags/${TAG_NAME}" >/dev/null 2>&1; thenSOURCE_SHA=$(git rev-parse "refs/tags/${TAG_NAME}^{commit}")- TAG_VERSION=$(git show "${SOURCE_SHA}:npm/package.json" | node -pe 'JSON.parse(require("fs").readFileSync(0, "utf8")).version')+ TAG_VERSION=$(git show "${SOURCE_SHA}:Cargo.toml" | node "$(dirname "${BASH_SOURCE[0]}")/release-version.js" -)if [ "$TAG_VERSION" != "$VERSION" ]; thenecho "Existing tag ${TAG_NAME} has inconsistent version metadata" >&2exit 1diff --git a/scripts/release-version.js b/scripts/release-version.jsnew file mode 100644index 000000000..5c1b9f977--- /dev/null+++ b/scripts/release-version.js@@ -0,0 +1,15 @@+const { readFileSync } = require('node:fs');++function releaseVersion(toml) {+ const section = toml.split(/^\[workspace\.package\][ \t]*\r?$/m)[1]?.split(/^\[/m)[0];+ const version = section?.match(/^version[ \t]*=[ \t]*"([^"\r\n]+)"[ \t]*\r?$/m)?.[1];+ if (!version || !/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?$/.test(version)) {+ throw new Error('Cargo.toml must contain a valid workspace.package.version');+ }+ return version;+}++if (require.main === module) {+ console.log(releaseVersion(readFileSync(process.argv[2] === '-' ? 0 : 'Cargo.toml', 'utf8')));+}+module.exports = { releaseVersion };diff --git a/scripts/update-release-packages.js b/scripts/update-release-packages.jsnew file mode 100644index 000000000..a2553adc4--- /dev/null+++ b/scripts/update-release-packages.js@@ -0,0 +1,52 @@+const { createHash } = require('node:crypto');+const { readFileSync, writeFileSync } = require('node:fs');+const { join } = require('node:path');+const { PLATFORMS, tarballName } = require('../npm/lib/platform');+const { checksumFor } = require('../npm/scripts/postinstall');+const { releaseVersion } = require('./release-version');++function updateReleasePackages(root, archives) {+ const version = releaseVersion(readFileSync(join(root, 'Cargo.toml'), 'utf8'));+ const npmPath = join(root, 'npm/package.json');+ const npm = JSON.parse(readFileSync(npmPath, 'utf8'));+ const repository = npm.repository.url.replace(/^git\+/, '').replace(/\.git$/, '');+ const checksums = readFileSync(join(archives, 'checksums.txt'), 'utf8');+ const packages = {};+ for (const [key, platform] of Object.entries(PLATFORMS)) {+ if (!platform.released) continue;+ const name = tarballName(version, platform.target);+ const hash = createHash('sha256').update(readFileSync(join(archives, name))).digest('hex');+ if (hash !== checksumFor(checksums, name)) throw new Error(`Checksum mismatch for ${name}`);+ packages[key] = { url: `${repository}/releases/download/v${version}/${name}`, hash };+ }++ const formulaPath = join(root, 'Formula/agent-desktop.rb');+ let formula = readFileSync(formulaPath, 'utf8').replace(/\r\n/g, '\n');+ if ((formula.match(/^ version "[^"\n]+"$/gm) || []).length !== 1) {+ throw new Error('Expected one Homebrew version');+ }+ formula = formula.replace(/^ version "[^"\n]+"$/m, ` version "${version}"`);+ for (const [key, platform] of Object.entries(PLATFORMS)) {+ if (!platform.released || key.startsWith('win32-')) continue;+ const pattern = new RegExp(`url "[^"\\n]+-${platform.target}\\.tar\\.gz"\\r?\\n( +)sha256 "[0-9a-f]{64}"`, 'g');+ if ([...formula.matchAll(pattern)].length !== 1) throw new Error(`Expected one Homebrew archive for ${key}`);+ const { url, hash } = packages[key];+ formula = formula.replace(pattern, (_, indent) => `url "${url}"\n${indent}sha256 "${hash}"`);+ }++ const scoopPath = join(root, 'bucket/agent-desktop.json');+ const scoop = JSON.parse(readFileSync(scoopPath, 'utf8'));+ scoop.version = version;+ scoop.architecture = { '64bit': packages['win32-x64'], arm64: packages['win32-arm64'] };+ npm.version = version;++ writeFileSync(formulaPath, formula);+ writeFileSync(scoopPath, `${JSON.stringify(scoop, null, 4)}\n`);+ writeFileSync(npmPath, `${JSON.stringify(npm, null, 2)}\n`);+}++if (require.main === module) {+ if (!process.argv[2]) throw new Error('Usage: node scripts/update-release-packages.js ARCHIVE_DIRECTORY');+ updateReleasePackages(process.cwd(), process.argv[2]);+}+module.exports = { updateReleasePackages };diff --git a/tests/native-install/homebrew.sh b/tests/native-install/homebrew.shnew file mode 100644index 000000000..70ce72e71--- /dev/null+++ b/tests/native-install/homebrew.sh@@ -0,0 +1,35 @@+#!/usr/bin/env bash+set -euo pipefail++TAP=lahfir/agent-desktop-ci+TAP_PATH="$(brew --repository)/Library/Taps/lahfir/homebrew-agent-desktop-ci"+test ! -e "$TAP_PATH"+test ! -e "$(brew --cellar)/agent-desktop"+mkdir -p "$TAP_PATH/Formula"+git -C "$TAP_PATH" init+git -C "$TAP_PATH" -c user.name=Lahfir -c [email protected] \+ commit --allow-empty -m 'test: initialize native installation tap'+cp Formula/agent-desktop.rb "$(brew --repo "$TAP")/Formula/agent-desktop.rb"+brew install "$TAP/agent-desktop"+brew test "$TAP/agent-desktop"+PREFIX=$(brew --prefix)+BINARY="$PREFIX/bin/agent-desktop"+KEG=$(brew --prefix "$TAP/agent-desktop")+test -L "$BINARY"+test "$BINARY" -ef "$KEG/bin/agent-desktop"+case "$(uname -s)" in+ Darwin) HELPER=agent-desktop-macos-helper ;;+ Linux) HELPER=agent-desktop-linux-clipboard-owner ;;+esac+test "$PREFIX/bin/$HELPER" -ef "$KEG/bin/$HELPER"+test "$(head -c 2 "$BINARY")" != '#!'+env -i HOME="$HOME" PATH="$KEG/bin" agent-desktop version+env -i HOME="$HOME" PATH="$KEG/bin" agent-desktop permissions+brew unlink agent-desktop+brew link agent-desktop+test "$BINARY" -ef "$KEG/bin/agent-desktop"+brew uninstall "$TAP/agent-desktop"+test ! -e "$BINARY"+test ! -L "$BINARY"+test ! -e "$PREFIX/bin/$HELPER"+brew untap "$TAP"diff --git a/tests/native-install/scoop.ps1 b/tests/native-install/scoop.ps1new file mode 100644index 000000000..91632e94e--- /dev/null+++ b/tests/native-install/scoop.ps1@@ -0,0 +1,73 @@+param(+ [Parameter(Mandatory = $true)][string]$ScoopRoot,+ [Parameter(Mandatory = $true)][string]$Manifest+)+$ErrorActionPreference = 'Stop'+$env:SCOOP = [IO.Path]::GetFullPath($ScoopRoot)+$env:SCOOP_CACHE = Join-Path $env:SCOOP 'cache'+$env:XDG_CONFIG_HOME = Join-Path $env:SCOOP 'config'+$scoop = Join-Path $env:SCOOP 'apps/scoop/current/bin/scoop.ps1'+$manifestData = Get-Content -Raw $Manifest | ConvertFrom-Json+$originalPath = $env:PATH+foreach ($app in @('agent-desktop', '7zip')) {+ if (Test-Path (Join-Path $env:SCOOP "apps/$app")) { throw "Test requires a fresh Scoop root: $app already exists" }+}+New-Item -ItemType Directory -Force (Join-Path $env:SCOOP 'shims'), (Join-Path $env:SCOOP 'buckets') | Out-Null++function Invoke-Scoop {+ & powershell -NoProfile -File $scoop @args+ if ($LASTEXITCODE -ne 0) { throw "Scoop failed: $args" }+}++function Assert-NativeCommand {+ $current = Join-Path $env:SCOOP 'apps/agent-desktop/current'+ $binary = Join-Path $current 'agent-desktop.exe'+ $registeredPath = [Environment]::GetEnvironmentVariable('Path', 'User') -split ';'+ if ($current -notin $registeredPath) { throw 'Native directory was not registered on PATH' }+ $junction = Get-Item $current+ if ($junction.LinkType -ne 'Junction') { throw 'Current version is not a directory junction' }+ if (@(Get-ChildItem (Join-Path $env:SCOOP 'shims') -Filter 'agent-desktop*').Count) {+ throw 'Scoop created an agent-desktop shim'+ }+ $versionedBinary = Join-Path $env:SCOOP "apps/agent-desktop/$($manifestData.version)/agent-desktop.exe"+ if ((Get-FileHash $binary).Hash -ne (Get-FileHash $versionedBinary).Hash) {+ throw 'PATH executable differs from installed release'+ }+ $magic = [IO.File]::ReadAllBytes($binary)+ if ($magic[0] -ne 77 -or $magic[1] -ne 90) { throw 'Command is not a native PE executable' }+ $env:PATH = "$current;$env:SystemRoot/System32;$env:SystemRoot"+ try {+ if ((Get-Command agent-desktop).Source -ne $binary) { throw 'Command is shadowed' }+ if (Get-Command node -ErrorAction SilentlyContinue) { throw 'Node is unexpectedly available' }+ foreach ($command in @('version', 'permissions')) {+ $response = & agent-desktop $command | ConvertFrom-Json+ if ($LASTEXITCODE -ne 0 -or -not $response.ok) { throw "Native $command failed" }+ if ($command -eq 'version' -and $response.data.version -ne $manifestData.version) {+ throw 'Installed version does not match manifest'+ }+ }+ } finally {+ $env:PATH = $originalPath+ }+}++try {+ Invoke-Scoop bucket add main+ Invoke-Scoop install --no-update-scoop $Manifest+ Assert-NativeCommand+ Invoke-Scoop reset agent-desktop+ Assert-NativeCommand+ Invoke-Scoop uninstall agent-desktop+ $current = Join-Path $env:SCOOP 'apps/agent-desktop/current'+ if (Test-Path $current) { throw 'Uninstall retained the native command' }+ if ($current -in ([Environment]::GetEnvironmentVariable('Path', 'User') -split ';')) {+ throw 'Uninstall retained the PATH entry'+ }+ Invoke-Scoop uninstall 7zip+ Write-Output 'PASS: fresh Scoop install, native PATH, no Node, reset and uninstall'+} finally {+ $userPath = [Environment]::GetEnvironmentVariable('Path', 'User')+ $cleanPath = ($userPath -split ';' | Where-Object { -not $_.StartsWith($env:SCOOP + '\', [StringComparison]::OrdinalIgnoreCase) }) -join ';'+ if ($userPath -ne $cleanPath) { [Environment]::SetEnvironmentVariable('Path', $cleanPath, 'User') }+ $env:PATH = $originalPath+}diff --git a/tests/npm/release-workflows.test.js b/tests/npm/release-workflows.test.jsindex 42a9f9565..d1b2fe482 100644--- a/tests/npm/release-workflows.test.js+++ b/tests/npm/release-workflows.test.js@@ -144,7 +144,7 @@ test('the dry run grants no write scope and has no publish step', () => {assert.doesNotMatch(dryRunWorkflow, /:\s*write\b/, 'no permission scope may be write');assert.doesNotMatch(dryRunWorkflow, /\bnpm publish\b/);assert.doesNotMatch(dryRunWorkflow, /gh release (create|upload|edit)/);- assert.doesNotMatch(dryRunWorkflow, /attest-build-provenance|clawhub|secrets\./);+ assert.doesNotMatch(dryRunWorkflow, /attest-build-provenance|secrets\./);const jobs = dryRunWorkflow.match(/^ {2}[a-z][a-z-]*:$/gm) ?? [];assert.deepEqual(jobs.map((job) => job.trim().slice(0, -1)).sort(),diff --git a/tests/release/package-pr.test.js b/tests/release/package-pr.test.jsnew file mode 100644index 000000000..7819227c0--- /dev/null+++ b/tests/release/package-pr.test.js@@ -0,0 +1,73 @@+const assert = require('node:assert/strict');+const { execFileSync, spawnSync } = require('node:child_process');+const { copyFileSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } = require('node:fs');+const { tmpdir } = require('node:os');+const { join, resolve } = require('node:path');+const { test } = require('node:test');++const source = resolve(__dirname, '../..');+const files = ['Formula/agent-desktop.rb', 'bucket/agent-desktop.json', 'npm/package.json'];++test('package PR creation is repeatable, excludes unrelated files, and stops on push failure', { skip: process.platform === 'win32' }, () => {+ const root = mkdtempSync(join(tmpdir(), 'ad-package-pr-'));+ const remote = join(root, 'origin.git');+ const tools = join(root, 'tools');+ const calls = join(root, 'gh.log');+ const marker = join(root, 'pr-created');+ mkdirSync(tools);+ writeFileSync(calls, '');+ writeFileSync(join(tools, 'gh'), `#!/bin/sh+set -eu+printf '%s\\n' "$*" >> "$TEST_GH_LOG"+case "$1 $2" in+ 'api users/'*) printf 'Release Actor\\n' ;;+ 'auth setup-git') ;;+ 'pr list') if [ -f "$TEST_PR_MARKER" ]; then printf '42\\n'; fi ;;+ 'pr create') touch "$TEST_PR_MARKER" ;;+ 'workflow run') ;;+ *) exit 99 ;;+esac+`, { mode: 0o755 });+ const runGit = (cwd, ...args) => execFileSync('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim();+ runGit(root, 'init', '--bare', '-q', remote);+ const main = join(root, 'main');+ runGit(root, 'clone', '-q', remote, main);+ runGit(main, 'switch', '-c', 'main');+ for (const directory of ['scripts', 'Formula', 'bucket', 'npm']) mkdirSync(join(main, directory));+ for (const script of ['release-version.js', 'open-release-package-pr.sh']) copyFileSync(join(source, 'scripts', script), join(main, 'scripts', script));+ writeFileSync(join(main, 'Cargo.toml'), '[workspace.package]\nversion = "1.2.3"\n');+ for (const file of files) writeFileSync(join(main, file), 'previous release\n');+ runGit(main, 'add', '.');+ runGit(main, '-c', 'user.name=Lahfir', '-c', '[email protected]', 'commit', '-qm', 'test: release fixture');+ runGit(main, 'push', '-q', 'origin', 'main');+ const branch = 'release/packages-v1.2.3';+ const execute = (name, changed) => {+ const checkout = join(root, name);+ runGit(root, 'clone', '-q', '--branch', 'main', remote, checkout);+ if (changed) for (const file of files) writeFileSync(join(checkout, file), `new release ${name}\n`);+ writeFileSync(join(checkout, 'unrelated.txt'), 'leave untouched\n');+ return spawnSync('bash', ['scripts/open-release-package-pr.sh'], {+ cwd: checkout, encoding: 'utf8', env: { ...process.env,+ PATH: `${tools}:${process.env.PATH}`, GITHUB_ACTOR: 'release-actor', GITHUB_ACTOR_ID: '123',+ TEST_GH_LOG: calls, TEST_PR_MARKER: marker },+ });+ };+ for (const name of ['first', 'repeat']) {+ const result = execute(name, true);+ assert.equal(result.status, 0, result.stderr);+ assert.deepEqual(runGit(remote, 'diff-tree', '--no-commit-id', '--name-only', '-r', branch).split('\n'), files);+ assert.equal(runGit(remote, 'show', '-s', '--format=%an <%ae>', branch), 'Release Actor <[email protected]>');+ }+ const log = readFileSync(calls, 'utf8');+ assert.equal(log.split('\n').filter((line) => line.startsWith('pr create ')).length, 1);+ assert.equal(log.split('\n').filter((line) => line.startsWith('workflow run ')).length, 10);+ const before = runGit(remote, 'rev-parse', branch);+ assert.equal(execute('unchanged', false).status, 0);+ assert.equal(readFileSync(calls, 'utf8'), log);+ writeFileSync(join(remote, 'hooks/pre-receive'), '#!/bin/sh\nexit 1\n', { mode: 0o755 });+ const rejected = execute('rejected', true);+ assert.notEqual(rejected.status, 0);+ assert.match(rejected.stderr, /pre-receive hook declined/);+ assert.equal(runGit(remote, 'rev-parse', branch), before);+ assert.equal(readFileSync(calls, 'utf8').split('\n').filter((line) => /^(pr|workflow) /.test(line)).join('\n'), log.split('\n').filter((line) => /^(pr|workflow) /.test(line)).join('\n'));+});diff --git a/tests/release/packages.test.js b/tests/release/packages.test.jsnew file mode 100644index 000000000..122788a28--- /dev/null+++ b/tests/release/packages.test.js@@ -0,0 +1,90 @@+const assert = require('node:assert/strict');+const { createHash } = require('node:crypto');+const { copyFileSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } = require('node:fs');+const { tmpdir } = require('node:os');+const { join, resolve } = require('node:path');+const { test } = require('node:test');+const { PLATFORMS, tarballName } = require('../../npm/lib/platform');+const { releaseVersion } = require('../../scripts/release-version');+const { updateReleasePackages } = require('../../scripts/update-release-packages');++const files = ['Formula/agent-desktop.rb', 'bucket/agent-desktop.json', 'npm/package.json'];+function fixture() {+ const root = mkdtempSync(join(tmpdir(), 'ad-release-packages-'));+ for (const name of ['Formula', 'bucket', 'npm', 'archives']) mkdirSync(join(root, name));+ for (const file of files) copyFileSync(resolve(__dirname, '../..', file), join(root, file));+ writeFileSync(join(root, 'Cargo.toml'), '[workspace.package]\nversion = "0.12.3"\n');+ const archives = join(root, 'archives');+ const expected = {};+ for (const [key, platform] of Object.entries(PLATFORMS)) {+ const name = tarballName('0.12.3', platform.target);+ const content = Buffer.from(`release artifact for ${key}`);+ const hash = createHash('sha256').update(content).digest('hex');+ writeFileSync(join(archives, name), content);+ expected[key] = { name, hash };+ }+ writeFileSync(join(archives, 'checksums.txt'), Object.values(expected).map(({ name, hash }) => `${hash} ${name}`).join('\n'));+ return { root, archives, expected };+}+const contents = (root) => files.map((file) => readFileSync(join(root, file), 'utf8'));++test('one Cargo version updates all six archives and npm; regeneration is a no-op', () => {+ const { root, archives, expected } = fixture();+ const packagePath = join(root, 'npm/package.json');+ const metadata = JSON.parse(readFileSync(packagePath, 'utf8'));+ metadata.repository.url = 'git+https://github.com/release-owner/desktop-tool.git';+ writeFileSync(packagePath, JSON.stringify(metadata));+ updateReleasePackages(root, archives);+ const [formula, scoopText, npmText] = contents(root);+ const scoop = JSON.parse(scoopText);+ assert.equal(JSON.parse(npmText).version, '0.12.3');+ assert.equal(scoop.version, '0.12.3');+ assert.match(formula, /version "0\.12\.3"/);+ for (const [key, { name, hash }] of Object.entries(expected)) {+ const url = `https://github.com/release-owner/desktop-tool/releases/download/v0.12.3/${name}`;+ if (key.startsWith('win32-')) {+ assert.deepEqual(scoop.architecture[key.endsWith('x64') ? '64bit' : 'arm64'], { url, hash });+ } else {+ assert.ok(formula.includes(`url "${url}"\n sha256 "${hash}"`));+ }+ }+ assert.equal(scoop.env_add_path, '.');+ assert.equal(scoop.bin, undefined);+ assert.equal(scoop.post_install, undefined);+ assert.match(formula, /bin\.install "agent-desktop-macos-helper"/);+ assert.match(formula, /bin\.install "agent-desktop-linux-clipboard-owner"/);+ const once = contents(root);+ updateReleasePackages(root, archives);+ assert.deepEqual(contents(root), once);+});++test('metadata generation accepts a Windows checkout with CRLF', () => {+ const { root, archives } = fixture();+ const formula = join(root, files[0]);+ writeFileSync(formula, readFileSync(formula, 'utf8').replace(/\r?\n/g, '\r\n'));+ updateReleasePackages(root, archives);+ assert.match(readFileSync(formula, 'utf8'), /version "0\.12\.3"/);+});++for (const problem of ['corrupt archive', 'missing checksum', 'changed formula', 'invalid version']) {+ test(`${problem} fails before any package file is updated`, () => {+ const { root, archives, expected } = fixture();+ if (problem === 'corrupt archive') writeFileSync(join(archives, expected['win32-x64'].name), 'tampered');+ if (problem === 'missing checksum') writeFileSync(join(archives, 'checksums.txt'), '');+ if (problem === 'changed formula') writeFileSync(join(root, files[0]), 'unrecognized formula');+ if (problem === 'invalid version') writeFileSync(join(root, 'Cargo.toml'), '[workspace.package]\nversion = "../../bad"\n');+ const before = contents(root);+ assert.throws(() => updateReleasePackages(root, archives));+ assert.deepEqual(contents(root), before);+ });+}++test('version comes only from the workspace package section', () => {+ const toml = '[package]\nversion = "9.9.9"\n[workspace.package]\nversion = "1.2.3"\n[dependencies]\nversion = "8.8.8"\n';+ assert.equal(releaseVersion(toml), '1.2.3');+ assert.equal(releaseVersion(toml.replaceAll('\n', '\r\n')), '1.2.3');+ for (const version of ['', '1.2', 'v1.2.3', '1.2.3;echo bad', '01.2.3']) {+ assert.throws(() => releaseVersion(`[workspace.package]\nversion = "${version}"\n`));+ }+ assert.throws(() => releaseVersion('[package]\nversion = "1.2.3"\n'));+});diff --git a/tests/release/prepare.test.js b/tests/release/prepare.test.jsindex c7ade0e13..8e3757c0e 100644--- a/tests/release/prepare.test.js+++ b/tests/release/prepare.test.js@@ -8,7 +8,8 @@ const { test } = require('node:test');function fixture() {const root = mkdtempSync(join(tmpdir(), 'ad-release-gate-'));for (const name of ['scripts', 'npm', 'tools']) mkdirSync(join(root, name));- writeFileSync(join(root, 'npm/package.json'), '{"version":"0.10.2"}');+ writeFileSync(join(root, 'npm/package.json'), '{"version":"0.9.0"}');+ writeFileSync(join(root, 'Cargo.toml'), '[workspace.package]\nversion = "0.10.2"\n');writeFileSync(join(root, 'scripts/check-release-consistency.sh'), 'exit 0\n');writeFileSync(join(root, 'tools/npm'), '#!/bin/sh\nprintf "%s\\n" "$TEST_NPM_VERSION"\n', { mode: 0o755 });writeFileSync(join(root, 'tools/gh'), '#!/bin/sh\nif [ "$1" = release ]; then exit "$TEST_GITHUB_STATUS"; fi\nprintf "%s\\n" "$*" >> "$TEST_GH_LOG"\n', { mode: 0o755 });