Class: SimpleCovMcp::StalenessChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov_mcp/staleness_checker.rb

Overview

Lightweight service object to check staleness of coverage vs. sources

Constant Summary collapse

MODES =
[:off, :error].freeze

Instance Method Summary collapse

Constructor Details

#initialize(root:, resultset:, mode: :off, tracked_globs: nil, timestamp: nil) ⇒ StalenessChecker

Returns a new instance of StalenessChecker.



13
14
15
16
17
18
19
20
# File 'lib/simplecov_mcp/staleness_checker.rb', line 13

def initialize(root:, resultset:, mode: :off, tracked_globs: nil, timestamp: nil)
  @root = File.absolute_path(root || '.')
  @resultset = resultset
  @mode = (mode || :off).to_sym
  @tracked_globs = tracked_globs
  @cov_timestamp = timestamp
  @resultset_path = nil
end

Instance Method Details

#check_file!(file_abs, coverage_lines) ⇒ Object

Raise CoverageDataStaleError if stale (only in error mode)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/simplecov_mcp/staleness_checker.rb', line 27

def check_file!(file_abs, coverage_lines)
  return if off?

  d = compute_file_staleness_details(file_abs, coverage_lines)
  # For single-file checks, missing files with recorded coverage count as stale
  # via length mismatch; project-level checks also handle deleted files explicitly.
  if d[:newer] || d[:len_mismatch]
    raise CoverageDataStaleError.new(
      nil,
      nil,
      file_path: rel(file_abs),
      file_mtime: d[:file_mtime],
      cov_timestamp: d[:coverage_timestamp],
      src_len: d[:src_len],
      cov_len: d[:cov_len],
      resultset_path: resultset_path
    )
  end
end

#check_project!(coverage_map) ⇒ Object

Raise CoverageDataProjectStaleError if any covered file is newer or if tracked files are missing from coverage, or coverage includes deleted files.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/simplecov_mcp/staleness_checker.rb', line 63

def check_project!(coverage_map)
  return if off?

  ts = coverage_timestamp
  coverage_files = coverage_map.keys

  newer, deleted = compute_newer_and_deleted_files(coverage_files, ts)
  missing = compute_missing_files(coverage_files)

  return if newer.empty? && missing.empty? && deleted.empty?

  raise CoverageDataProjectStaleError.new(
    nil,
    nil,
    cov_timestamp: ts,
    newer_files: newer,
    missing_files: missing,
    deleted_files: deleted,
    resultset_path: resultset_path
  )
end

#off?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/simplecov_mcp/staleness_checker.rb', line 22

def off?
  @mode == :off
end

#stale_for_file?(file_abs, coverage_lines) ⇒ Boolean

Compute whether a specific file appears stale relative to coverage. Ignores mode and never raises; returns true when:

  • the file is missing/deleted, or

  • the file mtime is newer than the coverage timestamp, or

  • the source line count differs from the coverage lines array length (when present).

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
# File 'lib/simplecov_mcp/staleness_checker.rb', line 52

def stale_for_file?(file_abs, coverage_lines)
  d = compute_file_staleness_details(file_abs, coverage_lines)
  return 'M' unless d[:exists]
  return 'T' if d[:newer]
  return 'L' if d[:len_mismatch]

  false
end