mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 03:15:01 +00:00
Read malformed revision metadata without retaining it
This commit is contained in:
@@ -97,21 +97,26 @@ it.each([100, 1000])(
|
||||
async (count) => {
|
||||
read.mockResolvedValue({ stdout: JSON.stringify([row(1, 'opened', 8)]) })
|
||||
pages.mockImplementation(async ([endpoint]: string[]) => {
|
||||
const page = Number(new URL(endpoint, 'https://gitlab.com').searchParams.get('page'))
|
||||
const query = new URL(endpoint, 'https://gitlab.com').searchParams
|
||||
const page = Number(query.get('page'))
|
||||
const branch = query.get('source_branch')
|
||||
return {
|
||||
body: JSON.stringify(
|
||||
Array.from({ length: 100 }, (_, i) => {
|
||||
const iid = (page - 1) * 100 + i + 1
|
||||
return row(iid, 'opened', iid === count ? 1 : 8)
|
||||
return { ...row(iid, 'opened', iid === count ? 1 : 8), source_branch: branch }
|
||||
})
|
||||
),
|
||||
headers: { 'x-next-page': page * 100 < count ? String(page + 1) : '' }
|
||||
}
|
||||
})
|
||||
await expect(createGitLabBranchDiscovery(args)('feature')).resolves.toMatchObject({
|
||||
iid: count
|
||||
const discover = createGitLabBranchDiscovery(args)
|
||||
await expect(discover('feature')).resolves.toMatchObject({ iid: count })
|
||||
await expect(discover('renamed')).resolves.toMatchObject({
|
||||
iid: count,
|
||||
source_branch: 'renamed'
|
||||
})
|
||||
expect(read).toHaveBeenCalledTimes(1)
|
||||
expect(pages).toHaveBeenCalledTimes(count / 100)
|
||||
expect(pages).toHaveBeenCalledTimes((2 * count) / 100)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -383,17 +383,19 @@ describe('gitlab client — MR operations', () => {
|
||||
|
||||
it('bypasses malformed revisions and evicts by accounted ID storage below the receipt limit', async () => {
|
||||
const f = membershipFixture(33000)
|
||||
Object.assign(f.mr, { diff_refs: { head_sha: 'bad' } })
|
||||
await f.read(f.member)
|
||||
await f.read(f.member)
|
||||
expect(glabApiWithHeadersMock).toHaveBeenCalledTimes(660)
|
||||
for (const diff_refs of [{ head_sha: 'bad' }, []]) {
|
||||
Object.assign(f.mr, { diff_refs })
|
||||
await f.read(f.member)
|
||||
await f.read(f.member)
|
||||
}
|
||||
expect(glabApiWithHeadersMock).toHaveBeenCalledTimes(1320)
|
||||
Object.assign(f.mr, { diff_refs: undefined })
|
||||
await f.read(f.member)
|
||||
f.mr.sha = 'b'.repeat(40)
|
||||
await f.read(f.member)
|
||||
f.mr.sha = 'a'.repeat(40)
|
||||
await f.read(f.member)
|
||||
expect(glabApiWithHeadersMock).toHaveBeenCalledTimes(1650)
|
||||
expect(glabApiWithHeadersMock).toHaveBeenCalledTimes(2310)
|
||||
})
|
||||
|
||||
it('completes oversized histories correctly without retaining them', async () => {
|
||||
|
||||
@@ -66,7 +66,7 @@ function revisionKey(headSha: unknown, diffRefs: unknown): (string | null)[] | n
|
||||
if (diffRefs === undefined || diffRefs === null) {
|
||||
return [head, null, null, null]
|
||||
}
|
||||
if (typeof diffRefs !== 'object') {
|
||||
if (typeof diffRefs !== 'object' || Array.isArray(diffRefs)) {
|
||||
return null
|
||||
}
|
||||
const refs = [
|
||||
|
||||
Reference in New Issue
Block a user