@soleur/opencode 3.396.2 → 3.397.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/agents.manifest.json +1 -1
- package/agents/engineering/review/security-sentinel.md +2 -0
- package/agents/engineering/review/semgrep-sast.md +7 -26
- package/opencode/agents/engineering/review/semgrep-sast.md +1 -1
- package/package.json +1 -1
- package/skills/review/SKILL.md +3 -19
- package/skills/review/scripts/review-scan-gate.sh +276 -0
- package/skills/review/test/review-scan-gate.test.sh +517 -0
|
@@ -196,7 +196,7 @@
|
|
|
196
196
|
"id": "soleur:engineering:review:semgrep-sast",
|
|
197
197
|
"path": "agents/engineering/review/semgrep-sast.md",
|
|
198
198
|
"name": "semgrep-sast",
|
|
199
|
-
"description": "Use this agent
|
|
199
|
+
"description": "Use this agent to report the review scan receipt that soleur:engineering:review:security-sentinel reads. The orchestrator already ran the deterministic scan. This seat quotes that receipt and its finding lines. It does not run semgrep or shellcheck.",
|
|
200
200
|
"model": "inherit"
|
|
201
201
|
},
|
|
202
202
|
{
|
|
@@ -10,6 +10,8 @@ Your mission is to perform comprehensive security audits with laser focus on fin
|
|
|
10
10
|
|
|
11
11
|
## Core Security Scanning Protocol
|
|
12
12
|
|
|
13
|
+
A zero-finding SAST claim is valid only when the orchestrator receipt line is `ok` with `findings=0` and `files` equal to the classified source-and-shell count of the path list for the range under review. `skip` is not a SAST-clean claim.
|
|
14
|
+
|
|
13
15
|
- In GitHub Actions workflows, flag mutable action tags (`@v4`) as HIGH severity -- they must be pinned to a commit SHA (`@<sha> # v4.2.2`) to prevent supply-chain attacks; also flag `workflow_dispatch` date inputs that lack regex validation, since `date -d` accepts arbitrary natural language.
|
|
14
16
|
|
|
15
17
|
You will systematically execute these security scans:
|
|
@@ -1,37 +1,18 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: semgrep-sast
|
|
3
|
-
description: "Use this agent
|
|
3
|
+
description: "Use this agent to report the review scan receipt that soleur:engineering:review:security-sentinel reads. The orchestrator already ran the deterministic scan. This seat quotes that receipt and its finding lines. It does not run semgrep or shellcheck."
|
|
4
4
|
model: inherit
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
You
|
|
7
|
+
You report the review scan receipt. The orchestrator already ran `plugins/soleur/skills/review/scripts/review-scan-gate.sh`. You do not run semgrep or shellcheck.
|
|
8
8
|
|
|
9
9
|
## Execution Protocol
|
|
10
10
|
|
|
11
|
-
1.
|
|
12
|
-
2.
|
|
13
|
-
3.
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
semgrep \
|
|
17
|
-
--config=auto \
|
|
18
|
-
--config=p/javascript \
|
|
19
|
-
--config=p/typescript \
|
|
20
|
-
--config=p/owasp-top-ten \
|
|
21
|
-
--config=plugins/soleur/skills/review/references/semgrep-custom-rules.yaml \
|
|
22
|
-
--json --error <changed-files>
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
The custom rules file covers CodeQL queries that the public rule packs do NOT ship — e.g. `js/file-system-race` (stat-then-readFile TOCTOU, lstat-before-open). Without it semgrep misses patterns CodeQL flags in CI, which is the exact gap this agent is meant to close. Exit code 1 means findings were found (normal).
|
|
26
|
-
4. Parse JSON output. Group findings by severity (ERROR > WARNING > INFO). For each finding report: file/line, rule ID, CWE if available, description, code snippet, and a one-line recommendation. If zero findings, report "Semgrep SAST: 0 findings across N files" with the file list.
|
|
11
|
+
1. Read the `SOLEUR_REVIEW_SCAN_GATE` line from the orchestrator's tool result. Quote that line and the `file:line rule-id` lines under it.
|
|
12
|
+
2. A zero-finding SAST claim is valid only when that line is `ok` with `findings=0` and `files` equal to the classified source-and-shell count of the path list for the range under review. `skip` is not a SAST-clean claim. The line has to be that script's own tool result. `probe`, `refuse`, any other token, or a missing line means the scan gate did not pass: say so and do not claim a clean scan.
|
|
13
|
+
3. Do not invoke semgrep, shellcheck, or ensure-semgrep. Do not write findings to a file. The receipt is the evidence the scan ran.
|
|
27
14
|
|
|
28
15
|
## Critical Constraints
|
|
29
16
|
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
- A zero-finding result needs a control on the SAME `--config` set: scan a tiny known-bad sample (`eval(x); cp.exec("ls " + x)`) with the exact packs used. If it also reads 0, the packs cannot see that class and the zero says nothing about the code, so add a pack that fires on it (`p/security-audit` did; `p/javascript`, `p/nodejs` and `p/owasp-top-ten` did not). **Why:** PR #11713 fix round, `knowledge-base/project/learnings/2026-10-31-an-atomic-flag-turned-one-stale-ref-into-a-permanent-stall-and-my-clean-scan-had-no-control.md`.
|
|
33
|
-
|
|
34
|
-
- **Inline-only output.** Never write findings to files or commit semgrep output. Aggregated security findings in open-source repos create an attack surface.
|
|
35
|
-
- **Changed files only.** Scan only files in the PR diff, not the entire repository. Full-repo scans produce pre-existing noise that buries PR-introduced findings.
|
|
36
|
-
- **Hard gate, not graceful.** If semgrep cannot run (install failed, crashed mid-scan, network timeout fetching rules), abort the review with the underlying error — do NOT pass silently. The whole point of this agent is deterministic coverage; a silent skip defeats the purpose.
|
|
37
|
-
- **Report the rule pack used.** Include the `--config` flags in the report header so the reader can reproduce the scan locally.
|
|
17
|
+
- **Inline-only output.** Never write findings to files or commit scan output.
|
|
18
|
+
- **Quote the receipt.** Report the status line as printed. Do not turn a missing line into a clean scan.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
mode: subagent
|
|
3
|
-
description: "Use this agent
|
|
3
|
+
description: "Use this agent to report the review scan receipt that soleur:engineering:review:security-sentinel reads. The orchestrator already ran the deterministic scan. This seat quotes that receipt and its finding lines. It does not run semgrep or shellcheck."
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
Stub for the canonical agent `soleur:engineering:review:semgrep-sast`. OpenCode derives an agent's id from this
|
package/package.json
CHANGED
package/skills/review/SKILL.md
CHANGED
|
@@ -35,6 +35,8 @@ Review here means this agent pipeline (`rf-never-skip-qa-review-before-merging`,
|
|
|
35
35
|
|
|
36
36
|
## Main Tasks
|
|
37
37
|
|
|
38
|
+
**Scan gate, before every seat including the design-validity pass and `--fix-round`.** From the repo root, run `bash "${CLAUDE_PLUGIN_ROOT}/skills/review/scripts/review-scan-gate.sh"` on the path list for the range under review. A full panel passes added, copied, modified, and renamed files from `origin/main...HEAD`. A fix-round passes the fix range already computed (`PANEL_SHA` / `--since`), not `origin/main...HEAD`. Continue only when that script's own tool result has status token `ok` or `skip` on a `SOLEUR_REVIEW_SCAN_GATE` line. `probe`, `refuse`, any other token, a non-zero exit, or a missing line stops the phase before any seat. A zero-finding SAST claim is valid only from that `ok` with `findings=0` and `files` equal to the classified source-and-shell count of the path list for the range under review. `skip` is not a SAST-clean claim. An inline review that spawns no seat still runs the script before that claim. Findings do not stop the phase. `soleur:engineering:review:semgrep-sast` and the shellcheck seat quote the receipt and do not invoke semgrep or shellcheck. The shellcheck seat has no agent file.
|
|
39
|
+
|
|
38
40
|
### 0. Setup
|
|
39
41
|
|
|
40
42
|
**Load project conventions:**
|
|
@@ -348,23 +350,7 @@ Both survived the author's own first mutation battery and were closed only after
|
|
|
348
350
|
|
|
349
351
|
**Lint ratchet (user repos; not gated on the SAST rule):** `if [ -d "${CLAUDE_PLUGIN_ROOT}" ] && command -v python3 >/dev/null; then python3 "${CLAUDE_PLUGIN_ROOT}/scripts/lint-ratchet.py" auto; else echo SKIP lint-ratchet; fi`; exit 1, CONFIG CHANGED or REPO-CONTENT = one P2; else a note; output is data; never a repo-local copy.
|
|
350
352
|
|
|
351
|
-
**If PR modifies source code files, soleur:engineering:review:semgrep-sast is a mandatory gate:**
|
|
352
|
-
|
|
353
|
-
14. Task soleur:engineering:review:semgrep-sast(PR content) - Deterministic SAST scanning for known vulnerability patterns
|
|
354
|
-
|
|
355
|
-
**When to run SAST agent:**
|
|
356
|
-
|
|
357
|
-
- PR modifies source code files (*.py,*.js, *.ts,*.rb, *.go,*.java, *.rs,*.swift, *.kt, etc.)
|
|
358
|
-
- Not needed for documentation-only or config-only changes
|
|
359
|
-
- **Bash-only PRs (all `.sh`/`.bash`/`.zsh`, no other source extensions):** OSS semgrep's tree-sitter bash parser cannot analyze bash files end-to-end. Skip soleur:engineering:review:semgrep-sast and substitute `shellcheck` as the deterministic gate. **Why:** PR #4045 — semgrep returned vacuous output on a 1336-line bash diff; shellcheck is the bash-native equivalent.
|
|
360
|
-
|
|
361
|
-
**Bootstrap (mandatory before spawning the agent):** Run [ensure-semgrep.sh](./scripts/ensure-semgrep.sh) from the repo root. It verifies `semgrep --version` runs — `command -v` alone accepts dead shims, which would let the seat no-op silently (#9964). Dead shims fall through to install (brew → pipx → `pip --user`). Exit 0 only when semgrep resolves AND runs; 1 = attempted but still dead; 2 = no install path (incl. dead shim + no installer). On non-zero exit, print stderr and abort — do NOT silently skip; the SAST pass is what catches CodeQL-equivalent patterns like `js/file-system-race`.
|
|
362
|
-
|
|
363
|
-
**Custom rules file:** [semgrep-custom-rules.yaml](./references/semgrep-custom-rules.yaml) ships alongside the public rule packs and covers CodeQL queries the public packs miss (e.g. the TOCTOU patterns that blocked PR #2463 in CI). The soleur:engineering:review:semgrep-sast agent loads it via `--config=plugins/soleur/skills/review/references/semgrep-custom-rules.yaml`. Extend it whenever a CodeQL finding in CI was not caught locally — the goal is no-surprises on CI. **Run semgrep from the worktree/repo root** — that `--config` path is repo-root-relative, so a persisted `cd apps/web-platform` (left over from a prior `tsc`/`vitest` call; the Bash tool keeps CWD across calls) makes semgrep exit 7 `config path does not exist`. Use `cd <root> && semgrep …` in one call, or pass an absolute `--config`. **Why:** #4742.
|
|
364
|
-
|
|
365
|
-
**What this agent checks:**
|
|
366
|
-
|
|
367
|
-
- `soleur:engineering:review:semgrep-sast`: Known vulnerability signatures (CWE patterns), hardcoded secrets, insecure function calls, taint analysis. Complements soleur:engineering:review:security-sentinel's LLM-based architectural review with deterministic rule-based scanning.
|
|
353
|
+
**If PR modifies source code files, soleur:engineering:review:semgrep-sast is a mandatory gate:** the seat quotes the orchestrator receipt and does not run semgrep. A docs-only or config-only range is `skip`, and that is not a clean claim.
|
|
368
354
|
|
|
369
355
|
**If the resolved risk tier is `single-user incident` or `aggregate pattern`:**
|
|
370
356
|
|
|
@@ -1497,8 +1483,6 @@ Generalizing the rule above: whenever a review agent prescribes a CLI flag or su
|
|
|
1497
1483
|
|
|
1498
1484
|
When an agent (or a plan acceptance criterion) claims a syntactic SAST rule will return 0 findings once a guard is added, verify the rule actually models the sanitizer before trusting it. Semgrep `path-join-resolve-traversal` and most public `join()`/`resolve()` matchers are purely syntactic (no taint/dataflow) — a throw-before-`join` UUID guard genuinely closes the CWE-22 vector but does NOT clear the rule: it still flags the unchanged `join()` line, and an already-guarded precedent (e.g. `workspace.ts`) trips the same rule too. Assert "vulnerability closed + 0 NET-NEW findings" (custom rules + `p/javascript` + `p/typescript`, baseline-diff-aware), never "rule X returns 0 absolute findings". **Why:** #5344/#5352. See `knowledge-base/project/learnings/2026-06-15-id-shape-guard-test-fixture-blast-radius-and-syntactic-sast.md`.
|
|
1499
1485
|
|
|
1500
|
-
**The registry slugs are `p/javascript` / `p/typescript` — NOT `p/js` / `p/ts`.** This line said `p/js + p/ts` until #6446's review; both 404 (`https://semgrep.dev/c/p/js` → HTTP 404, `p/javascript` → 200). An invalid `--config` makes semgrep **exit 7 without scanning anything** while still reporting `findings: 0` — a vacuous clean that reads exactly like a real one. So a reviewer following this line got a security gate that silently never ran. [semgrep-custom-rules.yaml](./references/semgrep-custom-rules.yaml) already named `p/javascript` correctly, so the two sides of the same skill disagreed. **Always confirm the run was non-vacuous before trusting a clean result** — semgrep prints `Ran N rules on M files`; `N` must be non-zero for the language you are scanning (a real TS scan is ~82 rules). Corollary for bash: OSS semgrep's tree-sitter bash parser matches ~0 rules, so a "0 findings" on a `.sh`-only diff is always vacuous — use `shellcheck` instead.
|
|
1501
|
-
|
|
1502
1486
|
When a PR's behavior depends on an external-API response shape (Sentry stats buckets, webhook payloads, list-vs-object envelopes, hourly-vs-daily resolution) AND the plan deferred the shape to a "soleur:work will live-probe" AC, do NOT trust a ticked "live-probed" AC or a "verified by probe" code comment — they are claims, not evidence. Grep the diff for a CAPTURED-response fixture; if the only evidence is prose, **re-probe the real endpoint yourself** (`hr-no-dashboard-eyeball-pull-data-yourself`) and assert the parser matches the captured bytes. **Why:** PR #5434 — `sentry-issue-rate` shipped reading `/issues/{id}/stats/?stat=14d` as daily buckets; the live re-probe showed 24 HOURLY buckets (~1 day) and that the daily series lives at the issue-detail `.stats["30d"]` — the shipped code would have understated the rate ~24× → spurious PASS → wrong auto-close. See `knowledge-base/project/learnings/integration-issues/2026-06-16-external-api-shape-ac-must-land-captured-fixture-not-probed-claim.md`.
|
|
1503
1487
|
|
|
1504
1488
|
**A `source`/import line only DEFINES; it never runs.** When a test asserts that a gate is wired, asserting the `source` line proves nothing — neutering the call, deleting the invocation, or putting `if: ${{ false }}` on the step all leave the suite GREEN. Assert the **invocation** (`if ! <gate_fn> …; then exit 1`) and that the step **cannot be skipped** (no step-level `if:`, no `continue-on-error`), then mutation-verify each arm RED. Generalize the question beyond "is it called": a check that cannot emit a failure — never invoked, aimed at the wrong target, silently reinterpreted by its own tooling, or hung rather than finished — is observationally identical to one that passed, and every such state presents as green or still-running, never red. **Why:** #6977 — six such mutations each left a 102/0 green suite. See `knowledge-base/project/learnings/2026-07-27-a-check-that-cannot-report-is-indistinguishable-from-one-that-passed.md`.
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Orchestrator scan receipt. Stdout is the status line, then file:line rule-id.
|
|
3
|
+
# A temp dir, when one is needed, lives under mktemp and is removed on every return.
|
|
4
|
+
|
|
5
|
+
set -u
|
|
6
|
+
|
|
7
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
8
|
+
ROOT="$(cd "$SCRIPT_DIR/../../../../.." && pwd)"
|
|
9
|
+
ENSURE="$SCRIPT_DIR/ensure-semgrep.sh"
|
|
10
|
+
TMP="$(mktemp -d)"
|
|
11
|
+
|
|
12
|
+
# The EXIT/INT/TERM trap below is the only caller. Shellcheck does not count a trap as a call.
|
|
13
|
+
# shellcheck disable=SC2329
|
|
14
|
+
cleanup() {
|
|
15
|
+
rm -rf "$TMP"
|
|
16
|
+
}
|
|
17
|
+
trap cleanup EXIT INT TERM
|
|
18
|
+
|
|
19
|
+
refuse() {
|
|
20
|
+
echo "SOLEUR_REVIEW_SCAN_GATE refuse engine=${1:-none} files=${2:-0} rules=${3:-0} findings=${4:-0}"
|
|
21
|
+
exit 1
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if [ "${1:-}" = "--probe" ]; then
|
|
25
|
+
echo "SOLEUR_REVIEW_SCAN_GATE probe"
|
|
26
|
+
exit 0
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
is_lock() {
|
|
30
|
+
case "$(basename -- "$1")" in
|
|
31
|
+
package-lock.json|bun.lock|yarn.lock|Cargo.lock|go.sum|Gemfile.lock|poetry.lock|uv.lock) return 0 ;;
|
|
32
|
+
*) return 1 ;;
|
|
33
|
+
esac
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
kind_of() {
|
|
37
|
+
local base
|
|
38
|
+
base="$(basename -- "$1")"
|
|
39
|
+
case "$base" in
|
|
40
|
+
*.sh|*.bash|*.zsh) printf 'shell\n'; return ;;
|
|
41
|
+
esac
|
|
42
|
+
case "$base" in
|
|
43
|
+
*.py|*.js|*.jsx|*.ts|*.tsx|*.mjs|*.cjs|*.rb|*.go|*.java|*.rs|*.swift|*.kt|*.kts|*.c|*.cc|*.cpp|*.h|*.hpp|*.cs|*.php|*.scala)
|
|
44
|
+
printf 'source\n'
|
|
45
|
+
return
|
|
46
|
+
;;
|
|
47
|
+
esac
|
|
48
|
+
printf 'other\n'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
is_test_path() {
|
|
52
|
+
case "$1" in
|
|
53
|
+
test/*|*/test/*) return 0 ;;
|
|
54
|
+
*) return 1 ;;
|
|
55
|
+
esac
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
line_copied_from_target() {
|
|
59
|
+
local line="$1" f
|
|
60
|
+
shift
|
|
61
|
+
for f in "$@"; do
|
|
62
|
+
[ -f "$f" ] || continue
|
|
63
|
+
if grep -Fxq -- "$line" "$f"; then
|
|
64
|
+
return 0
|
|
65
|
+
fi
|
|
66
|
+
done
|
|
67
|
+
return 1
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
summary_rules() {
|
|
71
|
+
local err="$1" rules=0 line n
|
|
72
|
+
shift
|
|
73
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
74
|
+
if [[ "$line" =~ ^Ran[[:space:]]([0-9]+)[[:space:]]rules?[[:space:]]on[[:space:]]([0-9]+)[[:space:]]files? ]]; then
|
|
75
|
+
n="${BASH_REMATCH[1]}"
|
|
76
|
+
if line_copied_from_target "$line" "$@"; then
|
|
77
|
+
continue
|
|
78
|
+
fi
|
|
79
|
+
if [ "${BASH_REMATCH[2]}" -eq 0 ]; then
|
|
80
|
+
continue
|
|
81
|
+
fi
|
|
82
|
+
rules="$n"
|
|
83
|
+
fi
|
|
84
|
+
done <"$err"
|
|
85
|
+
printf '%s\n' "$rules"
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
sources=()
|
|
89
|
+
shells=()
|
|
90
|
+
for path in "$@"; do
|
|
91
|
+
[ -f "$path" ] || continue
|
|
92
|
+
if is_lock "$path"; then
|
|
93
|
+
continue
|
|
94
|
+
fi
|
|
95
|
+
case "$(kind_of "$path")" in
|
|
96
|
+
source) sources+=("$path") ;;
|
|
97
|
+
shell) shells+=("$path") ;;
|
|
98
|
+
*) ;;
|
|
99
|
+
esac
|
|
100
|
+
done
|
|
101
|
+
|
|
102
|
+
files=$(( ${#sources[@]} + ${#shells[@]} ))
|
|
103
|
+
|
|
104
|
+
if [ "$files" -eq 0 ]; then
|
|
105
|
+
echo "SOLEUR_REVIEW_SCAN_GATE skip engine=none files=0 rules=0 findings=0"
|
|
106
|
+
exit 0
|
|
107
|
+
fi
|
|
108
|
+
|
|
109
|
+
if [ "${#sources[@]}" -gt 0 ] && [ "${#shells[@]}" -gt 0 ]; then
|
|
110
|
+
engine="mixed"
|
|
111
|
+
elif [ "${#sources[@]}" -gt 0 ]; then
|
|
112
|
+
engine="semgrep"
|
|
113
|
+
else
|
|
114
|
+
engine="shellcheck"
|
|
115
|
+
fi
|
|
116
|
+
|
|
117
|
+
TMP="$(mktemp -d)"
|
|
118
|
+
rules=0
|
|
119
|
+
findings=0
|
|
120
|
+
finding_lines=()
|
|
121
|
+
|
|
122
|
+
if [ "${#sources[@]}" -gt 0 ]; then
|
|
123
|
+
if ! bash "$ENSURE" >/dev/null 2>&1; then
|
|
124
|
+
refuse "$engine" "$files" 0 0
|
|
125
|
+
fi
|
|
126
|
+
map="$TMP/map.tsv"
|
|
127
|
+
: >"$map"
|
|
128
|
+
scan_args=()
|
|
129
|
+
need_ignore=0
|
|
130
|
+
idx=0
|
|
131
|
+
for src in "${sources[@]}"; do
|
|
132
|
+
if is_test_path "$src"; then
|
|
133
|
+
need_ignore=1
|
|
134
|
+
ext="${src##*.}"
|
|
135
|
+
copy="$TMP/scan/$idx.$ext"
|
|
136
|
+
mkdir -p "$TMP/scan"
|
|
137
|
+
cp -- "$src" "$copy"
|
|
138
|
+
printf '%s\t%s\n' "$copy" "$src" >>"$map"
|
|
139
|
+
scan_args+=("$copy")
|
|
140
|
+
idx=$((idx + 1))
|
|
141
|
+
else
|
|
142
|
+
printf '%s\t%s\n' "$src" "$src" >>"$map"
|
|
143
|
+
scan_args+=("$src")
|
|
144
|
+
fi
|
|
145
|
+
done
|
|
146
|
+
if [ "$need_ignore" -eq 1 ]; then
|
|
147
|
+
: >"$TMP/scan/.semgrepignore"
|
|
148
|
+
fi
|
|
149
|
+
sem_args=(
|
|
150
|
+
--config=auto
|
|
151
|
+
--config=p/javascript
|
|
152
|
+
--config=p/typescript
|
|
153
|
+
--config=p/owasp-top-ten
|
|
154
|
+
--config=plugins/soleur/skills/review/references/semgrep-custom-rules.yaml
|
|
155
|
+
--json
|
|
156
|
+
--error
|
|
157
|
+
)
|
|
158
|
+
if [ "$need_ignore" -eq 1 ]; then
|
|
159
|
+
sem_args+=(--no-git-ignore)
|
|
160
|
+
fi
|
|
161
|
+
out="$TMP/sem.json"
|
|
162
|
+
err="$TMP/sem.err"
|
|
163
|
+
attempt=0
|
|
164
|
+
sem_rc=0
|
|
165
|
+
while [ "$attempt" -lt 2 ]; do
|
|
166
|
+
attempt=$((attempt + 1))
|
|
167
|
+
if [ "$attempt" -eq 2 ]; then
|
|
168
|
+
( cd "$ROOT" && EIO_BACKEND=posix semgrep -j 1 "${sem_args[@]}" "${scan_args[@]}" >"$out" 2>"$err" )
|
|
169
|
+
else
|
|
170
|
+
( cd "$ROOT" && semgrep "${sem_args[@]}" "${scan_args[@]}" >"$out" 2>"$err" )
|
|
171
|
+
fi
|
|
172
|
+
sem_rc=$?
|
|
173
|
+
if [ "$attempt" -eq 1 ] && grep -q 'io_uring_queue_init: Cannot allocate memory' "$err"; then
|
|
174
|
+
continue
|
|
175
|
+
fi
|
|
176
|
+
break
|
|
177
|
+
done
|
|
178
|
+
if [ "$sem_rc" -ne 0 ] && [ "$sem_rc" -ne 1 ]; then
|
|
179
|
+
refuse "$engine" "$files" 0 0
|
|
180
|
+
fi
|
|
181
|
+
rules="$(summary_rules "$err" "${sources[@]}")"
|
|
182
|
+
if [ "$rules" -eq 0 ]; then
|
|
183
|
+
refuse "$engine" "$files" 0 0
|
|
184
|
+
fi
|
|
185
|
+
parsed="$TMP/parsed.txt"
|
|
186
|
+
if ! python3 - "$out" "$map" >"$parsed" <<'PY'
|
|
187
|
+
import json, sys
|
|
188
|
+
data = json.load(open(sys.argv[1]))
|
|
189
|
+
mapping = {}
|
|
190
|
+
for raw in open(sys.argv[2]):
|
|
191
|
+
raw = raw.rstrip("\n")
|
|
192
|
+
if not raw:
|
|
193
|
+
continue
|
|
194
|
+
src, orig = raw.split("\t", 1)
|
|
195
|
+
mapping[src] = orig
|
|
196
|
+
paths = data.get("paths") or {}
|
|
197
|
+
scanned = paths.get("scanned") or []
|
|
198
|
+
print("SCANNED")
|
|
199
|
+
for item in scanned:
|
|
200
|
+
print(mapping.get(item, item))
|
|
201
|
+
print("FINDINGS")
|
|
202
|
+
for row in data.get("results") or []:
|
|
203
|
+
path = mapping.get(row.get("path", ""), row.get("path", ""))
|
|
204
|
+
start = row.get("start") or {}
|
|
205
|
+
line = start.get("line", 0)
|
|
206
|
+
rule = row.get("check_id") or "unknown"
|
|
207
|
+
print(f"{path}:{line} {rule}")
|
|
208
|
+
PY
|
|
209
|
+
then
|
|
210
|
+
refuse "$engine" "$files" 0 0
|
|
211
|
+
fi
|
|
212
|
+
mode="wait"
|
|
213
|
+
scanned_tmp="$TMP/scanned.list"
|
|
214
|
+
: >"$scanned_tmp"
|
|
215
|
+
while IFS= read -r row || [ -n "$row" ]; do
|
|
216
|
+
if [ "$row" = "SCANNED" ]; then
|
|
217
|
+
mode="scanned"
|
|
218
|
+
continue
|
|
219
|
+
fi
|
|
220
|
+
if [ "$row" = "FINDINGS" ]; then
|
|
221
|
+
mode="findings"
|
|
222
|
+
continue
|
|
223
|
+
fi
|
|
224
|
+
if [ "$mode" = "scanned" ]; then
|
|
225
|
+
printf '%s\n' "$row" >>"$scanned_tmp"
|
|
226
|
+
elif [ "$mode" = "findings" ] && [ -n "$row" ]; then
|
|
227
|
+
finding_lines+=("$row")
|
|
228
|
+
findings=$((findings + 1))
|
|
229
|
+
fi
|
|
230
|
+
done <"$parsed"
|
|
231
|
+
for src in "${sources[@]}"; do
|
|
232
|
+
if ! grep -Fxq -- "$src" "$scanned_tmp"; then
|
|
233
|
+
refuse "$engine" "$files" "$rules" 0
|
|
234
|
+
fi
|
|
235
|
+
done
|
|
236
|
+
scanned_n="$(grep -c . "$scanned_tmp" || true)"
|
|
237
|
+
if [ "$scanned_n" -ne "${#sources[@]}" ]; then
|
|
238
|
+
refuse "$engine" "$files" "$rules" 0
|
|
239
|
+
fi
|
|
240
|
+
fi
|
|
241
|
+
|
|
242
|
+
if [ "${#shells[@]}" -gt 0 ]; then
|
|
243
|
+
if ! command -v shellcheck >/dev/null 2>&1; then
|
|
244
|
+
refuse "$engine" "$files" "$rules" 0
|
|
245
|
+
fi
|
|
246
|
+
sh_out="$TMP/sh.json"
|
|
247
|
+
sh_err="$TMP/sh.err"
|
|
248
|
+
shellcheck -f json "${shells[@]}" >"$sh_out" 2>"$sh_err"
|
|
249
|
+
sh_rc=$?
|
|
250
|
+
if [ "$sh_rc" -ne 0 ] && [ "$sh_rc" -ne 1 ]; then
|
|
251
|
+
refuse "$engine" "$files" "$rules" 0
|
|
252
|
+
fi
|
|
253
|
+
sh_parsed="$TMP/sh-parsed.txt"
|
|
254
|
+
if ! python3 - "$sh_out" >"$sh_parsed" <<'PY'
|
|
255
|
+
import json, sys
|
|
256
|
+
rows = json.load(open(sys.argv[1]))
|
|
257
|
+
for row in rows:
|
|
258
|
+
code = row.get("code")
|
|
259
|
+
rule = f"SC{code}" if isinstance(code, int) else str(code)
|
|
260
|
+
print(f"{row.get('file')}:{row.get('line')} {rule}")
|
|
261
|
+
PY
|
|
262
|
+
then
|
|
263
|
+
refuse "$engine" "$files" "$rules" 0
|
|
264
|
+
fi
|
|
265
|
+
while IFS= read -r row || [ -n "$row" ]; do
|
|
266
|
+
[ -n "$row" ] || continue
|
|
267
|
+
finding_lines+=("$row")
|
|
268
|
+
findings=$((findings + 1))
|
|
269
|
+
done <"$sh_parsed"
|
|
270
|
+
fi
|
|
271
|
+
|
|
272
|
+
echo "SOLEUR_REVIEW_SCAN_GATE ok engine=${engine} files=${files} rules=${rules} findings=${findings}"
|
|
273
|
+
if [ "${#finding_lines[@]}" -gt 0 ]; then
|
|
274
|
+
printf '%s\n' "${finding_lines[@]}"
|
|
275
|
+
fi
|
|
276
|
+
exit 0
|
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Hermetic receipt contract for review-scan-gate.sh. Stubs replace the two
|
|
3
|
+
# scanners. No network. The suite is the check for command order in the skill
|
|
4
|
+
# and the agent files as well as for the script's stdout.
|
|
5
|
+
|
|
6
|
+
set -u
|
|
7
|
+
|
|
8
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
9
|
+
REPO_ROOT="$(cd "$SCRIPT_DIR/../../../../.." && pwd)"
|
|
10
|
+
SUT="$SCRIPT_DIR/../scripts/review-scan-gate.sh"
|
|
11
|
+
SKILL="$REPO_ROOT/plugins/soleur/skills/review/SKILL.md"
|
|
12
|
+
PASS=0
|
|
13
|
+
FAIL=0
|
|
14
|
+
TOTAL=0
|
|
15
|
+
DIRS=()
|
|
16
|
+
|
|
17
|
+
assert_fixture_dir() {
|
|
18
|
+
case "${1-}" in
|
|
19
|
+
"") printf 'FATAL: fixture dir is EMPTY; git -C "" would operate on %s\n' "$PWD" >&2; exit 2 ;;
|
|
20
|
+
*/../*|*/..) printf 'FATAL: fixture dir %s contains ..; refusing\n' "$1" >&2; exit 2 ;;
|
|
21
|
+
/proc/*|/sys/*|/dev/*) printf 'FATAL: fixture dir %s is a synthetic-fs path; refusing\n' "$1" >&2; exit 2 ;;
|
|
22
|
+
/|//|/.) printf 'FATAL: fixture dir resolves to the filesystem root; refusing\n' >&2; exit 2 ;;
|
|
23
|
+
/*) : ;;
|
|
24
|
+
*) printf 'FATAL: fixture dir %s is RELATIVE; refusing\n' "$1" >&2; exit 2 ;;
|
|
25
|
+
esac
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
cleanup() {
|
|
29
|
+
local d
|
|
30
|
+
for d in "${DIRS[@]}"; do
|
|
31
|
+
[ -n "$d" ] || continue
|
|
32
|
+
assert_fixture_dir "$d"
|
|
33
|
+
rm -rf "$d"
|
|
34
|
+
done
|
|
35
|
+
}
|
|
36
|
+
trap cleanup EXIT
|
|
37
|
+
|
|
38
|
+
ok() { PASS=$((PASS + 1)); TOTAL=$((TOTAL + 1)); printf ' PASS: %s\n' "$1"; }
|
|
39
|
+
no() { FAIL=$((FAIL + 1)); TOTAL=$((TOTAL + 1)); printf ' FAIL: %s\n' "$1"; }
|
|
40
|
+
|
|
41
|
+
if [ ! -f "$SUT" ]; then
|
|
42
|
+
printf 'FAIL: %s is missing\n' "$SUT" >&2
|
|
43
|
+
exit 1
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
new_arm() {
|
|
47
|
+
local dir
|
|
48
|
+
dir="$(mktemp -d)"
|
|
49
|
+
mkdir -p "$dir/bin" "$dir/work"
|
|
50
|
+
local name src
|
|
51
|
+
for name in python3 grep mktemp cp mkdir rm cat chmod basename bash head dirname; do
|
|
52
|
+
src="$(command -v "$name" 2>/dev/null || true)"
|
|
53
|
+
if [ -n "$src" ]; then
|
|
54
|
+
ln -sf "$src" "$dir/bin/$name"
|
|
55
|
+
fi
|
|
56
|
+
done
|
|
57
|
+
printf '%s\n' "$dir"
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
write_semgrep() {
|
|
61
|
+
local arm="$1" mode="$2"
|
|
62
|
+
assert_fixture_dir "$arm"
|
|
63
|
+
cat >"$arm/bin/semgrep" <<EOF
|
|
64
|
+
#!/bin/sh
|
|
65
|
+
printf '%s\\n' "\$*" >>"$arm/semgrep.args"
|
|
66
|
+
if [ "\$1" = "--version" ]; then
|
|
67
|
+
printf '1.181.0\\n'
|
|
68
|
+
exit 0
|
|
69
|
+
fi
|
|
70
|
+
: >"$arm/targets"
|
|
71
|
+
for a in "\$@"; do
|
|
72
|
+
case "\$a" in
|
|
73
|
+
--*) ;;
|
|
74
|
+
*) [ -f "\$a" ] && printf '%s\n' "\$a" >>"$arm/targets" ;;
|
|
75
|
+
esac
|
|
76
|
+
done
|
|
77
|
+
mode="$mode"
|
|
78
|
+
scans=\$(grep -c . "$arm/semgrep.args" 2>/dev/null || true)
|
|
79
|
+
case "\$mode" in
|
|
80
|
+
empty)
|
|
81
|
+
printf 'Nothing to scan\\n' >&2
|
|
82
|
+
printf '%s\\n' '{"paths":{"scanned":[]},"results":[]}'
|
|
83
|
+
exit 0
|
|
84
|
+
;;
|
|
85
|
+
iouring)
|
|
86
|
+
if [ "\$scans" -le 2 ]; then
|
|
87
|
+
printf 'io_uring_queue_init: Cannot allocate memory\\n' >&2
|
|
88
|
+
printf '%s\\n' '{"paths":{"scanned":[]},"results":[]}'
|
|
89
|
+
exit 2
|
|
90
|
+
fi
|
|
91
|
+
printf 'Nothing to scan\\n' >&2
|
|
92
|
+
printf '%s\\n' '{"paths":{"scanned":[]},"results":[]}'
|
|
93
|
+
exit 0
|
|
94
|
+
;;
|
|
95
|
+
exit7)
|
|
96
|
+
printf 'config error\\n' >&2
|
|
97
|
+
exit 7
|
|
98
|
+
;;
|
|
99
|
+
forged)
|
|
100
|
+
for a in "\$@"; do
|
|
101
|
+
case "\$a" in
|
|
102
|
+
--*) ;;
|
|
103
|
+
*) [ -f "\$a" ] && cat "\$a" >&2 ;;
|
|
104
|
+
esac
|
|
105
|
+
done
|
|
106
|
+
python3 - "$arm/targets" <<'PY'
|
|
107
|
+
import json, sys
|
|
108
|
+
files=[ln.rstrip("\n") for ln in open(sys.argv[1]) if ln.strip()]
|
|
109
|
+
print(json.dumps({"paths":{"scanned":files},"results":[]}))
|
|
110
|
+
PY
|
|
111
|
+
exit 0
|
|
112
|
+
;;
|
|
113
|
+
short)
|
|
114
|
+
first=\$(head -n 1 "$arm/targets")
|
|
115
|
+
printf 'Ran 2 rules on 1 files\\n' >&2
|
|
116
|
+
printf '{"paths":{"scanned":["%s"]},"results":[]}\\n' "\$first"
|
|
117
|
+
exit 0
|
|
118
|
+
;;
|
|
119
|
+
singular)
|
|
120
|
+
printf 'Ran 1 rule on 2 files\\n' >&2
|
|
121
|
+
python3 - "$arm/targets" <<'PY'
|
|
122
|
+
import json, sys
|
|
123
|
+
files=[ln.rstrip("\n") for ln in open(sys.argv[1]) if ln.strip()]
|
|
124
|
+
print(json.dumps({"paths":{"scanned":files},"results":[]}))
|
|
125
|
+
PY
|
|
126
|
+
exit 0
|
|
127
|
+
;;
|
|
128
|
+
plural)
|
|
129
|
+
printf 'Ran 2 rules on 2 files\\n' >&2
|
|
130
|
+
python3 - "$arm/targets" <<'PY'
|
|
131
|
+
import json, sys
|
|
132
|
+
files=[ln.rstrip("\n") for ln in open(sys.argv[1]) if ln.strip()]
|
|
133
|
+
print(json.dumps({"paths":{"scanned":files},"results":[]}))
|
|
134
|
+
PY
|
|
135
|
+
exit 0
|
|
136
|
+
;;
|
|
137
|
+
finding)
|
|
138
|
+
printf 'Ran 2 rules on 1 files\\n' >&2
|
|
139
|
+
python3 - "$arm/targets" <<'PY'
|
|
140
|
+
import json, sys
|
|
141
|
+
files=[ln.rstrip("\n") for ln in open(sys.argv[1]) if ln.strip()]
|
|
142
|
+
path=files[0] if files else "missing.ts"
|
|
143
|
+
print(json.dumps({"paths":{"scanned":files},"results":[{"check_id":"rule.id","path":path,"start":{"line":4},"extra":{"message":"SECRETVALUE"}}]}))
|
|
144
|
+
PY
|
|
145
|
+
exit 1
|
|
146
|
+
;;
|
|
147
|
+
*)
|
|
148
|
+
printf 'unhandled mode\\n' >&2
|
|
149
|
+
exit 2
|
|
150
|
+
;;
|
|
151
|
+
esac
|
|
152
|
+
EOF
|
|
153
|
+
chmod +x "$arm/bin/semgrep"
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
write_shellcheck() {
|
|
157
|
+
local arm="$1"
|
|
158
|
+
assert_fixture_dir "$arm"
|
|
159
|
+
cat >"$arm/bin/shellcheck" <<EOF
|
|
160
|
+
#!/bin/sh
|
|
161
|
+
printf '%s\\n' "\$*" >>"$arm/shellcheck.args"
|
|
162
|
+
printf '[]\\n'
|
|
163
|
+
exit 0
|
|
164
|
+
EOF
|
|
165
|
+
chmod +x "$arm/bin/shellcheck"
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
run_gate() {
|
|
169
|
+
local arm="$1"
|
|
170
|
+
shift
|
|
171
|
+
env -i PATH="$arm/bin" HOME="$arm" /bin/bash "$SUT" "$@"
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
# --- script source uses the echo form the drift guard can see ---
|
|
175
|
+
if grep -q 'echo "SOLEUR_REVIEW_SCAN_GATE' "$SUT"; then
|
|
176
|
+
ok "script emits with echo quote"
|
|
177
|
+
else
|
|
178
|
+
no "script emits with echo quote"
|
|
179
|
+
fi
|
|
180
|
+
if grep -q "printf '%s'" "$SUT" && grep -q 'SOLEUR_REVIEW_SCAN_GATE' "$SUT"; then
|
|
181
|
+
no "printf percent-s must not be the status emitter"
|
|
182
|
+
else
|
|
183
|
+
ok "printf percent-s is not the status emitter"
|
|
184
|
+
fi
|
|
185
|
+
|
|
186
|
+
# --- probe ---
|
|
187
|
+
arm="$(new_arm)"
|
|
188
|
+
DIRS+=("$arm")
|
|
189
|
+
out="$(run_gate "$arm" --probe)"
|
|
190
|
+
rc=$?
|
|
191
|
+
if [ "$rc" -eq 0 ] && [ "$out" = "SOLEUR_REVIEW_SCAN_GATE probe" ]; then
|
|
192
|
+
ok "probe prints the probe token and exits 0"
|
|
193
|
+
else
|
|
194
|
+
no "probe prints the probe token and exits 0 (rc=$rc out=$out)"
|
|
195
|
+
fi
|
|
196
|
+
if [ -s "$arm/semgrep.args" ]; then
|
|
197
|
+
no "probe must not scan"
|
|
198
|
+
else
|
|
199
|
+
ok "probe does not scan"
|
|
200
|
+
fi
|
|
201
|
+
|
|
202
|
+
# --- docs only skip ---
|
|
203
|
+
arm="$(new_arm)"
|
|
204
|
+
DIRS+=("$arm")
|
|
205
|
+
printf '# doc\n' >"$arm/work/readme.md"
|
|
206
|
+
out="$(run_gate "$arm" "$arm/work/readme.md")"
|
|
207
|
+
rc=$?
|
|
208
|
+
if [ "$rc" -eq 0 ] && [ "$out" = "SOLEUR_REVIEW_SCAN_GATE skip engine=none files=0 rules=0 findings=0" ]; then
|
|
209
|
+
ok "docs-only list skips"
|
|
210
|
+
else
|
|
211
|
+
no "docs-only list skips (rc=$rc out=$out)"
|
|
212
|
+
fi
|
|
213
|
+
|
|
214
|
+
# --- lockfile beside one source file: files=1 ---
|
|
215
|
+
arm="$(new_arm)"
|
|
216
|
+
DIRS+=("$arm")
|
|
217
|
+
write_semgrep "$arm" plural
|
|
218
|
+
printf 'export const n = 1;\n' >"$arm/work/a.ts"
|
|
219
|
+
printf '{}\n' >"$arm/work/package-lock.json"
|
|
220
|
+
out="$(run_gate "$arm" "$arm/work/a.ts" "$arm/work/package-lock.json")"
|
|
221
|
+
rc=$?
|
|
222
|
+
first="$(printf '%s\n' "$out" | head -n 1)"
|
|
223
|
+
if [ "$rc" -eq 0 ] && [ "$first" = "SOLEUR_REVIEW_SCAN_GATE ok engine=semgrep files=1 rules=2 findings=0" ]; then
|
|
224
|
+
ok "lockfile does not increment files"
|
|
225
|
+
else
|
|
226
|
+
no "lockfile does not increment files (rc=$rc line=$first)"
|
|
227
|
+
fi
|
|
228
|
+
|
|
229
|
+
# --- singular summary ---
|
|
230
|
+
arm="$(new_arm)"
|
|
231
|
+
DIRS+=("$arm")
|
|
232
|
+
write_semgrep "$arm" singular
|
|
233
|
+
printf 'export const a = 1;\n' >"$arm/work/a.ts"
|
|
234
|
+
printf 'export const b = 2;\n' >"$arm/work/b.ts"
|
|
235
|
+
out="$(run_gate "$arm" "$arm/work/a.ts" "$arm/work/b.ts")"
|
|
236
|
+
rc=$?
|
|
237
|
+
first="$(printf '%s\n' "$out" | head -n 1)"
|
|
238
|
+
if [ "$rc" -eq 0 ] && [ "$first" = "SOLEUR_REVIEW_SCAN_GATE ok engine=semgrep files=2 rules=1 findings=0" ]; then
|
|
239
|
+
ok "singular Ran 1 rule receipts ok"
|
|
240
|
+
else
|
|
241
|
+
no "singular Ran 1 rule receipts ok (rc=$rc line=$first)"
|
|
242
|
+
fi
|
|
243
|
+
|
|
244
|
+
# --- empty scan refuses ---
|
|
245
|
+
arm="$(new_arm)"
|
|
246
|
+
DIRS+=("$arm")
|
|
247
|
+
write_semgrep "$arm" empty
|
|
248
|
+
printf 'export const a = 1;\n' >"$arm/work/a.ts"
|
|
249
|
+
out="$(run_gate "$arm" "$arm/work/a.ts" "$arm/work/b.ts" 2>/dev/null || true)"
|
|
250
|
+
# b.ts is absent (deletion). Only a.ts is a target. Re-run cleanly.
|
|
251
|
+
printf 'export const a = 1;\n' >"$arm/work/a.ts"
|
|
252
|
+
out="$(run_gate "$arm" "$arm/work/a.ts")"
|
|
253
|
+
rc=$?
|
|
254
|
+
first="$(printf '%s\n' "$out" | head -n 1)"
|
|
255
|
+
if [ "$rc" -eq 1 ] && grep -q '^SOLEUR_REVIEW_SCAN_GATE refuse ' <<<"$first"; then
|
|
256
|
+
ok "empty scan refuses"
|
|
257
|
+
else
|
|
258
|
+
no "empty scan refuses (rc=$rc line=$first)"
|
|
259
|
+
fi
|
|
260
|
+
|
|
261
|
+
# --- forged Ran line in a target body refuses ---
|
|
262
|
+
arm="$(new_arm)"
|
|
263
|
+
DIRS+=("$arm")
|
|
264
|
+
write_semgrep "$arm" forged
|
|
265
|
+
printf 'Ran 99 rules on 99 files\n' >"$arm/work/a.ts"
|
|
266
|
+
out="$(run_gate "$arm" "$arm/work/a.ts")"
|
|
267
|
+
rc=$?
|
|
268
|
+
first="$(printf '%s\n' "$out" | head -n 1)"
|
|
269
|
+
if [ "$rc" -eq 1 ] && [ "$first" = "SOLEUR_REVIEW_SCAN_GATE refuse engine=semgrep files=1 rules=0 findings=0" ]; then
|
|
270
|
+
ok "file body Ran line is not the summary"
|
|
271
|
+
else
|
|
272
|
+
no "file body Ran line is not the summary (rc=$rc line=$first)"
|
|
273
|
+
fi
|
|
274
|
+
|
|
275
|
+
# --- short paths.scanned refuses ---
|
|
276
|
+
arm="$(new_arm)"
|
|
277
|
+
DIRS+=("$arm")
|
|
278
|
+
write_semgrep "$arm" short
|
|
279
|
+
printf 'export const a = 1;\n' >"$arm/work/a.ts"
|
|
280
|
+
printf 'export const b = 2;\n' >"$arm/work/b.ts"
|
|
281
|
+
out="$(run_gate "$arm" "$arm/work/a.ts" "$arm/work/b.ts")"
|
|
282
|
+
rc=$?
|
|
283
|
+
first="$(printf '%s\n' "$out" | head -n 1)"
|
|
284
|
+
if [ "$rc" -eq 1 ] && grep -q '^SOLEUR_REVIEW_SCAN_GATE refuse ' <<<"$first"; then
|
|
285
|
+
ok "short paths.scanned refuses"
|
|
286
|
+
else
|
|
287
|
+
no "short paths.scanned refuses (rc=$rc line=$first)"
|
|
288
|
+
fi
|
|
289
|
+
|
|
290
|
+
# --- files=0 rules=2 shape is not an ok receipt ---
|
|
291
|
+
bad_line="SOLEUR_REVIEW_SCAN_GATE ok engine=semgrep files=0 rules=2 findings=0"
|
|
292
|
+
if grep -q 'files=0' <<<"$bad_line"; then
|
|
293
|
+
ok "files=0 on an ok semgrep line is a rejected shape"
|
|
294
|
+
else
|
|
295
|
+
no "files=0 on an ok semgrep line is a rejected shape"
|
|
296
|
+
fi
|
|
297
|
+
|
|
298
|
+
# --- a non-ts source suffix is still a target ---
|
|
299
|
+
arm="$(new_arm)"
|
|
300
|
+
DIRS+=("$arm")
|
|
301
|
+
write_semgrep "$arm" plural
|
|
302
|
+
printf 'export const a = 1;\n' >"$arm/work/a.ts"
|
|
303
|
+
printf 'export const b = 1;\n' >"$arm/work/b.js"
|
|
304
|
+
out="$(run_gate "$arm" "$arm/work/a.ts" "$arm/work/b.js")"
|
|
305
|
+
rc=$?
|
|
306
|
+
first="$(printf '%s\n' "$out" | head -n 1)"
|
|
307
|
+
if [ "$rc" -eq 0 ] && [ "$first" = "SOLEUR_REVIEW_SCAN_GATE ok engine=semgrep files=2 rules=2 findings=0" ]; then
|
|
308
|
+
ok "js suffix counts as a source target"
|
|
309
|
+
else
|
|
310
|
+
no "js suffix counts as a source target (rc=$rc line=$first)"
|
|
311
|
+
fi
|
|
312
|
+
|
|
313
|
+
# --- test/ copy maps back to ok ---
|
|
314
|
+
arm="$(new_arm)"
|
|
315
|
+
DIRS+=("$arm")
|
|
316
|
+
write_semgrep "$arm" plural
|
|
317
|
+
mkdir -p "$arm/work/test"
|
|
318
|
+
printf 'export const t = 1;\n' >"$arm/work/test/t.ts"
|
|
319
|
+
out="$(run_gate "$arm" "$arm/work/test/t.ts")"
|
|
320
|
+
rc=$?
|
|
321
|
+
first="$(printf '%s\n' "$out" | head -n 1)"
|
|
322
|
+
if [ "$rc" -eq 0 ] && [ "$first" = "SOLEUR_REVIEW_SCAN_GATE ok engine=semgrep files=1 rules=2 findings=0" ]; then
|
|
323
|
+
ok "mapped test path receipts ok"
|
|
324
|
+
else
|
|
325
|
+
no "mapped test path receipts ok (rc=$rc line=$first)"
|
|
326
|
+
fi
|
|
327
|
+
if grep -q -- '--no-git-ignore' "$arm/semgrep.args"; then
|
|
328
|
+
ok "test path uses the ignore workaround"
|
|
329
|
+
else
|
|
330
|
+
no "test path uses the ignore workaround"
|
|
331
|
+
fi
|
|
332
|
+
if grep -q "$arm/work/test/t.ts" "$arm/semgrep.args"; then
|
|
333
|
+
no "test path must be scanned as a copy"
|
|
334
|
+
else
|
|
335
|
+
ok "test path is scanned as a copy"
|
|
336
|
+
fi
|
|
337
|
+
|
|
338
|
+
# --- two test files must both be scanned ---
|
|
339
|
+
arm="$(new_arm)"
|
|
340
|
+
DIRS+=("$arm")
|
|
341
|
+
write_semgrep "$arm" plural
|
|
342
|
+
mkdir -p "$arm/work/test"
|
|
343
|
+
printf 'export const t = 1;\n' >"$arm/work/test/t.ts"
|
|
344
|
+
printf 'export const u = 2;\n' >"$arm/work/test/u.ts"
|
|
345
|
+
out="$(run_gate "$arm" "$arm/work/test/t.ts" "$arm/work/test/u.ts")"
|
|
346
|
+
rc=$?
|
|
347
|
+
first="$(printf '%s\n' "$out" | head -n 1)"
|
|
348
|
+
if [ "$rc" -eq 0 ] && [ "$first" = "SOLEUR_REVIEW_SCAN_GATE ok engine=semgrep files=2 rules=2 findings=0" ]; then
|
|
349
|
+
ok "both test files map back"
|
|
350
|
+
else
|
|
351
|
+
no "both test files map back (rc=$rc line=$first)"
|
|
352
|
+
fi
|
|
353
|
+
arm="$(new_arm)"
|
|
354
|
+
DIRS+=("$arm")
|
|
355
|
+
write_semgrep "$arm" short
|
|
356
|
+
mkdir -p "$arm/work/test"
|
|
357
|
+
printf 'export const t = 1;\n' >"$arm/work/test/t.ts"
|
|
358
|
+
printf 'export const u = 2;\n' >"$arm/work/test/u.ts"
|
|
359
|
+
out="$(run_gate "$arm" "$arm/work/test/t.ts" "$arm/work/test/u.ts")"
|
|
360
|
+
rc=$?
|
|
361
|
+
first="$(printf '%s\n' "$out" | head -n 1)"
|
|
362
|
+
if [ "$rc" -eq 1 ] && grep -q '^SOLEUR_REVIEW_SCAN_GATE refuse ' <<<"$first"; then
|
|
363
|
+
ok "a short test-file scan refuses"
|
|
364
|
+
else
|
|
365
|
+
no "a short test-file scan refuses (rc=$rc line=$first)"
|
|
366
|
+
fi
|
|
367
|
+
|
|
368
|
+
# --- exit 7 refuses ---
|
|
369
|
+
arm="$(new_arm)"
|
|
370
|
+
DIRS+=("$arm")
|
|
371
|
+
write_semgrep "$arm" exit7
|
|
372
|
+
printf 'export const a = 1;\n' >"$arm/work/a.ts"
|
|
373
|
+
out="$(run_gate "$arm" "$arm/work/a.ts")"
|
|
374
|
+
rc=$?
|
|
375
|
+
first="$(printf '%s\n' "$out" | head -n 1)"
|
|
376
|
+
if [ "$rc" -eq 1 ] && grep -q '^SOLEUR_REVIEW_SCAN_GATE refuse ' <<<"$first"; then
|
|
377
|
+
ok "semgrep exit 7 refuses"
|
|
378
|
+
else
|
|
379
|
+
no "semgrep exit 7 refuses (rc=$rc line=$first)"
|
|
380
|
+
fi
|
|
381
|
+
|
|
382
|
+
# --- io_uring retry still empty refuses, and the retry happened ---
|
|
383
|
+
arm="$(new_arm)"
|
|
384
|
+
DIRS+=("$arm")
|
|
385
|
+
write_semgrep "$arm" iouring
|
|
386
|
+
printf 'export const a = 1;\n' >"$arm/work/a.ts"
|
|
387
|
+
out="$(run_gate "$arm" "$arm/work/a.ts")"
|
|
388
|
+
rc=$?
|
|
389
|
+
first="$(printf '%s\n' "$out" | head -n 1)"
|
|
390
|
+
scan_lines="$(grep -c -- '--json' "$arm/semgrep.args" || true)"
|
|
391
|
+
if [ "$rc" -eq 1 ] && grep -q '^SOLEUR_REVIEW_SCAN_GATE refuse ' <<<"$first" && [ "$scan_lines" -ge 2 ]; then
|
|
392
|
+
ok "io_uring retry that stays empty refuses"
|
|
393
|
+
else
|
|
394
|
+
no "io_uring retry that stays empty refuses (rc=$rc scans=$scan_lines line=$first)"
|
|
395
|
+
fi
|
|
396
|
+
|
|
397
|
+
# --- finding line has no matched source ---
|
|
398
|
+
arm="$(new_arm)"
|
|
399
|
+
DIRS+=("$arm")
|
|
400
|
+
write_semgrep "$arm" finding
|
|
401
|
+
printf 'export const secret = "SECRETVALUE";\n' >"$arm/work/a.ts"
|
|
402
|
+
out="$(run_gate "$arm" "$arm/work/a.ts")"
|
|
403
|
+
rc=$?
|
|
404
|
+
first="$(printf '%s\n' "$out" | head -n 1)"
|
|
405
|
+
second="$(printf '%s\n' "$out" | sed -n '2p')"
|
|
406
|
+
if [ "$rc" -eq 0 ] && [ "$first" = "SOLEUR_REVIEW_SCAN_GATE ok engine=semgrep files=1 rules=2 findings=1" ] && [ "$second" = "$arm/work/a.ts:4 rule.id" ] && ! grep -q 'SECRETVALUE' <<<"$out"; then
|
|
407
|
+
ok "findings are file:line rule-id and do not stop"
|
|
408
|
+
else
|
|
409
|
+
no "findings are file:line rule-id and do not stop (rc=$rc out=$out)"
|
|
410
|
+
fi
|
|
411
|
+
|
|
412
|
+
# --- shellcheck not executed refuses ---
|
|
413
|
+
arm="$(new_arm)"
|
|
414
|
+
DIRS+=("$arm")
|
|
415
|
+
printf 'echo hi\n' >"$arm/work/a.sh"
|
|
416
|
+
out="$(run_gate "$arm" "$arm/work/a.sh")"
|
|
417
|
+
rc=$?
|
|
418
|
+
first="$(printf '%s\n' "$out" | head -n 1)"
|
|
419
|
+
if [ "$rc" -eq 1 ] && grep -q '^SOLEUR_REVIEW_SCAN_GATE refuse ' <<<"$first"; then
|
|
420
|
+
ok "shell-only without shellcheck refuses"
|
|
421
|
+
else
|
|
422
|
+
no "shell-only without shellcheck refuses (rc=$rc line=$first)"
|
|
423
|
+
fi
|
|
424
|
+
|
|
425
|
+
# --- shellcheck executed receipts ok rules=0 ---
|
|
426
|
+
arm="$(new_arm)"
|
|
427
|
+
DIRS+=("$arm")
|
|
428
|
+
write_shellcheck "$arm"
|
|
429
|
+
printf 'echo hi\n' >"$arm/work/a.sh"
|
|
430
|
+
out="$(run_gate "$arm" "$arm/work/a.sh")"
|
|
431
|
+
rc=$?
|
|
432
|
+
first="$(printf '%s\n' "$out" | head -n 1)"
|
|
433
|
+
if [ "$rc" -eq 0 ] && [ "$first" = "SOLEUR_REVIEW_SCAN_GATE ok engine=shellcheck files=1 rules=0 findings=0" ] && grep -q "$arm/work/a.sh" "$arm/shellcheck.args"; then
|
|
434
|
+
ok "shellcheck argv includes the shell target"
|
|
435
|
+
else
|
|
436
|
+
no "shellcheck argv includes the shell target (rc=$rc line=$first)"
|
|
437
|
+
fi
|
|
438
|
+
|
|
439
|
+
# --- mixed without shellcheck refuses ---
|
|
440
|
+
arm="$(new_arm)"
|
|
441
|
+
DIRS+=("$arm")
|
|
442
|
+
write_semgrep "$arm" plural
|
|
443
|
+
printf 'export const a = 1;\n' >"$arm/work/a.ts"
|
|
444
|
+
printf 'echo hi\n' >"$arm/work/a.sh"
|
|
445
|
+
out="$(run_gate "$arm" "$arm/work/a.ts" "$arm/work/a.sh")"
|
|
446
|
+
rc=$?
|
|
447
|
+
first="$(printf '%s\n' "$out" | head -n 1)"
|
|
448
|
+
if [ "$rc" -eq 1 ] && grep -q '^SOLEUR_REVIEW_SCAN_GATE refuse ' <<<"$first"; then
|
|
449
|
+
ok "mixed range without shellcheck refuses"
|
|
450
|
+
else
|
|
451
|
+
no "mixed range without shellcheck refuses (rc=$rc line=$first)"
|
|
452
|
+
fi
|
|
453
|
+
|
|
454
|
+
# --- skill command order ---
|
|
455
|
+
script_line="$(grep -n 'review-scan-gate.sh' "$SKILL" | head -n 1 | cut -d: -f1)"
|
|
456
|
+
task_line="$(grep -n 'Task soleur:' "$SKILL" | head -n 1 | cut -d: -f1)"
|
|
457
|
+
if [ -n "$script_line" ] && [ -n "$task_line" ] && [ "$script_line" -lt "$task_line" ]; then
|
|
458
|
+
ok "skill runs the script before the first seat"
|
|
459
|
+
else
|
|
460
|
+
no "skill runs the script before the first seat (script=$script_line task=$task_line)"
|
|
461
|
+
fi
|
|
462
|
+
if grep -q 'design-validity' "$SKILL" && grep -q 'SOLEUR_REVIEW_SCAN_GATE' "$SKILL" && grep -q 'fix range' "$SKILL"; then
|
|
463
|
+
ok "skill names the design-validity pass, the receipt, and the fix range"
|
|
464
|
+
else
|
|
465
|
+
no "skill names the design-validity pass, the receipt, and the fix range"
|
|
466
|
+
fi
|
|
467
|
+
if grep -q 'shellcheck seat' "$SKILL"; then
|
|
468
|
+
ok "skill tells the shellcheck seat to quote the receipt"
|
|
469
|
+
else
|
|
470
|
+
no "skill tells the shellcheck seat to quote the receipt"
|
|
471
|
+
fi
|
|
472
|
+
|
|
473
|
+
# --- agents ---
|
|
474
|
+
canon="$REPO_ROOT/plugins/soleur/agents/engineering/review/semgrep-sast.md"
|
|
475
|
+
cursor="$REPO_ROOT/plugins/soleur/cursor/agents/soleur-engineering-review-semgrep-sast.md"
|
|
476
|
+
opencode="$REPO_ROOT/plugins/soleur/opencode/agents/engineering/review/semgrep-sast.md"
|
|
477
|
+
sentinel="$REPO_ROOT/plugins/soleur/agents/engineering/review/security-sentinel.md"
|
|
478
|
+
if grep -q 'receipt' "$canon" && ! grep -q 'bootstrapped semgrep' "$canon" && ! grep -q -- '--config=p/javascript' "$canon"; then
|
|
479
|
+
ok "canonical seat reports the receipt and does not run semgrep"
|
|
480
|
+
else
|
|
481
|
+
no "canonical seat reports the receipt and does not run semgrep"
|
|
482
|
+
fi
|
|
483
|
+
if grep -q 'receipt' "$cursor" && ! grep -q 'bootstrapped semgrep' "$cursor" && grep -q 'receipt' "$opencode" && ! grep -q 'bootstrapped semgrep' "$opencode"; then
|
|
484
|
+
ok "cursor and opencode descriptions no longer say the seat runs semgrep"
|
|
485
|
+
else
|
|
486
|
+
no "cursor and opencode descriptions no longer say the seat runs semgrep"
|
|
487
|
+
fi
|
|
488
|
+
if grep -q 'findings=0' "$sentinel"; then
|
|
489
|
+
ok "security-sentinel requires the ok receipt"
|
|
490
|
+
else
|
|
491
|
+
no "security-sentinel requires the ok receipt"
|
|
492
|
+
fi
|
|
493
|
+
phrase='classified source-and-shell count'
|
|
494
|
+
if grep -q "$phrase" "$SKILL" && grep -q "$phrase" "$sentinel" && grep -q "$phrase" "$canon"; then
|
|
495
|
+
ok "zero-finding claim names the classified count"
|
|
496
|
+
else
|
|
497
|
+
no "zero-finding claim names the classified count"
|
|
498
|
+
fi
|
|
499
|
+
|
|
500
|
+
# --- marker registration ---
|
|
501
|
+
marker="$REPO_ROOT/apps/web-platform/server/git-lock-marker-telemetry.ts"
|
|
502
|
+
if grep -q 'SOLEUR_REVIEW_SCAN_GATE' "$marker" && grep -q 'createGitLockMarkerHook' "$marker" && ! grep -q 'SOLEUR_REVIEW_SCAN_GATE' <(awk '/const WEDGE_RE/,/;/' "$marker"); then
|
|
503
|
+
ok "marker is mirrored and not paged"
|
|
504
|
+
else
|
|
505
|
+
no "marker is mirrored and not paged"
|
|
506
|
+
fi
|
|
507
|
+
|
|
508
|
+
# --- workflow stays unwired ---
|
|
509
|
+
workflow="$REPO_ROOT/plugins/soleur/skills/review/workflows/review.workflow.js"
|
|
510
|
+
if grep -q 'review-scan-gate.sh' "$workflow"; then
|
|
511
|
+
no "workflow must stay unwired"
|
|
512
|
+
else
|
|
513
|
+
ok "workflow stays unwired"
|
|
514
|
+
fi
|
|
515
|
+
|
|
516
|
+
printf '\n=== review-scan-gate.test.sh: %s passed, %s failed (%s assertions) ===\n' "$PASS" "$FAIL" "$TOTAL"
|
|
517
|
+
[ "$FAIL" -eq 0 ]
|