Skip to content

Commit 7415491

Browse files
committed
fix: remove unavailable OpenGrep install alternatives
1 parent 67d22a5 commit 7415491

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

‎scripts/run-opengrep.sh‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ if ! command -v opengrep >/dev/null 2>&1; then
4545
cat >&2 <<'EOF'
4646
error: 'opengrep' not found on PATH.
4747
48-
Install with one of:
48+
Install with:
4949
curl -fsSL https://raw.githubusercontent.com/opengrep/opengrep/v1.27.1/install.sh | bash -s -- -v v1.27.1
50-
brew install opengrep/tap/opengrep
51-
pipx install opengrep
5250
5351
(See https://opengrep.dev for other options.)
5452
EOF

‎test/scripts/run-opengrep.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,37 @@ function installOpengrepStub(repo: string): { argsPath: string; binDir: string }
4242
}
4343

4444
describe("run-opengrep.sh", () => {
45+
it("fails before scanning with official installation advice when opengrep is missing", () => {
46+
const repo = createTempDir("openclaw-run-opengrep-missing-");
47+
copyRunOpengrepFiles(repo);
48+
writeFile(path.join(repo, "security/opengrep/precise.yml"), "rules: []\n");
49+
50+
const binDir = path.join(repo, "bin");
51+
fs.mkdirSync(binDir);
52+
for (const command of ["bash", "dirname", "cat"]) {
53+
const executable = execFileSync("bash", ["-c", 'command -v "$1"', "_", command], {
54+
encoding: "utf8",
55+
}).trim();
56+
fs.symlinkSync(executable, path.join(binDir, command));
57+
}
58+
59+
const result = spawnSync(
60+
"bash",
61+
["scripts/run-opengrep.sh", "--changed", "--sarif", "--error"],
62+
{ cwd: repo, env: { ...process.env, PATH: binDir }, encoding: "utf8" },
63+
);
64+
65+
expect(result.status).toBe(127);
66+
expect(result.stdout).toBe("");
67+
expect(result.stderr).toContain("'opengrep' not found on PATH");
68+
expect(result.stderr).toMatch(
69+
/curl -fsSL https:\/\/raw\.githubusercontent\.com\/opengrep\/opengrep\/\S+\/install\.sh \| bash -s -- -v \S+/,
70+
);
71+
expect(fs.existsSync(path.join(repo, ".opengrep-out"))).toBe(false);
72+
expect(result.stderr).not.toContain("pipx");
73+
expect(result.stderr).not.toContain("opengrep/tap/opengrep");
74+
});
75+
4576
it("validates the rulepack when only OpenGrep rulepack files changed", () => {
4677
const repo = createTempDir("openclaw-run-opengrep-");
4778
git(repo, "init", "-q");

0 commit comments

Comments
 (0)