diff --git a/scripts/check-miner-package.mjs b/scripts/check-miner-package.mjs index cc284ba515..1bb6ec7beb 100644 --- a/scripts/check-miner-package.mjs +++ b/scripts/check-miner-package.mjs @@ -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/.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$/, ]; @@ -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; diff --git a/test/unit/check-miner-package.test.ts b/test/unit/check-miner-package.test.ts index 1354932cc9..7c2f7f1c99 100644 --- a/test/unit/check-miner-package.test.ts +++ b/test/unit/check-miner-package.test.ts @@ -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"]),