@app-vitals/agent-admin 1.110.0 → 1.112.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.
Files changed (44) hide show
  1. package/openapi.json +0 -193
  2. package/openapi.platform.json +1 -238
  3. package/package.json +2 -2
  4. package/prisma/client/internal/class.ts +4 -4
  5. package/prisma/client/internal/prismaNamespace.ts +1 -0
  6. package/prisma/client/internal/prismaNamespaceBrowser.ts +1 -0
  7. package/prisma/client/models/UserNotificationPrefs.ts +29 -1
  8. package/prisma/migrations/20261201000000_rename_user_notification_prefs_to_user_prefs/migration.sql +4 -0
  9. package/prisma/schema/schema.prisma +3 -0
  10. package/src/admin-boot.ts +6 -5
  11. package/src/admin-ui-github-identity-pages.ts +35 -139
  12. package/src/admin-ui-github-identity-pages.unit.test.ts +50 -173
  13. package/src/admin-ui-github-identity.smoke.test.ts +103 -63
  14. package/src/admin-ui-installation-repos-pages.ts +2 -23
  15. package/src/admin-ui-installation-repos-pages.unit.test.ts +41 -36
  16. package/src/admin-ui-installation-repos.smoke.test.ts +9 -8
  17. package/src/admin-ui-pages.ts +4 -5
  18. package/src/admin-ui.ts +51 -36
  19. package/src/agents-api.smoke.test.ts +26 -315
  20. package/src/agents-api.ts +1 -107
  21. package/src/drop-email-key-columns-migration.integration.test.ts +0 -4
  22. package/src/github-access-preview.ts +2 -2
  23. package/src/github-enterprise-api.smoke.test.ts +26 -0
  24. package/src/github-enterprise-api.ts +18 -2
  25. package/src/github-enterprise-client.integration.test.ts +0 -41
  26. package/src/github-enterprise-client.ts +0 -25
  27. package/src/github-enterprise-client.unit.test.ts +0 -18
  28. package/src/github-installation-wiring.ts +18 -12
  29. package/src/github-sync-all-repos.unit.test.ts +116 -0
  30. package/src/github-sync-snapshot-refresh.integration.test.ts +168 -0
  31. package/src/github-sync-snapshot-refresh.unit.test.ts +144 -0
  32. package/src/github-sync.ts +103 -137
  33. package/src/github-sync.unit.test.ts +82 -1
  34. package/src/installation-ports.ts +1 -40
  35. package/src/principals-api.integration.test.ts +3 -3
  36. package/src/reconcile-open-work.integration.test.ts +0 -1
  37. package/src/user-notification-prefs.ts +10 -65
  38. package/src/user-notification-prefs.unit.test.ts +9 -0
  39. package/src/user-prefs-rename-migration.integration.test.ts +71 -0
  40. package/src/{user-notification-prefs.integration.test.ts → user-prefs.integration.test.ts} +22 -5
  41. package/src/user-prefs.ts +98 -0
  42. package/src/github-access-preview.integration.test.ts +0 -399
  43. package/src/github-sync-switch.integration.test.ts +0 -297
  44. package/src/github-sync-switch.unit.test.ts +0 -467
@@ -1,14 +1,10 @@
1
1
  /**
2
2
  * admin/src/admin-ui-github-identity-pages.unit.test.ts
3
- * Unit tests for the GHE-2.5 GitHub identity row, preview card and result
4
- * renderers, and for their placement in renderAgentDetailPage.
3
+ * Unit tests for the GHE-2.5 GitHub identity row and install blocks, and for their placement in renderAgentDetailPage.
5
4
  */
6
5
 
7
6
  import { describe, expect, test } from "bun:test";
8
7
  import {
9
- type GithubAccessPreviewView,
10
- renderGithubAccessCard,
11
- renderGithubAccessResult,
12
8
  renderGithubInstallCard,
13
9
  renderGithubOrgsFragment,
14
10
  renderGithubUninstallConfirm,
@@ -82,23 +78,6 @@ function page(
82
78
  );
83
79
  }
84
80
 
85
- const analysis = (
86
- over: Partial<NonNullable<GithubAccessPreviewView["access"]>>,
87
- ) =>
88
- ({
89
- status: "ok",
90
- access: {
91
- username: "octo",
92
- outcome: "ok",
93
- userVerified: true,
94
- orgs: [],
95
- unresolved: 0,
96
- complete: true,
97
- checkedAt: "2026-11-10T00:00:00Z",
98
- ...over,
99
- },
100
- }) as GithubAccessPreviewView;
101
-
102
81
  describe("agent detail — identity card (GHE-2.5)", () => {
103
82
  test("card is retitled Owner & identities", () => {
104
83
  const html = page(true, false);
@@ -123,15 +102,14 @@ describe("agent detail — identity card (GHE-2.5)", () => {
123
102
  expect(html).not.toContain("Preview access");
124
103
  });
125
104
 
126
- test("admin with configured apps sees save, clear and the preview card", () => {
105
+ test("admin with configured apps sees save and clear", () => {
127
106
  const html = page(true, true, "octo");
128
107
  expect(html).toContain("GitHub username");
129
108
  expect(html).toContain('action="/admin/agents/agent-123/github-username"');
130
109
  expect(html).toContain('value="octo"');
131
110
  expect(html).toContain("Save");
132
111
  expect(html).toContain("Clear");
133
- expect(html).toContain('id="github-access-btn"');
134
- expect(html).toContain("Preview access");
112
+ expect(html).not.toContain("Preview access");
135
113
  });
136
114
 
137
115
  test("clear is omitted when no username is bound", () => {
@@ -143,124 +121,6 @@ describe("agent detail — identity card (GHE-2.5)", () => {
143
121
  const row = renderGithubUsernameRow("a", '"><script>x</script>');
144
122
  expect(row).not.toContain("<script>x</script>");
145
123
  });
146
-
147
- test("card renders no key material", () => {
148
- expect(renderGithubAccessCard("a")).not.toMatch(/BEGIN|token|private/i);
149
- });
150
- });
151
-
152
- describe("renderGithubAccessResult", () => {
153
- test("empty org list", () => {
154
- const html = renderGithubAccessResult(analysis({}));
155
- expect(html).toContain("No organizations to check.");
156
- expect(html).not.toContain("Partial results");
157
- });
158
-
159
- test("complete: table grouped by org with push marker and ok badge", () => {
160
- const html = renderGithubAccessResult(
161
- analysis({
162
- orgs: [
163
- {
164
- org: "acme",
165
- status: "ok",
166
- unresolved: 0,
167
- repos: [
168
- { fullName: "acme/api", level: "write", canPush: true },
169
- { fullName: "acme/docs", level: "read", canPush: false },
170
- ],
171
- },
172
- ],
173
- }),
174
- );
175
- expect(html).toContain("acme");
176
- expect(html).toContain("acme/api");
177
- expect(html).toContain("write");
178
- expect(html).toContain("badge-green");
179
- expect(html.match(/title="Can push"/g)?.length).toBe(1);
180
- expect(html).not.toContain("Partial results");
181
- });
182
-
183
- test.each([
184
- ["lookup_app_not_installed", "lookup app not installed"],
185
- ["rate_limited", "rate-limited"],
186
- ["partial", "partial"],
187
- ["error", "error"],
188
- ] as const)("status %s renders a badge and the warning", (status, label) => {
189
- const html = renderGithubAccessResult(
190
- analysis({
191
- complete: false,
192
- unresolved: 3,
193
- orgs: [{ org: "acme", status, repos: [], unresolved: 3 }],
194
- }),
195
- );
196
- expect(html).toContain(`>${label}</span>`);
197
- expect(html).toContain("Partial results");
198
- });
199
-
200
- test("partial org with a reason shows the reason in the banner", () => {
201
- const html = renderGithubAccessResult(
202
- analysis({
203
- complete: false,
204
- orgs: [
205
- {
206
- org: "acme",
207
- status: "partial",
208
- repos: [],
209
- unresolved: 0,
210
- reason: "lookup app installed on selected repositories only <x>",
211
- },
212
- ],
213
- }),
214
- );
215
- expect(html).toContain("Partial results");
216
- expect(html).toContain("selected repositories only &lt;x&gt;");
217
- expect(html).not.toContain("<x>");
218
- });
219
-
220
- test("incomplete with all orgs ok still warns", () => {
221
- const html = renderGithubAccessResult(
222
- analysis({
223
- complete: false,
224
- orgs: [{ org: "a", status: "ok", repos: [], unresolved: 0 }],
225
- }),
226
- );
227
- expect(html).toContain("Partial results");
228
- });
229
-
230
- test("user not found", () => {
231
- const html = renderGithubAccessResult({
232
- status: "user_not_found",
233
- access: {
234
- username: "ghost",
235
- outcome: "user_not_found",
236
- userVerified: true,
237
- orgs: [],
238
- unresolved: 0,
239
- complete: false,
240
- checkedAt: "x",
241
- },
242
- });
243
- expect(html).toContain("was not found");
244
- expect(html).toContain("ghost");
245
- expect(html).not.toContain("<table");
246
- });
247
-
248
- test("escapes org and repo names", () => {
249
- const html = renderGithubAccessResult(
250
- analysis({
251
- orgs: [
252
- {
253
- org: "<b>o</b>",
254
- status: "ok",
255
- unresolved: 0,
256
- repos: [{ fullName: "<i>r</i>", level: "read", canPush: false }],
257
- },
258
- ],
259
- }),
260
- );
261
- expect(html).not.toContain("<b>o</b>");
262
- expect(html).not.toContain("<i>r</i>");
263
- });
264
124
  });
265
125
 
266
126
  describe("Install on org block (GHC-1.2)", () => {
@@ -306,6 +166,38 @@ describe("Install on org block (GHC-1.2)", () => {
306
166
  expect(html).not.toContain('name="agentId"');
307
167
  });
308
168
 
169
+ test("install form defaults to All with a hint when no cached repos", () => {
170
+ const html = renderGithubOrgsFragment("agent-123", orgs());
171
+ expect(html).toContain('value="all" checked');
172
+ expect(html).toContain('value="selected"');
173
+ expect(html).not.toContain('name="repositories"');
174
+ expect(html).toContain("Refresh the GitHub cache");
175
+ });
176
+
177
+ test("install form defaults to Selected with an escaped cached checklist", () => {
178
+ const html = renderGithubOrgsFragment("agent-123", orgs(), {
179
+ acme: ["api", "<i>web</i>"],
180
+ });
181
+ expect(html).toContain('value="selected" checked');
182
+ expect(html).toContain(
183
+ '<input type="checkbox" name="repositories" value="api" checked>',
184
+ );
185
+ expect(html).toContain("&lt;i&gt;web&lt;/i&gt;");
186
+ expect(html).not.toContain("<i>web</i>");
187
+ expect(html).toContain("2 of 50 selected");
188
+ expect(html).toContain(">Install</button>");
189
+ });
190
+
191
+ test("the 50 cap: only 50 pre-checked, JS blocks submit above 50", () => {
192
+ const repos = Array.from({ length: 60 }, (_, i) => `r${i}`);
193
+ const html = renderGithubOrgsFragment("agent-123", orgs(), { acme: repos });
194
+ expect(html.match(/name="repositories"[^>]* checked>/g)?.length).toBe(50);
195
+ expect(html.match(/name="repositories"/g)?.length).toBe(60);
196
+ expect(html).toContain("50 of 50 selected");
197
+ expect(html).toContain("n&gt;50");
198
+ expect(html).toContain("b.disabled=bad");
199
+ });
200
+
309
201
  test("installed org shows Uninstall, not installed keeps Install", () => {
310
202
  const html = renderGithubOrgsFragment("agent-123", orgs());
311
203
  expect(html.match(/>Uninstall<\/button>/g)?.length).toBe(1);
@@ -337,10 +229,22 @@ describe("Install on org block (GHC-1.2)", () => {
337
229
  });
338
230
  expect(html).toContain("acme/&lt;r&gt;");
339
231
  expect(html).toContain("T-1");
340
- expect(html).toContain('action="/admin/agents/agent-123/github-orgs/acme/uninstall"');
232
+ expect(html).toContain(
233
+ 'action="/admin/agents/agent-123/github-orgs/acme/uninstall"',
234
+ );
341
235
  expect(html).not.toContain("confirmRemovals");
342
236
  });
343
237
 
238
+ test("uninstall confirm shows empty states when nothing would be removed or blocked", () => {
239
+ const html = renderGithubUninstallConfirm("a", {
240
+ org: "acme",
241
+ repos: [],
242
+ openWork: [],
243
+ });
244
+ expect(html).toContain("No agent repos would be removed.");
245
+ expect(html).toContain("No open tasks or PRs would be blocked.");
246
+ });
247
+
344
248
  test("uninstall confirm carries confirmRemovals for more than 10 repos", () => {
345
249
  const repos = Array.from({ length: 11 }, (_, i) => `acme/r${i}`);
346
250
  expect(
@@ -389,17 +293,15 @@ describe("GitHub identity surfaces by App state (GFU-2.2)", () => {
389
293
  { timezone: "UTC", ...(appsState ? { githubAppsState: appsState } : {}) },
390
294
  );
391
295
 
392
- test("both: preview, sync button and the install org list", () => {
296
+ test("both: sync button and the install org list", () => {
393
297
  const html = pageState("both");
394
- expect(html).toContain('id="github-access-btn"');
395
298
  expect(html).toContain('id="github-sync-btn"');
396
299
  expect(html).toContain('id="github-install-result"');
397
300
  expect(html).not.toContain('data-reason="lookup-only"');
398
301
  });
399
302
 
400
- test("lookup-only: preview stays, Sync and Install explain the installer need", () => {
303
+ test("lookup-only: Sync and Install explain the installer need", () => {
401
304
  const html = pageState("lookup_only");
402
- expect(html).toContain('id="github-access-btn"');
403
305
  expect(html).toContain('data-reason="lookup-only"');
404
306
  expect(html).not.toContain('id="github-sync-btn"');
405
307
  expect(html).not.toContain('id="github-install-result"');
@@ -409,7 +311,6 @@ describe("GitHub identity surfaces by App state (GFU-2.2)", () => {
409
311
  test("lookup-missing: only the Sync card, saying the lookup App is missing", () => {
410
312
  const html = pageState("lookup_missing");
411
313
  expect(html).toContain('data-reason="lookup-missing"');
412
- expect(html).not.toContain('id="github-access-btn"');
413
314
  expect(html).not.toContain("Install on org");
414
315
  });
415
316
 
@@ -419,30 +320,6 @@ describe("GitHub identity surfaces by App state (GFU-2.2)", () => {
419
320
  expect(page(true, true)).not.toContain('data-reason="lookup-only"');
420
321
  });
421
322
 
422
- test("access preview: unconfigured is the lookup-missing message", () => {
423
- const html = renderGithubAccessResult({ status: "unconfigured" });
424
- expect(html).toContain('data-reason="lookup-missing"');
425
- expect(html).toContain("lookup GitHub App is not configured");
426
- expect(html).not.toContain("installer");
427
- });
428
-
429
- test("access preview: escapes the username and org values", () => {
430
- const html = renderGithubAccessResult({
431
- status: "user_not_found",
432
- access: {
433
- username: "<img src=x>",
434
- outcome: "user_not_found",
435
- userVerified: false,
436
- orgs: [],
437
- unresolved: 0,
438
- complete: true,
439
- checkedAt: "2026-11-10T00:00:00Z",
440
- },
441
- } as GithubAccessPreviewView);
442
- expect(html).not.toContain("<img src=x>");
443
- expect(html).toContain("&lt;img src=x&gt;");
444
- });
445
-
446
323
  test("install card: lookup-only explains; both lazy-loads; id escaped", () => {
447
324
  const only = renderGithubInstallCard('a"><i>', "lookup_only");
448
325
  expect(only).toContain('data-reason="lookup-only"');
@@ -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 and
4
- * access preview on the agent detail page. The GHE-1.3 status and the agents
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 and preview card to an admin when configured", async () => {
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 &amp; identities");
112
119
  expect(html).toContain("GitHub username");
113
- expect(html).toContain('id="github-access-btn"');
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(`${orgsUrl}/acme/uninstall`, opts(admin, "POST"));
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"))).status,
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))).status,
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>${selectionSwitchesHtml(switches)}${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(
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 &lt;e&gt;");
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("lists each selection switch with org and kept repo count in the one confirm", () => {
191
- const html = renderSyncConfirm("a1", {
192
- ...preview,
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&lt;x&gt;");
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
- selectionSwitches: [{ org: "acme", repos: ["acme/a"] }],
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("empty-org");
228
- expect(html).toContain("use Uninstall to remove the agent App");
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", () => {