mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-12-04 10:48:19 +00:00
feat(contributor-scan): a scan skips its runs directory when it lies inside the scanned path (3.1, follow-up)
Since part A a native scan writes its run under the user cache or wherever `OPENULTRASAST_RUNS_DIR` points. A scan of a path that contains that directory, a home directory or a tree with the runs directory set inside it, took the files under it for source: those of earlier runs and those of its own run. On the code as it was, a source file under the runs directory inside the target was read and its finding reported (`file_targets=3 findings=2` for a tree of two files and one such copy). By the maintainer's decision, recorded as step 2c of the handover, the scan skips the runs directory only: `config.runs_dir`, the default location or the override. The other directories under `~/.cache/openultrasast` are read as before, and so is every tree whose runs directory lies outside it. `preprocess_repository` and `enumerate_source_files` in src/openultrasast/preprocess.py take a `skip` directory, and the preprocess stage of a scan (`_map_scan_targets` in cli.py) passes `Path(config.runs_dir)`. The skip applies only where the runs directory lies inside the scanned path: a target that is the runs directory or lies inside it is read as it was, so a runs directory set to `.` does not silence a scan. Both paths are compared resolved, so a symlinked or relative name is found, and the excluded path is built under the root as the walk spells it, so a relative root works too. Every other caller of the two functions passes no `skip` and is unchanged. No run of this package keeps a source file today (the independent reviewer's count: a quick run holds 15 files, all `.json`, `.jsonl`, `.md` or `.sarif`; the two benchmark runs in the real cache hold `.json` and `.toml`). The copy in the tests is a constructed case. Tests: four tests failed on the code as it was and pass after the change: the runs directory inside the scanned path, by the override, by the default location and by the override through a symlink, and the rest of the cache still read. Two more pin the narrow reading, a target that is the runs directory or lies inside it is read as it was; they failed on a first cut that skipped more than was decided. A direct call with a relative root pins the path comparison. The nine test files around the change pass (113 passed), as do the 37 files that exercise the scan path (362 passed); ruff, mypy, the three gates and compileall pass. Runs of the real CLI on one scratch subject, the code at HEAD against this tree: with the runs directory inside the target the copy under it is no longer read (`file_targets=4 findings=3` for five source files); with the runs directory a parent of the target, or the target itself, both read the same five files and report the same four findings. An independent reviewer approved the change in three rounds; its first round found that the first cut also silenced a scan whose target lay inside the runs directory, which this cut narrows to the decided case.
This commit is contained in:
@@ -750,7 +750,12 @@ def _map_scan_targets(
|
||||
write_static_hints(static_hints, run.root / "mapping" / "static_hints.json")
|
||||
snapshot, targets = runtime.run_stage(
|
||||
"preprocess",
|
||||
lambda: preprocess_repository(run.target, run.root / "preprocess" / "file_targets.json", static_hints),
|
||||
lambda: preprocess_repository(
|
||||
run.target,
|
||||
run.root / "preprocess" / "file_targets.json",
|
||||
static_hints,
|
||||
skip=Path(config.runs_dir),
|
||||
),
|
||||
)
|
||||
# A language nothing here covers is named, never a silent zero (pre-push 17.2, Requirement 9.2).
|
||||
for language, count in uncovered_languages(targets, ruleset, engine=mode != "quick"):
|
||||
|
||||
Reference in New Issue
Block a user