diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 75ace0e..736ca6c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -125,6 +125,9 @@ jobs: shellcheck npm/bootstrap-names.sh npm/test-bootstrap-names.sh - name: trust_state fixtures run: bash npm/test-bootstrap-names.sh + - name: launcher exit status + # A binary killed by a signal must not look like a success (#87). + run: node --test npm/test-launcher.js test: name: test (${{ matrix.os }}) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index f5c10ee..c514afe 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -4,17 +4,17 @@ name: Publish to npm # trust target on every published package's npmjs.com settings — # `workflow_filename = npm-publish.yml` in npm's Trusted Publisher UI. # -# It publishes EIGHT packages in two independent jobs: +# It publishes SEVEN packages in the one `publish-optional-deps` job: +# @bugsee/cli + the six @bugsee/cli- packages — the binary split per +# os/cpu behind optionalDependencies, assembled by npm/build.mjs from the +# release's binary archives. See npm/README.md. # -# publish @bugsee/bugsee-cli — the cargo-dist npm installer, -# one package whose postinstall downloads the binary. -# Taken verbatim from the release asset. -# publish-optional-deps @bugsee/cli + the six @bugsee/cli- -# packages — the binary split per os/cpu behind -# optionalDependencies, assembled by npm/build.mjs -# from the release's binary archives. See npm/README.md. +# The legacy single-package `@bugsee/bugsee-cli` (the cargo-dist npm installer) +# is NOT published from here any more: its launcher exited 0 when the binary was +# killed by a signal (#87). It was frozen at 0.8.2 (the one patched release) and +# deprecated in favour of @bugsee/cli. Do not re-add a job for it. # -# EVERY ONE of those eight names needs its OWN Trusted Publisher entry on +# EVERY ONE of those seven names needs its OWN Trusted Publisher entry on # npmjs.com (repository bugsee/bugsee-cli, workflow npm-publish.yml) before its # FIRST publish. That entry lives on a PACKAGE's settings page, so it cannot # even be created for a name that has never been published: each new name needs @@ -25,16 +25,14 @@ name: Publish to npm # # >>> RUNBOOK: `bash npm/bootstrap-names.sh ` does both steps and is # >>> idempotent; npm/README.md, "First-publish bootstrap" explains it. Read it before the -# >>> first release that includes the @bugsee/cli family. @bugsee/bugsee-cli is -# >>> already bootstrapped and needs nothing. +# >>> first release that includes a new package name. # # Why a separate workflow (and not folded into release.yml): # `dist init` regenerates release.yml on every dist upgrade and would # silently clobber any OIDC wiring there. Keeping the npm publish in # our own workflow file insulates it from dist's lifecycle. dist still -# generates the `bugsee-cli-npm-package.tar.gz` tarball as a GitHub -# Release asset (via `installers = [..., "npm"]`); we just download -# the asset and publish ourselves. +# builds the per-platform binary archives and attaches them to the GitHub +# Release; we just download those and publish ourselves. # # Triggers: # - `workflow_run` on the dist `Release` workflow completing — the @@ -47,7 +45,7 @@ name: Publish to npm # it fires reliably. Guarded to a SUCCESSFUL, tag-`push`-triggered # Release whose tag looks like `vX.Y.Z` (PR-mode Release runs and # failed releases are skipped). By the time Release has completed, -# the npm tarball asset is already attached to the release. +# the binary archives are already attached to the release. # - `workflow_dispatch` with a `tag` input — the MANUAL path, for # backfilling missing versions or re-publishing a specific release. # @@ -84,134 +82,21 @@ concurrency: cancel-in-progress: false jobs: - publish: - name: publish to npm via OIDC + publish-optional-deps: + name: publish @bugsee/cli family via OIDC runs-on: ubuntu-latest # Manual dispatch always runs. The automated path runs only for a # SUCCESSFUL Release that was triggered by a tag PUSH whose ref looks # like a version tag — this filters out PR-mode Release runs (which # complete with event == 'pull_request') and failed releases. The - # exact `vX.Y.Z` shape is re-checked in `resolve` as a belt-and-braces - # guard (`startsWith(..., 'v')` alone would also match e.g. `vnext`). - if: >- - github.event_name == 'workflow_dispatch' || - (github.event.workflow_run.conclusion == 'success' && - github.event.workflow_run.event == 'push' && - startsWith(github.event.workflow_run.head_branch, 'v')) - steps: - - name: Resolve release tag - id: resolve - env: - # Via env, never interpolated into the script: head_branch and the - # dispatch input are untrusted strings (defence in depth), and `${{ }}` is - # substituted BEFORE the shell parses the script (code injection). - EVENT_NAME: ${{ github.event_name }} - INPUT_TAG: ${{ github.event.inputs.tag }} - HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} - run: | - if [ "$EVENT_NAME" = "workflow_dispatch" ]; then - tag="$INPUT_TAG" - else - tag="$HEAD_BRANCH" - fi - # A newline would let the value smuggle extra `key=value` lines into - # $GITHUB_OUTPUT (e.g. should_publish=true) — refuse before writing it. - case "$tag" in *$'\n'*|*$'\r'*) echo "::error::tag contains a newline"; exit 1 ;; esac - echo "tag=$tag" >> "$GITHUB_OUTPUT" - if echo "$tag" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+'; then - echo "should_publish=true" >> "$GITHUB_OUTPUT" - echo "Resolved release tag: $tag" - else - echo "should_publish=false" >> "$GITHUB_OUTPUT" - echo "::notice::'$tag' is not a version tag (vX.Y.Z); skipping npm publish." - fi - - - name: Setup Node - # DELIBERATELY no `registry-url:` here — setup-node@v6 with that - # option writes an .npmrc containing - # `//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}`, which - # tells npm to use token auth instead of OIDC. We want the - # opposite: no .npmrc, so npm 11.5+ auto-uses the OIDC token - # minted from `permissions: id-token: write` above. - if: steps.resolve.outputs.should_publish == 'true' - uses: actions/setup-node@v7 - with: - node-version: '22' - - - name: Upgrade npm to satisfy Trusted Publishing floor (≥ 11.5.1) - # Node 22's bundled npm is below the OIDC floor as of 2026. - if: steps.resolve.outputs.should_publish == 'true' - run: | - npm install -g npm@latest - node --version - npm --version - - - name: Download npm package tarball from release - if: steps.resolve.outputs.should_publish == 'true' - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - TAG: ${{ steps.resolve.outputs.tag }} - run: | - mkdir -p release-assets - gh release download "$TAG" \ - --repo "$GITHUB_REPOSITORY" \ - --dir release-assets \ - --pattern 'bugsee-cli-npm-package.tar.gz' - ls -la release-assets/ - - - name: Publish via OIDC - # `npm publish ` accepts an npm-pack-format tarball - # directly — no extraction needed. npm 11.5+ detects the - # ACTIONS_ID_TOKEN_REQUEST_* env vars GitHub injects when - # `id-token: write` is granted, mints the OIDC token, and - # presents it to the registry. Trust on npmjs.com side maps - # (repo, workflow filename) → @bugsee/bugsee-cli publish. - # - # Absolute path is critical: a bare relative path like - # `release-assets/bugsee-cli-npm-package.tar.gz` is parsed by - # npm as a git spec (`owner/repo`) and routed through git - # ls-remote, failing with a confusing SSH/permission error. - # - # `--tag` is intentionally omitted so each publish moves - # `dist-tags.latest`; the automated path always runs for the - # newest release, and manual backfills must be run oldest→newest - # so `latest` ends on the highest version. - # - # `--provenance` emits a sigstore build-provenance attestation - # (supply-chain integrity). It requires a PUBLIC source repo, and - # bugsee/bugsee-cli is public — so it's enabled. If the repo ever - # goes private again, drop this flag: npm rejects provenance from - # private repos with `E422 … repository visibility: "private"` - # (OIDC auth itself is unaffected by visibility). - # - # Do NOT add `env: NODE_AUTH_TOKEN: ...` — even an empty value - # makes npm prefer broken token auth over OIDC. - if: steps.resolve.outputs.should_publish == 'true' - run: | - tarball="$GITHUB_WORKSPACE/release-assets/bugsee-cli-npm-package.tar.gz" - ls -la "$tarball" - npm publish "$tarball" --access public --provenance - - publish-optional-deps: - name: publish @bugsee/cli family via OIDC - runs-on: ubuntu-latest - # DELIBERATELY NOT `needs: publish`. The two jobs publish different - # packages from the same release and neither depends on the other's - # output; chaining them would make a @bugsee/bugsee-cli failure (or a - # re-publish of an already-published version) suppress the family, and - # vice versa. They share only the trigger. - # - # Same guard as `publish` above, for the same reasons — see its comment. + # exact `vX.Y.Z` shape is re-checked in `resolve` + # (`startsWith(..., 'v')` alone would also match e.g. `vnext`). if: >- github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push' && startsWith(github.event.workflow_run.head_branch, 'v')) steps: - # Repeated rather than factored into a shared `resolve` job on purpose: - # hoisting it would mean editing the `publish` job above, which is the - # live, working OIDC path for @bugsee/bugsee-cli. Ten duplicated lines - # are cheaper than any risk to that. - name: Resolve release tag id: resolve env: @@ -231,15 +116,11 @@ jobs: # $GITHUB_OUTPUT (e.g. should_publish=true) — refuse before writing it. case "$tag" in *$'\n'*|*$'\r'*) echo "::error::tag contains a newline"; exit 1 ;; esac echo "tag=$tag" >> "$GITHUB_OUTPUT" - # ANCHORED, unlike the `publish` job's copy above. Unanchored, - # `^v[0-9]+\.[0-9]+\.[0-9]+` also matches `v1.2.3-rc1`, which would - # then publish as 1.2.3-rc1 with no `--tag` and MOVE - # `dist-tags.latest` onto a prerelease. Here that would hit all seven - # packages at once, so prereleases are matched explicitly and routed - # to `next` rather than silently treated as stable. The same latent - # bug in the `publish` job above is deliberately left alone: that is - # the live @bugsee/bugsee-cli path and is out of scope for this - # change. Worth a follow-up. + # ANCHORED. Unanchored, `^v[0-9]+\.[0-9]+\.[0-9]+` also matches + # `v1.2.3-rc1`, which would then publish as 1.2.3-rc1 with no `--tag` + # and MOVE `dist-tags.latest` onto a prerelease. That would hit all + # seven packages at once, so prereleases are matched explicitly and + # routed to `next` rather than silently treated as stable. if echo "$tag" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then { echo "should_publish=true" @@ -278,9 +159,9 @@ jobs: persist-credentials: false - name: Setup Node - # No `registry-url:` — see the note on the same step in `publish`. - # An .npmrc with `_authToken` would make npm prefer token auth over - # the OIDC token and every publish below would fail. + # DELIBERATELY no `registry-url:` — setup-node with that option writes + # an .npmrc with `_authToken=${NODE_AUTH_TOKEN}`, which makes npm prefer + # token auth over the OIDC token, and every publish below would fail. if: steps.resolve.outputs.should_publish == 'true' uses: actions/setup-node@v7 with: diff --git a/CLAUDE.md b/CLAUDE.md index 49a4fb9..42f24e1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -169,21 +169,20 @@ size-check FAIL can fail the build (exit 40). ## Distribution & activation Releases are tag-driven: pushing a `vX.Y.Z` tag runs `release.yml` (cargo-dist -builds the target triples + a GitHub Release with shell/powershell/npm/homebrew +builds the target triples + a GitHub Release with shell/powershell/homebrew installers). Two workflows then chain off it automatically via `workflow_run` — `npm-publish.yml` (npm, via OIDC Trusted Publishing) and `mirror-to-s3.yml` (`download.bugsee.com/cli/v/` + the `latest` alias and the `cli/v.x/version.txt` pointer that `bugsee-cli update` reads). Both also keep a `workflow_dispatch` path for backfilling a missed version. -`npm-publish.yml` has TWO independent jobs, because npm ships two packages -for the same binary: `publish` takes the cargo-dist-generated -`bugsee-cli-npm-package.tar.gz` release asset straight to `@bugsee/bugsee-cli` -(a single package whose postinstall downloads the binary), while -`publish-optional-deps` runs `npm/build.mjs` over the release's binary archives -to assemble and publish `@bugsee/cli` plus its six `@bugsee/cli-` -packages (per-`os`/`cpu` `optionalDependencies`, so nothing downloads at install -time). Seven packages, platform packages FIRST — npm skips an unresolvable +`npm-publish.yml`'s one job, `publish-optional-deps`, runs `npm/build.mjs` over +the release's binary archives to assemble and publish `@bugsee/cli` plus its six +`@bugsee/cli-` packages (per-`os`/`cpu` `optionalDependencies`, so +nothing downloads at install time). The legacy cargo-dist package +`@bugsee/bugsee-cli` is retired (frozen at 0.8.2, deprecated; its launcher +exited 0 on a signal kill, #87) — there is no `"npm"` in dist's `installers` and +no job for it; do not re-add either. Seven packages, platform packages FIRST — npm skips an unresolvable optional dependency silently, so the front package must never be live ahead of them. See `npm/README.md`. Each package needs its own Trusted Publisher entry pointing at `npm-publish.yml`, written with `npm trust github --file diff --git a/Cargo.toml b/Cargo.toml index 281303f..bb7efb7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,12 +66,13 @@ cargo-dist-version = "0.32.0" allow-dirty = ["ci"] # CI backends to support ci = "github" -# The installers to generate for each app -installers = ["shell", "powershell", "npm", "homebrew"] +# The installers to generate for each app. +# No "npm", and NO `npm-scope`: setting a scope makes dist emit the npm installer +# (`@bugsee/bugsee-cli`) even when "npm" is absent here. That package is retired +# (#87); npm packages are built by `npm/build.mjs` and published by `npm-publish.yml`. +installers = ["shell", "powershell", "homebrew"] # A GitHub repo to push Homebrew formulas to tap = "bugsee/homebrew-tap" -# A namespace to use when publishing this package to the npm registry -npm-scope = "@bugsee" # Publish jobs to run in CI publish-jobs = ["homebrew"] # Target platforms to build apps for (Rust target-triple syntax) diff --git a/README.md b/README.md index 4b5b1dd..53e6001 100644 --- a/README.md +++ b/README.md @@ -528,7 +528,7 @@ Every metadata `POST` sets `X-Bugsee-Uploader: cli`. The in-language fallback up |---|---| | GitHub Releases + `download.bugsee.com/cli` (archives, `.sha256`, `latest/` and `v.x/version.txt`), with the shell / PowerShell installers and `bugsee-cli update` | everyone; generic CI | | npm `@bugsee/cli` — per-platform `optionalDependencies` | JS toolchains (React Native, web bundler plugins) | -| npm `@bugsee/bugsee-cli` — single package, `postinstall` downloader | legacy alias for the above | +| npm `@bugsee/bugsee-cli` — single package, `postinstall` downloader | **deprecated**, frozen at 0.8.2; use `@bugsee/cli` | | CDN download + SHA-256 checksum on first use | fastlane plugin (`resolveCli`), iOS SDK BugseeAgent | | Homebrew tap `bugsee/tap` | macOS / Linux developers | @@ -536,13 +536,9 @@ Planned, not published yet: Maven Central `com.bugsee:bugsee-cli`, NuGet `Bugsee Target platforms: macOS arm64 + x86_64, Linux x86_64 + aarch64 (glibc only; no musl build), Windows x86_64 + arm64. (Windows arm64 builds natively on a `windows-11-arm` runner — see [#20](https://github.com/bugsee/bugsee-cli/issues/20).) -### The two npm packages +### npm packages -Both ship the same binary at the same version, and both are published from -`.github/workflows/npm-publish.yml` off the same release. They differ in how -the binary reaches `node_modules`: - -**`@bugsee/cli` — prefer this one.** The binary lives in six per-platform +**`@bugsee/cli`.** The binary lives in six per-platform packages (`@bugsee/cli-darwin-arm64`, `-darwin-x64`, `-linux-arm64`, `-linux-x64`, `-win32-x64`, `-win32-arm64`), each declaring `os`/`cpu` and pinned to the exact version by the front package's `optionalDependencies`. npm @@ -556,12 +552,14 @@ it warns and exits 0, leaving the error to surface only if `bugsee-cli` is actually invoked. It also exports `binaryPath()` for spawning the binary directly. Sources: [`npm/`](npm/). -**`@bugsee/bugsee-cli` — the cargo-dist package, kept as a working alias.** -One package, no binary inside; its `postinstall` runs `install.js`, which -downloads the archive for the host on every fresh install. That means it needs -network at install time and does nothing at all under `--ignore-scripts`. -Generated by cargo-dist from `installers = [..., "npm"]`; unchanged, still -published, still supported. New integrations should use `@bugsee/cli`. +**`@bugsee/bugsee-cli` — deprecated.** The former cargo-dist package: one +package, no binary inside, whose `postinstall` downloaded the archive on every +fresh install (so it needed network and did nothing under `--ignore-scripts`). +It is no longer published. 0.8.2 is the last version and still downloads the +0.8.1 binary; it fixes a launcher that exited `0` when the binary was killed by +a signal ([#87](https://github.com/bugsee/bugsee-cli/issues/87)). Every earlier +version is deprecated. Migrate to `@bugsee/cli`, which reports a signal death as +`128 + signum`. ## Design notes diff --git a/npm/README.md b/npm/README.md index 9930d3f..11286dc 100644 --- a/npm/README.md +++ b/npm/README.md @@ -22,7 +22,8 @@ six `optionalDependencies` to that exact version — never a range. npm resolves one of them by the `os`/`cpu` fields, so a consumer downloads one binary, not six, and nothing has to run at install time. That is the difference from `@bugsee/bugsee-cli` (generated by cargo-dist, one package whose `postinstall` -downloads the binary), which still publishes unchanged as an alias. +downloads the binary), which is deprecated and no longer published (last +version 0.8.2, see #87). ## Layout @@ -36,6 +37,7 @@ downloads the binary), which still publishes unchanged as an alias. | `build.mjs` | Assembles all seven packages from a directory of release assets. | | `bootstrap-names.sh` | One-time registry + trusted-publisher bootstrap for a NEW package name (see below). | | `test-bootstrap-names.sh` | Fixture tests for that script's trust-entry check. No network or npm needed: `bash npm/test-bootstrap-names.sh`. | +| `test-launcher.js` | Pins the launcher's exit-status contract, incl. a binary killed by a signal (#87). No network or built binary: `node --test npm/test-launcher.js`. | The six platform packages have no sources here: `build.mjs` mints each `package.json` and `README.md` from the platform table, so adding a platform is @@ -166,7 +168,7 @@ blocks publishing across the whole account for a while. A granular token is not a way around it either: npm removes direct publish for 2FA-bypass tokens in January 2027. -All eight published names — `@bugsee/bugsee-cli`, `@bugsee/cli` and the six +All seven published names — `@bugsee/cli` and the six platform packages — are already bootstrapped and need none of this. (Their `0.0.0` placeholders were kept; the 72-hour unpublish window has passed, and they are not under any dist-tag a user would install.) diff --git a/npm/cli/README.md b/npm/cli/README.md index a81ebd0..c2b5f66 100644 --- a/npm/cli/README.md +++ b/npm/cli/README.md @@ -79,9 +79,9 @@ gate). A launcher that cannot find a binary at all exits `1`, which is the ## Other install channels -`@bugsee/bugsee-cli` is the same CLI published by cargo-dist as a single -package that downloads its binary in a `postinstall`. It remains supported as -an alias; **prefer `@bugsee/cli`** — it is the one that works under +`@bugsee/bugsee-cli` was the same CLI published by cargo-dist as a single +package that downloads its binary in a `postinstall`. It is deprecated and no +longer published (last version 0.8.2); use `@bugsee/cli`, which also works under `--ignore-scripts`. See the [Distribution section](https://github.com/bugsee/bugsee-cli#distribution) for the shell installer, Homebrew tap, and the per-build-system bundles. diff --git a/npm/test-launcher.js b/npm/test-launcher.js new file mode 100644 index 0000000..16309a5 --- /dev/null +++ b/npm/test-launcher.js @@ -0,0 +1,75 @@ +// Tests the exit-status contract of the @bugsee/cli launcher (npm/cli/bin/bugsee-cli.js). +// No network, npm or built binary needed. +// +// Integrators branch on the launcher's exit code (<= 2 falls back, >= 10 is a real +// failure), so a binary killed by a signal must never be reported as success: +// `spawnSync` returns `status: null` for it, and `process.exit(null)` exits 0. That +// is the bug that made the retired @bugsee/bugsee-cli launcher report a killed CLI +// as a success (bugsee/bugsee-cli#87). +// +// The launcher is copied into a temp dir and pointed at a fake binary through its +// `vendor/` fallback, so the test runs the real file without touching the package. +// +// Run: node --test npm/test-launcher.js + +"use strict"; + +const { test } = require("node:test"); +const assert = require("node:assert"); +const { spawnSync } = require("node:child_process"); +const fs = require("node:fs"); +const os = require("node:os"); +const path = require("node:path"); + +const { PLATFORMS, currentTriple } = require("./cli/lib/platforms.js"); + +const triple = currentTriple(); +// The fake binary is a shell script, and Windows has no signals to die from. +const skip = + process.platform === "win32" + ? "needs POSIX signals" + : !triple && "no published binary for this platform"; + +/** Run the launcher against a fake binary whose body is `script`. */ +function runLauncher(script, args = []) { + const root = fs.mkdtempSync(path.join(os.tmpdir(), "bugsee-launcher-")); + try { + fs.cpSync(path.join(__dirname, "cli"), path.join(root, "cli"), { + recursive: true, + filter: (src) => !src.includes("node_modules"), + }); + const vendor = path.join(root, "cli", "vendor"); + fs.mkdirSync(vendor, { recursive: true }); + const bin = path.join(vendor, PLATFORMS[triple].bin); + fs.writeFileSync(bin, `#!/bin/sh\n${script}\n`, { mode: 0o755 }); + return spawnSync( + process.execPath, + [path.join(root, "cli", "bin", "bugsee-cli.js"), ...args], + { encoding: "utf8" }, + ); + } finally { + fs.rmSync(root, { recursive: true, force: true }); + } +} + +test("a binary killed by SIGKILL is not reported as success", { skip }, () => { + const r = runLauncher("kill -9 $$"); + assert.strictEqual(r.status, 128 + os.constants.signals.SIGKILL, r.stderr); +}); + +test("a binary killed by SIGTERM exits 128 + signum", { skip }, () => { + const r = runLauncher("kill -15 $$"); + assert.strictEqual(r.status, 128 + os.constants.signals.SIGTERM, r.stderr); +}); + +test("every ordinary exit code is forwarded verbatim", { skip }, () => { + for (const code of [0, 1, 2, 10, 23, 40]) { + assert.strictEqual(runLauncher(`exit ${code}`).status, code, `exit ${code}`); + } +}); + +test("argv and stdout pass through untouched", { skip }, () => { + const r = runLauncher('printf "%s|" "$@"', ["a b", "--flag=1"]); + assert.strictEqual(r.status, 0); + assert.strictEqual(r.stdout, "a b|--flag=1|"); +});