Skip to content

test: reach 100% test coverage - #184

Merged
uniqueg merged 9 commits into
devfrom
test/179-full-coverage
Nov 14, 2026
Merged

uniqueg merged 9 commits into
devfrom
test/179-full-coverage

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Summary

Brings the unit and integration tests together to 100% of the lines and branches, and makes the build and Codecov enforce it.

Why Codecov showed ~74%: the JaCoCo exclusion of the models pointed to uk/ac/ebi/tsc/tesk/model, a package that no longer exists, so all generated models were measured. The exclusions now list exactly the files that openapi-generator generates (src/main/java/.openapi-generator/FILES, the list Spotless and Checkstyle already exclude) plus TeskApplication (its main only starts Spring Boot, which @SpringBootTest does too). The reasons are in pom.xml and docs/development.md.

Tests (behaviour, not just execution), among others:

  • every Kubernetes call turns errors into KubernetesExceptions; LimitRanges without a minimum; jobs without labels
  • service-client tokens: nested JWTs, discovery without jwks_uri, blank client claim, [::1], concurrent builds and refreshes of the keys, refusal reasons
  • which wrapper calls are traced (never createSecret, which carries credentials), and the trace of Kubernetes errors
  • User account flags, groups, toString and equality; an admin group named like the managers of a team
  • the executors' security context from the ConfigMap (defaults, missing key, empty YAML), FTP/executor Secret settings
  • task creation: minimum memory, exhausted name-collision retries; FULL view with and without pod logs
  • TRS errors, empty and non-2xx responses; service-info.yaml reload and invalid files
  • Swagger UI grant types and scopes; error handler status and validation messages; task view parsing

Code removed or simplified instead of tested (unreachable):

  • ServiceClientTokenServices: the status check after jose4j's Get (it throws for any status but 200); the re-check of the verifier under the lock is kept and now has a deterministic test
  • User: null checks of group sets (the builder always sets them), the unused no-arg constructor; equals/hashCode via Objects
  • TraceInterceptorConfiguration: empty @Pointcut methods replaced by expressions
  • CustomErrorHandler: the non-servlet branch (Spring MVC always passes ServletWebRequests)
  • TesServiceImpl: the always-true FULL check; ServiceInfoApiController.getRequest (only the generated default methods use it)
  • GroupNamesSecurityExtractor: identical if/else branches; KubernetesClientWrapper.listLimits inlined; private constructors for constants classes
  • KubernetesObjectsSupplier reads taskmaster.json once at startup instead of on every task

One intended behaviour change: if a task can't be serialized to JSON, TesKubernetesConverter now fails the creation (500) instead of logging and creating a job without the task's JSON, which could be neither run nor read back. Jackson doesn't fail on TES models in practice.

Enforcement: ./mvnw verify fails below 100% lines or branches (JaCoCo check on the merged data); codecov.yml sets project and patch targets to 100%. CI now sends Codecov one report of the merged data (target/site/jacoco-merged/jacoco.xml) instead of the unit and integration reports separately: JaCoCo XML has no branch identities, so Codecov couldn't combine a line's branches covered in part by each suite, and would disagree with the check. docs/development.md has a new "Test coverage" section (what is measured, the exclusions, how to see the merged report locally) and a note to keep the exclusions in sync when regenerating the stub.

Verification

  • ./mvnw clean verify (Java 21): 18547 unit tests, 114 integration tests, all pass (after merging dev with fix: select only executor jobs for a single task #183); "All coverage checks have been met"; merged report target/site/jacoco-merged/jacoco.xml: 2260/2260 lines, 797/797 branches
  • ./mvnw spotless:check checkstyle:check (Java 8, as the Lint job): pass
  • mkdocs build --strict: pass
  • CI on head a5a274a (after the Sourcery fix): all jobs pass (Lint, Test, Docs, Smoke test, Scan image, CI passed, CodeQL); Codecov project 100.00% (target 100%), patch 100.00%

Declined review findings

From the reviewer subagents (round 1; round 2 below):

  • Replace the unchecked/IoSupplier helper by inline handling: kept; one helper for both checked call sites (Jackson and gzip) is what lets the gzip path, which can't fail on a ByteArrayOutputStream, share the tested failure path. The behaviour change is stated above.
  • failingRefresh_isThrottled is timing-dependent (300 ms interval, 400 ms sleep): a test that predates this PR and isn't changed here; it hasn't flaked in CI so far.
  • Guard that the JaCoCo excludes match FILES: the stub-generation docs now say to update the exclusions of Spotless, Checkstyle and JaCoCo together; a test reading the pom is more machinery than a list that changes with a new TES version.
  • TesServiceImpl relies on the early returns for MINIMAL and BASIC (observation; the comment says so).
  • User serialization shape: the resource server is stateless and never deserializes User.
  • CustomErrorHandler casts to ServletWebRequest: Spring MVC always passes one (comment in the code).
  • Round 2: the race test replaces the private final buildLock by reflection, which JEP 500 restricts in Java versions after 21: the project is on Java 21 (pom, Dockerfile, CI); when it moves on, make the lock injectable through a package-private constructor.

From Sourcery:

  • A null groups claim became an authority named "null": fixed in a5a274a, with a regression test; this behaviour predates the PR.
  • Removing User's public no-arg constructor breaks external callers: declined; tesk-api is an application, nothing constructs User except through its builder, and the builder is what guarantees non-null group sets.

Open questions

None.

Closes #179

🤖 Generated with Claude Code

uniqueg and others added 7 commits November 14, 2026 22:22
Cover the remaining lines and branches of the config package with tests
of behaviour, and remove code that no request can reach:

- User: the builder sets all group sets, so the null checks are gone;
  equals and hashCode use Objects; the unused no-arg constructor is
  gone. Tests cover the account flags, groups, toString and equality.
- ServiceClientTokenServices: no status check after jose4j's Get, which
  throws for any status but 200; no second check of the verifier under
  the lock (a request that raced another one's build builds it again).
  Tests cover nested JWTs, a discovery document without jwks_uri, a
  blank client claim, [::1], concurrent builds and refreshes, and the
  refusal reasons.
- TraceInterceptorConfiguration: the pointcuts are expressions instead
  of empty @pointcut methods; tests check which wrapper calls are
  traced (never createSecret) and the trace of Kubernetes errors.
- GroupNamesSecurityExtractor: one path per claim shape.
- CustomErrorHandler: Spring MVC always passes ServletWebRequests.
- Tests for the Swagger UI's grant types and scopes, and for an admin
  group named like the managers of a team.

Refs #179

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cover the remaining lines and branches of the k8s package:

- TesKubernetesConverter: a task that can't be serialized now fails the
  creation instead of creating a job without the task's JSON, which
  could be neither run nor read; gzipping has no unreachable catch.
- KubernetesObjectsSupplier reads taskmaster.json once, at startup,
  instead of on every task (no unreachable IOException per task).
- KubernetesClientWrapper: minimumRamGb reads the LimitRanges directly.
- Constants classes get private constructors.
- Tests for errors of every Kubernetes call, LimitRanges without a
  minimum, jobs without labels, the executors' security context from
  the ConfigMap, the FTP and executor Secret settings, and the task
  data classes.

Refs #179

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cover the remaining lines and branches of the tes and trs packages:
the minimum memory of tasks, exhausted name collision retries, pod logs
that Kubernetes doesn't return, TRS errors and empty responses, the
reload of service-info.yaml, and the view parameter. Remove the check
for the FULL view, which is the only one left at that point, and the
getRequest override of ServiceInfoApiController, which only the
generated default methods use.

Refs #179

Co-Authored-By: Claude Opus 5.5 <[email protected]>
./mvnw verify now fails below 100% of the lines or branches of the
unit and integration tests together, and Codecov's project and patch
targets are 100%. The JaCoCo exclusion of the models pointed to a
package that no longer exists (uk/ac/ebi/tsc/tesk/model), so the
generated code was measured; it now excludes exactly the files that
openapi-generator generates (src/main/java/.openapi-generator/FILES,
also excluded from Spotless and Checkstyle) and TeskApplication, with
the reasons. The developer docs say how to read the merged report.

Closes #179

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review findings: a request that found no verifier just before another
one finished building it fetched the keys again, and was refused if
that fetch failed. It now uses the verifier built meanwhile, as before;
a test makes that race deterministic. The tests of concurrent fetches
wait 3 seconds instead of 1 for the slow responses, so that a stalled
runner doesn't fail them.

Refs #179

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov got the unit and integration reports separately; JaCoCo XML
has no branch identities, so a line whose branches the two suites
cover in part each would stay partial for Codecov while the JaCoCo
check, on the merged data, passes. The build now writes a report of the
merged data (target/site/jacoco-merged), and CI sends only that one.

Refs #179

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Round 2 review: clearer comments on the merged report in pom.xml and
ci.yml; the race test names the fields it reaches by reflection and
fails clearly if the verifier field is renamed.

Refs #179

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg self-assigned this Nov 14, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Make User group collections non-null by construction and simplify its equality and hashing around that invariant.

  • src/main/java/uk/ac/ebi/tsc/tesk/config/security/User.java L139-143, L326-338, L343-356 (+7 small edits)

API

Remove the controller’s redundant request accessor while preserving its service-info endpoint.

  • src/main/java/uk/ac/ebi/tsc/tesk/tes/api/ServiceInfoApiController.java L3-20 (4 small edits)

Implementation

Simplify MVC exception handling to use the servlet request Spring supplies, and add consistent validation and status responses.

  • src/main/java/uk/ac/ebi/tsc/tesk/config/CustomErrorHandler.java L137-139

Replace named tracing pointcuts with explicit expressions and retain Kubernetes response bodies in traces of Kubernetes exceptions.

  • src/main/java/uk/ac/ebi/tsc/tesk/config/TraceInterceptorConfiguration.java L13-19, L24-46 (+5 small edits)

Normalize group claims by handling null as no groups and reducing claim-shape conversion to a single path per shape.

  • src/main/java/uk/ac/ebi/tsc/tesk/config/security/GroupNamesSecurityExtractor.java L3 (removed lines), L30, L41-52

Avoid redundant verifier fetches after acquiring the build lock and rely on jose4j’s status handling for discovery responses.

  • src/main/java/uk/ac/ebi/tsc/tesk/config/security/ServiceClientTokenServices.java L298-312 (+4 small edits)

Load the taskmaster template once when constructing the supplier, then build each job from the cached JSON.

  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/KubernetesObjectsSupplier.java L62-65, L126-191 (+3 small edits)

Fail task conversion on JSON or gzip I/O errors instead of creating a job without usable task data.

  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverter.java L91-99, L148-163, L172-201 (+2 small edits)

Inline LimitRange listing in minimum-memory calculation and define zero as the fallback when Kubernetes refuses the request.

  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/service/KubernetesClientWrapper.java L15-204 (4 small edits)

Read executor pod logs for the remaining full-view path without replacing the compatibility empty stdout when Kubernetes returns no log.

  • src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImpl.java L243, L248-253

Prevent instantiation of the constants-only classes.

  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/constant/Constants.java L14-15
  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/constant/K8sConstants.java L10-11

Configuration

Configure CI to upload the merged JaCoCo report so Codecov evaluates the same combined test data as the build.

  • .github/workflows/ci.yml L144-147
  • codecov.yml L2-8, L13

Exclude only the listed generated OpenAPI classes and application entry point, enforce complete merged line and branch coverage, and produce a merged report.

  • pom.xml L285-318, L366-378 (+3 small edits)

Documentation

Document the merged coverage requirement, exclusions, local report locations, and keeping generated-code exclusions synchronized.

  • docs/development.md L52-74, L247-250

Tests

Add behavioral coverage for TRS failure, missing images, and non-success responses.

  • src/integration-test/java/uk/ac/ebi/tsc/tesk/trs/TrsToolClientIT.java L6-8, L21, L125-170

Cover servlet error responses and validation messages, trace pointcut matching and exception logging, and security-claim edge cases.

  • src/test/java/uk/ac/ebi/tsc/tesk/config/CustomErrorHandlerTest.java L18-23, L55-110 (+2 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/config/TraceInterceptorConfigurationTest.java L1-95
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/ElixirPrincipalExtractorTest.java L205-224
  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/GroupNamesSecurityExtractorTest.java L4, L52-76

Exercise service-client configuration failures, nested tokens, discovery edge cases, verifier and JWKS concurrency, and refusal-reason reporting.

  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/ServiceClientTokenServicesTest.java L107-126, L435-440, L658-785 (+4 small edits)

Test User account flags, group behavior, string representation, equality, and hash-code consistency.

  • src/test/java/uk/ac/ebi/tsc/tesk/config/security/UserTest.java L1-121

Verify Swagger OAuth grant selection and scope parsing.

  • src/test/java/uk/ac/ebi/tsc/tesk/config/swagger/SwaggerConfigAuthTest.java L1-71

Cover creator-label behavior without metadata maps and executor security-context lookup defaults and missing data.

  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/CreatorLabelsTest.java L88-92
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/KubernetesObjectsSupplierTest.java L1-94

Test FTP and executor-secret enablement, conversion failures, group fallback, executor logs, and task input views.

  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/TaskmasterEnvPropertiesTest.java L1-42
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverterMinimalTest.java L63-66, L691-818 (+5 small edits)

Cover single-task listing, output-filer jobs outside the current task list, and executor ordering and missing pods.

  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/data/SingleTaskStrategyTest.java L60-69
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/data/TaskListStrategyTest.java L107-117
  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/data/TaskTest.java L4, L66-84

Exercise LimitRange minima, jobs without labels, and Kubernetes error conversion across wrapper calls.

  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/service/KubernetesClientWrapperHttpTest.java L13-19, L191-264

Update the controller test for its simplified constructor and verify task-view parsing, service-info reload behavior, and task-creation edge cases.

  • src/test/java/uk/ac/ebi/tsc/tesk/tes/api/ServiceInfoApiControllerTest.java L32
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/service/ServiceInfoServiceTest.java L8-12, L18-21, L86-114 (+1 small edits)
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImplCreateTest.java L393-440
  • src/test/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImplSystemLogsTest.java L8, L27, L110-174

Other changes

Files not grouped.

  • src/test/java/uk/ac/ebi/tsc/tesk/tes/model/TaskViewTest.java L1-22

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (39011c4) to head (a5a274a).

Additional details and impacted files
@@             Coverage Diff              @@
##              dev      #184       +/-   ##
============================================
+ Coverage   77.61%   100.00%   +22.38%     
============================================
  Files          74        51       -23     
  Lines        3489      2262     -1227     
  Branches      416       254      -162     
============================================
- Hits         2708      2262      -446     
+ Misses        621         0      -621     
+ Partials      160         0      -160     

☔ 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.

@uniqueg
uniqueg marked this pull request as ready for review November 14, 2026 21:59
@sourcery-ai

sourcery-ai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit a5a274a

#179 test: reach 100% test coverage · 4 of 5 met · 1 to check by hand

# Requirement Status Notes
1 Find missed lines and branches in the merged reports, cover them with meaningful tests, and remove dead code. ✅ Met The change adds behavior-focused tests, removes unreachable code, and reports merged coverage of 2260/2260 lines and 797/797 branches.
2 Exclude only code that cannot be sensibly tested, and state the reason for each exclusion. ✅ Met JaCoCo excludes the generated OpenAPI files and TeskApplication; the configuration and developer documentation explain why.
3 Make CI fail if coverage drops below 100%. ✅ Met JaCoCo checks the merged report against 100% line and branch thresholds, and Codecov project and patch targets are 100%.
4 Codecov shows 100% project coverage on dev. 👀 Check by hand (external system) Check Codecov's project coverage for the dev branch; the PR description reports 100% for the merged PR head, not the current dev branch.
5 Document how to run the coverage report locally. ✅ Met The developer guide explains running ./mvnw clean verify and opening the merged report at target/site/jacoco-merged/index.html.

@sourcery-ai sourcery-ai 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.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/main/java/uk/ac/ebi/tsc/tesk/config/security/GroupNamesSecurityExtractor.java" line_range="48" />
<code_context>
         }
-        return StringUtils.collectionToCommaDelimitedString(authorities);
+        // a single group, e.g. a string of comma-separated names
+        return String.valueOf(object);
     }
 }
</code_context>
<issue_to_address>
**Null group claim becomes an authority**

When the user-info map contains the configured groups claim with a null value, `asAuthorities` turns the null claim into the literal string `"null"`; `extractAuthorities` then creates a `GrantedAuthority` with that name, and `ElixirPrincipalExtractor` stores it as a group instead of treating the claim as empty.

Handle null explicitly so it produces no authorities (or apply the intended missing-claim default).
</issue_to_address>

### Comment 2
<location path="src/main/java/uk/ac/ebi/tsc/tesk/config/security/User.java" line_range="75" />
<code_context>
      */
     private Set<String> teskManagedGroups;

-    public User() {}
-
     public String getName() {
</code_context>
<issue_to_address>
**Downstream user construction breaks**

When an external consumer instantiates `User` with its former public no-argument constructor, downstream code that calls `new User()` no longer compiles because the public no-argument constructor was removed and the remaining constructor is package-private.

Retain the public no-argument constructor if `User` is intended to remain constructible by external callers, or make the breaking API change explicit.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 2 findings to address first, and the changes affect JWT verification concurrency and how group claims are normalized into authorities, which determine whether requests are authenticated and which group-scoped tasks a user can access. If that handling is wrong, task access could be granted or denied; reverting restores the old logic but cannot undo any access or data exposure that already occurred.

Blocking findings: src/main/java/uk/ac/ebi/tsc/tesk/config/security/GroupNamesSecurityExtractor.java:48, src/main/java/uk/ac/ebi/tsc/tesk/config/security/User.java:75


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

A groups claim with a null value turned into an authority named
"null". It now yields no authorities. Found by Sourcery on #184; the
old code behaved the same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 45e3a7f into dev Nov 14, 2026
34 checks passed
@uniqueg
uniqueg deleted the test/179-full-coverage branch November 14, 2026 22:16
uniqueg added a commit that referenced this pull request Nov 14, 2026
Brings in #161, #174, #175, #176, #178, #181, #183 and #184. The
conflict in docs/upgrading.md is resolved by merging both lists under
"To 1.3.0": the upgrade order for filer labels and Java 21 come first,
and the TES 1.1 fields item no longer says that ignore_error: true is
refused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
uniqueg added a commit that referenced this pull request Nov 14, 2026
Lists the changes merged into dev since the notes were written:
Java 21 (#161), ignore_error (#174), the resource server (#175),
output file logs (#176), the Kubernetes client (#178), Dependabot
labels (#181), the executor job selector (#183) and full test coverage
(#184). Adds a Breaking changes section, as in the 1.2.0 notes, and
sets date-released to the planned tag date, 2026-11-16.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: reach 100% test coverage

1 participant