-
Notifications
You must be signed in to change notification settings - Fork 7
RU-T50 Build fix #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
RU-T50 Build fix #244
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,3 +40,4 @@ expo-env.d.ts | |
| .dual-graph/ | ||
| .mcp.json | ||
| opencode.json | ||
| /.dual-graph-pro | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { describe, expect, it } from '@jest/globals'; | ||
| import { AxiosError, type AxiosResponse } from 'axios'; | ||
|
|
||
| import { isRefreshCredentialRejection } from '../token-refresh'; | ||
|
|
||
| const axiosErrorWithStatus = (status: number): AxiosError => { | ||
| const response = { status, statusText: '', data: {}, headers: {}, config: {} as never } as AxiosResponse; | ||
| return new AxiosError('Request failed', 'ERR_BAD_RESPONSE', undefined, undefined, response); | ||
| }; | ||
|
|
||
| describe('isRefreshCredentialRejection', () => { | ||
| it('returns true when the token endpoint rejects the refresh token (400 invalid_grant)', () => { | ||
| expect(isRefreshCredentialRejection(axiosErrorWithStatus(400))).toBe(true); | ||
| }); | ||
|
|
||
| it('returns true for a 401 from the token endpoint', () => { | ||
| expect(isRefreshCredentialRejection(axiosErrorWithStatus(401))).toBe(true); | ||
| }); | ||
|
|
||
| it.each([500, 502, 503, 504, 429])('returns false for transient server status %i (preserve session)', (status) => { | ||
| expect(isRefreshCredentialRejection(axiosErrorWithStatus(status))).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for 403 (ambiguous, not a definitive credential rejection)', () => { | ||
| expect(isRefreshCredentialRejection(axiosErrorWithStatus(403))).toBe(false); | ||
|
Comment on lines
+12
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# List relevant files
fd -a "token-refresh.ts" src/lib/auth || true
fd -a "token-refresh.test.ts" src/lib/auth/__tests__ || true
fd -a "client.tsx" src/api/common || true
# Print the test file section
echo "---- token-refresh.test.ts (lines 1-220) ----"
sed -n '1,220p' src/lib/auth/__tests__/token-refresh.test.ts
# Print predicate implementation
echo "---- token-refresh.ts (lines 1-240) ----"
sed -n '1,240p' src/lib/auth/token-refresh.ts
# Print usage in client
echo "---- client.tsx (lines 1-220) ----"
sed -n '1,220p' src/api/common/client.tsx
echo "---- client.tsx (search for isRefreshCredentialRejection) ----"
rg -n "isRefreshCredentialRejection" src/api/common/client.tsx src/lib/auth -SRepository: Resgrid/Unit Length of output: 10220 Don’t treat every HTTP 400 from the token endpoint as an invalid refresh credential.
🤖 Prompt for AI Agents |
||
| }); | ||
|
|
||
| it('returns false for a network error (no response — offline/DNS/TLS)', () => { | ||
| expect(isRefreshCredentialRejection(new AxiosError('Network Error', 'ERR_NETWORK'))).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for a timeout (no response)', () => { | ||
| expect(isRefreshCredentialRejection(new AxiosError('timeout exceeded', 'ECONNABORTED'))).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for a non-Axios error (e.g. "no refresh token available")', () => { | ||
| expect(isRefreshCredentialRejection(new Error('No refresh token available'))).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for non-error values', () => { | ||
| expect(isRefreshCredentialRejection(null)).toBe(false); | ||
| expect(isRefreshCredentialRejection(undefined)).toBe(false); | ||
| expect(isRefreshCredentialRejection({ response: { status: 401 } })).toBe(false); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { isAxiosError } from 'axios'; | ||
|
|
||
| /** | ||
| * Decides whether a failed token-refresh attempt means the stored credentials are | ||
| * known-bad and the user must be logged out. | ||
| * | ||
| * Returns true ONLY when the OAuth2 token endpoint explicitly rejected the refresh | ||
| * token — HTTP 400 (`invalid_grant`) or 401. Every other failure is treated as | ||
| * transient and recoverable: | ||
| * - no response at all (offline, DNS/TLS failure, request timeout) | ||
| * - 5xx server errors (the backend is down/degraded, e.g. 502 Bad Gateway) | ||
| * - 429 rate limiting | ||
| * - any non-Axios error (e.g. "no refresh token available") | ||
| * | ||
| * Treating those as recoverable (reject + retry on the next request) instead of | ||
| * forcing logout prevents a backend incident from logging out every active user at | ||
| * once — critical for an emergency-response app. | ||
| */ | ||
| export const isRefreshCredentialRejection = (error: unknown): boolean => { | ||
| if (!isAxiosError(error)) { | ||
| return false; | ||
| } | ||
| const status = error.response?.status; | ||
| return status === 400 || status === 401; | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.