@app-vitals/agent-admin 1.109.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.
Files changed (53) hide show
  1. package/openapi.json +0 -193
  2. package/openapi.platform.json +1 -238
  3. package/package.json +2 -2
  4. package/src/admin-boot.ts +6 -5
  5. package/src/admin-ui-github-enterprise-pages.ts +13 -2
  6. package/src/admin-ui-github-enterprise.smoke.test.ts +20 -1
  7. package/src/admin-ui-github-enterprise.ts +16 -1
  8. package/src/admin-ui-github-identity-pages.ts +35 -139
  9. package/src/admin-ui-github-identity-pages.unit.test.ts +50 -173
  10. package/src/admin-ui-github-identity.smoke.test.ts +103 -63
  11. package/src/admin-ui-installation-repos-pages.ts +2 -23
  12. package/src/admin-ui-installation-repos-pages.unit.test.ts +41 -36
  13. package/src/admin-ui-installation-repos.smoke.test.ts +9 -8
  14. package/src/admin-ui-pages.ts +4 -5
  15. package/src/admin-ui-slack-config-token-pages.ts +11 -2
  16. package/src/admin-ui-slack-config-token.smoke.test.ts +39 -3
  17. package/src/admin-ui-slack-config-token.ts +51 -9
  18. package/src/admin-ui-templates-pages.ts +7 -1
  19. package/src/admin-ui-templates.smoke.test.ts +31 -5
  20. package/src/admin-ui-templates.ts +43 -8
  21. package/src/admin-ui.ts +51 -36
  22. package/src/agent-templates-api.integration.test.ts +29 -7
  23. package/src/agent-templates.ts +7 -1
  24. package/src/agents-api.smoke.test.ts +26 -315
  25. package/src/agents-api.ts +1 -107
  26. package/src/deployment-wide-settings.integration.test.ts +309 -0
  27. package/src/deployment-wide-settings.ts +42 -0
  28. package/src/github-access-preview.ts +2 -2
  29. package/src/github-agent-installation-crawler.ts +18 -1
  30. package/src/github-enterprise-api.integration.test.ts +7 -0
  31. package/src/github-enterprise-api.smoke.test.ts +26 -0
  32. package/src/github-enterprise-api.ts +24 -4
  33. package/src/github-enterprise-apps.integration.test.ts +33 -8
  34. package/src/github-enterprise-apps.ts +4 -0
  35. package/src/github-enterprise-client.integration.test.ts +0 -41
  36. package/src/github-enterprise-client.ts +0 -25
  37. package/src/github-enterprise-client.unit.test.ts +0 -18
  38. package/src/github-installation-wiring.ts +48 -13
  39. package/src/github-installation-wiring.unit.test.ts +38 -1
  40. package/src/github-sync-all-repos.unit.test.ts +116 -0
  41. package/src/github-sync-cache.integration.test.ts +9 -2
  42. package/src/github-sync-snapshot-refresh.integration.test.ts +168 -0
  43. package/src/github-sync-snapshot-refresh.unit.test.ts +144 -0
  44. package/src/github-sync.ts +103 -137
  45. package/src/github-sync.unit.test.ts +82 -1
  46. package/src/installation-ports.ts +1 -40
  47. package/src/installation-repos-service.ts +7 -4
  48. package/src/reconcile-open-work.integration.test.ts +0 -1
  49. package/src/slack-config-token.integration.test.ts +19 -2
  50. package/src/slack-config-token.ts +6 -1
  51. package/src/github-access-preview.integration.test.ts +0 -399
  52. package/src/github-sync-switch.integration.test.ts +0 -297
  53. package/src/github-sync-switch.unit.test.ts +0 -467
@@ -1,72 +1,18 @@
1
1
  /**
2
2
  * admin/src/admin-ui-github-identity-pages.ts
3
- * Pure renderers for the agent detail page's GitHub identity row and access
4
- * preview (GHE-2.5). Both are platform-admin only and shown only when the
5
- * enterprise GitHub apps are configured; the caller decides that. Every
6
- * dynamic value is escaped. The input is the GHE-2.4 preview, which carries
7
- * repo names and levels only (no token or key ever reaches this module).
3
+ * Pure renderers for the agent detail page's GitHub identity row and install
4
+ * blocks (GHE-2.5). Platform-admin only and shown only when the enterprise
5
+ * GitHub apps are configured; the caller decides that. Every dynamic value is
6
+ * escaped.
8
7
  */
9
8
 
10
9
  import {
11
10
  type GithubAppsState,
12
- LOOKUP_MISSING_REASON,
13
11
  LOOKUP_ONLY_REASON,
14
12
  } from "./github-apps-state.ts";
15
13
  import type { GheOrgs } from "./admin-ui-github-enterprise-pages.ts";
16
14
  import { escapeHtml } from "./admin-ui-styles.ts";
17
15
 
18
- export interface GithubAccessRepo {
19
- fullName: string;
20
- level: string;
21
- canPush: boolean;
22
- }
23
-
24
- export type GithubAccessOrgStatus =
25
- | "ok"
26
- | "lookup_app_not_installed"
27
- | "rate_limited"
28
- | "partial"
29
- | "error";
30
-
31
- export interface GithubAccessOrg {
32
- org: string;
33
- status: GithubAccessOrgStatus;
34
- repos: GithubAccessRepo[];
35
- unresolved: number;
36
- /** Optional cause shown in the partial-results banner. */
37
- reason?: string;
38
- }
39
-
40
- /** JSON body of GET /agents/:id/github-access. */
41
- export interface GithubAccessPreviewView {
42
- status: "ok" | "user_not_found" | "unconfigured";
43
- access?: {
44
- username: string;
45
- outcome: "ok" | "user_not_found";
46
- userVerified: boolean;
47
- orgs: GithubAccessOrg[];
48
- unresolved: number;
49
- complete: boolean;
50
- checkedAt: string;
51
- };
52
- }
53
-
54
- const STATUS_BADGES: Record<GithubAccessOrgStatus, [string, string]> = {
55
- ok: ["badge-green", "ok"],
56
- lookup_app_not_installed: ["badge-gray", "lookup app not installed"],
57
- rate_limited: ["badge-warning", "rate-limited"],
58
- partial: ["badge-warning", "partial"],
59
- error: ["badge-warning", "error"],
60
- };
61
-
62
- function statusBadge(status: string): string {
63
- const [cls, label] = STATUS_BADGES[status as GithubAccessOrgStatus] ?? [
64
- "badge-warning",
65
- status,
66
- ];
67
- return `<span class="badge ${cls}">${escapeHtml(label)}</span>`;
68
- }
69
-
70
16
  /** The GitHub username `<tr>` for the "Owner & identities" card. */
71
17
  export function renderGithubUsernameRow(
72
18
  agentId: string,
@@ -90,86 +36,6 @@ export function renderGithubUsernameRow(
90
36
  </td></tr>`;
91
37
  }
92
38
 
93
- /** The "Preview access" fragment (rendered inside the GitHub card); the button loads the fragment from the UI route. */
94
- export function renderGithubAccessCard(agentId: string): string {
95
- const url = `/admin/agents/${escapeHtml(agentId)}/github-access`;
96
- return `<div id="github-access-card" style="margin-top:20px">
97
- <div class="form-label" style="font-weight:600;margin-bottom:6px">Preview access</div>
98
- <p style="color:var(--vos-text-muted);font-size:12px;margin:0 0 12px">Shows the repos this agent's GitHub user can reach. Read-only; nothing is stored.</p>
99
- <button type="button" class="btn btn-primary" id="github-access-btn" data-url="${url}">Preview access</button>
100
- <div id="github-access-result" style="margin-top:12px"></div>
101
- <script>
102
- (function() {
103
- var btn = document.getElementById('github-access-btn');
104
- var out = document.getElementById('github-access-result');
105
- if (!btn || !out) return;
106
- btn.addEventListener('click', function() {
107
- btn.disabled = true;
108
- out.textContent = 'Loading...';
109
- fetch(btn.getAttribute('data-url'), { credentials: 'same-origin' })
110
- .then(function(r) { return r.text(); })
111
- .then(function(t) { out.innerHTML = t; })
112
- .catch(function() { out.textContent = 'The request failed.'; })
113
- .then(function() { btn.disabled = false; });
114
- });
115
- })();
116
- </script>
117
- </div>`;
118
- }
119
-
120
- /** Fragment rendered into the preview card; also the body of the UI route. */
121
- export function renderGithubAccessResult(
122
- preview: GithubAccessPreviewView,
123
- ): string {
124
- if (preview.status === "unconfigured") {
125
- return `<div class="alert alert-warning" data-reason="lookup-missing">${escapeHtml(LOOKUP_MISSING_REASON)}</div>`;
126
- }
127
- const access = preview.access;
128
- if (
129
- preview.status === "user_not_found" ||
130
- access?.outcome === "user_not_found"
131
- ) {
132
- const who = access?.username ? ` "${escapeHtml(access.username)}"` : "";
133
- return `<div class="alert alert-warning">GitHub user${who} was not found.</div>`;
134
- }
135
- if (!access) return renderGithubAccessError("No preview was returned.");
136
-
137
- const orgs = access.orgs;
138
- const reasons = orgs
139
- .filter((o) => o.reason)
140
- .map((o) => `${escapeHtml(o.org)}: ${escapeHtml(o.reason ?? "")}`)
141
- .join("; ");
142
- const warn =
143
- !access.complete || orgs.some((o) => o.status !== "ok")
144
- ? `<div class="alert alert-warning">Partial results: some organizations or repos could not be checked${access.unresolved > 0 ? ` (${access.unresolved} unresolved)` : ""}. Repos that are not listed are unknown, not necessarily inaccessible.${reasons ? ` ${reasons}.` : ""}</div>`
145
- : "";
146
- if (orgs.length === 0) {
147
- return `${warn}<p class="empty-state">No organizations to check.</p>`;
148
- }
149
- const groups = orgs
150
- .map((o) => {
151
- const rows =
152
- o.repos.length === 0
153
- ? `<tr><td colspan="3" class="empty-state">No repos.</td></tr>`
154
- : o.repos
155
- .map(
156
- (r) =>
157
- `<tr><td class="mono">${escapeHtml(r.fullName)}</td><td>${escapeHtml(r.level)}</td><td>${r.canPush ? '<span class="badge badge-green" title="Can push">push</span>' : ""}</td></tr>`,
158
- )
159
- .join("");
160
- const unresolved =
161
- o.unresolved > 0
162
- ? ` <span style="color:var(--vos-text-muted);font-size:12px">${o.unresolved} unresolved</span>`
163
- : "";
164
- return `<div class="github-access-org" style="margin-bottom:16px">
165
- <div style="font-weight:600;margin-bottom:6px">${escapeHtml(o.org)} ${statusBadge(o.status)}${unresolved}</div>
166
- <table class="detail-table"><thead><tr><th>Repo</th><th>Level</th><th>Push</th></tr></thead><tbody>${rows}</tbody></table>
167
- </div>`;
168
- })
169
- .join("");
170
- return `${warn}${groups}`;
171
- }
172
-
173
39
  export function renderGithubAccessError(message: string): string {
174
40
  return `<div class="alert alert-error">${escapeHtml(message)}</div>`;
175
41
  }
@@ -214,10 +80,40 @@ function installedBadge(v: boolean | null): string {
214
80
  : `<span class="badge badge-gray">Not installed</span>`;
215
81
  }
216
82
 
83
+ /** Most repositories one install can select (mirrors the API and GitHub). */
84
+ export const MAX_INSTALL_REPOSITORIES = 50;
85
+
86
+ // Recomputes the Selected checklist state on any change: shows the list and
87
+ // count only for Selected, and blocks submit for 0 or more than the cap.
88
+ const INSTALL_FORM_JS = `var f=this,s=f.querySelector('input[name=repositorySelection]:checked').value==='selected',n=f.querySelectorAll('input[name=repositories]:checked').length,b=f.querySelector('button[type=submit]'),c=f.querySelector('[data-count]'),bad=s&&(n<1||n>${MAX_INSTALL_REPOSITORIES});f.querySelector('[data-selected-panel]').style.display=s?'block':'none';c.textContent=n+' of ${MAX_INSTALL_REPOSITORIES} selected';c.style.color=bad?'#b91c1c':'';b.disabled=bad||b.hasAttribute('data-locked')`;
89
+
90
+ /** The Install form for one not-installed org: All or Selected (capped checklist). */
91
+ function installForm(
92
+ base: string,
93
+ repos: readonly string[],
94
+ disabled: string,
95
+ ): string {
96
+ const known = repos.length > 0;
97
+ const initial = repos.slice(0, MAX_INSTALL_REPOSITORIES);
98
+ const items = repos
99
+ .map((r, i) => {
100
+ const checked = i < MAX_INSTALL_REPOSITORIES ? " checked" : "";
101
+ return `<label style="display:block;font-size:12px"><input type="checkbox" name="repositories" value="${escapeHtml(r)}"${checked}> ${escapeHtml(r)}</label>`;
102
+ })
103
+ .join("");
104
+ const panel = known
105
+ ? `<div style="max-height:160px;overflow:auto;border:1px solid #ddd;padding:4px 8px;margin:4px 0">${items}</div>`
106
+ : `<p style="font-size:12px;margin:4px 0">No cached repositories for this organization yet. Refresh the GitHub cache to choose repositories, or install on All.</p>`;
107
+ const locked = disabled ? " data-locked" : "";
108
+ return `<form method="POST" action="${base}/install" style="display:inline-block;margin:0;text-align:left" onchange="${escapeHtml(INSTALL_FORM_JS)}"><label style="font-size:12px"><input type="radio" name="repositorySelection" value="all"${known ? "" : " checked"}> All repositories</label> <label style="font-size:12px"><input type="radio" name="repositorySelection" value="selected"${known ? " checked" : ""}> Selected (max ${MAX_INSTALL_REPOSITORIES})</label><div data-selected-panel style="display:${known ? "block" : "none"}">${panel}<span data-count style="font-size:12px">${initial.length} of ${MAX_INSTALL_REPOSITORIES} selected</span></div><button type="submit" class="btn btn-primary" style="font-size:12px;padding:4px 10px"${locked}${disabled}>Install</button></form>`;
109
+ }
110
+
217
111
  /** Fragment for the Install on org block: org list with app status and Install buttons. */
218
112
  export function renderGithubOrgsFragment(
219
113
  agentId: string,
220
114
  data: GheOrgs,
115
+ /** Cached pushable repo names per org (never a live GitHub read). Absent/empty = no pre-fill. */
116
+ repoChoices: Record<string, readonly string[]> = {},
221
117
  ): string {
222
118
  if (!data.configured) {
223
119
  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>`;
@@ -234,7 +130,7 @@ export function renderGithubOrgsFragment(
234
130
  const base = `/admin/agents/${escapeHtml(agentId)}/github-orgs/${escapeHtml(encodeURIComponent(o.login))}`;
235
131
  const action = o.agentAppInstalled
236
132
  ? `<button type="button" class="btn btn-danger" style="font-size:12px;padding:4px 10px" data-url="${base}/uninstall-confirm" onclick="var b=this,t=document.getElementById('uninstall-confirm-'+b.getAttribute('data-org'));b.disabled=true;fetch(b.getAttribute('data-url'),{credentials:'same-origin'}).then(function(r){return r.text()}).then(function(h){t.innerHTML=h}).catch(function(){t.textContent='The request failed.'}).then(function(){b.disabled=false})" data-org="${escapeHtml(o.login)}"${disabled}>Uninstall</button>`
237
- : `<form method="POST" action="${base}/install" style="display:inline;margin:0"><button type="submit" class="btn btn-primary" style="font-size:12px;padding:4px 10px"${disabled}>Install</button></form>`;
133
+ : installForm(base, repoChoices[o.login] ?? [], disabled);
238
134
  const confirmRow = o.agentAppInstalled
239
135
  ? `<tr><td colspan="4" id="uninstall-confirm-${escapeHtml(o.login)}" style="padding:0"></td></tr>`
240
136
  : "";
@@ -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"');