@app-vitals/agent-admin 1.86.0 → 1.87.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/Dockerfile CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Build from the repository root: docker build -f admin/Dockerfile .
4
4
 
5
- FROM oven/bun:1.4.4-slim@sha256:1846adf22496bd711036aae8be147e57bdebbaea2e5264e3e0b5af1db187d9a4 AS deps
5
+ FROM oven/bun:1.4.5-slim@sha256:b780593f3e10918cbdaec3d5a08d52224b9198069a65eb47812085c2ec007643 AS deps
6
6
 
7
7
  WORKDIR /app
8
8
 
@@ -23,7 +23,7 @@ RUN if [ -f bun.lock ]; then bun install --frozen-lockfile --production; else bu
23
23
  && rm -rf node_modules/.bun/typescript@* node_modules/.bun/@typescript+* \
24
24
  node_modules/.bun/node_modules/typescript node_modules/.bun/node_modules/@typescript
25
25
 
26
- FROM oven/bun:1.4.4-slim@sha256:1846adf22496bd711036aae8be147e57bdebbaea2e5264e3e0b5af1db187d9a4 AS production
26
+ FROM oven/bun:1.4.5-slim@sha256:b780593f3e10918cbdaec3d5a08d52224b9198069a65eb47812085c2ec007643 AS production
27
27
 
28
28
  # Upgrade apt/libapt-pkg7.0 past the base image's 3.0.3 (Trivy HIGH CVE-2026-109518, fixed in 3.0.4).
29
29
  RUN apt-get update \
package/openapi.json CHANGED
@@ -2804,7 +2804,7 @@
2804
2804
  "user_not_found",
2805
2805
  "unconfigured"
2806
2806
  ],
2807
- "description": "`unconfigured` when the installer or lookup App is not set (no GitHub call was made)."
2807
+ "description": "`unconfigured` when the lookup App or its key is not set (no GitHub call was made). The installer App is optional."
2808
2808
  },
2809
2809
  "access": {
2810
2810
  "type": "object",
@@ -6356,7 +6356,7 @@
6356
6356
  "/agents/{id}/github-access": {
6357
6357
  "get": {
6358
6358
  "summary": "Preview the repos the agent's bound GitHub user can reach",
6359
- "description": "Platform-admin only (session members, ops keys and agent keys get 403): the response lists repo names the bound user can reach. Read-only; nothing is stored. 404 for an unknown agent; 422 when no githubUsername is bound. Returns `status: unconfigured` (not an error, no GitHub call) when the enterprise Apps are not configured, and `status: user_not_found` when the user does not exist on GitHub; otherwise `access` is the resolver output (per-org status, repos with level and canPush, unresolved count, complete flag).",
6359
+ "description": "Platform-admin only (session members, ops keys and agent keys get 403): the response lists repo names the bound user can reach. Read-only; nothing is stored. 404 for an unknown agent; 422 when no githubUsername is bound. Returns `status: unconfigured` (not an error, no GitHub call) when the lookup App is not configured (the installer App is optional), and `status: user_not_found` when the user does not exist on GitHub; otherwise `access` is the resolver output (per-org status, repos with level and canPush, unresolved count, complete flag).",
6360
6360
  "parameters": [
6361
6361
  {
6362
6362
  "schema": {
@@ -3418,7 +3418,7 @@
3418
3418
  "user_not_found",
3419
3419
  "unconfigured"
3420
3420
  ],
3421
- "description": "`unconfigured` when the installer or lookup App is not set (no GitHub call was made)."
3421
+ "description": "`unconfigured` when the lookup App or its key is not set (no GitHub call was made). The installer App is optional."
3422
3422
  },
3423
3423
  "access": {
3424
3424
  "type": "object",
@@ -3528,6 +3528,18 @@
3528
3528
  "appId": {
3529
3529
  "type": "integer"
3530
3530
  },
3531
+ "appsState": {
3532
+ "type": "string",
3533
+ "enum": [
3534
+ "lookup_only",
3535
+ "lookup_missing"
3536
+ ],
3537
+ "description": "Present only when an App role is missing: `lookup_only` (the enterprise installer App is not configured: repo access is visible but Sync and the agent App's installation repos are unavailable) or `lookup_missing` (the lookup App is not configured). `reason` carries the matching text."
3538
+ },
3539
+ "reason": {
3540
+ "type": "string",
3541
+ "description": "Set with `appsState`: why the installation repos cannot be changed here. The listing is the cached lookup crawl."
3542
+ },
3531
3543
  "complete": {
3532
3544
  "type": "boolean",
3533
3545
  "description": "Whether the cached crawl is complete. While false the list may be partial."
@@ -3671,6 +3683,14 @@
3671
3683
  "reason": {
3672
3684
  "type": "string"
3673
3685
  },
3686
+ "appsState": {
3687
+ "type": "string",
3688
+ "enum": [
3689
+ "lookup_only",
3690
+ "lookup_missing"
3691
+ ],
3692
+ "description": "Present only when an App role is missing: `lookup_only` (the enterprise installer App is not configured: repo access is visible but Sync and the agent App's installation repos are unavailable) or `lookup_missing` (the lookup App is not configured). `reason` carries the matching text."
3693
+ },
3674
3694
  "appAdds": {
3675
3695
  "type": "array",
3676
3696
  "items": {
@@ -3826,6 +3846,14 @@
3826
3846
  "reason": {
3827
3847
  "type": "string"
3828
3848
  },
3849
+ "appsState": {
3850
+ "type": "string",
3851
+ "enum": [
3852
+ "lookup_only",
3853
+ "lookup_missing"
3854
+ ],
3855
+ "description": "Present only when an App role is missing: `lookup_only` (the enterprise installer App is not configured: repo access is visible but Sync and the agent App's installation repos are unavailable) or `lookup_missing` (the lookup App is not configured). `reason` carries the matching text."
3856
+ },
3829
3857
  "auditId": {
3830
3858
  "type": "string"
3831
3859
  },
@@ -7961,7 +7989,7 @@
7961
7989
  "/agents/{id}/github-access": {
7962
7990
  "get": {
7963
7991
  "summary": "Preview the repos the agent's bound GitHub user can reach",
7964
- "description": "Platform-admin only (session members, ops keys and agent keys get 403): the response lists repo names the bound user can reach. Read-only; nothing is stored. 404 for an unknown agent; 422 when no githubUsername is bound. Returns `status: unconfigured` (not an error, no GitHub call) when the enterprise Apps are not configured, and `status: user_not_found` when the user does not exist on GitHub; otherwise `access` is the resolver output (per-org status, repos with level and canPush, unresolved count, complete flag).",
7992
+ "description": "Platform-admin only (session members, ops keys and agent keys get 403): the response lists repo names the bound user can reach. Read-only; nothing is stored. 404 for an unknown agent; 422 when no githubUsername is bound. Returns `status: unconfigured` (not an error, no GitHub call) when the lookup App is not configured (the installer App is optional), and `status: user_not_found` when the user does not exist on GitHub; otherwise `access` is the resolver output (per-org status, repos with level and canPush, unresolved count, complete flag).",
7965
7993
  "parameters": [
7966
7994
  {
7967
7995
  "schema": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-admin",
3
- "version": "1.86.0",
3
+ "version": "1.87.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@anthropic-ai/sdk": "0.137.0",
47
- "@app-vitals/agent-lib": "1.86.0",
47
+ "@app-vitals/agent-lib": "1.87.0",
48
48
  "@hono/zod-openapi": "^1.0.0",
49
49
  "@prisma/adapter-pg": "^7.10.0",
50
50
  "@prisma/client": "^7.10.0",
@@ -7,6 +7,11 @@
7
7
  * repo names and levels only (no token or key ever reaches this module).
8
8
  */
9
9
 
10
+ import {
11
+ type GithubAppsState,
12
+ LOOKUP_MISSING_REASON,
13
+ LOOKUP_ONLY_REASON,
14
+ } from "./github-apps-state.ts";
10
15
  import type { GheOrgs } from "./admin-ui-github-enterprise-pages.ts";
11
16
  import { escapeHtml } from "./admin-ui-styles.ts";
12
17
 
@@ -117,7 +122,7 @@ export function renderGithubAccessResult(
117
122
  preview: GithubAccessPreviewView,
118
123
  ): string {
119
124
  if (preview.status === "unconfigured") {
120
- return `<div class="alert alert-warning">The enterprise GitHub apps are not configured.</div>`;
125
+ return `<div class="alert alert-warning" data-reason="lookup-missing">${escapeHtml(LOOKUP_MISSING_REASON)}</div>`;
121
126
  }
122
127
  const access = preview.access;
123
128
  if (
@@ -169,8 +174,21 @@ export function renderGithubAccessError(message: string): string {
169
174
  return `<div class="alert alert-error">${escapeHtml(message)}</div>`;
170
175
  }
171
176
 
172
- /** "Install on org" block (GHC-1.2); lazy-loads the org list fragment on page load. */
173
- export function renderGithubInstallCard(agentId: string): string {
177
+ /**
178
+ * "Install on org" block (GHC-1.2); lazy-loads the org list fragment on page
179
+ * load. In lookup-only it explains that installing needs an installer App
180
+ * instead of loading the (installer-backed) org list.
181
+ */
182
+ export function renderGithubInstallCard(
183
+ agentId: string,
184
+ appsState: GithubAppsState = "both",
185
+ ): string {
186
+ if (appsState === "lookup_only") {
187
+ return `<div id="github-install-card" style="margin-top:20px">
188
+ <div class="form-label" style="font-weight:600;margin-bottom:6px">Install on org</div>
189
+ <div class="alert alert-warning" data-reason="lookup-only">${escapeHtml(LOOKUP_ONLY_REASON)}</div>
190
+ </div>`;
191
+ }
174
192
  const url = `/admin/agents/${escapeHtml(agentId)}/github-orgs`;
175
193
  return `<div id="github-install-card" style="margin-top:20px">
176
194
  <div class="form-label" style="font-weight:600;margin-bottom:6px">Install on org</div>
@@ -202,7 +220,7 @@ export function renderGithubOrgsFragment(
202
220
  data: GheOrgs,
203
221
  ): string {
204
222
  if (!data.configured) {
205
- return `<div class="alert alert-warning">The installer GitHub App is not configured.</div>`;
223
+ return `<div class="alert alert-warning" data-reason="installer-unconfigured">The installer GitHub App is not configured. Installing the agent App on an organization needs an enterprise installer App (GitHub Enterprise Cloud).</div>`;
206
224
  }
207
225
  const reason = data.agentAppReason
208
226
  ? `<div class="alert alert-error">${escapeHtml(data.agentAppReason)}</div>`
@@ -330,3 +330,90 @@ describe("Install on org block (GHC-1.2)", () => {
330
330
  );
331
331
  });
332
332
  });
333
+
334
+ describe("GitHub identity surfaces by App state (GFU-2.2)", () => {
335
+ const pageState = (appsState?: "both" | "lookup_only" | "lookup_missing") =>
336
+ renderAgentDetailPage(
337
+ { ...AGENT, githubUsername: "octo" },
338
+ { GH_APP_ID: "1" },
339
+ [],
340
+ [],
341
+ [],
342
+ [],
343
+ [],
344
+ "u@x.com",
345
+ true,
346
+ { timezone: "UTC", ...(appsState ? { githubAppsState: appsState } : {}) },
347
+ );
348
+
349
+ test("both: preview, sync button and the install org list", () => {
350
+ const html = pageState("both");
351
+ expect(html).toContain('id="github-access-btn"');
352
+ expect(html).toContain('id="github-sync-btn"');
353
+ expect(html).toContain('id="github-install-result"');
354
+ expect(html).not.toContain('data-reason="lookup-only"');
355
+ });
356
+
357
+ test("lookup-only: preview stays, Sync and Install explain the installer need", () => {
358
+ const html = pageState("lookup_only");
359
+ expect(html).toContain('id="github-access-btn"');
360
+ expect(html).toContain('data-reason="lookup-only"');
361
+ expect(html).not.toContain('id="github-sync-btn"');
362
+ expect(html).not.toContain('id="github-install-result"');
363
+ expect(html).toContain("Install on org");
364
+ });
365
+
366
+ test("lookup-missing: only the Sync card, saying the lookup App is missing", () => {
367
+ const html = pageState("lookup_missing");
368
+ expect(html).toContain('data-reason="lookup-missing"');
369
+ expect(html).not.toContain('id="github-access-btn"');
370
+ expect(html).not.toContain("Install on org");
371
+ });
372
+
373
+ test("no state: hidden; legacy githubEnterpriseConfigured: true means both", () => {
374
+ expect(pageState()).not.toContain('id="github-installation-card"');
375
+ expect(page(true, true)).toContain('id="github-installation-card"');
376
+ expect(page(true, true)).not.toContain('data-reason="lookup-only"');
377
+ });
378
+
379
+ test("access preview: unconfigured is the lookup-missing message", () => {
380
+ const html = renderGithubAccessResult({ status: "unconfigured" });
381
+ expect(html).toContain('data-reason="lookup-missing"');
382
+ expect(html).toContain("lookup GitHub App is not configured");
383
+ expect(html).not.toContain("installer");
384
+ });
385
+
386
+ test("access preview: escapes the username and org values", () => {
387
+ const html = renderGithubAccessResult({
388
+ status: "user_not_found",
389
+ access: {
390
+ username: "<img src=x>",
391
+ outcome: "user_not_found",
392
+ userVerified: false,
393
+ orgs: [],
394
+ unresolved: 0,
395
+ complete: true,
396
+ checkedAt: "2026-11-10T00:00:00Z",
397
+ },
398
+ } as GithubAccessPreviewView);
399
+ expect(html).not.toContain("<img src=x>");
400
+ expect(html).toContain("&lt;img src=x&gt;");
401
+ });
402
+
403
+ test("install card: lookup-only explains; both lazy-loads; id escaped", () => {
404
+ const only = renderGithubInstallCard('a"><i>', "lookup_only");
405
+ expect(only).toContain('data-reason="lookup-only"');
406
+ expect(only).not.toContain("github-install-result");
407
+ expect(only).not.toContain("<i>");
408
+ expect(renderGithubInstallCard("a", "both")).toBe(
409
+ renderGithubInstallCard("a"),
410
+ );
411
+ });
412
+
413
+ test("orgs fragment: installer-unconfigured names the installer and its enterprise need", () => {
414
+ const html = renderGithubOrgsFragment("a", { configured: false, orgs: [] });
415
+ expect(html).toContain("The installer GitHub App is not configured.");
416
+ expect(html).toContain("enterprise installer App");
417
+ expect(html).not.toContain("lookup");
418
+ });
419
+ });
@@ -13,6 +13,11 @@
13
13
 
14
14
  import type { components } from "@app-vitals/agent-lib/admin-types";
15
15
  import { escapeHtml } from "./admin-ui-styles.ts";
16
+ import {
17
+ type GithubAppsState,
18
+ LOOKUP_MISSING_REASON,
19
+ LOOKUP_ONLY_REASON,
20
+ } from "./github-apps-state.ts";
16
21
  import {
17
22
  MAX_UNCONFIRMED_REMOVALS,
18
23
  MISSING_APP_ID_REASON,
@@ -199,6 +204,7 @@ export const APP_ID_MISMATCH_MESSAGE =
199
204
  export interface GithubSyncPreviewView {
200
205
  status: "previewed" | "skipped";
201
206
  reason?: string;
207
+ appsState?: "lookup_only" | "lookup_missing";
202
208
  appAdds?: string[];
203
209
  appRemoves?: string[];
204
210
  agentRemoves?: string[];
@@ -211,6 +217,7 @@ export interface GithubSyncPreviewView {
211
217
  export interface GithubSyncApplyView {
212
218
  status: "applied" | "noop" | "skipped";
213
219
  reason?: string;
220
+ appsState?: "lookup_only" | "lookup_missing";
214
221
  appAdds?: string[];
215
222
  appRemoves?: string[];
216
223
  agentRemoves?: string[];
@@ -223,6 +230,12 @@ export interface GithubSyncCardState {
223
230
  /** The agent has a GH_APP_ID in its env. */
224
231
  hasAppId: boolean;
225
232
  githubUsername?: string | null;
233
+ /**
234
+ * Which enterprise Apps are configured. Default "both" (today's card).
235
+ * "lookup_only" explains that Sync needs an installer App; "lookup_missing"
236
+ * says the lookup App is missing. Neither loads installer-backed data.
237
+ */
238
+ appsState?: GithubAppsState;
226
239
  }
227
240
 
228
241
  /**
@@ -236,18 +249,27 @@ export function renderGithubSyncCard(
236
249
  ): string {
237
250
  const id = escapeHtml(agentId);
238
251
  const base = `/admin/agents/${id}/github-installation`;
252
+ const appsState = state.appsState ?? "both";
239
253
  let action: string;
240
- if (!state.hasAppId) {
254
+ if (appsState === "lookup_only") {
255
+ action = `<div class="alert alert-warning" data-reason="lookup-only">${escapeHtml(LOOKUP_ONLY_REASON)}</div>`;
256
+ } else if (appsState === "lookup_missing") {
257
+ action = `<div class="alert alert-warning" data-reason="lookup-missing">${escapeHtml(LOOKUP_MISSING_REASON)}</div>`;
258
+ } else if (!state.hasAppId) {
241
259
  action = `<div class="alert alert-warning" data-reason="missing-app-id">${escapeHtml(MISSING_APP_ID_REASON)}</div>`;
242
260
  } else if (!state.githubUsername?.trim()) {
243
261
  action = `<div class="alert alert-warning" data-reason="no-username">${escapeHtml(NO_USERNAME_REASON)}</div>`;
244
262
  } else {
245
263
  action = `<button type="button" class="btn btn-primary" id="github-sync-btn" data-url="/admin/agents/${id}/github-sync/confirm">Sync</button><div id="github-sync-confirm" style="margin-top:12px"></div>`;
246
264
  }
247
- const loader = state.hasAppId
248
- ? `<div id="github-installation-body">Loading...</div>`
249
- : "";
250
- const refresh = `<div style="margin:0 0 12px"><button type="button" class="btn btn-secondary" id="github-refresh-btn" data-url="/admin/agents/${id}/github-cache/refresh">Refresh</button> <span style="color:#6b7280;font-size:12px">Re-reads the cached repo lists in the background. Reload the page to see progress.</span></div>`;
265
+ const loader =
266
+ state.hasAppId && appsState === "both"
267
+ ? `<div id="github-installation-body">Loading...</div>`
268
+ : "";
269
+ const refresh =
270
+ appsState === "lookup_missing"
271
+ ? ""
272
+ : `<div style="margin:0 0 12px"><button type="button" class="btn btn-secondary" id="github-refresh-btn" data-url="/admin/agents/${id}/github-cache/refresh">Refresh</button> <span style="color:#6b7280;font-size:12px">Re-reads the cached repo lists in the background. Reload the page to see progress.</span></div>`;
251
273
  return `<div id="github-installation-card" data-base-url="${base}" style="margin-top:20px">
252
274
  <div class="form-label" style="font-weight:600;margin-bottom:6px">GitHub sync</div>
253
275
  <p style="color:#6b7280;font-size:12px;margin:0 0 12px">Brings this agent's App installation and its repos in line with what the bound GitHub user can push to.</p>
@@ -517,7 +539,7 @@ export function renderSyncConfirm(
517
539
  timezone?: string,
518
540
  ): string {
519
541
  if (preview.status === "skipped") {
520
- return `<div class="alert alert-warning" data-sync="skipped">Sync was skipped: ${escapeHtml(preview.reason ?? "unknown reason")}</div>`;
542
+ return `<div class="alert alert-warning" data-sync="skipped"${preview.appsState ? ` data-apps-state="${escapeHtml(preview.appsState)}"` : ""}>Sync was skipped: ${escapeHtml(preview.reason ?? "unknown reason")}</div>`;
521
543
  }
522
544
  const appAdds = preview.appAdds ?? [];
523
545
  const appRemoves = preview.appRemoves ?? [];
@@ -556,7 +578,7 @@ export function renderSyncResult(
556
578
  timezone?: string,
557
579
  ): string {
558
580
  if (result.status === "skipped") {
559
- return `<div class="alert alert-warning" data-sync="skipped">Sync was skipped: ${escapeHtml(result.reason ?? "unknown reason")}</div>`;
581
+ return `<div class="alert alert-warning" data-sync="skipped"${result.appsState ? ` data-apps-state="${escapeHtml(result.appsState)}"` : ""}>Sync was skipped: ${escapeHtml(result.reason ?? "unknown reason")}</div>`;
560
582
  }
561
583
  if (result.status === "noop") {
562
584
  const skippedList = result.skippedOrgs ?? [];
@@ -17,6 +17,10 @@ import {
17
17
  renderSyncResult,
18
18
  uncoveredRepos,
19
19
  } from "./admin-ui-installation-repos-pages.ts";
20
+ import {
21
+ LOOKUP_MISSING_REASON,
22
+ LOOKUP_ONLY_REASON,
23
+ } from "./github-apps-state.ts";
20
24
  import { MISSING_APP_ID_REASON } from "./installation-ports.ts";
21
25
 
22
26
  describe("uncoveredRepos", () => {
@@ -570,3 +574,82 @@ describe("installation sync timestamps in the admin timezone", () => {
570
574
  expect(html).toContain("Oldest check Jul 1, 12:00 PM PDT");
571
575
  });
572
576
  });
577
+
578
+ describe("renderGithubSyncCard: App states (GFU-2.2)", () => {
579
+ const base = { hasAppId: true, githubUsername: "octo" };
580
+
581
+ it("both (explicit or default) renders identically", () => {
582
+ expect(renderGithubSyncCard("a1", { ...base, appsState: "both" })).toBe(
583
+ renderGithubSyncCard("a1", base),
584
+ );
585
+ });
586
+
587
+ it("lookup-only explains that Sync needs an installer; no button, body or form", () => {
588
+ const html = renderGithubSyncCard("a1", {
589
+ ...base,
590
+ appsState: "lookup_only",
591
+ });
592
+ expect(html).toContain('data-reason="lookup-only"');
593
+ expect(html).toContain("&#39;");
594
+ expect(html).toContain(LOOKUP_ONLY_REASON.replace(/'/g, "&#39;"));
595
+ expect(html).not.toContain('id="github-sync-btn"');
596
+ expect(html).not.toContain('id="github-installation-body"');
597
+ expect(html).toContain('id="github-refresh-btn"');
598
+ });
599
+
600
+ it("lookup-only wins over a missing App id or username", () => {
601
+ const html = renderGithubSyncCard("a1", {
602
+ hasAppId: false,
603
+ githubUsername: null,
604
+ appsState: "lookup_only",
605
+ });
606
+ expect(html).toContain('data-reason="lookup-only"');
607
+ expect(html).not.toContain('data-reason="missing-app-id"');
608
+ expect(html).not.toContain('data-reason="no-username"');
609
+ });
610
+
611
+ it("lookup-missing says the lookup App is missing, never the installer", () => {
612
+ const html = renderGithubSyncCard("a1", {
613
+ ...base,
614
+ appsState: "lookup_missing",
615
+ });
616
+ expect(html).toContain('data-reason="lookup-missing"');
617
+ expect(html).toContain(LOOKUP_MISSING_REASON);
618
+ expect(html).not.toContain("installer");
619
+ expect(html).not.toContain('id="github-sync-btn"');
620
+ expect(html).not.toContain('id="github-refresh-btn"');
621
+ });
622
+
623
+ it("escapes the agent id in every state", () => {
624
+ for (const appsState of [
625
+ "both",
626
+ "lookup_only",
627
+ "lookup_missing",
628
+ ] as const) {
629
+ const html = renderGithubSyncCard('"><img src=x>', {
630
+ ...base,
631
+ appsState,
632
+ });
633
+ expect(html).not.toContain("<img src=x>");
634
+ }
635
+ });
636
+
637
+ it("sync skipped fragments carry an escaped apps-state marker and reason", () => {
638
+ const skipped = {
639
+ status: "skipped" as const,
640
+ appsState: "lookup_only" as const,
641
+ reason: "<b>no installer</b>",
642
+ };
643
+ for (const html of [
644
+ renderSyncConfirm("a1", skipped),
645
+ renderSyncResult(skipped, []),
646
+ ]) {
647
+ expect(html).toContain('data-apps-state="lookup_only"');
648
+ expect(html).toContain("&lt;b&gt;no installer&lt;/b&gt;");
649
+ expect(html).not.toContain("<b>no installer</b>");
650
+ }
651
+ expect(
652
+ renderSyncResult({ status: "skipped", reason: "r" }, []),
653
+ ).not.toContain("data-apps-state");
654
+ });
655
+ });
@@ -126,28 +126,65 @@ describe("admin UI — GitHub sync card (IRM-3.2)", () => {
126
126
  expect(cardHtml).not.toContain("<input");
127
127
  });
128
128
 
129
- it("is absent when only the installer App is configured", async () => {
130
- const { app } = setup({
129
+ it("lookup-only: shows the access preview and the plain installer explanation, no Sync button or installer-backed body", async () => {
130
+ const { app, calls } = setup({
131
131
  enterprise: {
132
132
  configured: true,
133
- installer: { role: "installer" },
134
- lookup: null,
133
+ installer: null,
134
+ lookup: { role: "lookup" },
135
135
  },
136
136
  });
137
137
  const html = await (await get(app, "/access")).text();
138
- expect(html).not.toContain("github-installation-card");
138
+ expect(html).toContain('id="github-access-btn"');
139
+ const card = html.slice(html.indexOf('id="github-installation-card"'));
140
+ const cardHtml = card.slice(0, card.indexOf("</script>"));
141
+ expect(cardHtml).toContain('data-reason="lookup-only"');
142
+ expect(cardHtml).toContain(
143
+ "Sync and the agent App&#39;s installation repos need an enterprise installer App",
144
+ );
145
+ expect(cardHtml).not.toContain('id="github-sync-btn"');
146
+ expect(cardHtml).not.toContain('id="github-installation-body"');
147
+ expect(html).toContain('id="github-install-card"');
148
+ expect(html).toContain('data-reason="lookup-only"');
149
+ expect(html).not.toContain(
150
+ "is not configured, so repo access cannot be checked",
151
+ );
152
+ // No installer-backed list was requested for the page render.
153
+ expect(
154
+ calls.some((c) => c.path.includes("/github-installation/repos")),
155
+ ).toBe(false);
156
+ });
157
+
158
+ it("both Apps: renders as before, with no lookup-only or lookup-missing text", async () => {
159
+ const { app } = setup({ agentsApi: () => json(INSTALLED) });
160
+ const html = await (await get(app, "/access")).text();
161
+ expect(html).toContain('id="github-access-btn"');
162
+ expect(html).toContain('id="github-sync-btn"');
163
+ expect(html).toContain('id="github-installation-body"');
164
+ expect(html).toContain(
165
+ 'data-url="/admin/agents/' + AGENT_ID + '/github-orgs"',
166
+ );
167
+ expect(html).not.toContain('data-reason="lookup-only"');
168
+ expect(html).not.toContain('data-reason="lookup-missing"');
139
169
  });
140
170
 
141
- it("is absent when only the lookup App is configured", async () => {
171
+ it("lookup App missing (installer only): the Sync card says the lookup App is missing", async () => {
142
172
  const { app } = setup({
143
173
  enterprise: {
144
174
  configured: true,
145
- installer: null,
146
- lookup: { role: "lookup" },
175
+ installer: { role: "installer" },
176
+ lookup: null,
147
177
  },
148
178
  });
149
179
  const html = await (await get(app, "/access")).text();
150
- expect(html).not.toContain("github-installation-card");
180
+ const card = html.slice(html.indexOf('id="github-installation-card"'));
181
+ const cardHtml = card.slice(0, card.indexOf("</script>"));
182
+ expect(cardHtml).toContain('data-reason="lookup-missing"');
183
+ expect(cardHtml).toContain("The lookup GitHub App is not configured");
184
+ expect(cardHtml).not.toContain("installer");
185
+ expect(cardHtml).not.toContain('id="github-sync-btn"');
186
+ expect(html).not.toContain('id="github-access-btn"');
187
+ expect(html).not.toContain('data-reason="lookup-only"');
151
188
  });
152
189
 
153
190
  it("is absent when no App is configured", async () => {
@@ -227,6 +264,37 @@ describe("admin UI — GitHub sync card (IRM-3.2)", () => {
227
264
  expect(html).not.toContain('data-reason="no-username"');
228
265
  });
229
266
 
267
+ it("renders the lookup-only skip reason from the agents API in the sync confirm fragment", async () => {
268
+ const { app } = setup({
269
+ agentsApi: () =>
270
+ json({
271
+ status: "skipped",
272
+ appsState: "lookup_only",
273
+ reason:
274
+ "Only the lookup GitHub App is configured, so repo access is visible",
275
+ }),
276
+ });
277
+ const html = await (await get(app, "/github-sync/confirm")).text();
278
+ expect(html).toContain('data-apps-state="lookup_only"');
279
+ expect(html).toContain("Only the lookup GitHub App is configured");
280
+ });
281
+
282
+ it("renders the lookup-missing skip reason distinctly", async () => {
283
+ const { app } = setup({
284
+ agentsApi: () =>
285
+ json({
286
+ status: "skipped",
287
+ appsState: "lookup_missing",
288
+ reason:
289
+ "The lookup GitHub App is not configured, so repo access cannot be checked.",
290
+ }),
291
+ });
292
+ const html = await (await get(app, "/github-sync/confirm")).text();
293
+ expect(html).toContain('data-apps-state="lookup_missing"');
294
+ expect(html).toContain("The lookup GitHub App is not configured");
295
+ expect(html).not.toContain("Only the lookup");
296
+ });
297
+
230
298
  it("is forbidden for a non-admin and makes no call", async () => {
231
299
  const { app, calls } = setup({});
232
300
  const res = await get(app, "/github-installation", member);
@@ -10,6 +10,7 @@
10
10
  * coding/ (AEP-3.2) and are mounted by the coding AdminExtension.
11
11
  */
12
12
 
13
+ import type { GithubAppsState } from "./github-apps-state.ts";
13
14
  import { PROGRESS_LABELS } from "@app-vitals/agent-lib/progress-phases";
14
15
  import { getSelfServeSpecialty } from "./account-agent-create.ts";
15
16
  import {
@@ -1149,6 +1150,12 @@ export function renderAgentDetailPage(
1149
1150
  * false renders the card without them.
1150
1151
  */
1151
1152
  githubEnterpriseConfigured?: boolean;
1153
+ /**
1154
+ * Which enterprise GitHub Apps are configured (GFU-2.2). Supersedes
1155
+ * githubEnterpriseConfigured (true = "both") when set; absent = neither
1156
+ * App configured, so no GitHub identity cards.
1157
+ */
1158
+ githubAppsState?: GithubAppsState;
1152
1159
  /**
1153
1160
  * SCT-4.1: a stored Slack config token resolves for this agent's account
1154
1161
  * (its own row, else the deployment default). The xoxpToken fields become
@@ -1704,8 +1711,14 @@ export function renderAgentDetailPage(
1704
1711
  </div>`
1705
1712
  : "";
1706
1713
 
1714
+ const appsState: GithubAppsState | undefined =
1715
+ opts?.githubAppsState ??
1716
+ (opts?.githubEnterpriseConfigured === true ? "both" : undefined);
1717
+ // Username, access preview and the repo-removal flow need the lookup App;
1718
+ // the Sync/Install cards also show for a missing lookup App, to say so.
1707
1719
  const showGithubIdentity =
1708
- isAdmin && opts?.githubEnterpriseConfigured === true;
1720
+ isAdmin && (appsState === "both" || appsState === "lookup_only");
1721
+ const showGithubCards = isAdmin && appsState !== undefined;
1709
1722
  // IRM-1.7: removing a repo first shows the open work it would block.
1710
1723
  const repoRemovalScript = `<div id="repo-removal-confirm" style="margin-top:12px"></div>
1711
1724
  <script>
@@ -2113,7 +2126,7 @@ export function renderAgentDetailPage(
2113
2126
 
2114
2127
  // One GitHub card: connect actions plus (admin + enterprise GitHub) the
2115
2128
  // Preview access and GitHub sync fragments.
2116
- const githubCardBody = `${githubConnectActionsHtml}${showGithubIdentity ? renderGithubAccessCard(agent.id) : ""}${showGithubIdentity ? renderGithubSyncCard(agent.id, { hasAppId: "GH_APP_ID" in envVars, githubUsername: agent.githubUsername }) : ""}${showGithubIdentity ? renderGithubInstallCard(agent.id) : ""}`;
2129
+ 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) : ""}`;
2117
2130
  const githubSection =
2118
2131
  canManage && githubCardBody.trim() !== ""
2119
2132
  ? `<div class="card">