Add SAST evaluation runner and validation artifacts
- Add run_sast_eval.py with SQLite/CSV result storage, retries, JSON repair, resumability, and expected-label scoring - Add exact SAST prompt and full benchmark expected-results CSV - Add mock-API end-to-end tests and uv/bandit dev requirements - Record Bandit parity and DeepSeek original-vs-obfuscated comparisons
This commit is contained in:
15 files changed
+26580
No files matched your search
@@ -0,0 +1,106 @@
|
||||
# Validation artifacts
|
||||
|
||||
This directory contains reproducible checks and the executed results used to
|
||||
validate the obfuscated dataset condition.
|
||||
|
||||
## Automated pipeline test
|
||||
|
||||
The test starts a local mock OpenAI-compatible API and runs the real
|
||||
`run_sast_eval.py` CLI against four benchmark samples. It covers:
|
||||
|
||||
- valid JSON
|
||||
- fenced JSON
|
||||
- malformed JSON followed by a repair request
|
||||
- a `429` retry
|
||||
- SQLite persistence
|
||||
- CSV export
|
||||
- `--report` without API calls
|
||||
- dry-run without an API key
|
||||
|
||||
Run it with the standard library only:
|
||||
|
||||
```bash
|
||||
python3 -m unittest validation/test_pipeline.py -v
|
||||
```
|
||||
|
||||
Current result: **3 tests passed**.
|
||||
|
||||
## Bandit comparison
|
||||
|
||||
Bandit was installed in a `uv` virtual environment:
|
||||
|
||||
```bash
|
||||
uv venv --python 3.14 .venv
|
||||
uv pip install --python .venv/bin/python -r requirements-dev.txt
|
||||
```
|
||||
|
||||
Commands:
|
||||
|
||||
```bash
|
||||
.venv/bin/bandit -r Samples -f json -o validation/bandit/samples.json
|
||||
.venv/bin/bandit -r Samples_Obfuscated_v2 -f json -o validation/bandit/obfuscated_v2.json
|
||||
```
|
||||
|
||||
Result:
|
||||
|
||||
- Original: **89 findings**
|
||||
- Obfuscated v2: **86 findings**
|
||||
- **86 findings identical** by file, rule, severity, and confidence
|
||||
- **No new findings**
|
||||
- The only difference is **3 B608** findings in
|
||||
`BenchmarkTest00192.py`, `BenchmarkTest00284.py`, and
|
||||
`BenchmarkTest00286.py`
|
||||
|
||||
B608 is a string-pattern rule for SQL-looking text. The obfuscator replaces SQL
|
||||
strings with generic `msg` tokens, so those findings disappear. The SQL sink
|
||||
and data flow remain. With B608 skipped, both directories produce exactly
|
||||
**86/86** identical findings.
|
||||
|
||||
See `bandit_comparison.txt` for the full report and `bandit/*.json` for raw
|
||||
Bandit output.
|
||||
|
||||
## DeepSeek comparison
|
||||
|
||||
Two runs were executed with `opencode-go/deepseek-v4.1-flash` and
|
||||
`prompts/sast_v1.txt`:
|
||||
|
||||
| Metric | Original | Obfuscated v2 |
|
||||
|---|---:|---:|
|
||||
| TP | 46 | 46 |
|
||||
| FP | 13 | 18 |
|
||||
| TN | 98 | 93 |
|
||||
| FN | 0 | 0 |
|
||||
| Accuracy | 91.7% | 88.5% |
|
||||
| Precision | 78.0% | 71.9% |
|
||||
| Recall | 100% | 100% |
|
||||
| Category accuracy (TP) | 100% | 100% |
|
||||
| CWE accuracy (TP) | 100% | 100% |
|
||||
| Total tokens | 381,410 | 472,990 |
|
||||
| API calls | 201 | 202 |
|
||||
|
||||
Paired McNemar test on the 157 in-scope samples: **p = 0.125**, so the +5
|
||||
false-positive difference is not statistically significant in this single run.
|
||||
|
||||
Caveat: the original run used `--workers 4` and the obfuscated run used
|
||||
`--workers 1`, so wall-clock times are not comparable. See
|
||||
`deepseek_comparison.md` for the per-category breakdown, new false positives,
|
||||
and the recommended replication.
|
||||
|
||||
Raw per-sample outputs are in `deepseek/*.csv`; `deepseek/summary.csv` contains
|
||||
the comparison table in machine-readable form.
|
||||
|
||||
## Contents
|
||||
|
||||
```text
|
||||
validation/
|
||||
├── test_pipeline.py # mock-API end-to-end test
|
||||
├── bandit_comparison.txt # human-readable Bandit diff
|
||||
├── bandit/
|
||||
│ ├── samples.json # raw Bandit JSON, original
|
||||
│ └── obfuscated_v2.json # raw Bandit JSON, obfuscated
|
||||
├── deepseek_comparison.md # original vs obfuscated analysis
|
||||
└── deepseek/
|
||||
├── deepseek-original.csv # per-sample original results
|
||||
├── deepseek-v4.1-flash.csv # per-sample obfuscated results
|
||||
└── summary.csv # comparison metrics
|
||||
```
|
||||
Reference in new issue
Block a user