-
Notifications
You must be signed in to change notification settings - Fork 327
fix(worker): classify permission sync failures by provider context #1482
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
brendan-kellam
merged 4 commits into
brendan/fix-token-refresh-permission-cleanup
from
brendan/classify-permission-sync-errors
Jul 23, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
efbbe3f
fix(worker): classify permission sync failures by provider context
brendan-kellam ac17561
chore: add changelog entry for permission sync classification
brendan-kellam 084350e
refactor(worker): normalize HTTP error metadata access
brendan-kellam 515ad7e
fix(worker): stop treating Bitbucket Cloud 410 as removed endpoint
brendan-kellam 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
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,91 @@ | ||
| import { describe, expect, test } from 'vitest'; | ||
| import { | ||
| classifyPermissionSyncUpstreamError, | ||
| PermissionSyncUpstreamError, | ||
| withPermissionSyncUpstreamError, | ||
| } from './permissionSyncError.js'; | ||
|
|
||
| describe('classifyPermissionSyncUpstreamError', () => { | ||
| test('classifies a 401 from an authenticated operation as a credential rejection', () => { | ||
| const cause = Object.assign(new Error('Unauthorized'), { status: 401 }); | ||
|
|
||
| expect(classifyPermissionSyncUpstreamError( | ||
| cause, | ||
| 'bitbucket-server', | ||
| 'list_accessible_repositories', | ||
| )).toMatchObject({ | ||
| kind: 'credential_rejected', | ||
| provider: 'bitbucket-server', | ||
| operation: 'list_accessible_repositories', | ||
| status: 401, | ||
| cause, | ||
| }); | ||
| }); | ||
|
|
||
| test('classifies a GitHub rate-limit 403 separately from an ambiguous forbidden response', () => { | ||
| const rateLimitError = Object.assign(new Error('Rate limited'), { | ||
| status: 403, | ||
| response: { headers: { 'x-ratelimit-remaining': '0' } }, | ||
| }); | ||
| const forbiddenError = Object.assign(new Error('Forbidden'), { status: 403 }); | ||
|
|
||
| expect(classifyPermissionSyncUpstreamError( | ||
| rateLimitError, | ||
| 'github', | ||
| 'list_accessible_repositories', | ||
| ).kind).toBe('rate_limited'); | ||
| expect(classifyPermissionSyncUpstreamError( | ||
| forbiddenError, | ||
| 'github', | ||
| 'list_accessible_repositories', | ||
| ).kind).toBe('forbidden'); | ||
| }); | ||
|
|
||
| test('classifies HTTP 429 as rate limited', () => { | ||
| const cause = Object.assign(new Error('Too Many Requests'), { status: 429 }); | ||
|
|
||
| expect(classifyPermissionSyncUpstreamError( | ||
| cause, | ||
| 'gitlab', | ||
| 'list_accessible_repositories', | ||
| ).kind).toBe('rate_limited'); | ||
| }); | ||
|
|
||
| test('does not classify Bitbucket Cloud 410 as a removed permission endpoint', () => { | ||
| const cause = Object.assign(new Error('Gone'), { status: 410 }); | ||
|
|
||
| expect(classifyPermissionSyncUpstreamError( | ||
| cause, | ||
| 'bitbucket-cloud', | ||
| 'list_accessible_repositories', | ||
| ).kind).toBe('unknown'); | ||
| }); | ||
|
|
||
| test.each([ | ||
| Object.assign(new Error('Internal Server Error'), { status: 500 }), | ||
| new TypeError('fetch failed'), | ||
| Object.assign(new Error('request timed out'), { name: 'TimeoutError' }), | ||
| ])('classifies an unavailable provider as transient', (cause) => { | ||
| expect(classifyPermissionSyncUpstreamError( | ||
| cause, | ||
| 'bitbucket-server', | ||
| 'list_accessible_repositories', | ||
| ).kind).toBe('upstream_unavailable'); | ||
| }); | ||
|
|
||
| test('does not reclassify an existing permission sync error', async () => { | ||
| const error = new PermissionSyncUpstreamError('Missing scope', { | ||
| kind: 'insufficient_scope', | ||
| provider: 'github', | ||
| operation: 'inspect_token_scopes', | ||
| }); | ||
|
|
||
| const caught = await withPermissionSyncUpstreamError( | ||
| 'github', | ||
| 'inspect_token_scopes', | ||
| () => Promise.reject(error), | ||
| ).catch(error => error); | ||
|
|
||
| expect(caught).toBe(error); | ||
| }); | ||
| }); |
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.