fix(release): reject extra npm publish arguments

This commit is contained in:
Vincent Koc
2026-06-26 14:55:54 -07:00
parent 9d2bed25d8
commit 18fd38529d
2 changed files with 38 additions and 0 deletions
+5
View File
@@ -5,6 +5,11 @@ set -euo pipefail
mode="${1:-}"
publish_target="${2:-}"
if [[ "$#" -gt 2 ]]; then
echo "usage: bash scripts/clawhub-cli-npm-publish.sh --publish [package.tgz]" >&2
exit 2
fi
if [[ "${mode}" != "--publish" ]]; then
echo "usage: bash scripts/clawhub-cli-npm-publish.sh --publish [package.tgz]" >&2
exit 2
+33
View File
@@ -7,6 +7,39 @@ import { join, resolve } from "node:path";
import { describe, expect, it } from "vitest";
describe("clawhub CLI npm publish", () => {
it("rejects extra arguments before invoking npm", () => {
const root = mkdtempSync(join(tmpdir(), "clawhub-cli-npm-publish-"));
try {
const fakeBin = join(root, "bin");
const publishMarker = join(root, "published");
mkdirSync(fakeBin);
writeFileSync(
join(fakeBin, "npm"),
`#!/usr/bin/env bash\nprintf '%s\\n' "$*" > "${publishMarker}"\n`,
);
chmodSync(join(fakeBin, "npm"), 0o755);
const result = spawnSync(
"bash",
["scripts/clawhub-cli-npm-publish.sh", "--publish", "package.tgz", "--tag", "next"],
{
cwd: resolve("."),
encoding: "utf8",
env: { ...process.env, PATH: `${fakeBin}:${process.env.PATH}` },
},
);
expect(result.status).toBe(2);
expect(result.stderr).toContain(
"usage: bash scripts/clawhub-cli-npm-publish.sh --publish [package.tgz]",
);
expect(() => readFileSync(publishMarker)).toThrow();
} finally {
rmSync(root, { force: true, recursive: true });
}
});
it("rejects a tarball whose package version does not match the source package", () => {
const root = mkdtempSync(join(tmpdir(), "clawhub-cli-npm-publish-"));