@app-vitals/agent-admin 1.81.0 → 1.83.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.
@@ -3528,6 +3528,45 @@
3528
3528
  "appId": {
3529
3529
  "type": "integer"
3530
3530
  },
3531
+ "complete": {
3532
+ "type": "boolean",
3533
+ "description": "Whether the cached crawl is complete. While false the list may be partial."
3534
+ },
3535
+ "syncedAt": {
3536
+ "type": "string",
3537
+ "description": "When the completed crawl finished (ISO 8601)."
3538
+ },
3539
+ "reposSeen": {
3540
+ "type": "integer",
3541
+ "description": "Repos in the cache (the N of 'N of M')."
3542
+ },
3543
+ "totalCount": {
3544
+ "type": "integer",
3545
+ "description": "GitHub's repo count, when known (the M)."
3546
+ },
3547
+ "lastError": {
3548
+ "type": "string"
3549
+ },
3550
+ "rateLimitResetAt": {
3551
+ "type": "string",
3552
+ "description": "When the GitHub rate limit resets (ISO 8601)."
3553
+ },
3554
+ "attempts": {
3555
+ "type": "integer",
3556
+ "description": "Failed refresh attempts; absent when zero."
3557
+ },
3558
+ "nextAttemptAt": {
3559
+ "type": "string",
3560
+ "description": "Next refresh attempt while backing off (ISO 8601)."
3561
+ },
3562
+ "leaseHolder": {
3563
+ "type": "string",
3564
+ "description": "Holder of a live refresh lease, if any."
3565
+ },
3566
+ "lastTickAt": {
3567
+ "type": "string",
3568
+ "description": "Last refresh tick on the snapshot (ISO 8601)."
3569
+ },
3531
3570
  "orgs": {
3532
3571
  "type": "array",
3533
3572
  "items": {
@@ -3536,6 +3575,45 @@
3536
3575
  "org": {
3537
3576
  "type": "string"
3538
3577
  },
3578
+ "complete": {
3579
+ "type": "boolean",
3580
+ "description": "Whether the cached crawl is complete. While false the list may be partial."
3581
+ },
3582
+ "syncedAt": {
3583
+ "type": "string",
3584
+ "description": "When the completed crawl finished (ISO 8601)."
3585
+ },
3586
+ "reposSeen": {
3587
+ "type": "integer",
3588
+ "description": "Repos in the cache (the N of 'N of M')."
3589
+ },
3590
+ "totalCount": {
3591
+ "type": "integer",
3592
+ "description": "GitHub's repo count, when known (the M)."
3593
+ },
3594
+ "lastError": {
3595
+ "type": "string"
3596
+ },
3597
+ "rateLimitResetAt": {
3598
+ "type": "string",
3599
+ "description": "When the GitHub rate limit resets (ISO 8601)."
3600
+ },
3601
+ "attempts": {
3602
+ "type": "integer",
3603
+ "description": "Failed refresh attempts; absent when zero."
3604
+ },
3605
+ "nextAttemptAt": {
3606
+ "type": "string",
3607
+ "description": "Next refresh attempt while backing off (ISO 8601)."
3608
+ },
3609
+ "leaseHolder": {
3610
+ "type": "string",
3611
+ "description": "Holder of a live refresh lease, if any."
3612
+ },
3613
+ "lastTickAt": {
3614
+ "type": "string",
3615
+ "description": "Last refresh tick on the snapshot (ISO 8601)."
3616
+ },
3539
3617
  "repos": {
3540
3618
  "type": "array",
3541
3619
  "items": {
@@ -3546,7 +3624,7 @@
3546
3624
  },
3547
3625
  "userCanPush": {
3548
3626
  "type": "boolean",
3549
- "description": "Whether the agent's bound GitHub user can push. Omitted when no username is bound or the org's access lookup is incomplete; never reported as false for unknown."
3627
+ "description": "Whether the agent's bound GitHub user can push, from cached access rows. Omitted when no username is bound or the org's access data is incomplete (a missing or errored pair is never reported as false)."
3550
3628
  }
3551
3629
  },
3552
3630
  "required": [
@@ -7879,7 +7957,7 @@
7879
7957
  "/agents/{id}/github-installation/repos": {
7880
7958
  "get": {
7881
7959
  "summary": "List the repos on the agent App's installation",
7882
- "description": "Platform-admin only (session members, ops keys and agent keys get 403). Per org the agent's own GitHub App (its GH_APP_ID) is installed on, lists the installation's repos. When the agent has a bound githubUsername, each repo carries `userCanPush` from the access lookup only when that org's lookup result is complete; otherwise the field is omitted (never false). 404 for an unknown agent; 422 when the agent has no GH_APP_ID.",
7960
+ "description": "Platform-admin only (session members, ops keys and agent keys get 403). Per org the agent's own GitHub App (its GH_APP_ID) is installed on, lists the installation's repos from the background-synced cache; it makes no GitHub call. Sync detail (`complete`, `syncedAt`, `reposSeen`, `totalCount`, `lastError`, `rateLimitResetAt`) is reported per org and overall. When the agent has a bound githubUsername, each repo carries `userCanPush` from cached access rows only when that org's snapshot is complete and every repo has an answer; otherwise the field is omitted (never false). 404 for an unknown agent; 422 when the agent has no GH_APP_ID.",
7883
7961
  "parameters": [
7884
7962
  {
7885
7963
  "schema": {
@@ -8408,6 +8486,76 @@
8408
8486
  }
8409
8487
  }
8410
8488
  },
8489
+ "/github-enterprise/refresh": {
8490
+ "post": {
8491
+ "tags": [
8492
+ "github-enterprise"
8493
+ ],
8494
+ "summary": "Request a refresh of the GitHub cache",
8495
+ "description": "Admin-only. Marks the cached GitHub repo lists stale and clears retry waits so the background refresher works them next, then returns at once. It makes no GitHub call and does not wait for the refresher; reload the page to see progress. The refresher still honours its per-org lease and rate-limit window.",
8496
+ "responses": {
8497
+ "202": {
8498
+ "description": "Refresh requested",
8499
+ "content": {
8500
+ "application/json": {
8501
+ "schema": {
8502
+ "type": "object",
8503
+ "properties": {
8504
+ "status": {
8505
+ "type": "string",
8506
+ "enum": [
8507
+ "accepted"
8508
+ ]
8509
+ },
8510
+ "snapshots": {
8511
+ "type": "integer"
8512
+ },
8513
+ "accessPairs": {
8514
+ "type": "integer"
8515
+ }
8516
+ },
8517
+ "required": [
8518
+ "status",
8519
+ "snapshots",
8520
+ "accessPairs"
8521
+ ]
8522
+ }
8523
+ }
8524
+ }
8525
+ },
8526
+ "401": {
8527
+ "description": "Unauthorized",
8528
+ "content": {
8529
+ "application/json": {
8530
+ "schema": {
8531
+ "$ref": "#/components/schemas/Error"
8532
+ }
8533
+ }
8534
+ }
8535
+ },
8536
+ "403": {
8537
+ "description": "Forbidden (non-admin caller)",
8538
+ "content": {
8539
+ "application/json": {
8540
+ "schema": {
8541
+ "$ref": "#/components/schemas/Error"
8542
+ }
8543
+ }
8544
+ }
8545
+ },
8546
+ "503": {
8547
+ "description": "Refresh is not available",
8548
+ "content": {
8549
+ "application/json": {
8550
+ "schema": {
8551
+ "$ref": "#/components/schemas/Error"
8552
+ }
8553
+ }
8554
+ }
8555
+ }
8556
+ }
8557
+ }
8558
+ },
8411
8559
  "/github-enterprise/apps/{role}/validate": {
8412
8560
  "post": {
8413
8561
  "tags": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-admin",
3
- "version": "1.81.0",
3
+ "version": "1.83.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@anthropic-ai/sdk": "0.137.0",
46
- "@app-vitals/agent-lib": "1.81.0",
46
+ "@app-vitals/agent-lib": "1.83.0",
47
47
  "@hono/zod-openapi": "^1.0.0",
48
48
  "@prisma/adapter-pg": "^7.10.0",
49
49
  "@prisma/client": "^7.10.0",
package/src/admin-boot.ts CHANGED
@@ -116,18 +116,19 @@ import {
116
116
  createGithubSync,
117
117
  createStoredAppRefreshDiscovery,
118
118
  } from "./github-installation-wiring.ts";
119
+ import { createGithubRefreshAction } from "./github-refresh-action.ts";
119
120
  import { GitHubRepoCacheService } from "./github-repo-cache.ts";
120
121
  import {
121
122
  GithubRepoRefresher,
122
123
  resolveRefreshConfig,
123
124
  } from "./github-repo-refresher.ts";
124
- import { PrincipalLookupService } from "./principal-lookup.ts";
125
- import { createPrincipalsApp } from "./principals-api.ts";
126
125
  import { HttpGoogleAuthClient } from "./google-auth-client.ts";
127
126
  import { HttpChatClient } from "./http-chat-client.ts";
128
127
  import { HttpOktaAuthClient } from "./okta-auth-client.ts";
129
128
  import { mountPlatformDoc } from "./platform-doc-route.ts";
130
129
  import { parsePodServiceAccountConfig } from "./pod-service-account-config.ts";
130
+ import { PrincipalLookupService } from "./principal-lookup.ts";
131
+ import { createPrincipalsApp } from "./principals-api.ts";
131
132
  import { createAdminPrismaClient } from "./prisma-client.ts";
132
133
  import { isPushEnabled } from "./push-sender.ts";
133
134
  import { PushService } from "./push-service.ts";
@@ -649,7 +650,17 @@ export async function startAdmin(
649
650
  // 3b'. GitHub Enterprise Apps API — /github-enterprise/* — admin-only,
650
651
  // optional (GHE-1.3). With no rows configured it reports unconfigured
651
652
  // and does nothing else. Strict crypto: no plain-text key storage.
653
+ // GLC-2.4: the Refresh action marks the cache stale (DB only). It asks the
654
+ // refresher (created further down) to re-discover through this hook.
655
+ const githubRefreshConfig = resolveRefreshConfig(process.env);
656
+ let invalidateGithubDiscovery: () => void = () => {};
657
+ const githubRefreshAction = createGithubRefreshAction({
658
+ cache: githubRepoCache,
659
+ stalenessCapMs: githubRefreshConfig.stalenessCapMs,
660
+ onMarked: () => invalidateGithubDiscovery(),
661
+ });
652
662
  const githubEnterpriseApp = createGithubEnterpriseApp({
663
+ refreshAction: githubRefreshAction,
653
664
  appService: githubEnterpriseAppService,
654
665
  agentService,
655
666
  agentEnvService,
@@ -860,7 +871,6 @@ export async function startAdmin(
860
871
  // replica work an org at a time. Without stored GitHub Apps discovery finds
861
872
  // nothing and every tick is idle.
862
873
  {
863
- const githubRefreshConfig = resolveRefreshConfig(process.env);
864
874
  const githubRepoRefresher = new GithubRepoRefresher({
865
875
  discovery: createStoredAppRefreshDiscovery({
866
876
  prisma,
@@ -872,6 +882,7 @@ export async function startAdmin(
872
882
  store: githubRepoCache,
873
883
  config: githubRefreshConfig,
874
884
  });
885
+ invalidateGithubDiscovery = () => githubRepoRefresher.invalidateDiscovery();
875
886
  setInterval(() => {
876
887
  githubRepoRefresher
877
888
  .tick()
@@ -0,0 +1,96 @@
1
+ /**
2
+ * admin/src/admin-ui-github-refresh.smoke.test.ts
3
+ * GLC-2.4: the Refresh button on the agent GitHub card and its POST route:
4
+ * admin only, redirects at once, and makes no GitHub call (the enterprise API
5
+ * is a stub that records paths). No DB, no network.
6
+ */
7
+
8
+ import { beforeAll, describe, expect, it } from "bun:test";
9
+ import {
10
+ AGENT_ID,
11
+ makeMockDeps,
12
+ makeSessionCookie,
13
+ } from "./admin-ui.fixtures.ts";
14
+ import { createAdminUIApp } from "./admin-ui.ts";
15
+
16
+ const json = (b: unknown, status = 200) =>
17
+ new Response(JSON.stringify(b), {
18
+ status,
19
+ headers: { "Content-Type": "application/json" },
20
+ });
21
+
22
+ function setup(refreshStatus = 202) {
23
+ const paths: string[] = [];
24
+ const deps = makeMockDeps({
25
+ githubEnterpriseApi: (path: string, init?: RequestInit) => {
26
+ paths.push(`${init?.method ?? "GET"} ${path}`);
27
+ if (path === "/github-enterprise/refresh") {
28
+ return refreshStatus === 202
29
+ ? json({ status: "accepted", snapshots: 1, accessPairs: 0 }, 202)
30
+ : json({ error: "nope" }, refreshStatus);
31
+ }
32
+ return json({
33
+ configured: true,
34
+ installer: { role: "installer" },
35
+ lookup: { role: "lookup" },
36
+ });
37
+ },
38
+ agentsApi: () => json({ appId: 1, orgs: [] }),
39
+ } as never);
40
+ return { app: createAdminUIApp(deps), paths };
41
+ }
42
+
43
+ describe("admin UI — GitHub cache Refresh (GLC-2.4)", () => {
44
+ let admin: string;
45
+ let member: string;
46
+ beforeAll(async () => {
47
+ admin = await makeSessionCookie();
48
+ member = await makeSessionCookie(
49
+ undefined,
50
+ "sub-2",
51
+ "other@example.com",
52
+ false,
53
+ );
54
+ });
55
+ const h = (cookie: string) => ({ Cookie: `admin_session=${cookie}` });
56
+ const refresh = (app: ReturnType<typeof setup>["app"], c = admin) =>
57
+ app.request(`/admin/agents/${AGENT_ID}/github-cache/refresh`, {
58
+ method: "POST",
59
+ headers: h(c),
60
+ redirect: "manual",
61
+ });
62
+
63
+ it("shows the Refresh button on the agent GitHub card", async () => {
64
+ const { app } = setup();
65
+ const html = await (
66
+ await app.request(`/admin/agents/${AGENT_ID}/access`, {
67
+ headers: h(admin),
68
+ })
69
+ ).text();
70
+ expect(html).toContain('id="github-refresh-btn"');
71
+ expect(html).toContain(`/admin/agents/${AGENT_ID}/github-cache/refresh`);
72
+ });
73
+
74
+ it("redirects an admin with 302 after one refresh call", async () => {
75
+ const { app, paths } = setup();
76
+ const res = await refresh(app);
77
+ expect(res.status).toBe(302);
78
+ expect(res.headers.get("location")).toContain(
79
+ "success=github_refresh_requested",
80
+ );
81
+ expect(paths).toEqual(["POST /github-enterprise/refresh"]);
82
+ });
83
+
84
+ it("redirects with an error when the API refuses", async () => {
85
+ const { app } = setup(503);
86
+ const res = await refresh(app);
87
+ expect(res.status).toBe(302);
88
+ expect(res.headers.get("location")).toContain("error=");
89
+ });
90
+
91
+ it("is forbidden for a non-admin and calls nothing", async () => {
92
+ const { app, paths } = setup();
93
+ expect((await refresh(app, member)).status).toBe(403);
94
+ expect(paths).toEqual([]);
95
+ });
96
+ });
@@ -24,12 +24,86 @@ export interface OpenWorkView {
24
24
  }
25
25
 
26
26
  /** JSON body of GET /agents/:id/github-installation/repos. */
27
- export interface InstallationReposView {
27
+ export interface InstallationSyncView {
28
+ /** False while the cached crawl is incomplete. Absent (older API): treated as complete. */
29
+ complete?: boolean;
30
+ syncedAt?: string;
31
+ reposSeen?: number;
32
+ totalCount?: number;
33
+ lastError?: string;
34
+ rateLimitResetAt?: string;
35
+ attempts?: number;
36
+ nextAttemptAt?: string;
37
+ leaseHolder?: string;
38
+ lastTickAt?: string;
39
+ }
40
+
41
+ export interface InstallationReposView extends InstallationSyncView {
28
42
  appId?: number;
29
- orgs: {
43
+ orgs: ({
30
44
  org: string;
31
45
  repos: { fullName: string; userCanPush?: boolean }[];
32
- }[];
46
+ } & InstallationSyncView)[];
47
+ }
48
+
49
+ /** True unless the view says its snapshot is incomplete. */
50
+ export const installationSnapshotComplete = (
51
+ view: InstallationSyncView,
52
+ ): boolean => view.complete !== false;
53
+
54
+ /** True when the view carries any sync detail worth showing. */
55
+ const hasSyncDetail = (v: InstallationSyncView): boolean =>
56
+ v.complete !== undefined ||
57
+ v.syncedAt !== undefined ||
58
+ v.reposSeen !== undefined ||
59
+ v.lastError !== undefined ||
60
+ v.rateLimitResetAt !== undefined ||
61
+ v.attempts !== undefined ||
62
+ v.nextAttemptAt !== undefined ||
63
+ v.leaseHolder !== undefined ||
64
+ v.lastTickAt !== undefined;
65
+
66
+ const utc = (iso: string): string =>
67
+ `${escapeHtml(iso.slice(0, 16).replace("T", " "))} UTC`;
68
+
69
+ /**
70
+ * One-line sync status: synced-at, "N of M repos", last error and the rate-limit
71
+ * reset. Empty when the view has no sync detail (older API).
72
+ */
73
+ export function renderInstallationSyncStatus(v: InstallationSyncView): string {
74
+ if (!hasSyncDetail(v)) return "";
75
+ const complete = installationSnapshotComplete(v);
76
+ const parts: string[] = [];
77
+ parts.push(
78
+ v.syncedAt
79
+ ? `Synced ${escapeHtml(v.syncedAt.slice(0, 16).replace("T", " "))} UTC`
80
+ : complete
81
+ ? "Synced"
82
+ : "Sync in progress",
83
+ );
84
+ if (v.reposSeen !== undefined) {
85
+ parts.push(
86
+ v.totalCount !== undefined
87
+ ? `${v.reposSeen} of ${v.totalCount} repos`
88
+ : `${v.reposSeen} repos`,
89
+ );
90
+ }
91
+ if (v.lastError) parts.push(`Last error: ${escapeHtml(v.lastError)}`);
92
+ if (v.rateLimitResetAt) {
93
+ parts.push(
94
+ `GitHub rate limit resets ${escapeHtml(v.rateLimitResetAt.slice(0, 16).replace("T", " "))} UTC`,
95
+ );
96
+ }
97
+ if (v.attempts) {
98
+ parts.push(
99
+ `${v.attempts} failed ${v.attempts === 1 ? "attempt" : "attempts"}`,
100
+ );
101
+ }
102
+ if (v.nextAttemptAt) parts.push(`Next attempt ${utc(v.nextAttemptAt)}`);
103
+ if (v.leaseHolder) parts.push(`Refreshing (${escapeHtml(v.leaseHolder)})`);
104
+ if (v.lastTickAt) parts.push(`Last tick ${utc(v.lastTickAt)}`);
105
+ const cls = v.lastError || v.rateLimitResetAt ? "alert alert-warning" : "";
106
+ return `<div class="${cls}" data-installation-sync="${complete ? "complete" : "incomplete"}" style="color:#6b7280;font-size:12px;margin:8px 0">${parts.join(" &middot; ")}</div>`;
33
107
  }
34
108
 
35
109
  /** JSON body of GET /agents/:id/repos/:owner/:name/removal-preview. */
@@ -142,9 +216,11 @@ export function renderGithubSyncCard(
142
216
  const loader = state.hasAppId
143
217
  ? `<div id="github-installation-body">Loading...</div>`
144
218
  : "";
219
+ 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>`;
145
220
  return `<div id="github-installation-card" data-base-url="${base}" style="margin-top:20px">
146
221
  <div class="form-label" style="font-weight:600;margin-bottom:6px">GitHub sync</div>
147
222
  <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>
223
+ ${refresh}
148
224
  ${action}
149
225
  ${loader}
150
226
  <script>
@@ -161,6 +237,15 @@ export function renderGithubSyncCard(
161
237
  .then(function(t) { body.innerHTML = t; })
162
238
  .catch(function() { body.textContent = 'The request failed.'; });
163
239
  }
240
+ var refreshBtn = document.getElementById('github-refresh-btn');
241
+ if (refreshBtn) {
242
+ refreshBtn.addEventListener('click', function() {
243
+ refreshBtn.disabled = true;
244
+ fetch(refreshBtn.getAttribute('data-url'), { method: 'POST', credentials: 'same-origin' })
245
+ .then(function(r) { window.location.href = r.url; })
246
+ .catch(function() { refreshBtn.disabled = false; });
247
+ });
248
+ }
164
249
  if (!out) return;
165
250
  card.addEventListener('click', function(e) {
166
251
  var t = e.target;
@@ -198,31 +283,40 @@ export function renderInstallationReposBody(
198
283
  view: InstallationReposView,
199
284
  opts: { appIdMismatch?: boolean } = {},
200
285
  ): string {
201
- if (view.orgs.length === 0) {
286
+ const sync = renderInstallationSyncStatus(view);
287
+ if (view.orgs.length === 0 || view.orgs.every((o) => o.repos.length === 0)) {
202
288
  if (opts.appIdMismatch) {
203
- return `<div class="alert alert-warning" data-reason="app-id-mismatch">${escapeHtml(APP_ID_MISMATCH_MESSAGE)}</div>`;
289
+ return `${sync}<div class="alert alert-warning" data-reason="app-id-mismatch">${escapeHtml(APP_ID_MISMATCH_MESSAGE)}</div>`;
290
+ }
291
+ if (!installationSnapshotComplete(view)) {
292
+ return `${sync}<p class="empty-state">The installation repos have not finished syncing yet.</p>`;
293
+ }
294
+ if (view.orgs.length === 0) {
295
+ return `${sync}<p class="empty-state">The agent App is not installed on any organization the installer can reach.</p>`;
204
296
  }
205
- return `<p class="empty-state">The agent App is not installed on any organization the installer can reach.</p>`;
206
297
  }
207
- return view.orgs
208
- .map((o) => {
209
- const rows =
210
- o.repos.length === 0
211
- ? `<tr><td colspan="2" class="empty-state">No repos.</td></tr>`
212
- : o.repos
213
- .map((r) => {
214
- const hint =
215
- r.userCanPush === undefined
216
- ? ""
217
- : r.userCanPush
218
- ? '<span class="badge badge-green" title="The bound user can push">user can push</span>'
219
- : '<span class="badge badge-warning" title="The bound user cannot push">user cannot push</span>';
220
- return `<tr><td class="mono">${escapeHtml(r.fullName)}</td><td>${hint}</td></tr>`;
221
- })
222
- .join("");
223
- return `<div class="github-installation-org" data-org="${escapeHtml(o.org)}" style="margin-bottom:16px"><div style="font-weight:600;margin-bottom:6px">${escapeHtml(o.org)}</div><table class="detail-table"><thead><tr><th>Repo</th><th>Bound user</th></tr></thead><tbody>${rows}</tbody></table></div>`;
224
- })
225
- .join("");
298
+ return (
299
+ sync +
300
+ view.orgs
301
+ .map((o) => {
302
+ const rows =
303
+ o.repos.length === 0
304
+ ? `<tr><td colspan="2" class="empty-state">No repos.</td></tr>`
305
+ : o.repos
306
+ .map((r) => {
307
+ const hint =
308
+ r.userCanPush === undefined
309
+ ? ""
310
+ : r.userCanPush
311
+ ? '<span class="badge badge-green" title="The bound user can push">user can push</span>'
312
+ : '<span class="badge badge-warning" title="The bound user cannot push">user cannot push</span>';
313
+ return `<tr><td class="mono">${escapeHtml(r.fullName)}</td><td>${hint}</td></tr>`;
314
+ })
315
+ .join("");
316
+ return `<div class="github-installation-org" data-org="${escapeHtml(o.org)}" style="margin-bottom:16px"><div style="font-weight:600;margin-bottom:6px">${escapeHtml(o.org)}</div>${renderInstallationSyncStatus(o)}<table class="detail-table"><thead><tr><th>Repo</th><th>Bound user</th></tr></thead><tbody>${rows}</tbody></table></div>`;
317
+ })
318
+ .join("")
319
+ );
226
320
  }
227
321
 
228
322
  /** Why the card body could not be shown, distinct per cause. */
@@ -5,11 +5,12 @@
5
5
 
6
6
  import { describe, expect, it } from "bun:test";
7
7
  import {
8
- actuallyBlockedWork,
9
8
  APP_ID_MISMATCH_MESSAGE,
9
+ actuallyBlockedWork,
10
10
  NO_USERNAME_REASON,
11
11
  renderGithubSyncCard,
12
12
  renderInstallationReposBody,
13
+ renderInstallationSyncStatus,
13
14
  renderOpenWorkByRepo,
14
15
  renderSyncConfirm,
15
16
  renderSyncResult,
@@ -254,3 +255,50 @@ describe("renderSyncResult", () => {
254
255
  ).toContain("no user");
255
256
  });
256
257
  });
258
+
259
+ describe("renderInstallationSyncStatus debug detail", () => {
260
+ it("shows attempts, next attempt, lease holder and last tick on a failed snapshot, as an error", () => {
261
+ const html = renderInstallationSyncStatus({
262
+ complete: false,
263
+ reposSeen: 3,
264
+ totalCount: 10,
265
+ lastError: "boom <b>",
266
+ attempts: 3,
267
+ nextAttemptAt: "2026-11-21T10:30:00.000Z",
268
+ leaseHolder: "worker-1",
269
+ lastTickAt: "2026-11-21T10:00:00.000Z",
270
+ });
271
+ expect(html).toContain("alert alert-warning");
272
+ expect(html).toContain("Last error: boom &lt;b&gt;");
273
+ expect(html).toContain("3 failed attempts");
274
+ expect(html).toContain("Next attempt 2026-11-21 10:30 UTC");
275
+ expect(html).toContain("Refreshing (worker-1)");
276
+ expect(html).toContain("Last tick 2026-11-21 10:00 UTC");
277
+ expect(html).not.toContain("no access");
278
+ });
279
+
280
+ it("shows nothing misleading on a complete snapshot with unset fields", () => {
281
+ const html = renderInstallationSyncStatus({
282
+ complete: true,
283
+ syncedAt: "2026-11-21T10:00:00.000Z",
284
+ reposSeen: 2,
285
+ totalCount: 2,
286
+ });
287
+ expect(html).toContain("Synced 2026-11-21 10:00 UTC");
288
+ expect(html).toContain("2 of 2 repos");
289
+ expect(html).not.toMatch(/attempt|Refreshing|Last tick|error/i);
290
+ });
291
+
292
+ it("singularizes one attempt and ignores zero attempts", () => {
293
+ expect(
294
+ renderInstallationSyncStatus({ complete: true, attempts: 1 }),
295
+ ).toContain("1 failed attempt<");
296
+ expect(
297
+ renderInstallationSyncStatus({ complete: true, attempts: 0 }),
298
+ ).not.toContain("attempt");
299
+ });
300
+
301
+ it("renders nothing for an older API with no detail", () => {
302
+ expect(renderInstallationSyncStatus({})).toBe("");
303
+ });
304
+ });