@app-vitals/agent-admin 1.82.0 → 1.84.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/openapi.platform.json +115 -1
- package/package.json +2 -2
- package/src/admin-boot.ts +14 -3
- package/src/admin-ui-github-refresh.smoke.test.ts +96 -0
- package/src/admin-ui-installation-repos-pages.ts +51 -3
- package/src/admin-ui-installation-repos-pages.unit.test.ts +49 -1
- package/src/admin-ui-pages.ts +1 -0
- package/src/admin-ui.ts +40 -5
- package/src/agents-api.smoke.test.ts +39 -2
- package/src/agents-api.ts +28 -1
- package/src/github-enterprise-api.smoke.test.ts +73 -0
- package/src/github-enterprise-api.ts +51 -0
- package/src/github-installation-wiring.ts +61 -1
- package/src/github-installation-wiring.unit.test.ts +55 -3
- package/src/github-installation.fixtures.ts +44 -3
- package/src/github-refresh-action.ts +45 -0
- package/src/github-refresh-action.unit.test.ts +121 -0
- package/src/github-repo-cache.ts +52 -0
- package/src/github-repo-refresher.ts +5 -0
- package/src/github-sync-cache.integration.test.ts +134 -0
- package/src/github-sync-cached-access.ts +125 -0
- package/src/github-sync-reverify.unit.test.ts +138 -0
- package/src/github-sync.ts +174 -8
- package/src/installation-repos-service.ts +70 -1
- package/src/installation-repos-service.unit.test.ts +34 -0
- package/src/repo-access-rules.ts +13 -1
|
@@ -44,6 +44,12 @@ export interface InstallationRepoView {
|
|
|
44
44
|
fullName: string;
|
|
45
45
|
/** Present only when the bound user's access to this repo is known. */
|
|
46
46
|
userCanPush?: boolean;
|
|
47
|
+
/** ISO time the bound user's access to this repo was last checked, when a row exists. */
|
|
48
|
+
accessCheckedAt?: string;
|
|
49
|
+
/** Failed access checks for this repo since the last success, when any. */
|
|
50
|
+
accessAttempts?: number;
|
|
51
|
+
/** Last access-check error for this repo, when any. */
|
|
52
|
+
accessError?: string;
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
/** Sync detail for one org's cached snapshot (all optional, additive). */
|
|
@@ -59,6 +65,14 @@ export interface InstallationSyncDetail {
|
|
|
59
65
|
lastError?: string;
|
|
60
66
|
/** ISO time the GitHub rate limit resets, while limited. */
|
|
61
67
|
rateLimitResetAt?: string;
|
|
68
|
+
/** Failed refresh attempts since the last success. */
|
|
69
|
+
attempts?: number;
|
|
70
|
+
/** ISO time of the next refresh attempt, while backing off. */
|
|
71
|
+
nextAttemptAt?: string;
|
|
72
|
+
/** Holder of a live refresh lease. */
|
|
73
|
+
leaseHolder?: string;
|
|
74
|
+
/** ISO time of the last refresh tick on this snapshot. */
|
|
75
|
+
lastTickAt?: string;
|
|
62
76
|
}
|
|
63
77
|
|
|
64
78
|
export interface InstallationOrgView extends InstallationSyncDetail {
|
|
@@ -73,6 +87,11 @@ export interface InstallationSnapshotRow {
|
|
|
73
87
|
totalCount: number | null;
|
|
74
88
|
lastError: string | null;
|
|
75
89
|
rateLimitResetAt: Date | null;
|
|
90
|
+
attempts?: number;
|
|
91
|
+
nextAttemptAt?: Date | null;
|
|
92
|
+
leaseHolder?: string | null;
|
|
93
|
+
leasedUntil?: Date | null;
|
|
94
|
+
lastTickAt?: Date | null;
|
|
76
95
|
repos: { fullName: string }[];
|
|
77
96
|
}
|
|
78
97
|
|
|
@@ -81,6 +100,10 @@ export interface CachedAccessRow {
|
|
|
81
100
|
repo: string;
|
|
82
101
|
status: string;
|
|
83
102
|
canPush: boolean;
|
|
103
|
+
level?: string | null;
|
|
104
|
+
checkedAt?: Date;
|
|
105
|
+
attempts?: number;
|
|
106
|
+
lastError?: string | null;
|
|
84
107
|
}
|
|
85
108
|
|
|
86
109
|
/** The slice of GitHubRepoCacheService the list reads; never calls GitHub. */
|
|
@@ -185,6 +208,28 @@ export function userPushHints(
|
|
|
185
208
|
});
|
|
186
209
|
}
|
|
187
210
|
|
|
211
|
+
/** Adds per-repo checkedAt / attempts / last error from the cached rows (additive). */
|
|
212
|
+
function withAccessDetail(
|
|
213
|
+
views: InstallationRepoView[],
|
|
214
|
+
rows: readonly CachedAccessRow[],
|
|
215
|
+
): InstallationRepoView[] {
|
|
216
|
+
const byRepo = new Map(rows.map((r) => [r.repo.toLowerCase(), r]));
|
|
217
|
+
return views.map((v) => {
|
|
218
|
+
const row = byRepo.get(
|
|
219
|
+
v.fullName.slice(v.fullName.indexOf("/") + 1).toLowerCase(),
|
|
220
|
+
);
|
|
221
|
+
if (!row) return v;
|
|
222
|
+
return {
|
|
223
|
+
...v,
|
|
224
|
+
...(row.checkedAt
|
|
225
|
+
? { accessCheckedAt: row.checkedAt.toISOString() }
|
|
226
|
+
: {}),
|
|
227
|
+
...(row.attempts ? { accessAttempts: row.attempts } : {}),
|
|
228
|
+
...(row.lastError ? { accessError: row.lastError } : {}),
|
|
229
|
+
};
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
188
233
|
const iso = (d: Date | null): string | undefined =>
|
|
189
234
|
d ? d.toISOString() : undefined;
|
|
190
235
|
|
|
@@ -207,8 +252,23 @@ function summarize(
|
|
|
207
252
|
.filter((d): d is string => d !== undefined)
|
|
208
253
|
.sort()
|
|
209
254
|
.at(-1);
|
|
255
|
+
const attempts = Math.max(0, ...orgs.map((o) => o.attempts ?? 0));
|
|
256
|
+
const next = orgs
|
|
257
|
+
.map((o) => o.nextAttemptAt)
|
|
258
|
+
.filter((d): d is string => d !== undefined)
|
|
259
|
+
.sort()[0];
|
|
260
|
+
const tick = orgs
|
|
261
|
+
.map((o) => o.lastTickAt)
|
|
262
|
+
.filter((d): d is string => d !== undefined)
|
|
263
|
+
.sort()
|
|
264
|
+
.at(-1);
|
|
265
|
+
const holder = orgs.find((o) => o.leaseHolder)?.leaseHolder;
|
|
210
266
|
return {
|
|
211
267
|
complete,
|
|
268
|
+
...(attempts > 0 ? { attempts } : {}),
|
|
269
|
+
...(next ? { nextAttemptAt: next } : {}),
|
|
270
|
+
...(holder ? { leaseHolder: holder } : {}),
|
|
271
|
+
...(tick ? { lastTickAt: tick } : {}),
|
|
212
272
|
reposSeen: orgs.reduce((a, o) => a + (o.reposSeen ?? 0), 0),
|
|
213
273
|
...(complete && synced[0] ? { syncedAt: synced[0] } : {}),
|
|
214
274
|
...(orgs.length > 0 && totalCount !== undefined ? { totalCount } : {}),
|
|
@@ -251,7 +311,10 @@ export class InstallationReposService {
|
|
|
251
311
|
username,
|
|
252
312
|
repos: names.map((f) => f.slice(f.indexOf("/") + 1)),
|
|
253
313
|
});
|
|
254
|
-
repos =
|
|
314
|
+
repos = withAccessDetail(
|
|
315
|
+
userPushHints({ cachedRows: rows }, s.org, names),
|
|
316
|
+
rows,
|
|
317
|
+
);
|
|
255
318
|
} catch {
|
|
256
319
|
// The hint is advisory: a failed cache read omits it.
|
|
257
320
|
}
|
|
@@ -267,6 +330,12 @@ export class InstallationReposService {
|
|
|
267
330
|
...(s.rateLimitResetAt
|
|
268
331
|
? { rateLimitResetAt: iso(s.rateLimitResetAt) }
|
|
269
332
|
: {}),
|
|
333
|
+
...(s.attempts ? { attempts: s.attempts } : {}),
|
|
334
|
+
...(s.nextAttemptAt ? { nextAttemptAt: iso(s.nextAttemptAt) } : {}),
|
|
335
|
+
...(s.leaseHolder && s.leasedUntil && s.leasedUntil > new Date()
|
|
336
|
+
? { leaseHolder: s.leaseHolder }
|
|
337
|
+
: {}),
|
|
338
|
+
...(s.lastTickAt ? { lastTickAt: iso(s.lastTickAt) } : {}),
|
|
270
339
|
});
|
|
271
340
|
}
|
|
272
341
|
return { status: "ok", appId: agent.appId, orgs, ...summarize(orgs) };
|
|
@@ -303,3 +303,37 @@ describe("InstallationReposService.list (cache read)", () => {
|
|
|
303
303
|
expect(r.status).toBe("no_app_id");
|
|
304
304
|
});
|
|
305
305
|
});
|
|
306
|
+
|
|
307
|
+
describe("InstallationReposService.list debug detail", () => {
|
|
308
|
+
it("surfaces attempts, next attempt, live lease and last tick; drops an expired lease", async () => {
|
|
309
|
+
const future = new Date(Date.now() + 60_000);
|
|
310
|
+
const past = new Date(Date.now() - 60_000);
|
|
311
|
+
const live = build({
|
|
312
|
+
snapshots: [
|
|
313
|
+
snap({
|
|
314
|
+
attempts: 2,
|
|
315
|
+
nextAttemptAt: T0,
|
|
316
|
+
lastTickAt: T0,
|
|
317
|
+
leaseHolder: "w1",
|
|
318
|
+
leasedUntil: future,
|
|
319
|
+
lastError: "x",
|
|
320
|
+
}),
|
|
321
|
+
],
|
|
322
|
+
});
|
|
323
|
+
const r = await live.svc.list("a1");
|
|
324
|
+
if (r.status !== "ok") throw new Error("expected ok");
|
|
325
|
+
expect(r.attempts).toBe(2);
|
|
326
|
+
expect(r.nextAttemptAt).toBe(T0.toISOString());
|
|
327
|
+
expect(r.lastTickAt).toBe(T0.toISOString());
|
|
328
|
+
expect(r.leaseHolder).toBe("w1");
|
|
329
|
+
expect(r.orgs[0]?.lastError).toBe("x");
|
|
330
|
+
|
|
331
|
+
const stale = build({
|
|
332
|
+
snapshots: [snap({ leaseHolder: "w1", leasedUntil: past })],
|
|
333
|
+
});
|
|
334
|
+
const r2 = await stale.svc.list("a1");
|
|
335
|
+
if (r2.status !== "ok") throw new Error("expected ok");
|
|
336
|
+
expect(r2.leaseHolder).toBeUndefined();
|
|
337
|
+
expect(r2.attempts).toBeUndefined();
|
|
338
|
+
});
|
|
339
|
+
});
|
package/src/repo-access-rules.ts
CHANGED
|
@@ -37,7 +37,9 @@ export function orgSkipReason(
|
|
|
37
37
|
if (result.reason === SELECTED_REPOS_REASON) {
|
|
38
38
|
return "lookup app is installed on selected repositories only";
|
|
39
39
|
}
|
|
40
|
-
if (result.status === "partial")
|
|
40
|
+
if (result.status === "partial") {
|
|
41
|
+
return result.reason ?? "access listing is incomplete";
|
|
42
|
+
}
|
|
41
43
|
if (result.status !== "ok") return `access lookup failed: ${result.status}`;
|
|
42
44
|
return undefined;
|
|
43
45
|
}
|
|
@@ -56,3 +58,13 @@ export function accessSkipReason(
|
|
|
56
58
|
if (!access.userVerified) return "GitHub user could not be verified";
|
|
57
59
|
return undefined;
|
|
58
60
|
}
|
|
61
|
+
|
|
62
|
+
/** Why cached access data cannot justify removals: a crawl or a repo answer is missing. */
|
|
63
|
+
export const INCOMPLETE_ACCESS_REASON = "access data is incomplete";
|
|
64
|
+
|
|
65
|
+
/** Why cached access data cannot justify removals: it is older than the freshness bound. */
|
|
66
|
+
export function staleAccessReason(oldestChecked: Date | undefined): string {
|
|
67
|
+
return oldestChecked
|
|
68
|
+
? `access data is stale (checked ${oldestChecked.toISOString()})`
|
|
69
|
+
: "access data is stale (check time unknown)";
|
|
70
|
+
}
|