Skip to content

Commit ce33da6

Browse files
committed
fix e2e reachability tests, respect --disable-blocking when set
Signed-off-by: lelia <2418071+lelia@users.noreply.github.com>
1 parent 2e25468 commit ce33da6

2 files changed

Lines changed: 39 additions & 19 deletions

File tree

socketsecurity/core/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,8 @@ def get_added_and_removed_packages(
947947
)
948948
except APIFailure as e:
949949
log.error(f"API Error: {e}")
950+
if self.cli_config and self.cli_config.disable_blocking:
951+
sys.exit(0)
950952
sys.exit(1)
951953
except Exception as e:
952954
import traceback
@@ -1124,6 +1126,8 @@ def create_new_diff(
11241126
os.unlink(temp_file)
11251127
except OSError:
11261128
pass
1129+
if self.cli_config and self.cli_config.disable_blocking:
1130+
sys.exit(0)
11271131
sys.exit(1)
11281132
except Exception as e:
11291133
import traceback

tests/e2e/validate-reachability.sh

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,47 @@ else
2727
exit 1
2828
fi
2929

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
3942
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+
"
4965

5066
# 5. Verify reachable-only results are a subset of all results
5167
test -f /tmp/sarif-all.sarif
5268
test -f /tmp/sarif-reachable.sarif
5369

54-
python3 -c "
70+
uv run python -c "
5571
import json
5672
with open('/tmp/sarif-all.sarif') as f:
5773
all_data = json.load(f)

0 commit comments

Comments
 (0)