Skip to content

🌱 test(auth): add unit coverage for logoutCleanup branches - #24640

Open
vjymisal0 wants to merge 3 commits into
kubestellar:mainfrom
vjymisal0:test/logout-cleanup-coverage
Open

vjymisal0 wants to merge 3 commits into
kubestellar:mainfrom
vjymisal0:test/logout-cleanup-coverage

Conversation

@vjymisal0

Copy link
Copy Markdown
Contributor

Fixes #24639

Summary

Adds web/src/lib/auth/__tests__/logoutCleanup.test.ts, covering branches of lib/auth/logoutCleanup.ts that AuthContext.test.tsx does not reach:

  • invalidateServerSession() POSTs /auth/logout with Authorization: Bearer <token> and X-Requested-With: XMLHttpRequest for a real session.
  • It skips the backend call when there is no stored token or the token is DEMO_TOKEN_VALUE.
  • It resolves without throwing when the backend is unreachable.
  • clearLocalAuthStorage() removes the session-scoped user cache and rotates kc-session-id.
  • clearLocalAuthStorage() still resets demo mode when sessionStorage.removeItem throws.

Test-only. No source changes.

Verification

cd web
npx vitest run src/lib/auth/__tests__/logoutCleanup.test.ts src/lib/auth/__tests__/AuthContext.test.tsx
Test Files  2 passed (2)
     Tests  14 passed (14)

Mutation check: removing the DEMO_TOKEN_VALUE guard and the kc-session-id removal from logoutCleanup.ts makes the corresponding new tests fail (2 failed, 4 passed). The source was restored afterwards.

Cover the demo/no-token skip of the /auth/logout POST, the request
headers, sessionStorage cleanup of the user cache and presence
session ID, and demo-mode reset when sessionStorage throws.

Fixes kubestellar#24639

Signed-off-by: vjymisal0 <misalvijay153@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 26, 2026 16:30
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Oct 26, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign eeshaansa for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 26, 2026

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@netlify

netlify Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for kubestellarconsole ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit eb29d35
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6ae1d7a0846e8abc49e2c333
😎 Deploy Preview https://deploy-preview-24640.console-deploy-preview.kubestellar.io
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@hivecommons-hive hivecommons-hive Bot added author/human A person pushed this PR themselves dco All commits are DCO signed-off role/untrusted Author has no registry profile or verified hive claim (or is revoked); never auto-merged stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 26, 2026

@hivecommons-hive hivecommons-hive 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.

Read the implementation alongside the tests, not just the diff — this looks correct to me (a maintainer still needs to approve; I cannot).

Verified against web/src/lib/auth/logoutCleanup.ts at head 77994af:

  • Every vi.mock path resolves to the module the implementation actually imports: ../../authToken → lib/authToken, ../../../hooks/mcp/agentFetch → hooks/mcp/agentFetch, ../../demoMode → lib/demoMode, etc. None are stale.
  • The two skip branches tested (null token, DEMO_TOKEN_VALUE) match the guard at logoutCleanup.ts:23; the unreachable-backend case matches the .catch(() => {}) at logoutCleanup.ts:31 (fire-and-forget, so resolves.toBeUndefined() is the right assertion).
  • The sessionStorage-throws test is subtler than it looks and is implemented correctly: cacheUser(null) (tokenHelpers.ts:132-137) runs after the try/catch at logoutCleanup.ts:53-60 but only calls safeRemove, so the mocked throwing Storage.prototype.removeItem cannot reject the promise; and the mock's this === sessionStorage guard leaves localStorage assertions meaningful.
  • clearSessionCaches's collaborators are mocked at module level, so importing logoutCleanup doesn't drag in the SSE/presence graph. Test-only change; no source files touched.

One note: the Authorization header line in both the implementation and the test assertion was masked by a secret scrubber on my read path, so I could not independently verify the exact header value the test pins — CI running vitest verifies it functionally either way.

— hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added stage/090-ready-for-human-merge Hive would merge this but trust/role blocks it; a maintainer's /lgtm /approve is all that is missing and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 26, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

Ready for a human merge: verdict approved @77994af, 31/31 checks green, DCO yes, soak 30m0s elapsed. Blocked only by role/untrusted (no verified hive claim or registry tier).

The hive never approves on your behalf: /lgtm /approve (or merge) if you accept it.

@hivecommons-hive hivecommons-hive Bot added stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) stage/stalled In its current stage longer than expected stage/090-ready-for-human-merge Hive would merge this but trust/role blocks it; a maintainer's /lgtm /approve is all that is missing and removed stage/090-ready-for-human-merge Hive would merge this but trust/role blocks it; a maintainer's /lgtm /approve is all that is missing stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) stage/stalled In its current stage longer than expected labels Oct 26, 2026
@hivecommons-hive hivecommons-hive Bot added stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) and removed stage/090-ready-for-human-merge Hive would merge this but trust/role blocks it; a maintainer's /lgtm /approve is all that is missing labels Oct 27, 2026
@hivecommons-hive hivecommons-hive Bot added stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) stage/stalled In its current stage longer than expected stage/090-ready-for-human-merge Hive would merge this but trust/role blocks it; a maintainer's /lgtm /approve is all that is missing and removed stage/090-ready-for-human-merge Hive would merge this but trust/role blocks it; a maintainer's /lgtm /approve is all that is missing stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) stage/stalled In its current stage longer than expected labels Oct 28, 2026
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/090-ready-for-human-merge Hive would merge this but trust/role blocks it; a maintainer's /lgtm /approve is all that is missing labels Oct 28, 2026

@hivecommons-hive hivecommons-hive 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.

Read the tests against web/src/lib/auth/logoutCleanup.ts on main — this looks correct to me.

Verified against the source (not just the diff):

  • All eight vi.mock paths match the module's real imports (authToken, agentFetch, demoMode, usePermissions, useActiveUsers, sseClient, mcp/shared, dashboardSync).
  • The demo/no-token skip branch being pinned exists at logoutCleanup.ts:23 (currentToken && currentToken !== DEMO_TOKEN_VALUE), and the unreachable-backend test is backed by the .catch at logoutCleanup.ts:32.
  • kc-session-id rotation (logoutCleanup.ts:58) and setGlobalDemoMode(false, true) (logoutCleanup.ts:50) match the assertions exactly; the SecurityError spy only throws for sessionStorage, so safeSet/safeRemove on localStorage still run, which is what the final assertion depends on.

One note, not a defect: the expected Authorization header value in the test was masked by a secret scrubber in every read I could get, so I could not byte-compare it to the source's header literal. CI (including the frontend test run and coverage-gate) is green at head eb29d35, which covers that assertion in practice.

Test-only change, matches the stated scope of #24639. No findings.

— hive: agent=reviewer backend=copilot model=claude-fable-5 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) stage/stalled In its current stage longer than expected stage/090-ready-for-human-merge Hive would merge this but trust/role blocks it; a maintainer's /lgtm /approve is all that is missing and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) stage/stalled In its current stage longer than expected labels Oct 28, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

Ready for a human merge: verdict approved @eb29d35, 25/25 checks green, DCO yes, soak 30m0s elapsed. Blocked only by role/untrusted (no verified hive claim or registry tier).

The hive never approves on your behalf: /lgtm /approve (or merge) if you accept it.

@hivecommons-hive hivecommons-hive Bot added stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) stage/stalled In its current stage longer than expected stage/090-ready-for-human-merge Hive would merge this but trust/role blocks it; a maintainer's /lgtm /approve is all that is missing and removed stage/090-ready-for-human-merge Hive would merge this but trust/role blocks it; a maintainer's /lgtm /approve is all that is missing stage/060-reviewed Review swarm verdict approve; a gate is still pending (CI running, soak not started) stage/stalled In its current stage longer than expected labels Oct 28, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/human A person pushed this PR themselves dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. role/untrusted Author has no registry profile or verified hive claim (or is revoked); never auto-merged size/L Denotes a PR that changes 100-499 lines, ignoring generated files. stage/090-ready-for-human-merge Hive would merge this but trust/role blocks it; a maintainer's /lgtm /approve is all that is missing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add unit coverage for lib/auth/logoutCleanup branches

2 participants