@app-vitals/agent-admin 1.86.0 → 1.86.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Dockerfile CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # Build from the repository root: docker build -f admin/Dockerfile .
4
4
 
5
- FROM oven/bun:1.4.4-slim@sha256:1846adf22496bd711036aae8be147e57bdebbaea2e5264e3e0b5af1db187d9a4 AS deps
5
+ FROM oven/bun:1.4.5-slim@sha256:b780593f3e10918cbdaec3d5a08d52224b9198069a65eb47812085c2ec007643 AS deps
6
6
 
7
7
  WORKDIR /app
8
8
 
@@ -23,7 +23,7 @@ RUN if [ -f bun.lock ]; then bun install --frozen-lockfile --production; else bu
23
23
  && rm -rf node_modules/.bun/typescript@* node_modules/.bun/@typescript+* \
24
24
  node_modules/.bun/node_modules/typescript node_modules/.bun/node_modules/@typescript
25
25
 
26
- FROM oven/bun:1.4.4-slim@sha256:1846adf22496bd711036aae8be147e57bdebbaea2e5264e3e0b5af1db187d9a4 AS production
26
+ FROM oven/bun:1.4.5-slim@sha256:b780593f3e10918cbdaec3d5a08d52224b9198069a65eb47812085c2ec007643 AS production
27
27
 
28
28
  # Upgrade apt/libapt-pkg7.0 past the base image's 3.0.3 (Trivy HIGH CVE-2026-109518, fixed in 3.0.4).
29
29
  RUN apt-get update \
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-admin",
3
- "version": "1.86.0",
3
+ "version": "1.86.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@anthropic-ai/sdk": "0.137.0",
47
- "@app-vitals/agent-lib": "1.86.0",
47
+ "@app-vitals/agent-lib": "1.86.1",
48
48
  "@hono/zod-openapi": "^1.0.0",
49
49
  "@prisma/adapter-pg": "^7.10.0",
50
50
  "@prisma/client": "^7.10.0",
@@ -32,6 +32,19 @@ import {
32
32
  */
33
33
  export const DEPLOYMENT_WIDE_ACCOUNT_KEY = "deployment";
34
34
 
35
+ /**
36
+ * The SnapshotKey.accountId values a lookup reads for an agent: its own
37
+ * account (when it has one) plus DEPLOYMENT_WIDE_ACCOUNT_KEY, where the
38
+ * crawler files deployment-wide App snapshots. A null/empty account reads only
39
+ * the deployment key. Note: a real account literally named "deployment" would
40
+ * collide with this fallback key; that is known and deliberately not fixed.
41
+ */
42
+ export function lookupAccountKeys(accountId?: string | null): string[] {
43
+ return accountId
44
+ ? [accountId, DEPLOYMENT_WIDE_ACCOUNT_KEY]
45
+ : [DEPLOYMENT_WIDE_ACCOUNT_KEY];
46
+ }
47
+
35
48
  /** The slice of the installer client the crawl needs. */
36
49
  export type AgentInstallationClient = Pick<
37
50
  InstallationRepoClient,
@@ -11,6 +11,7 @@ import {
11
11
  agentInstallationPageSource,
12
12
  crawlAgentInstallation,
13
13
  DEPLOYMENT_WIDE_ACCOUNT_KEY,
14
+ lookupAccountKeys,
14
15
  type AgentInstallationClient,
15
16
  } from "./github-agent-installation-crawler.ts";
16
17
  import type {
@@ -355,3 +356,23 @@ describe("crawlAgentInstallation", () => {
355
356
  expect(store.snap?.attempts).toBe(1);
356
357
  });
357
358
  });
359
+
360
+ describe("lookupAccountKeys", () => {
361
+ it("a deployment-wide agent (no account) reads only the deployment key", () => {
362
+ expect(lookupAccountKeys(null)).toEqual([DEPLOYMENT_WIDE_ACCOUNT_KEY]);
363
+ expect(lookupAccountKeys(undefined)).toEqual([DEPLOYMENT_WIDE_ACCOUNT_KEY]);
364
+ expect(lookupAccountKeys("")).toEqual([DEPLOYMENT_WIDE_ACCOUNT_KEY]);
365
+ });
366
+
367
+ it("an account agent reads its own account and the deployment key", () => {
368
+ expect(lookupAccountKeys("acct")).toEqual([
369
+ "acct",
370
+ DEPLOYMENT_WIDE_ACCOUNT_KEY,
371
+ ]);
372
+ });
373
+
374
+ it("never includes the empty-string key", () => {
375
+ expect(lookupAccountKeys(null)).not.toContain("");
376
+ expect(lookupAccountKeys("acct")).not.toContain("");
377
+ });
378
+ });
@@ -36,6 +36,7 @@ import {
36
36
  UnprocessableEntityError,
37
37
  } from "./errors.ts";
38
38
  import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
39
+ import { lookupAccountKeys } from "./github-agent-installation-crawler.ts";
39
40
  import { fetchAuthenticatedApp, fetchPublicApp } from "./github-app-api.ts";
40
41
  import {
41
42
  GITHUB_ENTERPRISE_APP_ROLES,
@@ -563,10 +564,8 @@ export function createGithubLookupService(
563
564
  if (!lookupKey || (installer?.enterpriseSlug && !installerKey)) {
564
565
  return { configured: false, repos: [] };
565
566
  }
566
- // The crawler files a deployment-wide App's snapshots under accountId "".
567
- const accountIds = accountId ? [accountId, ""] : [""];
568
567
  const snapshots = await deps.cache.listLookupSnapshots(
569
- accountIds,
568
+ lookupAccountKeys(accountId),
570
569
  lookup.appId,
571
570
  );
572
571
  return summarizeLookupSnapshots(
@@ -13,7 +13,7 @@ import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
13
13
  import type { Clock } from "./clock.ts";
14
14
  import type { GitHubEnterpriseAppService } from "./github-enterprise-apps.ts";
15
15
  import { GithubEnterpriseClient } from "./github-enterprise-client.ts";
16
- import { DEPLOYMENT_WIDE_ACCOUNT_KEY } from "./github-agent-installation-crawler.ts";
16
+ import { lookupAccountKeys } from "./github-agent-installation-crawler.ts";
17
17
  import { GithubLookupClient } from "./github-lookup-client.ts";
18
18
  import { GitHubRepoCacheService } from "./github-repo-cache.ts";
19
19
  import type { CrawlStore } from "./github-repo-crawler.ts";
@@ -159,15 +159,8 @@ export function createGithubSync(
159
159
  lookupRepos: async (accountId) => {
160
160
  const lookup = await lookupClient(accountId);
161
161
  if (!lookup) return [];
162
- // The crawler files a deployment-wide App's snapshots under
163
- // DEPLOYMENT_WIDE_ACCOUNT_KEY, so a null-account agent reads that key and
164
- // an account agent reads its own account plus that key.
165
- // Note: a real account literally named "deployment" would collide with
166
- // this fallback key; that is known and deliberately not fixed here.
167
162
  const snapshots = await cache.listLookupOrgSnapshots(
168
- accountId
169
- ? [accountId, DEPLOYMENT_WIDE_ACCOUNT_KEY]
170
- : [DEPLOYMENT_WIDE_ACCOUNT_KEY],
163
+ lookupAccountKeys(accountId),
171
164
  lookup.appId,
172
165
  );
173
166
  return snapshots.map((s) => ({
@@ -83,4 +83,20 @@ describeOrSkip("githubLookup.listRepositories (cache, integration)", () => {
83
83
  expect(done.repos).toHaveLength(2);
84
84
  expect(done.fetchedAt).toEqual(NOW);
85
85
  });
86
+
87
+ it("null-account lookup reads a deployment-wide snapshot filed under 'deployment'", async () => {
88
+ const snap = await cache.upsertSnapshot(
89
+ { ...key("acme"), accountId: "deployment" },
90
+ { crawlPage: 1, crawlStartedAt: NOW, totalCount: 1 },
91
+ );
92
+ await cache.upsertRepos(snap.id, [{ githubId: 3, fullName: "acme/c" }]);
93
+ await cache.upsertSnapshot(
94
+ { ...key("acme"), accountId: "deployment" },
95
+ { completedAt: NOW },
96
+ );
97
+ const r = await svc().listRepositories(null);
98
+ expect(r.configured).toBe(true);
99
+ expect(r.syncState).toBe("ready");
100
+ expect(r.repos).toEqual([{ fullName: "acme/c", archived: false }]);
101
+ });
86
102
  });
@@ -198,8 +198,69 @@ describe("createGithubLookupService", () => {
198
198
  const { svc, calls } = build({ lookup: lookupRow }, [snap()]);
199
199
  const r = await svc.listRepositories("acct");
200
200
  expect(r.syncState).toBe("ready");
201
- expect(calls[0]).toEqual([["acct", ""], "555"]);
202
- await svc.listRepositories();
203
- expect(calls[1]).toEqual([[""], "555"]);
201
+ expect(calls[0]).toEqual([["acct", "deployment"], "555"]);
202
+ });
203
+
204
+ describe("against a cache seeded under the real keys", () => {
205
+ /** Fake cache that only returns snapshots filed under a requested accountId. */
206
+ function seededCache(seed: Record<string, LookupSnapshotView[]>) {
207
+ const calls: string[][] = [];
208
+ return {
209
+ calls,
210
+ cache: {
211
+ listLookupSnapshots: async (accountIds: string[]) => {
212
+ calls.push(accountIds);
213
+ return accountIds.flatMap((id) => seed[id] ?? []);
214
+ },
215
+ },
216
+ };
217
+ }
218
+ const deploymentApps = {
219
+ get: async (role: string) => (role === "lookup" ? lookupRow : null),
220
+ getPrivateKey: async (role: string) => (role === "lookup" ? "pem" : null),
221
+ } as unknown as GitHubEnterpriseAppService;
222
+
223
+ it("deployment-wide lookup App (null account) reads the 'deployment' key: ready", async () => {
224
+ const { cache, calls } = seededCache({
225
+ deployment: [snap({ completedAt: ago(5 * MIN) })],
226
+ });
227
+ const svc = createGithubLookupService({
228
+ appService: deploymentApps,
229
+ cache,
230
+ now: () => NOW,
231
+ });
232
+ const r = await svc.listRepositories(null);
233
+ expect(calls).toEqual([["deployment"]]);
234
+ expect(r.configured).toBe(true);
235
+ expect(r.syncState).toBe("ready");
236
+ expect(r.repos.map((x) => x.fullName)).toEqual(["acme/a", "acme/b"]);
237
+ });
238
+
239
+ it("account-scoped lookup also serves the deployment-wide snapshots", async () => {
240
+ const { cache, calls } = seededCache({
241
+ deployment: [snap({ completedAt: ago(5 * MIN) })],
242
+ });
243
+ const svc = createGithubLookupService({
244
+ appService: deploymentApps,
245
+ cache,
246
+ now: () => NOW,
247
+ });
248
+ const r = await svc.listRepositories("acct");
249
+ expect(calls).toEqual([["acct", "deployment"]]);
250
+ expect(r.syncState).toBe("ready");
251
+ expect(r.repos).toHaveLength(2);
252
+ });
253
+
254
+ it("never queries the empty-string key", async () => {
255
+ const { cache, calls } = seededCache({});
256
+ const svc = createGithubLookupService({
257
+ appService: deploymentApps,
258
+ cache,
259
+ now: () => NOW,
260
+ });
261
+ await svc.listRepositories();
262
+ await svc.listRepositories("acct");
263
+ expect(calls.flat()).not.toContain("");
264
+ });
204
265
  });
205
266
  });