@app-vitals/agent-admin 1.132.0 → 1.134.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.
@@ -3377,8 +3377,23 @@
3377
3377
  "type": "string",
3378
3378
  "minLength": 1,
3379
3379
  "maxLength": 50,
3380
+ "description": "Installation state, e.g. \"ok\", \"broken\", or \"shadowed\" (a higher-priority app owns the same owner).",
3380
3381
  "example": "active"
3381
3382
  },
3383
+ "appId": {
3384
+ "type": "string",
3385
+ "minLength": 1,
3386
+ "maxLength": 100,
3387
+ "description": "GitHub App id this installation belongs to. Omitted by older agents, which are treated as the single legacy app.",
3388
+ "example": "123456"
3389
+ },
3390
+ "slug": {
3391
+ "type": "string",
3392
+ "minLength": 1,
3393
+ "maxLength": 200,
3394
+ "description": "GitHub App slug, when the agent knows it.",
3395
+ "example": "my-agent-app"
3396
+ },
3382
3397
  "lastError": {
3383
3398
  "type": [
3384
3399
  "string",
@@ -4536,6 +4551,12 @@
4536
4551
  "minLength": 1,
4537
4552
  "example": "agent-id"
4538
4553
  },
4554
+ "appId": {
4555
+ "type": "string",
4556
+ "minLength": 1,
4557
+ "example": "12345",
4558
+ "description": "Which of the agent's GitHub Apps to install: the App's numeric id (or its AgentGitHubApp row id). Required when the agent has more than one App; defaults to the only App otherwise."
4559
+ },
4539
4560
  "repositorySelection": {
4540
4561
  "type": "string",
4541
4562
  "enum": [
@@ -9097,7 +9118,7 @@
9097
9118
  "github-enterprise"
9098
9119
  ],
9099
9120
  "summary": "Install an agent's App on an organization",
9100
- "description": "Admin-only. Uses the agent's stored GH_APP_CLIENT_ID when set; otherwise resolves the stored GH_APP_SLUG and looks the App up through the public GET /apps/{slug} to get its client id. Installs it on the org with the installer App. 422 for an agent with neither a stored client id nor a slug, and for a private App (not visible to the public lookup) with no stored client id; 409 when the installer App is not configured.",
9121
+ "description": "Admin-only. The App is chosen with `appId` (required, 422, when the agent has more than one App; 404 when the agent has no such App). Uses the App's stored client id when set; otherwise resolves the stored GH_APP_SLUG and looks the App up through the public GET /apps/{slug} to get its client id. Installs it on the org with the installer App. 422 for an agent with neither a stored client id nor a slug, and for a private App (not visible to the public lookup) with no stored client id; 409 when the installer App is not configured.",
9101
9122
  "parameters": [
9102
9123
  {
9103
9124
  "schema": {
@@ -9248,7 +9269,7 @@
9248
9269
  "github-enterprise"
9249
9270
  ],
9250
9271
  "summary": "Uninstall an agent's App from an organization",
9251
- "description": "Admin-only. Finds the agent App's installation on the org (client id, slug or app id) and deletes it with the installer App, removes that org's repos from the agent's repos, blocks the agent's open tasks and PRs on them through the open-work port (a port failure is a warning) and writes one audit row (uninstall:org). `preview=true` lists the repos and open work that would be affected and changes nothing. 404 when the App is not installed on the org; 422 when more than 10 repos would be removed without `confirmRemovals=true`; 502 (with a failed audit row) when GitHub refuses.",
9272
+ "description": "Admin-only. Finds the named App's installation on the org (`appId` is required when the agent has several Apps; the agent's other Apps' installations are untouched; matched by client id, slug or app id) and deletes it with the installer App, removes that org's repos from the agent's repos, blocks the agent's open tasks and PRs on them (both skipped when another App of the agent is still installed on the org) through the open-work port (a port failure is a warning) and writes one audit row (uninstall:org). `preview=true` lists the repos and open work that would be affected and changes nothing. 404 when the App is not installed on the org; 422 when more than 10 repos would be removed without `confirmRemovals=true`; 502 (with a failed audit row) when GitHub refuses.",
9252
9273
  "parameters": [
9253
9274
  {
9254
9275
  "schema": {
@@ -9281,6 +9302,18 @@
9281
9302
  "name": "agentId",
9282
9303
  "in": "query"
9283
9304
  },
9305
+ {
9306
+ "schema": {
9307
+ "type": "string",
9308
+ "minLength": 1,
9309
+ "example": "12345",
9310
+ "description": "Which of the agent's GitHub Apps to uninstall: the App's numeric id (or its AgentGitHubApp row id). Required when the agent has more than one App; defaults to the only App otherwise."
9311
+ },
9312
+ "required": false,
9313
+ "description": "Which of the agent's GitHub Apps to uninstall: the App's numeric id (or its AgentGitHubApp row id). Required when the agent has more than one App; defaults to the only App otherwise.",
9314
+ "name": "appId",
9315
+ "in": "query"
9316
+ },
9284
9317
  {
9285
9318
  "schema": {
9286
9319
  "type": "string",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-admin",
3
- "version": "1.132.0",
3
+ "version": "1.134.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@anthropic-ai/sdk": "0.137.0",
48
- "@app-vitals/agent-lib": "1.132.0",
48
+ "@app-vitals/agent-lib": "1.134.0",
49
49
  "@hono/zod-openapi": "^1.0.0",
50
50
  "@prisma/adapter-pg": "^7.10.0",
51
51
  "@prisma/client": "^7.10.0",
@@ -24,6 +24,7 @@ import {
24
24
  renderUncoveredBadge,
25
25
  uncoveredRepos,
26
26
  } from "./admin-ui-installation-repos-pages.ts";
27
+ import { renderInfoTip } from "./admin-ui-info-tip.ts";
27
28
  import { renderHelpTip } from "./admin-ui-help-catalogue.ts";
28
29
  import { renderAdminPage } from "./admin-ui-layout.ts";
29
30
  import { renderSettingsLayout } from "./admin-ui-settings-layout.ts";
@@ -39,6 +40,7 @@ import {
39
40
  } from "./agent-github-apps.ts";
40
41
  import { isAudioFilename } from "./attachment-validation.ts";
41
42
  import { parseChatMarkers } from "./chat-markers.ts";
43
+ import type { CronHelpLookup } from "./cron-help.ts";
42
44
  import type { GithubAppsState } from "./github-apps-state.ts";
43
45
  import type {
44
46
  ChatMessage,
@@ -1335,6 +1337,12 @@ export function renderAgentDetailPage(
1335
1337
  * /admin/agents/:id/queue-activity; absent/false omits the link.
1336
1338
  */
1337
1339
  queueActivityLinks?: boolean;
1340
+ /**
1341
+ * Per-cron help for the Cron Jobs card (cron-help.ts): a cron whose name
1342
+ * resolves gets an info tooltip beside its label. Absent, or no entry for
1343
+ * a name, renders that row without one.
1344
+ */
1345
+ cronHelp?: CronHelpLookup;
1338
1346
  /** PMK-1.5: remote AgentMarketplace rows for the Marketplaces card. */
1339
1347
  marketplaces?: MarketplaceItem[];
1340
1348
  /**
@@ -1589,6 +1597,23 @@ export function renderAgentDetailPage(
1589
1597
  }`;
1590
1598
  }
1591
1599
 
1600
+ /**
1601
+ * The info tooltip for a cron that has help (opts.cronHelp), or "". Only
1602
+ * named system crons are looked up: a custom cron that happens to share a
1603
+ * system cron's name must not borrow its explanation.
1604
+ */
1605
+ function renderCronHelpTip(c: CronJobItem): string {
1606
+ if (!c.system || !c.name) return "";
1607
+ const help = opts?.cronHelp?.(c.name);
1608
+ if (!help) return "";
1609
+ return ` ${renderInfoTip({
1610
+ id: `cron-help-${c.id}`,
1611
+ label: c.name,
1612
+ summary: help.summary,
1613
+ docsHref: help.docsHref,
1614
+ })}`;
1615
+ }
1616
+
1592
1617
  /**
1593
1618
  * Renders the nested "Phases of <parent>" block for a top-level cron's
1594
1619
  * children (e.g. shipwright-loop's dev-task/review/patch/deploy phases).
@@ -1608,7 +1633,7 @@ export function renderAgentDetailPage(
1608
1633
  ? cronRunOutcomeLabel(child.lastRun)
1609
1634
  : null;
1610
1635
  return `<tr>
1611
- <td style="padding-left:20px">${escapeHtml(child.name ? `${child.name}: ${child.prompt}` : child.prompt)}</td>
1636
+ <td style="padding-left:20px">${escapeHtml(child.name ? `${child.name}: ${child.prompt}` : child.prompt)}${renderCronHelpTip(child)}</td>
1612
1637
  <td class="mono">${escapeHtml(child.schedule)}</td>
1613
1638
  <td><span class="badge ${child.enabled ? "badge-green" : "badge-gray"}">${child.enabled ? "enabled" : "disabled"}</span></td>
1614
1639
  <td style="font-size:11px">${
@@ -1677,7 +1702,7 @@ export function renderAgentDetailPage(
1677
1702
 
1678
1703
  return `<tr>
1679
1704
  <td class="mono">${escapeHtml(c.schedule)}</td>
1680
- <td style="max-width:280px;overflow:hidden;text-overflow:ellipsis">${escapeHtml(c.name ? `${c.name}: ${c.prompt}` : c.prompt)}${sourceBadge(c.system ? undefined : c.source)}</td>
1705
+ <td style="max-width:280px;overflow-wrap:anywhere">${escapeHtml(c.name ? `${c.name}: ${c.prompt}` : c.prompt)}${renderCronHelpTip(c)}${sourceBadge(c.system ? undefined : c.source)}</td>
1681
1706
  <td class="mono" style="font-size:11px;color:var(--vos-text-muted);max-width:170px;overflow:hidden;text-overflow:ellipsis">${c.preCheck ? escapeHtml(c.preCheck) : "—"}</td>
1682
1707
  <td>${c.channel ? escapeHtml(c.channel) : c.user ? escapeHtml(c.user) : "—"}</td>
1683
1708
  <td><span class="badge ${c.enabled ? "badge-green" : "badge-gray"}">${c.enabled ? "enabled" : "disabled"}</span></td>
@@ -4834,3 +4834,76 @@ describe("deriveAgentSetupSteps with the GitHub App table (multi-github-apps 1.5
4834
4834
  );
4835
4835
  });
4836
4836
  });
4837
+
4838
+ // ─── renderAgentDetailPage — per-cron help tooltips ──────────────────────────
4839
+
4840
+ describe("renderAgentDetailPage — cron help tooltips", () => {
4841
+ const HELP = {
4842
+ summary: "Checks health <once> an hour.",
4843
+ docsHref: "https://shipwrightharness.com/docs/widgets#health-check",
4844
+ };
4845
+ const PHASE_HELP = {
4846
+ summary: "Runs the build phase.",
4847
+ docsHref: "https://shipwrightharness.com/docs/widgets#build-phase",
4848
+ };
4849
+ const PHASE: CronJobItem = {
4850
+ ...SYSTEM_CRON,
4851
+ id: "cron-phase-1",
4852
+ name: "build-phase",
4853
+ prompt: "/run build",
4854
+ parentCronId: SYSTEM_CRON.id,
4855
+ };
4856
+ const lookup = (name: string) =>
4857
+ ({ "health-check": HELP, "build-phase": PHASE_HELP })[name];
4858
+
4859
+ function render(
4860
+ crons: CronJobItem[],
4861
+ cronHelp?: (name: string) => typeof HELP | undefined,
4862
+ ): string {
4863
+ return renderAgentDetailSection(
4864
+ AGENT,
4865
+ {},
4866
+ crons,
4867
+ [],
4868
+ [],
4869
+ [],
4870
+ [],
4871
+ USER_NAME,
4872
+ true,
4873
+ { timezone: "UTC", section: "automation", cronHelp },
4874
+ );
4875
+ }
4876
+ const tipCount = (html: string) =>
4877
+ html.split('class="info-tip-btn"').length - 1;
4878
+
4879
+ test("a system row and a phase row each get exactly one tooltip", () => {
4880
+ const html = render([SYSTEM_CRON, PHASE], lookup);
4881
+ expect(tipCount(html)).toBe(2);
4882
+ expect(html).toContain('aria-label="About health-check"');
4883
+ expect(html).toContain('id="cron-help-cron-sys-1"');
4884
+ expect(html).toContain("Checks health &lt;once&gt; an hour.");
4885
+ expect(html).toContain(
4886
+ `<a href="${HELP.docsHref}" target="_blank" rel="noopener">Learn more →</a>`,
4887
+ );
4888
+ expect(html).toContain('aria-label="About build-phase"');
4889
+ expect(html).toContain('id="cron-help-cron-phase-1"');
4890
+ expect(html).toContain(PHASE_HELP.docsHref);
4891
+ });
4892
+
4893
+ test("no lookup leaves the rows without tooltips", () => {
4894
+ expect(tipCount(render([SYSTEM_CRON, PHASE]))).toBe(0);
4895
+ });
4896
+
4897
+ test("a cron with no entry gets no tooltip", () => {
4898
+ const html = render([{ ...SYSTEM_CRON, name: "other-cron" }], lookup);
4899
+ expect(tipCount(html)).toBe(0);
4900
+ });
4901
+
4902
+ test("a custom cron never borrows a system cron's help", () => {
4903
+ const html = render(
4904
+ [{ ...CUSTOM_CRON, name: "health-check", source: "custom" }],
4905
+ lookup,
4906
+ );
4907
+ expect(tipCount(html)).toBe(0);
4908
+ });
4909
+ });
package/src/admin-ui.ts CHANGED
@@ -210,6 +210,7 @@ import {
210
210
  SlackProvisioningService,
211
211
  } from "./slack-provisioning-service.ts";
212
212
  import type { SpecialtyDefaultsResolver } from "./specialty-defaults.ts";
213
+ import { buildCronHelpLookup } from "./cron-help.ts";
213
214
  import {
214
215
  type SpecialtyTypeResolver,
215
216
  SpecialtyTypes,
@@ -2972,6 +2973,9 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
2972
2973
  extensionCardsHtml: cards.header,
2973
2974
  configurationCardsHtml: cards.configuration,
2974
2975
  queueActivityLinks: deps.queueActivityLinks,
2976
+ cronHelp: buildCronHelpLookup(
2977
+ specialtyDefaults?.(agentDetail.specialty),
2978
+ ),
2975
2979
  marketplaces,
2976
2980
  ...(appsState ? { githubAppsState: appsState } : {}),
2977
2981
  slackConfigTokenStored: await hasStoredSlackConfigToken(
@@ -4008,6 +4012,9 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
4008
4012
  extensionCardsHtml: cards.header,
4009
4013
  configurationCardsHtml: cards.configuration,
4010
4014
  queueActivityLinks: deps.queueActivityLinks,
4015
+ cronHelp: buildCronHelpLookup(
4016
+ specialtyDefaults?.(agentDetail.specialty),
4017
+ ),
4011
4018
  marketplaces,
4012
4019
  ...(await githubAppsState(c).then((st) =>
4013
4020
  st ? { githubAppsState: st } : {},
@@ -50,6 +50,26 @@ describeOrSkip("AgentGitHubInstallationsService (integration)", () => {
50
50
  await prisma.$disconnect();
51
51
  });
52
52
 
53
+ it("round-trips appId, slug and shadowed state through the real DB", async () => {
54
+ const agentId = await createAgent(prisma);
55
+ const installations = [
56
+ {
57
+ owner: "acme",
58
+ installationId: 1,
59
+ state: "ok",
60
+ appId: "100",
61
+ slug: "a",
62
+ },
63
+ { owner: "acme", installationId: 2, state: "shadowed", appId: "200" },
64
+ { owner: "legacy", installationId: 3, state: "ok" },
65
+ ];
66
+ await service.push(agentId, {
67
+ reportedAt: new Date("2026-01-01T00:00:00.000Z"),
68
+ installations,
69
+ });
70
+ expect((await service.get(agentId))?.installations).toEqual(installations);
71
+ });
72
+
53
73
  it("push() creates a snapshot and get() reads it back", async () => {
54
74
  const agentId = await createAgent(prisma);
55
75
  const reportedAt = new Date("2026-01-15T12:00:00.000Z");
@@ -1269,6 +1269,39 @@ describe("admin API — GitHub installations snapshot", () => {
1269
1269
  expect(body.snapshot.reportedAt).toBe(BODY.reportedAt);
1270
1270
  });
1271
1271
 
1272
+ it("stores appId, slug and shadowed state per app+owner and returns them", async () => {
1273
+ const app = createAdminApp(makeMockDeps());
1274
+ const installations = [
1275
+ {
1276
+ owner: "acme",
1277
+ installationId: 1,
1278
+ state: "ok",
1279
+ appId: "100",
1280
+ slug: "a",
1281
+ },
1282
+ { owner: "acme", installationId: 2, state: "shadowed", appId: "200" },
1283
+ ];
1284
+ const res = await put(app, { ...BODY, installations });
1285
+ expect(res.status).toBe(200);
1286
+ expect((await res.json()).snapshot.installations).toEqual(installations);
1287
+ });
1288
+
1289
+ it("rejects two rows for the same app and owner (400)", async () => {
1290
+ const app = createAdminApp(makeMockDeps());
1291
+ const row = { owner: "Acme", installationId: 1, state: "ok", appId: "100" };
1292
+ const res = await put(app, {
1293
+ ...BODY,
1294
+ installations: [row, { ...row, owner: "acme", installationId: 2 }],
1295
+ });
1296
+ expect(res.status).toBe(400);
1297
+ });
1298
+
1299
+ it("accepts rows without appId (older agents, legacy app)", async () => {
1300
+ const app = createAdminApp(makeMockDeps());
1301
+ const res = await put(app, BODY);
1302
+ expect(res.status).toBe(200);
1303
+ });
1304
+
1272
1305
  it("a second PUT replaces the first, dropping a removed installation", async () => {
1273
1306
  const app = createAdminApp(makeMockDeps());
1274
1307
  await put(app, BODY);
@@ -0,0 +1,60 @@
1
+ /**
2
+ * admin/src/cron-help.ts
3
+ *
4
+ * Per-cron help for the agent detail page's Cron Jobs card. A specialty's
5
+ * default crons (specialty-defaults.ts) may each carry a short summary and a
6
+ * docs link; the card shows them in the shared info tooltip next to the cron's
7
+ * name. The wording belongs to whoever supplies the defaults, never to the
8
+ * platform: a cron with no help entry renders exactly as before.
9
+ */
10
+
11
+ import { ADMIN_DOCS_BASE_URL } from "./admin-ui-info-tip.ts";
12
+ import type { SpecialtyDefaults } from "./specialty-defaults.ts";
13
+
14
+ /** Help shown for one cron: one or two sentences plus a docs link. */
15
+ export interface CronHelp {
16
+ /** Plain-text summary shown in the tooltip. */
17
+ summary: string;
18
+ /** Absolute docs URL; must start with ADMIN_DOCS_BASE_URL. */
19
+ docsHref: string;
20
+ }
21
+
22
+ /** Longest summary a tooltip shows; the same limit the help catalogue uses. */
23
+ export const CRON_HELP_MAX_SUMMARY_LENGTH = 280;
24
+
25
+ /** Resolves a cron's name to its help, or undefined when there is none. */
26
+ export type CronHelpLookup = (cronName: string) => CronHelp | undefined;
27
+
28
+ /** True when the help is safe to show: a real summary and a docs-site link. */
29
+ export function isValidCronHelp(help: unknown): help is CronHelp {
30
+ if (typeof help !== "object" || help === null) return false;
31
+ const { summary, docsHref } = help as Record<string, unknown>;
32
+ if (typeof summary !== "string" || typeof docsHref !== "string") return false;
33
+ const trimmed = summary.trim();
34
+ return (
35
+ trimmed.length > 0 &&
36
+ trimmed.length <= CRON_HELP_MAX_SUMMARY_LENGTH &&
37
+ docsHref.startsWith(ADMIN_DOCS_BASE_URL)
38
+ );
39
+ }
40
+
41
+ /**
42
+ * Builds the lookup for one specialty's defaults. Invalid entries (empty or
43
+ * over-long summary, a link outside the docs site) are dropped so a bad entry
44
+ * hides its tooltip instead of rendering a broken one. Names are matched
45
+ * exactly; a Map keeps prototype keys such as "constructor" from resolving.
46
+ */
47
+ export function buildCronHelpLookup(
48
+ defaults: SpecialtyDefaults | undefined,
49
+ ): CronHelpLookup {
50
+ const byName = new Map<string, CronHelp>();
51
+ for (const cron of defaults?.crons ?? []) {
52
+ if (isValidCronHelp(cron.help)) {
53
+ byName.set(cron.name, {
54
+ summary: cron.help.summary.trim(),
55
+ docsHref: cron.help.docsHref,
56
+ });
57
+ }
58
+ }
59
+ return (cronName) => byName.get(cronName);
60
+ }
@@ -0,0 +1,101 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { ADMIN_DOCS_BASE_URL } from "./admin-ui-info-tip.ts";
3
+ import {
4
+ buildCronHelpLookup,
5
+ CRON_HELP_MAX_SUMMARY_LENGTH,
6
+ isValidCronHelp,
7
+ } from "./cron-help.ts";
8
+ import type { SpecialtyDefaultCron } from "./specialty-defaults.ts";
9
+
10
+ const cron = (
11
+ name: string,
12
+ help?: SpecialtyDefaultCron["help"],
13
+ ): SpecialtyDefaultCron => ({
14
+ name,
15
+ schedule: "* * * * *",
16
+ prompt: `/run ${name}`,
17
+ ...(help ? { help } : {}),
18
+ });
19
+
20
+ const good = {
21
+ summary: "Builds the selected task.",
22
+ docsHref: `${ADMIN_DOCS_BASE_URL}widgets#build`,
23
+ };
24
+
25
+ describe("isValidCronHelp", () => {
26
+ test("accepts a summary with a docs-site link", () => {
27
+ expect(isValidCronHelp(good)).toBe(true);
28
+ });
29
+
30
+ test("rejects a blank or over-long summary", () => {
31
+ expect(isValidCronHelp({ ...good, summary: " " })).toBe(false);
32
+ expect(
33
+ isValidCronHelp({
34
+ ...good,
35
+ summary: "x".repeat(CRON_HELP_MAX_SUMMARY_LENGTH + 1),
36
+ }),
37
+ ).toBe(false);
38
+ expect(
39
+ isValidCronHelp({
40
+ ...good,
41
+ summary: "x".repeat(CRON_HELP_MAX_SUMMARY_LENGTH),
42
+ }),
43
+ ).toBe(true);
44
+ });
45
+
46
+ test("rejects a link outside the docs site", () => {
47
+ expect(
48
+ isValidCronHelp({ ...good, docsHref: "https://example.com/docs/x" }),
49
+ ).toBe(false);
50
+ expect(isValidCronHelp({ ...good, docsHref: "javascript:alert(1)" })).toBe(
51
+ false,
52
+ );
53
+ });
54
+
55
+ test("rejects values that are not help objects", () => {
56
+ for (const value of [undefined, null, "text", 3, {}, { summary: "x" }]) {
57
+ expect(isValidCronHelp(value)).toBe(false);
58
+ }
59
+ expect(isValidCronHelp({ summary: 1, docsHref: good.docsHref })).toBe(
60
+ false,
61
+ );
62
+ });
63
+ });
64
+
65
+ describe("buildCronHelpLookup", () => {
66
+ test("resolves a cron by exact name and trims the summary", () => {
67
+ const lookup = buildCronHelpLookup({
68
+ crons: [cron("build", { ...good, summary: " Builds it. " })],
69
+ });
70
+ expect(lookup("build")).toEqual({
71
+ summary: "Builds it.",
72
+ docsHref: good.docsHref,
73
+ });
74
+ expect(lookup("Build")).toBeUndefined();
75
+ });
76
+
77
+ test("returns nothing for crons without help or with invalid help", () => {
78
+ const lookup = buildCronHelpLookup({
79
+ crons: [
80
+ cron("plain"),
81
+ cron("blank", { ...good, summary: "" }),
82
+ cron("offsite", { ...good, docsHref: "https://example.com/x" }),
83
+ ],
84
+ });
85
+ expect(lookup("plain")).toBeUndefined();
86
+ expect(lookup("blank")).toBeUndefined();
87
+ expect(lookup("offsite")).toBeUndefined();
88
+ });
89
+
90
+ test("returns nothing for unknown names and prototype keys", () => {
91
+ const lookup = buildCronHelpLookup({ crons: [cron("build", good)] });
92
+ expect(lookup("no-such-cron")).toBeUndefined();
93
+ expect(lookup("constructor")).toBeUndefined();
94
+ expect(lookup("__proto__")).toBeUndefined();
95
+ });
96
+
97
+ test("is empty when the specialty supplies no defaults or no crons", () => {
98
+ expect(buildCronHelpLookup(undefined)("build")).toBeUndefined();
99
+ expect(buildCronHelpLookup({})("build")).toBeUndefined();
100
+ });
101
+ });
@@ -1603,5 +1603,94 @@
1603
1603
  "body": {
1604
1604
  "message": "Not Found"
1605
1605
  }
1606
+ },
1607
+ "org_installations_two_apps": {
1608
+ "status": 200,
1609
+ "body": [
1610
+ {
1611
+ "id": 501,
1612
+ "client_id": "Iv1.targetapp0001",
1613
+ "account": {
1614
+ "login": "acme-eng",
1615
+ "id": 5511,
1616
+ "type": "Organization"
1617
+ },
1618
+ "repository_selection": "all",
1619
+ "access_tokens_url": "https://api.github.com/app/installations/501/access_tokens",
1620
+ "repositories_url": "https://api.github.com/installation/repositories",
1621
+ "html_url": "https://github.com/organizations/acme-eng/settings/installations/501",
1622
+ "app_id": 777,
1623
+ "app_slug": "target-app",
1624
+ "target_id": 5511,
1625
+ "target_type": "Organization",
1626
+ "permissions": {
1627
+ "contents": "write",
1628
+ "metadata": "read"
1629
+ },
1630
+ "events": [],
1631
+ "created_at": "2026-10-01T00:00:00Z",
1632
+ "updated_at": "2026-10-01T00:00:00Z",
1633
+ "single_file_name": null,
1634
+ "suspended_at": null,
1635
+ "suspended_by": null
1636
+ },
1637
+ {
1638
+ "id": 503,
1639
+ "client_id": "Iv1.secondapp0002",
1640
+ "account": {
1641
+ "login": "acme-eng",
1642
+ "id": 5513,
1643
+ "type": "Organization"
1644
+ },
1645
+ "repository_selection": "all",
1646
+ "access_tokens_url": "https://api.github.com/app/installations/503/access_tokens",
1647
+ "repositories_url": "https://api.github.com/installation/repositories",
1648
+ "html_url": "https://github.com/organizations/acme-eng/settings/installations/503",
1649
+ "app_id": 888,
1650
+ "app_slug": "second-app",
1651
+ "target_id": 5513,
1652
+ "target_type": "Organization",
1653
+ "permissions": {
1654
+ "contents": "write",
1655
+ "metadata": "read"
1656
+ },
1657
+ "events": [],
1658
+ "created_at": "2026-10-01T00:00:00Z",
1659
+ "updated_at": "2026-10-01T00:00:00Z",
1660
+ "single_file_name": null,
1661
+ "suspended_at": null,
1662
+ "suspended_by": null
1663
+ }
1664
+ ]
1665
+ },
1666
+ "install_second_created": {
1667
+ "status": 201,
1668
+ "body": {
1669
+ "id": 602,
1670
+ "client_id": "Iv1.secondapp0002",
1671
+ "account": {
1672
+ "login": "acme-eng",
1673
+ "id": 5612,
1674
+ "type": "Organization"
1675
+ },
1676
+ "repository_selection": "all",
1677
+ "access_tokens_url": "https://api.github.com/app/installations/602/access_tokens",
1678
+ "repositories_url": "https://api.github.com/installation/repositories",
1679
+ "html_url": "https://github.com/organizations/acme-eng/settings/installations/602",
1680
+ "app_id": 888,
1681
+ "app_slug": "second-app",
1682
+ "target_id": 5612,
1683
+ "target_type": "Organization",
1684
+ "permissions": {
1685
+ "contents": "write",
1686
+ "metadata": "read"
1687
+ },
1688
+ "events": [],
1689
+ "created_at": "2026-10-01T00:00:00Z",
1690
+ "updated_at": "2026-10-01T00:00:00Z",
1691
+ "single_file_name": null,
1692
+ "suspended_at": null,
1693
+ "suspended_by": null
1694
+ }
1606
1695
  }
1607
1696
  }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * admin/src/github-enterprise-api-apps.unit.test.ts
3
+ * Unit tests for how install/uninstall pick the agent's App: several Apps need
4
+ * an appId, one defaults, an unknown appId is 404. The installer App is absent
5
+ * for the failing cases so a wrong resolution would surface as a 409, and the
6
+ * fetch seam throws so no case can reach GitHub.
7
+ */
8
+
9
+ import { describe, expect, it } from "bun:test";
10
+ import { parseAdminApiKeys } from "./api-auth.ts";
11
+ import {
12
+ createGithubEnterpriseApp,
13
+ type GithubEnterpriseApiDeps,
14
+ } from "./github-enterprise-api.ts";
15
+
16
+ const row = (id: string, appId: string) => ({
17
+ id,
18
+ appId,
19
+ slug: `app-${appId}`,
20
+ clientId: null,
21
+ });
22
+
23
+ function build(apps: ReturnType<typeof row>[]) {
24
+ const deps = {
25
+ appService: {
26
+ get: async () => ({ role: "installer" }),
27
+ getPrivateKey: async () => null,
28
+ },
29
+ agentService: { getSummary: async (id: string) => ({ id }) },
30
+ agentEnvService: { getByAgentId: async () => null },
31
+ agentGitHubAppService: { list: async () => apps },
32
+ uninstall: {
33
+ agents: { get: async () => null, setRepos: async () => {} },
34
+ audit: { write: async () => "a" },
35
+ },
36
+ sessionSecret: "test-secret-32chars-for-ghe-api!!",
37
+ adminApiKeys: parseAdminApiKeys("root:tok-admin:*"),
38
+ agentTokenService: { validate: async () => null },
39
+ fetchFn: (async () => {
40
+ throw new Error("network");
41
+ }) as unknown as typeof fetch,
42
+ } as unknown as GithubEnterpriseApiDeps;
43
+ return createGithubEnterpriseApp(deps);
44
+ }
45
+
46
+ const H = { Authorization: "Bearer tok-admin" };
47
+ const install = (app: ReturnType<typeof build>, body: object) =>
48
+ app.request("/github-enterprise/orgs/o/install", {
49
+ method: "POST",
50
+ headers: { ...H, "Content-Type": "application/json" },
51
+ body: JSON.stringify(body),
52
+ });
53
+ const uninstall = (app: ReturnType<typeof build>, q: string) =>
54
+ app.request(`/github-enterprise/orgs/o/install?agentId=a${q}`, {
55
+ method: "DELETE",
56
+ headers: H,
57
+ });
58
+
59
+ describe("agent App selection", () => {
60
+ const two = [row("r1", "1"), row("r2", "2")];
61
+
62
+ it("422 without appId when the agent has several Apps", async () => {
63
+ const app = build(two);
64
+ expect((await install(app, { agentId: "a" })).status).toBe(422);
65
+ expect((await uninstall(app, "")).status).toBe(422);
66
+ });
67
+
68
+ it("404 for an appId the agent does not have", async () => {
69
+ const app = build(two);
70
+ expect((await install(app, { agentId: "a", appId: "9" })).status).toBe(404);
71
+ expect((await uninstall(app, "&appId=9")).status).toBe(404);
72
+ });
73
+
74
+ it("a named or only App passes selection and reaches the lookup", async () => {
75
+ // Past selection the missing client id leads to the public lookup, which
76
+ // the throwing fetch turns into 504 (never 404 or the "pass appId" 422).
77
+ const named = await install(build(two), { agentId: "a", appId: "2" });
78
+ expect(named.status).toBe(504);
79
+ const only = await install(build([row("r1", "1")]), { agentId: "a" });
80
+ expect(only.status).toBe(504);
81
+ });
82
+ });