-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(connectors): stop hydration after rate limits #7255
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
Merged
Changes from all commits
Commits
Show all changes
3 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 |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { afterEach, describe, expect, it, vi } from 'vitest' | ||
| import { githubConnector } from '@/connectors/github/github' | ||
|
|
||
| describe('githubConnector.getDocument', () => { | ||
| afterEach(() => { | ||
| vi.unstubAllGlobals() | ||
| }) | ||
|
|
||
| it('uses the object media type and hydrates large file content through the blob API', async () => { | ||
| const fetchMock = vi | ||
| .fn() | ||
| .mockResolvedValueOnce( | ||
| new Response( | ||
| JSON.stringify({ | ||
| sha: 'blob-sha', | ||
| size: 2 * 1024 * 1024, | ||
| content: '', | ||
| encoding: 'none', | ||
| }), | ||
| { status: 200, headers: { 'last-modified': 'Fri, 28 Aug 2026 12:00:00 GMT' } } | ||
| ) | ||
| ) | ||
| .mockResolvedValueOnce( | ||
| new Response('large text file', { status: 200, headers: { 'content-length': '15' } }) | ||
| ) | ||
| vi.stubGlobal('fetch', fetchMock) | ||
|
|
||
| const document = await githubConnector.getDocument( | ||
| 'token', | ||
| { repository: 'owner/repo', branch: 'main' }, | ||
| 'docs/large.md' | ||
| ) | ||
|
|
||
| expect(fetchMock).toHaveBeenCalledTimes(2) | ||
| expect(fetchMock.mock.calls[0][1]).toMatchObject({ | ||
| headers: expect.objectContaining({ Accept: 'application/vnd.github.object+json' }), | ||
| }) | ||
| expect(fetchMock.mock.calls[1][1]).toMatchObject({ | ||
| headers: expect.objectContaining({ Accept: 'application/vnd.github.raw+json' }), | ||
| }) | ||
| expect(document).toMatchObject({ | ||
| externalId: 'docs/large.md', | ||
| content: 'large text file', | ||
| contentDeferred: false, | ||
| contentHash: 'git-sha:blob-sha', | ||
| }) | ||
| }) | ||
|
|
||
| it('returns null only when a listed path is no longer present', async () => { | ||
| vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(null, { status: 404 }))) | ||
|
|
||
| await expect( | ||
| githubConnector.getDocument('token', { repository: 'owner/repo' }, 'deleted.md') | ||
| ).resolves.toBeNull() | ||
| }) | ||
|
|
||
| it('records a blob that exceeds the byte cap as a visible skipped document', async () => { | ||
| const fetchMock = vi | ||
| .fn() | ||
| .mockResolvedValueOnce( | ||
| new Response( | ||
| JSON.stringify({ | ||
| sha: 'blob-sha', | ||
| size: 2 * 1024 * 1024, | ||
| content: '', | ||
| encoding: 'none', | ||
| }), | ||
| { status: 200 } | ||
| ) | ||
| ) | ||
| .mockResolvedValueOnce( | ||
| new Response('oversized', { | ||
| status: 200, | ||
| headers: { 'content-length': String(100 * 1024 * 1024 + 1) }, | ||
| }) | ||
| ) | ||
| vi.stubGlobal('fetch', fetchMock) | ||
|
|
||
| await expect( | ||
| githubConnector.getDocument('token', { repository: 'owner/repo' }, 'oversized.md') | ||
| ).resolves.toMatchObject({ | ||
| externalId: 'oversized.md', | ||
| content: '', | ||
| skippedReason: 'File exceeds the 100MB size limit and was not indexed', | ||
| }) | ||
| }) | ||
|
|
||
| it('rejects a bodyless blob response instead of misreporting it as oversized', async () => { | ||
| const fetchMock = vi | ||
| .fn() | ||
| .mockResolvedValueOnce( | ||
| new Response( | ||
| JSON.stringify({ | ||
| sha: 'blob-sha', | ||
| size: 2 * 1024 * 1024, | ||
| content: '', | ||
| encoding: 'none', | ||
| }), | ||
| { status: 200 } | ||
| ) | ||
| ) | ||
| .mockResolvedValueOnce(new Response(null, { status: 200 })) | ||
| vi.stubGlobal('fetch', fetchMock) | ||
|
|
||
| await expect( | ||
| githubConnector.getDocument('token', { repository: 'owner/repo' }, 'missing-body.md') | ||
| ).rejects.toThrow('GitHub git blob blob-sha returned no body') | ||
| }) | ||
|
|
||
| it('surfaces a non-rate-limit 403 as a document failure', async () => { | ||
| vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(null, { status: 403 }))) | ||
|
|
||
| await expect( | ||
| githubConnector.getDocument('token', { repository: 'owner/repo' }, 'private.md') | ||
| ).rejects.toThrow('Failed to fetch file private.md: 403') | ||
| }) | ||
| }) |
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
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.