1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//! `CheckSource` — abstraction over a runnable check.
//!
//! Design: [docs/design.md §3.2]. v0.1 ships exactly one impl (`Shell`,
//! living in the `klasp` binary). The trait exists at v0.1 so v0.2's named
//! recipes (`pre_commit`, `fallow`, `pytest`, `cargo`) and v0.3's
//! subprocess plugins land as new impls without touching the trait.
//!
//! **Lifetime note**: `source_id(&self) -> &str` returns a `&str` tied to
//! `&self`, *not* `&'static str`. v0.3 subprocess plugins have IDs derived
//! from binary filenames discovered at runtime — a `'static` lifetime
//! cannot represent that. This is the v0.3 plugin commitment locked in
//! at v0.1. See issue [klasp#1] for the explicit callout.
use PathBuf;
use crateCheckConfig;
use crateGitEvent;
use crateVerdict;
/// Typed error for `CheckSource::run`. Covers runtime-level failures only;
/// semantic failures (lint hits, test failures) ride inside `Verdict::Fail`.
/// Use `CheckSourceError::Other` for impl-specific errors that don't fit the
/// predefined variants.
/// Snapshot of repo metadata passed to every check execution.
///
/// `base_ref` is the merge-base ref between `HEAD` and the upstream tracking
/// branch — the "branch divergence point" diff-aware tools (`pre-commit
/// run --from-ref`, `fallow audit --base`) want. The gate runtime exposes it
/// to shell checks via the `KLASP_BASE_REF` env var; sources that talk to
/// other check tools (named recipes in v0.2, subprocess plugins in v0.3) read
/// it directly off this struct.
///
/// Falls back to `HEAD~1` when no upstream is configured (a fresh checkout,
/// a detached HEAD, or a branch that has never been pushed). The fallback is
/// best-effort — diff-aware tools that don't recognise the ref simply lint
/// the whole tree, which is the same behaviour they'd have without klasp.
///
/// `staged_files` carries the absolute paths of files in the current group's
/// scope when running in monorepo mode (i.e. the subset of staged files that
/// belong to the `klasp.toml` group that owns this invocation). An **empty
/// Vec means "no scoping; the check sees the whole repo"** — this is the
/// back-compat value used by the single-config fallback path and by callers
/// that do not dispatch per-group. Per-source consumption of `staged_files`
/// for fine-grained scoping is deferred to issue #34 (rayon / named recipes);
/// the field is present now so that data is available to checks without a
/// further struct-breaking change.
/// Outcome of a single `CheckSource::run` invocation.
/// Object-safe trait. Implementations are stored as `Box<dyn CheckSource>`
/// in the source registry.