Repository navigation
Conversation
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>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for kubestellarconsole ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
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.mockpath 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 (
nulltoken,DEMO_TOKEN_VALUE) match the guard atlogoutCleanup.ts:23; the unreachable-backend case matches the.catch(() => {})atlogoutCleanup.ts:31(fire-and-forget, soresolves.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 atlogoutCleanup.ts:53-60but only callssafeRemove, so the mocked throwingStorage.prototype.removeItemcannot reject the promise; and the mock'sthis === sessionStorageguard leaves localStorage assertions meaningful. clearSessionCaches's collaborators are mocked at module level, so importinglogoutCleanupdoesn'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
|
Ready for a human merge: verdict approved @77994af, 31/31 checks green, DCO yes, soak 30m0s elapsed. Blocked only by The hive never approves on your behalf: |
There was a problem hiding this comment.
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.mockpaths 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.catchatlogoutCleanup.ts:32. kc-session-idrotation (logoutCleanup.ts:58) andsetGlobalDemoMode(false, true)(logoutCleanup.ts:50) match the assertions exactly; theSecurityErrorspy only throws forsessionStorage, sosafeSet/safeRemoveon 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
|
Ready for a human merge: verdict approved @eb29d35, 25/25 checks green, DCO yes, soak 30m0s elapsed. Blocked only by The hive never approves on your behalf: |
Fixes #24639
Summary
Adds
web/src/lib/auth/__tests__/logoutCleanup.test.ts, covering branches oflib/auth/logoutCleanup.tsthatAuthContext.test.tsxdoes not reach:invalidateServerSession()POSTs/auth/logoutwithAuthorization: Bearer <token>andX-Requested-With: XMLHttpRequestfor a real session.DEMO_TOKEN_VALUE.clearLocalAuthStorage()removes the session-scoped user cache and rotateskc-session-id.clearLocalAuthStorage()still resets demo mode whensessionStorage.removeItemthrows.Test-only. No source changes.
Verification
Mutation check: removing the
DEMO_TOKEN_VALUEguard and thekc-session-idremoval fromlogoutCleanup.tsmakes the corresponding new tests fail (2 failed, 4 passed). The source was restored afterwards.