@app-vitals/agent-admin 1.75.0 → 1.77.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/prisma/client/browser.ts +15 -0
- package/prisma/client/client.ts +15 -0
- package/prisma/client/internal/class.ts +34 -4
- package/prisma/client/internal/prismaNamespace.ts +284 -2
- package/prisma/client/internal/prismaNamespaceBrowser.ts +58 -1
- package/prisma/client/models/GitHubCachedRepo.ts +1430 -0
- package/prisma/client/models/GitHubRepoAccess.ts +1397 -0
- package/prisma/client/models/GitHubRepoSnapshot.ts +1807 -0
- package/prisma/client/models.ts +3 -0
- package/prisma/migrations/20261120000000_add_github_repo_cache/migration.sql +75 -0
- package/prisma/schema/schema.prisma +62 -0
- package/src/fixtures/github-lookup-cassette.json +65 -0
- package/src/github-lookup-client.integration.test.ts +90 -1
- package/src/github-lookup-client.ts +156 -6
- package/src/github-lookup-client.unit.test.ts +147 -2
- package/src/github-repo-cache.integration.test.ts +227 -0
- package/src/github-repo-cache.ts +304 -0
- package/src/github-repo-cache.unit.test.ts +66 -0
- package/src/github-repo-crawler.integration.test.ts +244 -0
- package/src/github-repo-crawler.ts +273 -0
- package/src/github-repo-crawler.unit.test.ts +452 -0
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/github-repo-crawler.unit.test.ts
|
|
3
|
+
* Unit tests for the resumable repo crawl engine, driven by a fake PageSource
|
|
4
|
+
* and an in-memory CrawlStore that mirrors GitHubRepoCacheService semantics.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { beforeEach, describe, expect, it } from "bun:test";
|
|
8
|
+
import { GithubEnterpriseError } from "./github-enterprise-client.ts";
|
|
9
|
+
import { GithubLookupRateLimitError } from "./github-lookup-client.ts";
|
|
10
|
+
import type {
|
|
11
|
+
CachedRepoInput,
|
|
12
|
+
SnapshotKey,
|
|
13
|
+
SnapshotProgress,
|
|
14
|
+
} from "./github-repo-cache.ts";
|
|
15
|
+
import {
|
|
16
|
+
type CrawlSnapshot,
|
|
17
|
+
type CrawlStore,
|
|
18
|
+
crawlRepos,
|
|
19
|
+
type PageSource,
|
|
20
|
+
type RepoPage,
|
|
21
|
+
} from "./github-repo-crawler.ts";
|
|
22
|
+
|
|
23
|
+
const KEY: SnapshotKey = {
|
|
24
|
+
accountId: "acc",
|
|
25
|
+
appKind: "lookup",
|
|
26
|
+
appRef: "555",
|
|
27
|
+
org: "acme",
|
|
28
|
+
};
|
|
29
|
+
const T0 = new Date("2026-11-20T12:00:00Z");
|
|
30
|
+
|
|
31
|
+
class ManualClock {
|
|
32
|
+
t = T0.getTime();
|
|
33
|
+
now(): Date {
|
|
34
|
+
return new Date(this.t);
|
|
35
|
+
}
|
|
36
|
+
advance(ms: number): void {
|
|
37
|
+
this.t += ms;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface Row {
|
|
42
|
+
fullName: string;
|
|
43
|
+
seenAt: Date;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
class MemoryStore implements CrawlStore {
|
|
47
|
+
snap: CrawlSnapshot | null = null;
|
|
48
|
+
rows = new Map<number, Row>();
|
|
49
|
+
sweeps = 0;
|
|
50
|
+
upsertCalls = 0;
|
|
51
|
+
|
|
52
|
+
async getSnapshot(_key: SnapshotKey) {
|
|
53
|
+
return this.snap ? { ...this.snap } : null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async upsertSnapshot(_key: SnapshotKey, progress: SnapshotProgress = {}) {
|
|
57
|
+
const base: CrawlSnapshot = this.snap ?? {
|
|
58
|
+
id: "snap1",
|
|
59
|
+
crawlPage: 0,
|
|
60
|
+
crawlStartedAt: null,
|
|
61
|
+
completedAt: null,
|
|
62
|
+
totalCount: null,
|
|
63
|
+
lastError: null,
|
|
64
|
+
attempts: 0,
|
|
65
|
+
nextAttemptAt: null,
|
|
66
|
+
rateLimitResetAt: null,
|
|
67
|
+
lastTickAt: null,
|
|
68
|
+
};
|
|
69
|
+
const next = { ...base } as Record<string, unknown>;
|
|
70
|
+
for (const [k, v] of Object.entries(progress)) {
|
|
71
|
+
if (v !== undefined) next[k] = v;
|
|
72
|
+
}
|
|
73
|
+
this.snap = next as unknown as CrawlSnapshot;
|
|
74
|
+
return { ...this.snap };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async upsertRepos(_id: string, repos: CachedRepoInput[], seenAt: Date) {
|
|
78
|
+
this.upsertCalls++;
|
|
79
|
+
for (const r of repos) {
|
|
80
|
+
this.rows.set(Number(r.githubId), { fullName: r.fullName, seenAt });
|
|
81
|
+
}
|
|
82
|
+
return repos.length;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async countReposSeenSince(_id: string, since: Date) {
|
|
86
|
+
let n = 0;
|
|
87
|
+
for (const r of this.rows.values()) if (r.seenAt >= since) n++;
|
|
88
|
+
return n;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async sweepGeneration(_id: string) {
|
|
92
|
+
this.sweeps++;
|
|
93
|
+
const since = this.snap?.crawlStartedAt;
|
|
94
|
+
if (!since) return 0;
|
|
95
|
+
let n = 0;
|
|
96
|
+
for (const [id, r] of this.rows) {
|
|
97
|
+
if (r.seenAt < since) {
|
|
98
|
+
this.rows.delete(id);
|
|
99
|
+
n++;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return n;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const repo = (id: number): CachedRepoInput => ({
|
|
107
|
+
githubId: id,
|
|
108
|
+
fullName: `acme/r${id}`,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A fake GitHub listing: `ids` is the current server-side order, sliced into
|
|
113
|
+
* pages of `perPage`. `onFetch` may throw, return a canned response, or
|
|
114
|
+
* mutate the listing (to simulate repos appearing mid-crawl).
|
|
115
|
+
*/
|
|
116
|
+
class FakeSource implements PageSource {
|
|
117
|
+
fetched: number[] = [];
|
|
118
|
+
totalOverride: number | null = null;
|
|
119
|
+
onFetch: ((page: number) => RepoPage | undefined) | null = null;
|
|
120
|
+
|
|
121
|
+
constructor(
|
|
122
|
+
public ids: number[],
|
|
123
|
+
private readonly perPage = 2,
|
|
124
|
+
) {}
|
|
125
|
+
|
|
126
|
+
async fetchPage(page: number): Promise<RepoPage> {
|
|
127
|
+
this.fetched.push(page);
|
|
128
|
+
const canned = this.onFetch?.(page);
|
|
129
|
+
if (canned) return canned;
|
|
130
|
+
const start = (page - 1) * this.perPage;
|
|
131
|
+
const slice = this.ids.slice(start, start + this.perPage);
|
|
132
|
+
return {
|
|
133
|
+
repos: slice.map(repo),
|
|
134
|
+
totalCount: this.totalOverride ?? this.ids.length,
|
|
135
|
+
hasNext: start + this.perPage < this.ids.length,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let clock: ManualClock;
|
|
141
|
+
let store: MemoryStore;
|
|
142
|
+
|
|
143
|
+
beforeEach(() => {
|
|
144
|
+
clock = new ManualClock();
|
|
145
|
+
store = new MemoryStore();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const run = (source: PageSource) =>
|
|
149
|
+
crawlRepos({ key: KEY, source, store, clock });
|
|
150
|
+
|
|
151
|
+
describe("crawlRepos: fresh crawl", () => {
|
|
152
|
+
it("persists every page, completes, and sweeps the previous generation", async () => {
|
|
153
|
+
store.rows.set(99, { fullName: "acme/gone", seenAt: new Date(0) });
|
|
154
|
+
const source = new FakeSource([1, 2, 3, 4, 5]);
|
|
155
|
+
clock.advance(1);
|
|
156
|
+
const out = await run(source);
|
|
157
|
+
expect(out.outcome).toBe("complete");
|
|
158
|
+
expect(source.fetched).toEqual([1, 2, 3]);
|
|
159
|
+
expect(store.upsertCalls).toBe(3);
|
|
160
|
+
expect(store.sweeps).toBe(1);
|
|
161
|
+
expect([...store.rows.keys()].sort()).toEqual([1, 2, 3, 4, 5]);
|
|
162
|
+
expect(store.snap?.completedAt).toEqual(clock.now());
|
|
163
|
+
expect(store.snap?.crawlStartedAt).toEqual(new Date(T0.getTime() + 1));
|
|
164
|
+
expect(store.snap?.crawlPage).toBe(3);
|
|
165
|
+
expect(store.snap?.totalCount).toBe(5);
|
|
166
|
+
expect(out.swept).toBe(1);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("starts a new generation after a completed crawl", async () => {
|
|
170
|
+
const source = new FakeSource([1, 2, 3]);
|
|
171
|
+
await run(source);
|
|
172
|
+
const firstStart = store.snap?.crawlStartedAt;
|
|
173
|
+
clock.advance(60_000);
|
|
174
|
+
source.fetched = [];
|
|
175
|
+
const out = await run(source);
|
|
176
|
+
expect(out.outcome).toBe("complete");
|
|
177
|
+
expect(source.fetched).toEqual([1, 2]);
|
|
178
|
+
expect(store.snap?.crawlStartedAt).not.toEqual(firstStart);
|
|
179
|
+
expect(store.snap?.crawlStartedAt).toEqual(clock.now());
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("clears completedAt when a new crawl starts", async () => {
|
|
183
|
+
const source = new FakeSource([1, 2, 3]);
|
|
184
|
+
await run(source);
|
|
185
|
+
clock.advance(1000);
|
|
186
|
+
source.onFetch = (p) => {
|
|
187
|
+
if (p === 2) throw new GithubEnterpriseError("server", "boom");
|
|
188
|
+
return undefined;
|
|
189
|
+
};
|
|
190
|
+
const out = await run(source);
|
|
191
|
+
expect(out.outcome).toBe("failed");
|
|
192
|
+
expect(store.snap?.completedAt).toBeNull();
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
describe("crawlRepos: resume", () => {
|
|
197
|
+
it("restarts from the saved page minus one and completes without duplicating rows", async () => {
|
|
198
|
+
const source = new FakeSource([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
199
|
+
source.onFetch = (p) => {
|
|
200
|
+
if (p === 4) throw new GithubEnterpriseError("server", "HTTP 502");
|
|
201
|
+
return undefined;
|
|
202
|
+
};
|
|
203
|
+
const first = await run(source);
|
|
204
|
+
expect(first.outcome).toBe("failed");
|
|
205
|
+
expect(source.fetched).toEqual([1, 2, 3, 4]);
|
|
206
|
+
expect(store.snap?.crawlPage).toBe(3);
|
|
207
|
+
expect(store.snap?.lastError).toContain("HTTP 502");
|
|
208
|
+
expect(store.snap?.attempts).toBe(1);
|
|
209
|
+
expect(store.snap?.nextAttemptAt).not.toBeNull();
|
|
210
|
+
expect(store.snap?.completedAt).toBeNull();
|
|
211
|
+
expect(store.sweeps).toBe(0);
|
|
212
|
+
const startedAt = store.snap?.crawlStartedAt;
|
|
213
|
+
|
|
214
|
+
clock.advance(5 * 60_000);
|
|
215
|
+
source.onFetch = null;
|
|
216
|
+
source.fetched = [];
|
|
217
|
+
const second = await run(source);
|
|
218
|
+
expect(second.outcome).toBe("complete");
|
|
219
|
+
expect(source.fetched).toEqual([2, 3, 4]);
|
|
220
|
+
expect(store.rows.size).toBe(8);
|
|
221
|
+
expect(store.snap?.crawlStartedAt).toEqual(startedAt);
|
|
222
|
+
expect(store.snap?.completedAt).not.toBeNull();
|
|
223
|
+
expect(store.snap?.lastError).toBeNull();
|
|
224
|
+
expect(store.snap?.attempts).toBe(0);
|
|
225
|
+
expect(store.snap?.nextAttemptAt).toBeNull();
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("resumes from page 1 when only page 1 was saved", async () => {
|
|
229
|
+
const source = new FakeSource([1, 2, 3, 4]);
|
|
230
|
+
source.onFetch = (p) => {
|
|
231
|
+
if (p === 2) throw new GithubEnterpriseError("network", "timeout");
|
|
232
|
+
return undefined;
|
|
233
|
+
};
|
|
234
|
+
await run(source);
|
|
235
|
+
expect(store.snap?.crawlPage).toBe(1);
|
|
236
|
+
source.onFetch = null;
|
|
237
|
+
source.fetched = [];
|
|
238
|
+
expect((await run(source)).outcome).toBe("complete");
|
|
239
|
+
expect(source.fetched).toEqual([1, 2]);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("the overlapping page catches a row that shifted back across the page boundary", async () => {
|
|
243
|
+
// Listing [1..8], pages of 2. The crawl saves pages 1-3 then fails on 4.
|
|
244
|
+
const source = new FakeSource([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
245
|
+
source.onFetch = (p) => {
|
|
246
|
+
if (p === 4) throw new GithubEnterpriseError("server", "HTTP 500");
|
|
247
|
+
return undefined;
|
|
248
|
+
};
|
|
249
|
+
await run(source);
|
|
250
|
+
expect(store.snap?.crawlPage).toBe(3);
|
|
251
|
+
// Repo 2 is deleted: everything shifts one slot left; repo 7 moves from
|
|
252
|
+
// page 4 back to page 3. Resuming at page 4 alone would miss it.
|
|
253
|
+
source.ids = [1, 3, 4, 5, 6, 7, 8];
|
|
254
|
+
source.onFetch = null;
|
|
255
|
+
source.fetched = [];
|
|
256
|
+
const out = await run(source);
|
|
257
|
+
expect(source.fetched).toEqual([2, 3, 4]);
|
|
258
|
+
expect(store.rows.has(7)).toBe(true);
|
|
259
|
+
// Repo 2 was seen this crawl before it was deleted: seen (8) != total (7),
|
|
260
|
+
// so the crawl is not trusted and restarts from page 1 next time.
|
|
261
|
+
expect(out.outcome).toBe("incomplete");
|
|
262
|
+
expect(store.snap?.crawlPage).toBe(0);
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
describe("crawlRepos: total_count", () => {
|
|
267
|
+
it("leaves completedAt unset on a mismatch and restarts from page 1 next run", async () => {
|
|
268
|
+
const source = new FakeSource([1, 2, 3, 4, 5]);
|
|
269
|
+
source.totalOverride = 6;
|
|
270
|
+
const out = await run(source);
|
|
271
|
+
expect(out.outcome).toBe("incomplete");
|
|
272
|
+
expect(store.snap?.completedAt).toBeNull();
|
|
273
|
+
expect(store.snap?.crawlPage).toBe(0);
|
|
274
|
+
expect(store.snap?.totalCount).toBe(6);
|
|
275
|
+
expect(store.sweeps).toBe(0);
|
|
276
|
+
const firstStart = store.snap?.crawlStartedAt;
|
|
277
|
+
|
|
278
|
+
clock.advance(60_000);
|
|
279
|
+
source.totalOverride = null;
|
|
280
|
+
source.fetched = [];
|
|
281
|
+
const again = await run(source);
|
|
282
|
+
expect(source.fetched).toEqual([1, 2, 3]);
|
|
283
|
+
expect(again.outcome).toBe("complete");
|
|
284
|
+
expect(store.snap?.crawlStartedAt).not.toEqual(firstStart);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("counts distinct rows, so a row repeated across pages is not double-counted", async () => {
|
|
288
|
+
const source = new FakeSource([1, 2, 3]);
|
|
289
|
+
source.onFetch = (p) =>
|
|
290
|
+
p === 2
|
|
291
|
+
? { repos: [repo(2), repo(3)], totalCount: 3, hasNext: false }
|
|
292
|
+
: undefined;
|
|
293
|
+
expect((await run(source)).outcome).toBe("complete");
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("treats an empty page as the last page", async () => {
|
|
297
|
+
const source = new FakeSource([1, 2]);
|
|
298
|
+
source.onFetch = (p) =>
|
|
299
|
+
p === 1
|
|
300
|
+
? { repos: [repo(1), repo(2)], totalCount: 2, hasNext: true }
|
|
301
|
+
: { repos: [], totalCount: 2, hasNext: true };
|
|
302
|
+
const out = await run(source);
|
|
303
|
+
expect(source.fetched).toEqual([1, 2]);
|
|
304
|
+
expect(out.outcome).toBe("complete");
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
describe("crawlRepos: generation sweep", () => {
|
|
309
|
+
it("never sweeps on a partial crawl", async () => {
|
|
310
|
+
store.rows.set(99, { fullName: "acme/old", seenAt: new Date(0) });
|
|
311
|
+
const source = new FakeSource([1, 2, 3, 4]);
|
|
312
|
+
source.onFetch = (p) => {
|
|
313
|
+
if (p === 2)
|
|
314
|
+
throw new GithubLookupRateLimitError(
|
|
315
|
+
new GithubEnterpriseError("rate_limit", "429"),
|
|
316
|
+
new Date(T0.getTime() + 60_000),
|
|
317
|
+
);
|
|
318
|
+
return undefined;
|
|
319
|
+
};
|
|
320
|
+
await run(source);
|
|
321
|
+
expect(store.sweeps).toBe(0);
|
|
322
|
+
expect(store.rows.has(99)).toBe(true);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it("keeps rows added during the crawl and drops only the previous generation", async () => {
|
|
326
|
+
store.rows.set(99, { fullName: "acme/old", seenAt: new Date(0) });
|
|
327
|
+
const source = new FakeSource([1, 2, 3, 4]);
|
|
328
|
+
source.onFetch = (p) => {
|
|
329
|
+
clock.advance(1000);
|
|
330
|
+
// A repo is created mid-crawl and lands on a page not yet read.
|
|
331
|
+
if (p === 2) source.ids = [1, 2, 3, 4, 7];
|
|
332
|
+
return undefined;
|
|
333
|
+
};
|
|
334
|
+
const out = await run(source);
|
|
335
|
+
expect(out.outcome).toBe("complete");
|
|
336
|
+
expect([...store.rows.keys()].sort()).toEqual([1, 2, 3, 4, 7]);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
describe("crawlRepos: rate limits", () => {
|
|
341
|
+
it("records rateLimitResetAt and stops cleanly, without a failure", async () => {
|
|
342
|
+
const reset = new Date(T0.getTime() + 15 * 60_000);
|
|
343
|
+
const source = new FakeSource([1, 2, 3, 4, 5]);
|
|
344
|
+
source.onFetch = (p) => {
|
|
345
|
+
if (p === 2)
|
|
346
|
+
throw new GithubLookupRateLimitError(
|
|
347
|
+
new GithubEnterpriseError("rate_limit", "HTTP 429"),
|
|
348
|
+
reset,
|
|
349
|
+
);
|
|
350
|
+
return undefined;
|
|
351
|
+
};
|
|
352
|
+
const out = await run(source);
|
|
353
|
+
expect(out.outcome).toBe("rate_limited");
|
|
354
|
+
expect(out.rateLimitResetAt).toEqual(reset);
|
|
355
|
+
expect(store.snap?.rateLimitResetAt).toEqual(reset);
|
|
356
|
+
expect(store.snap?.attempts).toBe(0);
|
|
357
|
+
expect(store.snap?.lastError).toBeNull();
|
|
358
|
+
expect(store.snap?.crawlPage).toBe(1);
|
|
359
|
+
});
|
|
360
|
+
|
|
361
|
+
it("uses Retry-After from a plain rate_limit error", async () => {
|
|
362
|
+
const source = new FakeSource([1, 2, 3]);
|
|
363
|
+
source.onFetch = () => {
|
|
364
|
+
throw new GithubEnterpriseError("rate_limit", "HTTP 429", {
|
|
365
|
+
status: 429,
|
|
366
|
+
retryAfterSeconds: 30,
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
const out = await run(source);
|
|
370
|
+
expect(out.outcome).toBe("rate_limited");
|
|
371
|
+
expect(store.snap?.rateLimitResetAt).toEqual(
|
|
372
|
+
new Date(T0.getTime() + 30_000),
|
|
373
|
+
);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
it("stops after a successful page that exhausted the quota, keeping the page", async () => {
|
|
377
|
+
const reset = new Date(T0.getTime() + 10 * 60_000);
|
|
378
|
+
const source = new FakeSource([1, 2, 3, 4]);
|
|
379
|
+
source.onFetch = (p) =>
|
|
380
|
+
p === 1
|
|
381
|
+
? {
|
|
382
|
+
repos: [repo(1), repo(2)],
|
|
383
|
+
totalCount: 4,
|
|
384
|
+
hasNext: true,
|
|
385
|
+
rateLimit: { remaining: 0, resetAt: reset },
|
|
386
|
+
}
|
|
387
|
+
: undefined;
|
|
388
|
+
const out = await run(source);
|
|
389
|
+
expect(out.outcome).toBe("rate_limited");
|
|
390
|
+
expect(source.fetched).toEqual([1]);
|
|
391
|
+
expect(store.rows.size).toBe(2);
|
|
392
|
+
expect(store.snap?.crawlPage).toBe(1);
|
|
393
|
+
expect(store.snap?.rateLimitResetAt).toEqual(reset);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it("does not fetch before rateLimitResetAt, then resumes and clears it", async () => {
|
|
397
|
+
const reset = new Date(T0.getTime() + 60_000);
|
|
398
|
+
const source = new FakeSource([1, 2, 3, 4, 5]);
|
|
399
|
+
source.onFetch = (p) => {
|
|
400
|
+
if (p === 3)
|
|
401
|
+
throw new GithubLookupRateLimitError(
|
|
402
|
+
new GithubEnterpriseError("rate_limit", "HTTP 403"),
|
|
403
|
+
reset,
|
|
404
|
+
);
|
|
405
|
+
return undefined;
|
|
406
|
+
};
|
|
407
|
+
await run(source);
|
|
408
|
+
source.onFetch = null;
|
|
409
|
+
source.fetched = [];
|
|
410
|
+
|
|
411
|
+
clock.advance(30_000);
|
|
412
|
+
const early = await run(source);
|
|
413
|
+
expect(early.outcome).toBe("rate_limited");
|
|
414
|
+
expect(source.fetched).toEqual([]);
|
|
415
|
+
|
|
416
|
+
clock.advance(30_000);
|
|
417
|
+
const late = await run(source);
|
|
418
|
+
expect(late.outcome).toBe("complete");
|
|
419
|
+
expect(source.fetched).toEqual([1, 2, 3]);
|
|
420
|
+
expect(store.snap?.rateLimitResetAt).toBeNull();
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
it("records a plain permission error as a failure, not a rate limit", async () => {
|
|
424
|
+
const source = new FakeSource([1, 2]);
|
|
425
|
+
source.onFetch = () => {
|
|
426
|
+
throw new GithubEnterpriseError("permission", "HTTP 403 not accessible");
|
|
427
|
+
};
|
|
428
|
+
const out = await run(source);
|
|
429
|
+
expect(out.outcome).toBe("failed");
|
|
430
|
+
expect(store.snap?.rateLimitResetAt).toBeNull();
|
|
431
|
+
expect(store.snap?.attempts).toBe(1);
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
describe("crawlRepos: page budget", () => {
|
|
436
|
+
it("stops after maxPages with progress saved, and resumes with overlap", async () => {
|
|
437
|
+
const source = new FakeSource([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
438
|
+
const out = await crawlRepos({
|
|
439
|
+
key: KEY,
|
|
440
|
+
source,
|
|
441
|
+
store,
|
|
442
|
+
clock,
|
|
443
|
+
maxPages: 2,
|
|
444
|
+
});
|
|
445
|
+
expect(out.outcome).toBe("in_progress");
|
|
446
|
+
expect(store.snap?.crawlPage).toBe(2);
|
|
447
|
+
source.fetched = [];
|
|
448
|
+
const done = await run(source);
|
|
449
|
+
expect(source.fetched).toEqual([1, 2, 3, 4]);
|
|
450
|
+
expect(done.outcome).toBe("complete");
|
|
451
|
+
});
|
|
452
|
+
});
|