Skip to content

Code cleanups#1180

Merged
orpiske merged 21 commits into
wanaku-ai:mainfrom
orpiske:code-cleanups
May 22, 2026
Merged

Code cleanups#1180
orpiske merged 21 commits into
wanaku-ai:mainfrom
orpiske:code-cleanups

Conversation

@orpiske
Copy link
Copy Markdown
Contributor

@orpiske orpiske commented May 22, 2026

  • Cleanup duplicated health check code in the SDK
  • Cleanup duplicated data store label check code
  • Convert to local variables when possible
  • Removed call to printStackTrace
  • Removed commented code
  • Avoid calling deprecated URL APIs
  • Cleanup duplicated prompt parsing code
  • Break down bigger method
  • Use cleaner isEmpty checks
  • Remove redundant toString calls
  • Use simpler list calls for better performance
  • Remove redundant throws declarations
  • Simplify collection calls
  • Modernize the code and avoid outdated patterns and constructs
  • Simplify assertions
  • Avoid concatenation with empty String
  • Cleanup redundant type casts
  • Avoid redundant unmodifiables
  • Fixed incorrect table formatting
  • Fixed broken documentation references
  • Removed outdated test settings

Summary by Sourcery

Modernize CLI, backend, and SDK code by removing redundant constructs, centralizing shared logic, and tightening type/URL handling while keeping behavior intact.

Bug Fixes:

  • Fix incorrect markdown table layouts and broken documentation references in Helm and CLI documentation.
  • Correct label filtering and namespace tests to use stronger assertions and expectations.

Enhancements:

  • Refactor duplicated prompt argument parsing, data store label validation, and tool property mapping into shared helpers for reuse across commands.
  • Modernize various APIs and language features in CLI and backend (e.g., switch expressions, String/collection utilities, URL handling via URI, and simplified exception signatures).
  • Streamline health and readiness checks for gRPC capabilities via a shared helper and improve test assertions for health checks and URI helpers.
  • Remove unnecessary fields, deprecated patterns, and commented-out code across commands and tests to simplify the codebase and reduce noise.
  • Improve markdown table formatting and documentation links for Helm chart and CLI docs to render correctly and point to valid locations.

Documentation:

  • Reformat Markdown tables in Helm and label expression docs and fix CLI README links for clearer, correctly rendered documentation.

Tests:

  • Simplify and harden tests by removing unnecessary checked exceptions, improving assertions, and aligning with the updated health check and helper logic.

@orpiske orpiske requested a review from a team as a code owner May 22, 2026 13:35
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 22, 2026

Reviewer's Guide

Broad codebase cleanup and modernization: extracted shared health/CLI parsing logic, centralized repeated validation and health checks, modernized Java idioms (switch expressions, String/collection helpers, URL handling), simplified method signatures and assertions, and fixed documentation tables/paths.

File-Level Changes

Change Details Files
Centralize and reuse prompt argument parsing logic for CLI commands.
  • Extract prompt argument parsing from PromptsAdd into a reusable parsePromptArguments method and static doParse helper
  • Update PromptsEdit to reuse PromptsAdd.doParse for consistent argument parsing
  • Modernize multi-line @CommandLine.Option descriptions using Java text blocks for prompt-related commands
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/prompts/PromptsAdd.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/prompts/PromptsEdit.java
Deduplicate and centralize CLI capabilities and datastore label validation and display logic.
  • Extract datastore label expression validation into DataStoresLabelAdd.validateLabelExpression and reuse from DataStoresLabelRemove
  • Extract InputSchema-to-PropertyDisplay conversion into ToolsShow.toPropertyDisplays for reuse
  • Remove stored CapabilitiesService fields in several commands in favor of method-local variables and simplified signatures
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/datastores/DataStoresLabelAdd.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/datastores/DataStoresLabelRemove.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/tools/ToolsShow.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/capabilities/CapabilitiesShow.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/capabilities/CapabilitiesList.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/capabilities/CapabilitiesCleanup.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/capabilities/CapabilitiesStatus.java
Introduce shared gRPC health check helper and reuse it for capability health checks.
  • Create CapabilityChecks.grpcPortCheck to build HealthCheckResponse based on gRPC server port
  • Refactor CapabilityLivenessCheck and CapabilityReadinessCheck to delegate to grpcPortCheck instead of duplicating logic
  • Align CapabilityReadinessCheck tests to the new shared behavior
capabilities-quarkus-sdk/wanaku-capabilities-base/src/main/java/ai/wanaku/core/capabilities/common/CapabilityChecks.java
capabilities-quarkus-sdk/wanaku-capabilities-base/src/main/java/ai/wanaku/core/capabilities/common/CapabilityLivenessCheck.java
capabilities-quarkus-sdk/wanaku-capabilities-base/src/main/java/ai/wanaku/core/capabilities/common/CapabilityReadinessCheck.java
capabilities-quarkus-sdk/wanaku-capabilities-base/src/test/java/ai/wanaku/core/capabilities/common/CapabilityReadinessCheckTest.java
Modernize tests and assertions and remove redundant exception declarations.
  • Drop unnecessary 'throws Exception' from many test methods to simplify signatures
  • Replace assertTrue(x == CONST) and assertEquals(true, ...) patterns with assertSame/assertTrue/assertFalse/assertNull for clarity
  • Remove redundant or duplicate assertions in repository tests
apps/wanaku-router-backend/src/test/java/ai/wanaku/backend/api/v1/servicecatalog/ServiceCatalogResourceTest.java
apps/wanaku-router-backend/src/test/java/ai/wanaku/backend/health/InfinispanReadinessCheckTest.java
apps/wanaku-router-backend/src/test/java/ai/wanaku/backend/health/OidcReadinessCheckTest.java
capabilities-quarkus-sdk/wanaku-capabilities-base/src/test/java/ai/wanaku/core/capabilities/provider/AbstractResourceDelegateTest.java
capabilities-quarkus-sdk/wanaku-capabilities-base/src/test/java/ai/wanaku/core/capabilities/tool/AbstractToolDelegateTest.java
core/core-services-api/src/test/java/ai/wanaku/core/services/api/ToolsetRepoIndexTest.java
core/core-services-api/src/test/java/ai/wanaku/core/services/api/ServiceCatalogIndexTest.java
core/core-util/src/test/java/ai/wanaku/core/uri/URIHelperTest.java
apps/wanaku-cli/src/test/java/ai/wanaku/cli/main/commands/namespaces/NamespacesCreateTest.java
apps/wanaku-cli/src/test/java/ai/wanaku/cli/main/commands/namespaces/NamespacesUpdateTest.java
apps/wanaku-router-backend/src/test/java/ai/wanaku/backend/core/persistence/infinispan/LabelFilteringIntegrationTest.java
apps/wanaku-router-backend/src/test/java/ai/wanaku/backend/core/persistence/infinispan/DataStoreRepositoryTest.java
apps/wanaku-router-backend/src/test/java/ai/wanaku/backend/api/v1/datastores/DataStoresResourceTest.java
Modernize CLI/core implementation details and remove deprecated/verbose patterns.
  • Switch URLConverter and Downloader to build URLs via URI.create(...).toURL() instead of deprecated URL constructors
  • Use switch expressions, String.formatted, Objects.requireNonNullElse, StringBuilder, String#isEmpty, and type inference-friendly TypeReference<>()
  • Remove redundant toString(), Collections.unmodifiableMap, and pre-declared service fields in favor of local variables and immutable Map.of
  • Simplify AuthenticationInterceptor.filter and WanakuPrinter internals (no checked exceptions for filter/read, generic TypeReference)
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/converter/URLConverter.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/support/Downloader.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/support/AuthenticationInterceptor.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/support/WanakuPrinter.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/configure/ConfigureMcpClientCommand.java
apps/wanaku-router-backend/src/main/java/ai/wanaku/backend/bridge/InvokerToolExecutor.java
apps/wanaku-router-backend/src/main/java/ai/wanaku/backend/api/v2/codeexecution/CodeExecutionBean.java
apps/wanaku-router-backend/src/main/java/ai/wanaku/backend/bridge/transports/grpc/GrpcTransport.java
apps/wanaku-router-backend/src/main/java/ai/wanaku/backend/common/PromptExpander.java
capabilities/tools/wanaku-tool-service-exec/src/main/java/ai/wanaku/tool/exec/ExecCommandPolicy.java
capabilities/tools/wanaku-tool-service-exec/src/test/java/ai/wanaku/tool/exec/ExecClientSecurityTest.java
capabilities-quarkus-sdk/wanaku-capabilities-base/src/main/java/ai/wanaku/core/capabilities/common/AuthConfigSource.java
apps/wanaku-router-backend/src/main/java/ai/wanaku/backend/api/v1/forwards/ForwardToolHelper.java
Align CLI command entrypoints and handlers to consistent signatures and behavior.
  • Remove broad 'throws Exception'/IOException from most CLI command doCall implementations that don't actually throw checked exceptions
  • Convert various class fields (e.g., CapabilitiesService instances) to method-local variables for simpler lifecycle and thread safety
  • Remove printStackTrace in AuthLogin and rely on user-friendly error messages
  • Fix small table-printing bug in CapabilitiesCleanup by avoiding incorrect use of String.repeat
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/CliMain.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/admin/Admin.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/auth/*.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/capabilities/*.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/completion/*.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/configure/*.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/credentials/*.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/datastores/*.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/forwards/*.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/man/*.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/namespaces/*.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/prompts/*.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/realm/*.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/resources/*.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/service/*.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/start/*.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/tools/*.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/toolset/*.java
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/users/*.java
Cleanup duplicated markdown/tables and documentation paths and remove stale config.
  • Fix Helm values README table formatting for Wanaku operator to use proper markdown columns
  • Clean up LABEL_EXPRESSIONS.md operator tables for consistent column alignment
  • Fix broken relative link paths in wanaku-cli README and drop trailing no-newline marker
  • Remove obsolete application.properties test settings file
apps/wanaku-operator/deploy/helm/wanaku-operator/README.md
apps/wanaku-cli/src/main/resources/docs/LABEL_EXPRESSIONS.md
apps/wanaku-cli/README.md
core/core-util/src/test/resources/application.properties
Refactor Kubernetes Operator reconcilers to simpler method signatures.
  • Remove checked Exception from WanakuCapabilityReconciler.reconcile signature
  • Remove checked Exception from WanakuRouterReconciler.reconcile and WanakuServiceCatalogReconciler.reconcile signatures for cleaner API usage
apps/wanaku-operator/src/main/java/ai/wanaku/operator/wanaku/WanakuCapabilityReconciler.java
apps/wanaku-operator/src/main/java/ai/wanaku/operator/wanaku/WanakuRouterReconciler.java
apps/wanaku-operator/src/main/java/ai/wanaku/operator/wanaku/WanakuServiceCatalogReconciler.java
Modernize Markdown rendering and custom node dispatch.
  • Use List.of instead of Arrays.asList when building Flexmark parser extensions
  • Replace chained instanceof checks in MarkdownRenderer.CustomNode visitor with a modern pattern-matching switch for custom table nodes
apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/support/MarkdownRenderer.java

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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 3 issues, and left some high level feedback:

  • In CapabilitiesCleanup.printSimpleTable, replacing separator.append("-".repeat(widths[i])) with separator.repeat("-", widths[i]) introduces a compile error because StringBuilder has no repeat method; this should be reverted or implemented via append("-".repeat(widths[i])) or a small helper.
  • The pattern-matching switch in MarkdownRenderer.visit(CustomNode) (e.g., switch (customNode) { case TableHead tableHead -> ... }) relies on newer Java pattern-matching semantics; please confirm the project’s target JDK supports this or fall back to instanceof checks to avoid compatibility issues.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In CapabilitiesCleanup.printSimpleTable, replacing `separator.append("-".repeat(widths[i]))` with `separator.repeat("-", widths[i])` introduces a compile error because StringBuilder has no `repeat` method; this should be reverted or implemented via `append("-".repeat(widths[i]))` or a small helper.
- The pattern-matching switch in MarkdownRenderer.visit(CustomNode) (e.g., `switch (customNode) { case TableHead tableHead -> ... }`) relies on newer Java pattern-matching semantics; please confirm the project’s target JDK supports this or fall back to `instanceof` checks to avoid compatibility issues.

## Individual Comments

### Comment 1
<location path="apps/wanaku-cli/src/main/java/ai/wanaku/cli/main/commands/capabilities/CapabilitiesCleanup.java" line_range="197" />
<code_context>
         for (int i = 0; i < widths.length; i++) {
             if (i > 0) separator.append("-+-");
-            separator.append("-".repeat(widths[i]));
+            separator.repeat("-", widths[i]);
         }
         System.out.println(separator);
</code_context>
<issue_to_address>
**issue (bug_risk):** StringBuilder has no repeat method, causing a compilation failure here.

`StringBuilder`/`StringBuffer` don’t define `repeat`, so this change won’t compile. Use `separator.append("-".repeat(widths[i]));` as before, or add a small helper to append a character `widths[i]` times.
</issue_to_address>

### Comment 2
<location path="capabilities-quarkus-sdk/wanaku-capabilities-base/src/main/java/ai/wanaku/core/capabilities/common/CapabilityChecks.java" line_range="11-16" />
<code_context>
+     * Creates a new response build for checking the grpc port
+     * @param grpcServer The gRPC server instance
+     * @param name the check name
+     * @return a new HealtCheckResponse
+     */
+    static HealthCheckResponse grpcPortCheck(GrpcServer grpcServer, String name) {
</code_context>
<issue_to_address>
**nitpick (typo):** Minor typo and wording issue in the Javadoc for grpcPortCheck.

The Javadoc currently says `Creates a new response build` and `HealtCheckResponse`. Please update the description to something like `Creates a new health check response for the gRPC server port` and fix the return tag to `@return a new HealthCheckResponse` for clarity and correctness.

```suggestion
    /**
     * Creates a new health check response for the gRPC server port
     * @param grpcServer The gRPC server instance
     * @param name the check name
     * @return a new HealthCheckResponse
     */
```
</issue_to_address>

### Comment 3
<location path="apps/wanaku-operator/deploy/helm/wanaku-operator/README.md" line_range="16-25" />
<code_context>
+| `app.livenessProbe.httpGet.scheme`                                            | The http schema to use for the probe.                | HTTP                                  |
</code_context>
<issue_to_address>
**issue (typo):** Use "HTTP scheme" instead of "http schema" in the probe descriptions.

For `app.livenessProbe.httpGet.scheme`, `app.readinessProbe.httpGet.scheme`, and `app.startupProbe.httpGet.scheme`, “schema” is incorrect in this HTTP context. Please update the text to refer to the “HTTP scheme” instead (e.g., “The HTTP scheme to use for the probe.”).

Suggested implementation:

```
| `app.livenessProbe.httpGet.scheme`                                            | The HTTP scheme to use for the probe.                | HTTP                                  |

```

```
| `app.readinessProbe.httpGet.scheme`                                           | The HTTP scheme to use for the probe.                | HTTP                                  |

```

The same wording likely exists for `app.startupProbe.httpGet.scheme` elsewhere in this README (or a related values/README file). Apply the same replacement there:

- Change “The http schema to use for the probe.” to “The HTTP scheme to use for the probe.”

If there are other occurrences of “http schema” in this file or related chart docs, they should also be updated for consistency.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +11 to +16
/**
* Creates a new response build for checking the grpc port
* @param grpcServer The gRPC server instance
* @param name the check name
* @return a new HealtCheckResponse
*/
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nitpick (typo): Minor typo and wording issue in the Javadoc for grpcPortCheck.

The Javadoc currently says Creates a new response build and HealtCheckResponse. Please update the description to something like Creates a new health check response for the gRPC server port and fix the return tag to @return a new HealthCheckResponse for clarity and correctness.

Suggested change
/**
* Creates a new response build for checking the grpc port
* @param grpcServer The gRPC server instance
* @param name the check name
* @return a new HealtCheckResponse
*/
/**
* Creates a new health check response for the gRPC server port
* @param grpcServer The gRPC server instance
* @param name the check name
* @return a new HealthCheckResponse
*/

Comment on lines +16 to +25
| `app.livenessProbe.httpGet.scheme` | The http schema to use for the probe. | HTTP |
| `app.livenessProbe.initialDelaySeconds` | The amount of time to wait before starting to probe. | 5 |
| `app.livenessProbe.periodSeconds` | The period in which the action should be called. | 10 |
| `app.livenessProbe.successThreshold` | The success threshold to use. | 1 |
| `app.livenessProbe.timeoutSeconds` | The amount of time to wait for each action. | 10 |
| `app.ports.http` | The http port to use for the probe. | 8081 |
| `app.readinessProbe.failureThreshold` | The failure threshold to use. | 3 |
| `app.readinessProbe.httpGet.path` | The http path to use for the probe. | /q/health/ready |
| `app.readinessProbe.httpGet.scheme` | The http schema to use for the probe. | HTTP |
| `app.readinessProbe.initialDelaySeconds` | The amount of time to wait before starting to probe. | 5 |
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (typo): Use "HTTP scheme" instead of "http schema" in the probe descriptions.

For app.livenessProbe.httpGet.scheme, app.readinessProbe.httpGet.scheme, and app.startupProbe.httpGet.scheme, “schema” is incorrect in this HTTP context. Please update the text to refer to the “HTTP scheme” instead (e.g., “The HTTP scheme to use for the probe.”).

Suggested implementation:

| `app.livenessProbe.httpGet.scheme`                                            | The HTTP scheme to use for the probe.                | HTTP                                  |

| `app.readinessProbe.httpGet.scheme`                                           | The HTTP scheme to use for the probe.                | HTTP                                  |

The same wording likely exists for app.startupProbe.httpGet.scheme elsewhere in this README (or a related values/README file). Apply the same replacement there:

  • Change “The http schema to use for the probe.” to “The HTTP scheme to use for the probe.”

If there are other occurrences of “http schema” in this file or related chart docs, they should also be updated for consistency.

@orpiske orpiske merged commit 2cac7c9 into wanaku-ai:main May 22, 2026
5 checks passed
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.

2 participants