Skip to content

Commit f31c2ac

Browse files
committed
🔧 Read through the package filesystem and prove the graph ships (#83)
Two corrections to `0f179628`. `stat` comes from `@effectionx/fs` and is yielded directly, so the packaged- document walk goes through the repository's filesystem like everything else on this path. `node:fs/promises` keeps only what the package does not provide — recursive copy, temp directories, and a recursive listing, since its own `readdir` takes no options — and the import comment now says so. The npm proof is the contract rather than the symptom. `cli-npm-bin.test.ts` compares every entry of `REVIEW_DOCUMENTS` against its emitted copy under `npm/esm/src/documents/`, byte for byte, plus `src/components.md`. Driven by the manifest rather than a count or a second list: a component added to the graph and not shipped is exactly what has to fail, and a hand-kept list is what would not notice. Presence and content are told apart so a missing asset reports as one instead of an unexplained ENOENT. Three mutations discriminate it: copying directories as files reproduces the original EINVAL; skipping nested documents builds a clean package the review cannot resolve a component from; and altering one emitted document's bytes, which loads and digests fine, is caught by the byte comparison alone and named.
1 parent 0f17962 commit f31c2ac

2 files changed

Lines changed: 40 additions & 3 deletions

File tree

‎scripts/build-npm.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ import {
3333
fromFileUrl,
3434
readTextFile,
3535
rm,
36+
stat,
3637
writeTextFile,
3738
} from "@effectionx/fs";
3839
import { listWorkspacePaths } from "./lib/workspace.ts";
3940
import { join, sep } from "node:path";
40-
// Recursive directory copy and temp-dir creation are not part of @effectionx/fs.
41-
import { cp, mkdtemp, readdir, stat } from "node:fs/promises";
41+
// Only what `@effectionx/fs` does not provide: recursive directory copy,
42+
// temp-dir creation, and a recursive listing — its own `readdir` takes no
43+
// options. Everything else on this path goes through the package.
44+
import { cp, mkdtemp, readdir } from "node:fs/promises";
4245
import { tmpdir } from "node:os";
4346
import { z } from "npm:zod@^4";
4447

@@ -81,7 +84,7 @@ function* packagedDocuments(pkgDir: URL): Operation<string[]> {
8184
// `src/documents/` never noticed; the review graph keeps its documents under
8285
// `components/` and `policies/`, and copying a directory as a file fails the
8386
// whole npm build with `EINVAL`.
84-
const info = yield* until(stat(join(root, name)));
87+
const info = yield* stat(join(root, name));
8588
if (info.isFile()) {
8689
found.push(`src/documents/${name.split(sep).join("/")}`);
8790
}

‎scripts/tests/cli-npm-bin.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import { describe, it } from "@executablemd/test-support/bdd";
1616
import { expect } from "@executablemd/test-support/expect";
1717
import { runShell, shellQuote } from "@executablemd/test-support/launch";
18+
import { REVIEW_DOCUMENTS } from "../../packages/code-review-agent/src/review-components.ts";
1819
import { ensure, until } from "effection";
1920
import { exists, readTextFile, rm } from "@effectionx/fs";
2021
import { createHash } from "node:crypto";
@@ -149,6 +150,39 @@ describe("npm CLI package", { sanitizeOps: false, sanitizeResources: false }, ()
149150
yield* readTextFile(path.join(ROOT, PKG_DIR, "src/documents", asset)),
150151
);
151152
}
153+
154+
// The same contract for the review graph, which is where it actually bit.
155+
// Those documents sit in `components/` and `policies/` subdirectories, and
156+
// the recursive listing that finds them also names the directories
157+
// themselves — so the build copied a directory as a file and produced no
158+
// package at all. A build that skipped them instead would have produced a
159+
// package that installs cleanly and cannot resolve a single review
160+
// component, on Node and Bun, while Deno read them from the source tree and
161+
// stayed green.
162+
//
163+
// Driven by the manifest rather than by a count or a list written here: the
164+
// thing that has to fail is a component added to the graph and not shipped,
165+
// and a second copy of the list maintained by hand is exactly what would
166+
// not notice.
167+
const reviewSource = path.join(ROOT, "packages/code-review-agent/src");
168+
const reviewEmitted = path.join(ROOT, "packages/code-review-agent/npm/esm/src");
169+
for (const document of REVIEW_DOCUMENTS) {
170+
const asset = path.join("documents", document.group, `${document.name}.md`);
171+
const emitted = path.join(reviewEmitted, asset);
172+
// Told apart on purpose: an absent asset and one whose bytes differ are
173+
// different build failures, and a bare read would report the first as an
174+
// unexplained ENOENT.
175+
expect([asset, yield* exists(emitted)]).toEqual([asset, true]);
176+
expect([asset, yield* readTextFile(emitted)]).toEqual([
177+
asset,
178+
yield* readTextFile(path.join(reviewSource, asset)),
179+
]);
180+
}
181+
// And the documentation for the six reserved registrations, which is named
182+
// individually rather than swept out of `src/documents/`.
183+
expect(yield* readTextFile(path.join(reviewEmitted, "components.md"))).toBe(
184+
yield* readTextFile(path.join(reviewSource, "components.md")),
185+
);
152186
});
153187

154188
/**

0 commit comments

Comments
 (0)