Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions scripts/check-miner-package.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { fileURLToPath } from "node:url";

const ALLOWED = [
/^bin\/gittensory-miner\.js$/,
/^lib\/[a-z0-9-]+\.(js|d\.ts)$/,
// One optional level of subdirectory (e.g. lib/calibration/index.js, #2332) alongside the original flat
// lib/<name>.js layout -- both forms ship real runtime/type files, never build tooling or config.
/^lib\/([a-z0-9-]+\/)?[a-z0-9-]+\.(js|d\.ts)$/,
/^package\.json$/,
/^README\.md$/,
];
Expand All @@ -26,7 +28,7 @@ export function validateMinerPackFileList(files, readContent) {
for (const required of REQUIRED) {
if (!paths.includes(required)) throw new Error(`Miner package is missing required file: ${required}`);
}
if (!paths.some((file) => /^lib\/[a-z0-9-]+\.js$/.test(file))) {
if (!paths.some((file) => /^lib\/([a-z0-9-]+\/)?[a-z0-9-]+\.js$/.test(file))) {
throw new Error("Miner package is missing lib/*.js artifacts");
}
return paths;
Expand Down
27 changes: 27 additions & 0 deletions test/unit/check-miner-package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,33 @@ describe("check-miner-package script", () => {
expect(result.out).toContain("Unexpected file in miner package: scripts/extra.mjs");
});

it("REGRESSION (main was red after #3704): accepts a lib module split into a one-level subdirectory", () => {
const result = runChecker({
CHECK_MINER_PACK_TEST_FILES: JSON.stringify([
"package.json",
"bin/gittensory-miner.js",
"lib/calibration/index.js",
"lib/calibration/index.d.ts",
]),
CHECK_MINER_PACK_TEST_CONTENT: "{}",
});
expect(result.status).toBe(0);
expect(result.out).toContain("lib/calibration/index.js");
});

it("still rejects a file nested two levels deep under lib/", () => {
const result = runChecker({
CHECK_MINER_PACK_TEST_FILES: JSON.stringify([
"package.json",
"bin/gittensory-miner.js",
"lib/cli.js",
"lib/calibration/nested/index.js",
]),
});
expect(result.status).toBe(1);
expect(result.out).toContain("Unexpected file in miner package: lib/calibration/nested/index.js");
});

it("rejects a package missing the CLI bin", () => {
const result = runChecker({
CHECK_MINER_PACK_TEST_FILES: JSON.stringify(["package.json", "lib/cli.js"]),
Expand Down