Skip to content

Remove unreachable checks and improve test coverage - #1291

Merged
jgabry merged 2 commits into
v1.0from
coverage-review
Sep 26, 2026
Merged

jgabry merged 2 commits into
v1.0from
coverage-review

Conversation

@jgabry

@jgabry jgabry commented Sep 25, 2026

Copy link
Copy Markdown
Member

Submission Checklist

  • Run unit tests
  • Declare copyright holder and agree to license (see below)

Summary

Part of #1258. Before the v1.0 release candidate we went through every
line Codecov reports as uncovered (Linux and Windows sessions merged) and
decided each one: a test, a removal, or an accepted gap.

Removed, because nothing can reach them:

  • validate_exe_file(): every method that runs the executable calls the
    model's assert_current() first, which already reports a missing
    executable.
  • The format_version check in validate_build_record():
    read_build_record() checks the version before calling the validator
    and new_build_record() writes it.
  • The rvars cases in the draws-format helpers: assert_valid_draws_format()
    rejects that format first. $unconstrain_draws() now uses that assertion
    instead of its own check.
  • Two branches of .remove_leftmost_dim() for shapes draws_of() never
    produces, and the unused show_stderr_messages() getter.

The guard against reading a fit whose chains all failed was repeated in
six public methods with three different messages. It now lives only in
each class's read_csv_(), so $draws(), $summary(), $print(),
$metadata(), $sampler_diagnostics() and $inv_metric() give the same
error, and $draws() no longer errors when the draws are already cached.
No NEWS entry: only the wording of that error changes.

New tests go through the public API: iter_warmup = 0 with
save_warmup = TRUE, a fit as init that failed or has different
parameters, $diagnostic_summary(quiet = TRUE), $loo(r_eff = TRUE),
$print(line_numbers = TRUE), format_stan_file() with canonicalize = TRUE and max_line_length, the release-candidate branch of
cmdstan_default_path(), a makefile without a version line, the knitr
engine's cache branches, save_object(format = "qs2") without qs2, the
pathfinder method in the shared fit tests, and the remaining draws-format
values. One existing test is fixed: it passed variables = to
posterior::subset_draws(), which ignores it, so the "draws_array
without lp__" test had been running with lp__ all along.

Left uncovered on purpose: the WSL helpers (the WSL job runs the checks,
not covr, and adding covr there would take about as long again), code
that needs a failing CmdStan build or download, and guards in the
stdout state machine for output CmdStan doesn't print.

Copyright and Licensing

Please list the copyright holder for the work you are submitting
(this will be you or your assignee, such as a university or company):
Jonah Gabry

By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses:

…sted

The v1.0 coverage review (rc-work/coverage-review.md) went through every
uncovered line. Some were checks nothing can reach: validate_exe_file()
runs after the model's own assert_current() has already caught a missing
executable, validate_build_record() rechecked a format_version that
read_build_record() checks before calling it, and the draws-format
helpers carried rvars cases that assert_valid_draws_format() rejects
first. Those go, along with .remove_leftmost_dim()'s branches for shapes
draws_of() never produces and an unused CmdStanProcs getter.

The guard against reading a fit whose chains all failed was repeated in
six public methods with three different messages. It now lives only in
each class's read_csv_(), which every reader reaches, so $draws(),
$summary(), $print(), $metadata(), $sampler_diagnostics() and
$inv_metric() give the same error, and the shared $draws() no longer
errors when the draws are already cached.

The new tests go through the public API. One existing test gets fixed:
it passed `variables =` to posterior::subset_draws(), which ignores it,
so the "draws_array without lp__" test had been running with lp__ all
along.

Part of #1258.
@jgabry jgabry added the internal-code Tests, code cleanup, refactoring, or other things not user facing label Sep 25, 2026
@jgabry jgabry changed the title Remove unreachable checks and and improve test coverage Remove unreachable checks and improve test coverage Sep 25, 2026
@codecov-commenter

codecov-commenter commented Sep 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.00000% with 3 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (v1.0@f4bb79c). Learn more about missing BASE report.

Files with missing lines Patch % Lines
R/fit.R 72.72% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             v1.0    #1291   +/-   ##
=======================================
  Coverage        ?   93.89%           
=======================================
  Files           ?       19           
  Lines           ?     7289           
  Branches        ?        0           
=======================================
  Hits            ?     6844           
  Misses          ?      445           
  Partials        ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

On Windows stanc ends its output lines with CRLF, and format() passes
that through, so capture.output() left a carriage return on each line
and the line that is exactly 30 characters long measured 31. Reading
the file format_stan_file() writes back with readLines() drops the
line terminator on every platform.

Part of #1258.
@jgabry
jgabry marked this pull request as ready for review September 26, 2026 16:30
@jgabry
jgabry merged commit 989d985 into v1.0 Sep 26, 2026
16 checks passed
@jgabry
jgabry deleted the coverage-review branch September 26, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal-code Tests, code cleanup, refactoring, or other things not user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants