From 77f9361a5cb4cec911ad1e3e6f90f99a51cd031e Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Mon, 9 Nov 2026 12:37:40 -0500 Subject: [PATCH 1/2] Fix host01 registry verifier CLI initialization cycle --- AGENTS.md | 10 ++-- docs/AWS_ADAPTER.md | 15 +++--- docs/RELEASING.md | 25 +++++++--- packages/storage-dynamodb/README.md | 10 ++-- packages/storage-dynamodb/package.json | 2 +- scripts/release-registry-verify.mjs | 15 +++++- tests/release-packages.test.ts | 4 +- tests/release-registry-cli.test.ts | 69 ++++++++++++++++++++++++++ 8 files changed, 123 insertions(+), 27 deletions(-) create mode 100644 tests/release-registry-cli.test.ts diff --git a/AGENTS.md b/AGENTS.md index 96e6e1d..4608265 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -96,11 +96,13 @@ 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 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 +The `v0.4.3` attempt failed its npm-version check before preparation. +The `v0.4.4` attempt completed preparation and smoke checks, then failed the +preflight CLI entry with a module cycle (exit 13), before publication. +Keep both signed tags immutable and retain their releases as failed attempts. +`@pegma/storage-dynamodb@0.4.5` 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 +The later D1 feature is planned as `0.4.6`. 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 diff --git a/docs/AWS_ADAPTER.md b/docs/AWS_ADAPTER.md index fd78759..6a29896 100644 --- a/docs/AWS_ADAPTER.md +++ b/docs/AWS_ADAPTER.md @@ -4,12 +4,14 @@ 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.4` is the unpublished first trusted +are satisfied. `@pegma/storage-dynamodb@0.4.5` 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. 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. +attempt failed its npm-version check before preparation, producing no runtime +archive. The `v0.4.4` attempt completed preparation and smoke checks, then failed +the preflight CLI entry with a module cycle (exit 13). Neither published a +runtime. Keep both signed tags immutable and retain the failed releases. Runtime qualification remains pending. Decided 2026-09-11. This is the assignment record for Storage Core's third @@ -80,10 +82,11 @@ 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.4`; +not a usable adapter release. The first trusted runtime candidate is `0.4.5`; its publication requires the reviewed signed-source and trusted-publisher flow. -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. +Existing repository-wide tags `v0.4.0`, `v0.4.1`, failed `v0.4.3` and failed +`v0.4.4` must never be reused. The later D1 feature is planned as `0.4.6`, 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 diff --git a/docs/RELEASING.md b/docs/RELEASING.md index 8404b90..7c1ff42 100644 --- a/docs/RELEASING.md +++ b/docs/RELEASING.md @@ -8,11 +8,14 @@ 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 -published registration-only metadata, and `0.4.4` is the unpublished first trusted +published registration-only metadata, and `0.4.5` 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 +tag remains immutable; preserve the release as a failed attempt. The `v0.4.4` +attempt completed preparation and smoke checks, then its direct preflight CLI +failed with a top-level-await module-entry cycle (exit 13), before publication. +Retain that signed tag, prepared artifacts and failed release as well. +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 @@ -24,8 +27,14 @@ 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 now planned as `v0.4.4`; the -separate later D1 feature is planned as `0.4.5`, after rebase and its own review. +registration versions. First trusted DynamoDB is now planned as `v0.4.5`; the +separate later D1 feature is planned as `0.4.6`, after rebase and its own review. + +A release run uses the workflow at its tagged commit, as documented in +[workflow triggers](https://docs.github.com/en/actions/concepts/workflows-and-actions/workflows#workflow-triggers) +and the [`release` event reference](https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#release). +Changing `main` cannot repair that older tagged workflow; workflow code fixes +require a fresh version and signed tag. ## Required configuration @@ -58,10 +67,10 @@ v0.4.2 release is needed. 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 +create and verify its signed annotated `v0.4.5` 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 +the signed `v0.4.3` or `v0.4.4` tags; retain their releases as failed attempts. +Never manually publish the real `0.4.5` 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. diff --git a/packages/storage-dynamodb/README.md b/packages/storage-dynamodb/README.md index 7ab6582..5fbcbc5 100644 --- a/packages/storage-dynamodb/README.md +++ b/packages/storage-dynamodb/README.md @@ -3,12 +3,14 @@ Amazon DynamoDB adapter for [`@pegma/storage-core`](https://www.npmjs.com/package/@pegma/storage-core). -Source `0.4.4` is the unpublished first trusted runtime candidate and pins +Source `0.4.5` 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. 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. +dependency. The `v0.4.3` release attempt failed its npm-version check before +preparation, producing no runtime archive. The `v0.4.4` attempt completed +preparation and smoke checks, then failed the preflight CLI entry with a module +cycle (exit 13). Neither published a runtime. Both signed tags remain immutable; +retain their releases as failed attempts. 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 e55ab2b..e97b5b5 100644 --- a/packages/storage-dynamodb/package.json +++ b/packages/storage-dynamodb/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/storage-dynamodb", - "version": "0.4.4", + "version": "0.4.5", "description": "Amazon DynamoDB adapter for @pegma/storage-core.", "license": "MIT", "type": "module", diff --git a/scripts/release-registry-verify.mjs b/scripts/release-registry-verify.mjs index ebc2f53..60e6d81 100644 --- a/scripts/release-registry-verify.mjs +++ b/scripts/release-registry-verify.mjs @@ -1463,5 +1463,16 @@ async function main() { if ( process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url) -) - await main(); +) { + // Finish module evaluation before main imports the producer/registry cycle. + // An unsettled CLI stays failed; only completed verification may succeed. + process.exitCode = 13; + main() + .then(() => { + process.exitCode = 0; + }) + .catch((error) => { + process.exitCode = 1; + console.error(error instanceof Error ? error.message : String(error)); + }); +} diff --git a/tests/release-packages.test.ts b/tests/release-packages.test.ts index 6d8e596..87fa5cd 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. Dynamo044 + // Core/Azure040 and D1041 retain their original registry bytes. Dynamo045 // 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.4" }, + { name: "@pegma/storage-dynamodb", version: "0.4.5" }, ]); for (const adapter of manifests.slice(1)) { expect(adapter.dependencies?.["@pegma/storage-core"]).toBe("0.4.0"); diff --git a/tests/release-registry-cli.test.ts b/tests/release-registry-cli.test.ts new file mode 100644 index 0000000..8826071 --- /dev/null +++ b/tests/release-registry-cli.test.ts @@ -0,0 +1,69 @@ +import { spawnSync } from "node:child_process"; +import { mkdtemp, readdir, rm } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { fileURLToPath } from "node:url"; +import { describe, expect, it } from "vitest"; + +const cli = fileURLToPath( + new URL("../scripts/release-registry-verify.mjs", import.meta.url), +); + +describe("release registry CLI startup", () => { + it.each(["preflight", "verify"] as const)( + "%s reaches the missing-manifest error through the actual cyclic CLI modules", + async (command) => { + const directory = await mkdtemp(join(tmpdir(), "storage-registry-cli-")); + const manifest = join(directory, "missing-package-manifest.json"); + try { + // These are synthetic parser inputs, not release identities or proof. + // The missing manifest must refuse before registry, npm or crypto work. + // Enter the actual file directly: importing the exported API would not + // exercise its CLI guard or the former top-level-await import cycle. + const result = spawnSync( + process.execPath, + [ + cli, + command, + "--manifest", + manifest, + "--expected-release-commit", + "a".repeat(40), + "--expected-manifest-sha256", + "b".repeat(64), + "--output", + join(directory, "verification-output"), + "--run-id", + "12345", + "--run-attempt", + "1", + ], + { + cwd: directory, + encoding: "utf8", + timeout: 10_000, + maxBuffer: 128 * 1024, + env: { + PATH: process.env.PATH, + SystemRoot: process.env.SystemRoot, + HOME: directory, + TMP: directory, + TEMP: directory, + }, + }, + ); + + expect(result.error).toBeUndefined(); + expect(result.signal).toBeNull(); + expect(result.status, result.stderr).toBe(1); + expect(result.stderr).toMatch(/\bENOENT\b/u); + expect(result.stderr).toContain(manifest); + expect(result.stderr).not.toMatch(/unsettled top-level await/iu); + expect(result.stdout).toBe(""); + expect(await readdir(directory)).toEqual([]); + } finally { + await rm(directory, { recursive: true, force: true }); + } + }, + ); +}); From f3d529ee1b936df611e8ba1b68b0d6830c89e33f Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Mon, 9 Nov 2026 13:02:16 -0500 Subject: [PATCH 2/2] Preserve CLI diagnostics and validate invocation before I/O --- scripts/release-registry-verify.mjs | 15 +- tests/release-registry-cli.test.ts | 214 ++++++++++++++++++++++++---- 2 files changed, 198 insertions(+), 31 deletions(-) diff --git a/scripts/release-registry-verify.mjs b/scripts/release-registry-verify.mjs index 60e6d81..5c84227 100644 --- a/scripts/release-registry-verify.mjs +++ b/scripts/release-registry-verify.mjs @@ -1445,16 +1445,27 @@ function cliOptions(args) { } async function main() { const [command, ...args] = process.argv.slice(2), - options = cliOptions(args); + options = cliOptions(args), + runId = Number(options.runId ?? process.env.GITHUB_RUN_ID), + runAttempt = Number(options.runAttempt ?? process.env.GITHUB_RUN_ATTEMPT); if ( !["preflight", "verify"].includes(command) || !options.manifest || + typeof options.output !== "string" || + options.output.length === 0 || + !Number.isSafeInteger(runId) || + runId < 1 || + !Number.isSafeInteger(runAttempt) || + runAttempt < 1 || !/^[0-9a-f]{40}$/u.test(options.expectedReleaseCommit ?? "") || !/^[0-9a-f]{64}$/u.test(options.expectedManifestSha256 ?? "") ) fail( "usage: release-registry-verify.mjs preflight|verify --manifest --expected-release-commit --expected-manifest-sha256 --output --run-id --run-attempt", ); + // Keep the resolved invocation identity stable across asynchronous work. + options.runId = runId; + options.runAttempt = runAttempt; const { verifyPreparedManifest } = await import("./release-packages.mjs"); const manifest = await verifyPreparedManifest(options.manifest, options); if (command === "preflight") await preflightRegistry(manifest, options); @@ -1473,6 +1484,6 @@ if ( }) .catch((error) => { process.exitCode = 1; - console.error(error instanceof Error ? error.message : String(error)); + console.error(error); }); } diff --git a/tests/release-registry-cli.test.ts b/tests/release-registry-cli.test.ts index 8826071..3b221a4 100644 --- a/tests/release-registry-cli.test.ts +++ b/tests/release-registry-cli.test.ts @@ -1,5 +1,5 @@ import { spawnSync } from "node:child_process"; -import { mkdtemp, readdir, rm } from "node:fs/promises"; +import { mkdtemp, readFile, readdir, rm } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { fileURLToPath } from "node:url"; @@ -8,36 +8,188 @@ import { describe, expect, it } from "vitest"; const cli = fileURLToPath( new URL("../scripts/release-registry-verify.mjs", import.meta.url), ); +const cliSource = (await readFile(cli, "utf8")).replace(/\r\n/gu, "\n"); +const commands = ["preflight", "verify"] as const; + +function actualEntryBody(): string { + const marker = [ + "if (", + " process.argv[1] &&", + " resolve(process.argv[1]) === fileURLToPath(import.meta.url)", + ") {", + "", + ].join("\n"); + const parts = cliSource.split(marker); + if (parts.length !== 2 || !parts[1]!.trimEnd().endsWith("\n}")) + throw new Error("The actual registry CLI entry guard was not found."); + return parts[1]!.trimEnd().slice(0, -2); +} + +async function runActualCli( + command: string, + changes: { + readonly omit?: readonly string[]; + readonly overrides?: Readonly>; + readonly env?: Readonly>; + } = {}, +) { + const directory = await mkdtemp(join(tmpdir(), "storage-registry-cli-")); + const manifest = join(directory, "missing-package-manifest.json"); + try { + // Synthetic parser inputs only. No release identity or crypto is claimed. + // A nonexistent manifest refuses before registry, npm or proof operations. + const fields = new Map([ + ["--manifest", manifest], + ["--expected-release-commit", "a".repeat(40)], + ["--expected-manifest-sha256", "b".repeat(64)], + ["--output", join(directory, "verification-output")], + ["--run-id", "12345"], + ["--run-attempt", "1"], + ]); + for (const flag of changes.omit ?? []) fields.delete(flag); + for (const [flag, value] of Object.entries(changes.overrides ?? {})) + fields.set(flag, value); + // Enter the actual file: importing an API never exercised its CLI cycle. + const result = spawnSync( + process.execPath, + [ + cli, + command, + ...Array.from(fields).flatMap(([flag, value]) => [flag, value]), + ], + { + cwd: directory, + encoding: "utf8", + timeout: 10_000, + maxBuffer: 128 * 1024, + env: { + PATH: process.env.PATH, + SystemRoot: process.env.SystemRoot, + HOME: directory, + TMP: directory, + TEMP: directory, + // In particular, missing-ID cases inherit no host GitHub fallback. + ...changes.env, + }, + }, + ); + return { result, manifest, entries: await readdir(directory) }; + } finally { + await rm(directory, { recursive: true, force: true }); + } +} describe("release registry CLI startup", () => { - it.each(["preflight", "verify"] as const)( + it.each(commands)( "%s reaches the missing-manifest error through the actual cyclic CLI modules", async (command) => { - const directory = await mkdtemp(join(tmpdir(), "storage-registry-cli-")); - const manifest = join(directory, "missing-package-manifest.json"); + const f = await runActualCli(command); + expect(f.result.error).toBeUndefined(); + expect(f.result.signal).toBeNull(); + expect(f.result.status, f.result.stderr).toBe(1); + expect(f.result.stderr).toMatch(/\bENOENT\b/u); + expect(f.result.stderr).toContain(f.manifest); + expect(f.result.stderr).not.toMatch(/unsettled top-level await/iu); + expect(f.result.stdout).toBe(""); + expect(f.entries).toEqual([]); + }, + ); + + it.each( + commands.flatMap((command) => + ["--output", "--run-id", "--run-attempt"].map((flag) => ({ + command, + flag, + })), + ), + )( + "$command rejects missing $flag before manifest I/O", + async ({ command, flag }) => { + const f = await runActualCli(command, { omit: [flag] }); + expect(f.result.error).toBeUndefined(); + expect(f.result.signal).toBeNull(); + expect(f.result.status, f.result.stderr).toBe(1); + expect(f.result.stderr).toContain("usage: release-registry-verify.mjs"); + expect(f.result.stderr).not.toMatch(/ENOENT|unsettled top-level await/iu); + expect(f.result.stdout).toBe(""); + expect(f.entries).toEqual([]); + }, + ); + + it.each([ + { command: "preflight", flag: "--run-id", value: "0" }, + { command: "verify", flag: "--run-attempt", value: "-1" }, + { command: "preflight", flag: "--run-id", value: "9007199254740992" }, + { command: "verify", flag: "--run-attempt", value: "1.5" }, + ])( + "$command rejects $flag=$value before manifest I/O", + async ({ command, flag, value }) => { + const f = await runActualCli(command, { overrides: { [flag]: value } }); + expect(f.result.error).toBeUndefined(); + expect(f.result.signal).toBeNull(); + expect(f.result.status, f.result.stderr).toBe(1); + expect(f.result.stderr).toContain("usage: release-registry-verify.mjs"); + expect(f.result.stderr).not.toMatch(/ENOENT|unsettled top-level await/iu); + expect(f.result.stdout).toBe(""); + expect(f.entries).toEqual([]); + }, + ); + + it.each(commands)( + "%s retains valid GitHub run-ID environment fallbacks", + async (command) => { + const f = await runActualCli(command, { + omit: ["--run-id", "--run-attempt"], + env: { GITHUB_RUN_ID: "12345", GITHUB_RUN_ATTEMPT: "2" }, + }); + expect(f.result.error).toBeUndefined(); + expect(f.result.signal).toBeNull(); + expect(f.result.status, f.result.stderr).toBe(1); + expect(f.result.stderr).toMatch(/\bENOENT\b/u); + expect(f.result.stderr).toContain(f.manifest); + expect(f.result.stderr).not.toMatch(/usage:|unsettled top-level await/iu); + expect(f.result.stdout).toBe(""); + expect(f.entries).toEqual([]); + }, + ); + + it("rejects an unknown command before manifest I/O", async () => { + const f = await runActualCli("not-a-command"); + expect(f.result.error).toBeUndefined(); + expect(f.result.signal).toBeNull(); + expect(f.result.status, f.result.stderr).toBe(1); + expect(f.result.stderr).toContain("usage: release-registry-verify.mjs"); + expect(f.result.stderr).not.toMatch(/ENOENT|unsettled top-level await/iu); + expect(f.result.stdout).toBe(""); + expect(f.entries).toEqual([]); + }); +}); + +describe("actual CLI entry exit mapping, without verification", () => { + it.each([ + { outcome: "fulfilled", status: 0, main: "async function main() {}" }, + { + outcome: "rejected", + status: 1, + main: 'async function main() { throw new Error("synthetic entry failure", {cause: new Error("synthetic underlying cause")}); }', + }, + { + outcome: "unsettled", + status: 13, + main: "function main() { return new Promise(() => {}); }", + }, + ])( + "maps a $outcome main to exit $status using the verbatim entry body", + async ({ outcome, status, main }) => { + const directory = await mkdtemp( + join(tmpdir(), "storage-registry-entry-"), + ); try { - // These are synthetic parser inputs, not release identities or proof. - // The missing manifest must refuse before registry, npm or crypto work. - // Enter the actual file directly: importing the exported API would not - // exercise its CLI guard or the former top-level-await import cycle. + // The exact production guard BODY is executed with only main controlled. + // This isolates completion/error handling, not a crypto or publish PASS. const result = spawnSync( process.execPath, - [ - cli, - command, - "--manifest", - manifest, - "--expected-release-commit", - "a".repeat(40), - "--expected-manifest-sha256", - "b".repeat(64), - "--output", - join(directory, "verification-output"), - "--run-id", - "12345", - "--run-attempt", - "1", - ], + ["--input-type=module", "-e", main + "\n" + actualEntryBody()], { cwd: directory, encoding: "utf8", @@ -52,14 +204,18 @@ describe("release registry CLI startup", () => { }, }, ); - expect(result.error).toBeUndefined(); expect(result.signal).toBeNull(); - expect(result.status, result.stderr).toBe(1); - expect(result.stderr).toMatch(/\bENOENT\b/u); - expect(result.stderr).toContain(manifest); - expect(result.stderr).not.toMatch(/unsettled top-level await/iu); + expect(result.status, result.stderr).toBe(status); expect(result.stdout).toBe(""); + if (outcome === "rejected") { + expect(result.stderr).toContain("Error: synthetic entry failure"); + expect(result.stderr).toMatch(/\bat main\s*\(/u); + expect(result.stderr).toContain("[cause]"); + expect(result.stderr).toContain("Error: synthetic underlying cause"); + } else { + expect(result.stderr).toBe(""); + } expect(await readdir(directory)).toEqual([]); } finally { await rm(directory, { recursive: true, force: true });