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

   ### Which Issue(s) This PR Fixes
   
   - Fixes #6510
   
   ### Brief Description
   
   The demo data source's `exportGrafanaDashboard` answered an unknown uid with 
a fabricated
   `{ "uid": <uid> }` document (`web/src/services/grafanaService.ts:34-36`), 
while the endpoint it stands
   in for answers 404 — `GrafanaDashboardController.exportDashboard` reaches
   `GrafanaDashboardService.getDashboardJson`, which throws
   `BusinessException(404, "Grafana dashboard not found: " + uid)` — and 
`getGrafanaDashboard` in the
   same file already threw that message. `GrafanaDashboardList.handleExport` 
therefore downloaded
   `<uid>.json` containing only the uid and reported `grafana.exported`.
   
   The lookup is now shared by both functions through 
`getMockGrafanaDashboard`, which throws for an
   unknown uid, so the export takes the page's existing `grafana.exportFailed` 
branch. This is the same
   shape the alert-rule asset service already uses (`getMockAlertRuleAsset`, 
part of #6044), and it is
   the only remaining `found ? found.model : placeholder` lookup on the web 
side.
   
   User-visible change: in the demo data source, exporting a dashboard that is 
not in the inventory now
   reports a failure instead of downloading a stub file and claiming success. 
No copy is added.
   
   ### How Did You Test This Change?
   
   ```
   $ cd web && npx eslint src/services/grafanaService.test.ts 
src/services/grafanaService.ts
   # clean
   
   $ cd web && npx prettier --check src/services/grafanaService.test.ts 
src/services/grafanaService.ts
   # clean
   
   $ cd web && npx vitest run src/services/grafanaService.test.ts 
--maxWorkers=1 --fileParallelism=false
    ✓ src/services/grafanaService.test.ts (9 tests) 13ms
        ✓ rejects exporting an unknown dashboard uid in mock mode
    Test Files  1 passed (1)
         Tests  9 passed (9)
   
   $ cd web && npx tsc -b
   # clean
   ```
   
   The new test fails without the fix (this is the mutation check: the two 
lines that look the uid up
   without throwing are restored, the test is kept):
   
   ```
   $ cd web && npx vitest run src/services/grafanaService.test.ts 
--maxWorkers=1 --fileParallelism=false
    FAIL src/services/grafanaService.test.ts > grafanaService > rejects 
exporting an unknown dashboard uid in mock mode
   AssertionError: promise resolved "Blob{ …(1) }" instead of rejecting
    Test Files  1 failed (1)
         Tests  1 failed | 8 passed (9)
   ```
   
   The assertion is the 404 text the live endpoint returns for the same uid, so 
it only passes once the
   mock lookup throws; the six neighbouring cases (list, get, the mutable-state 
guard, the successful
   single export, the bulk export, and the two real-mode delegations) pin that 
the fix does not break a
   known dashboard.
   
   ### Checklist
   
   - [x] One coherent change; unrelated modifications are not bundled in
   - [x] Commit subject follows Conventional Commits (`feat:` / `fix:` / 
`refactor:` / `chore:` / `docs:` / `perf:`)
   - [x] Tests added or updated for non-trivial changes, test methods named 
`...Test`
   - [ ] New UI text has both Chinese and English entries under `web/src/i18n/`
   - [ ] Architecture constraints stay green (`mvn test` runs the ArchUnit 
checks)
   - [ ] New source files carry the ASF license header
   - [ ] Documentation touched where behaviour changed (README / `docs/` / 
in-app help)
   


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