@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
@@ -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 access preview and the plain installer explanation, no Sync button or installer-backed body", async () => {
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("renders a selection switch row in the Sync confirm fragment", async () => {
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
- selectionSwitches: [{ org: "acme", repos: ["acme/a", "acme/b"] }],
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-list="selection-switches"');
410
- expect(html).toContain('data-switch-org="acme"');
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 () => {
@@ -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 and the Preview access card; absent or
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, access preview and the repo-removal flow need the lookup App;
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
- // Preview access and GitHub sync fragments.
2263
- const githubCardBody = `${githubConnectActionsHtml}${showGithubIdentity ? renderGithubAccessCard(agent.id) : ""}${showGithubCards ? renderGithubSyncCard(agent.id, { hasAppId: "GH_APP_ID" in envVars, githubUsername: agent.githubUsername, ...(appsState === "both" ? {} : { appsState }) }) : ""}${showGithubIdentity ? renderGithubInstallCard(agent.id, appsState) : ""}`;
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
- renderGithubAccessResult,
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 and
540
- * GET /agents/:id/github-access). Optional (additive): absent hides the
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
- return html(
2295
- renderGithubOrgsFragment(agentId, (await res.json()) as GheOrgs),
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({ agentId }),
2354
+ body: JSON.stringify(
2355
+ selected
2356
+ ? { agentId, repositorySelection: "selected", repositories }
2357
+ : { agentId },
2358
+ ),
2344
2359
  },
2345
2360
  );
2346
2361
  if (!res?.ok) {
@@ -24,7 +24,6 @@ import type { AgentTokenService } from "./agent-tokens.ts";
24
24
  import type { AdminDeps } from "./agents-api.ts";
25
25
  import { createAdminApp, parseAdminApiKeys } from "./agents-api.ts";
26
26
  import { PLATFORM_OPS_ROUTES } from "./api-auth.ts";
27
- import { createGithubAccessPreview } from "./github-enterprise-api.ts";
28
27
  import { accessFor, envWith } from "./github-installation.fixtures.ts";
29
28
  import {
30
29
  createGithubInstallationRepos,
@@ -7285,278 +7284,6 @@ describe("admin API — PATCH /agents/:id githubUsername (GHE-2.1)", () => {
7285
7284
  });
7286
7285
  });
7287
7286
 
7288
- // ─── GHE-2.4: GET /agents/:id/github-access ──────────────────────────────────
7289
-
7290
- describe("admin API — GET /agents/:id/github-access (GHE-2.4)", () => {
7291
- const OPS = "gha-ops-token";
7292
- const READER = "gha-read-token";
7293
- const AGENT_KEY = "gha-agent-token";
7294
- const ACCESS = {
7295
- username: "octocat",
7296
- outcome: "ok" as const,
7297
- userVerified: true,
7298
- orgs: [
7299
- {
7300
- org: "acme-eng",
7301
- status: "ok" as const,
7302
- repos: [
7303
- { fullName: "acme-eng/api", level: "write" as const, canPush: true },
7304
- ],
7305
- unresolved: 0,
7306
- },
7307
- ],
7308
- unresolved: 0,
7309
- complete: true,
7310
- checkedAt: "2026-11-09T12:00:00.000Z",
7311
- };
7312
-
7313
- function setup(opts: {
7314
- githubUsername?: string | null;
7315
- preview?: AdminDeps["githubAccessPreview"];
7316
- }) {
7317
- const base = makeMockDeps();
7318
- const calls: string[] = [];
7319
- const deps: AdminDeps = {
7320
- ...base,
7321
- adminApiKeys: parseAdminApiKeys(
7322
- `root:${ADMIN_API_KEY}:*,operator:${OPS}:platform.ops,reader:${READER}:platform.read`,
7323
- ),
7324
- agentTokenService: {
7325
- ...base.agentTokenService,
7326
- validate: async (t: string) =>
7327
- t === AGENT_KEY ? { agentId: AGENT_ID } : null,
7328
- },
7329
- agentService: {
7330
- ...base.agentService,
7331
- getDetail: async (id: string) => {
7332
- const d = await base.agentService.getDetail(id);
7333
- return d ? { ...d, githubUsername: opts.githubUsername ?? null } : d;
7334
- },
7335
- },
7336
- githubAccessPreview:
7337
- opts.preview ??
7338
- (async (u) => {
7339
- calls.push(u);
7340
- return { status: "ok", access: ACCESS };
7341
- }),
7342
- };
7343
- return { app: createAdminApp(deps), calls };
7344
- }
7345
-
7346
- const get = (
7347
- app: ReturnType<typeof createAdminApp>,
7348
- headers: Record<string, string>,
7349
- id = AGENT_ID,
7350
- ) => app.request(`/agents/${id}/github-access`, { headers });
7351
- const asAdmin = { Authorization: `Bearer ${ADMIN_API_KEY}` };
7352
-
7353
- it("platform admin gets the resolver output unchanged", async () => {
7354
- const { app, calls } = setup({ githubUsername: "octocat" });
7355
- const res = await get(app, asAdmin);
7356
- expect(res.status).toBe(200);
7357
- expect(await res.json()).toEqual({ status: "ok", access: ACCESS });
7358
- expect(calls).toEqual(["octocat"]);
7359
- });
7360
-
7361
- it("403 for a session member, ops key, read key and agent key", async () => {
7362
- const { app, calls } = setup({ githubUsername: "octocat" });
7363
- const memberApp = createAdminApp({
7364
- ...makeMockDeps(),
7365
- callerScopeResolver: async () => ({
7366
- kind: "scoped",
7367
- accountId: "acct-a",
7368
- agentIds: [AGENT_ID],
7369
- }),
7370
- });
7371
- const cookie = await sign(
7372
- {
7373
- isAdmin: false,
7374
- userId: "user-acct",
7375
- email: "owner@acct-a.example.com",
7376
- iat: Math.floor(Date.now() / 1000),
7377
- exp: Math.floor(Date.now() / 1000) + 3600,
7378
- },
7379
- SESSION_SECRET,
7380
- "HS256",
7381
- );
7382
- expect(
7383
- (await get(memberApp, { Cookie: `admin_session=${cookie}` })).status,
7384
- ).toBe(403);
7385
- for (const key of [OPS, READER, AGENT_KEY]) {
7386
- const res = await get(app, { Authorization: `Bearer ${key}` });
7387
- expect(res.status).toBe(403);
7388
- }
7389
- expect(calls).toEqual([]);
7390
- });
7391
-
7392
- it("404 for an unknown agent", async () => {
7393
- const { app, calls } = setup({ githubUsername: "octocat" });
7394
- expect((await get(app, asAdmin, "no-such-agent")).status).toBe(404);
7395
- expect(calls).toEqual([]);
7396
- });
7397
-
7398
- it("422 with a clear message when no githubUsername is bound", async () => {
7399
- const { app, calls } = setup({ githubUsername: null });
7400
- const res = await get(app, asAdmin);
7401
- expect(res.status).toBe(422);
7402
- expect(((await res.json()) as { error: string }).error).toContain(
7403
- "githubUsername",
7404
- );
7405
- expect(calls).toEqual([]);
7406
- });
7407
-
7408
- it("unconfigured is a 200 status, not an error", async () => {
7409
- const { app } = setup({
7410
- githubUsername: "octocat",
7411
- preview: async () => ({ status: "unconfigured" }),
7412
- });
7413
- const res = await get(app, asAdmin);
7414
- expect(res.status).toBe(200);
7415
- expect(await res.json()).toEqual({ status: "unconfigured" });
7416
- });
7417
-
7418
- describe("real preview over a fake GitHub (lookup-only and both Apps)", () => {
7419
- const { privateKey: PEM } = generateKeyPairSync("rsa", {
7420
- modulusLength: 2048,
7421
- privateKeyEncoding: { type: "pkcs8", format: "pem" },
7422
- publicKeyEncoding: { type: "spki", format: "pem" },
7423
- });
7424
- type Role = "installer" | "lookup";
7425
- const record = (role: Role) => ({
7426
- role,
7427
- appId: role === "lookup" ? "555" : "12345",
7428
- slug: `example-${role}`,
7429
- enterpriseSlug: role === "installer" ? "acme" : null,
7430
- });
7431
-
7432
- function preview(roles: Role[]) {
7433
- const paths: string[] = [];
7434
- const json = (body: unknown, status = 200) =>
7435
- new Response(JSON.stringify(body), {
7436
- status,
7437
- headers: { "Content-Type": "application/json" },
7438
- });
7439
- const fetchFn = (async (input: RequestInfo | URL, init?: RequestInit) => {
7440
- const path = new URL(input.toString()).pathname;
7441
- paths.push(`${init?.method ?? "GET"} ${path}`);
7442
- if (path === "/app/installations")
7443
- return json([
7444
- { id: 7001, account: { login: "acme-eng", type: "Organization" } },
7445
- ]);
7446
- if (path === "/enterprises/acme/installation")
7447
- return json({
7448
- id: 4242,
7449
- access_tokens_url:
7450
- "https://ghe.test/app/installations/4242/access_tokens",
7451
- });
7452
- if (path === "/app/installations/4242/access_tokens")
7453
- return json({ token: "ghs_i", expires_at: "2099-01-01T00:00:00Z" });
7454
- if (path === "/enterprises/acme/apps/installable_organizations")
7455
- return json([{ id: 1, login: "acme-eng" }]);
7456
- if (path === "/orgs/acme-eng/installation")
7457
- return json({ id: 7001, repository_selection: "all" });
7458
- if (path === "/app/installations/7001/access_tokens")
7459
- return json({ token: "ghs_l", expires_at: "2099-01-01T00:00:00Z" });
7460
- if (path === "/installation/repositories")
7461
- return json({
7462
- total_count: 1,
7463
- repositories: [
7464
- {
7465
- id: 1,
7466
- name: "api",
7467
- full_name: "acme-eng/api",
7468
- private: true,
7469
- archived: false,
7470
- },
7471
- ],
7472
- });
7473
- if (path === "/users/octocat")
7474
- return json({ id: 9, login: "octocat", type: "User" });
7475
- if (path === "/repos/acme-eng/api/collaborators/octocat/permission")
7476
- return json({ permission: "write", role_name: "write" });
7477
- return json({ message: "Not Found" }, 404);
7478
- }) as typeof fetch;
7479
- const appService = {
7480
- get: async (role: Role) => (roles.includes(role) ? record(role) : null),
7481
- getPrivateKey: async (role: Role) =>
7482
- roles.includes(role) ? PEM : null,
7483
- } as unknown as Parameters<
7484
- typeof createGithubAccessPreview
7485
- >[0]["appService"];
7486
- return {
7487
- paths,
7488
- fn: createGithubAccessPreview({
7489
- appService,
7490
- fetchFn,
7491
- apiBase: "https://ghe.test",
7492
- now: () => new Date("2026-11-09T12:00:00Z"),
7493
- }),
7494
- };
7495
- }
7496
-
7497
- const expectedOrgs = [
7498
- {
7499
- org: "acme-eng",
7500
- status: "ok",
7501
- repos: [{ fullName: "acme-eng/api", level: "write", canPush: true }],
7502
- unresolved: 0,
7503
- },
7504
- ];
7505
-
7506
- it("lookup-only: status ok with the repos the lookup App sees", async () => {
7507
- const p = preview(["lookup"]);
7508
- const { app } = setup({ githubUsername: "octocat", preview: p.fn });
7509
- const res = await get(app, asAdmin);
7510
- expect(res.status).toBe(200);
7511
- const body = (await res.json()) as {
7512
- status: string;
7513
- access: { orgs: unknown[]; complete: boolean };
7514
- };
7515
- expect(body.status).toBe("ok");
7516
- expect(body.access.orgs).toEqual(expectedOrgs);
7517
- expect(body.access.complete).toBe(true);
7518
- expect(p.paths).toContain("GET /app/installations");
7519
- expect(p.paths.some((x) => x.includes("/enterprises/"))).toBe(false);
7520
- });
7521
-
7522
- it("both Apps: same result, orgs come from the installer", async () => {
7523
- const p = preview(["installer", "lookup"]);
7524
- const { app } = setup({ githubUsername: "octocat", preview: p.fn });
7525
- const body = (await (await get(app, asAdmin)).json()) as {
7526
- status: string;
7527
- access: { orgs: unknown[] };
7528
- };
7529
- expect(body.status).toBe("ok");
7530
- expect(body.access.orgs).toEqual(expectedOrgs);
7531
- expect(p.paths).toContain(
7532
- "GET /enterprises/acme/apps/installable_organizations",
7533
- );
7534
- expect(p.paths).not.toContain("GET /app/installations");
7535
- });
7536
-
7537
- it("installer-only is unconfigured with no GitHub call", async () => {
7538
- const p = preview(["installer"]);
7539
- const { app } = setup({ githubUsername: "octocat", preview: p.fn });
7540
- const res = await get(app, asAdmin);
7541
- expect(await res.json()).toEqual({ status: "unconfigured" });
7542
- expect(p.paths).toEqual([]);
7543
- });
7544
- });
7545
-
7546
- it("user_not_found is passed through", async () => {
7547
- const access = { ...ACCESS, outcome: "user_not_found" as const, orgs: [] };
7548
- const { app } = setup({
7549
- githubUsername: "ghost",
7550
- preview: async () => ({ status: "user_not_found", access }),
7551
- });
7552
- const res = await get(app, asAdmin);
7553
- expect(res.status).toBe(200);
7554
- expect(((await res.json()) as { status: string }).status).toBe(
7555
- "user_not_found",
7556
- );
7557
- });
7558
- });
7559
-
7560
7287
  // ─── IRM-1.2 / IRM-3.1: installation repos list and GitHub Sync ───────────────
7561
7288
 
7562
7289
  describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, IRM-3.1)", () => {
@@ -8304,7 +8031,7 @@ describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, I
8304
8031
  expect(state.repos).toEqual([]);
8305
8032
  });
8306
8033
 
8307
- // GIS-1.2: an agent App installed on All repositories is switched to Selected.
8034
+ // GIS-1.2: an agent App installed on All repositories is skipped, never switched.
8308
8035
  const allSnapshot = () => [
8309
8036
  {
8310
8037
  org: "acme-eng",
@@ -8316,61 +8043,45 @@ describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, I
8316
8043
  repos: [{ fullName: "acme-eng/repo-1" }, { fullName: "acme-eng/repo-2" }],
8317
8044
  },
8318
8045
  ];
8046
+ const ALL_REPOS_MESSAGE =
8047
+ "Sync does not work when the app has access to all repositories; uninstall the app and install again with selected repositories.";
8319
8048
 
8320
- it("sync preview lists the selection switch for an 'all' installation", async () => {
8321
- const { app, events } = setup({ snapshots: allSnapshot() });
8049
+ it("sync preview reports an 'all' installation as skipped with the reinstall message", async () => {
8050
+ const { app, gh } = setup({ snapshots: allSnapshot() });
8322
8051
  const res = await app.request(previewUrl, { headers: asAdmin });
8323
8052
  expect(res.status).toBe(200);
8324
8053
  const body = (await res.json()) as {
8325
- selectionSwitches: unknown[];
8326
8054
  appRemoves: string[];
8055
+ skippedOrgs: { org: string; reason: string }[];
8056
+ selectionSwitches?: unknown;
8327
8057
  };
8328
- expect(body.selectionSwitches).toEqual([
8329
- { org: "acme-eng", repos: ["acme-eng/repo-1"] },
8058
+ expect(body.skippedOrgs).toEqual([
8059
+ { org: "acme-eng", reason: ALL_REPOS_MESSAGE },
8330
8060
  ]);
8331
- expect(body.appRemoves).toEqual(["acme-eng/repo-2"]);
8332
- // Read-only: only the open-work listing, no GitHub change.
8333
- expect(events.map((e) => e[0])).toEqual(["list"]);
8061
+ expect(body.appRemoves).toEqual([]);
8062
+ expect(body.selectionSwitches).toBeUndefined();
8063
+ expect(gh.filter((c) => c.startsWith("PATCH"))).toEqual([]);
8334
8064
  });
8335
8065
 
8336
- it("sync apply switches before removing, folds the removal and audits once", async () => {
8337
- const { app, audits, events } = setup({ snapshots: allSnapshot() });
8066
+ it("sync apply on an 'all' installation never calls the installation PATCH", async () => {
8067
+ const { app, audits, gh } = setup({ snapshots: allSnapshot() });
8338
8068
  const res = await apply(app, {
8339
8069
  appRemoves: ["acme-eng/repo-2"],
8340
- agentRemoves: ["acme-eng/repo-2"],
8070
+ appAdds: ["acme-eng/repo-3"],
8341
8071
  });
8342
8072
  expect(res.status).toBe(200);
8343
- expect(await res.json()).toMatchObject({
8344
- status: "applied",
8345
- appRemoves: ["acme-eng/repo-2"],
8346
- selectionSwitches: [{ org: "acme-eng", repos: ["acme-eng/repo-1"] }],
8347
- });
8348
- expect(events.map((e) => e[0])).toEqual([
8349
- "switch",
8350
- "setRepos",
8351
- "audit",
8352
- "block",
8073
+ const body = (await res.json()) as {
8074
+ status: string;
8075
+ skippedOrgs: { org: string; reason: string }[];
8076
+ selectionSwitches?: unknown;
8077
+ };
8078
+ expect(body.status).toBe("noop");
8079
+ expect(body.skippedOrgs).toEqual([
8080
+ { org: "acme-eng", reason: ALL_REPOS_MESSAGE },
8353
8081
  ]);
8354
- expect(events[0]).toEqual(["switch", ["repo-1"]]);
8355
- expect(audits[0]?.diff).toMatchObject({
8356
- installationRemoves: ["acme-eng/repo-2"],
8357
- selectionSwitches: [{ org: "acme-eng", repos: ["acme-eng/repo-1"] }],
8358
- });
8359
- });
8360
-
8361
- it("sync apply: a 403 on the switch is a 502 naming the missing permission, with a failed audit", async () => {
8362
- const { app, audits } = setup({
8363
- snapshots: allSnapshot(),
8364
- override: { [`PATCH ${INST}/501/repositories`]: "install_selection_403" },
8365
- });
8366
- const res = await apply(app, { appRemoves: ["acme-eng/repo-2"] });
8367
- expect(res.status).toBe(502);
8368
- expect(JSON.stringify(await res.json())).toContain(
8369
- "enterprise_organization_installation_repositories",
8370
- );
8371
- expect(audits).toHaveLength(1);
8372
- expect(audits[0]).toMatchObject({ result: { status: "failed" } });
8373
- expect(audits[0]?.diff).toMatchObject({ installationRemoves: [] });
8082
+ expect(body.selectionSwitches).toBeUndefined();
8083
+ expect(gh.filter((c) => c.startsWith("PATCH"))).toEqual([]);
8084
+ expect(audits).toEqual([]);
8374
8085
  });
8375
8086
 
8376
8087
  it("sync apply: noop when nothing confirmed still applies; 400 for bad names", async () => {