From 4dcb596219a039674d6cd36284d8002fd48c05a3 Mon Sep 17 00:00:00 2001 From: Taras Mankovski Date: Sun, 8 Nov 2026 07:10:56 -0500 Subject: [PATCH 1/3] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Check=20npm=20closure?= =?UTF-8?q?=20publishability=20in=20the=20Plan=20identity=20case?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The closure-publishability case and the identity case each built the CLI package into their own private workspace. The manifest checks now run immediately after the Plan case's build, before its emitted-bin consumers, so the file builds four times instead of five. Every assertion and child command is retained. Co-Authored-By: Claude Opus 5.5 --- scripts/tests/cli-npm-bin.test.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/scripts/tests/cli-npm-bin.test.ts b/scripts/tests/cli-npm-bin.test.ts index 11f6661bf..c02c04958 100644 --- a/scripts/tests/cli-npm-bin.test.ts +++ b/scripts/tests/cli-npm-bin.test.ts @@ -498,7 +498,7 @@ describe("npm CLI package", { sanitizeOps: false, sanitizeResources: false }, () * closure has to be publishable afterwards — not a verification artifact that * works locally and names directories npm would reject. */ - it("leaves every manifest in the closure publishable", function* () { + it("leaves every manifest in the closure publishable and reports the same Component identity the source tree ships", function* () { const root = yield* useNpmWorkspace(); const { version } = yield* readManifest(root, PKG_DIR, "deno.json"); const built = yield* buildCliPackage(root, version ?? "0.0.0-dev"); @@ -506,8 +506,8 @@ describe("npm CLI package", { sanitizeOps: false, sanitizeResources: false }, () throw new Error(`build-npm.ts exited ${built.code}\n${built.stderr}`); } - const source = yield* readManifest(root, PKG_DIR, "package.json"); - const internal = Object.keys(source.dependencies ?? {}).filter((name) => + const sourceManifest = yield* readManifest(root, PKG_DIR, "package.json"); + const internal = Object.keys(sourceManifest.dependencies ?? {}).filter((name) => name.startsWith("@executablemd/"), ); // Non-vacuous: the CLI is the deepest closure in the workspace. @@ -533,15 +533,6 @@ describe("npm CLI package", { sanitizeOps: false, sanitizeResources: false }, () }); } } - }); - - it("reports the same Component identity the source tree ships", function* () { - const root = yield* useNpmWorkspace(); - const { version } = yield* readManifest(root, PKG_DIR, "deno.json"); - const built = yield* buildCliPackage(root, version ?? "0.0.0-dev"); - if (built.code !== 0) { - throw new Error(`build-npm.ts exited ${built.code}\n${built.stderr}`); - } const source = yield* readTextFile(path.join(root, PKG_DIR, "src/documents/Plan.md")); const digest = createHash("sha256").update(source, "utf8").digest("hex"); From e09a31c5ffdeb5bba0ea43d503e07002f0bb07e4 Mon Sep 17 00:00:00 2001 From: Taras Mankovski Date: Sun, 8 Nov 2026 07:36:04 -0500 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20Build=20the=20npm=20CL?= =?UTF-8?q?I=20package=20once=20for=20its=20distribution=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every case in cli-npm-bin.test.ts built packages/cli into a private workspace of its own, five builds of the same inputs. A beforeAll now acquires one workspace and builds it once; each case reads that finished package and keeps its consumer directories, child processes and Api middleware to itself. The five original cases and their assertions are restored. The two smoke runs and the upgrade refusal run from a case-owned directory instead of the shared package root, and planned.txt is checked where the smoke run would write it. A same-file regression drives the test adapter directly. It proves that a one-time resource outlives each case, that a failed case leaves it to the next, and that it is released only after the last case's cleanup. Co-Authored-By: Claude Opus 5.5 --- scripts/tests/cli-npm-bin.test.ts | 188 ++++++++++++++++++++++++------ 1 file changed, 151 insertions(+), 37 deletions(-) diff --git a/scripts/tests/cli-npm-bin.test.ts b/scripts/tests/cli-npm-bin.test.ts index c02c04958..540886e0c 100644 --- a/scripts/tests/cli-npm-bin.test.ts +++ b/scripts/tests/cli-npm-bin.test.ts @@ -11,11 +11,12 @@ * what used to type-check a branch against the *previous* release — green until * a branch changed a shared API, then red for a reason the branch could not fix. */ -import { describe, it } from "@executablemd/test-support/bdd"; +import { beforeAll, beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import { runShell, shellQuote } from "@executablemd/test-support/launch"; -import { scoped, until } from "effection"; +import { ensure, scoped, spawn, suspend, until, withResolvers } from "effection"; import { createApi } from "@effectionx/context-api"; +import { createTestAdapter } from "@effectionx/test-adapter"; import * as sourceGitApi from "@executablemd/git/api"; import { exists, readTextFile, writeTextFile } from "@effectionx/fs"; import { createHash } from "node:crypto"; @@ -170,12 +171,10 @@ function* readEmittedManifest(root: string): Operation { return JSON.parse(yield* readTextFile(path.join(root, PKG_DIR, "npm/package.json"))); } -/** Run the built bin under Node, the way an `npm i -g @executablemd/cli` user would. */ -function runEmittedBin(root: string, args: string[]): Operation { - return runEmittedBinIn(root, root, args); -} - -/** The same, from a working directory the caller chooses. */ +/** + * Run the built bin under Node, the way an `npm i -g @executablemd/cli` user + * would, from a working directory the caller chooses. + */ function* runEmittedBinIn(root: string, cwd: string, args: string[]): Operation { const result = yield* timebox(TIMEOUT, function* () { return yield* exec("node", { @@ -190,15 +189,48 @@ function* runEmittedBinIn(root: string, cwd: string, args: string[]): Operation< return result.value; } +/** The finished build every case reads, and the version its manifest named. */ +interface BuiltPackage { + root: string; + version?: string; +} + describe("npm CLI package", { sanitizeOps: false, sanitizeResources: false }, () => { - it("relaunches its test-agent worker under Node", function* () { + let built: BuiltPackage | undefined; + + // One build answers every case: each reads the emitted package and writes + // only beneath directories of its own, so a failed build fails them all + // rather than being retried by the next. + beforeAll(function* () { + yield* ensure(() => { + built = undefined; + }); const root = yield* useNpmWorkspace(); const { version } = yield* readManifest(root, PKG_DIR, "deno.json"); + const result = yield* scoped(() => buildCliPackage(root, version ?? "0.0.0-dev")); + if (result.code !== 0) { + throw new Error(`build-npm.ts exited ${result.code}\n${result.stderr}`); + } + built = { root, version }; + }); + + // Children narrate as they run; each case reads only their captured results. + beforeEach(function* () { + yield* Stdio.around({ + *stdout() {}, + *stderr() {}, + }); + }); - const built = yield* buildCliPackage(root, version ?? "0.0.0-dev"); - if (built.code !== 0) { - throw new Error(`build-npm.ts exited ${built.code}\n${built.stderr}`); + function builtPackage(): BuiltPackage { + if (!built) { + throw new Error("the npm CLI package was not built"); } + return built; + } + + it("relaunches its test-agent worker under Node", function* () { + const { root } = builtPackage(); const consumer = yield* useTempDirectory("xmd-npm-module-consumer-"); yield* until( @@ -239,7 +271,8 @@ describe("npm CLI package", { sanitizeOps: false, sanitizeResources: false }, () expect({ code: moduleResult.code, stderr: moduleResult.stderr }).toMatchObject({ code: 0 }); expect(moduleResult.stdout).toContain("npm-typed-component"); - const run = yield* runEmittedBin(root, [ + const smokeCwd = yield* useTempDirectory("xmd-npm-smoke-"); + const run = yield* runEmittedBinIn(root, smokeCwd, [ "test", path.join(root, "smoke-test/test-agent/README.md"), ]); @@ -264,7 +297,7 @@ describe("npm CLI package", { sanitizeOps: false, sanitizeResources: false }, () // `` answers only a prompt carrying the selected documentation, // so a package missing the documentation assets or the protected tier gets // no Plan written at all rather than a weaker one. - const planned = yield* runEmittedBin(root, [ + const planned = yield* runEmittedBinIn(root, smokeCwd, [ "test", path.join(root, "smoke-test/plan-information/README.md"), "--raw", @@ -277,7 +310,7 @@ describe("npm CLI package", { sanitizeOps: false, sanitizeResources: false }, () expect(planned.stdout).not.toContain("ERROR"); // And nothing ran it: `` renders program text, so the file that // program names is still nobody's. - expect(yield* exists(path.join(root, "planned.txt"))).toBe(false); + expect(yield* exists(path.join(smokeCwd, "planned.txt"))).toBe(false); // The Markdown this package executes itself ships beside the module that // reads it. dnt emits the module graph only, so an asset nothing imports is @@ -317,12 +350,7 @@ describe("npm CLI package", { sanitizeOps: false, sanitizeResources: false }, () * route — the one an operator drives. */ it("publishes contextual Git APIs that compose across copies and loads a named Plugin", function* () { - const root = yield* useNpmWorkspace(); - const { version } = yield* readManifest(root, PKG_DIR, "deno.json"); - const built = yield* buildCliPackage(root, version ?? "0.0.0-dev"); - if (built.code !== 0) { - throw new Error(`build-npm.ts exited ${built.code}\n${built.stderr}`); - } + const { root } = builtPackage(); // Both halves of the subpath, for both packages a Plugin imports from. for (const pkg of ["packages/core", "packages/runtime"]) { @@ -445,12 +473,7 @@ describe("npm CLI package", { sanitizeOps: false, sanitizeResources: false }, () * way a caller composes it rather than through argv. */ it("runs a complete program piped into the emitted bin", function* () { - const root = yield* useNpmWorkspace(); - const { version } = yield* readManifest(root, PKG_DIR, "deno.json"); - const built = yield* buildCliPackage(root, version ?? "0.0.0-dev"); - if (built.code !== 0) { - throw new Error(`build-npm.ts exited ${built.code}\n${built.stderr}`); - } + const { root } = builtPackage(); // Run from a directory that is not the package, so nothing the program // renders could have come from a file beside the bin. @@ -498,16 +521,11 @@ describe("npm CLI package", { sanitizeOps: false, sanitizeResources: false }, () * closure has to be publishable afterwards — not a verification artifact that * works locally and names directories npm would reject. */ - it("leaves every manifest in the closure publishable and reports the same Component identity the source tree ships", function* () { - const root = yield* useNpmWorkspace(); - const { version } = yield* readManifest(root, PKG_DIR, "deno.json"); - const built = yield* buildCliPackage(root, version ?? "0.0.0-dev"); - if (built.code !== 0) { - throw new Error(`build-npm.ts exited ${built.code}\n${built.stderr}`); - } + it("leaves every manifest in the closure publishable", function* () { + const { root, version } = builtPackage(); - const sourceManifest = yield* readManifest(root, PKG_DIR, "package.json"); - const internal = Object.keys(sourceManifest.dependencies ?? {}).filter((name) => + const source = yield* readManifest(root, PKG_DIR, "package.json"); + const internal = Object.keys(source.dependencies ?? {}).filter((name) => name.startsWith("@executablemd/"), ); // Non-vacuous: the CLI is the deepest closure in the workspace. @@ -533,6 +551,10 @@ describe("npm CLI package", { sanitizeOps: false, sanitizeResources: false }, () }); } } + }); + + it("reports the same Component identity the source tree ships", function* () { + const { root } = builtPackage(); const source = yield* readTextFile(path.join(root, PKG_DIR, "src/documents/Plan.md")); const digest = createHash("sha256").update(source, "utf8").digest("hex"); @@ -668,7 +690,7 @@ describe("npm CLI package", { sanitizeOps: false, sanitizeResources: false }, () // provenance refusal runs ahead of the block that imports semver, ahead of // any release lookup, and ahead of touching a file — which is what makes // the npm package safe to publish without the eval block ever resolving. - const refused = yield* runEmittedBin(root, ["upgrade", "--status"]); + const refused = yield* runEmittedBinIn(root, elsewhere, ["upgrade", "--status"]); expect(refused.code).toBe(1); // The document is the output, so even a refused host renders its heading. // What matters is that the npm package answered at all: the transcript @@ -681,3 +703,95 @@ describe("npm CLI package", { sanitizeOps: false, sanitizeResources: false }, () ); }); }); + +/** What a case's operation ended with: `"completed"`, or the message it raised. */ +function* settled(operation: Operation): Operation { + try { + yield* operation; + return "completed"; + } catch (error) { + return error instanceof Error ? error.message : String(error); + } +} + +/** + * The ownership the suite above relies on, through the same adapter its + * `beforeAll` and cases run in: a one-time resource outlives each case, a + * failed case leaves it to the next, and it is released only after the last + * case's own cleanup has finished. + */ +describe("a beforeAll resource", { sanitizeOps: false, sanitizeResources: false }, () => { + it("outlives each case and is released after the last case's cleanup", function* () { + const outcome = yield* timebox(5_000, function* () { + const adapter = createTestAdapter({ name: "suite owner" }); + yield* ensure(() => adapter.destroy()); + const release = withResolvers(); + yield* ensure(() => { + release.resolve(); + }); + + let initializations = 0; + let suiteRoot: string | undefined; + adapter.addOnetimeSetup(function* () { + const directory = yield* useTempDirectory("xmd-npm-suite-owner-"); + initializations += 1; + suiteRoot = directory; + }); + function initialized(): string { + if (suiteRoot === undefined) { + throw new Error("the one-time setup never finished"); + } + return suiteRoot; + } + + let caseDirectory = ""; + const first = yield* adapter.runTest(function* () { + caseDirectory = yield* useTempDirectory("xmd-npm-case-"); + }); + expect(first.ok).toBe(true); + expect(initializations).toBe(1); + expect(yield* exists(initialized())).toBe(true); + expect(caseDirectory).not.toBe(""); + expect(yield* exists(caseDirectory)).toBe(false); + + const sentinel = new Error("an intentional case failure"); + const failed = yield* adapter.runTest(function* () { + throw sentinel; + }); + expect(failed.ok ? undefined : failed.error).toBe(sentinel); + expect(yield* exists(initialized())).toBe(true); + + const ready = withResolvers(); + const cleanupEntered = withResolvers(); + const held = adapter.runTest(function* () { + yield* ensure(function* () { + cleanupEntered.resolve(); + yield* release.operation; + }); + ready.resolve(); + yield* suspend(); + }); + yield* ready.operation; + expect(initializations).toBe(1); + + let destroyed = false; + const destroying = yield* spawn(function* () { + yield* adapter.destroy(); + destroyed = true; + }); + yield* cleanupEntered.operation; + expect(destroyed).toBe(false); + expect(yield* exists(initialized())).toBe(true); + + release.resolve(); + yield* destroying; + expect(destroyed).toBe(true); + expect(yield* exists(initialized())).toBe(false); + expect(initializations).toBe(1); + expect(yield* settled(held)).toBe("halted"); + }); + if (outcome.timeout) { + throw new Error("the adapter lifetime regression timed out"); + } + }); +}); From b80b25ca1e3dca647fa5f6c26041e1ae6ae3759a Mon Sep 17 00:00:00 2001 From: Taras Mankovski Date: Sun, 8 Nov 2026 07:50:00 -0500 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=A5=20Drop=20the=20exploratory=20b?= =?UTF-8?q?eforeAll-resource=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The adapter lifetime test in cli-npm-bin.test.ts was written to confirm how a beforeAll resource outlives its cases. It is not coverage this suite needs to carry. It is removed together with the imports and helper only it used. The one-build npm CLI package suite is unchanged. Co-Authored-By: Claude Opus 5.5 --- scripts/tests/cli-npm-bin.test.ts | 95 +------------------------------ 1 file changed, 1 insertion(+), 94 deletions(-) diff --git a/scripts/tests/cli-npm-bin.test.ts b/scripts/tests/cli-npm-bin.test.ts index 540886e0c..84bda304c 100644 --- a/scripts/tests/cli-npm-bin.test.ts +++ b/scripts/tests/cli-npm-bin.test.ts @@ -14,9 +14,8 @@ import { beforeAll, beforeEach, describe, it } from "@executablemd/test-support/bdd"; import { expect } from "@executablemd/test-support/expect"; import { runShell, shellQuote } from "@executablemd/test-support/launch"; -import { ensure, scoped, spawn, suspend, until, withResolvers } from "effection"; +import { ensure, scoped, until } from "effection"; import { createApi } from "@effectionx/context-api"; -import { createTestAdapter } from "@effectionx/test-adapter"; import * as sourceGitApi from "@executablemd/git/api"; import { exists, readTextFile, writeTextFile } from "@effectionx/fs"; import { createHash } from "node:crypto"; @@ -703,95 +702,3 @@ describe("npm CLI package", { sanitizeOps: false, sanitizeResources: false }, () ); }); }); - -/** What a case's operation ended with: `"completed"`, or the message it raised. */ -function* settled(operation: Operation): Operation { - try { - yield* operation; - return "completed"; - } catch (error) { - return error instanceof Error ? error.message : String(error); - } -} - -/** - * The ownership the suite above relies on, through the same adapter its - * `beforeAll` and cases run in: a one-time resource outlives each case, a - * failed case leaves it to the next, and it is released only after the last - * case's own cleanup has finished. - */ -describe("a beforeAll resource", { sanitizeOps: false, sanitizeResources: false }, () => { - it("outlives each case and is released after the last case's cleanup", function* () { - const outcome = yield* timebox(5_000, function* () { - const adapter = createTestAdapter({ name: "suite owner" }); - yield* ensure(() => adapter.destroy()); - const release = withResolvers(); - yield* ensure(() => { - release.resolve(); - }); - - let initializations = 0; - let suiteRoot: string | undefined; - adapter.addOnetimeSetup(function* () { - const directory = yield* useTempDirectory("xmd-npm-suite-owner-"); - initializations += 1; - suiteRoot = directory; - }); - function initialized(): string { - if (suiteRoot === undefined) { - throw new Error("the one-time setup never finished"); - } - return suiteRoot; - } - - let caseDirectory = ""; - const first = yield* adapter.runTest(function* () { - caseDirectory = yield* useTempDirectory("xmd-npm-case-"); - }); - expect(first.ok).toBe(true); - expect(initializations).toBe(1); - expect(yield* exists(initialized())).toBe(true); - expect(caseDirectory).not.toBe(""); - expect(yield* exists(caseDirectory)).toBe(false); - - const sentinel = new Error("an intentional case failure"); - const failed = yield* adapter.runTest(function* () { - throw sentinel; - }); - expect(failed.ok ? undefined : failed.error).toBe(sentinel); - expect(yield* exists(initialized())).toBe(true); - - const ready = withResolvers(); - const cleanupEntered = withResolvers(); - const held = adapter.runTest(function* () { - yield* ensure(function* () { - cleanupEntered.resolve(); - yield* release.operation; - }); - ready.resolve(); - yield* suspend(); - }); - yield* ready.operation; - expect(initializations).toBe(1); - - let destroyed = false; - const destroying = yield* spawn(function* () { - yield* adapter.destroy(); - destroyed = true; - }); - yield* cleanupEntered.operation; - expect(destroyed).toBe(false); - expect(yield* exists(initialized())).toBe(true); - - release.resolve(); - yield* destroying; - expect(destroyed).toBe(true); - expect(yield* exists(initialized())).toBe(false); - expect(initializations).toBe(1); - expect(yield* settled(held)).toBe("halted"); - }); - if (outcome.timeout) { - throw new Error("the adapter lifetime regression timed out"); - } - }); -});