Skip to content

[AAASM-3512] ♻️ (dashboard): Harden Overview page — Sonar fixes + tests#1188

Merged
Chisanan232 merged 7 commits into
masterfrom
v0.0.1/AAASM-3512/refactor/overview_sonar_tests
Jun 21, 2026
Merged

[AAASM-3512] ♻️ (dashboard): Harden Overview page — Sonar fixes + tests#1188
Chisanan232 merged 7 commits into
masterfrom
v0.0.1/AAASM-3512/refactor/overview_sonar_tests

Conversation

@Chisanan232

Copy link
Copy Markdown
Contributor

Description

Refactor-only hardening of the dashboard Overview page to clear the four
SonarCloud Reliability/Maintainability issues flagged on
dashboard/src/pages/OverviewPage.tsx, plus broader test coverage. No behaviour
change to the page — rendered output is identical.

SonarCloud rules fixed:

Line Rule Fix
L131 typescript:S4624 (nested template literals) Hoisted the inner ${TONE_CLASS[...]} template into a named toneClass const in LayerCard.
L169 typescript:S3776 (Cognitive Complexity 18 > 15) Extracted the pure KPI/score/alert derivations into deriveOverviewKpis + compareBySeverity in a sibling OverviewPage.kpis.ts module, and pulled the recent-decisions row into a RecentDecisionRow component. The component now destructures one helper result.
L191 typescript:S3735 (void operator) Replaced void agentsQuery.refetch() with the repo's existing ignorePromise(...) helper (already used by every other page) — satisfies no-floating-promises, swallows unexpected rejections, tolerates the test mock's undefined return.
L239 typescript:S6772 (ambiguous JSX spacing) Added explicit {' '} between "Overview" and the zh subtitle <span> in the <h1>.

Note: the helper was placed in a sibling .ts module (matching the repo's
fleetTypes / fleetFilters pattern) rather than exported from the component
file, because react-refresh/only-export-components forbids non-component
exports there. This also makes the pure derivation directly unit-testable.

Type of Change

  • ♻️ Refactoring

Breaking Changes

  • No

Related Issues

  • Related Jira ticket: AAASM-3512

Testing

  • Unit tests added / updated

Tests added:

  • OverviewPage.kpis.test.ts (new, 9 cases) — deriveOverviewKpis branches:
    empty-fleet total === 0 full-score posture, mode/flag counting, identity &
    capability score degradation, identity clamp-at-zero, blocked/scrubbed
    null-as-zero summation, FIRING-only filtering + most-severe top-alert,
    no-firing undefined case; plus compareBySeverity ordering and the
    equal-severity (0) branch.
  • OverviewPage.test.tsx (extended, +14 cases) — default 24h window + all four
    window-toggle states (1h/24h/7d/30d) asserting single-active + subtitle echo;
    singular/plural/healthy hero posture messages; fleet-snapshot mode/flag tile
    derivations; recent-decisions severity→decision mapping (deny/narrow/scrub)
    with agentId-vs-fleet rendering; empty recent note; approvals clear-vs-awaiting
    copy; fleet-wide top-issue with active-policy count. (loading/error/empty
    states were already covered and remain green.)

Local validation (all green):

  • pnpm type-check — clean
  • pnpm lint (--max-warnings 0) — clean
  • pnpm build — succeeds (pre-existing chunk-size warnings only)
  • pnpm test148 files / 1326 tests passed (Overview suite: 22 + KPI suite: 9)

Checklist

  • Self-review of the diff completed
  • All local checks passing
  • Commits are small and follow the Gitmoji convention

🤖 Generated with Claude Code

Chisanan232 and others added 7 commits June 21, 2026 14:07
Resolves SonarCloud typescript:S4624 in the Overview LayerCard: the inner
`${...}` template was nested inside the className template literal. Hoist it to
a named `toneClass` const. No behaviour change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Resolves SonarCloud typescript:S6772: the whitespace between "Overview" and the
zh subtitle <span> was implicit (collapsed JSX text). Make the intended single
space explicit with `{' '}`. Rendered output is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Resolves SonarCloud typescript:S3735: the error-state retry handler discarded
the refetch() promise with the `void` operator. Use the repo's `ignorePromise`
helper (already used by every other page) — it satisfies no-floating-promises,
swallows unexpected rejections, and tolerates the test mock's undefined return.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Resolves SonarCloud typescript:S3776 (Cognitive Complexity 18 > 15) in
OverviewPage. Move the pure KPI/score/alert derivations into a side-effect-free
`deriveOverviewKpis` helper, hoist the alert sort comparator (`compareBySeverity`
+ `SEVERITY_RANK`) out of the component, and extract the recent-decisions row
into a `RecentDecisionRow` component. The component now destructures one helper
result. No behaviour change — rendered output is identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Extract `deriveOverviewKpis` + `compareBySeverity` + `OverviewKpis` into a plain
`OverviewPage.kpis.ts` module (matching the repo's fleetTypes/fleetFilters
pattern). Keeps `OverviewPage.tsx` a components-only module so it satisfies
react-refresh `only-export-components`, and makes the pure derivation directly
unit-testable. No behaviour change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Cover the extracted Overview KPI helper: empty-fleet (total === 0) full-score
posture, mode/flag counting, identity/capability score degradation, identity
clamp at zero, blocked/scrubbed null-as-zero summation, FIRING-only filtering
with most-severe top-alert selection, and the no-firing undefined case. Plus the
severity comparator ordering and the equal-severity (0) branch.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Extend OverviewPage component coverage: default 24h window + all four
window-toggle states (1h/24h/7d/30d) asserting single-active and subtitle echo;
singular/plural/healthy hero posture messages; fleet-snapshot mode/flag tile
derivations; recent-decisions severity→decision mapping (deny/narrow/scrub) with
agentId vs fleet rendering; empty recent note; approvals clear vs awaiting copy;
and fleet-wide top-issue with active-policy count.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.65217% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
dashboard/src/pages/OverviewPage.tsx 87.50% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Chisanan232

Copy link
Copy Markdown
Contributor Author

🔎 Review (Claude Code) — ready for approval

CI: ✅ All green — 0 failures (Dashboard tests + coverage, aa-cli build compat, CI Success all pass). The codecov/patch-class acceptance check is non-blocking.

Scope vs AAASM-3512: ✅ Fixes all 4 listed SonarCloud issues in OverviewPage.tsx, refactor-only:

  • S4624 nested template → hoisted toneClass const
  • S3776 cognitive complexity 18→≤15 → pure KPI/score/alert logic extracted to a sibling OverviewPage.kpis.ts module (matches the repo's fleetTypes/fleetFilters convention; also makes it unit-testable) + a RecentDecisionRow component
  • S3735 void operator → replaced with the repo-native ignorePromise(...) idiom
  • S6772 ambiguous JSX spacing → explicit {' '} in the <h1>

Tests (2-2): +23 meaningful cases (new OverviewPage.kpis.test.ts covering the extracted derivations' branches + window-toggle/hero/snapshot/recent-decisions in OverviewPage.test.tsx). Full suite 1326 pass; lint/type-check/build clean. No behaviour change.

Verdict: Scope-complete, correct, green, well-tested. Ready to approve & merge.

@Chisanan232 Chisanan232 merged commit 726316f into master Jun 21, 2026
37 checks passed
@Chisanan232 Chisanan232 deleted the v0.0.1/AAASM-3512/refactor/overview_sonar_tests branch June 21, 2026 06:29
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.

1 participant