Skip to content

Fix for #2892 basePath with configuration - #2893

Merged
rrayst merged 4 commits into
masterfrom
configuration-basepath-fix-#2892
Mar 27, 2026
Merged

Fix for #2892 basePath with configuration#2893
rrayst merged 4 commits into
masterfrom
configuration-basepath-fix-#2892

Conversation

@predic8

@predic8 predic8 commented Mar 26, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes

    • Router startup ordering adjusted so configuration base location is set at the correct point during initialization.
  • Tests

    • Reorganized and expanded CLI tests; removed an old test and added new CLI tests that assert runtime behavior.
    • Added a test logging appender to capture and wait-for log messages.
    • Included sample YAML configuration and a simple OpenAPI spec to support testing.

@coderabbitai

coderabbitai Bot commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7c2272a0-a102-478c-b097-67c652bcbe5d

📥 Commits

Reviewing files that changed from the base of the PR and between 6e30291 and 1b2a2a7.

📒 Files selected for processing (2)
  • core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java
  • core/src/test/java/com/predic8/membrane/core/cli/RouterCLITest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java

📝 Walkthrough

Walkthrough

RouterCLI startup ordering changed: router base location is now set after registry startup to avoid being overwritten. Minor local-variable and return simplifications applied. Tests were reorganized and extended; a Log4j test appender and OpenAPI fixtures were added for integration-style tests.

Changes

Cohort / File(s) Summary
RouterCLI Initialization
core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java
Moved router.getConfiguration().setBaseLocation(location) to after reg.start() (changed visibility of initRouterByYAML to package-private static); replaced explicit local type with var in start.
OpenAPI Conversion
core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactory.java
Refactored convertPathToFileUriPathIfNeeded to return early for non-URL paths (removed redundant mutation).
Tests & Test Utilities
core/src/test/java/com/predic8/membrane/core/RouterCLITest.java (deleted), core/src/test/java/com/predic8/membrane/core/cli/RouterCLITest.java, core/src/test/java/com/predic8/membrane/test/TestAppender.java
Deleted old test class; added new RouterCLITest in cli package with log-waiting integration-style test; added TestAppender (Log4j2) to capture and await log messages.
Test Resources (OpenAPI)
core/src/test/resources/configuration/config.apis.yaml, core/src/test/resources/configuration/openapi/simple.oas.yml
Added YAML config referencing an OpenAPI file and a minimal OpenAPI spec used by the new tests.

Sequence Diagram(s)

sequenceDiagram
    participant CLI as RouterCLI
    participant YAML as YAML Parser
    participant Reg as Registry
    participant Router as Router Configuration

    CLI->>YAML: parse(location)
    YAML-->>Reg: register components from config
    Reg->>Reg: start registered components
    Reg-->>CLI: registry started
    CLI->>Router: setBaseLocation(location)  %% applied after registry start
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • christiangoerdes

Poem

🐰 Hopping through code with a bright little hop,
Base path waits patient till the registry stops,
Tests and OpenAPI tucked snug in their den,
Logs chant "running" — I nibble a carrot, and then I hop again!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix for #2892 basePath with configuration' directly references the issue being addressed and describes the main change (basePath fix with configuration), which aligns with the PR's objective of fixing basePath handling in configuration.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch configuration-basepath-fix-#2892

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@core/src/test/java/com/predic8/membrane/core/cli/RouterCLITest.java`:
- Around line 39-55: The test installs a root TestAppender and starts a
background Thread running RouterCLI.main without cleaning them up; wrap the
Logger/TestAppender and Thread lifecycle in a try/finally: start the Thread (t)
then in finally ensure the thread is signalled and waited on (e.g.,
t.interrupt() and t.join with a short timeout or set t as daemon) to avoid
background router activity, and remove/stop the appender from the root Logger
(logger.removeAppender(appender); appender.stop()) so global logging state is
restored; keep existing assertions like appender.awaitContainsOrThrow("running",
...) but perform the cleanup after the assertion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6f3894be-e224-430c-9ccf-477aadd50fb9

📥 Commits

Reviewing files that changed from the base of the PR and between d814d70 and 8f19cf1.

📒 Files selected for processing (6)
  • core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java
  • core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactory.java
  • core/src/test/java/com/predic8/membrane/core/RouterCLITest.java
  • core/src/test/java/com/predic8/membrane/core/cli/RouterCLITest.java
  • core/src/test/resources/configuration/config.apis.yaml
  • core/src/test/resources/configuration/openapi/simple.oas.yml
💤 Files with no reviewable changes (1)
  • core/src/test/java/com/predic8/membrane/core/RouterCLITest.java

Comment thread core/src/test/java/com/predic8/membrane/core/cli/RouterCLITest.java

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@core/src/test/java/com/predic8/membrane/core/cli/RouterCLITest.java`:
- Around line 37-55: The test starts RouterCLI.main in a background Thread (t)
and attaches a TestAppender to the root Logger but never stops the thread or
removes the appender, causing test pollution and resource leaks; modify the test
to ensure cleanup by stopping/removing the TestAppender from the Logger and
interrupting/stopping/joining the Thread (t) after the assertion (or in a
finally/@AfterEach), and if possible call RouterCLI shutdown/waitFor/stop method
on the router instance (or trigger graceful shutdown) so the background router
terminates before the test ends.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 261b62d3-e3d4-4759-9959-e88e6ff8cc7f

📥 Commits

Reviewing files that changed from the base of the PR and between d814d70 and 8f19cf1.

📒 Files selected for processing (6)
  • core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java
  • core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactory.java
  • core/src/test/java/com/predic8/membrane/core/RouterCLITest.java
  • core/src/test/java/com/predic8/membrane/core/cli/RouterCLITest.java
  • core/src/test/resources/configuration/config.apis.yaml
  • core/src/test/resources/configuration/openapi/simple.oas.yml
💤 Files with no reviewable changes (1)
  • core/src/test/java/com/predic8/membrane/core/RouterCLITest.java

Comment thread core/src/test/java/com/predic8/membrane/core/cli/RouterCLITest.java

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
core/src/test/java/com/predic8/membrane/test/TestAppender.java (1)

23-25: Do not expose mutable internal state directly

getMessages() returns the live list, so callers can mutate internal appender state. Returning a snapshot/read-only view keeps assertions deterministic.

Proposed refactor
 public List<String> getMessages() {
-    return messages;
+    return List.copyOf(messages);
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/src/test/java/com/predic8/membrane/test/TestAppender.java` around lines
23 - 25, The TestAppender.getMessages() currently exposes the mutable internal
List messages; change getMessages() in TestAppender to return an immutable
snapshot instead (e.g., return an unmodifiable view or a copy: use
List.copyOf(messages) or Collections.unmodifiableList(new
ArrayList<>(messages))) so callers cannot mutate internal state and tests remain
deterministic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@core/src/test/java/com/predic8/membrane/test/TestAppender.java`:
- Around line 31-42: The polling loop in awaitContains can miss messages that
arrive during the final sleep window; update awaitContains so it checks contains
immediately, then computes remaining time (deadline - System.nanoTime()), and if
remainingTime <= 0 returns false, otherwise sleeps for Math.min(50ms,
remainingTime) and repeats; reference the awaitContains method and the
contains(...) call and ensure you use remaining nanos->millis conversion when
calling Thread.sleep to avoid sleeping past the deadline.

---

Nitpick comments:
In `@core/src/test/java/com/predic8/membrane/test/TestAppender.java`:
- Around line 23-25: The TestAppender.getMessages() currently exposes the
mutable internal List messages; change getMessages() in TestAppender to return
an immutable snapshot instead (e.g., return an unmodifiable view or a copy: use
List.copyOf(messages) or Collections.unmodifiableList(new
ArrayList<>(messages))) so callers cannot mutate internal state and tests remain
deterministic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0f1e1e82-5330-405d-8980-b5fc8ae657a1

📥 Commits

Reviewing files that changed from the base of the PR and between 8f19cf1 and 2973525.

📒 Files selected for processing (1)
  • core/src/test/java/com/predic8/membrane/test/TestAppender.java

Comment thread core/src/test/java/com/predic8/membrane/test/TestAppender.java
@predic8
predic8 requested a review from rrayst March 26, 2026 21:19
@rrayst
rrayst merged commit d40b3a4 into master Mar 27, 2026
5 checks passed
@rrayst
rrayst deleted the configuration-basepath-fix-#2892 branch March 27, 2026 13:10
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