Skip to content

Commit 03e092b

Browse files
authored
fix(ci): validate submissions against the checked-out PR merge (#197)
* fix(ci): validate submissions against the PR event base * fix(ci): compare the PR merge with its actual first parent
1 parent 5578ebe commit 03e092b

5 files changed

Lines changed: 91 additions & 16 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,5 @@ jobs:
135135
- name: Test runtime update branch push
136136
run: node --test scripts/push-runtime-tool-update-branch.test.mjs
137137

138-
- name: Test Security Signals publishing
139-
run: node --test scripts/publish-security-signals-results.test.mjs
138+
- name: Test Security Signals publishing and validation
139+
run: node --test scripts/publish-security-signals-results.test.mjs scripts/validate-security-signals-submissions.test.mjs

‎.github/workflows/security-signals-submissions.yml‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,21 @@ jobs:
1818
validate:
1919
name: Validate submissions
2020
runs-on: ubuntu-latest
21+
env:
22+
# GitHub may build the PR merge against a newer base than the event payload names.
23+
CLAWSCAN_SUBMISSION_BASE: HEAD^1
2124
steps:
2225
- name: Checkout
2326
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2427
with:
25-
fetch-depth: 0
28+
fetch-depth: 2
2629

27-
# Checkout uses the PR merge commit. An unavailable base falls through to validation.
2830
- name: Check for submission changes
2931
id: submissions
30-
env:
31-
BASE_SHA: ${{ github.event.pull_request.base.sha }}
3232
run: |
33-
if git diff --quiet "$BASE_SHA" HEAD -- leaderboard/submissions; then
33+
# Require a PR merge before treating the first parent as its base.
34+
git rev-parse --verify HEAD^2 >/dev/null
35+
if git diff --quiet "$CLAWSCAN_SUBMISSION_BASE" HEAD -- leaderboard/submissions; then
3436
echo "unchanged=true" >> "$GITHUB_OUTPUT"
3537
echo "No Security Signals submissions changed." >> "$GITHUB_STEP_SUMMARY"
3638
fi

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- CI builds the full npm bundle on Linux and checks both Darwin architectures on macOS, avoiding four repeated cross-platform builds per run.
1313
- Refresh Node setup to 7.1.0, use Node 24.22.2 for CI and docs, and Node 26.13.0 for release packaging.
1414
- ClawSweeper skips ineligible issue and comment events before allocating a runner and handles eligible events on a single CPU.
15+
- Security Signals PR validation checks changed submissions against the checked-out merge's base and reports a failed Git comparison.
1516

1617
- **Breaking for plugin targets:** add the plugin-only `aig-mcp` scanner (Tencent A.I.G `aig-mcp-scan` 0.2.0, patched in the runtime image to allow only confined read-only tools, refuse model-chosen MCP destinations and fail unusable reports) and the profile field `pluginScanners`. The `clawhub` profile now runs only `aig-mcp` for OpenClaw plugins, over a bounded copy without `node_modules`; skills keep `skillspector` and `aig`. Consumers that read `scanners.skillspector` or `scanners.aig` for plugin runs must read `scanners["aig-mcp"]` instead. Host runs need `AIG_MCP_SCAN_ALLOW_HOST_EXEC=1` ([#149](https://github.com/openclaw/clawscan/pull/149)).
1718
- **Breaking:** the `clawhub` and `clawhub-aig` profiles take their verdict from the OpenAI Decisions API (`gpt-6-luna`) through the new `clawscan-decisions-judge` command in the runtime image, and add a Codex `gpt-6-luna` low-effort overview step for readable prose. `judge.result` now holds typed fields only: `verdict`, `confidence`, `dimensions.<name>.status`/`.confidence`, `scan_findings_in_context[]` (`ruleId`, `scanner`, `expected_for_purpose`, `probability`), and a new `decision` object with the model, usage, latency, verdict probabilities, and risk-signal probabilities. `summary`, dimension `detail`, finding `note`, and `user_guidance` move to the new top-level `overview.result`. Refusals, HTTP errors, and oversized input fail the judge with the real error.

‎scripts/validate-security-signals-submissions.sh‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,27 @@ find_all_submission_dirs() {
8181

8282
find_changed_submission_dirs() {
8383
local base_ref="${GITHUB_BASE_REF:-}"
84-
if [ -z "$base_ref" ]; then
84+
local comparison
85+
if [ -n "${CLAWSCAN_SUBMISSION_BASE:-}" ]; then
86+
comparison="$CLAWSCAN_SUBMISSION_BASE..HEAD"
87+
elif [ -n "$base_ref" ] && git fetch --no-tags --depth=1 origin "$base_ref"; then
88+
comparison="FETCH_HEAD...HEAD"
89+
else
8590
find_all_submission_dirs
8691
return
8792
fi
88-
git fetch --no-tags --depth=1 origin "$base_ref" >/dev/null 2>&1 || true
89-
local base="origin/$base_ref"
90-
if ! git rev-parse --verify "$base" >/dev/null 2>&1; then
91-
find_all_submission_dirs
92-
return
93-
fi
94-
while IFS= read -r file; do
93+
94+
# Complete the diff before treating an empty path list as a successful check.
95+
changed_paths="$(mktemp)"
96+
trap 'rm -f "$changed_paths"' EXIT
97+
git diff --name-only -z "$comparison" -- "$submission_root" > "$changed_paths"
98+
while IFS= read -r -d '' file; do
9599
case "$file" in
96100
"$submission_root"/*/*)
97101
add_submission_dir "$(dirname "$file")"
98102
;;
99103
esac
100-
done < <(git diff --name-only "$base"...HEAD -- "$submission_root" || true)
104+
done < "$changed_paths"
101105
}
102106

103107
if [ "${#explicit_dirs[@]}" -gt 0 ]; then
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import assert from 'node:assert/strict';
2+
import { execFileSync, spawnSync } from 'node:child_process';
3+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
4+
import { tmpdir } from 'node:os';
5+
import { join } from 'node:path';
6+
import test from 'node:test';
7+
import { fileURLToPath } from 'node:url';
8+
9+
const script = fileURLToPath(new URL('./validate-security-signals-submissions.sh', import.meta.url));
10+
11+
test('selects only the PR changes when the checked-out merge has a newer base', (t) => {
12+
const root = mkdtempSync(join(tmpdir(), 'clawscan-submission-base-'));
13+
t.after(() => rmSync(root, { recursive: true, force: true }));
14+
const source = join(root, 'source');
15+
const checkout = join(root, 'checkout');
16+
mkdirSync(source);
17+
mkdirSync(checkout);
18+
const env = {
19+
PATH: process.env.PATH,
20+
HOME: root,
21+
GIT_CONFIG_NOSYSTEM: '1',
22+
GIT_AUTHOR_NAME: 'Fixture',
23+
GIT_AUTHOR_EMAIL: 'fixture@example.com',
24+
GIT_COMMITTER_NAME: 'Fixture',
25+
GIT_COMMITTER_EMAIL: 'fixture@example.com',
26+
};
27+
const git = (cwd, ...args) => execFileSync('git', args, { cwd, env, encoding: 'utf8' }).trim();
28+
git(source, 'init', '-q', '-b', 'main');
29+
const changed = 'leaderboard/submissions/changed entry';
30+
const unchanged = 'leaderboard/submissions/base-only';
31+
for (const dir of [changed, unchanged]) {
32+
mkdirSync(join(source, dir), { recursive: true });
33+
writeFileSync(join(source, dir, 'metadata.json'), '{}\n');
34+
writeFileSync(join(source, dir, 'predictions.jsonl'), '{}\n');
35+
}
36+
git(source, 'add', '.');
37+
git(source, 'commit', '-qm', 'initial submissions');
38+
const eventBase = git(source, 'rev-parse', 'HEAD');
39+
git(source, 'checkout', '-qb', 'pr');
40+
writeFileSync(join(source, changed, 'predictions.jsonl'), '{"pr":true}\n');
41+
git(source, 'commit', '-qam', 'change submission');
42+
git(source, 'checkout', '-q', 'main');
43+
writeFileSync(join(source, unchanged, 'metadata.json'), '{"base":true}\n');
44+
git(source, 'commit', '-qam', 'advance base');
45+
const base = git(source, 'rev-parse', 'HEAD');
46+
git(source, 'merge', '-q', '--no-ff', '-m', 'PR merge', 'pr');
47+
48+
git(checkout, 'init', '-q');
49+
git(checkout, 'fetch', '-q', '--depth=2', source, 'main');
50+
git(checkout, 'checkout', '-q', '--detach', 'FETCH_HEAD');
51+
assert.equal(git(checkout, 'rev-parse', '--is-shallow-repository'), 'true');
52+
assert.equal(git(checkout, 'rev-parse', 'HEAD^1'), base);
53+
assert.notEqual(spawnSync('git', ['cat-file', '-e', eventBase], { cwd: checkout, env }).status, 0);
54+
function validate(baseRef) {
55+
return spawnSync('bash', [script], {
56+
cwd: checkout, encoding: 'utf8',
57+
env: { ...env, GITHUB_BASE_REF: 'main', CLAWSCAN_SUBMISSION_BASE: baseRef, CLAWSCAN_VALIDATE_SUBMISSION_CMD: 'true' },
58+
});
59+
}
60+
const result = validate('HEAD^1');
61+
assert.equal(result.status, 0, result.stderr);
62+
assert.deepEqual(result.stdout.split('\n').filter((line) => line.startsWith('Validating ')), [`Validating ${changed}`]);
63+
assert.equal(result.stderr, '');
64+
65+
const missing = validate(eventBase);
66+
assert.notEqual(missing.status, 0);
67+
assert.doesNotMatch(missing.stdout, /No Security Signals submissions changed/);
68+
});

0 commit comments

Comments
 (0)