feat(contributor-scan): a scan says how many source files it left out under its runs directory (3.1, follow-up)

`56c4620` made a scan skip its runs directory when it lies inside the scanned
path, and said nothing about it. By the maintainer's decision of 2026-11-25,
recorded in the handover, the scan now prints one notice. The decision, as the
handover records it: "When source files lie under the runs directory inside the
scanned path, the scan prints one notice: line naming the path and the number
left out, the way run retention does."

The line is `notice: skipped <n> source files under the runs directory <path>`
(`source file` at one). `ousast scan` prints it, the `openultrasast.scan` tool
returns it among its notices, and `openultrasast.benchmark` returns the notices
of the scan it runs. Nothing is added to the manifest or the report.

The count follows the scanned tree's own rules, so it is the number the skip
took: a source file that the target's root `.gitignore` already keeps out, or
that lies under a directory the scan ignores, brings no notice, and a
`.gitignore` inside the runs directory does not hide what was left out. To that
end `enumerate_source_files` in src/openultrasast/preprocess.py and the new
`count_skipped_source_files` share one private predicate,
`_is_read_as_source`. The enumeration returns the lists it returned before
(the skip test now comes first, so a path under the skipped directory is no
longer stat'ed). The count is taken after the preprocess stage, so a tree
whose ignore file cannot be read stops the scan inside that stage, as before.
It costs one more read of the target's root `.gitignore` and, where there is
one, one more `git ls-files`, and only when the runs directory lies inside the
scanned path.

Nothing is said when no source file is left out, when the runs directory lies
outside the scanned path, or when it is the target or lies above it.

Tests: the notice tests failed on the code as it was (6 failed) and pass after
the change. Four more failed on a first cut that counted by the runs
directory's own `.gitignore` and pass on this one: a `.gitignore` inside the
runs directory does not hide what the scan left out, nothing is left out where
the target already ignores the runs directory, nothing under a directory the
scan ignores, and a directory named `.gitignore` costs the scan nothing. The
test that a target inside the runs directory is read as it was now also pins
that nothing is said; a count that covered that target failed it. The 23 test
files around the change pass (241 passed); ruff, mypy, the three gates and
compileall pass, and the gates print what they printed before the change.

An independent reviewer approved the change in two rounds. Its first round
found the count by the wrong rules, which this cut closes. Its second round
named two things that are left open and recorded in the handover: were the
target's root `.gitignore` to become unreadable between the preprocess stage
and the count, the scan would stop with no failed stage recorded in its trace
and no manifest; and no test pins that a tracked source file under an ignored
runs directory is counted.
This commit is contained in:
Marius Ciepluch
2026-11-25 17:15:13 +01:00
parent 9a0b27e07b
commit 52c9afb85f
3 changed files with 163 additions and 19 deletions
+20 -7
View File
@@ -55,7 +55,7 @@ from .pairs import (
select_vendored,
)
from .policy import assert_rules_resolve, load_policy
from .preprocess import FileTarget, preprocess_repository, write_preprocess_artifact
from .preprocess import FileTarget, count_skipped_source_files, preprocess_repository, write_preprocess_artifact
from .profiling import start as start_profiling
from .provenance import fingerprint
from .rank import rank_obligations, rank_targets, write_rankings
@@ -598,7 +598,7 @@ def _run_scan(path: Path, config_path: Path, mode: str, fail_on: str) -> ScanOut
)
write_harness_config(config=config, path=run.root / "harness.json")
runtime.start(mode=mode, target=run.target)
policy, ruleset, targets, entry_points = _map_scan_targets(runtime, run, config, mode)
policy, ruleset, targets, entry_points, left_out = _map_scan_targets(runtime, run, config, mode)
ledger_path = run.target / CALIBRATION_DIR / "false_positive_learnings.json"
provenance = runtime.run_stage("provenance", lambda: fingerprint(run.target))
rankings = runtime.run_stage("rank", lambda: rank_targets(targets))
@@ -731,7 +731,8 @@ def _run_scan(path: Path, config_path: Path, mode: str, fail_on: str) -> ScanOut
for item in runtime.state["degradations"]
if item.get("reason") == "language_not_covered"
)
+ prune_notices,
+ prune_notices
+ _skipped_files_notices(Path(config.runs_dir), left_out),
)
@@ -740,21 +741,23 @@ def _map_scan_targets(
run: ScanRun,
config: ResolvedConfig,
mode: str,
) -> tuple[dict[str, CwePolicy], tuple[PatternRule, ...], list[FileTarget], list[EntryPointRecord]]:
"""The policy and ruleset the scan runs under, and the targets and entry points every later stage reads."""
) -> tuple[dict[str, CwePolicy], tuple[PatternRule, ...], list[FileTarget], list[EntryPointRecord], int]:
"""The policy and ruleset the scan runs under, the targets and entry points every later stage reads, and how
many source files the skip left out."""
policy = runtime.run_stage("policy_load", load_policy)
rule_ledger_path = run.target / CALIBRATION_DIR / "rule_policy.json"
ruleset = runtime.run_stage("ruleset_load", lambda: load_ruleset(DEFAULT_RULESET_DIR, rule_ledger_path))
runtime.run_stage("policy_check", lambda: assert_rules_resolve(ruleset, policy))
static_hints = runtime.run_stage("static_mapping", lambda: _load_static_hints(config.static_analysis.sarif_paths))
write_static_hints(static_hints, run.root / "mapping" / "static_hints.json")
runs_dir = Path(config.runs_dir)
snapshot, targets = runtime.run_stage(
"preprocess",
lambda: preprocess_repository(
run.target,
run.root / "preprocess" / "file_targets.json",
static_hints,
skip=Path(config.runs_dir),
skip=runs_dir,
),
)
# A language nothing here covers is named, never a silent zero (pre-push 17.2, Requirement 9.2).
@@ -772,7 +775,17 @@ def _map_scan_targets(
write_entry_points(entry_points, run.root / "mapping" / "entry_points.json")
targets = attach_reachability_hints(targets, entry_points)
write_preprocess_artifact(snapshot, targets, run.root / "preprocess" / "file_targets.json")
return policy, ruleset, targets, entry_points
# After the preprocess stage, so a tree whose ignore file cannot be read stops the scan inside that stage, as before.
left_out = count_skipped_source_files(run.target, runs_dir)
return policy, ruleset, targets, entry_points, left_out
def _skipped_files_notices(runs_dir: Path, left_out: int) -> tuple[str, ...]:
"""What the scan says about the source files it left out under its runs directory: nothing when there are none."""
if not left_out:
return ()
files = "file" if left_out == 1 else "files"
return (f"skipped {left_out} source {files} under the runs directory {runs_dir}",)
def _collect_findings(