@app-vitals/agent-admin 1.110.0 → 1.111.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.json +0 -193
- package/openapi.platform.json +1 -238
- package/package.json +2 -2
- package/src/admin-boot.ts +6 -5
- package/src/admin-ui-github-identity-pages.ts +35 -139
- package/src/admin-ui-github-identity-pages.unit.test.ts +50 -173
- package/src/admin-ui-github-identity.smoke.test.ts +103 -63
- package/src/admin-ui-installation-repos-pages.ts +2 -23
- package/src/admin-ui-installation-repos-pages.unit.test.ts +41 -36
- package/src/admin-ui-installation-repos.smoke.test.ts +9 -8
- package/src/admin-ui-pages.ts +4 -5
- package/src/admin-ui.ts +51 -36
- package/src/agents-api.smoke.test.ts +26 -315
- package/src/agents-api.ts +1 -107
- package/src/github-access-preview.ts +2 -2
- package/src/github-enterprise-api.smoke.test.ts +26 -0
- package/src/github-enterprise-api.ts +18 -2
- package/src/github-enterprise-client.integration.test.ts +0 -41
- package/src/github-enterprise-client.ts +0 -25
- package/src/github-enterprise-client.unit.test.ts +0 -18
- package/src/github-installation-wiring.ts +18 -12
- package/src/github-sync-all-repos.unit.test.ts +116 -0
- package/src/github-sync-snapshot-refresh.integration.test.ts +168 -0
- package/src/github-sync-snapshot-refresh.unit.test.ts +144 -0
- package/src/github-sync.ts +103 -137
- package/src/github-sync.unit.test.ts +82 -1
- package/src/installation-ports.ts +1 -40
- package/src/reconcile-open-work.integration.test.ts +0 -1
- package/src/github-access-preview.integration.test.ts +0 -399
- package/src/github-sync-switch.integration.test.ts +0 -297
- package/src/github-sync-switch.unit.test.ts +0 -467
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* admin/src/admin-ui-github-identity.smoke.test.ts
|
|
3
|
-
* Smoke tests (app.request()) for the GHE-2.5 GitHub username form post
|
|
4
|
-
*
|
|
3
|
+
* Smoke tests (app.request()) for the GHE-2.5 GitHub username form post on the
|
|
4
|
+
* agent detail page. The GHE-1.3 status and the agents
|
|
5
5
|
* API are stubbed seams; no DB, no network.
|
|
6
6
|
*/
|
|
7
7
|
|
|
@@ -24,6 +24,10 @@ function setup(opts: {
|
|
|
24
24
|
configured?: boolean | "installer-only";
|
|
25
25
|
agentsApi?: (path: string, init?: RequestInit) => Response;
|
|
26
26
|
enterpriseApi?: (path: string, init?: RequestInit) => Response;
|
|
27
|
+
installRepoChoices?: (
|
|
28
|
+
agentId: string,
|
|
29
|
+
orgs: string[],
|
|
30
|
+
) => Promise<Record<string, string[]>>;
|
|
27
31
|
}) {
|
|
28
32
|
const calls: { path: string; init?: RequestInit }[] = [];
|
|
29
33
|
const base = makeMockDeps();
|
|
@@ -46,6 +50,9 @@ function setup(opts: {
|
|
|
46
50
|
githubUsername: "octo",
|
|
47
51
|
}),
|
|
48
52
|
},
|
|
53
|
+
...(opts.installRepoChoices
|
|
54
|
+
? { installRepoChoices: opts.installRepoChoices }
|
|
55
|
+
: {}),
|
|
49
56
|
githubEnterpriseApi: (path: string, init?: RequestInit) => {
|
|
50
57
|
if (path !== "/github-enterprise/apps" && opts.enterpriseApi) {
|
|
51
58
|
calls.push({ path, init });
|
|
@@ -105,12 +112,12 @@ describe("admin UI — GitHub identity (GHE-2.5)", () => {
|
|
|
105
112
|
body: new URLSearchParams({ githubUsername: v }),
|
|
106
113
|
});
|
|
107
114
|
|
|
108
|
-
it("shows the row
|
|
115
|
+
it("shows the username row to an admin when configured", async () => {
|
|
109
116
|
const { app } = setup({});
|
|
110
117
|
const html = await (await get(app, admin)).text();
|
|
111
118
|
expect(html).toContain("Owner & identities");
|
|
112
119
|
expect(html).toContain("GitHub username");
|
|
113
|
-
expect(html).toContain(
|
|
120
|
+
expect(html).not.toContain("github-access-btn");
|
|
114
121
|
});
|
|
115
122
|
|
|
116
123
|
it("hides both when not configured", async () => {
|
|
@@ -175,62 +182,6 @@ describe("admin UI — GitHub identity (GHE-2.5)", () => {
|
|
|
175
182
|
expect(calls.length).toBe(0);
|
|
176
183
|
});
|
|
177
184
|
|
|
178
|
-
it("preview route calls the access API and renders the table", async () => {
|
|
179
|
-
const { app, calls } = setup({
|
|
180
|
-
agentsApi: () =>
|
|
181
|
-
json({
|
|
182
|
-
status: "ok",
|
|
183
|
-
access: {
|
|
184
|
-
username: "octo",
|
|
185
|
-
outcome: "ok",
|
|
186
|
-
userVerified: true,
|
|
187
|
-
orgs: [
|
|
188
|
-
{
|
|
189
|
-
org: "acme",
|
|
190
|
-
status: "partial",
|
|
191
|
-
unresolved: 1,
|
|
192
|
-
repos: [
|
|
193
|
-
{ fullName: "acme/api", level: "admin", canPush: true },
|
|
194
|
-
],
|
|
195
|
-
},
|
|
196
|
-
],
|
|
197
|
-
unresolved: 1,
|
|
198
|
-
complete: false,
|
|
199
|
-
checkedAt: "2026-11-10T00:00:00Z",
|
|
200
|
-
},
|
|
201
|
-
}),
|
|
202
|
-
});
|
|
203
|
-
const res = await app.request(`/admin/agents/${AGENT_ID}/github-access`, {
|
|
204
|
-
headers: { Cookie: `admin_session=${admin}` },
|
|
205
|
-
});
|
|
206
|
-
expect(res.status).toBe(200);
|
|
207
|
-
const html = await res.text();
|
|
208
|
-
expect(calls.at(-1)?.path).toBe(`/agents/${AGENT_ID}/github-access`);
|
|
209
|
-
expect(html).toContain("acme/api");
|
|
210
|
-
expect(html).toContain("Partial results");
|
|
211
|
-
expect(html).toContain("Can push");
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
it("preview route surfaces an API error (no username bound)", async () => {
|
|
215
|
-
const { app } = setup({
|
|
216
|
-
agentsApi: () => json({ error: "no githubUsername bound" }, 422),
|
|
217
|
-
});
|
|
218
|
-
const res = await app.request(`/admin/agents/${AGENT_ID}/github-access`, {
|
|
219
|
-
headers: { Cookie: `admin_session=${admin}` },
|
|
220
|
-
});
|
|
221
|
-
expect(res.status).toBe(422);
|
|
222
|
-
expect(await res.text()).toContain("no githubUsername bound");
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
it("preview route is forbidden for a non-admin", async () => {
|
|
226
|
-
const { app, calls } = setup({});
|
|
227
|
-
const res = await app.request(`/admin/agents/${AGENT_ID}/github-access`, {
|
|
228
|
-
headers: { Cookie: `admin_session=${member}` },
|
|
229
|
-
});
|
|
230
|
-
expect(res.status).toBe(403);
|
|
231
|
-
expect(calls.length).toBe(0);
|
|
232
|
-
});
|
|
233
|
-
|
|
234
185
|
describe("Install on org (GHC-1.2)", () => {
|
|
235
186
|
const orgsUrl = `/admin/agents/${AGENT_ID}/github-orgs`;
|
|
236
187
|
const installUrl = `${orgsUrl}/acme/install`;
|
|
@@ -294,6 +245,90 @@ describe("admin UI — GitHub identity (GHE-2.5)", () => {
|
|
|
294
245
|
expect(JSON.parse(String(c?.init?.body))).toEqual({ agentId: AGENT_ID });
|
|
295
246
|
});
|
|
296
247
|
|
|
248
|
+
const form = (body: URLSearchParams) => ({
|
|
249
|
+
method: "POST",
|
|
250
|
+
headers: {
|
|
251
|
+
Cookie: `admin_session=${admin}`,
|
|
252
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
253
|
+
},
|
|
254
|
+
body,
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("install: selected passes repositorySelection and repositories", async () => {
|
|
258
|
+
const { app, calls } = setup({
|
|
259
|
+
enterpriseApi: () => json({ created: true }),
|
|
260
|
+
});
|
|
261
|
+
const body = new URLSearchParams();
|
|
262
|
+
body.append("repositorySelection", "selected");
|
|
263
|
+
body.append("repositories", "api");
|
|
264
|
+
body.append("repositories", "web");
|
|
265
|
+
const res = await app.request(installUrl, form(body));
|
|
266
|
+
expect(res.headers.get("location")).toContain("github_app_installed");
|
|
267
|
+
expect(JSON.parse(String(calls.at(-1)?.init?.body))).toEqual({
|
|
268
|
+
agentId: AGENT_ID,
|
|
269
|
+
repositorySelection: "selected",
|
|
270
|
+
repositories: ["api", "web"],
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("install: all posts only the agent id", async () => {
|
|
275
|
+
const { app, calls } = setup({
|
|
276
|
+
enterpriseApi: () => json({ created: true }),
|
|
277
|
+
});
|
|
278
|
+
const res = await app.request(
|
|
279
|
+
installUrl,
|
|
280
|
+
form(new URLSearchParams({ repositorySelection: "all" })),
|
|
281
|
+
);
|
|
282
|
+
expect(res.status).toBe(302);
|
|
283
|
+
expect(JSON.parse(String(calls.at(-1)?.init?.body))).toEqual({
|
|
284
|
+
agentId: AGENT_ID,
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("install: selected with none or over 50 is refused before the API", async () => {
|
|
289
|
+
const { app, calls } = setup({
|
|
290
|
+
enterpriseApi: () => json({ created: true }),
|
|
291
|
+
});
|
|
292
|
+
const before = calls.length;
|
|
293
|
+
const none = await app.request(
|
|
294
|
+
installUrl,
|
|
295
|
+
form(new URLSearchParams({ repositorySelection: "selected" })),
|
|
296
|
+
);
|
|
297
|
+
expect(none.headers.get("location")).toContain("error=");
|
|
298
|
+
const many = new URLSearchParams({ repositorySelection: "selected" });
|
|
299
|
+
for (let i = 0; i < 51; i++) many.append("repositories", `r${i}`);
|
|
300
|
+
const over = await app.request(installUrl, form(many));
|
|
301
|
+
expect(over.headers.get("location")).toContain("error=");
|
|
302
|
+
expect(calls.length).toBe(before);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("fragment pre-fills from the cached choices dep, no GitHub call", async () => {
|
|
306
|
+
const calls2: string[] = [];
|
|
307
|
+
const { app } = setup({
|
|
308
|
+
enterpriseApi: () =>
|
|
309
|
+
json({
|
|
310
|
+
configured: true,
|
|
311
|
+
agentAppReason: null,
|
|
312
|
+
orgs: [
|
|
313
|
+
{
|
|
314
|
+
id: 1,
|
|
315
|
+
login: "acme",
|
|
316
|
+
lookupAppInstalled: true,
|
|
317
|
+
agentAppInstalled: false,
|
|
318
|
+
},
|
|
319
|
+
],
|
|
320
|
+
}),
|
|
321
|
+
installRepoChoices: async (_id, orgs) => {
|
|
322
|
+
calls2.push(orgs.join(","));
|
|
323
|
+
return { acme: ["api"] };
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
const html = await (await app.request(orgsUrl, opts(admin))).text();
|
|
327
|
+
expect(calls2).toEqual(["acme"]);
|
|
328
|
+
expect(html).toContain('name="repositories" value="api" checked');
|
|
329
|
+
expect(html).toContain('value="selected" checked');
|
|
330
|
+
});
|
|
331
|
+
|
|
297
332
|
it("install: already installed", async () => {
|
|
298
333
|
const { app } = setup({
|
|
299
334
|
enterpriseApi: () => json({ created: false }),
|
|
@@ -354,7 +389,10 @@ describe("admin UI — GitHub identity (GHE-2.5)", () => {
|
|
|
354
389
|
const { app, calls } = setup({
|
|
355
390
|
enterpriseApi: () => json({ status: "uninstalled" }),
|
|
356
391
|
});
|
|
357
|
-
const res = await app.request(
|
|
392
|
+
const res = await app.request(
|
|
393
|
+
`${orgsUrl}/acme/uninstall`,
|
|
394
|
+
opts(admin, "POST"),
|
|
395
|
+
);
|
|
358
396
|
expect(res.status).toBe(302);
|
|
359
397
|
expect(res.headers.get("location")).toBe(
|
|
360
398
|
`/admin/agents/${AGENT_ID}/access?success=github_app_uninstalled`,
|
|
@@ -388,10 +426,12 @@ describe("admin UI — GitHub identity (GHE-2.5)", () => {
|
|
|
388
426
|
it("uninstall routes are forbidden for a non-admin and make no call", async () => {
|
|
389
427
|
const { app, calls } = setup({});
|
|
390
428
|
expect(
|
|
391
|
-
(await app.request(`${orgsUrl}/acme/uninstall`, opts(member, "POST")))
|
|
429
|
+
(await app.request(`${orgsUrl}/acme/uninstall`, opts(member, "POST")))
|
|
430
|
+
.status,
|
|
392
431
|
).toBe(403);
|
|
393
432
|
expect(
|
|
394
|
-
(await app.request(`${orgsUrl}/acme/uninstall-confirm`, opts(member)))
|
|
433
|
+
(await app.request(`${orgsUrl}/acme/uninstall-confirm`, opts(member)))
|
|
434
|
+
.status,
|
|
395
435
|
).toBe(403);
|
|
396
436
|
expect(calls.length).toBe(0);
|
|
397
437
|
});
|
|
@@ -208,7 +208,6 @@ export interface GithubSyncPreviewView {
|
|
|
208
208
|
appAdds?: string[];
|
|
209
209
|
appRemoves?: string[];
|
|
210
210
|
agentRemoves?: string[];
|
|
211
|
-
selectionSwitches?: { org: string; repos: string[] }[];
|
|
212
211
|
skippedOrgs?: { org: string; reason: string; detail?: SkipDetail }[];
|
|
213
212
|
openWork?: OpenWorkView[];
|
|
214
213
|
warnings?: string[];
|
|
@@ -466,19 +465,6 @@ const repoList = (kind: string, title: string, repos: readonly string[]) =>
|
|
|
466
465
|
const plural = (n: number, one: string, many: string) =>
|
|
467
466
|
`${n} ${n === 1 ? one : many}`;
|
|
468
467
|
|
|
469
|
-
/** Orgs the confirmed sync switches from "all repositories" to "selected repositories". */
|
|
470
|
-
const selectionSwitchesHtml = (
|
|
471
|
-
switches: readonly { org: string; repos: readonly string[] }[],
|
|
472
|
-
) =>
|
|
473
|
-
switches.length === 0
|
|
474
|
-
? ""
|
|
475
|
-
: `<div data-list="selection-switches" style="margin-top:8px"><div style="font-weight:600">Switch from all repositories to selected repositories (${switches.length})</div><ul style="margin:4px 0 0 18px">${switches
|
|
476
|
-
.map(
|
|
477
|
-
(s) =>
|
|
478
|
-
`<li data-switch-org="${escapeHtml(s.org)}"><span class="mono">${escapeHtml(s.org)}</span>: keeps ${plural(s.repos.length, "repo", "repos")}</li>`,
|
|
479
|
-
)
|
|
480
|
-
.join("")}</ul></div>`;
|
|
481
|
-
|
|
482
468
|
/** One readable sentence-list describing why an org's cached access was skipped. */
|
|
483
469
|
function skipDetailText(d: SkipDetail, timezone?: string): string {
|
|
484
470
|
const out: string[] = [];
|
|
@@ -558,19 +544,12 @@ export function renderSyncConfirm(
|
|
|
558
544
|
const appAdds = preview.appAdds ?? [];
|
|
559
545
|
const appRemoves = preview.appRemoves ?? [];
|
|
560
546
|
const agentRemoves = preview.agentRemoves ?? [];
|
|
561
|
-
const switches = preview.selectionSwitches ?? [];
|
|
562
547
|
const skippedList = preview.skippedOrgs ?? [];
|
|
563
548
|
const skipped = skippedOrgsHtml(skippedList, timezone);
|
|
564
549
|
const warnings = warningsHtml(
|
|
565
550
|
withoutSkipWarnings(preview.warnings, skippedList),
|
|
566
551
|
);
|
|
567
|
-
if (
|
|
568
|
-
appAdds.length +
|
|
569
|
-
appRemoves.length +
|
|
570
|
-
agentRemoves.length +
|
|
571
|
-
switches.length ===
|
|
572
|
-
0
|
|
573
|
-
) {
|
|
552
|
+
if (appAdds.length + appRemoves.length + agentRemoves.length === 0) {
|
|
574
553
|
if (skippedList.length > 0) {
|
|
575
554
|
return `<div class="alert alert-warning" data-sync="nothing-synced">Nothing was synced: ${skippedList.length} org(s) skipped, see below.</div>${skipped}${warnings}`;
|
|
576
555
|
}
|
|
@@ -585,7 +564,7 @@ export function renderSyncConfirm(
|
|
|
585
564
|
const capBox = overCap
|
|
586
565
|
? `<label style="display:block;margin:12px 0"><input type="checkbox" id="github-sync-confirm-removals" /> I confirm removing ${removals} repos (more than ${MAX_UNCONFIRMED_REMOVALS}).</label>`
|
|
587
566
|
: "";
|
|
588
|
-
return `<div class="alert alert-warning" data-sync="confirm">Apply these changes?</div>${
|
|
567
|
+
return `<div class="alert alert-warning" data-sync="confirm">Apply these changes?</div>${repoList("app-adds", "Add to the agent App installation", appAdds)}${repoList("app-removes", "Remove from the agent App installation", appRemoves)}${repoList("agent-removes", "Remove from the agent's repos", agentRemoves)}${renderOpenWorkByRepo(
|
|
589
568
|
preview.openWork ?? [],
|
|
590
569
|
"Open tasks and PRs that will be blocked",
|
|
591
570
|
"No open tasks or PRs would be blocked.",
|
|
@@ -133,6 +133,40 @@ describe("renderInstallationReposBody", () => {
|
|
|
133
133
|
expect(html).not.toContain('data-reason="app-id-mismatch"');
|
|
134
134
|
});
|
|
135
135
|
|
|
136
|
+
it("says the snapshot is still syncing when it is incomplete", () => {
|
|
137
|
+
const html = renderInstallationReposBody({
|
|
138
|
+
complete: false,
|
|
139
|
+
orgs: [{ org: "acme", repos: [] }],
|
|
140
|
+
});
|
|
141
|
+
expect(html).toContain("have not finished syncing yet");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("renders empty orgs, cannot-push hints and access details", () => {
|
|
145
|
+
const html = renderInstallationReposBody({
|
|
146
|
+
orgs: [
|
|
147
|
+
{ org: "empty", repos: [] },
|
|
148
|
+
{
|
|
149
|
+
org: "acme",
|
|
150
|
+
repos: [
|
|
151
|
+
{
|
|
152
|
+
fullName: "acme/ro",
|
|
153
|
+
userCanPush: false,
|
|
154
|
+
accessCheckedAt: "2026-11-25T00:00:00.000Z",
|
|
155
|
+
accessAttempts: 2,
|
|
156
|
+
accessError: "boom <e>",
|
|
157
|
+
},
|
|
158
|
+
{ fullName: "acme/rw", userCanPush: true },
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
});
|
|
163
|
+
expect(html).toContain("No repos.");
|
|
164
|
+
expect(html).toContain("user cannot push");
|
|
165
|
+
expect(html).toContain("user can push");
|
|
166
|
+
expect(html).toContain("2 failed attempts");
|
|
167
|
+
expect(html).toContain("error: boom <e>");
|
|
168
|
+
});
|
|
169
|
+
|
|
136
170
|
it("shows a distinct GH_APP_ID mismatch message", () => {
|
|
137
171
|
const html = renderInstallationReposBody(
|
|
138
172
|
{ orgs: [] },
|
|
@@ -187,45 +221,16 @@ describe("renderSyncConfirm", () => {
|
|
|
187
221
|
});
|
|
188
222
|
});
|
|
189
223
|
|
|
190
|
-
it("
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
selectionSwitches: [
|
|
194
|
-
{ org: "acme", repos: ["acme/a", "acme/b"] },
|
|
195
|
-
{ org: "solo<x>", repos: ["solo/a"] },
|
|
196
|
-
],
|
|
197
|
-
});
|
|
198
|
-
expect(html).toContain('data-list="selection-switches"');
|
|
199
|
-
expect(html).toContain("all repositories to selected repositories (2)");
|
|
200
|
-
expect(html).toContain('data-switch-org="acme"');
|
|
201
|
-
expect(html).toContain("keeps 2 repos");
|
|
202
|
-
expect(html).toContain("solo<x>");
|
|
203
|
-
expect(html).toContain("keeps 1 repo<");
|
|
204
|
-
expect(html.match(/id="github-sync-confirm-btn"/g)?.length).toBe(1);
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it("confirms a switch-only plan instead of saying in sync", () => {
|
|
224
|
+
it("shows the all-repositories message for a skipped org and nothing to confirm", () => {
|
|
225
|
+
const reason =
|
|
226
|
+
"Sync does not work when the app has access to all repositories; uninstall the app and install again with selected repositories.";
|
|
208
227
|
const html = renderSyncConfirm("a1", {
|
|
209
228
|
status: "previewed",
|
|
210
|
-
|
|
211
|
-
});
|
|
212
|
-
expect(html).toContain('data-sync="confirm"');
|
|
213
|
-
expect(html).not.toContain("in-sync");
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it("shows the empty-target skip warning with the Uninstall hint", () => {
|
|
217
|
-
const html = renderSyncConfirm("a1", {
|
|
218
|
-
...preview,
|
|
219
|
-
skippedOrgs: [
|
|
220
|
-
{
|
|
221
|
-
org: "empty-org",
|
|
222
|
-
reason:
|
|
223
|
-
"the bound user can push to none of this org's repos, so it stays on All repositories; use Uninstall to remove the agent App from this org",
|
|
224
|
-
},
|
|
225
|
-
],
|
|
229
|
+
skippedOrgs: [{ org: "acme", reason }],
|
|
226
230
|
});
|
|
227
|
-
expect(html).toContain("
|
|
228
|
-
expect(html).toContain("
|
|
231
|
+
expect(html).toContain("uninstall the app and install again");
|
|
232
|
+
expect(html).toContain('data-sync="nothing-synced"');
|
|
233
|
+
expect(html).not.toContain("github-sync-confirm-btn");
|
|
229
234
|
});
|
|
230
235
|
|
|
231
236
|
it("requires the over-cap checkbox for more than 10 removals", () => {
|
|
@@ -126,7 +126,7 @@ describe("admin UI — GitHub sync card (IRM-3.2)", () => {
|
|
|
126
126
|
expect(cardHtml).not.toContain("<input");
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
-
it("lookup-only: shows the
|
|
129
|
+
it("lookup-only: shows the plain installer explanation, no Sync button or installer-backed body", async () => {
|
|
130
130
|
const { app, calls } = setup({
|
|
131
131
|
enterprise: {
|
|
132
132
|
configured: true,
|
|
@@ -135,7 +135,7 @@ describe("admin UI — GitHub sync card (IRM-3.2)", () => {
|
|
|
135
135
|
},
|
|
136
136
|
});
|
|
137
137
|
const html = await (await get(app, "/access")).text();
|
|
138
|
-
expect(html).toContain('id="github-access-btn"');
|
|
138
|
+
expect(html).not.toContain('id="github-access-btn"');
|
|
139
139
|
const card = html.slice(html.indexOf('id="github-installation-card"'));
|
|
140
140
|
const cardHtml = card.slice(0, card.indexOf("</script>"));
|
|
141
141
|
expect(cardHtml).toContain('data-reason="lookup-only"');
|
|
@@ -158,7 +158,7 @@ describe("admin UI — GitHub sync card (IRM-3.2)", () => {
|
|
|
158
158
|
it("both Apps: renders as before, with no lookup-only or lookup-missing text", async () => {
|
|
159
159
|
const { app } = setup({ agentsApi: () => json(INSTALLED) });
|
|
160
160
|
const html = await (await get(app, "/access")).text();
|
|
161
|
-
expect(html).toContain('id="github-access-btn"');
|
|
161
|
+
expect(html).not.toContain('id="github-access-btn"');
|
|
162
162
|
expect(html).toContain('id="github-sync-btn"');
|
|
163
163
|
expect(html).toContain('id="github-installation-body"');
|
|
164
164
|
expect(html).toContain(
|
|
@@ -397,18 +397,19 @@ describe("admin UI — GitHub sync card (IRM-3.2)", () => {
|
|
|
397
397
|
expect(html).toContain("30 repos have no access answer yet.");
|
|
398
398
|
});
|
|
399
399
|
|
|
400
|
-
it("
|
|
400
|
+
it("shows the all-repositories reinstall message for a skipped org", async () => {
|
|
401
|
+
const reason =
|
|
402
|
+
"Sync does not work when the app has access to all repositories; uninstall the app and install again with selected repositories.";
|
|
401
403
|
const { app } = setup({
|
|
402
404
|
agentsApi: () =>
|
|
403
405
|
json({
|
|
404
406
|
status: "previewed",
|
|
405
|
-
|
|
407
|
+
skippedOrgs: [{ org: "acme", reason }],
|
|
406
408
|
}),
|
|
407
409
|
});
|
|
408
410
|
const html = await (await get(app, "/github-sync/confirm")).text();
|
|
409
|
-
expect(html).toContain('data-
|
|
410
|
-
expect(html).toContain(
|
|
411
|
-
expect(html).toContain("keeps 2 repos");
|
|
411
|
+
expect(html).toContain('data-sync="nothing-synced"');
|
|
412
|
+
expect(html).toContain("uninstall the app and install again");
|
|
412
413
|
});
|
|
413
414
|
|
|
414
415
|
it("shows the reason for a skipped preview", async () => {
|
package/src/admin-ui-pages.ts
CHANGED
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
import { PROGRESS_LABELS } from "@app-vitals/agent-lib/progress-phases";
|
|
14
14
|
import { getOwnerAgentSpecialty } from "./account-agent-create.ts";
|
|
15
15
|
import {
|
|
16
|
-
renderGithubAccessCard,
|
|
17
16
|
renderGithubInstallCard,
|
|
18
17
|
renderGithubUsernameRow,
|
|
19
18
|
} from "./admin-ui-github-identity-pages.ts";
|
|
@@ -1276,7 +1275,7 @@ export function renderAgentDetailPage(
|
|
|
1276
1275
|
marketplaces?: MarketplaceItem[];
|
|
1277
1276
|
/**
|
|
1278
1277
|
* GHE-2.5: the enterprise GitHub apps are configured. With isAdmin this
|
|
1279
|
-
* adds the GitHub username row
|
|
1278
|
+
* adds the GitHub username row; absent or
|
|
1280
1279
|
* false renders the card without them.
|
|
1281
1280
|
*/
|
|
1282
1281
|
githubEnterpriseConfigured?: boolean;
|
|
@@ -1847,7 +1846,7 @@ export function renderAgentDetailPage(
|
|
|
1847
1846
|
const appsState: GithubAppsState | undefined =
|
|
1848
1847
|
opts?.githubAppsState ??
|
|
1849
1848
|
(opts?.githubEnterpriseConfigured === true ? "both" : undefined);
|
|
1850
|
-
// Username
|
|
1849
|
+
// Username and the repo-removal flow need the lookup App;
|
|
1851
1850
|
// the Sync/Install cards also show for a missing lookup App, to say so.
|
|
1852
1851
|
const showGithubIdentity =
|
|
1853
1852
|
isAdmin && (appsState === "both" || appsState === "lookup_only");
|
|
@@ -2259,8 +2258,8 @@ export function renderAgentDetailPage(
|
|
|
2259
2258
|
</div>`;
|
|
2260
2259
|
|
|
2261
2260
|
// One GitHub card: connect actions plus (admin + enterprise GitHub) the
|
|
2262
|
-
//
|
|
2263
|
-
const githubCardBody = `${githubConnectActionsHtml}${
|
|
2261
|
+
// GitHub sync fragments.
|
|
2262
|
+
const githubCardBody = `${githubConnectActionsHtml}${showGithubCards ? renderGithubSyncCard(agent.id, { hasAppId: "GH_APP_ID" in envVars, githubUsername: agent.githubUsername, ...(appsState === "both" ? {} : { appsState }) }) : ""}${showGithubIdentity ? renderGithubInstallCard(agent.id, appsState) : ""}`;
|
|
2264
2263
|
const githubSection =
|
|
2265
2264
|
canManage && githubCardBody.trim() !== ""
|
|
2266
2265
|
? `<div class="card">
|
package/src/admin-ui.ts
CHANGED
|
@@ -53,10 +53,9 @@ import { registerAdminAccountsRoutes } from "./admin-ui-accounts.ts";
|
|
|
53
53
|
import { registerAdminGithubEnterpriseRoutes } from "./admin-ui-github-enterprise.ts";
|
|
54
54
|
import type { GheOrgs } from "./admin-ui-github-enterprise-pages.ts";
|
|
55
55
|
import {
|
|
56
|
-
type GithubAccessPreviewView,
|
|
57
56
|
type GithubUninstallPreviewView,
|
|
58
57
|
renderGithubAccessError,
|
|
59
|
-
|
|
58
|
+
MAX_INSTALL_REPOSITORIES,
|
|
60
59
|
renderGithubOrgsFragment,
|
|
61
60
|
renderGithubUninstallConfirm,
|
|
62
61
|
} from "./admin-ui-github-identity-pages.ts";
|
|
@@ -531,14 +530,21 @@ export interface AdminUIDeps {
|
|
|
531
530
|
AdminSlackConfigTokenRouteDeps,
|
|
532
531
|
"tokens" | "rotateClient" | "encryptionConfigured"
|
|
533
532
|
>;
|
|
533
|
+
/**
|
|
534
|
+
* Cached repo names the bound user can push to, per org, for the org Install
|
|
535
|
+
* picker. Cache only (no GitHub call). Optional: absent = no pre-fill.
|
|
536
|
+
*/
|
|
537
|
+
installRepoChoices?: (
|
|
538
|
+
agentId: string,
|
|
539
|
+
orgs: string[],
|
|
540
|
+
) => Promise<Record<string, string[]>>;
|
|
534
541
|
githubEnterpriseApi?: (
|
|
535
542
|
path: string,
|
|
536
543
|
init?: RequestInit,
|
|
537
544
|
) => Response | Promise<Response>;
|
|
538
545
|
/**
|
|
539
|
-
* GHE-2.5: the admin API app's `request` (PATCH /agents/:id
|
|
540
|
-
*
|
|
541
|
-
* GitHub username row and the access preview.
|
|
546
|
+
* GHE-2.5: the admin API app's `request` (PATCH /agents/:id).
|
|
547
|
+
* Optional (additive): absent hides the GitHub username row.
|
|
542
548
|
*/
|
|
543
549
|
agentsApi?: (
|
|
544
550
|
path: string,
|
|
@@ -996,6 +1002,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
996
1002
|
ensureAccountMember,
|
|
997
1003
|
accountServices,
|
|
998
1004
|
githubEnterpriseApi,
|
|
1005
|
+
installRepoChoices,
|
|
999
1006
|
templateService,
|
|
1000
1007
|
slackConfigToken,
|
|
1001
1008
|
templateReconcile,
|
|
@@ -2234,33 +2241,6 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
2234
2241
|
);
|
|
2235
2242
|
});
|
|
2236
2243
|
|
|
2237
|
-
app.get("/admin/agents/:id/github-access", requireAuth, async (c) => {
|
|
2238
|
-
const agentId = c.req.param("id");
|
|
2239
|
-
if (!c.var.isAdmin || !agentsApi) {
|
|
2240
|
-
return new Response("Forbidden", { status: 403 });
|
|
2241
|
-
}
|
|
2242
|
-
const res = await callApi(
|
|
2243
|
-
c,
|
|
2244
|
-
agentsApi,
|
|
2245
|
-
`/agents/${encodeURIComponent(agentId)}/github-access`,
|
|
2246
|
-
);
|
|
2247
|
-
if (!res?.ok) {
|
|
2248
|
-
let message = "Could not load the access preview.";
|
|
2249
|
-
try {
|
|
2250
|
-
const j = (await res?.json()) as { error?: unknown };
|
|
2251
|
-
if (typeof j.error === "string" && j.error) message = j.error;
|
|
2252
|
-
} catch {
|
|
2253
|
-
// keep the generic message
|
|
2254
|
-
}
|
|
2255
|
-
return html(renderGithubAccessError(message), {
|
|
2256
|
-
status: res && res.status >= 400 ? res.status : 502,
|
|
2257
|
-
});
|
|
2258
|
-
}
|
|
2259
|
-
return html(
|
|
2260
|
-
renderGithubAccessResult((await res.json()) as GithubAccessPreviewView),
|
|
2261
|
-
);
|
|
2262
|
-
});
|
|
2263
|
-
|
|
2264
2244
|
// GHC-1.2: Install on org block on the agent's GitHub card. Both routes
|
|
2265
2245
|
// call the GHE-1.3 API with the agent implicit (the route's :id).
|
|
2266
2246
|
const gheError = async (res: Response | null, fallback: string) => {
|
|
@@ -2291,9 +2271,19 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
2291
2271
|
{ status: res && res.status >= 400 ? res.status : 502 },
|
|
2292
2272
|
);
|
|
2293
2273
|
}
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
)
|
|
2274
|
+
const orgsData = (await res.json()) as GheOrgs;
|
|
2275
|
+
let choices: Record<string, string[]> = {};
|
|
2276
|
+
if (installRepoChoices) {
|
|
2277
|
+
try {
|
|
2278
|
+
choices = await installRepoChoices(
|
|
2279
|
+
agentId,
|
|
2280
|
+
orgsData.orgs.filter((o) => !o.agentAppInstalled).map((o) => o.login),
|
|
2281
|
+
);
|
|
2282
|
+
} catch {
|
|
2283
|
+
// The pre-fill is advisory: fall back to no cached choices.
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
return html(renderGithubOrgsFragment(agentId, orgsData, choices));
|
|
2297
2287
|
});
|
|
2298
2288
|
|
|
2299
2289
|
// GLC-2.4: fire-and-forget Refresh. Proxies the 202 API route and redirects
|
|
@@ -2333,6 +2323,27 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
2333
2323
|
if (!c.var.isAdmin || !githubEnterpriseApi) {
|
|
2334
2324
|
return new Response("Forbidden", { status: 403 });
|
|
2335
2325
|
}
|
|
2326
|
+
const form: Record<string, unknown> = await c.req
|
|
2327
|
+
.parseBody({ all: true })
|
|
2328
|
+
.catch(() => ({}));
|
|
2329
|
+
const selected = form.repositorySelection === "selected";
|
|
2330
|
+
const repositories = [form.repositories ?? []]
|
|
2331
|
+
.flat()
|
|
2332
|
+
.filter((r): r is string => typeof r === "string")
|
|
2333
|
+
.map((r) => r.trim())
|
|
2334
|
+
.filter(Boolean);
|
|
2335
|
+
if (
|
|
2336
|
+
selected &&
|
|
2337
|
+
(repositories.length === 0 ||
|
|
2338
|
+
repositories.length > MAX_INSTALL_REPOSITORIES)
|
|
2339
|
+
) {
|
|
2340
|
+
return c.redirect(
|
|
2341
|
+
agentSectionPath(agentId, "access", {
|
|
2342
|
+
error: `Select between 1 and ${MAX_INSTALL_REPOSITORIES} repositories, or install on all.`,
|
|
2343
|
+
}),
|
|
2344
|
+
302,
|
|
2345
|
+
);
|
|
2346
|
+
}
|
|
2336
2347
|
const res = await callApi(
|
|
2337
2348
|
c,
|
|
2338
2349
|
githubEnterpriseApi,
|
|
@@ -2340,7 +2351,11 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
2340
2351
|
{
|
|
2341
2352
|
method: "POST",
|
|
2342
2353
|
headers: { "content-type": "application/json" },
|
|
2343
|
-
body: JSON.stringify(
|
|
2354
|
+
body: JSON.stringify(
|
|
2355
|
+
selected
|
|
2356
|
+
? { agentId, repositorySelection: "selected", repositories }
|
|
2357
|
+
: { agentId },
|
|
2358
|
+
),
|
|
2344
2359
|
},
|
|
2345
2360
|
);
|
|
2346
2361
|
if (!res?.ok) {
|