Skip to content

feat: add baseline loading, generation and deltas - #14

Merged
floriankraemer merged 5 commits into
mainfrom
feat/baseline
Nov 12, 2026
Merged

floriankraemer merged 5 commits into
mainfrom
feat/baseline

Conversation

@floriankraemer

Copy link
Copy Markdown
Owner

Summary

  • analyse --baseline/-b <file> loads and applies a baseline. Without it, the newest .jcca/baseline/baseline-*.json (by the timestamp in the name, then mtime) is auto-detected and announced with a warning.
  • analyse --generate-baseline/-g writes .jcca/baseline/baseline-YYYY-MM-DD_HH-mm-ss.json (format 2.0, atomic write, injectable clock) after the existing baseline was applied.
  • Loading accepts the 2.0 format and legacy files (a JSON report). All validation errors are collected into one Invalid baseline file format: ... message. Missing and malformed files have their own messages. A config-hash mismatch is a warning.
  • Deltas (after minus before, compared at three decimals) for the 8 weights, score, Halstead volume/difficulty/effort, cyclomatic and understandability. Console cells get a second line Δ +x (red) or Δ -x (green) in grouped and single tables. The JSON report also carries the non-weight deltas.
  • Baseline loading and validation live in domain (PIT-covered); the file handling and matching by the JSON report's class key (<class>@<file> for classes in several files) live next to the reports. The atomic write of ReportWriter is extracted to a shared AtomicFileWriter.
  • New schemas/baseline.json (draft-07) for the 2.0 and legacy formats. A test validates every generated baseline and a JSON report against it (json-schema-validator, test scope).

Test plan

  • ./mvnw -B verify: 610 tests, JaCoCo 97.2% line / 95.4% branch, PIT 834 of 844 mutations killed
  • Reader: v2, legacy, every validation error alone and combined, malformed, missing, unreadable, non-UTF-8
  • Auto-detect: several files, none, no directory, directory is a file, unreadable directory, names without timestamp
  • Generation: fixed clock, path, golden file, schema validation, no deltas written
  • E2E: run, -g, modify sources, run with auto-detect shows deltas (grouped and single table golden files), apply-then-generate order, hash mismatch, legacy report as baseline, reports with deltas
  • Smoke test with java -jar target/cognitive-analysis.jar

Adds --baseline/-b and --generate-baseline/-g to analyse. A baseline is
auto-detected from .jcca/baseline when none is given. Both the 2.0 format
and a JSON report (legacy) are accepted, all validation errors are
collected, and a changed metric configuration produces a warning.
Deltas of weights, score, Halstead, cyclomatic and understandability are
shown in the console tables and the JSON report. Includes a corrected
schemas/baseline.json that every generated baseline is validated against.
…eltas

Validation no longer returns partial results, which removes unobservable
return paths. The previous-metrics delta calculation is replaced by
applyBaseline everywhere. Deltas of non-finite values no longer throw.
Adds tests for the remaining unkilled and uncovered mutants.
…den numbers

Generated baselines use UTC for the file name and createdAt, are created
without replacing an existing file and get a -N suffix on a collision.
Auto-detect parses the timestamp strictly, ignores other names and
non-regular files, and orders by timestamp then suffix. A class that
became or stopped being duplicate is matched by its name when that
identifies exactly one baseline class. Non-finite numbers are rejected
when reading and shown as N/A in the console. The format error names the file.
@floriankraemer
floriankraemer merged commit 8001dbe into main Nov 12, 2026
1 check passed
@floriankraemer
floriankraemer deleted the feat/baseline branch November 12, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant