Skip to content

Conversation

@tcheeric
Copy link
Owner

Summary

  • ensure WebSocket handlers use unique keys relay:subscription
  • create handlers via a helper method
  • add a test for multiple subscriptions

Testing

  • mvn -q verify

https://chatgpt.com/codex/tasks/task_b_688a865ff7b88331af6affddbf1fe7bb

@tcheeric tcheeric requested a review from Copilot July 30, 2025 21:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes subscription key management in the Spring WebSocket client to ensure proper handler isolation for multiple subscriptions. The changes resolve issues where WebSocket handlers were being overwritten when creating multiple subscriptions by implementing unique relay:subscription keys.

  • Refactored createRequestClient method to use unique relay:subscription keys
  • Added a protected helper method for creating WebSocket client handlers
  • Implemented comprehensive test coverage for multiple subscription scenarios

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
NostrSpringWebSocketClient.java Refactored subscription key logic to use relay:subscription format and added handler creation helper method
NostrSpringWebSocketClientTest.java Replaced singleton tests with comprehensive multi-subscription test using reflection-based test infrastructure

Comment on lines +12 to +13
import sun.misc.Unsafe;

Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

Using sun.misc.Unsafe is discouraged as it's an internal JDK API that may not be available in all JVM implementations and could be removed in future versions. Consider using reflection-based alternatives or test frameworks like Mockito to create test instances instead.

Suggested change
import sun.misc.Unsafe;

Copilot uses AI. Check for mistakes.
NostrIF first = NostrSpringWebSocketClient.getInstance();
NostrIF second = NostrSpringWebSocketClient.getInstance();
assertSame(first, second, "Multiple calls should return the same instance");
private static WebSocketClientHandler createHandler(String name, String uri) throws Exception {
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

[nitpick] The createHandler method contains complex reflection logic that could be simplified. Consider using a builder pattern or factory method that doesn't require manual field manipulation, making the test more maintainable and less brittle to implementation changes.

Copilot uses AI. Check for mistakes.
Comment on lines +167 to +169
.filter(entry -> !entry.getKey().contains(":"))
.forEach(entry -> {
String requestKey = entry.getKey() + ":" + subscriptionId;
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

[nitpick] Using a magic string ":" for filtering could be error-prone. Consider defining a constant like SUBSCRIPTION_SEPARATOR to make the code more maintainable and self-documenting.

Suggested change
.filter(entry -> !entry.getKey().contains(":"))
.forEach(entry -> {
String requestKey = entry.getKey() + ":" + subscriptionId;
.filter(entry -> !entry.getKey().contains(SUBSCRIPTION_SEPARATOR))
.forEach(entry -> {
String requestKey = entry.getKey() + SUBSCRIPTION_SEPARATOR + subscriptionId;

Copilot uses AI. Check for mistakes.
@tcheeric tcheeric merged commit d07268d into develop Jul 30, 2025
@tcheeric tcheeric deleted the codex/generate-distinct-keys-for-subscriptions branch July 30, 2025 22:01
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