Class: SimpleCov::Formatter::AIFormatter::MarkdownBuilder::ReportBudget
- Inherits:
-
Object
- Object
- SimpleCov::Formatter::AIFormatter::MarkdownBuilder::ReportBudget
- Extended by:
- T::Sig
- Defined in:
- lib/simplecov-ai/markdown_builder/report_budget.rb
Overview
Enforces the configured size ceiling on the report. Every section appends through
#admit, which only writes a fragment when it still fits below the ceiling minus the
room reserved for the closing truncation notice, so the finished file never exceeds
max_file_size_kb. Fragments are admitted whole: one that does not fit is dropped and
reported back to the caller, which then closes its section. The notice itself is
written through #write_notice once every section has reported what it left out.
Constant Summary collapse
- BYTES_PER_KB =
The number of bytes in a kilobyte (metric kB, matching the "kB" unit shown to users)
T.let(1000, Integer)
- TRUNCATION_ALERT_HEADING =
Alert heading for truncated reports
T.let("> **[WARNING] TRUNCATION NOTIFICATION:**\n", String)
- TRUNCATION_ALERT_BODY =
Alert body for truncated reports, naming what the size budget left out
T.let( '> The report reached the maximum token constraint (%<limit>d kB) and was truncated: ' \ '%<deficit_files>d deficit file(s) and %<bypass_files>d bypass file(s) omitted or cut short. ' \ 'Lowest-coverage files are listed first; resolve the deficits above to reveal the remaining ' \ "ones in subsequent test runs.\n", String )
- SEPARATOR_MARGIN =
Bytes kept free, beyond the notice itself, for the blank-line separators the sections write outside the admission check.
T.let(4, Integer)
Instance Method Summary collapse
- #admit(fragment) ⇒ Object
-
#initialize(buffer, limit_kb, file_count) ⇒ ReportBudget
constructor
A new instance of ReportBudget.
- #write(fragment) ⇒ Object
- #write_notice(omitted_deficit_files, omitted_bypass_files) ⇒ Object
Constructor Details
#initialize(buffer, limit_kb, file_count) ⇒ ReportBudget
38 39 40 41 42 43 44 |
# File 'lib/simplecov-ai/markdown_builder/report_budget.rb', line 38 def initialize(buffer, limit_kb, file_count) @buffer = buffer @limit_kb = limit_kb reserved_bytes = notice(file_count, file_count).bytesize + SEPARATOR_MARGIN admissible_bytes = (limit_kb * BYTES_PER_KB) - reserved_bytes @admissible_bytes = T.let(admissible_bytes, Integer) end |
Instance Method Details
#admit(fragment) ⇒ Object
51 52 53 54 55 |
# File 'lib/simplecov-ai/markdown_builder/report_budget.rb', line 51 def admit(fragment) fits = @buffer.string.bytesize + fragment.bytesize <= @admissible_bytes write(fragment) if fits fits end |
#write(fragment) ⇒ Object
63 64 65 |
# File 'lib/simplecov-ai/markdown_builder/report_budget.rb', line 63 def write(fragment) @buffer.write(fragment) end |
#write_notice(omitted_deficit_files, omitted_bypass_files) ⇒ Object
73 74 75 |
# File 'lib/simplecov-ai/markdown_builder/report_budget.rb', line 73 def write_notice(omitted_deficit_files, omitted_bypass_files) write(notice(omitted_deficit_files, omitted_bypass_files)) end |