@app-vitals/agent-admin 1.84.1 → 1.85.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 +71 -0
- package/package.json +2 -2
- package/src/admin-ui-installation-repos-pages.ts +75 -9
- package/src/admin-ui-installation-repos-pages.unit.test.ts +180 -0
- package/src/admin-ui-installation-repos.smoke.test.ts +24 -0
- package/src/agents-api.smoke.test.ts +39 -0
- package/src/agents-api.ts +31 -1
- package/src/github-installation-wiring.ts +11 -2
- package/src/github-installation-wiring.unit.test.ts +90 -0
- package/src/github-installation.fixtures.ts +42 -0
- package/src/github-repo-cache.ts +2 -0
- package/src/github-sync-cache.integration.test.ts +57 -1
- package/src/github-sync-cached-access.ts +53 -1
- package/src/github-sync-cached-access.unit.test.ts +114 -0
- package/src/github-sync.ts +30 -4
- package/src/github-sync.unit.test.ts +195 -0
- package/src/repo-access-rules.ts +3 -0
- package/src/user-repo-access-resolver.ts +27 -0
|
@@ -5,11 +5,13 @@ import {
|
|
|
5
5
|
fakeOpenWork,
|
|
6
6
|
fakePrisma,
|
|
7
7
|
freshCache,
|
|
8
|
+
withLookupSnapshots,
|
|
8
9
|
} from "./github-installation.fixtures.ts";
|
|
9
10
|
import {
|
|
10
11
|
createGithubInstallationRepos,
|
|
11
12
|
createGithubSync,
|
|
12
13
|
} from "./github-installation-wiring.ts";
|
|
14
|
+
import type { GitHubEnterpriseAppMetadata } from "./github-enterprise-apps.ts";
|
|
13
15
|
import type { InstallationReposPort } from "./installation-repos-service.ts";
|
|
14
16
|
|
|
15
17
|
const noApp = { get: async () => null, getPrivateKey: async () => null };
|
|
@@ -169,3 +171,91 @@ describe("createGithubSync", () => {
|
|
|
169
171
|
expect(state.repos).toEqual(ALL);
|
|
170
172
|
});
|
|
171
173
|
});
|
|
174
|
+
|
|
175
|
+
describe("createGithubSync lookup snapshot read", () => {
|
|
176
|
+
const ALL = ["acme/old", "acme/api"];
|
|
177
|
+
const now = new Date();
|
|
178
|
+
// A real lookupRepos (no syncOverrides): the lookup App's snapshots are read
|
|
179
|
+
// from the cache under the agent's account key, plus the deployment-wide key.
|
|
180
|
+
const build = (
|
|
181
|
+
lookupAccountId: string | null,
|
|
182
|
+
lookupRows: Parameters<typeof withLookupSnapshots>[1],
|
|
183
|
+
agentAccountId?: string,
|
|
184
|
+
) => {
|
|
185
|
+
const { prisma, state } = fakePrisma(
|
|
186
|
+
ALL,
|
|
187
|
+
freshCache("acme", ALL, ["acme/api"], now),
|
|
188
|
+
);
|
|
189
|
+
if (agentAccountId !== undefined) {
|
|
190
|
+
(
|
|
191
|
+
prisma.agent as unknown as { findUnique: () => Promise<unknown> }
|
|
192
|
+
).findUnique = async () => ({
|
|
193
|
+
id: "a1",
|
|
194
|
+
repos: state.repos,
|
|
195
|
+
githubUsername: "dev",
|
|
196
|
+
accountId: agentAccountId,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
withLookupSnapshots(prisma, lookupRows);
|
|
200
|
+
const svc = createGithubSync({
|
|
201
|
+
prisma,
|
|
202
|
+
appService: {
|
|
203
|
+
get: async () =>
|
|
204
|
+
({
|
|
205
|
+
accountId: lookupAccountId,
|
|
206
|
+
appId: "99",
|
|
207
|
+
updatedAt: now,
|
|
208
|
+
}) as unknown as GitHubEnterpriseAppMetadata,
|
|
209
|
+
getPrivateKey: async () => "test-key",
|
|
210
|
+
},
|
|
211
|
+
access: accessFor(["acme/api"]),
|
|
212
|
+
agentEnv: envWith({ GH_APP_ID: "42" }),
|
|
213
|
+
installationRepos: portWith([], ALL),
|
|
214
|
+
now: () => now,
|
|
215
|
+
});
|
|
216
|
+
return { svc, state };
|
|
217
|
+
};
|
|
218
|
+
const lookupAcme = (accountId: string) => ({
|
|
219
|
+
accountId,
|
|
220
|
+
appRef: "99",
|
|
221
|
+
org: "acme",
|
|
222
|
+
completedAt: now,
|
|
223
|
+
repos: ALL.map((fullName) => ({ fullName })),
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('a null-account agent finds the lookup snapshot filed under "deployment"', async () => {
|
|
227
|
+
const { svc, state } = build(null, [lookupAcme("deployment")]);
|
|
228
|
+
const preview = await svc.preview("a1");
|
|
229
|
+
if (preview.status !== "previewed") throw new Error(preview.status);
|
|
230
|
+
// The org is complete and fresh, so it is not skipped for missing lookup data.
|
|
231
|
+
expect(preview.plan.skippedOrgs).toEqual([]);
|
|
232
|
+
const lookupQueries = state.snapshotQueries.filter(
|
|
233
|
+
(q) => (q as { where: { appKind?: string } }).where.appKind === "lookup",
|
|
234
|
+
);
|
|
235
|
+
expect(lookupQueries).toMatchObject([
|
|
236
|
+
{ where: { accountId: { in: ["deployment"] }, appRef: "99" } },
|
|
237
|
+
]);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("an account-scoped agent reads its own account's and the deployment-wide lookup snapshots", async () => {
|
|
241
|
+
const { svc, state } = build("acct-1", [lookupAcme("acct-1")], "acct-1");
|
|
242
|
+
const preview = await svc.preview("a1");
|
|
243
|
+
if (preview.status !== "previewed") throw new Error(preview.status);
|
|
244
|
+
expect(preview.plan.skippedOrgs).toEqual([]);
|
|
245
|
+
const lookupQueries = state.snapshotQueries.filter(
|
|
246
|
+
(q) => (q as { where: { appKind?: string } }).where.appKind === "lookup",
|
|
247
|
+
);
|
|
248
|
+
expect(lookupQueries).toMatchObject([
|
|
249
|
+
{ where: { accountId: { in: ["acct-1", "deployment"] }, appRef: "99" } },
|
|
250
|
+
]);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("with no lookup snapshot under the agent's key, the org is skipped as incomplete", async () => {
|
|
254
|
+
const { svc } = build(null, [lookupAcme("some-other-account")]);
|
|
255
|
+
const preview = await svc.preview("a1");
|
|
256
|
+
if (preview.status !== "previewed") throw new Error(preview.status);
|
|
257
|
+
expect(preview.plan.skippedOrgs).toMatchObject([
|
|
258
|
+
{ org: "acme", reason: "access data is incomplete" },
|
|
259
|
+
]);
|
|
260
|
+
});
|
|
261
|
+
});
|
|
@@ -126,3 +126,45 @@ export const envWith = (env?: Record<string, string>) => ({
|
|
|
126
126
|
getConfigBundle: async (agentId: string) =>
|
|
127
127
|
env ? { env, agentId, allowedTools: [] } : null,
|
|
128
128
|
});
|
|
129
|
+
|
|
130
|
+
/** A lookup-App snapshot row as the crawler files it, keyed by its SnapshotKey accountId. */
|
|
131
|
+
export interface FakeLookupSnapshot {
|
|
132
|
+
accountId: string;
|
|
133
|
+
appRef: string;
|
|
134
|
+
org: string;
|
|
135
|
+
completedAt: Date;
|
|
136
|
+
repos: { fullName: string }[];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Serves `appKind: "lookup"` reads from `rows` honouring the `accountId.in`
|
|
141
|
+
* and `appRef` filters, so a wrong account key returns nothing. Other reads
|
|
142
|
+
* fall through to the fake's own snapshot rows.
|
|
143
|
+
*/
|
|
144
|
+
export function withLookupSnapshots(
|
|
145
|
+
prisma: PrismaClient,
|
|
146
|
+
rows: FakeLookupSnapshot[],
|
|
147
|
+
) {
|
|
148
|
+
const snapshots = prisma.gitHubRepoSnapshot as unknown as {
|
|
149
|
+
findMany: (args: unknown) => Promise<unknown[]>;
|
|
150
|
+
};
|
|
151
|
+
const base = snapshots.findMany;
|
|
152
|
+
snapshots.findMany = async (args: unknown) => {
|
|
153
|
+
const where = (
|
|
154
|
+
args as {
|
|
155
|
+
where: {
|
|
156
|
+
accountId?: { in: string[] };
|
|
157
|
+
appKind?: string;
|
|
158
|
+
appRef?: string;
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
).where;
|
|
162
|
+
if (where.appKind !== "lookup") return base(args);
|
|
163
|
+
await base(args);
|
|
164
|
+
return rows.filter(
|
|
165
|
+
(r) =>
|
|
166
|
+
where.accountId?.in.includes(r.accountId) && r.appRef === where.appRef,
|
|
167
|
+
);
|
|
168
|
+
};
|
|
169
|
+
return prisma;
|
|
170
|
+
}
|
package/src/github-repo-cache.ts
CHANGED
|
@@ -4,11 +4,13 @@ import {
|
|
|
4
4
|
envWith,
|
|
5
5
|
fakePrisma,
|
|
6
6
|
freshCache,
|
|
7
|
+
withLookupSnapshots,
|
|
7
8
|
} from "./github-installation.fixtures.ts";
|
|
8
9
|
import {
|
|
9
10
|
createGithubInstallationRepos,
|
|
10
11
|
createGithubSync,
|
|
11
12
|
} from "./github-installation-wiring.ts";
|
|
13
|
+
import type { GitHubEnterpriseAppMetadata } from "./github-enterprise-apps.ts";
|
|
12
14
|
import type { InstallationReposPort } from "./installation-repos-service.ts";
|
|
13
15
|
|
|
14
16
|
// Sync preview over the real cache service (fake prisma): complete, partial, stale.
|
|
@@ -67,7 +69,7 @@ describe("sync preview over the cache", () => {
|
|
|
67
69
|
const r = await preview(cache, now);
|
|
68
70
|
if (r.status !== "previewed") throw new Error(r.status);
|
|
69
71
|
expect(r.plan.removedRepos).toEqual([]);
|
|
70
|
-
expect(r.plan.skippedOrgs).
|
|
72
|
+
expect(r.plan.skippedOrgs).toMatchObject([
|
|
71
73
|
{ org: "acme", reason: "access data is incomplete" },
|
|
72
74
|
]);
|
|
73
75
|
});
|
|
@@ -132,3 +134,57 @@ describe("installation list access detail", () => {
|
|
|
132
134
|
expect(repos[1]?.userCanPush).toBeUndefined();
|
|
133
135
|
});
|
|
134
136
|
});
|
|
137
|
+
|
|
138
|
+
// A null-account agent: the lookup App's crawl is filed under the deployment-wide key.
|
|
139
|
+
describe("sync preview for a null-account agent over the real lookup read", () => {
|
|
140
|
+
it("is not skipped and proposes the expected adds from a complete, fresh cache", async () => {
|
|
141
|
+
const now = new Date();
|
|
142
|
+
const pushable = ["acme/a", "acme/b"];
|
|
143
|
+
const cache = freshCache("acme", REPOS, pushable, now);
|
|
144
|
+
const { prisma, state } = fakePrisma(REPOS, cache);
|
|
145
|
+
withLookupSnapshots(prisma, [
|
|
146
|
+
{
|
|
147
|
+
accountId: "deployment",
|
|
148
|
+
appRef: "77",
|
|
149
|
+
org: "acme",
|
|
150
|
+
completedAt: new Date(now.getTime() - 1000),
|
|
151
|
+
repos: REPOS.map((fullName) => ({ fullName })),
|
|
152
|
+
},
|
|
153
|
+
]);
|
|
154
|
+
const svc = createGithubSync({
|
|
155
|
+
prisma,
|
|
156
|
+
appService: {
|
|
157
|
+
get: async () =>
|
|
158
|
+
({
|
|
159
|
+
accountId: null,
|
|
160
|
+
appId: "77",
|
|
161
|
+
updatedAt: now,
|
|
162
|
+
}) as unknown as GitHubEnterpriseAppMetadata,
|
|
163
|
+
getPrivateKey: async () => "test-key",
|
|
164
|
+
},
|
|
165
|
+
access: accessFor([]), // the live resolver must not be consulted
|
|
166
|
+
agentEnv: envWith({ GH_APP_ID: "42" }),
|
|
167
|
+
// The agent App has only acme/a installed; acme/b is pushable but not added yet.
|
|
168
|
+
installationRepos: {
|
|
169
|
+
listRepos: async () => ({ acme: ["acme/a"] }),
|
|
170
|
+
listInstalled: async () => ({
|
|
171
|
+
status: "found",
|
|
172
|
+
orgs: [{ org: "acme", repos: ["acme/a"] }],
|
|
173
|
+
}),
|
|
174
|
+
addRepos: async () => {},
|
|
175
|
+
removeRepos: async () => {},
|
|
176
|
+
},
|
|
177
|
+
now: () => now,
|
|
178
|
+
});
|
|
179
|
+
const r = await svc.preview("a1");
|
|
180
|
+
if (r.status !== "previewed") throw new Error(r.status);
|
|
181
|
+
expect(r.plan.skippedOrgs).toEqual([]);
|
|
182
|
+
expect(r.plan.appAdds).toEqual(["acme/b"]);
|
|
183
|
+
const lookupQueries = state.snapshotQueries.filter(
|
|
184
|
+
(q) => (q as { where: { appKind?: string } }).where.appKind === "lookup",
|
|
185
|
+
);
|
|
186
|
+
expect(lookupQueries).toMatchObject([
|
|
187
|
+
{ where: { accountId: { in: ["deployment"] } } },
|
|
188
|
+
]);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
import {
|
|
22
22
|
canPushForRole,
|
|
23
23
|
type OrgAccessResult,
|
|
24
|
+
type OrgSkipDetail,
|
|
24
25
|
type ResolvedRepoAccess,
|
|
25
26
|
type UserRepoAccessResult,
|
|
26
27
|
} from "./user-repo-access-resolver.ts";
|
|
@@ -29,7 +30,13 @@ import type { RepoRole } from "./github-lookup-client.ts";
|
|
|
29
30
|
export interface CachedOrgInput {
|
|
30
31
|
org: string;
|
|
31
32
|
/** completedAt of each crawl snapshot this org depends on; null = not completed. Empty = none needed. */
|
|
32
|
-
crawls: {
|
|
33
|
+
crawls: {
|
|
34
|
+
completedAt: Date | null;
|
|
35
|
+
lastError?: string | null;
|
|
36
|
+
rateLimitResetAt?: Date | null;
|
|
37
|
+
}[];
|
|
38
|
+
/** Whether the lookup crawl snapshot was found (omit when no lookup source is wired). */
|
|
39
|
+
lookupSnapshotFound?: boolean;
|
|
33
40
|
/** True when a crawl snapshot that must exist does not. */
|
|
34
41
|
crawlMissing?: boolean;
|
|
35
42
|
/** Every repo (full name) that needs an answer. */
|
|
@@ -50,6 +57,49 @@ const ROLES = new Set<string>([
|
|
|
50
57
|
const nameOf = (fullName: string): string =>
|
|
51
58
|
fullName.slice(fullName.indexOf("/") + 1).toLowerCase();
|
|
52
59
|
|
|
60
|
+
function skipDetail(
|
|
61
|
+
o: CachedOrgInput,
|
|
62
|
+
answers: { row?: CachedAccessRow }[],
|
|
63
|
+
oldest?: Date,
|
|
64
|
+
): OrgSkipDetail {
|
|
65
|
+
const rows = answers.flatMap((a) => (a.row ? [a.row] : []));
|
|
66
|
+
const ok = rows.filter((r) => r.status === "ok").length;
|
|
67
|
+
const attempts = rows.flatMap((r) =>
|
|
68
|
+
r.attempts === undefined ? [] : [r.attempts],
|
|
69
|
+
);
|
|
70
|
+
const rowErrors = [
|
|
71
|
+
...new Set(
|
|
72
|
+
rows.flatMap((r) =>
|
|
73
|
+
r.status !== "ok" && r.lastError ? [r.lastError] : [],
|
|
74
|
+
),
|
|
75
|
+
),
|
|
76
|
+
].slice(0, 3);
|
|
77
|
+
return {
|
|
78
|
+
...(o.lookupSnapshotFound === undefined
|
|
79
|
+
? {}
|
|
80
|
+
: { lookupSnapshotFound: o.lookupSnapshotFound }),
|
|
81
|
+
crawls: o.crawls.map((c) => ({
|
|
82
|
+
completedAt: c.completedAt ? c.completedAt.toISOString() : null,
|
|
83
|
+
...(c.lastError === undefined ? {} : { lastError: c.lastError }),
|
|
84
|
+
...(c.rateLimitResetAt === undefined
|
|
85
|
+
? {}
|
|
86
|
+
: {
|
|
87
|
+
rateLimitResetAt: c.rateLimitResetAt
|
|
88
|
+
? c.rateLimitResetAt.toISOString()
|
|
89
|
+
: null,
|
|
90
|
+
}),
|
|
91
|
+
})),
|
|
92
|
+
totalRepos: o.repos.length,
|
|
93
|
+
reposWithOkAccess: ok,
|
|
94
|
+
reposMissingAnswer: answers.length - ok,
|
|
95
|
+
errorRows: rows.filter((r) => r.status === "error").length,
|
|
96
|
+
terminalRows: rows.filter((r) => r.status === "terminal").length,
|
|
97
|
+
...(attempts.length > 0 ? { maxAttempts: Math.max(...attempts) } : {}),
|
|
98
|
+
...(rowErrors.length > 0 ? { rowErrors } : {}),
|
|
99
|
+
...(oldest ? { oldestCheckedAt: oldest.toISOString() } : {}),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
53
103
|
export function buildCachedAccess(opts: {
|
|
54
104
|
username: string;
|
|
55
105
|
now: Date;
|
|
@@ -76,6 +126,7 @@ export function buildCachedAccess(opts: {
|
|
|
76
126
|
repos: [],
|
|
77
127
|
unresolved: missing.length,
|
|
78
128
|
reason: INCOMPLETE_ACCESS_REASON,
|
|
129
|
+
detail: skipDetail(o, answers),
|
|
79
130
|
});
|
|
80
131
|
continue;
|
|
81
132
|
}
|
|
@@ -93,6 +144,7 @@ export function buildCachedAccess(opts: {
|
|
|
93
144
|
repos: [],
|
|
94
145
|
unresolved: 0,
|
|
95
146
|
reason: staleAccessReason(unknownTime ? undefined : oldest),
|
|
147
|
+
detail: skipDetail(o, answers, unknownTime ? undefined : oldest),
|
|
96
148
|
});
|
|
97
149
|
continue;
|
|
98
150
|
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import { buildCachedAccess } from "./github-sync-cached-access.ts";
|
|
3
|
+
|
|
4
|
+
const NOW = new Date("2026-11-20T12:00:00.000Z");
|
|
5
|
+
const HOUR = 3_600_000;
|
|
6
|
+
const build = (o: Parameters<typeof buildCachedAccess>[0]["orgs"][number]) =>
|
|
7
|
+
buildCachedAccess({
|
|
8
|
+
username: "octo",
|
|
9
|
+
now: NOW,
|
|
10
|
+
maxAgeMs: 24 * HOUR,
|
|
11
|
+
orgs: [o],
|
|
12
|
+
}).orgs[0];
|
|
13
|
+
|
|
14
|
+
const row = (repo: string, over: Record<string, unknown> = {}) => ({
|
|
15
|
+
repo,
|
|
16
|
+
status: "ok",
|
|
17
|
+
canPush: true,
|
|
18
|
+
checkedAt: new Date(NOW.getTime() - HOUR),
|
|
19
|
+
...over,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("buildCachedAccess skip detail", () => {
|
|
23
|
+
it("reports a missing lookup snapshot", () => {
|
|
24
|
+
const r = build({
|
|
25
|
+
org: "acme",
|
|
26
|
+
crawls: [],
|
|
27
|
+
crawlMissing: true,
|
|
28
|
+
lookupSnapshotFound: false,
|
|
29
|
+
repos: [],
|
|
30
|
+
rows: [],
|
|
31
|
+
});
|
|
32
|
+
expect(r?.reason).toBe("access data is incomplete");
|
|
33
|
+
expect(r?.detail).toMatchObject({
|
|
34
|
+
lookupSnapshotFound: false,
|
|
35
|
+
totalRepos: 0,
|
|
36
|
+
reposWithOkAccess: 0,
|
|
37
|
+
reposMissingAnswer: 0,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("reports an incomplete crawl with its lastError and rateLimitResetAt", () => {
|
|
42
|
+
const reset = new Date("2026-11-20T13:00:00.000Z");
|
|
43
|
+
const r = build({
|
|
44
|
+
org: "acme",
|
|
45
|
+
crawls: [
|
|
46
|
+
{ completedAt: null, lastError: "boom", rateLimitResetAt: reset },
|
|
47
|
+
],
|
|
48
|
+
lookupSnapshotFound: true,
|
|
49
|
+
repos: ["acme/a"],
|
|
50
|
+
rows: [row("a")],
|
|
51
|
+
});
|
|
52
|
+
expect(r?.detail?.lookupSnapshotFound).toBe(true);
|
|
53
|
+
expect(r?.detail?.crawls).toEqual([
|
|
54
|
+
{
|
|
55
|
+
completedAt: null,
|
|
56
|
+
lastError: "boom",
|
|
57
|
+
rateLimitResetAt: reset.toISOString(),
|
|
58
|
+
},
|
|
59
|
+
]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("counts repos without an ok row, error and terminal rows", () => {
|
|
63
|
+
const r = build({
|
|
64
|
+
org: "acme",
|
|
65
|
+
crawls: [{ completedAt: NOW }],
|
|
66
|
+
repos: ["acme/a", "acme/b", "acme/c", "acme/d"],
|
|
67
|
+
rows: [
|
|
68
|
+
row("a"),
|
|
69
|
+
row("b", { status: "error", attempts: 3, lastError: "rate limited" }),
|
|
70
|
+
row("c", { status: "terminal", attempts: 5, lastError: "gone" }),
|
|
71
|
+
],
|
|
72
|
+
});
|
|
73
|
+
expect(r?.reason).toBe("access data is incomplete");
|
|
74
|
+
expect(r?.detail).toMatchObject({
|
|
75
|
+
totalRepos: 4,
|
|
76
|
+
reposWithOkAccess: 1,
|
|
77
|
+
reposMissingAnswer: 3,
|
|
78
|
+
errorRows: 1,
|
|
79
|
+
terminalRows: 1,
|
|
80
|
+
maxAttempts: 5,
|
|
81
|
+
rowErrors: ["rate limited", "gone"],
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("reports the oldest-checked time for stale data", () => {
|
|
86
|
+
const old = new Date(NOW.getTime() - 48 * HOUR);
|
|
87
|
+
const r = build({
|
|
88
|
+
org: "acme",
|
|
89
|
+
crawls: [{ completedAt: NOW }],
|
|
90
|
+
repos: ["acme/a"],
|
|
91
|
+
rows: [row("a", { checkedAt: old })],
|
|
92
|
+
});
|
|
93
|
+
expect(r?.reason).toBe(
|
|
94
|
+
`access data is stale (checked ${old.toISOString()})`,
|
|
95
|
+
);
|
|
96
|
+
expect(r?.detail).toMatchObject({
|
|
97
|
+
oldestCheckedAt: old.toISOString(),
|
|
98
|
+
totalRepos: 1,
|
|
99
|
+
reposWithOkAccess: 1,
|
|
100
|
+
reposMissingAnswer: 0,
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("has no detail for a usable org", () => {
|
|
105
|
+
const r = build({
|
|
106
|
+
org: "acme",
|
|
107
|
+
crawls: [{ completedAt: NOW }],
|
|
108
|
+
repos: ["acme/a"],
|
|
109
|
+
rows: [row("a")],
|
|
110
|
+
});
|
|
111
|
+
expect(r?.status).toBe("ok");
|
|
112
|
+
expect(r?.detail).toBeUndefined();
|
|
113
|
+
});
|
|
114
|
+
});
|
package/src/github-sync.ts
CHANGED
|
@@ -56,7 +56,10 @@ import {
|
|
|
56
56
|
previewRepoRemovalWork,
|
|
57
57
|
repoLostAccessBlockReason,
|
|
58
58
|
} from "./repo-removal-open-work.ts";
|
|
59
|
-
import type {
|
|
59
|
+
import type {
|
|
60
|
+
OrgSkipDetail,
|
|
61
|
+
UserRepoAccessResult,
|
|
62
|
+
} from "./user-repo-access-resolver.ts";
|
|
60
63
|
|
|
61
64
|
/** `planHash` of the audit row a sync apply writes. */
|
|
62
65
|
export const GITHUB_SYNC_AUDIT_PLAN_HASH = "sync:apply";
|
|
@@ -163,6 +166,7 @@ export function planGithubSync(input: GithubSyncPlanInput): GithubSyncPlan {
|
|
|
163
166
|
: [...configured.values()];
|
|
164
167
|
|
|
165
168
|
const skipReasons = new Map<string, string>();
|
|
169
|
+
const skipDetails = new Map<string, OrgSkipDetail>();
|
|
166
170
|
const notApplied = new Map<string, NotAppliedRepo>();
|
|
167
171
|
const leave = (repo: string, reason: string) => {
|
|
168
172
|
if (requested)
|
|
@@ -171,9 +175,11 @@ export function planGithubSync(input: GithubSyncPlanInput): GithubSyncPlan {
|
|
|
171
175
|
// Unknown is never none: false (with the reason recorded) for a skipped org.
|
|
172
176
|
const orgUsable = (repo: string): boolean => {
|
|
173
177
|
const org = repoOrg(repo);
|
|
174
|
-
const
|
|
178
|
+
const result = orgResults.get(lower(org));
|
|
179
|
+
const reason = orgSkipReason(result);
|
|
175
180
|
if (!reason) return true;
|
|
176
181
|
skipReasons.set(org, reason);
|
|
182
|
+
if (result?.detail) skipDetails.set(org, result.detail);
|
|
177
183
|
leave(repo, `skipped for org: ${reason}`);
|
|
178
184
|
return false;
|
|
179
185
|
};
|
|
@@ -224,6 +230,7 @@ export function planGithubSync(input: GithubSyncPlanInput): GithubSyncPlan {
|
|
|
224
230
|
const skippedOrgs = sorted(skipReasons.keys()).map((org) => ({
|
|
225
231
|
org,
|
|
226
232
|
reason: skipReasons.get(org) as string,
|
|
233
|
+
...(skipDetails.has(org) ? { detail: skipDetails.get(org) } : {}),
|
|
227
234
|
}));
|
|
228
235
|
return {
|
|
229
236
|
skipped: false,
|
|
@@ -244,6 +251,8 @@ export interface CachedLookupOrg {
|
|
|
244
251
|
org: string;
|
|
245
252
|
completedAt: Date | null;
|
|
246
253
|
repos: readonly string[];
|
|
254
|
+
lastError?: string | null;
|
|
255
|
+
rateLimitResetAt?: Date | null;
|
|
247
256
|
}
|
|
248
257
|
|
|
249
258
|
/** Default freshness bound: the refresher's staleness cap (the longest data is left unrefreshed). */
|
|
@@ -501,8 +510,22 @@ export class GithubSyncService {
|
|
|
501
510
|
repos.set(key(r), r);
|
|
502
511
|
}
|
|
503
512
|
const crawls = [
|
|
504
|
-
...(inst && snap
|
|
505
|
-
|
|
513
|
+
...(inst && snap
|
|
514
|
+
? [
|
|
515
|
+
{
|
|
516
|
+
completedAt: snap.completedAt,
|
|
517
|
+
lastError: snap.lastError,
|
|
518
|
+
rateLimitResetAt: snap.rateLimitResetAt,
|
|
519
|
+
},
|
|
520
|
+
]
|
|
521
|
+
: []),
|
|
522
|
+
...lk.map((l) => ({
|
|
523
|
+
completedAt: l.completedAt,
|
|
524
|
+
...(l.lastError === undefined ? {} : { lastError: l.lastError }),
|
|
525
|
+
...(l.rateLimitResetAt === undefined
|
|
526
|
+
? {}
|
|
527
|
+
: { rateLimitResetAt: l.rateLimitResetAt }),
|
|
528
|
+
})),
|
|
506
529
|
];
|
|
507
530
|
let rows: Awaited<ReturnType<InstallationCachePort["getAccessRows"]>> =
|
|
508
531
|
[];
|
|
@@ -522,6 +545,9 @@ export class GithubSyncService {
|
|
|
522
545
|
inputs.push({
|
|
523
546
|
org,
|
|
524
547
|
crawls,
|
|
548
|
+
...(this.deps.lookupRepos !== undefined
|
|
549
|
+
? { lookupSnapshotFound: lk.length > 0 }
|
|
550
|
+
: {}),
|
|
525
551
|
// A read failure, an installed org with no crawl, or a lookup source with no crawl of this org.
|
|
526
552
|
crawlMissing:
|
|
527
553
|
failed ||
|