vcs-git only.Expand description
Just-in-time (commit-level) defect-induction risk scoring (issue #331).
Where score ranks files at a ref, this module
scores a single commit at check-in time — the unit a CI gate
actually reviews. It is the static, rule-based counterpart to the
machine-learning just-in-time (JIT) defect-prediction models in the
literature; no model is trained or persisted, so there is nothing to
re-fit as a project ages.
§Why static rules rather than a model
The JIT defect-prediction literature (Kamei et al., A Large-Scale Empirical Study of Just-in-Time Quality Assurance, IEEE TSE 39(6), 2013; the systematic survey by Zhao et al. in ACM Computing Surveys 55(4), 2022) is mature and consistently finds commit-level prediction high-value at check-in. The survey’s key tooling caveat is that trained JIT models lose predictive power within about a year and must be re-trained on recent data, so a rule-based scorer with no model to drift is the most maintainable starting point. The signed direction of every term below is taken from that literature, not fitted, so the score needs no retraining.
§Features (the Kamei change measures)
Grouped exactly as Kamei et al. group them, with the open-source replications [Commit Guru (Rosen, Grawi & Shihab, FSE 2015 tool demo)] and [McIntosh & Kamei, Are Fix-Inducing Changes a Moving Target?, IEEE TSE 44(5), 2018] confirming the directions on independent corpora:
- Size — lines added/deleted, files touched, diff hunks. Larger
changes are more defect-prone (Kamei
LA/LD/NF). - Diffusion — distinct subsystems and directories touched, plus
the within-commit change entropy. Scattered changes are riskier
(Kamei
NS/ND/Entropy). - History — the touched files’ priors: prior change count,
distinct prior authors, prior bug- and security-fix counts, and the
composite file-level
risk_score. Files with turbulent history induce more defects (KameiNDEV/NUC; the file priors fold in the #328 composite). - Experience — the author’s prior commit count, long and recent.
This term is negatively signed: experienced authors induce
fewer defects (Kamei
EXP/REXP, the one robustly protective signal in their models). - Purpose — whether the commit is a fix (itself defect-prone in
Kamei’s
FIX), a security fix (weighted higher here), or a revert (corrective, so dampened).
§The score is ordinal
score returns a non-negative composite plus its per-group
JitContributions (so a consumer sees why a commit scored as it
did). Like the file-level risk score it is ordinal: rank commits
by it, compare a commit against a project’s own distribution, but do
not read the absolute magnitude as a probability. Any change to the
term set or weights must bump JIT_SCORE_VERSION.
§Scope
score / JitReport cover a real commit (all five groups).
Scoring an arbitrary unprovenanced diff (bca vcs jit --diff <file>)
is supported as a deliberately partial path (issue #580): a bare
diff carries no author, parent, or file history, so only the size and
diffusion groups are computable. That path produces a distinct
JitDiffReport whose unavailable groups are absent from the type
(not present as zero), and whose partial_risk_score
is not comparable to a commit score — see JitDiffReport.
ML-based JIT and server-side hook integration remain out of scope per
issues #331 / #580.
Structs§
- JitCommit
- Structural facts about the scored commit.
- JitContributions
- Per-group contributions to the composite score. They sum to the score
before the non-negative floor (so
experienceis typically negative); surfaced so a consumer can see which group drove the result. - JitDiff
Contributions - The contributions available from a bare diff: size and diffusion only.
History, experience, and purpose are omitted (no input), so — unlike
JitContributions— there is no zero-valued field a consumer could misread as “this group is low risk”. - JitDiff
Report - The result of scoring an arbitrary unified diff (issue #580).
- JitDiffusion
- How widely the change is spread (Kamei
NS/ND/Entropy). - JitExperience
- The author’s prior activity (Kamei
EXP/REXP). Higher means more experience, which lowers the score. - JitFeatures
- Every numeric feature of one commit, grouped as Kamei groups them. The
score’s purpose term is supplied separately (
JitPurpose) so this struct is the pure numeric feature vector. - JitHistory
- Priors of the touched files, measured from history before the scored
commit (Kamei
NDEV/NUCplus the #328 file composite). - JitPurpose
- Keyword classification of the commit message (Kamei
FIX, plus the security and revert refinements this crate already detects). - JitReport
- The full result of scoring one commit: the resolved commit, its features, the per-group contributions, and the composite score.
- JitSize
- Size of the change (Kamei
LA/LD/NF, plus diff hunks).
Enums§
- JitSource
- Which input a JIT report was scored from. Serializes to a lowercase
string (
"commit"/"diff") so consumers can branch on it.
Constants§
- JIT_
SCHEMA_ VERSION - Output-shape version for a
JitReport. Bump on any change to the serialized field set. - JIT_
SCORE_ VERSION - Version of the composite JIT formula. Increment on any change to the
term set, weights, or bumps in
score. Separate from the file-levelRISK_SCORE_VERSIONso the two scores version independently.
Functions§
- score
- Compute the composite JIT risk score and its per-group breakdown.
- score_
diff_ features - Compute the partial (size + diffusion only) JIT score for an arbitrary
diff, reusing the same
scoremath as a commit so the two terms are computed by one code path. The history, experience, and purpose terms are left at their zero defaults (no input), and their zero contributions are discarded — only size and diffusion survive into the returnedJitDiffContributions.