|
27 | 27 | exit 1 |
28 | 28 | fi |
29 | 29 |
|
30 | | -# 3. Run SARIF with --sarif-reachability all |
31 | | -socketcli \ |
32 | | - --target-path tests/e2e/fixtures/simple-npm \ |
33 | | - --reach \ |
34 | | - --sarif-file /tmp/sarif-all.sarif \ |
35 | | - --sarif-scope full \ |
36 | | - --sarif-reachability all \ |
37 | | - --disable-blocking \ |
38 | | - 2>/dev/null |
| 30 | +FACTS_PATH="tests/e2e/fixtures/simple-npm/.socket.facts.json" |
| 31 | +if [ ! -f "$FACTS_PATH" ]; then |
| 32 | + echo "FAIL: Expected reachability facts at $FACTS_PATH after initial scan" |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | +echo "PASS: Reachability facts file present at $FACTS_PATH" |
| 36 | + |
| 37 | +# 3-4. Build SARIF from the facts file produced by the initial --reach run. |
| 38 | +# Avoid re-running reach + full scan here; duplicate API scans are slow and flaky in CI. |
| 39 | +uv run python -c " |
| 40 | +import json |
| 41 | +from pathlib import Path |
39 | 42 |
|
40 | | -# 4. Run SARIF with --sarif-reachability reachable (filtered) |
41 | | -socketcli \ |
42 | | - --target-path tests/e2e/fixtures/simple-npm \ |
43 | | - --reach \ |
44 | | - --sarif-file /tmp/sarif-reachable.sarif \ |
45 | | - --sarif-scope full \ |
46 | | - --sarif-reachability reachable \ |
47 | | - --disable-blocking \ |
48 | | - 2>/dev/null |
| 43 | +from socketsecurity.core.alert_selection import load_components_with_alerts |
| 44 | +from socketsecurity.core.messages import Messages |
| 45 | +
|
| 46 | +target = 'tests/e2e/fixtures/simple-npm' |
| 47 | +facts_file = '.socket.facts.json' |
| 48 | +components = load_components_with_alerts(target, facts_file) |
| 49 | +if not components: |
| 50 | + raise SystemExit('FAIL: no components with alerts in .socket.facts.json') |
| 51 | +
|
| 52 | +for outfile, reach_filter in [ |
| 53 | + ('/tmp/sarif-all.sarif', 'all'), |
| 54 | + ('/tmp/sarif-reachable.sarif', 'reachable'), |
| 55 | +]: |
| 56 | + sarif = Messages.create_security_comment_sarif_from_facts( |
| 57 | + components, |
| 58 | + reachability_filter=reach_filter, |
| 59 | + grouping='instance', |
| 60 | + ) |
| 61 | + Path(outfile).write_text(json.dumps(sarif, indent=2)) |
| 62 | + count = len(sarif['runs'][0]['results']) |
| 63 | + print(f'PASS: Wrote {outfile} ({count} results, filter={reach_filter})') |
| 64 | +" |
49 | 65 |
|
50 | 66 | # 5. Verify reachable-only results are a subset of all results |
51 | 67 | test -f /tmp/sarif-all.sarif |
52 | 68 | test -f /tmp/sarif-reachable.sarif |
53 | 69 |
|
54 | | -python3 -c " |
| 70 | +uv run python -c " |
55 | 71 | import json |
56 | 72 | with open('/tmp/sarif-all.sarif') as f: |
57 | 73 | all_data = json.load(f) |
|
0 commit comments