Skip to content

chore(coverage): close every reachable coverage gap in lib - #933

Merged
yordis merged 8 commits into
masterfrom
yordis/chore-cover-mock-semconv-gaps
Aug 31, 2026
Merged

chore(coverage): close every reachable coverage gap in lib#933
yordis merged 8 commits into
masterfrom
yordis/chore-cover-mock-semconv-gaps

Conversation

@yordis

@yordis yordis commented Aug 31, 2026

Copy link
Copy Markdown
Member
  • Line coverage across lib/ was 96.3%, and every uncovered line was a branch a caller can reach. An untested branch is a branch a regression can break silently, so the suite was not actually guarding them.
  • The repository total is now 99.1%. Every remaining gap is a clause that cannot run against the dependency versions pinned here: gun 1.x compatibility fallbacks that the "Test (Gun 1)" job does exercise, a Finch pre-0.22 error shape, hackney 4.x, and a {:data_error, _} that OTP 24 through 28 never raise.
  • Four clauses turned out to be unreachable rather than untested, so they were removed instead of being papered over with a test that could not exist:
    • sem_conv.ex had an extract_port/1 clause for scheme: "https" with a non-integer port. URI.parse/1 always fills the scheme default port, verified across eleven URL shapes including https://host:/p, https://host:abc/p and https://host:-1/p, all of which yield 443.
    • test.ex had a catch-all encode!/2. Its only call site passes the literal "application/json", and the two application/json clauses are total.
    • mock.ex had a raise other fallback in agent_set/1. start_supervised/2 returns only {:ok, pid} or {:error, {:already_started, pid}} there, so the clause was both dead and latently broken: raise on a tuple raises ArgumentError about raise/1 rather than the intended error.
    • The httpc adapter had a fallback for a multipart request without a content-type header. Multipart.headers/1 always returns one, so List.keytake/3 can never miss.
  • Every new test was checked by mutation testing rather than by coverage alone. Coverage proves a line ran; it does not prove an assertion would notice if the line changed. Fifty two mutants were applied across the touched modules and all fifty two were caught, with one exception that was triaged as equivalent: deleting the max_retries: 0 shortcut in retry.ex changes nothing observable, because put_retry_count_opt/2 is already a no-op at retries: 0.
  • Two of those mutants only died after the tests were rewritten, which is the point of running them: the httpc and ibrowse binary body tests passed while the adapter appended a trailing space, and the gun connection reuse tests passed while the scheme comparison was deleted outright.

@yordis
yordis requested a review from a team as a code owner August 31, 2026 08:13
Copilot AI lite review requested due to automatic review settings August 31, 2026 08:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@cursor

cursor Bot commented Aug 31, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Changes are almost entirely tests plus removal of unreachable library branches; runtime behavior for supported call paths should be unchanged.

Overview
This PR raises lib/ test coverage by exercising reachable branches across adapters, middleware, mocks, and core Tesla behavior, and deletes three clauses that could never run instead of adding fake tests for them.

Production tweaks (dead code only): Tesla.Mock no longer has a broken raise other fallback when the global mock Agent fails to start; OpenTelemetry extract_port/1 drops a redundant https → 443 clause because URI.parse/1 already supplies an integer port; Tesla.Test.encode!/2 loses an unused catch-all since callers always pass "application/json".

New / expanded tests guard real edge paths: Finch (invalid :response, non-HTTP responses, chunked trailers) and Gun (reused conn on wrong port/scheme, stream errors to multiple owners, monitor :killed, retry while connections flap) via raw TCP helpers; httpc/ibrowse binary body passthrough; middleware error passthrough and encoding options (JSON/MessagePack streams and custom encode/decode, Logger OTel with charlist URLs and :default log level, Query empty-map merge rules, Retry with max_retries: 0, SSE id/retry, PathParams missing values); Mock global replacement and registered $ancestors; plus smaller cases for multipart header validation, Tesla.effective_adapter/1 app config, builder deprecation stderr, and anonymous function middleware in Tesla.run/2.

Reviewed by Cursor Bugbot for commit 30d0fe9. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions github-actions Bot added the chore label Aug 31, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a489671. Configure here.

Comment thread test/tesla/middleware/logger_test.exs
@yordis yordis changed the title chore(test): cover the reachable gaps in mock and semantic convention attributes chore(coverage): bring mock, test and semantic convention modules to full coverage Aug 31, 2026
@yordis yordis changed the title chore(coverage): bring mock, test and semantic convention modules to full coverage chore(coverage): close every reachable coverage gap outside the adapters Aug 31, 2026
@yordis yordis changed the title chore(coverage): close every reachable coverage gap outside the adapters chore(coverage): close every reachable coverage gap in lib Aug 31, 2026
@yordis
yordis force-pushed the yordis/chore-cover-mock-semconv-gaps branch from e07f178 to 37bc7be Compare August 31, 2026 15:25
@yordis
yordis changed the base branch from master to yordis/fix-httpc-multipart-content-type August 31, 2026 15:25
Base automatically changed from yordis/fix-httpc-multipart-content-type to master August 31, 2026 17:21
@github-actions github-actions Bot added the bug label Aug 31, 2026
yordis added 8 commits August 31, 2026 13:23
… attributes

These branches guard mock lookup through a registered ancestor, global mock replacement, and a malformed env, none of which had a test pinning them.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Each one is shadowed by a total set of preceding clauses, so it could never run and kept its module below full coverage while looking like live code.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Every one of these lines is a path a caller can reach, so leaving them
unexercised meant a regression in them would ship silently.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Everything in lib/ except the adapter implementations is now exercised, so
a regression in these paths fails the suite instead of shipping quietly.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
The connection reuse guard compares scheme, host and port, and none of
the three was pinned down on its own before, so a dropped comparison
would have gone unnoticed.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
gun 1 names the tls options differently and reports a richer close
reason, so the assertions had to stop assuming the gun 2 shapes.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
A nil url made the Logger emit a chardata truncation error in place of
the summary line, which left the assertions unable to tell a skipped
attribute from a lost log line.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis
yordis force-pushed the yordis/chore-cover-mock-semconv-gaps branch from 37bc7be to 30d0fe9 Compare August 31, 2026 17:24
@github-actions github-actions Bot removed the bug label Aug 31, 2026
@yordis
yordis merged commit 1c79381 into master Aug 31, 2026
16 of 23 checks passed
@yordis
yordis deleted the yordis/chore-cover-mock-semconv-gaps branch August 31, 2026 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants