From dbc236dfd54f64ccd7d629352d4c6728eac80823 Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Sun, 8 Nov 2026 11:54:20 -0500 Subject: [PATCH 1/3] Carry approved signer trust into release packaging checkout --- .github/workflows/publish.yml | 7 ++++ README.md | 11 ++++-- docs/PROJECT_PLAN.md | 16 +++++++-- docs/RELEASING.md | 61 ++++++++++++++++++++++++++------ packages/rate-limit/README.md | 14 +++++++- packages/rate-limit/package.json | 2 +- 6 files changed, 94 insertions(+), 17 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c316cd1..0c0e122 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -74,6 +74,13 @@ jobs: persist-credentials: false fetch-depth: 0 + - name: Apply approved signing trust to the packaging checkout + shell: bash + run: | + set -euo pipefail + git config --local gpg.format ssh + git config --local gpg.ssh.allowedSignersFile "${RUNNER_TEMP}/release-allowed-signers" + - name: Set up Node.js uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7 with: diff --git a/README.md b/README.md index a2401ac..81378f7 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,8 @@ in-memory tier and a durable storage-backed tier for expensive operations. > [!IMPORTANT] > Rate Limit is in early `0.x` development. Its public API is not stable. -> Current source is the **`0.3.0` candidate, not published**. Registry `0.2.0` +> Current source is the **`0.3.1` candidate, not published**. Registry `latest` +> remains `0.2.0`, which > predates the merged [PR #8 hardening](https://github.com/pegma-dev/rate-limit/pull/8) > and the new bounded maintenance helper. The first advertised `0.1.0` > release was published from protected signed `v0.1.0` through @@ -15,9 +16,15 @@ in-memory tier and a durable storage-backed tier for expensive operations. > remains separate under `bootstrap`. pegma.dev composes the durable tier in > its production Identity worker; this candidate is not a new host deployment. -The source behavior below describes the `0.3.0` candidate. Adoption waits for +The source behavior below describes the `0.3.1` candidate. Adoption waits for its reviewed publication and the host's explicit configuration/storage transition. +The signed `v0.3.0` tag and GitHub release are retained history: their +preparation failed before packing, produced no release artifact, and did not +publish npm bytes. `0.3.1` corrects the packing checkout's SSH trust configuration +without changing the reviewed limiter API. See the +[failed preparation and patch-release record](docs/RELEASING.md#failed-030-preparation-and-031-candidate). + ## Two tiers, no pretending The most damaging thing a rate limiter can do is misrepresent its consistency. diff --git a/docs/PROJECT_PLAN.md b/docs/PROJECT_PLAN.md index 2d2bd11..5dca0c0 100644 --- a/docs/PROJECT_PLAN.md +++ b/docs/PROJECT_PLAN.md @@ -4,7 +4,8 @@ **Stage:** Phases 1, 2, and 4 are complete; Phase 3 has its first production consumer. Registry `@pegma/rate-limit@0.2.0` is published, and pegma.dev composes -the durable tier for its Identity surface. Current source is the **`0.3.0` +the durable tier for its Identity surface. Registry `latest` remains `0.2.0`. +Current source is the **`0.3.1` candidate, not published**, retaining exact Storage Core `0.4.0`. Published `0.2.0` predates the already-merged [PR #8 hardening](https://github.com/pegma-dev/rate-limit/pull/8) for immutable policy descriptors, counter kind/configuration bindings, and @@ -12,6 +13,14 @@ clock-skew grace. The candidate includes that hardening plus bounded global maintenance. The public API remains unstable; source completion is not a publication or host-adoption receipt. +Signed `v0.3.0` and its GitHub release remain immutable history. Their +preparation failed before packing because SSH trust was configured only in the +temporary verification repository, not the packing checkout. No release +artifact or npm `0.3.0` bytes were published. The `0.3.1` candidate corrects that +release configuration without changing the helper API; its own review, gates, +publication and registry verification remain required. See the +[failed-run receipt](RELEASING.md#failed-030-preparation-and-031-candidate). + The exact reviewed `0.0.0` package-name bootstrap remains published under `bootstrap`. The first advertised `0.1.0` release was published from the protected signed annotated `v0.1.0` tag by the GitHub release workflow through @@ -187,7 +196,7 @@ collection over an injected Store). The memory tier must remain importable without a Store — a host wanting only abuse-dampening should not construct storage. TypeScript, vitest, the ecosystem's standard layout. -## `0.3.0` bounded-maintenance source candidate +## `0.3.1` bounded-maintenance source candidate `sweepDurableWindowsPage` is a root/durable export over the existing `rate-limit-windows` collection. One call makes one physical global scan page, @@ -218,6 +227,9 @@ retrying from the previous cursor can repeat work. The define the interface; current-head gates, review, exact publication, and host adoption remain release work. +Host aliases for this helper must pin `0.3.1` only after its actual verified +registry publication. A signed tag or GitHub release alone is not publication. + Upgrading existing durable data is deliberate: use versioned policy names or an isolated Store namespace, or coordinate a policy-store reset. Immutable descriptors bind `limit` and `windowMs`; neither conflicting configuration nor diff --git a/docs/RELEASING.md b/docs/RELEASING.md index 5009062..fc8f636 100644 --- a/docs/RELEASING.md +++ b/docs/RELEASING.md @@ -21,7 +21,10 @@ exact integrity with npm. Only npm `E404` means `absent`; an existing different artifact or another registry failure stops the ceremony. Normal preparation authenticates the stable signed tag in a temporary bare -repository before checkout. The resulting artifact contains exactly two +repository before checkout. The packing checkout must also configure the same +approved SSH allowed-signers trust before the release tool independently checks +the signed tag; trust scoped to the temporary bare repository is not inherited. +The resulting artifact contains exactly two regular files: the manifest and its named tarball. Consumer installation runs in a separate job without publication authority. The environment-protected OIDC job checks the tag again, downloads the sealed artifact outside a source @@ -29,6 +32,38 @@ checkout, verifies the preparation manifest digest and both tarball digests, and invokes npm from a fresh directory with empty configuration files and an allowlisted environment. It never executes repository code. +## Failed `0.3.0` preparation and `0.3.1` candidate + +As of 2026-11-08, npm `latest` remains `0.2.0`; current source is the unpublished +`0.3.1` candidate. Protected signed annotated +[`v0.3.0`](https://github.com/pegma-dev/rate-limit/releases/tag/v0.3.0), tag object +`9df80b019b8ed6e5b7fc0f5a8c7359ae4cae6486`, points to reviewed source +[`93c7a4207d493e10568b797bf7d5a402f446cc70`](https://github.com/pegma-dev/rate-limit/commit/93c7a4207d493e10568b797bf7d5a402f446cc70). +Its GitHub release triggered +[run `42501172611`](https://github.com/pegma-dev/rate-limit/actions/runs/42501172611), +whose [preparation job `128794037936`](https://github.com/pegma-dev/rate-limit/actions/runs/42501172611/job/128794037936) +failed before packing. There is no prepared manifest/tarball artifact from that +run and no npm `0.3.0` publication. + +The temporary bare repository had the approved SSH allowed-signers trust, but +the separate packing checkout did not. The release tool's independent tag +verification therefore failed there. This was a checkout trust-configuration +failure, not evidence that the protected signed tag was invalid. + +Preserve the `v0.3.0` tag object, source commit, GitHub release and failed-run +record. Never move or replace that tag, reuse its version for changed source, +or treat the failed preparation as publication. The correction uses a reviewed +`0.3.1` patch and a new protected signed `v0.3.1` release identity after merge. +It adds explicit trust to the packing checkout; the limiter/helper API and +behavior remain unchanged. The full Node 22/24 gates and exact-artifact release +checks still apply to the new source. + +Only after `0.3.1` actually publishes and its original prepared bytes and +registry release are verified may a host pin it, including through an npm +alias. This does not migrate legacy `0.2.0` counters or change existing host +deployment state. No repeated bootstrap, token fallback or signature bypass is +part of this recovery. + ## One-time `0.0.0` package-name bootstrap **Complete; do not repeat.** The exact reviewed `0.0.0` artifact was published @@ -36,11 +71,11 @@ under `bootstrap`, its signed annotated source tag points to the reviewed `origin/main` commit, and npm trusted publishing is configured for `pegma-dev/rate-limit`, `publish.yml`, and the `npm-publish` environment. -npm also assigned the default `latest` tag to `0.0.0`. The operator attempted +During bootstrap npm also assigned the default `latest` tag to `0.0.0`. The operator attempted to remove it, but npm rejected the request with HTTP 400. The immutable -bootstrap remains exact and the `bootstrap` tag remains correct; publishing -`0.1.0` through the normal workflow will immediately move `latest` to the -first advertised version. +bootstrap remains exact and the `bootstrap` tag remains correct. The later +normal `0.1.0` publication moved `latest` to the first advertised version; +`latest` has since advanced to `0.2.0`. The steps below are retained only as the ceremony's audit and recovery record. @@ -122,7 +157,7 @@ npm dist-tag ls @pegma/rate-limit `bootstrap` points to `0.0.0`. npm unexpectedly also made `latest` point to `0.0.0` and rejected its removal with HTTP 400; do not retry destructive -registry changes. The `0.1.0` publication corrects the default tag. +registry changes. The later `0.1.0` publication corrected that default tag. ### 4. Configure trusted publishing @@ -145,15 +180,17 @@ The workflow intentionally rejects `0.0.0`; its first permitted release is ## First advertised `0.1.0` release -This separate reviewed pull request must: +**Complete; historical ceremony.** The separate reviewed release pull request +was required to: 1. change `packages/rate-limit/package.json` from `0.0.0` to `0.1.0`; 2. regenerate `pnpm-lock.yaml` and verify its workspace importer pins `0.1.0`; 3. update README and plan status with the advertised release notes; and 4. pass the full gate and release pack smoke on Node 22 and 24. -After that pull request merges, create the protected signed annotated -`v0.1.0` tag on the exact `origin/main` commit and create the GitHub release: +After that pull request merged, the protected signed annotated `v0.1.0` tag +and GitHub release were created at the exact `origin/main` commit. These +commands are retained as the historical ceremony, not instructions to repeat it: ```sh git fetch origin @@ -205,5 +242,7 @@ pnpm run release:registry:check -- --manifest "${artifact_dir}/package-manifest. npm dist-tag ls @pegma/rate-limit ``` -The registry check must report `@pegma/rate-limit@0.1.0: exact`; -`latest` must point to `0.1.0`, while `bootstrap` remains at `0.0.0`. +For that ceremony the registry check had to report +`@pegma/rate-limit@0.1.0: exact`, with `latest` at `0.1.0` and `bootstrap` at +`0.0.0`. Current `latest` is `0.2.0`; do not retag an older release or repeat +the bootstrap to prepare the unpublished `0.3.1` candidate. diff --git a/packages/rate-limit/README.md b/packages/rate-limit/README.md index c90a67f..2a43169 100644 --- a/packages/rate-limit/README.md +++ b/packages/rate-limit/README.md @@ -9,7 +9,8 @@ Two explicitly named application rate-limit tiers: abuse-critical operations. > [!IMPORTANT] -> Current source is the **`0.3.0` candidate, not published**. Published `0.2.0` +> Current source is the **`0.3.1` candidate, not published**. Registry `latest` +> remains `0.2.0`, which > predates the merged descriptor/configuration hardening and the bounded > global sweep described here. `0.1.0` was the first advertised release, published through > trusted-publisher OIDC with provenance. The exact reviewed `0.0.0` @@ -20,6 +21,12 @@ The API and storage behavior below describe candidate source. Use an exact published version only after its release verification and an explicit host storage/configuration transition. +The signed `v0.3.0` tag and GitHub release exist, but preparation failed before +packing: no release artifact or npm `0.3.0` bytes were published. The `0.3.1` +candidate fixes release-checkout SSH trust, with the reviewed limiter API +unchanged. The immutable failure history and new patch identity are recorded in +[release operations](../../docs/RELEASING.md#failed-030-preparation-and-031-candidate). + There is no default tier and no automatic upgrade. This package is application abuse control, not DDoS protection, HTTP middleware, or billing metering. Policy names and limiter keys must be primitive, non-blank strings. Whitespace @@ -198,6 +205,11 @@ reset; conflicting instances fail closed. Do not edit descriptors in place, delete arbitrary malformed rows, or mistake the global sweep for a migration of previously published `0.2.0` data. +A host adopting the new helper through an npm alias must wait for actual +`0.3.1` publication and registry verification before pinning that alias. Existing +`0.2.0` consumers and counters need their own deliberate migration; the new +release does not convert them automatically. + ## License MIT diff --git a/packages/rate-limit/package.json b/packages/rate-limit/package.json index 1ad059f..1538cac 100644 --- a/packages/rate-limit/package.json +++ b/packages/rate-limit/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/rate-limit", - "version": "0.3.0", + "version": "0.3.1", "description": "Explicit per-instance sliding-window and shared durable fixed-window rate limiters.", "license": "MIT", "type": "module", From 6fd45fc573c1d17cd0e69b65c8faf310a973cd78 Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Sun, 8 Nov 2026 12:15:04 -0500 Subject: [PATCH 2/3] Prove packaging signer trust with real Git regression tests --- .github/workflows/publish.yml | 10 +- package.json | 2 +- packages/rate-limit/README.md | 4 +- scripts/configure-release-signing.mjs | 108 +++++++++ scripts/configure-release-signing.test.mjs | 269 +++++++++++++++++++++ 5 files changed, 383 insertions(+), 10 deletions(-) create mode 100644 scripts/configure-release-signing.mjs create mode 100644 scripts/configure-release-signing.test.mjs diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0c0e122..e656606 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -74,19 +74,15 @@ jobs: persist-credentials: false fetch-depth: 0 - - name: Apply approved signing trust to the packaging checkout - shell: bash - run: | - set -euo pipefail - git config --local gpg.format ssh - git config --local gpg.ssh.allowedSignersFile "${RUNNER_TEMP}/release-allowed-signers" - - name: Set up Node.js uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7 with: node-version: 24.18.0 package-manager-cache: false + - name: Apply approved signing trust to the packaging checkout + run: node scripts/configure-release-signing.mjs "${RUNNER_TEMP}/release-allowed-signers" "${RELEASE_TAG}" + - name: Enable Corepack run: corepack enable diff --git a/package.json b/package.json index fe43343..5cad1c0 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "release:pack": "node scripts/release-package.mjs pack", "release:publish": "node scripts/release-package.mjs publish", "release:registry:check": "node scripts/release-package.mjs registry-check", - "test": "pnpm run build && vitest run" + "test": "pnpm run build && vitest run && node --test scripts/configure-release-signing.test.mjs" }, "devDependencies": { "@azure/data-tables": "13.3.1", diff --git a/packages/rate-limit/README.md b/packages/rate-limit/README.md index 2a43169..07e481a 100644 --- a/packages/rate-limit/README.md +++ b/packages/rate-limit/README.md @@ -25,7 +25,7 @@ The signed `v0.3.0` tag and GitHub release exist, but preparation failed before packing: no release artifact or npm `0.3.0` bytes were published. The `0.3.1` candidate fixes release-checkout SSH trust, with the reviewed limiter API unchanged. The immutable failure history and new patch identity are recorded in -[release operations](../../docs/RELEASING.md#failed-030-preparation-and-031-candidate). +[release operations](https://github.com/pegma-dev/rate-limit/blob/main/docs/RELEASING.md). There is no default tier and no automatic upgrade. This package is application abuse control, not DDoS protection, HTTP middleware, or billing metering. @@ -131,7 +131,7 @@ row. Checks against that malformed row still fail closed. ## Bounded global cleanup The candidate adds this interface at the root and durable subpath, defined in -[the actual source](src/durable.ts): +[the actual source](https://github.com/pegma-dev/rate-limit/blob/main/packages/rate-limit/src/durable.ts): ```ts export declare function sweepDurableWindowsPage( diff --git a/scripts/configure-release-signing.mjs b/scripts/configure-release-signing.mjs new file mode 100644 index 0000000..e797330 --- /dev/null +++ b/scripts/configure-release-signing.mjs @@ -0,0 +1,108 @@ +import { constants } from "node:fs"; +import { lstat, open } from "node:fs/promises"; +import { isAbsolute, resolve } from "node:path"; +import { spawnSync } from "node:child_process"; +import { fileURLToPath } from "node:url"; + +const MAX_SIGNERS_BYTES = 64 * 1024; +const STABLE_TAG = /^v(0\.[1-9][0-9]*|[1-9][0-9]*\.[0-9]+)\.[0-9]+$/u; + +async function validatePublicSigners(path) { + if (typeof path !== "string" || !isAbsolute(path)) { + throw new Error("The approved public signers file must be absolute."); + } + let file; + try { + const before = await lstat(path); + if ( + before.isSymbolicLink() || + !before.isFile() || + before.size === 0 || + before.size > MAX_SIGNERS_BYTES + ) { + throw new Error("invalid public signers file"); + } + file = await open(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0)); + const opened = await file.stat(); + if ( + !opened.isFile() || + opened.dev !== before.dev || + opened.ino !== before.ino || + opened.size > MAX_SIGNERS_BYTES + ) { + throw new Error("public signers file changed"); + } + const buffer = Buffer.alloc(MAX_SIGNERS_BYTES + 1); + const { bytesRead } = await file.read(buffer, 0, buffer.length, 0); + const after = await file.stat(); + if ( + bytesRead > MAX_SIGNERS_BYTES || + bytesRead !== after.size || + buffer.subarray(0, bytesRead).toString("utf8").trim() === "" + ) { + throw new Error("invalid public signers contents"); + } + } catch { + throw new Error( + "Approved public signers must be a nonempty regular file of at most 64 KiB, without a symlink.", + ); + } finally { + await file?.close(); + } +} + +/** Configure only the current packaging checkout, then verify its actual tag. */ +export async function configureReleaseSigning( + approvedSignersFile, + stableTag, + { cwd = process.cwd(), env = process.env } = {}, +) { + if (typeof stableTag !== "string" || !STABLE_TAG.test(stableTag)) { + throw new Error("A stable release tag is required."); + } + await validatePublicSigners(approvedSignersFile); + function git(arguments_, failure) { + const result = spawnSync("git", arguments_, { + cwd, + env, + stdio: ["ignore", "pipe", "pipe"], + maxBuffer: 64 * 1024, + }); + // Do not expose raw signature output or inherited Git diagnostics. + if (result.error !== undefined || result.status !== 0) { + throw new Error(failure); + } + } + git( + ["config", "--local", "gpg.format", "ssh"], + "Could not configure release signing format.", + ); + git( + ["config", "--local", "gpg.ssh.allowedSignersFile", approvedSignersFile], + "Could not configure approved public release signers.", + ); + git( + ["verify-tag", `refs/tags/${stableTag}`], + "The release tag signature is not valid for an approved signer.", + ); +} + +if ( + process.argv[1] !== undefined && + resolve(process.argv[1]) === fileURLToPath(import.meta.url) +) { + try { + if (process.argv.length !== 4) { + throw new Error( + "usage: configure-release-signing.mjs ", + ); + } + await configureReleaseSigning(process.argv[2], process.argv[3]); + process.stdout.write( + "Release signing trust configured and tag verified.\n", + ); + } catch (error) { + process.stderr.write(`${error.message}\n`); + process.exitCode = 1; + } +} diff --git a/scripts/configure-release-signing.test.mjs b/scripts/configure-release-signing.test.mjs new file mode 100644 index 0000000..e722fe6 --- /dev/null +++ b/scripts/configure-release-signing.test.mjs @@ -0,0 +1,269 @@ +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { spawnSync } from "node:child_process"; +import { + mkdtemp, + mkdir, + readFile, + realpath, + rm, + symlink, + writeFile, +} from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { basename, dirname, isAbsolute, join, relative } from "node:path"; +import { fileURLToPath } from "node:url"; +import { configureReleaseSigning } from "./configure-release-signing.mjs"; + +const TAG = "v0.3.1"; +const PRINCIPAL = "release-fixture@example.invalid"; +const PREFIX = "pegma-release-signing-test-"; + +async function fixture(t, { signed = true } = {}) { + const parent = await realpath(tmpdir()); + const root = await realpath(await mkdtemp(join(parent, PREFIX))); + t.after(async () => { + const target = await realpath(root); + const child = relative(parent, target); + if ( + target !== root || + isAbsolute(child) || + dirname(child) !== "." || + !basename(child).startsWith(PREFIX) + ) { + throw new Error("Refusing cleanup outside the owned temporary fixture."); + } + await rm(target, { recursive: true, force: true }); + }); + const repo = join(root, "repository"); + const template = join(root, "empty-template"); + const globalConfig = join(root, "empty-global-config"); + await mkdir(repo); + await mkdir(template); + await writeFile(globalConfig, ""); + const env = {}; + // No user Git injection, signing configuration, credentials or SSH agent. + for (const name of [ + "PATH", + "PATHEXT", + "SYSTEMROOT", + "WINDIR", + "COMSPEC", + "SYSTEMDRIVE", + "TEMP", + "TMP", + "USERPROFILE", + "HOMEDRIVE", + "HOMEPATH", + "PROGRAMDATA", + "ALLUSERSPROFILE", + ]) { + if (process.env[name] !== undefined) env[name] = process.env[name]; + } + env.GIT_CONFIG_GLOBAL = globalConfig; + env.GIT_CONFIG_NOSYSTEM = "1"; + env.GIT_TERMINAL_PROMPT = "0"; + function run(command, arguments_, { allowFailure = false, cwd = repo } = {}) { + const result = spawnSync(command, arguments_, { + cwd, + env, + encoding: "utf8", + stdio: ["ignore", "pipe", "pipe"], + }); + if (result.error !== undefined || (!allowFailure && result.status !== 0)) { + throw new Error( + `Fixture ${command} failed (${result.error?.code ?? result.status}).`, + ); + } + return result; + } + const git = (arguments_, options) => run("git", arguments_, options); + git(["init", "--template", template, "."]); + git(["config", "--local", "user.name", "Synthetic Release Fixture"]); + git(["config", "--local", "user.email", PRINCIPAL]); + git([ + "-c", + "commit.gpgsign=false", + "commit", + "--allow-empty", + "--message", + "synthetic source", + ]); + async function publicSigners(name) { + const privateKey = join(root, name); + run("ssh-keygen", [ + "-q", + "-t", + "ed25519", + "-N", + "", + "-C", + "synthetic release fixture", + "-f", + privateKey, + ]); + // Only this fixture's public key is read by Node; Git signs with its own + // freshly generated private key, never a user key or SSH agent identity. + const publicKey = (await readFile(`${privateKey}.pub`, "utf8")).trim(); + const allowed = join(root, `${name}.allowed-signers`); + await writeFile(allowed, `${PRINCIPAL} ${publicKey}\n`); + return { privateKey, allowed }; + } + const signer = signed ? await publicSigners("fixture-key") : null; + if (signer !== null) { + git([ + "-c", + "gpg.format=ssh", + "-c", + `user.signingkey=${signer.privateKey}`, + "tag", + "--sign", + "--message", + "synthetic release", + TAG, + ]); + } + function assertNoTrust() { + for (const name of ["gpg.format", "gpg.ssh.allowedSignersFile"]) { + const result = git(["config", "--local", "--get", name], { + allowFailure: true, + }); + assert.equal(result.status, 1); + assert.equal(result.stdout, ""); + } + } + return { root, repo, env, git, run, signer, publicSigners, assertNoTrust }; +} + +test("actual signed tag fails without checkout trust and verifies after configuration", async (t) => { + const f = await fixture(t); + f.assertNoTrust(); + const before = f.git(["verify-tag", `refs/tags/${TAG}`], { + allowFailure: true, + }); + assert.notEqual(before.status, 0); + const head = f.git(["rev-parse", "HEAD"]).stdout; + const tag = f.git(["rev-parse", `refs/tags/${TAG}`]).stdout; + await configureReleaseSigning(f.signer.allowed, TAG, { + cwd: f.repo, + env: f.env, + }); + assert.equal(f.git(["verify-tag", `refs/tags/${TAG}`]).status, 0); + assert.equal( + f.git(["config", "--local", "--get", "gpg.format"]).stdout.trim(), + "ssh", + ); + assert.equal( + f + .git(["config", "--local", "--get", "gpg.ssh.allowedSignersFile"]) + .stdout.trim(), + f.signer.allowed, + ); + assert.equal(f.git(["rev-parse", "HEAD"]).stdout, head); + assert.equal(f.git(["rev-parse", `refs/tags/${TAG}`]).stdout, tag); + assert.equal(f.git(["status", "--porcelain"]).stdout, ""); +}); + +test("a real tag signed by another key remains rejected", async (t) => { + const f = await fixture(t); + const other = await f.publicSigners("other-fixture-key"); + await assert.rejects( + configureReleaseSigning(other.allowed, TAG, { cwd: f.repo, env: f.env }), + /signature is not valid for an approved signer/u, + ); + assert.notEqual( + f.git(["verify-tag", `refs/tags/${TAG}`], { allowFailure: true }).status, + 0, + ); +}); + +test("the actual CLI verifies a real signed tag in its current checkout", async (t) => { + const f = await fixture(t); + const helper = fileURLToPath( + new URL("./configure-release-signing.mjs", import.meta.url), + ); + const result = f.run(process.execPath, [helper, f.signer.allowed, TAG]); + assert.equal(result.status, 0); + assert.equal( + result.stdout, + "Release signing trust configured and tag verified.\n", + ); + assert.equal(result.stderr, ""); + assert.equal(f.git(["verify-tag", `refs/tags/${TAG}`]).status, 0); +}); + +for (const kind of [ + "missing", + "empty", + "whitespace", + "oversized", + "directory", + "symlink", + "relative", +]) { + test(`invalid ${kind} public trust is rejected before either configuration write`, async (t) => { + const f = await fixture(t, { signed: false }); + let path = join(f.root, "invalid-signers"); + if (kind === "empty") await writeFile(path, ""); + if (kind === "whitespace") await writeFile(path, " \n\r\n"); + if (kind === "oversized") + await writeFile(path, Buffer.alloc(64 * 1024 + 1, 65)); + if (kind === "directory") await mkdir(path); + if (kind === "symlink") { + const target = join(f.root, "own-link-target"); + await mkdir(target); + // Windows junctions require no privileged file-symlink capability. + await symlink( + target, + path, + process.platform === "win32" ? "junction" : "dir", + ); + } + if (kind === "relative") path = "relative-public-signers"; + await assert.rejects( + configureReleaseSigning(path, TAG, { cwd: f.repo, env: f.env }), + /public signers/u, + ); + f.assertNoTrust(); + }); +} + +test("a nonrelease ref cannot change checkout configuration", async (t) => { + const f = await fixture(t); + await assert.rejects( + configureReleaseSigning(f.signer.allowed, "main", { + cwd: f.repo, + env: f.env, + }), + /stable release tag/u, + ); + f.assertNoTrust(); +}); + +test("a missing real release tag fails verification without raw Git output", async (t) => { + const f = await fixture(t); + await assert.rejects( + configureReleaseSigning(f.signer.allowed, "v0.3.2", { + cwd: f.repo, + env: f.env, + }), + { + message: "The release tag signature is not valid for an approved signer.", + }, + ); +}); + +test("a real Git configuration failure rejects", async (t) => { + const f = await fixture(t); + const notRepository = join(f.root, "not-a-repository"); + await mkdir(notRepository); + await assert.rejects( + configureReleaseSigning(f.signer.allowed, TAG, { + cwd: notRepository, + env: f.env, + }), + { + message: "Could not configure release signing format.", + }, + ); +}); From a76b107f462e501f6c6f1ac570c42d46aebeb537 Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Sun, 8 Nov 2026 12:37:39 -0500 Subject: [PATCH 3/3] Replay release workflow signing in isolated Git fixtures --- package.json | 5 +- pnpm-lock.yaml | 25 ++- scripts/configure-release-signing.test.mjs | 135 +----------- scripts/release-signing-fixture.mjs | 145 +++++++++++++ scripts/release-workflow-signing.test.mjs | 236 +++++++++++++++++++++ 5 files changed, 405 insertions(+), 141 deletions(-) create mode 100644 scripts/release-signing-fixture.mjs create mode 100644 scripts/release-workflow-signing.test.mjs diff --git a/package.json b/package.json index 5cad1c0..6f47ef2 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "release:pack": "node scripts/release-package.mjs pack", "release:publish": "node scripts/release-package.mjs publish", "release:registry:check": "node scripts/release-package.mjs registry-check", - "test": "pnpm run build && vitest run && node --test scripts/configure-release-signing.test.mjs" + "test": "pnpm run build && vitest run && node --test scripts/configure-release-signing.test.mjs scripts/release-workflow-signing.test.mjs" }, "devDependencies": { "@azure/data-tables": "13.3.1", @@ -31,6 +31,7 @@ "azurite": "3.36.0", "prettier": "3.9.6", "typescript": "7.0.2", - "vitest": "4.1.10" + "vitest": "4.1.10", + "yaml": "2.9.1" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d8e52a5..ca7bad0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -28,7 +28,10 @@ importers: version: 7.0.2 vitest: specifier: 4.1.10 - version: 4.1.10(@opentelemetry/api@1.9.1)(@types/node@26.1.1)(vite@8.1.5(@types/node@26.1.1)) + version: 4.1.10(@opentelemetry/api@1.9.1)(@types/node@26.1.1)(vite@8.1.5(@types/node@26.1.1)(yaml@2.9.1)) + yaml: + specifier: 2.9.1 + version: 2.9.1 packages/rate-limit: dependencies: @@ -1751,6 +1754,11 @@ packages: resolution: {integrity: sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==} engines: {node: '>=4.0'} + yaml@2.9.1: + resolution: {integrity: sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==} + engines: {node: '>= 14.6'} + hasBin: true + snapshots: '@azure-rest/core-client@2.8.0': @@ -2242,13 +2250,13 @@ snapshots: chai: 6.2.2 tinyrainbow: 3.1.0 - '@vitest/mocker@4.1.10(vite@8.1.5(@types/node@26.1.1))': + '@vitest/mocker@4.1.10(vite@8.1.5(@types/node@26.1.1)(yaml@2.9.1))': dependencies: '@vitest/spy': 4.1.10 estree-walker: 3.0.3 magic-string: 0.30.21 optionalDependencies: - vite: 8.1.5(@types/node@26.1.1) + vite: 8.1.5(@types/node@26.1.1)(yaml@2.9.1) '@vitest/pretty-format@4.1.10': dependencies: @@ -3396,7 +3404,7 @@ snapshots: vary@1.1.2: {} - vite@8.1.5(@types/node@26.1.1): + vite@8.1.5(@types/node@26.1.1)(yaml@2.9.1): dependencies: lightningcss: 1.33.0 picomatch: 4.0.5 @@ -3406,11 +3414,12 @@ snapshots: optionalDependencies: '@types/node': 26.1.1 fsevents: 2.3.3 + yaml: 2.9.1 - vitest@4.1.10(@opentelemetry/api@1.9.1)(@types/node@26.1.1)(vite@8.1.5(@types/node@26.1.1)): + vitest@4.1.10(@opentelemetry/api@1.9.1)(@types/node@26.1.1)(vite@8.1.5(@types/node@26.1.1)(yaml@2.9.1)): dependencies: '@vitest/expect': 4.1.10 - '@vitest/mocker': 4.1.10(vite@8.1.5(@types/node@26.1.1)) + '@vitest/mocker': 4.1.10(vite@8.1.5(@types/node@26.1.1)(yaml@2.9.1)) '@vitest/pretty-format': 4.1.10 '@vitest/runner': 4.1.10 '@vitest/snapshot': 4.1.10 @@ -3427,7 +3436,7 @@ snapshots: tinyexec: 1.2.4 tinyglobby: 0.2.17 tinyrainbow: 3.1.0 - vite: 8.1.5(@types/node@26.1.1) + vite: 8.1.5(@types/node@26.1.1)(yaml@2.9.1) why-is-node-running: 2.3.0 optionalDependencies: '@opentelemetry/api': 1.9.1 @@ -3490,3 +3499,5 @@ snapshots: xmlbuilder: 11.0.1 xmlbuilder@11.0.1: {} + + yaml@2.9.1: {} diff --git a/scripts/configure-release-signing.test.mjs b/scripts/configure-release-signing.test.mjs index e722fe6..7298bc3 100644 --- a/scripts/configure-release-signing.test.mjs +++ b/scripts/configure-release-signing.test.mjs @@ -1,139 +1,10 @@ import assert from "node:assert/strict"; import { test } from "node:test"; -import { spawnSync } from "node:child_process"; -import { - mkdtemp, - mkdir, - readFile, - realpath, - rm, - symlink, - writeFile, -} from "node:fs/promises"; -import { tmpdir } from "node:os"; -import { basename, dirname, isAbsolute, join, relative } from "node:path"; +import { mkdir, symlink, writeFile } from "node:fs/promises"; +import { join } from "node:path"; import { fileURLToPath } from "node:url"; import { configureReleaseSigning } from "./configure-release-signing.mjs"; - -const TAG = "v0.3.1"; -const PRINCIPAL = "release-fixture@example.invalid"; -const PREFIX = "pegma-release-signing-test-"; - -async function fixture(t, { signed = true } = {}) { - const parent = await realpath(tmpdir()); - const root = await realpath(await mkdtemp(join(parent, PREFIX))); - t.after(async () => { - const target = await realpath(root); - const child = relative(parent, target); - if ( - target !== root || - isAbsolute(child) || - dirname(child) !== "." || - !basename(child).startsWith(PREFIX) - ) { - throw new Error("Refusing cleanup outside the owned temporary fixture."); - } - await rm(target, { recursive: true, force: true }); - }); - const repo = join(root, "repository"); - const template = join(root, "empty-template"); - const globalConfig = join(root, "empty-global-config"); - await mkdir(repo); - await mkdir(template); - await writeFile(globalConfig, ""); - const env = {}; - // No user Git injection, signing configuration, credentials or SSH agent. - for (const name of [ - "PATH", - "PATHEXT", - "SYSTEMROOT", - "WINDIR", - "COMSPEC", - "SYSTEMDRIVE", - "TEMP", - "TMP", - "USERPROFILE", - "HOMEDRIVE", - "HOMEPATH", - "PROGRAMDATA", - "ALLUSERSPROFILE", - ]) { - if (process.env[name] !== undefined) env[name] = process.env[name]; - } - env.GIT_CONFIG_GLOBAL = globalConfig; - env.GIT_CONFIG_NOSYSTEM = "1"; - env.GIT_TERMINAL_PROMPT = "0"; - function run(command, arguments_, { allowFailure = false, cwd = repo } = {}) { - const result = spawnSync(command, arguments_, { - cwd, - env, - encoding: "utf8", - stdio: ["ignore", "pipe", "pipe"], - }); - if (result.error !== undefined || (!allowFailure && result.status !== 0)) { - throw new Error( - `Fixture ${command} failed (${result.error?.code ?? result.status}).`, - ); - } - return result; - } - const git = (arguments_, options) => run("git", arguments_, options); - git(["init", "--template", template, "."]); - git(["config", "--local", "user.name", "Synthetic Release Fixture"]); - git(["config", "--local", "user.email", PRINCIPAL]); - git([ - "-c", - "commit.gpgsign=false", - "commit", - "--allow-empty", - "--message", - "synthetic source", - ]); - async function publicSigners(name) { - const privateKey = join(root, name); - run("ssh-keygen", [ - "-q", - "-t", - "ed25519", - "-N", - "", - "-C", - "synthetic release fixture", - "-f", - privateKey, - ]); - // Only this fixture's public key is read by Node; Git signs with its own - // freshly generated private key, never a user key or SSH agent identity. - const publicKey = (await readFile(`${privateKey}.pub`, "utf8")).trim(); - const allowed = join(root, `${name}.allowed-signers`); - await writeFile(allowed, `${PRINCIPAL} ${publicKey}\n`); - return { privateKey, allowed }; - } - const signer = signed ? await publicSigners("fixture-key") : null; - if (signer !== null) { - git([ - "-c", - "gpg.format=ssh", - "-c", - `user.signingkey=${signer.privateKey}`, - "tag", - "--sign", - "--message", - "synthetic release", - TAG, - ]); - } - function assertNoTrust() { - for (const name of ["gpg.format", "gpg.ssh.allowedSignersFile"]) { - const result = git(["config", "--local", "--get", name], { - allowFailure: true, - }); - assert.equal(result.status, 1); - assert.equal(result.stdout, ""); - } - } - return { root, repo, env, git, run, signer, publicSigners, assertNoTrust }; -} +import { fixture, TAG } from "./release-signing-fixture.mjs"; test("actual signed tag fails without checkout trust and verifies after configuration", async (t) => { const f = await fixture(t); diff --git a/scripts/release-signing-fixture.mjs b/scripts/release-signing-fixture.mjs new file mode 100644 index 0000000..e0e5881 --- /dev/null +++ b/scripts/release-signing-fixture.mjs @@ -0,0 +1,145 @@ +import assert from "node:assert/strict"; +import { spawnSync } from "node:child_process"; +import { + mkdtemp, + mkdir, + readFile, + realpath, + rm, + writeFile, +} from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { basename, dirname, isAbsolute, join, relative } from "node:path"; + +export const TAG = "v0.3.1"; +const PRINCIPAL = "release-fixture@example.invalid"; +const PREFIX = "pegma-release-signing-test-"; + +export async function fixture( + t, + { signed = true, sourceFiles = {}, tag = TAG } = {}, +) { + const parent = await realpath(tmpdir()); + const root = await realpath(await mkdtemp(join(parent, PREFIX))); + t.after(async () => { + const target = await realpath(root); + const child = relative(parent, target); + if ( + target !== root || + isAbsolute(child) || + dirname(child) !== "." || + !basename(child).startsWith(PREFIX) + ) { + throw new Error("Refusing cleanup outside the owned temporary fixture."); + } + await rm(target, { recursive: true, force: true }); + }); + const repo = join(root, "repository"); + const template = join(root, "empty-template"); + const globalConfig = join(root, "empty-global-config"); + await mkdir(repo); + await mkdir(template); + await writeFile(globalConfig, ""); + const env = {}; + // No user Git injection, signing configuration, credentials or SSH agent. + for (const name of [ + "PATH", + "PATHEXT", + "SYSTEMROOT", + "WINDIR", + "COMSPEC", + "SYSTEMDRIVE", + "TEMP", + "TMP", + "USERPROFILE", + "HOMEDRIVE", + "HOMEPATH", + "PROGRAMDATA", + "ALLUSERSPROFILE", + ]) { + if (process.env[name] !== undefined) env[name] = process.env[name]; + } + env.GIT_CONFIG_GLOBAL = globalConfig; + env.GIT_CONFIG_NOSYSTEM = "1"; + env.GIT_TERMINAL_PROMPT = "0"; + function run( + command, + arguments_, + { allowFailure = false, cwd = repo, environment = env } = {}, + ) { + const result = spawnSync(command, arguments_, { + cwd, + env: environment, + encoding: "utf8", + stdio: ["ignore", "pipe", "pipe"], + }); + if (result.error !== undefined || (!allowFailure && result.status !== 0)) { + throw new Error( + `Fixture ${command} failed (${result.error?.code ?? result.status}).`, + ); + } + return result; + } + const git = (arguments_, options) => run("git", arguments_, options); + git(["init", "--template", template, "."]); + git(["config", "--local", "user.name", "Synthetic Release Fixture"]); + git(["config", "--local", "user.email", PRINCIPAL]); + for (const [name, contents] of Object.entries(sourceFiles)) { + const path = join(repo, name); + await mkdir(dirname(path), { recursive: true }); + await writeFile(path, contents); + } + git(["add", "--all"]); + git([ + "-c", + "commit.gpgsign=false", + "commit", + "--allow-empty", + "--message", + "synthetic source", + ]); + async function publicSigners(name) { + const privateKey = join(root, name); + run("ssh-keygen", [ + "-q", + "-t", + "ed25519", + "-N", + "", + "-C", + "synthetic release fixture", + "-f", + privateKey, + ]); + // Only this fixture's public key is read by Node; Git signs with its own + // freshly generated private key, never a user key or SSH agent identity. + const publicKey = (await readFile(`${privateKey}.pub`, "utf8")).trim(); + const allowed = join(root, `${name}.allowed-signers`); + await writeFile(allowed, `${PRINCIPAL} ${publicKey}\n`); + return { privateKey, allowed }; + } + const signer = signed ? await publicSigners("fixture-key") : null; + if (signer !== null) { + git([ + "-c", + "gpg.format=ssh", + "-c", + `user.signingkey=${signer.privateKey}`, + "tag", + "--sign", + "--message", + "synthetic release", + tag, + ]); + } + function assertNoTrust() { + for (const name of ["gpg.format", "gpg.ssh.allowedSignersFile"]) { + const result = git(["config", "--local", "--get", name], { + allowFailure: true, + }); + assert.equal(result.status, 1); + assert.equal(result.stdout, ""); + } + } + return { root, repo, env, git, run, signer, publicSigners, assertNoTrust }; +} diff --git a/scripts/release-workflow-signing.test.mjs b/scripts/release-workflow-signing.test.mjs new file mode 100644 index 0000000..76838d0 --- /dev/null +++ b/scripts/release-workflow-signing.test.mjs @@ -0,0 +1,236 @@ +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { mkdir, readFile, writeFile } from "node:fs/promises"; +import { join, normalize } from "node:path"; +import { parse } from "yaml"; +import { fixture } from "./release-signing-fixture.mjs"; + +const WORKFLOW = new URL("../.github/workflows/publish.yml", import.meta.url); +const HELPER = "scripts/configure-release-signing.mjs"; +const SIGNING_STEP = "Apply approved signing trust to the packaging checkout"; +const AUTHENTICATE_STEP = "Authenticate the release tag"; +// Deliberately differs from the package version: consume the real env binding. +const FIXTURE_TAG = "v7.8.9"; + +function actionValue(value, context) { + const expression = /^\$\{\{\s*([A-Za-z0-9_.]+)\s*\}\}$/u.exec(String(value)); + if (expression === null) return String(value); + assert.ok( + Object.hasOwn(context, expression[1]), + "Unsupported workflow expression", + ); + return context[expression[1]]; +} + +function expand(value, environment) { + return value.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/gu, (_, name) => { + assert.ok( + Object.hasOwn(environment, name), + "Unknown replay environment variable", + ); + return environment[name]; + }); +} + +async function workflow() { + return parse(await readFile(WORKFLOW, "utf8")); +} + +/** Selected signing stages only: no runner/setup/install/gate/upload execution. */ +async function replay(t, document) { + const helperSource = await readFile( + new URL("./configure-release-signing.mjs", import.meta.url), + "utf8", + ); + const f = await fixture(t, { + sourceFiles: { [HELPER]: helperSource }, + tag: FIXTURE_TAG, + }); + const workspace = join(f.root, "checkout-workspace"); + const runnerTemp = join(f.root, "runner-temp"); + await mkdir(workspace); + await mkdir(runnerTemp); + const commit = f.git(["rev-parse", "HEAD"]).stdout.trim(); + const tagObject = f + .git(["rev-parse", `refs/tags/${FIXTURE_TAG}`]) + .stdout.trim(); + const context = { + "github.sha": commit, + "github.event.release.tag_name": FIXTURE_TAG, + "github.event.release.prerelease": "false", + "vars.RELEASE_ALLOWED_SIGNERS": ( + await readFile(f.signer.allowed, "utf8") + ).trim(), + }; + const prepare = document.jobs.prepare; + const jobEnvironment = { + ...f.env, + RUNNER_TEMP: runnerTemp, + ...Object.fromEntries( + Object.entries(prepare.env).map(([name, value]) => [ + name, + actionValue(value, context), + ]), + ), + }; + let producerPath; + let verified = false; + for (const step of prepare.steps) { + const environment = { + ...jobEnvironment, + ...Object.fromEntries( + Object.entries(step.env ?? {}).map(([name, value]) => [ + name, + actionValue(value, context), + ]), + ), + }; + if (step.name === AUTHENTICATE_STEP) { + // Replay only this public-file producer, not its GitHub fetch/shell body. + const assignment = /^\s*allowed_signers="([^"\r\n]+)"\s*$/mu.exec( + step.run, + ); + const producer = + /^\s*printf '%s\\n' "([^"\r\n]+)" > "([^"\r\n]+)"\s*$/mu.exec(step.run); + assert.ok( + assignment && producer, + "Approved public-file producer must be present", + ); + producerPath = expand(assignment[1], environment); + // A source contract and a filesystem boundary: never write outside temp. + assert.equal( + normalize(producerPath), + join(runnerTemp, "release-allowed-signers"), + ); + const producerEnvironment = { + ...environment, + allowed_signers: producerPath, + }; + assert.equal( + normalize(expand(producer[2], producerEnvironment)), + normalize(producerPath), + ); + const publicSigners = expand(producer[1], producerEnvironment); + await writeFile(producerPath, `${publicSigners}\n`); + f.git( + [ + "-c", + "gpg.format=ssh", + "-c", + `gpg.ssh.allowedSignersFile=${producerPath}`, + "verify-tag", + `refs/tags/${environment.RELEASE_TAG}`, + ], + { environment }, + ); + } else if (step.uses?.startsWith("actions/checkout@")) { + // A fresh real checkout cannot inherit the authenticator's local config. + f.run( + "git", + [ + "-c", + `init.templateDir=${join(f.root, "empty-template")}`, + "clone", + "--no-local", + "--no-hardlinks", + "--no-checkout", + f.repo, + workspace, + ], + { cwd: f.root, environment }, + ); + const ref = actionValue(step.with.ref, context); + f.run("git", ["checkout", "--detach", ref], { + cwd: workspace, + environment, + }); + } else if (step.name === SIGNING_STEP) { + // This restricted argv grammar consumes the actual YAML invocation; it + // never executes arbitrary shell or substitutes a test-only helper call. + const invocation = + /^node\s+(\S+)\s+"([^"\r\n]+)"\s+"([^"\r\n]+)"\s*$/u.exec( + step.run.trim(), + ); + assert.ok(invocation, "Signing step must invoke the reviewed Node CLI"); + f.run( + process.execPath, + [ + invocation[1], + expand(invocation[2], environment), + expand(invocation[3], environment), + ], + { cwd: workspace, environment }, + ); + } else if (step.id === "pack") { + const pack = step.run.replace(/\\\r?\n\s*/gu, " "); + assert.match(pack, /pnpm run release:pack -- /u); + assert.match(pack, /(?:^|\s)--require-release-tag(?:\s|$)/u); + const expected = /--expected-release-commit\s+"([^"]+)"/u.exec(pack); + assert.ok(expected, "Pack must bind its expected release commit"); + const git = (args) => + f.run("git", args, { cwd: workspace, environment }).stdout.trim(); + // The same real Git verification used by the packer's signature gate. + git(["verify-tag", "--raw", `refs/tags/${environment.RELEASE_TAG}`]); + assert.equal(git(["config", "--local", "--get", "gpg.format"]), "ssh"); + assert.equal( + normalize( + git(["config", "--local", "--get", "gpg.ssh.allowedSignersFile"]), + ), + normalize(producerPath), + ); + assert.equal( + git(["rev-parse", "HEAD"]), + expand(expected[1], environment), + ); + assert.equal( + git(["rev-parse", `refs/tags/${environment.RELEASE_TAG}^{commit}`]), + commit, + ); + assert.equal( + git(["rev-parse", `refs/tags/${environment.RELEASE_TAG}`]), + tagObject, + ); + verified = true; + break; + } + } + assert.ok(verified, "Replay must reach the actual pack verification stage"); +} + +test("actual prepare YAML carries approved trust into a fresh packaging checkout", async (t) => { + await replay(t, await workflow()); +}); + +test("removing the YAML signing step fails the actual Git pack signature guard", async (t) => { + const document = await workflow(); + document.jobs.prepare.steps = document.jobs.prepare.steps.filter( + (step) => step.name !== SIGNING_STEP, + ); + await assert.rejects(replay(t, document), /Fixture git failed/u); +}); + +test("moving the signing step before checkout fails its actual Node invocation", async (t) => { + const document = await workflow(); + const steps = document.jobs.prepare.steps; + const index = steps.findIndex((step) => step.name === SIGNING_STEP); + assert.notEqual(index, -1); + const [signing] = steps.splice(index, 1); + steps.splice( + steps.findIndex((step) => step.uses?.startsWith("actions/checkout@")), + 0, + signing, + ); + await assert.rejects(replay(t, document), /Fixture .* failed/u); +}); + +test("using a path other than the authenticator's public file fails the real helper", async (t) => { + const document = await workflow(); + const signing = document.jobs.prepare.steps.find( + (step) => step.name === SIGNING_STEP, + ); + signing.run = signing.run.replace( + "/release-allowed-signers", + "/missing-approved-file", + ); + await assert.rejects(replay(t, document), /Fixture .* failed/u); +});