Class: SimpleCov::Formatter::AIFormatter::MarkdownBuilder

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
SnippetFormatter
Defined in:
lib/simplecov-ai/markdown_builder.rb,
lib/simplecov-ai/markdown_builder/branch_enricher.rb,
lib/simplecov-ai/markdown_builder/bypass_compiler.rb,
lib/simplecov-ai/markdown_builder/deficit_grouper.rb,
lib/simplecov-ai/markdown_builder/deficit_compiler.rb,
lib/simplecov-ai/markdown_builder/deficit_formatter.rb,
lib/simplecov-ai/markdown_builder/snippet_formatter.rb

Overview

Responsible for compiling static text representations from evaluated coverage metrics, optimizing layout size, orchestrating string IO buffers, and halting upon token exhaustion. Serves as the primary mutation boundary to format AI consumption targets.

Defined Under Namespace

Modules: SnippetFormatter Classes: BranchEnricher, BypassCompiler, DeficitCompiler, DeficitFormatter, DeficitGroup, DeficitGrouper

Constant Summary collapse

BYTES_PER_KB =

The number of bytes in a kilobyte

T.let(1024.0, Float)
STATUS_PASSED =

Text representation for a passed coverage check

T.let('PASSED', String)
STATUS_FAILED =

Text representation for a failed coverage check

T.let('FAILED', String)
HEADER_TEMPLATE =

Template for the report header

T.let(
  "# AI Coverage Digest\n" \
  "**Status:** %<status>s\n" \
  "**Global Line Coverage:** %<line_pct>s%%\n" \
  "**Global Branch Coverage:** %<branch_pct>s%%\n" \
  "**Generated At:** %<time>s (Local Timezone)\n",
  String
)
TRUNCATION_ALERT_HEADING =

Alert heading for truncated reports

T.let('> **[WARNING] TRUNCATION NOTIFICATION:**', String)
TRUNCATION_ALERT_BODY =

Alert body for truncated reports

T.let(
  '> The total coverage deficit report exceeded the maximum token ' \
  'constraint (%<limit>d kB). ' \
  'The report was truncated. The deficits detailed above represent ' \
  'the lowest-coverage (most critical) files. ' \
  'Please resolve these deficits to reveal the remaining uncovered files in subsequent test runs.',
  String
)

Constants included from SnippetFormatter

SnippetFormatter::ESTIMATED_CHARS_PER_LINE, SnippetFormatter::OCCURRENCE_TEMPLATE, SnippetFormatter::TRUNCATION_ELLIPSIS

Instance Method Summary collapse

Methods included from SnippetFormatter

#calculate_occurrence, #count_snippet_occurrences, #fetch_snippet_text, #truncate_snippet

Constructor Details

#initialize(coverage_metrics, config) ⇒ MarkdownBuilder

Returns a new instance of MarkdownBuilder.



68
69
70
71
72
73
74
75
# File 'lib/simplecov-ai/markdown_builder.rb', line 68

def initialize(coverage_metrics, config)
  @coverage_metrics = T.let(coverage_metrics, SimpleCov::Result)
  @config = T.let(config, Configuration)
  @buffer = T.let(StringIO.new, StringIO)
  @file_count = T.let(0, Integer)
  @truncated = T.let(false, T::Boolean)
  @ast_cache = T.let({}, T::Hash[String, T::Array[ASTResolver::SemanticNode]])
end

Instance Method Details

#buildObject



82
83
84
85
86
87
88
# File 'lib/simplecov-ai/markdown_builder.rb', line 82

def build
  write_header
  DeficitCompiler.new(@coverage_metrics, @config, self).write_deficits(@buffer)
  BypassCompiler.new(@coverage_metrics, self).write_bypasses(@buffer) if @config.include_bypasses
  write_truncation_warning if @truncated
  @buffer.string
end

#truncate_if_needed?Boolean

Returns:

  • (Boolean)


98
99
100
101
102
103
# File 'lib/simplecov-ai/markdown_builder.rb', line 98

def truncate_if_needed?
  return false unless @buffer.size / BYTES_PER_KB > @config.max_file_size_kb

  @truncated = true
  true
end

#try_resolve_ast(filename) ⇒ Object



91
92
93
94
95
# File 'lib/simplecov-ai/markdown_builder.rb', line 91

def try_resolve_ast(filename)
  @ast_cache[filename] ||= ASTResolver.resolve(filename)
rescue StandardError
  nil
end