@app-vitals/agent-admin 1.22.0 → 1.23.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-admin",
3
- "version": "1.22.0",
3
+ "version": "1.23.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@anthropic-ai/sdk": "0.135.0",
45
- "@app-vitals/agent-lib": "1.22.0",
45
+ "@app-vitals/agent-lib": "1.23.0",
46
46
  "@hono/zod-openapi": "^1.0.0",
47
47
  "@prisma/adapter-pg": "^7.10.0",
48
48
  "@prisma/client": "^7.10.0",
@@ -83,7 +83,7 @@ const ROLE_COPY = {
83
83
  },
84
84
  lookup: {
85
85
  title: "Lookup app",
86
- help: "Read-only App used to see which organizations the platform can look up. Needs the metadata (read) permission.",
86
+ help: "Read-only App used to see which organizations the platform can look up. Needs the metadata (read) permission. It must be installed on all repositories of each organization, not selected repositories only.",
87
87
  },
88
88
  } as const;
89
89
 
@@ -39,6 +39,7 @@ describe("renderGithubEnterpriseSettingsPage", () => {
39
39
  expect(html).toContain("optional");
40
40
  expect(html).toContain("Installer app");
41
41
  expect(html).toContain("Lookup app");
42
+ expect(html).toContain("installed on all repositories");
42
43
  expect(html).toContain(
43
44
  'action="/admin/settings/github-enterprise/apps/installer"',
44
45
  );
@@ -27,6 +27,8 @@ export interface GithubAccessOrg {
27
27
  status: GithubAccessOrgStatus;
28
28
  repos: GithubAccessRepo[];
29
29
  unresolved: number;
30
+ /** Optional cause shown in the partial-results banner. */
31
+ reason?: string;
30
32
  }
31
33
 
32
34
  /** JSON body of GET /agents/:id/github-access. */
@@ -127,9 +129,13 @@ export function renderGithubAccessResult(
127
129
  if (!access) return renderGithubAccessError("No preview was returned.");
128
130
 
129
131
  const orgs = access.orgs;
132
+ const reasons = orgs
133
+ .filter((o) => o.reason)
134
+ .map((o) => `${escapeHtml(o.org)}: ${escapeHtml(o.reason ?? "")}`)
135
+ .join("; ");
130
136
  const warn =
131
137
  !access.complete || orgs.some((o) => o.status !== "ok")
132
- ? `<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.</div>`
138
+ ? `<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>`
133
139
  : "";
134
140
  if (orgs.length === 0) {
135
141
  return `${warn}<p class="empty-state">No organizations to check.</p>`;
@@ -173,6 +173,26 @@ describe("renderGithubAccessResult", () => {
173
173
  expect(html).toContain("Partial results");
174
174
  });
175
175
 
176
+ test("partial org with a reason shows the reason in the banner", () => {
177
+ const html = renderGithubAccessResult(
178
+ analysis({
179
+ complete: false,
180
+ orgs: [
181
+ {
182
+ org: "acme",
183
+ status: "partial",
184
+ repos: [],
185
+ unresolved: 0,
186
+ reason: "lookup app installed on selected repositories only <x>",
187
+ },
188
+ ],
189
+ }),
190
+ );
191
+ expect(html).toContain("Partial results");
192
+ expect(html).toContain("selected repositories only &lt;x&gt;");
193
+ expect(html).not.toContain("<x>");
194
+ });
195
+
176
196
  test("incomplete with all orgs ok still warns", () => {
177
197
  const html = renderGithubAccessResult(
178
198
  analysis({
@@ -17,6 +17,24 @@
17
17
  }
18
18
  }
19
19
  },
20
+ "org_installation_selected": {
21
+ "status": 200,
22
+ "body": {
23
+ "id": 7001,
24
+ "app_id": 555,
25
+ "app_slug": "example-lookup",
26
+ "target_type": "Organization",
27
+ "account": {
28
+ "login": "acme-eng",
29
+ "id": 11,
30
+ "type": "Organization"
31
+ },
32
+ "repository_selection": "selected",
33
+ "permissions": {
34
+ "metadata": "read"
35
+ }
36
+ }
37
+ },
20
38
  "org_installation_403": {
21
39
  "status": 403,
22
40
  "body": {
@@ -126,6 +126,7 @@ describe("getOrgToken", () => {
126
126
  token: "ghs_lookupInstallationTokenSecret",
127
127
  expiresAt: "2026-11-09T13:00:00Z",
128
128
  installationId: 7001,
129
+ repositorySelection: "all",
129
130
  });
130
131
  expect(calls.map((c) => `${c.method} ${c.path}`)).toEqual([INST, MINT]);
131
132
  for (const c of calls) {
@@ -135,6 +136,13 @@ describe("getOrgToken", () => {
135
136
  }
136
137
  });
137
138
 
139
+ it("reports repository_selection selected from the installation", async () => {
140
+ const { client } = makeClient({ [INST]: "org_installation_selected" });
141
+ expect((await client.getOrgToken("acme-eng")).repositorySelection).toBe(
142
+ "selected",
143
+ );
144
+ });
145
+
138
146
  it("caches per org until near expiry", async () => {
139
147
  const { client, calls } = makeClient({});
140
148
  await client.getOrgToken("acme-eng");
@@ -73,6 +73,12 @@ export interface LookupToken {
73
73
  token: string;
74
74
  expiresAt: string;
75
75
  installationId: number;
76
+ /**
77
+ * The lookup App's own installation scope on the org, from GET
78
+ * /orgs/{org}/installation (read with the App JWT, so it describes this
79
+ * App's installation). Absent when GitHub did not report a known value.
80
+ */
81
+ repositorySelection?: "all" | "selected";
76
82
  }
77
83
 
78
84
  export interface GithubLookupClientOptions {
@@ -119,7 +125,10 @@ export class GithubLookupClient {
119
125
  privateKey: this.privateKey,
120
126
  now: this.now(),
121
127
  });
122
- const inst = await this.request<{ id?: number }>(
128
+ const inst = await this.request<{
129
+ id?: number;
130
+ repository_selection?: unknown;
131
+ }>(
123
132
  "GET",
124
133
  `/orgs/${encodeURIComponent(org)}/installation`,
125
134
  jwt,
@@ -148,6 +157,10 @@ export class GithubLookupClient {
148
157
  expiresAt: minted.data.expires_at,
149
158
  installationId: inst.data.id,
150
159
  };
160
+ const selection = inst.data.repository_selection;
161
+ if (selection === "all" || selection === "selected") {
162
+ token.repositorySelection = selection;
163
+ }
151
164
  this.cached.set(key, token);
152
165
  return token;
153
166
  }
@@ -28,8 +28,9 @@ const { privateKey } = generateKeyPairSync("rsa", {
28
28
  });
29
29
 
30
30
  const NOW = new Date("2026-11-09T12:00:00Z");
31
+ const INST = "GET /orgs/acme-eng/installation";
31
32
  const BASE: Record<string, string> = {
32
- "GET /orgs/acme-eng/installation": "org_installation_success",
33
+ [INST]: "org_installation_success",
33
34
  "POST /app/installations/7001/access_tokens": "lookup_token_success",
34
35
  "GET /installation/repositories": "repos_success",
35
36
  "GET /users/octocat": "user_success",
@@ -98,6 +99,20 @@ describe("UserRepoAccessResolver against GHE-2.2 cassettes", () => {
98
99
  ]);
99
100
  });
100
101
 
102
+ it("selected installation: partial with a reason naming the selection", async () => {
103
+ const { resolver } = setup({
104
+ [INST]: "org_installation_selected",
105
+ [API]: "permission_maintain",
106
+ [WEB]: "permission_triage",
107
+ });
108
+ const res = await resolver.resolve("octocat");
109
+ expect(res.complete).toBe(false);
110
+ expect(res.orgs[0].status).toBe("partial");
111
+ expect(res.orgs[0].reason).toContain("selected repositories");
112
+ expect(res.orgs[0].repos).toHaveLength(2);
113
+ expect(res.orgs[0].unresolved).toBe(0);
114
+ });
115
+
101
116
  it("partial run: 429 mid-org keeps resolved and stops further calls", async () => {
102
117
  const { resolver, calls } = setup({
103
118
  [API]: "permission_write",
@@ -58,8 +58,14 @@ export interface OrgAccessResult {
58
58
  repos: ResolvedRepoAccess[];
59
59
  /** Repos that could not be checked. Never reported as "none". */
60
60
  unresolved: number;
61
+ /** Why the org is not "ok" when the cause is the lookup install scope. */
62
+ reason?: string;
61
63
  }
62
64
 
65
+ /** Shown when the lookup App is installed on selected repositories only. */
66
+ export const SELECTED_REPOS_REASON =
67
+ "lookup app is installed on selected repositories only; install it on all repositories";
68
+
63
69
  export interface UserRepoAccessResult {
64
70
  username: string;
65
71
  outcome: "ok" | "user_not_found";
@@ -173,8 +179,10 @@ export class UserRepoAccessResolver {
173
179
  username: string,
174
180
  ): Promise<OrgAccessResult> {
175
181
  let repos: LookupRepository[];
182
+ let selectedOnly = false;
176
183
  try {
177
- await this.lookup.getOrgToken(org);
184
+ const token = await this.lookup.getOrgToken(org);
185
+ selectedOnly = token.repositorySelection === "selected";
178
186
  repos = await this.lookup.listInstallationRepositories(org);
179
187
  } catch (e) {
180
188
  return orgLevelFailure(org, e);
@@ -221,6 +229,16 @@ export class UserRepoAccessResolver {
221
229
  else if (list.length > 0) status = "partial";
222
230
  else if (stop === "rate_limit") status = "rate_limited";
223
231
  else status = "error";
232
+ // A selected-only install lists a subset that looks complete: never "ok".
233
+ if (selectedOnly && status === "ok") {
234
+ return {
235
+ org,
236
+ status: "partial",
237
+ repos: list,
238
+ unresolved,
239
+ reason: SELECTED_REPOS_REASON,
240
+ };
241
+ }
224
242
  return { org, status, repos: list, unresolved };
225
243
  }
226
244
 
@@ -31,6 +31,7 @@ interface FakeOpts {
31
31
  perm?: (owner: string, repo: string) => RepoRole | Error | Promise<RepoRole>;
32
32
  token?: Record<string, Error>;
33
33
  user?: Error;
34
+ selection?: Record<string, "all" | "selected">;
34
35
  }
35
36
 
36
37
  function fake(o: FakeOpts = {}) {
@@ -40,7 +41,14 @@ function fake(o: FakeOpts = {}) {
40
41
  async getOrgToken(org) {
41
42
  const e = o.token?.[org];
42
43
  if (e) throw e;
43
- return { token: "ghs_secret", expiresAt: "x", installationId: 1 };
44
+ return {
45
+ token: "ghs_secret",
46
+ expiresAt: "x",
47
+ installationId: 1,
48
+ ...(o.selection?.[org]
49
+ ? { repositorySelection: o.selection[org] }
50
+ : {}),
51
+ };
44
52
  },
45
53
  async getUser(_org, login) {
46
54
  if (o.user) throw o.user;
@@ -70,6 +78,31 @@ function fake(o: FakeOpts = {}) {
70
78
  return { resolver, calls };
71
79
  }
72
80
 
81
+ describe("selected-repositories installation", () => {
82
+ it("marks the org partial with a reason and keeps resolved repos", async () => {
83
+ const { resolver } = fake({
84
+ repos: { acme: ["a"], beta: ["b"] },
85
+ selection: { acme: "selected", beta: "all" },
86
+ });
87
+ const res = await resolver.resolve("octocat");
88
+ const [acme, beta] = res.orgs;
89
+ expect(acme.status).toBe("partial");
90
+ expect(acme.reason).toContain("selected repositories");
91
+ expect(acme.repos).toHaveLength(1);
92
+ expect(beta.status).toBe("ok");
93
+ expect(beta.reason).toBeUndefined();
94
+ expect(res.complete).toBe(false);
95
+ });
96
+
97
+ it("an all-repositories or unreported selection is unchanged", async () => {
98
+ const { resolver } = fake({ selection: { acme: "all" } });
99
+ const res = await resolver.resolve("octocat");
100
+ expect(res.orgs[0].status).toBe("ok");
101
+ expect(res.orgs[0].reason).toBeUndefined();
102
+ expect(res.complete).toBe(true);
103
+ });
104
+ });
105
+
73
106
  describe("canPushForRole", () => {
74
107
  const cases: Array<[RepoRole, boolean]> = [
75
108
  ["admin", true],