btlqql opened a new pull request, #4695:
URL: https://github.com/apache/rocketmq-dashboard/pull/4695

   <!-- Base branch: `rocketmq-studio`, the RocketMQ Studio trunk. -->
   
   ### Brief Description
   
   `MessageService.queryMessageByUniqueKey` (the UNIQ_KEY lookup behind the 
`rmq.message.query` AI
   tool, `MessageQueryToolHandler`) forwarded `startTime`/`endTime` to the 
provider unvalidated. Every
   other message query rejects a broken window in the service - `queryMessages` 
via
   `validateTopicQueryWindow` ("message query timestamps must not be negative", 
"startTime must be
   before endTime"), and `RocketMQMessageProvider` re-checks `begin >= end` for 
the topic/key branches:
   
   ```java
   // MessageService.java:71 (before)
   if (!StringUtils.hasText(uniqueKey)) {
       throw new BusinessException(400, "uniqueKey is required");
   }
   log.info("Querying message by unique key: topic={}, uniqueKey={}", topic, 
uniqueKey);
   return messageProvider.queryMessageByUniqueKey(instanceId, topic, uniqueKey, 
startTime, endTime);
   ```
   
   The unique-key branch is the one path with no guard on either layer
   (`RocketMQMessageProvider.queryMessageByUniqueKey` only defaults a missing 
endpoint and then calls
   `adminExt.queryMessageByUniqKey(..., begin, end)`), so an inverted window 
was sent to the broker as
   an inverted range: the broker answers `NO_MESSAGE`, the provider maps that 
to an empty list and the
   caller is told "no messages found" for a request that was really malformed. 
A negative timestamp
   queried the store from epoch-1 in the same way.
   
   The window is now validated before the provider is called, reusing the 
messages the topic path
   already returns. The window itself stays optional: a UNIQ_KEY lookup without 
a window still
   delegates unchanged (the provider keeps its own default recent range), and a 
single-sided window is
   still accepted.
   
   ### How Did You Test This Change?
   
   New tests in `MessageServiceTest` 
(`uniqueKeyQueryRejectsInvertedTimeWindowBeforeCallingProviderTest`,
   `uniqueKeyQueryRejectsNegativeTimeWindowBeforeCallingProviderTest`, plus
   `uniqueKeyQueryKeepsTheTimeWindowOptionalTest` / 
`uniqueKeyQueryAcceptsASingleSidedTimeWindowTest` as
   guards that the window stays optional).
   
   Before the fix (red) - the service returned `null` from the mock provider 
instead of rejecting the
   window:
   
   ```
   $ cd server && mvn -B -ntp test -Dtest=MessageServiceTest
   [ERROR] Tests run: 23, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 
2.178 s <<< FAILURE! -- in 
org.apache.rocketmq.studio.instance.message.MessageServiceTest
   [ERROR] 
org.apache.rocketmq.studio.instance.message.MessageServiceTest.uniqueKeyQueryRejectsInvertedTimeWindowBeforeCallingProviderTest
 -- Time elapsed: 0.029 s <<< FAILURE!
   [ERROR] 
org.apache.rocketmq.studio.instance.message.MessageServiceTest.uniqueKeyQueryRejectsNegativeTimeWindowBeforeCallingProviderTest
 -- Time elapsed: 0.005 s <<< FAILURE!
   [ERROR]   
MessageServiceTest.uniqueKeyQueryRejectsInvertedTimeWindowBeforeCallingProviderTest:364
   [ERROR]   
MessageServiceTest.uniqueKeyQueryRejectsNegativeTimeWindowBeforeCallingProviderTest:378
   Expecting code to raise a throwable.
   ```
   
   After the fix (green) - the whole class:
   
   ```
   $ cd server && mvn -B -ntp test -Dtest=MessageServiceTest
   [INFO] Tests run: 23, Failures: 0, Errors: 0, Skipped: 0
   [INFO] BUILD SUCCESS
   ```
   
   `mvn test` runs checkstyle in the `validate` phase: `You have 0 Checkstyle 
violations.`
   
   Note on the full suite: on a clean `rocketmq-studio` checkout `mvn -B -ntp 
test` already reports
   `Tests run: 3051, Failures: 6, Errors: 25, Skipped: 4`. The 11 red classes 
are the MySQL 8 backed
   Spring integration tests (`AuthServiceBootstrapIntegrationTest`,
   `AuthServiceConcurrencyIntegrationTest`, 
`AuthServiceSessionOverviewIntegrationTest`,
   `HealthProbeIntegrationTest`, `QueryHistoryServiceIntegrationTest`,
   `NativeAlertEvaluationTransactionTest`, 
`NotificationOutboxMapperIntegrationTest`,
   `RmqAlertStateMapperIntegrationTest`, `StudioApplicationTest`) plus the 
external-CLI ones
   (`CliAgentProviderTest`, `ClaudeCodeAgentProviderTest`). None of them are 
touched by this change.
   
   ### Checklist
   
   - [x] One coherent change; unrelated modifications are not bundled in
   - [x] Commit subject follows Conventional Commits (`fix:`)
   - [x] Tests added or updated for non-trivial changes, test methods named 
`...Test`
   - [x] New UI text has both Chinese and English entries under `web/src/i18n/` 
(no UI text in this change)
   - [x] Architecture constraints stay green (`mvn test` runs the ArchUnit 
checks)
   - [x] New source files carry the ASF license header (no new files)
   - [x] Documentation touched where behaviour changed (no user-visible 
contract change: a malformed time window was never a supported request)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to