diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index efdaaab..1d19a5a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -127,6 +127,32 @@ jobs: with: node-version: 24.18.0 package-manager-cache: false + - name: Bootstrap the reviewed npm CLI + shell: bash + run: | + set -euo pipefail + umask 077 + npm_directory="$(mktemp -d "${RUNNER_TEMP}/reviewed-npm.XXXXXX")" + npm_archive="${npm_directory}/npm-11.18.0.tgz" + node_path="$(command -v node)" + [[ "${node_path}" == /* && -f "${node_path}" && -x "${node_path}" ]] + curl --disable --fail --silent --show-error --proto '=https' --proxy '' \ + --max-time 60 --max-filesize 16777216 \ + --output "${npm_archive}" \ + 'https://registry.npmjs.org/npm/-/npm-11.18.0.tgz' + printf '%s %s\n' \ + '73f6155215ebabf4ed96dca1f567c2372cc713c33af2e5b9b62fde4e92373e2e' \ + "${npm_archive}" | sha256sum --check --status + tar --extract --gzip --file "${npm_archive}" --directory "${npm_directory}" \ + --no-same-owner --no-same-permissions + npm_cli="${npm_directory}/package/bin/npm-cli.js" + [[ -f "${npm_cli}" && ! -L "${npm_cli}" ]] + mkdir "${npm_directory}/bin" + # The archive's bin/npm selects Node's global npm; bypass that wrapper. + printf '#!/bin/bash\nexec %q %q "$@"\n' "${node_path}" "${npm_cli}" \ + > "${npm_directory}/bin/npm" + chmod 0700 "${npm_directory}/bin/npm" + printf '%s\n' "${npm_directory}/bin" >> "${GITHUB_PATH}" - name: Check the npm version shell: bash run: | @@ -365,6 +391,32 @@ jobs: with: node-version: 24.18.0 package-manager-cache: false + - name: Bootstrap the reviewed npm CLI + shell: bash + run: | + set -euo pipefail + umask 077 + npm_directory="$(mktemp -d "${RUNNER_TEMP}/reviewed-npm.XXXXXX")" + npm_archive="${npm_directory}/npm-11.18.0.tgz" + node_path="$(command -v node)" + [[ "${node_path}" == /* && -f "${node_path}" && -x "${node_path}" ]] + curl --disable --fail --silent --show-error --proto '=https' --proxy '' \ + --max-time 60 --max-filesize 16777216 \ + --output "${npm_archive}" \ + 'https://registry.npmjs.org/npm/-/npm-11.18.0.tgz' + printf '%s %s\n' \ + '73f6155215ebabf4ed96dca1f567c2372cc713c33af2e5b9b62fde4e92373e2e' \ + "${npm_archive}" | sha256sum --check --status + tar --extract --gzip --file "${npm_archive}" --directory "${npm_directory}" \ + --no-same-owner --no-same-permissions + npm_cli="${npm_directory}/package/bin/npm-cli.js" + [[ -f "${npm_cli}" && ! -L "${npm_cli}" ]] + mkdir "${npm_directory}/bin" + # The archive's bin/npm selects Node's global npm; bypass that wrapper. + printf '#!/bin/bash\nexec %q %q "$@"\n' "${node_path}" "${npm_cli}" \ + > "${npm_directory}/bin/npm" + chmod 0700 "${npm_directory}/bin/npm" + printf '%s\n' "${npm_directory}/bin" >> "${GITHUB_PATH}" - name: Check the npm version shell: bash run: | diff --git a/AGENTS.md b/AGENTS.md index 0c1beef..96e6e1d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -78,9 +78,10 @@ packages. Only the minimal publish job receives OIDC authority. Publication is integrity-checked, retry-safe, and dependency-ordered. See `docs/RELEASING.md`. -The sole registration exception is a separately reviewed, metadata-only first -`@pegma/storage-dynamodb@0.4.2` archive under `bootstrap`, which may be published -only by the maintainer with interactive 2FA. It contains no runtime, exports, scripts or +The sole registration exception was the separately reviewed, metadata-only +`@pegma/storage-dynamodb@0.4.2` archive published under `bootstrap`. That exception +requires maintainer interactive 2FA; it authorizes no runtime publication. +The archive contains no runtime, exports, scripts or dependencies, is not an SDK/release qualification, and is never a host input. Actual runtime publication remains trusted-publisher only. @@ -94,10 +95,13 @@ published code or substitute them for the pinned Core `0.4.0` runtime/error clas All four packages are in this repository. `@pegma/storage-core` and `@pegma/storage-azure-tables` are published at `0.4.0`, `@pegma/storage-cloudflare-d1` carries a `0.4.1` transaction-robustness -patch of its own. DynamoDB `0.4.2` is reserved for registration-only metadata; -`@pegma/storage-dynamodb@0.4.3` is the unpublished first trusted AWS runtime -candidate (see `docs/AWS_ADAPTER.md` and `docs/RELEASING.md`). Do not claim -registration or release before its actual registry evidence. The port offers keyed access, +patch of its own. DynamoDB `0.4.2` is published registration-only metadata. +The `v0.4.3` attempt failed before preparation, with no runtime archive or +publication. Its signed tag remains immutable; retain its release as a failure. +`@pegma/storage-dynamodb@0.4.4` is the unpublished first trusted +AWS runtime candidate (see `docs/AWS_ADAPTER.md` and `docs/RELEASING.md`). +The later D1 feature is planned as `0.4.5`. Do not claim runtime release before +its actual registry qualification. The port offers keyed access, optimistic concurrency through `update`, version-conditional `putIfUnchanged` and `deleteIfUnchanged`, partition reads, bounded authoritative cross-partition scans, and `transact`. diff --git a/docs/AWS_ADAPTER.md b/docs/AWS_ADAPTER.md index 4b7cc7d..fd78759 100644 --- a/docs/AWS_ADAPTER.md +++ b/docs/AWS_ADAPTER.md @@ -4,11 +4,13 @@ The runtime adapter is implemented in this repository. It qualifies when every conformance case passes against **Amazon DynamoDB Local** and the release gates -are satisfied. `@pegma/storage-dynamodb@0.4.3` is the unpublished first trusted -runtime candidate. Version `0.4.2` is reserved for a separately reviewed, +are satisfied. `@pegma/storage-dynamodb@0.4.4` is the unpublished first trusted +runtime candidate. Version `0.4.2` was published as a separately reviewed, metadata-only registration archive: it contains no runtime, exports, scripts or -dependencies, is not an SDK, and must never be a host input. Registration and -runtime publication remain pending until their actual registry evidence exists. +dependencies, is not an SDK, and must never be a host input. The `v0.4.3` release +attempt failed before preparation, producing no runtime archive or publication. +Its signed tag remains immutable; retain the release as a failed attempt. +Runtime qualification remains pending. Decided 2026-09-11. This is the assignment record for Storage Core's third real adapter — read `AGENTS.md` first; its hard rules govern everything here. @@ -78,17 +80,18 @@ Node 22 + 24. The port is unchanged, so `@pegma/storage-core` stays at `0.4.0` and the runtime candidate pins it exactly. `0.4.2` is registration-only metadata under `bootstrap`, -not a usable adapter release. The first trusted runtime candidate is `0.4.3`; +not a usable adapter release. The first trusted runtime candidate is `0.4.4`; its publication requires the reviewed signed-source and trusted-publisher flow. -Existing repository-wide tags `v0.4.0` and `v0.4.1` must never be reused. +Existing repository-wide tags `v0.4.0`, `v0.4.1` and failed `v0.4.3` must never +be reused. The later D1 feature is planned as `0.4.5`, after its own review. Unprivileged validation runs the full gates on Node 22 and 24 before preparation. Preparation depends on that validation and signed-release identity checks; it packs only selected source packages and retains the independently pinned exact original registry archives for unselected packages. Only the minimal publish job receives OIDC authority. See [RELEASING.md](RELEASING.md) for the separate -registration exception and runtime release procedure; this document records no -completed registration or runtime publication. +registration exception and runtime release procedure. Published metadata +registration does not qualify a runtime, which remains unpublished. ## What it unblocks diff --git a/docs/RELEASING.md b/docs/RELEASING.md index 399412d..8404b90 100644 --- a/docs/RELEASING.md +++ b/docs/RELEASING.md @@ -7,11 +7,13 @@ below is an explicit first-package exception, not a runtime release path. ## Current versions and source ownership -Core and Azure are published at `0.4.0`; D1 at `0.4.1`. DynamoDB `0.4.2` is reserved for -registration-only metadata, and `0.4.3` is the unpublished first trusted runtime -candidate. Registration is not adapter code, conformance evidence or a production -dependency. Do not claim an actual registration or release until its public -registry evidence exists. +Core and Azure are published at `0.4.0`; D1 at `0.4.1`. DynamoDB `0.4.2` is +published registration-only metadata, and `0.4.4` is the unpublished first trusted +runtime candidate. The `v0.4.3` release attempt failed its npm-version check +before preparation: no runtime archive was produced or published. Its signed +tag remains immutable; preserve the release as a failed attempt. Registration is +not adapter code, conformance +evidence or a production dependency; runtime qualification remains pending. Unversioned Core/Azure/D1 changes in current source are **not** the code published at those versions. Schema 2 deliberately selects source artifacts by the new tag @@ -22,9 +24,8 @@ no Core or host upgrade is implied. Versions are independently assigned but release tags share a repository-wide namespace. Never reuse or move a tag/version, including failed publication or -registration versions. First trusted DynamoDB is planned as `v0.4.3`; the separate -later D1 feature must allocate a fresh unused version, such as `0.4.4`, after rebase -and review. +registration versions. First trusted DynamoDB is now planned as `v0.4.4`; the +separate later D1 feature is planned as `0.4.5`, after rebase and its own review. ## Required configuration @@ -46,22 +47,22 @@ export refuse before I/O and direct the owner to the protected workflow. ## DynamoDB namespace registration -After the policy PR, full gates and normal merge, the maintainer may create and -verify the signed v0.4.3 source tag without creating its GitHub release yet. -That approved immutable source guards the separate registration preparation. - -A registration-only `@pegma/storage-dynamodb@0.4.2` archive contains exactly +The published registration-only `@pegma/storage-dynamodb@0.4.2` archive contains exactly package.json, README.md and LICENSE. It has no exports/main/module/types/bin, runtime files, scripts or dependencies of any kind. Metadata/README say that it only registers the namespace, is not an SDK and has no OIDC provenance. Inspect -and retain its exact bytes/digests before an explicit maintainer 2FA publication -under bootstrap; never install it for a backend/host proof or describe it as the +and retain its exact bytes/digests and the maintainer's bootstrap publication +record; never install it for a backend/host proof or describe it as the latest runtime. Inspect actual registry bytes/dist-tags afterward. No GitHub v0.4.2 release is needed. -Then configure and verify trusted publishing and package/account restrictions. -Create the v0.4.3 GitHub release only when this configuration is complete. Never -manually publish the real `0.4.3` artifact first: immutable bytes with missing trusted +Verify trusted publishing and package/account restrictions again for the fresh +runtime candidate. After the corrected source passes full gates and merges, +create and verify its signed annotated `v0.4.4` tag on `origin/main`; create its +GitHub release only when this configuration is complete. Do not move or reuse +the signed `v0.4.3` tag; retain its release as a failed attempt. +Never manually publish the real `0.4.4` artifact +first: immutable bytes with missing trusted provenance cannot later be repaired by a skip. Registration `0.4.2` remains immutable and explicitly outside runtime qualification. @@ -98,7 +99,7 @@ original invocation and github-hosted builder. Raw outputs and locks are retaine outside the five-file release inventory. Decoding an attestation is not cryptographic verification. -Old schema 1 releases and tags remain immutable. New producer code rejects their +Old schema 1 archives and signed tags remain immutable. New producer code rejects their schema rather than guessing an origin. Recover an old release using its original reviewed producer and retained artifacts; do not repack or rewrite historical tags under schema 2. @@ -110,6 +111,14 @@ Tests use real Azurite, local Miniflare D1 and Amazon DynamoDB Local with Java 2 The release workflow verifies the signed stable event identity before source execution, then runs both Node validation lanes before preparation. +Before the npm-version checks in both preparation and publication, the workflow +downloads the official npm `11.18.0` archive into an owned temporary directory, +verifies its pinned SHA-256 and extracts it. A private launcher invokes the exact +Node executable and that archive's `bin/npm-cli.js`; the stock `bin/npm` wrapper +can instead select Node's global npm. Neither job changes the global npm +installation. The publisher still installs no package dependencies and executes +no release-tag or package-source code. + Preparation requires a clean checkout at the signed annotated tag, exact event commit and origin/main ancestry. The selected runtime comes from that source; ordinary workspace builds for types/tests do not become unselected release @@ -158,8 +167,8 @@ Publisher validates the independently sealed original manifest, policy and preflight receipts again. It receives only verified original archives and publishes only selected source tar paths from a fresh private directory, with ignore-scripts, explicit official registry and provenance. Reused packages are -never republished. Package imports and crypto tool installation remain outside -OIDC authority. +never republished. Consumer package imports and signature/provenance auditing +remain outside OIDC authority. The verified npm tool is exactly `11.18.0`. By default, unprivileged verification authenticates the pinned official archive digest, extracts its bounded regular @@ -168,7 +177,7 @@ discover or execute host-bundled npm, whose legitimate extra `.bin` links are outside the original archive. An explicit `npmCli`/`RELEASE_NPM_CLI` remains a strict reviewed path: every file must match the verified official tree, without links or extra files, before execution. The minimal OIDC publisher still installs -nothing and uses its separately pinned Node/npm runtime. +no package dependencies and uses the separately verified CLI described above. Raw audit output is retained before any public consumer import, and its hashes are checked afterward. Never let a caller-provided qualified boolean or decoded bundle substitute for that actual cryptographic command. diff --git a/packages/storage-dynamodb/README.md b/packages/storage-dynamodb/README.md index ed84284..7ab6582 100644 --- a/packages/storage-dynamodb/README.md +++ b/packages/storage-dynamodb/README.md @@ -3,10 +3,13 @@ Amazon DynamoDB adapter for [`@pegma/storage-core`](https://www.npmjs.com/package/@pegma/storage-core). -Source `0.4.3` is the unpublished first trusted runtime candidate and pins -released Core `0.4.0`. Version `0.4.2` is reserved for registration-only metadata, +Source `0.4.4` is the unpublished first trusted runtime candidate and pins +released Core `0.4.0`. Version `0.4.2` was published as registration-only metadata, with no runtime exports/scripts/dependencies; it is not this adapter or a host -dependency. Source merge and metadata registration do not establish publication, +dependency. The `v0.4.3` release attempt failed before preparation, producing no +runtime archive or publication. Its signed tag remains immutable, and the +release is retained as a failed attempt. +Source merge and metadata registration do not establish runtime publication, registry provenance or host acceptance. See the [release policy](https://github.com/pegma-dev/storage-core/blob/main/docs/RELEASING.md). diff --git a/packages/storage-dynamodb/package.json b/packages/storage-dynamodb/package.json index acc3b04..e55ab2b 100644 --- a/packages/storage-dynamodb/package.json +++ b/packages/storage-dynamodb/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/storage-dynamodb", - "version": "0.4.3", + "version": "0.4.4", "description": "Amazon DynamoDB adapter for @pegma/storage-core.", "license": "MIT", "type": "module", diff --git a/tests/publish-workflow.test.ts b/tests/publish-workflow.test.ts index 5f03720..4c6a1b0 100644 --- a/tests/publish-workflow.test.ts +++ b/tests/publish-workflow.test.ts @@ -1,6 +1,15 @@ -import { execFileSync } from "node:child_process"; -import { readFile } from "node:fs/promises"; +import { execFileSync, spawnSync } from "node:child_process"; +import { + chmod, + mkdir, + mkdtemp, + readFile, + rm, + stat, + writeFile, +} from "node:fs/promises"; import { tmpdir } from "node:os"; +import { dirname, join, win32 } from "node:path"; import { describe, expect, it } from "vitest"; const workflow = ( @@ -46,7 +55,380 @@ function inlinePublisher(): string { .join("\n"); } +function shellStep(job: string, name: string): string { + const step = workflowStep(workflowJob(job), name); + const marker = " run: |\n"; + const start = step.indexOf(marker); + if (start === -1) throw new Error(`Shell body for ${name} was not found.`); + const lines = step + .slice(start + marker.length) + .trimEnd() + .split("\n"); + if (lines.some((line) => line.length > 0 && !line.startsWith(" "))) + throw new Error(`Unexpected shell indentation in ${name}.`); + return lines.map((line) => line.replace(/^ {10}/u, "")).join("\n"); +} + +function gitBashFromExecPath(output: string): string { + const execPath = output.trim(); + if (!win32.isAbsolute(execPath) || /[\r\n]/u.test(execPath)) + throw new Error( + "Git for Windows returned an invalid executable directory.", + ); + return win32.resolve(execPath, "..", "..", "..", "bin", "bash.exe"); +} + +async function bootstrapBash(): Promise { + if (process.platform !== "win32") return "/bin/bash"; + let output: string; + try { + output = execFileSync("git.exe", ["--exec-path"], { + encoding: "utf8", + timeout: 5_000, + maxBuffer: 64 * 1024, + }); + } catch { + throw new Error( + "Git for Windows is required to run the workflow shell tests.", + ); + } + const path = gitBashFromExecPath(output); + if (!(await stat(path).catch(() => undefined))?.isFile()) + throw new Error(`Git Bash was not found beside Git for Windows: ${path}`); + return path; +} + +function bashPath(path: string): string { + if (process.platform !== "win32") return path; + return path + .replace(/\\/gu, "/") + .replace( + /^([a-z]):\//iu, + (_match, drive: string) => `/${drive.toLowerCase()}/`, + ); +} + +function shellQuote(value: string): string { + return "'" + value.replaceAll("'", "'\"'\"'") + "'"; +} + +const bootstrapJobs = ["prepare", "publish"] as const; +const probeArguments = [ + "--fixture-probe", + "argument with spaces", + "single'and\"double", + "$(must-not-execute)", + "semicolon;literal", +]; +type BootstrapMode = + | "success" + | "download" + | "digest" + | "extract" + | "missing-cli" + | "relative-node"; +interface BootstrapTrace { + readonly kind: string; + readonly args?: readonly string[]; +} + +async function runReviewedNpmBootstrap(job: string, mode: BootstrapMode) { + const root = await mkdtemp(join(tmpdir(), "storage-reviewed-npm-")); + const runner = join(root, "runner with spaces"); + const fixture = join(root, "synthetic archive with spaces"); + const hostBin = join(root, "host bin"); + const githubPath = join(root, "github-path"); + const tracePath = join(root, "trace.jsonl"); + const digestInput = join(root, "digest-input"); + try { + await Promise.all([ + mkdir(runner), + mkdir(join(fixture, "package", "bin"), { recursive: true }), + mkdir(hostBin), + mkdir(join(root, "relative")), + ]); + const hostNpm = `#!/bin/bash +printf '%s\\n' '{"kind":"host"}' >> "$TEST_TRACE" +printf '%s\\n' '11.16.0' +`; + const stockNpm = hostNpm.replace('"host"', '"stock-wrapper"'); + await Promise.all([ + writeFile(join(hostBin, "npm"), hostNpm), + writeFile(join(root, "relative", "node"), "#!/bin/bash\nexit 0\n"), + writeFile(join(fixture, "package", "bin", "npm"), stockNpm), + writeFile(join(fixture, "package", "package.json"), '{"type":"module"}'), + writeFile(githubPath, ""), + writeFile(tracePath, ""), + writeFile(digestInput, ""), + ]); + await Promise.all([ + chmod(join(hostBin, "npm"), 0o700), + chmod(join(root, "relative", "node"), 0o700), + chmod(join(fixture, "package", "bin", "npm"), 0o700), + ]); + if (mode !== "missing-cli") + await writeFile( + join(fixture, "package", "bin", "npm-cli.js"), + `import {appendFileSync} from "node:fs"; +const args=process.argv.slice(2); +appendFileSync(process.env.TEST_TRACE_NATIVE,JSON.stringify({kind:"owned",args})+"\\n"); +process.stdout.write(args.length===1&&args[0]==="--version"?"11.18.0\\n":JSON.stringify(args)+"\\n"); +`, + ); + + // Only shell control flow and actual launcher selection are under test. + // Download, digest verification and extraction are explicitly controlled + // external ports; these synthetic bytes are NOT a real npm/crypto proof. + const controlledTools = ` +command() { + if [[ "$TEST_MODE" == 'relative-node' && "$#" == 2 && "$1" == '-v' && "$2" == 'node' ]]; then + printf '%s\\n' 'relative/node' + return 0 + fi + builtin command "$@" +} +curl() { + printf '%s\\n' '{"kind":"download"}' >> "$TEST_TRACE" + local output='' url='' proto='' proxy='unset' max_time='' max_size='' + local disabled=false fail=false silent=false show_error=false + [[ "$1" == '--disable' ]] || return 91 + while (( $# )); do + case "$1" in + --disable) disabled=true; shift ;; + --fail) fail=true; shift ;; + --silent) silent=true; shift ;; + --show-error) show_error=true; shift ;; + --proto) proto="$2"; shift 2 ;; + --proxy) proxy="$2"; shift 2 ;; + --max-time) max_time="$2"; shift 2 ;; + --max-filesize) max_size="$2"; shift 2 ;; + --output) output="$2"; shift 2 ;; + https://*) url="$1"; shift ;; + *) return 91 ;; + esac + done + [[ "$disabled" == true && "$fail" == true && "$silent" == true && "$show_error" == true ]] || return 91 + [[ "$proto" == '=https' && "$proxy" == '' && "$max_time" == 60 && "$max_size" == 16777216 ]] || return 91 + [[ "$url" == 'https://registry.npmjs.org/npm/-/npm-11.18.0.tgz' && -n "$output" ]] || return 91 + if [[ "$TEST_MODE" == 'download' ]]; then return 31; fi + printf '%s' 'synthetic archive bytes, not real npm' > "$output" +} +sha256sum() { + printf '%s\\n' '{"kind":"digest"}' >> "$TEST_TRACE" + local checksum + IFS= read -r checksum + printf '%s\\n' "$checksum" > "$TEST_DIGEST_INPUT" + [[ "$#" == 2 && "$1" == '--check' && "$2" == '--status' ]] || return 92 + [[ "$checksum" == '73f6155215ebabf4ed96dca1f567c2372cc713c33af2e5b9b62fde4e92373e2e '* ]] || return 93 + if [[ "$TEST_MODE" == 'digest' ]]; then return 32; fi +} +tar() { + printf '%s\\n' '{"kind":"extract"}' >> "$TEST_TRACE" + local archive='' destination='' + local extract=false gzip=false no_owner=false no_permissions=false + while (( $# )); do + case "$1" in + --extract) extract=true; shift ;; + --gzip) gzip=true; shift ;; + --file) archive="$2"; shift 2 ;; + --directory) destination="$2"; shift 2 ;; + --no-same-owner) no_owner=true; shift ;; + --no-same-permissions) no_permissions=true; shift ;; + *) return 94 ;; + esac + done + [[ "$extract" == true && "$gzip" == true && "$no_owner" == true && "$no_permissions" == true ]] || return 94 + [[ -s "$archive" && -n "$destination" ]] || return 94 + if [[ "$TEST_MODE" == 'extract' ]]; then return 33; fi + cp -R -- "$TEST_ARCHIVE_FIXTURE/package" "$destination/package" +} +`; + const version = /^ REVIEWED_NPM_VERSION: "([^"]+)"$/mu.exec(workflow)?.[1]; + if (version === undefined) + throw new Error("Reviewed npm version was not found."); + const script = `set -euo pipefail +${controlledTools} +printf 'HOST_VERSION=' +npm --version +if [[ "$TEST_MODE" == 'relative-node' ]]; then + [[ -f relative/node && -x relative/node ]] || exit 95 +fi +${shellStep(job, "Bootstrap the reviewed npm CLI")} +IFS= read -r reviewed_bin < "$GITHUB_PATH" +export PATH="$reviewed_bin:$PATH" +hash -r +${shellStep(job, "Check the npm version")} +printf 'OWNED_ARGUMENTS=' +npm ${probeArguments.map(shellQuote).join(" ")} +`; + const result = spawnSync( + await bootstrapBash(), + ["--noprofile", "--norc", "-c", script], + { + cwd: root, + encoding: "utf8", + timeout: 10_000, + maxBuffer: 256 * 1024, + env: { + PATH: `${bashPath(hostBin)}:${bashPath(dirname(process.execPath))}:/usr/bin:/bin`, + HOME: bashPath(root), + RUNNER_TEMP: bashPath(runner), + GITHUB_PATH: bashPath(githubPath), + REVIEWED_NPM_VERSION: version, + TEST_MODE: mode, + TEST_TRACE: bashPath(tracePath), + TEST_TRACE_NATIVE: tracePath, + TEST_DIGEST_INPUT: bashPath(digestInput), + TEST_ARCHIVE_FIXTURE: bashPath(fixture), + SystemRoot: process.env.SystemRoot, + TEMP: root, + TMP: root, + }, + }, + ); + const trace = (await readFile(tracePath, "utf8")) + .split("\n") + .filter(Boolean) + .map((line) => JSON.parse(line) as BootstrapTrace); + return { + result, + trace, + path: await readFile(githubPath, "utf8"), + digestInput: await readFile(digestInput, "utf8"), + }; + } finally { + await rm(root, { recursive: true, force: true }); + } +} + describe("publish workflow", () => { + it.each([ + { + execPath: String.raw`C:\Program Files\Git\mingw64\libexec\git-core`, + bash: String.raw`C:\Program Files\Git\bin\bash.exe`, + }, + { + execPath: String.raw`D:\developer tools\Git\mingw64\libexec\git-core`, + bash: String.raw`D:\developer tools\Git\bin\bash.exe`, + }, + { + execPath: "E:/scoop/apps/git/current/mingw64/libexec/git-core\n", + bash: String.raw`E:\scoop\apps\git\current\bin\bash.exe`, + }, + ])( + "resolves Git Bash beside the actual Git installation: $execPath", + ({ execPath, bash }) => { + expect(gitBashFromExecPath(execPath)).toBe(bash); + }, + ); + + it("keeps the actual preparation and publishing bootstrap shell bodies identical", () => { + expect(shellStep("prepare", "Bootstrap the reviewed npm CLI")).toBe( + shellStep("publish", "Bootstrap the reviewed npm CLI"), + ); + }); + + it.each(bootstrapJobs)( + "%s bootstraps reviewed npm after Node setup and before version checks or consumers", + (name) => { + const job = workflowJob(name); + const setup = job.indexOf(" - name: Set up Node.js\n"); + const bootstrap = job.indexOf( + " - name: Bootstrap the reviewed npm CLI\n", + ); + const check = job.indexOf(" - name: Check the npm version\n"); + const consumer = job.indexOf( + name === "prepare" + ? " - name: Pack the release files\n" + : " - name: Verify and publish the prepared release\n", + ); + expect(setup).toBeGreaterThanOrEqual(0); + expect(bootstrap).toBeGreaterThan(setup); + expect(check).toBeGreaterThan(bootstrap); + expect(consumer).toBeGreaterThan(check); + }, + ); + + it.each(bootstrapJobs)( + "%s actual shell selects the owned reviewed CLI over host npm 11.16 and preserves literal arguments", + async (job) => { + const f = await runReviewedNpmBootstrap(job, "success"); + expect(f.result.error).toBeUndefined(); + expect(f.result.signal).toBeNull(); + expect(f.result.status, f.result.stderr).toBe(0); + expect(f.result.stdout).toContain("HOST_VERSION=11.16.0\n"); + expect(f.result.stdout).toContain( + "OWNED_ARGUMENTS=" + JSON.stringify(probeArguments) + "\n", + ); + expect(f.trace.map((entry) => entry.kind)).toEqual([ + "host", + "download", + "digest", + "extract", + "owned", + "owned", + ]); + expect( + f.trace + .filter((entry) => entry.kind === "owned") + .map((entry) => entry.args), + ).toEqual([["--version"], probeArguments]); + expect(f.path.trim().split("\n")).toHaveLength(1); + expect(f.path.trim()).toMatch(/\/reviewed-npm\.[^/]+\/bin$/u); + expect(f.path).not.toContain("/package/bin"); + expect(f.digestInput).toMatch( + /^73f6155215ebabf4ed96dca1f567c2372cc713c33af2e5b9b62fde4e92373e2e .+\/npm-11\.18\.0\.tgz\n$/u, + ); + }, + ); + + it.each( + bootstrapJobs.flatMap((job) => [ + { + job, + mode: "download" as const, + status: 31, + calls: ["host", "download"], + }, + { + job, + mode: "digest" as const, + status: 32, + calls: ["host", "download", "digest"], + }, + { + job, + mode: "extract" as const, + status: 33, + calls: ["host", "download", "digest", "extract"], + }, + { + job, + mode: "missing-cli" as const, + status: 1, + calls: ["host", "download", "digest", "extract"], + }, + { + job, + mode: "relative-node" as const, + status: 1, + calls: ["host"], + }, + ]), + )( + "$job actual bootstrap stops on $mode failure without publishing PATH or falling back to host npm", + async ({ job, mode, status, calls }) => { + const f = await runReviewedNpmBootstrap(job, mode); + expect(f.result.error).toBeUndefined(); + expect(f.result.signal).toBeNull(); + expect(f.result.status, f.result.stderr).toBe(status); + expect(f.result.stdout).toContain("HOST_VERSION=11.16.0\n"); + expect(f.result.stdout).not.toContain("OWNED_ARGUMENTS="); + expect(f.trace.map((entry) => entry.kind)).toEqual(calls); + expect(f.path).toBe(""); + }, + ); + it.each([ { outcome: "success", reuseRequired: "false", upload: false }, { outcome: "success", reuseRequired: "true", upload: true }, diff --git a/tests/release-packages.test.ts b/tests/release-packages.test.ts index d19f0da..6d8e596 100644 --- a/tests/release-packages.test.ts +++ b/tests/release-packages.test.ts @@ -91,14 +91,14 @@ describe("release package metadata", () => { scripts?: { prepack?: string }; }>; - // Core/Azure040 and D1041 retain their original registry bytes. Dynamo043 + // Core/Azure040 and D1041 retain their original registry bytes. Dynamo044 // is the reviewed runtime candidate; registration-only042 is no SDK. // Every adapter pins the port exactly where it was published. expect(manifests.map(({ name, version }) => ({ name, version }))).toEqual([ { name: "@pegma/storage-core", version: "0.4.0" }, { name: "@pegma/storage-azure-tables", version: "0.4.0" }, { name: "@pegma/storage-cloudflare-d1", version: "0.4.1" }, - { name: "@pegma/storage-dynamodb", version: "0.4.3" }, + { name: "@pegma/storage-dynamodb", version: "0.4.4" }, ]); for (const adapter of manifests.slice(1)) { expect(adapter.dependencies?.["@pegma/storage-core"]).toBe("0.4.0"); @@ -633,11 +633,13 @@ async function preparedSchema2() { ); const bytes = sourceArchive(metadata), inspected = inspectReleaseTarball(bytes); - const tarball = "pegma-storage-dynamodb-0.4.3.tgz"; + const version = inspected.package.version; + const releaseTag = `v${version}`; + const tarball = `pegma-storage-dynamodb-${version}.tgz`; writeFileSync(join(output, tarball), bytes); packages.push({ name: "@pegma/storage-dynamodb", - version: "0.4.3", + version, directory: "storage-dynamodb", tarball, size: bytes.length, @@ -651,7 +653,7 @@ async function preparedSchema2() { kind: "source", repository: "pegma-dev/storage-core", gitCommit, - releaseTag: "v0.4.3", + releaseTag, directory: "storage-dynamodb", }, }); @@ -659,7 +661,7 @@ async function preparedSchema2() { schemaVersion: 2, repository: "pegma-dev/storage-core", gitCommit, - releaseTag: "v0.4.3", + releaseTag, registryPolicySha256, packages, }; diff --git a/tests/release-registry.test.ts b/tests/release-registry.test.ts index adb86ab..2bb4e6e 100644 --- a/tests/release-registry.test.ts +++ b/tests/release-registry.test.ts @@ -1269,7 +1269,7 @@ async function pipelineFixture() { kind: "source", repository: "pegma-dev/storage-core", gitCommit: gitRun(["rev-parse", "HEAD"]), - releaseTag: "v0.4.3", + releaseTag: `v${metadata.version}`, directory: basename(directory), }, }; @@ -1513,7 +1513,7 @@ function enableUnqualifiedRegistryOnlyStub( expect(selected).toHaveLength(1); const record = selected[0]!; expect(record.name).toBe("@pegma/storage-dynamodb"); - expect(manifest.releaseTag).toBe("v0.4.3"); + expect(manifest.releaseTag).toBe(`v${record.version}`); const bundle = JSON.parse( fixture("core040-slsa.json").toString("utf8"), ) as BundleFixture; @@ -1651,11 +1651,17 @@ async function controlledPrepare( vi.stubGlobal("fetch", f.seams.fetch); try { const { prepareRelease } = await import("../scripts/release-packages.mjs"); + const metadata = JSON.parse( + readFileSync( + join(f.root, "packages", "storage-dynamodb", "package.json"), + "utf8", + ), + ) as { version: string }; return await withoutExplicitNpm(() => prepareRelease({ root: f.root, requireClean: true, - releaseTag: "v0.4.3", + releaseTag: `v${metadata.version}`, ...(skipSmoke ? { skipSmoke: true } : {}), ...(output === undefined ? {} : { output }), }),