Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(module-pin-inventory): cover provider and shared pin sources

Steven Enamakelbf7af78f9467
diff --git a/scripts/__tests__/fetch-submodule-tags.test.mjs b/scripts/__tests__/fetch-submodule-tags.test.mjs
index ef2d12c10b..db86248d3f 100644
--- a/scripts/__tests__/fetch-submodule-tags.test.mjs
+++ b/scripts/__tests__/fetch-submodule-tags.test.mjs
@@ -11,43 +11,98 @@ function fetchTags(inventorySource) {
try {
for (const folder of ["scripts/ci", "scripts/lib", "bin"])
fs.mkdirSync(path.join(dir, folder), { recursive: true });
- fs.copyFileSync(path.join(root, "scripts/ci/fetch-submodule-tags.sh"), path.join(dir, "scripts/ci/fetch-submodule-tags.sh"));
+ fs.copyFileSync(
+ path.join(root, "scripts/ci/fetch-submodule-tags.sh"),
+ path.join(dir, "scripts/ci/fetch-submodule-tags.sh"),
+ );
if (inventorySource !== undefined)
- fs.writeFileSync(path.join(dir, "scripts/lib/module-pin-inventory.mjs"), inventorySource);
- fs.writeFileSync(path.join(dir, "bin/git"), `#!${process.execPath}
+ fs.writeFileSync(
+ path.join(dir, "scripts/lib/module-pin-inventory.mjs"),
+ inventorySource,
+ );
+ fs.writeFileSync(
+ path.join(dir, "bin/git"),
+ `#!${process.execPath}
const fs = require('node:fs');
const args = process.argv.slice(2);
fs.appendFileSync(process.env.FETCH_LOG, JSON.stringify(args) + '\\n');
if (args[2] === 'rev-parse') console.log(args[1] === 'vendor/tinycomputer' ? 'true' : 'false');
-`, { mode: 0o755 });
- execFileSync("bash", ["scripts/ci/fetch-submodule-tags.sh"], { cwd: dir, env: { ...process.env, PATH: `${dir}/bin:${process.env.PATH}`, FETCH_LOG: `${dir}/calls` }, stdio: "pipe" });
- return fs.readFileSync(`${dir}/calls`, "utf8").trim().split("\n").map(JSON.parse);
- } finally { fs.rmSync(dir, { recursive: true, force: true }); }
+`,
+ { mode: 0o755 },
+ );
+ execFileSync("bash", ["scripts/ci/fetch-submodule-tags.sh"], {
+ cwd: dir,
+ env: {
+ ...process.env,
+ PATH: `${dir}/bin:${process.env.PATH}`,
+ FETCH_LOG: `${dir}/calls`,
+ },
+ stdio: "pipe",
+ });
+ return fs
+ .readFileSync(`${dir}/calls`, "utf8")
+ .trim()
+ .split("\n")
+ .map(JSON.parse);
+ } finally {
+ fs.rmSync(dir, { recursive: true, force: true });
+ }
}
test("module tag fetch includes tinycomputer and unshallows only shallow modules", () => {
const inventoryPath = path.join(root, "scripts/lib/module-pin-inventory.mjs");
- const calls = fetchTags(fs.existsSync(inventoryPath) ? fs.readFileSync(inventoryPath, "utf8") : undefined);
+ const calls = fetchTags(
+ fs.existsSync(inventoryPath)
+ ? fs.readFileSync(inventoryPath, "utf8")
+ : undefined,
+ );
const fetches = calls.filter((args) => args[2] === "fetch");
const computer = fetches.find((args) => args[1] === "vendor/tinycomputer");
- assert.ok(computer, "every module-pin source, including tinycomputer, needs its tags");
+ assert.ok(
+ computer,
+ "every module-pin source, including tinycomputer, needs its tags",
+ );
assert.ok(computer.includes("--unshallow"));
- assert.ok(fetches.find((args) => args[1] === "vendor/tinywallet").every((arg) => arg !== "--unshallow"));
- assert.ok(fetches.every((args) => args.includes("--tags") && args.includes("--no-recurse-submodules")));
+ assert.ok(
+ fetches
+ .find((args) => args[1] === "vendor/tinywallet")
+ .every((arg) => arg !== "--unshallow"),
+ );
+ assert.ok(
+ fetches.every(
+ (args) =>
+ args.includes("--tags") && args.includes("--no-recurse-submodules"),
+ ),
+ );
});
test("module inventory import is inert and new/shared/provider sources are fetched once", async () => {
- const { PIN_MAP, modulePinRepositories } = await import("../lib/module-pin-inventory.mjs");
+ const { PIN_MAP, modulePinRepositories } =
+ await import("../lib/module-pin-inventory.mjs");
assert.ok(PIN_MAP.tinycomputer);
const fixture = {
original: { submodule: "vendor/original" },
shared: { sharesWith: "vendor/original" },
- provider: { submodule: null, provider: { builtAgainst: "vendor/original" } },
+ provider: {
+ submodule: null,
+ provider: { builtAgainst: "vendor/original" },
+ },
future: { submodule: "vendor/future" },
};
- assert.deepEqual(modulePinRepositories(fixture), ["vendor/future", "vendor/original"]);
- const source = fs.readFileSync(path.join(root, "scripts/lib/module-pin-inventory.mjs"), "utf8") + '\nPIN_MAP.future = { submodule: "vendor/future" };\nPIN_MAP.shared = { sharesWith: "vendor/tinycomputer" };\n';
+ assert.deepEqual(modulePinRepositories(fixture), [
+ "vendor/future",
+ "vendor/original",
+ ]);
+ const source =
+ fs.readFileSync(
+ path.join(root, "scripts/lib/module-pin-inventory.mjs"),
+ "utf8",
+ ) +
+ '\nPIN_MAP.future = { submodule: "vendor/future" };\nPIN_MAP.shared = { sharesWith: "vendor/tinycomputer" };\n';
const fetches = fetchTags(source).filter((args) => args[2] === "fetch");
- assert.equal(fetches.filter((args) => args[1] === "vendor/tinycomputer").length, 1);
+ assert.equal(
+ fetches.filter((args) => args[1] === "vendor/tinycomputer").length,
+ 1,
+ );
assert.equal(fetches.filter((args) => args[1] === "vendor/future").length, 1);
});
diff --git a/scripts/lib/module-pin-inventory.mjs b/scripts/lib/module-pin-inventory.mjs
index 14864945a2..0dad5a5d0a 100644
--- a/scripts/lib/module-pin-inventory.mjs
+++ b/scripts/lib/module-pin-inventory.mjs
@@ -27,7 +27,15 @@ export const PIN_MAP = {
/** Return each module repository needed by the pin gate, in stable order. */
export function modulePinRepositories(pinMap = PIN_MAP) {
- return [...new Set(Object.values(pinMap).map((entry) =>
- entry.provider ? entry.provider.builtAgainst : (entry.submodule ?? entry.sharesWith),
- ).filter(Boolean))].sort();
+ return [
+ ...new Set(
+ Object.values(pinMap)
+ .map((entry) =>
+ entry.provider
+ ? entry.provider.builtAgainst
+ : (entry.submodule ?? entry.sharesWith),
+ )
+ .filter(Boolean),
+ ),
+ ].sort();
}