fix(ci): validate Kova bin-only dependency (#103810)

This commit is contained in:
Vincent Koc
2026-07-10 09:41:01 -07:00
committed by GitHub
parent 845311cf97
commit 90322074dd
2 changed files with 25 additions and 4 deletions

View File

@@ -288,10 +288,27 @@ jobs:
git -C "$KOVA_SRC" checkout --detach FETCH_HEAD
npm --prefix "$KOVA_SRC" ci --ignore-scripts --no-audit --no-fund
node - "$KOVA_SRC" <<'NODE'
const fs = require("node:fs");
const path = require("node:path");
const root = process.argv[2];
for (const dependency of ["mock-ai-provider", "zod"]) {
require.resolve(dependency, { paths: [root] });
const packageJsonPath = require.resolve("mock-ai-provider/package.json", {
paths: [root],
});
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
const bin =
typeof packageJson.bin === "string"
? packageJson.bin
: packageJson.bin?.["mock-ai-provider"];
if (typeof bin !== "string" || bin.length === 0) {
throw new Error("mock-ai-provider does not declare its CLI entrypoint");
}
fs.accessSync(path.resolve(path.dirname(packageJsonPath), bin), fs.constants.R_OK);
fs.accessSync(
path.join(root, "node_modules", ".bin", "mock-ai-provider"),
fs.constants.X_OK,
);
require.resolve("zod", { paths: [root] });
NODE
cat > "$HOME/.local/bin/kova" <<EOF
#!/usr/bin/env bash

View File

@@ -91,8 +91,12 @@ describe("OpenClaw performance workflow", () => {
expect(installRun).toContain(
'npm --prefix "$KOVA_SRC" ci --ignore-scripts --no-audit --no-fund',
);
expect(installRun).toContain('for (const dependency of ["mock-ai-provider", "zod"])');
expect(installRun).toContain("require.resolve(dependency, { paths: [root] })");
expect(installRun).toContain('require.resolve("mock-ai-provider/package.json", {');
expect(installRun).toContain('packageJson.bin?.["mock-ai-provider"]');
expect(installRun).toContain('path.join(root, "node_modules", ".bin", "mock-ai-provider")');
expect(installRun).toContain("fs.constants.X_OK");
expect(installRun).toContain('require.resolve("zod", { paths: [root] })');
expect(installRun).not.toContain('require.resolve("mock-ai-provider",');
expect(
installRun.indexOf('npm --prefix "$KOVA_SRC" ci --ignore-scripts --no-audit --no-fund'),
).toBeLessThan(installRun.indexOf('cat > "$HOME/.local/bin/kova"'));