@app-vitals/agent-admin 1.120.1 → 1.121.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 (73) hide show
  1. package/package.json +2 -2
  2. package/src/account-repo-lookup-api.integration.test.ts +1 -1
  3. package/src/admin-boot-config.ts +2 -2
  4. package/src/admin-boot-config.unit.test.ts +1 -1
  5. package/src/admin-boot.ts +1 -1
  6. package/src/admin-ui-account.ts +2 -2
  7. package/src/admin-ui-agent-template.smoke.test.ts +1 -1
  8. package/src/admin-ui-github-identity-pages.ts +2 -2
  9. package/src/admin-ui-push-test.smoke.test.ts +7 -5
  10. package/src/admin-ui-styles.unit.test.ts +3 -1
  11. package/src/admin-ui-templates-pages.ts +5 -5
  12. package/src/agent-cron-run-stats.integration.test.ts +11 -2
  13. package/src/agent-deletion-checklist.unit.test.ts +1 -1
  14. package/src/agent-manifest.unit.test.ts +3 -3
  15. package/src/agent-marketplaces-api.integration.test.ts +22 -1
  16. package/src/agent-members.integration.test.ts +1 -1
  17. package/src/agent-pod-labels.unit.test.ts +2 -2
  18. package/src/agent-provisioner.unit.test.ts +4 -4
  19. package/src/agent-setup.unit.test.ts +14 -3
  20. package/src/agent-template-items.ts +1 -1
  21. package/src/agent-templates.ts +1 -1
  22. package/src/agent-tools-token.integration.test.ts +3 -3
  23. package/src/api-auth.ts +11 -4
  24. package/src/brand-tokens.json +23 -4
  25. package/src/brand-tokens.unit.test.ts +11 -4
  26. package/src/chat-credential-config.unit.test.ts +6 -2
  27. package/src/chat-markers.unit.test.ts +5 -2
  28. package/src/cron-run-now.smoke.test.ts +1 -1
  29. package/src/cron-run-now.ts +1 -1
  30. package/src/errors.unit.test.ts +7 -4
  31. package/src/fixtures/github-agent-installation-cassette.json +35 -5
  32. package/src/github-access-backfill.ts +1 -1
  33. package/src/github-access-backfill.unit.test.ts +1 -1
  34. package/src/github-agent-installation-crawler.integration.test.ts +29 -12
  35. package/src/github-agent-installation-crawler.ts +2 -2
  36. package/src/github-agent-installation-crawler.unit.test.ts +28 -7
  37. package/src/github-app-api.ts +1 -1
  38. package/src/github-app-jwt.unit.test.ts +2 -1
  39. package/src/github-cache-roundtrip.integration.test.ts +4 -4
  40. package/src/github-enterprise-api.integration.test.ts +4 -4
  41. package/src/github-enterprise-api.ts +6 -6
  42. package/src/github-enterprise-client-page.unit.test.ts +18 -6
  43. package/src/github-enterprise-client.integration.test.ts +97 -32
  44. package/src/github-enterprise-client.ts +81 -22
  45. package/src/github-enterprise-client.unit.test.ts +1 -1
  46. package/src/github-enterprise-warnings.unit.test.ts +19 -6
  47. package/src/github-installation-selection.integration.test.ts +4 -1
  48. package/src/github-installation-wiring.unit.test.ts +1 -1
  49. package/src/github-repo-refresh-discovery.unit.test.ts +1 -1
  50. package/src/github-repo-refresher.unit.test.ts +11 -5
  51. package/src/github-sync-cache.integration.test.ts +1 -1
  52. package/src/github-sync-cached-access.ts +1 -1
  53. package/src/github-sync-reverify.unit.test.ts +1 -1
  54. package/src/github-sync-snapshot-refresh.integration.test.ts +1 -1
  55. package/src/github-sync.unit.test.ts +6 -6
  56. package/src/installation-ports-fixture.integration.test.ts +2 -2
  57. package/src/installation-repos-service.ts +5 -5
  58. package/src/kubernetes-client.integration.test.ts +1 -2
  59. package/src/platform-routes.ts +1 -1
  60. package/src/push-content.unit.test.ts +2 -2
  61. package/src/push-sender.unit.test.ts +1 -1
  62. package/src/push-service.integration.test.ts +1 -1
  63. package/src/pwa-icons.unit.test.ts +1 -1
  64. package/src/slack-config-token-resolve.unit.test.ts +25 -7
  65. package/src/slack-provisioning-client.integration.test.ts +10 -8
  66. package/src/slack-provisioning-client.ts +2 -6
  67. package/src/tools-token-policy.integration.test.ts +68 -6
  68. package/src/tools-token-policy.smoke.test.ts +22 -5
  69. package/src/tools-token-policy.ts +100 -8
  70. package/src/tools-token-policy.unit.test.ts +137 -4
  71. package/src/trial-expiry-sweeper.unit.test.ts +1 -1
  72. package/src/user-prefs.integration.test.ts +1 -1
  73. package/src/user-repo-access-resolver.unit.test.ts +1 -1
@@ -2,23 +2,53 @@
2
2
  "_comment": "Hand-authored from GitHub's enterprise organization-installations OpenAPI description (nothing recorded live). Repo list pages are generated in the test: only the routes, headers and status codes live here.",
3
3
  "enterprise_installation": {
4
4
  "status": 200,
5
- "body": { "id": 4242, "app_id": 12345, "app_slug": "shipwright-installer", "repository_selection": "all", "target_type": "Enterprise" }
5
+ "body": {
6
+ "id": 4242,
7
+ "app_id": 12345,
8
+ "app_slug": "shipwright-installer",
9
+ "repository_selection": "all",
10
+ "target_type": "Enterprise"
11
+ }
6
12
  },
7
13
  "installer_token": {
8
14
  "status": 201,
9
- "body": { "token": "ghs_cassetteInstallationToken0000000000", "expires_at": "2026-11-20T13:00:00Z" }
15
+ "body": {
16
+ "token": "ghs_cassetteInstallationToken0000000000",
17
+ "expires_at": "2026-11-20T13:00:00Z"
18
+ }
10
19
  },
11
20
  "org_installations_agent": {
12
21
  "status": 200,
13
22
  "body": [
14
- { "id": 900, "client_id": "Iv1.other", "app_id": 111, "app_slug": "other-app", "account": { "login": "acme-eng" }, "repository_selection": "all" },
15
- { "id": 501, "client_id": "Iv1.agentapp0001", "app_id": 777, "app_slug": "doc-agent", "account": { "login": "acme-eng" }, "repository_selection": "selected" }
23
+ {
24
+ "id": 900,
25
+ "client_id": "Iv1.other",
26
+ "app_id": 111,
27
+ "app_slug": "other-app",
28
+ "account": { "login": "acme-eng" },
29
+ "repository_selection": "all"
30
+ },
31
+ {
32
+ "id": 501,
33
+ "client_id": "Iv1.agentapp0001",
34
+ "app_id": 777,
35
+ "app_slug": "doc-agent",
36
+ "account": { "login": "acme-eng" },
37
+ "repository_selection": "selected"
38
+ }
16
39
  ]
17
40
  },
18
41
  "org_installations_no_agent": {
19
42
  "status": 200,
20
43
  "body": [
21
- { "id": 900, "client_id": "Iv1.other", "app_id": 111, "app_slug": "other-app", "account": { "login": "beta-eng" }, "repository_selection": "all" }
44
+ {
45
+ "id": 900,
46
+ "client_id": "Iv1.other",
47
+ "app_id": 111,
48
+ "app_slug": "other-app",
49
+ "account": { "login": "beta-eng" },
50
+ "repository_selection": "all"
51
+ }
22
52
  ]
23
53
  },
24
54
  "repos_rate_limited": {
@@ -25,8 +25,8 @@ import { GithubEnterpriseError } from "./github-enterprise-client.ts";
25
25
  import {
26
26
  GithubLookupRateLimitError,
27
27
  type LookupRateLimit,
28
- rateLimitResetAt,
29
28
  type RepoRole,
29
+ rateLimitResetAt,
30
30
  } from "./github-lookup-client.ts";
31
31
  import type {
32
32
  AccessInput,
@@ -5,7 +5,6 @@
5
5
  */
6
6
 
7
7
  import { describe, expect, it } from "bun:test";
8
- import { GithubEnterpriseError } from "./github-enterprise-client.ts";
9
8
  import {
10
9
  type AccessBackfillStore,
11
10
  type AccessProbe,
@@ -14,6 +13,7 @@ import {
14
13
  buildWorkList,
15
14
  defaultAccessBackoffMs,
16
15
  } from "./github-access-backfill.ts";
16
+ import { GithubEnterpriseError } from "./github-enterprise-client.ts";
17
17
  import {
18
18
  GithubLookupRateLimitError,
19
19
  type LookupRateLimit,
@@ -12,9 +12,7 @@
12
12
  import { describe, expect, it } from "bun:test";
13
13
  import { generateKeyPairSync } from "node:crypto";
14
14
  import { readFileSync } from "node:fs";
15
- import {
16
- crawlAgentInstallation,
17
- } from "./github-agent-installation-crawler.ts";
15
+ import { crawlAgentInstallation } from "./github-agent-installation-crawler.ts";
18
16
  import { lazyInstallerClient } from "./github-installation-wiring.ts";
19
17
  import type {
20
18
  CachedRepoInput,
@@ -31,8 +29,10 @@ interface CassetteEntry {
31
29
 
32
30
  const cassette: Record<string, CassetteEntry> = JSON.parse(
33
31
  readFileSync(
34
- new URL("./fixtures/github-agent-installation-cassette.json", import.meta.url)
35
- .pathname,
32
+ new URL(
33
+ "./fixtures/github-agent-installation-cassette.json",
34
+ import.meta.url,
35
+ ).pathname,
36
36
  "utf-8",
37
37
  ),
38
38
  );
@@ -105,7 +105,11 @@ function repoPage(total: number, page: number): CassetteEntry {
105
105
  return {
106
106
  status: 200,
107
107
  ...(hasNext
108
- ? { headers: { link: `<https://ghe.test/x?page=${page + 1}>; rel="next"` } }
108
+ ? {
109
+ headers: {
110
+ link: `<https://ghe.test/x?page=${page + 1}>; rel="next"`,
111
+ },
112
+ }
109
113
  : {}),
110
114
  body: Array.from({ length: n }, (_, i) => ({
111
115
  id: start + i + 1,
@@ -127,9 +131,14 @@ function setup(opts: {
127
131
  const method = init?.method ?? "GET";
128
132
  paths.push(`${method} ${u.pathname}${u.search}`);
129
133
  let entry: CassetteEntry | undefined;
130
- if (u.pathname === `${ENT}/installation`) entry = cassette.enterprise_installation;
131
- else if (u.pathname === "/app/installations/4242/access_tokens") entry = cassette.installer_token;
132
- else if (u.pathname === `${ENT}/apps/organizations/acme-eng/installations` || u.pathname === `${ENT}/apps/organizations/beta-eng/installations`)
134
+ if (u.pathname === `${ENT}/installation`)
135
+ entry = cassette.enterprise_installation;
136
+ else if (u.pathname === "/app/installations/4242/access_tokens")
137
+ entry = cassette.installer_token;
138
+ else if (
139
+ u.pathname === `${ENT}/apps/organizations/acme-eng/installations` ||
140
+ u.pathname === `${ENT}/apps/organizations/beta-eng/installations`
141
+ )
133
142
  entry = cassette[opts.installs];
134
143
  else if (u.pathname === REPOS_501) {
135
144
  const page = Number(u.searchParams.get("page"));
@@ -219,14 +228,20 @@ describe("crawlAgentInstallation through the installer client (integration)", ()
219
228
  store,
220
229
  clock,
221
230
  });
222
- expect(res).toEqual({ outcome: "not_installed", pagesFetched: 0, swept: 1 });
231
+ expect(res).toEqual({
232
+ outcome: "not_installed",
233
+ pagesFetched: 0,
234
+ swept: 1,
235
+ });
223
236
  expect(store.snap?.lastError).toBeNull();
224
237
  expect(store.snap?.completedAt).toEqual(NOW);
225
238
  expect(paths.some((p) => p.includes("/repositories"))).toBe(false);
226
239
  });
227
240
 
228
241
  it("never crawls an agent without GH_APP_ID", async () => {
229
- const { client, store, paths } = setup({ installs: "org_installations_agent" });
242
+ const { client, store, paths } = setup({
243
+ installs: "org_installations_agent",
244
+ });
230
245
  const res = await crawlAgentInstallation({
231
246
  agent: { accountId: "acc" },
232
247
  org: "acme-eng",
@@ -255,7 +270,9 @@ describe("crawlAgentInstallation through the installer client (integration)", ()
255
270
  });
256
271
  expect(res.outcome).toBe("rate_limited");
257
272
  expect(res.pagesFetched).toBe(1);
258
- expect(store.snap?.rateLimitResetAt).toEqual(new Date(NOW.getTime() + 30_000));
273
+ expect(store.snap?.rateLimitResetAt).toEqual(
274
+ new Date(NOW.getTime() + 30_000),
275
+ );
259
276
  expect(store.snap?.attempts).toBe(0);
260
277
  expect(store.snap?.completedAt).toBeNull();
261
278
  });
@@ -17,14 +17,14 @@ import {
17
17
  type PageSource,
18
18
  type RepoPage,
19
19
  } from "./github-repo-crawler.ts";
20
- import { identityOf } from "./installation-repos-service.ts";
21
20
  import {
22
- AppNotInstalledError,
23
21
  type AppIdentity,
22
+ AppNotInstalledError,
24
23
  type InstallationAgentRecord,
25
24
  type InstallationRepoClient,
26
25
  matchInstallation,
27
26
  } from "./installation-ports.ts";
27
+ import { identityOf } from "./installation-repos-service.ts";
28
28
 
29
29
  /**
30
30
  * SnapshotKey.accountId for an agent with no account (the deployment-wide
@@ -6,15 +6,15 @@
6
6
  */
7
7
 
8
8
  import { beforeEach, describe, expect, it } from "bun:test";
9
- import { GithubEnterpriseError } from "./github-enterprise-client.ts";
10
9
  import {
10
+ type AgentInstallationClient,
11
11
  agentInstallationPageSource,
12
12
  crawlAgentInstallation,
13
13
  DEPLOYMENT_WIDE_ACCOUNT_KEY,
14
14
  getAccessRowsAcrossKeys,
15
15
  lookupAccountKeys,
16
- type AgentInstallationClient,
17
16
  } from "./github-agent-installation-crawler.ts";
17
+ import { GithubEnterpriseError } from "./github-enterprise-client.ts";
18
18
  import type {
19
19
  CachedRepoInput,
20
20
  SnapshotKey,
@@ -163,7 +163,11 @@ describe("agentInstallationPageSource", () => {
163
163
 
164
164
  it("resolves the installation once and caches it", async () => {
165
165
  const { client, calls } = fakeClient();
166
- const src = agentInstallationPageSource({ client, org: "acme", appId: 777 });
166
+ const src = agentInstallationPageSource({
167
+ client,
168
+ org: "acme",
169
+ appId: 777,
170
+ });
167
171
  await src.fetchPage(1);
168
172
  await src.fetchPage(2);
169
173
  await src.resolveInstallationId();
@@ -188,7 +192,11 @@ describe("agentInstallationPageSource", () => {
188
192
 
189
193
  it("throws AppNotInstalledError when no installation matches", async () => {
190
194
  const { client } = fakeClient({ installs: [{ id: 1, appId: 5 }] });
191
- const src = agentInstallationPageSource({ client, org: "acme", appId: 777 });
195
+ const src = agentInstallationPageSource({
196
+ client,
197
+ org: "acme",
198
+ appId: 777,
199
+ });
192
200
  await expect(src.fetchPage(1)).rejects.toBeInstanceOf(AppNotInstalledError);
193
201
  });
194
202
  });
@@ -236,10 +244,19 @@ describe("crawlAgentInstallation", () => {
236
244
  const dup: AgentInstallationClient = {
237
245
  listOrgInstallations: client.listOrgInstallations,
238
246
  async listInstallationRepositoriesPage(org, id, page) {
239
- const res = await client.listInstallationRepositoriesPage(org, id, page);
247
+ const res = await client.listInstallationRepositoriesPage(
248
+ org,
249
+ id,
250
+ page,
251
+ );
240
252
  // page 2 repeats a row from page 1 and loses its own
241
253
  return page === 2
242
- ? { ...res, repos: [res.repos[0], { id: 1, fullName: "acme/r1" }].filter((r): r is NonNullable<typeof r> => !!r) }
254
+ ? {
255
+ ...res,
256
+ repos: [res.repos[0], { id: 1, fullName: "acme/r1" }].filter(
257
+ (r): r is NonNullable<typeof r> => !!r,
258
+ ),
259
+ }
243
260
  : res;
244
261
  },
245
262
  };
@@ -300,7 +317,11 @@ describe("crawlAgentInstallation", () => {
300
317
  store,
301
318
  clock,
302
319
  });
303
- expect(res).toEqual({ outcome: "not_installed", pagesFetched: 0, swept: 1 });
320
+ expect(res).toEqual({
321
+ outcome: "not_installed",
322
+ pagesFetched: 0,
323
+ swept: 1,
324
+ });
304
325
  expect(calls.pages).toEqual([]);
305
326
  expect(store.rows.size).toBe(0);
306
327
  expect(store.snap).toMatchObject({
@@ -11,11 +11,11 @@
11
11
  * never appears in a result or an error.
12
12
  */
13
13
 
14
+ import { signGithubAppJwt } from "./github-app-jwt.ts";
14
15
  import {
15
16
  GithubEnterpriseError,
16
17
  mapGithubEnterpriseError,
17
18
  } from "./github-enterprise-client.ts";
18
- import { signGithubAppJwt } from "./github-app-jwt.ts";
19
19
 
20
20
  interface FetchOpts {
21
21
  apiBase?: string;
@@ -76,7 +76,8 @@ describe("signGithubAppJwt", () => {
76
76
  });
77
77
 
78
78
  it("throws a key-free error for an invalid key", () => {
79
- const bad = "-----BEGIN RSA PRIVATE KEY-----\nSECRETGARBAGE\n-----END RSA PRIVATE KEY-----";
79
+ const bad =
80
+ "-----BEGIN RSA PRIVATE KEY-----\nSECRETGARBAGE\n-----END RSA PRIVATE KEY-----";
80
81
  let msg = "";
81
82
  try {
82
83
  signGithubAppJwt({ appId: "1", privateKey: bad, now: NOW });
@@ -21,16 +21,16 @@ import type { PrismaClient } from "../prisma/client/client.ts";
21
21
  import type { AgentEnvService } from "./agent-envs.ts";
22
22
  import type { Clock } from "./clock.ts";
23
23
  import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
24
+ import {
25
+ DEPLOYMENT_WIDE_ACCOUNT_KEY,
26
+ lookupAccountKeys,
27
+ } from "./github-agent-installation-crawler.ts";
24
28
  import { createGithubLookupService } from "./github-enterprise-api.ts";
25
29
  import type { GitHubEnterpriseAppService } from "./github-enterprise-apps.ts";
26
30
  import {
27
31
  createGithubInstallationRepos,
28
32
  createGithubSync,
29
33
  } from "./github-installation-wiring.ts";
30
- import {
31
- DEPLOYMENT_WIDE_ACCOUNT_KEY,
32
- lookupAccountKeys,
33
- } from "./github-agent-installation-crawler.ts";
34
34
  import { GitHubRepoCacheService } from "./github-repo-cache.ts";
35
35
  import {
36
36
  createRefreshDiscovery,
@@ -11,16 +11,16 @@
11
11
  import { afterEach, beforeEach, describe, expect, it } from "bun:test";
12
12
  import { generateKeyPairSync } from "node:crypto";
13
13
  import { readFileSync } from "node:fs";
14
+ import type { MiddlewareHandler } from "hono";
15
+ import { Hono } from "hono";
14
16
  import type { PrismaClient } from "../prisma/client/client.ts";
17
+ import type { AdminUIEnv } from "./admin-ui.ts";
18
+ import { registerAdminGithubEnterpriseRoutes } from "./admin-ui-github-enterprise.ts";
15
19
  import { AgentEnvService } from "./agent-envs.ts";
16
20
  import { AgentPluginService } from "./agent-plugins.ts";
17
21
  import { AgentService } from "./agents.ts";
18
22
  import { createAgentRuntimeApp } from "./api.ts";
19
23
  import { parseAdminApiKeys } from "./api-auth.ts";
20
- import type { MiddlewareHandler } from "hono";
21
- import { Hono } from "hono";
22
- import { type AdminUIEnv } from "./admin-ui.ts";
23
- import { registerAdminGithubEnterpriseRoutes } from "./admin-ui-github-enterprise.ts";
24
24
  import { createGithubEnterpriseApp } from "./github-enterprise-api.ts";
25
25
  import { GitHubEnterpriseAppService } from "./github-enterprise-apps.ts";
26
26
  import {
@@ -50,12 +50,6 @@ import {
50
50
  GithubEnterpriseError,
51
51
  type GithubEnterpriseErrorKind,
52
52
  } from "./github-enterprise-client.ts";
53
- import {
54
- findAgentInstallation,
55
- GITHUB_UNINSTALL_AUDIT_PLAN_HASH,
56
- planOrgUninstall,
57
- uninstallBlockReason,
58
- } from "./github-uninstall.ts";
59
53
  import { resolveValidation } from "./github-enterprise-warnings.ts";
60
54
  import { GithubLookupClient } from "./github-lookup-client.ts";
61
55
  import {
@@ -64,6 +58,12 @@ import {
64
58
  } from "./github-lookup-repositories.ts";
65
59
  import type { GithubRefreshAction } from "./github-refresh-action.ts";
66
60
  import type { GitHubRepoCacheService } from "./github-repo-cache.ts";
61
+ import {
62
+ findAgentInstallation,
63
+ GITHUB_UNINSTALL_AUDIT_PLAN_HASH,
64
+ planOrgUninstall,
65
+ uninstallBlockReason,
66
+ } from "./github-uninstall.ts";
67
67
  import {
68
68
  CLIENT_ID_RE,
69
69
  type InstallationAgentsPort,
@@ -19,8 +19,7 @@ function make(repoResp: () => Response) {
19
19
  const fetchFn = (async (input: RequestInfo | URL) => {
20
20
  const u = new URL(input.toString());
21
21
  paths.push(`${u.pathname}${u.search}`);
22
- if (u.pathname.endsWith("/installation"))
23
- return Response.json({ id: 1 });
22
+ if (u.pathname.endsWith("/installation")) return Response.json({ id: 1 });
24
23
  if (u.pathname.endsWith("/access_tokens"))
25
24
  return Response.json(
26
25
  { token: "t", expires_at: "2099-01-01T00:00:00Z" },
@@ -65,10 +64,18 @@ describe("listInstallationRepositoriesPage", () => {
65
64
  full_name: "o/n",
66
65
  }));
67
66
  expect(
68
- (await make(() => Response.json(full)).client.listInstallationRepositoriesPage("o", 5, 1)).hasNext,
67
+ (
68
+ await make(() =>
69
+ Response.json(full),
70
+ ).client.listInstallationRepositoriesPage("o", 5, 1)
71
+ ).hasNext,
69
72
  ).toBe(true);
70
73
  expect(
71
- (await make(() => Response.json(full.slice(0, 3))).client.listInstallationRepositoriesPage("o", 5, 1)).hasNext,
74
+ (
75
+ await make(() =>
76
+ Response.json(full.slice(0, 3)),
77
+ ).client.listInstallationRepositoriesPage("o", 5, 1)
78
+ ).hasNext,
72
79
  ).toBe(false);
73
80
  });
74
81
 
@@ -90,10 +97,15 @@ describe("listInstallationRepositoriesPage", () => {
90
97
  it("rejects a bad page or installation id before any request", async () => {
91
98
  const { client, paths } = make(() => Response.json([]));
92
99
  expect(
93
- (await client.listInstallationRepositoriesPage("o", 5, 0).catch((e) => e)).kind,
100
+ (await client.listInstallationRepositoriesPage("o", 5, 0).catch((e) => e))
101
+ .kind,
94
102
  ).toBe("validation");
95
103
  expect(
96
- (await client.listInstallationRepositoriesPage("o", Number.NaN, 1).catch((e) => e)).kind,
104
+ (
105
+ await client
106
+ .listInstallationRepositoriesPage("o", Number.NaN, 1)
107
+ .catch((e) => e)
108
+ ).kind,
97
109
  ).toBe("validation");
98
110
  expect(paths).toEqual([]);
99
111
  });