@app-vitals/agent-admin 1.60.0 → 1.61.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/openapi.platform.json +75 -0
- package/package.json +2 -2
- package/src/admin-ui-github-enterprise-pages.ts +88 -16
- package/src/admin-ui-github-enterprise.smoke.test.ts +135 -12
- package/src/admin-ui-github-enterprise.ts +59 -18
- package/src/admin-ui.ts +2 -1
- package/src/agents-api.ts +4 -1
- package/src/github-access-preview.ts +2 -0
- package/src/github-enterprise-api.smoke.test.ts +171 -27
- package/src/github-enterprise-api.ts +63 -25
- package/src/github-installation-wiring.ts +15 -13
- package/src/github-lookup-repositories.integration.test.ts +136 -6
- package/src/github-lookup-repositories.ts +4 -1
- package/src/github-sync.ts +1 -1
- package/src/installation-ports.ts +16 -3
- package/src/installation-repos-service.ts +9 -3
package/openapi.platform.json
CHANGED
|
@@ -4042,6 +4042,13 @@
|
|
|
4042
4042
|
"null"
|
|
4043
4043
|
],
|
|
4044
4044
|
"properties": {
|
|
4045
|
+
"accountId": {
|
|
4046
|
+
"type": [
|
|
4047
|
+
"string",
|
|
4048
|
+
"null"
|
|
4049
|
+
],
|
|
4050
|
+
"description": "Null for the deployment-wide App."
|
|
4051
|
+
},
|
|
4045
4052
|
"role": {
|
|
4046
4053
|
"type": "string",
|
|
4047
4054
|
"example": "installer"
|
|
@@ -8129,6 +8136,19 @@
|
|
|
8129
8136
|
],
|
|
8130
8137
|
"summary": "GitHub Enterprise App status",
|
|
8131
8138
|
"description": "Admin-only. Metadata and key-set flag per role; never the key. Returns configured=false with null roles when nothing is set.",
|
|
8139
|
+
"parameters": [
|
|
8140
|
+
{
|
|
8141
|
+
"schema": {
|
|
8142
|
+
"type": "string",
|
|
8143
|
+
"minLength": 1,
|
|
8144
|
+
"description": "Account whose App pair to read/write. Omit for the deployment-wide pair."
|
|
8145
|
+
},
|
|
8146
|
+
"required": false,
|
|
8147
|
+
"description": "Account whose App pair to read/write. Omit for the deployment-wide pair.",
|
|
8148
|
+
"name": "accountId",
|
|
8149
|
+
"in": "query"
|
|
8150
|
+
}
|
|
8151
|
+
],
|
|
8132
8152
|
"responses": {
|
|
8133
8153
|
"200": {
|
|
8134
8154
|
"description": "Status",
|
|
@@ -8183,6 +8203,17 @@
|
|
|
8183
8203
|
"required": true,
|
|
8184
8204
|
"name": "role",
|
|
8185
8205
|
"in": "path"
|
|
8206
|
+
},
|
|
8207
|
+
{
|
|
8208
|
+
"schema": {
|
|
8209
|
+
"type": "string",
|
|
8210
|
+
"minLength": 1,
|
|
8211
|
+
"description": "Account whose App pair to read/write. Omit for the deployment-wide pair."
|
|
8212
|
+
},
|
|
8213
|
+
"required": false,
|
|
8214
|
+
"description": "Account whose App pair to read/write. Omit for the deployment-wide pair.",
|
|
8215
|
+
"name": "accountId",
|
|
8216
|
+
"in": "query"
|
|
8186
8217
|
}
|
|
8187
8218
|
],
|
|
8188
8219
|
"requestBody": {
|
|
@@ -8266,6 +8297,17 @@
|
|
|
8266
8297
|
"required": true,
|
|
8267
8298
|
"name": "role",
|
|
8268
8299
|
"in": "path"
|
|
8300
|
+
},
|
|
8301
|
+
{
|
|
8302
|
+
"schema": {
|
|
8303
|
+
"type": "string",
|
|
8304
|
+
"minLength": 1,
|
|
8305
|
+
"description": "Account whose App pair to read/write. Omit for the deployment-wide pair."
|
|
8306
|
+
},
|
|
8307
|
+
"required": false,
|
|
8308
|
+
"description": "Account whose App pair to read/write. Omit for the deployment-wide pair.",
|
|
8309
|
+
"name": "accountId",
|
|
8310
|
+
"in": "query"
|
|
8269
8311
|
}
|
|
8270
8312
|
],
|
|
8271
8313
|
"responses": {
|
|
@@ -8315,6 +8357,17 @@
|
|
|
8315
8357
|
"required": true,
|
|
8316
8358
|
"name": "role",
|
|
8317
8359
|
"in": "path"
|
|
8360
|
+
},
|
|
8361
|
+
{
|
|
8362
|
+
"schema": {
|
|
8363
|
+
"type": "string",
|
|
8364
|
+
"minLength": 1,
|
|
8365
|
+
"description": "Account whose App pair to read/write. Omit for the deployment-wide pair."
|
|
8366
|
+
},
|
|
8367
|
+
"required": false,
|
|
8368
|
+
"description": "Account whose App pair to read/write. Omit for the deployment-wide pair.",
|
|
8369
|
+
"name": "accountId",
|
|
8370
|
+
"in": "query"
|
|
8318
8371
|
}
|
|
8319
8372
|
],
|
|
8320
8373
|
"responses": {
|
|
@@ -8369,6 +8422,17 @@
|
|
|
8369
8422
|
"summary": "List installable organizations",
|
|
8370
8423
|
"description": "Admin-only. Lists the enterprise's installable organizations, whether each has the lookup App installed, and (with agentId) whether each has that agent's App installed. Returns configured=false and no orgs when the installer App is not set.",
|
|
8371
8424
|
"parameters": [
|
|
8425
|
+
{
|
|
8426
|
+
"schema": {
|
|
8427
|
+
"type": "string",
|
|
8428
|
+
"minLength": 1,
|
|
8429
|
+
"description": "Account whose App pair to read/write. Omit for the deployment-wide pair."
|
|
8430
|
+
},
|
|
8431
|
+
"required": false,
|
|
8432
|
+
"description": "Account whose App pair to read/write. Omit for the deployment-wide pair.",
|
|
8433
|
+
"name": "accountId",
|
|
8434
|
+
"in": "query"
|
|
8435
|
+
},
|
|
8372
8436
|
{
|
|
8373
8437
|
"schema": {
|
|
8374
8438
|
"type": "string",
|
|
@@ -8490,6 +8554,17 @@
|
|
|
8490
8554
|
"required": true,
|
|
8491
8555
|
"name": "org",
|
|
8492
8556
|
"in": "path"
|
|
8557
|
+
},
|
|
8558
|
+
{
|
|
8559
|
+
"schema": {
|
|
8560
|
+
"type": "string",
|
|
8561
|
+
"minLength": 1,
|
|
8562
|
+
"description": "Account whose App pair to read/write. Omit for the deployment-wide pair."
|
|
8563
|
+
},
|
|
8564
|
+
"required": false,
|
|
8565
|
+
"description": "Account whose App pair to read/write. Omit for the deployment-wide pair.",
|
|
8566
|
+
"name": "accountId",
|
|
8567
|
+
"in": "query"
|
|
8493
8568
|
}
|
|
8494
8569
|
],
|
|
8495
8570
|
"requestBody": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.61.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.137.0",
|
|
45
|
-
"@app-vitals/agent-lib": "1.
|
|
45
|
+
"@app-vitals/agent-lib": "1.61.0",
|
|
46
46
|
"@hono/zod-openapi": "^1.0.0",
|
|
47
47
|
"@prisma/adapter-pg": "^7.10.0",
|
|
48
48
|
"@prisma/client": "^7.10.0",
|
|
@@ -7,17 +7,17 @@
|
|
|
7
7
|
* never renders a key (the status API only reports `keySet`).
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
GHE_WARNINGS,
|
|
12
|
-
type GheWarningCode,
|
|
13
|
-
} from "./github-enterprise-warnings.ts";
|
|
14
10
|
import { renderAdminPage } from "./admin-ui-layout.ts";
|
|
15
|
-
import { escapeHtml } from "./admin-ui-styles.ts";
|
|
16
11
|
import {
|
|
17
12
|
buildSettingsNav,
|
|
18
13
|
renderSettingsLayout,
|
|
19
14
|
type SettingsNav,
|
|
20
15
|
} from "./admin-ui-settings-layout.ts";
|
|
16
|
+
import { escapeHtml } from "./admin-ui-styles.ts";
|
|
17
|
+
import {
|
|
18
|
+
GHE_WARNINGS,
|
|
19
|
+
type GheWarningCode,
|
|
20
|
+
} from "./github-enterprise-warnings.ts";
|
|
21
21
|
|
|
22
22
|
export const ADMIN_GITHUB_ENTERPRISE_PATH = "/admin/settings/github-enterprise";
|
|
23
23
|
|
|
@@ -63,6 +63,12 @@ export interface GithubEnterpriseSettingsPageOpts {
|
|
|
63
63
|
/** Settings sidebar nav; defaults to the base Platform nav. */
|
|
64
64
|
nav?: SettingsNav;
|
|
65
65
|
status: GheStatus;
|
|
66
|
+
/** Account whose pair is shown; omitted for the deployment-wide pair. */
|
|
67
|
+
accountId?: string;
|
|
68
|
+
/** Accounts offered by the selector; omitted hides it. */
|
|
69
|
+
accounts?: { id: string; name: string }[];
|
|
70
|
+
/** Deployment-wide pair, passed when an account is selected (fallback). */
|
|
71
|
+
defaultStatus?: GheStatus;
|
|
66
72
|
/** Present when the installer App is configured and the org list loaded. */
|
|
67
73
|
orgs?: GheOrgs;
|
|
68
74
|
/** Readable message when the org list could not be loaded. */
|
|
@@ -113,12 +119,31 @@ const ROLE_COPY = {
|
|
|
113
119
|
},
|
|
114
120
|
} as const;
|
|
115
121
|
|
|
122
|
+
/** Lookup setup steps when no installer App exists (per-org manual install). */
|
|
123
|
+
function lookupOnlySteps(slug: string | undefined): string[] {
|
|
124
|
+
const link = slug
|
|
125
|
+
? `https://github.com/apps/${escapeHtml(slug)}/installations/new`
|
|
126
|
+
: "https://github.com/apps/<slug>/installations/new";
|
|
127
|
+
return [
|
|
128
|
+
"In GitHub, open the organization that will own the App: Settings → Developer settings → GitHub Apps → New GitHub App.",
|
|
129
|
+
"Grant Repository <code>Metadata</code> at <strong>Read</strong> and Organization <code>Members</code> at <strong>Read</strong>.",
|
|
130
|
+
"Create the App. The App ID is on the App's settings page; the App slug is the last part of its public URL (<code>github.com/apps/<slug></code>).",
|
|
131
|
+
`Install it manually on each organization you want covered, choosing <strong>All repositories</strong> (it must be installed on all repositories of each organization, not selected repositories only): <a href="${link}" target="_blank" rel="noopener noreferrer">${link}</a>. GitHub Enterprise Cloud is not needed.`,
|
|
132
|
+
"Under Private keys, choose Generate a private key and paste the downloaded PEM below.",
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
|
|
116
136
|
const IGNORED_OPTIONS =
|
|
117
137
|
"Ignore these options: callback URL, request user authorization, expire user authorization tokens, device flow, and webhook (uncheck Active).";
|
|
118
138
|
|
|
119
|
-
function guidance(
|
|
120
|
-
|
|
121
|
-
|
|
139
|
+
function guidance(
|
|
140
|
+
role: "installer" | "lookup",
|
|
141
|
+
lookupOnly: string[] | null,
|
|
142
|
+
): string {
|
|
143
|
+
const steps =
|
|
144
|
+
role === "lookup" && lookupOnly ? lookupOnly : ROLE_COPY[role].steps;
|
|
145
|
+
const variant = role === "lookup" && lookupOnly ? " gh-ent-lookup-only" : "";
|
|
146
|
+
return `<ol class="help-text gh-ent-steps${variant}" style="font-size:12px;margin:8px 0;padding-left:20px">${steps.map((x) => `<li>${x}</li>`).join("")}</ol>
|
|
122
147
|
<p class="help-text gh-ent-ignore" style="font-size:12px;margin:8px 0">${IGNORED_OPTIONS}</p>`;
|
|
123
148
|
}
|
|
124
149
|
|
|
@@ -160,17 +185,57 @@ function warningsBlock(
|
|
|
160
185
|
.join("");
|
|
161
186
|
}
|
|
162
187
|
|
|
188
|
+
/** Query suffix carrying the selected account (empty = deployment-wide). */
|
|
189
|
+
function scopeQuery(accountId: string | undefined): string {
|
|
190
|
+
return accountId ? `?accountId=${encodeURIComponent(accountId)}` : "";
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function accountSelector(opts: GithubEnterpriseSettingsPageOpts): string {
|
|
194
|
+
if (!opts.accounts) return "";
|
|
195
|
+
const options = [
|
|
196
|
+
`<option value=""${opts.accountId ? "" : " selected"}>Deployment-wide default</option>`,
|
|
197
|
+
...opts.accounts.map(
|
|
198
|
+
(a) =>
|
|
199
|
+
`<option value="${escapeHtml(a.id)}"${a.id === opts.accountId ? " selected" : ""}>${escapeHtml(a.name)}</option>`,
|
|
200
|
+
),
|
|
201
|
+
].join("");
|
|
202
|
+
return `<form method="GET" action="${BASE}" class="gh-ent-account-selector" style="display:flex;gap:8px;align-items:center;margin:8px 0">
|
|
203
|
+
<label>Account <select name="accountId" class="form-input">${options}</select></label>
|
|
204
|
+
<button type="submit" class="btn btn-secondary" style="font-size:12px;padding:4px 10px">Switch</button>
|
|
205
|
+
</form>`;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Which pair the selected account is using: its own row or the fallback. */
|
|
209
|
+
function scopeNote(
|
|
210
|
+
role: "installer" | "lookup",
|
|
211
|
+
opts: GithubEnterpriseSettingsPageOpts,
|
|
212
|
+
own: GheApp | null,
|
|
213
|
+
): string {
|
|
214
|
+
if (!opts.accountId) return "";
|
|
215
|
+
if (own)
|
|
216
|
+
return `<p class="help-text gh-ent-scope" style="font-size:12px;margin:8px 0"><span class="badge badge-green">Account's own App</span> This account uses its own ${role} App.</p>`;
|
|
217
|
+
const fallback = opts.defaultStatus?.[role];
|
|
218
|
+
return fallback
|
|
219
|
+
? `<p class="help-text gh-ent-scope" style="font-size:12px;margin:8px 0"><span class="badge badge-gray">Deployment-wide fallback</span> This account has no ${role} App of its own and uses the deployment-wide one (slug <strong>${escapeHtml(fallback.slug)}</strong>). Saving credentials below creates an account-specific App.</p>`
|
|
220
|
+
: `<p class="help-text gh-ent-scope" style="font-size:12px;margin:8px 0"><span class="badge badge-gray">None</span> No ${role} App for this account or deployment-wide.</p>`;
|
|
221
|
+
}
|
|
222
|
+
|
|
163
223
|
function appCard(
|
|
164
224
|
role: "installer" | "lookup",
|
|
165
225
|
app: GheApp | null,
|
|
166
|
-
|
|
226
|
+
opts: GithubEnterpriseSettingsPageOpts,
|
|
227
|
+
lookupOnly: string[] | null,
|
|
167
228
|
): string {
|
|
229
|
+
const warnings = opts.warnings;
|
|
168
230
|
const copy = ROLE_COPY[role];
|
|
169
|
-
const
|
|
231
|
+
const scope = scopeQuery(opts.accountId);
|
|
232
|
+
const action = `${BASE}/apps/${role}${scope}`;
|
|
233
|
+
const actionFor = (suffix: string) =>
|
|
234
|
+
`${BASE}/apps/${role}/${suffix}${scope}`;
|
|
170
235
|
const summary = app
|
|
171
236
|
? `<p style="margin:8px 0">App ID <strong>${escapeHtml(app.appId)}</strong> · slug <strong>${escapeHtml(app.slug)}</strong>${app.enterpriseSlug ? ` · enterprise <strong>${escapeHtml(app.enterpriseSlug)}</strong>` : ""}</p>
|
|
172
237
|
${statusLine(app)}${warningsBlock(role, warnings)}
|
|
173
|
-
<div style="display:flex;gap:8px;margin:12px 0">${postButton(
|
|
238
|
+
<div style="display:flex;gap:8px;margin:12px 0">${postButton(actionFor("validate"), "Validate")}${postButton(actionFor("delete"), "Delete", "btn-danger")}</div>`
|
|
174
239
|
: `<p class="help-text" style="font-size:12px;margin:8px 0">Not configured.</p>`;
|
|
175
240
|
const enterprise =
|
|
176
241
|
role === "installer"
|
|
@@ -179,7 +244,9 @@ function appCard(
|
|
|
179
244
|
return `<div class="card">
|
|
180
245
|
<div class="card-title">${copy.title}</div>
|
|
181
246
|
<p class="help-text" style="font-size:12px">${copy.descriptor}</p>
|
|
182
|
-
${
|
|
247
|
+
${accountSelector(opts)}
|
|
248
|
+
${scopeNote(role, opts, app)}
|
|
249
|
+
${guidance(role, lookupOnly)}
|
|
183
250
|
${summary}
|
|
184
251
|
<form method="POST" action="${action}" enctype="multipart/form-data" style="display:grid;gap:8px;max-width:480px">
|
|
185
252
|
<label>App ID <input name="appId" class="form-input" required inputmode="numeric" pattern="[0-9]+" /></label>
|
|
@@ -201,8 +268,8 @@ function installedCell(v: boolean | null): string {
|
|
|
201
268
|
|
|
202
269
|
function orgsCard(opts: GithubEnterpriseSettingsPageOpts): string {
|
|
203
270
|
const { status } = opts;
|
|
204
|
-
if (!status.installer) return "";
|
|
205
|
-
const lookupSlug = status.lookup?.slug;
|
|
271
|
+
if (!(status.installer ?? opts.defaultStatus?.installer)) return "";
|
|
272
|
+
const lookupSlug = (status.lookup ?? opts.defaultStatus?.lookup)?.slug;
|
|
206
273
|
|
|
207
274
|
let body: string;
|
|
208
275
|
if (opts.orgsError) {
|
|
@@ -240,6 +307,11 @@ export function renderGithubEnterpriseSettingsPage(
|
|
|
240
307
|
opts: GithubEnterpriseSettingsPageOpts,
|
|
241
308
|
): string {
|
|
242
309
|
const { status } = opts;
|
|
310
|
+
const effectiveInstaller = status.installer ?? opts.defaultStatus?.installer;
|
|
311
|
+
const effectiveLookup = status.lookup ?? opts.defaultStatus?.lookup;
|
|
312
|
+
const lookupOnly = effectiveInstaller
|
|
313
|
+
? null
|
|
314
|
+
: lookupOnlySteps(effectiveLookup?.slug);
|
|
243
315
|
const error = opts.error
|
|
244
316
|
? `<div class="alert alert-error">${escapeHtml(opts.error)}</div>`
|
|
245
317
|
: "";
|
|
@@ -262,8 +334,8 @@ export function renderGithubEnterpriseSettingsPage(
|
|
|
262
334
|
active: BASE,
|
|
263
335
|
isAdmin: opts.isAdmin ?? false,
|
|
264
336
|
body: `${error}${notice}${intro}
|
|
265
|
-
${appCard("installer", status.installer, opts
|
|
266
|
-
${appCard("lookup", status.lookup, opts
|
|
337
|
+
${appCard("installer", status.installer, opts, lookupOnly)}
|
|
338
|
+
${appCard("lookup", status.lookup, opts, lookupOnly)}
|
|
267
339
|
${orgsCard(opts)}`,
|
|
268
340
|
}),
|
|
269
341
|
});
|
|
@@ -9,8 +9,8 @@ import { describe, expect, it } from "bun:test";
|
|
|
9
9
|
import { generateKeyPairSync } from "node:crypto";
|
|
10
10
|
import type { MiddlewareHandler } from "hono";
|
|
11
11
|
import { Hono } from "hono";
|
|
12
|
-
import { type AdminUIEnv, createAdminUIApp } from "./admin-ui.ts";
|
|
13
12
|
import { makeMockDeps, makeSessionCookie } from "./admin-ui.fixtures.ts";
|
|
13
|
+
import { type AdminUIEnv, createAdminUIApp } from "./admin-ui.ts";
|
|
14
14
|
import { registerAdminGithubEnterpriseRoutes } from "./admin-ui-github-enterprise.ts";
|
|
15
15
|
import { parseAdminApiKeys } from "./api-auth.ts";
|
|
16
16
|
import { createGithubEnterpriseApp } from "./github-enterprise-api.ts";
|
|
@@ -29,20 +29,28 @@ const { privateKey: PEM } = generateKeyPairSync("rsa", {
|
|
|
29
29
|
function fakeAppService() {
|
|
30
30
|
const rows = new Map<string, GitHubEnterpriseAppMetadata & { pem: string }>();
|
|
31
31
|
const now = new Date("2026-11-09T12:00:00Z");
|
|
32
|
+
const key = (role: string, accountId?: string | null) =>
|
|
33
|
+
`${accountId ?? ""}/${role}`;
|
|
32
34
|
const strip = ({
|
|
33
35
|
pem: _p,
|
|
34
36
|
...m
|
|
35
37
|
}: GitHubEnterpriseAppMetadata & { pem: string }) => m;
|
|
38
|
+
// Account row wins, else the deployment-wide row.
|
|
39
|
+
const resolve = (role: string, accountId?: string | null) =>
|
|
40
|
+
rows.get(key(role, accountId)) ?? rows.get(key(role));
|
|
36
41
|
return {
|
|
37
|
-
async list() {
|
|
38
|
-
return [...rows.values()]
|
|
42
|
+
async list(accountId?: string | null) {
|
|
43
|
+
return [...rows.values()]
|
|
44
|
+
.filter((r) => (r.accountId ?? null) === (accountId ?? null))
|
|
45
|
+
.map(strip);
|
|
39
46
|
},
|
|
40
|
-
async get(role: GitHubEnterpriseAppRole) {
|
|
41
|
-
const r =
|
|
47
|
+
async get(role: GitHubEnterpriseAppRole, accountId?: string | null) {
|
|
48
|
+
const r = resolve(role, accountId);
|
|
42
49
|
return r ? strip(r) : null;
|
|
43
50
|
},
|
|
44
51
|
async save(input: SaveGitHubEnterpriseAppInput) {
|
|
45
52
|
const row = {
|
|
53
|
+
accountId: input.accountId ?? null,
|
|
46
54
|
role: input.role,
|
|
47
55
|
appId: input.appId,
|
|
48
56
|
slug: input.slug,
|
|
@@ -55,20 +63,24 @@ function fakeAppService() {
|
|
|
55
63
|
updatedAt: now,
|
|
56
64
|
pem: input.privateKey,
|
|
57
65
|
} as GitHubEnterpriseAppMetadata & { pem: string };
|
|
58
|
-
rows.set(input.role, row);
|
|
66
|
+
rows.set(key(input.role, input.accountId), row);
|
|
59
67
|
return strip(row);
|
|
60
68
|
},
|
|
61
|
-
async delete(role: GitHubEnterpriseAppRole) {
|
|
62
|
-
rows.delete(role);
|
|
69
|
+
async delete(role: GitHubEnterpriseAppRole, accountId?: string | null) {
|
|
70
|
+
rows.delete(key(role, accountId));
|
|
63
71
|
},
|
|
64
|
-
async getPrivateKey(
|
|
65
|
-
|
|
72
|
+
async getPrivateKey(
|
|
73
|
+
role: GitHubEnterpriseAppRole,
|
|
74
|
+
accountId?: string | null,
|
|
75
|
+
) {
|
|
76
|
+
return resolve(role, accountId)?.pem ?? null;
|
|
66
77
|
},
|
|
67
78
|
async recordValidation(
|
|
68
79
|
role: GitHubEnterpriseAppRole,
|
|
69
80
|
r: { status: string; error: string | null },
|
|
81
|
+
accountId?: string | null,
|
|
70
82
|
) {
|
|
71
|
-
const row = rows.get(role);
|
|
83
|
+
const row = rows.get(key(role, accountId));
|
|
72
84
|
if (row) {
|
|
73
85
|
row.lastValidationStatus = r.status;
|
|
74
86
|
row.lastValidationError = r.error;
|
|
@@ -78,7 +90,9 @@ function fakeAppService() {
|
|
|
78
90
|
};
|
|
79
91
|
}
|
|
80
92
|
|
|
81
|
-
function setup(
|
|
93
|
+
function setup(
|
|
94
|
+
opts: { isAdmin?: boolean; fetchStatus?: number; accounts?: boolean } = {},
|
|
95
|
+
) {
|
|
82
96
|
const appService = fakeAppService();
|
|
83
97
|
const fetchCalls: string[] = [];
|
|
84
98
|
const fetchFn = (async (input: RequestInfo | URL) => {
|
|
@@ -116,6 +130,16 @@ function setup(opts: { isAdmin?: boolean; fetchStatus?: number } = {}) {
|
|
|
116
130
|
c.set("isAdmin", opts.isAdmin ?? true);
|
|
117
131
|
await next();
|
|
118
132
|
}) as MiddlewareHandler<AdminUIEnv>,
|
|
133
|
+
...(opts.accounts
|
|
134
|
+
? {
|
|
135
|
+
accounts: {
|
|
136
|
+
listWithCounts: async () => [
|
|
137
|
+
{ id: "acct-1", name: "Acme" },
|
|
138
|
+
{ id: "acct-2", name: "Globex" },
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
}
|
|
142
|
+
: {}),
|
|
119
143
|
html: (content, o) =>
|
|
120
144
|
new Response(content, {
|
|
121
145
|
status: o?.status ?? 200,
|
|
@@ -169,6 +193,105 @@ describe("GET /admin/settings/github-enterprise", () => {
|
|
|
169
193
|
});
|
|
170
194
|
});
|
|
171
195
|
|
|
196
|
+
const saveForm = (
|
|
197
|
+
appId: string,
|
|
198
|
+
slug: string,
|
|
199
|
+
extra: Record<string, string> = {},
|
|
200
|
+
) => form({ appId, slug, privateKey: PEM, ...extra });
|
|
201
|
+
|
|
202
|
+
describe("lookup card without an installer", () => {
|
|
203
|
+
it("shows manual per-org install steps with the lookup slug link", async () => {
|
|
204
|
+
const { app } = setup();
|
|
205
|
+
await app.request(`${BASE}/apps/lookup`, saveForm("7", "my-lookup"));
|
|
206
|
+
const html = await (await app.request(BASE)).text();
|
|
207
|
+
expect(html).toContain("gh-ent-lookup-only");
|
|
208
|
+
expect(html).toContain(
|
|
209
|
+
"https://github.com/apps/my-lookup/installations/new",
|
|
210
|
+
);
|
|
211
|
+
expect(html).toContain("GitHub Enterprise Cloud is not needed");
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("shows a slug placeholder link when no lookup App is known", async () => {
|
|
215
|
+
const { app } = setup();
|
|
216
|
+
const html = await (await app.request(BASE)).text();
|
|
217
|
+
expect(html).toContain("gh-ent-lookup-only");
|
|
218
|
+
expect(html).toContain("github.com/apps/<slug>/installations/new");
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("keeps the existing instructions once an installer exists", async () => {
|
|
222
|
+
const { app } = setup();
|
|
223
|
+
await app.request(
|
|
224
|
+
`${BASE}/apps/installer`,
|
|
225
|
+
saveForm("1", "inst", { enterpriseSlug: "ent" }),
|
|
226
|
+
);
|
|
227
|
+
const html = await (await app.request(BASE)).text();
|
|
228
|
+
expect(html).not.toContain("gh-ent-lookup-only");
|
|
229
|
+
expect(html).toContain("It must be installed on all repositories");
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
describe("account selector", () => {
|
|
234
|
+
it("is hidden without an accounts dependency", async () => {
|
|
235
|
+
const { app } = setup();
|
|
236
|
+
expect(await (await app.request(BASE)).text()).not.toContain(
|
|
237
|
+
"gh-ent-account-selector",
|
|
238
|
+
);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("renders on both cards with the default and each account", async () => {
|
|
242
|
+
const { app } = setup({ accounts: true });
|
|
243
|
+
const html = await (await app.request(`${BASE}?accountId=acct-2`)).text();
|
|
244
|
+
expect(html.match(/gh-ent-account-selector/g)?.length).toBe(2);
|
|
245
|
+
expect(html).toContain("Deployment-wide default");
|
|
246
|
+
expect(html).toContain('<option value="acct-1">Acme</option>');
|
|
247
|
+
expect(html).toContain('<option value="acct-2" selected>Globex</option>');
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("saves under the chosen account and marks own vs fallback", async () => {
|
|
251
|
+
const { app, appService } = setup({ accounts: true });
|
|
252
|
+
await app.request(`${BASE}/apps/lookup`, saveForm("7", "shared-lookup"));
|
|
253
|
+
const res = await app.request(
|
|
254
|
+
`${BASE}/apps/lookup?accountId=acct-1`,
|
|
255
|
+
saveForm("8", "acme-lookup"),
|
|
256
|
+
);
|
|
257
|
+
expect(res.status).toBe(302);
|
|
258
|
+
expect(res.headers.get("location")).toBe(
|
|
259
|
+
`${BASE}?notice=saved&accountId=acct-1`,
|
|
260
|
+
);
|
|
261
|
+
expect((await appService.list("acct-1"))[0]?.slug).toBe("acme-lookup");
|
|
262
|
+
expect((await appService.list())[0]?.slug).toBe("shared-lookup");
|
|
263
|
+
|
|
264
|
+
const own = await (await app.request(`${BASE}?accountId=acct-1`)).text();
|
|
265
|
+
expect(own).toContain("Account's own App");
|
|
266
|
+
const fallback = await (
|
|
267
|
+
await app.request(`${BASE}?accountId=acct-2`)
|
|
268
|
+
).text();
|
|
269
|
+
expect(fallback).toContain("Deployment-wide fallback");
|
|
270
|
+
expect(fallback).toContain("shared-lookup");
|
|
271
|
+
expect(fallback).toContain(`action="${BASE}/apps/lookup?accountId=acct-2"`);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("validates and deletes against the chosen account", async () => {
|
|
275
|
+
const { app, appService } = setup({ accounts: true });
|
|
276
|
+
await app.request(
|
|
277
|
+
`${BASE}/apps/installer?accountId=acct-1`,
|
|
278
|
+
saveForm("1", "inst", { enterpriseSlug: "ent" }),
|
|
279
|
+
);
|
|
280
|
+
const v = await app.request(
|
|
281
|
+
`${BASE}/apps/installer/validate?accountId=acct-1`,
|
|
282
|
+
{ method: "POST" },
|
|
283
|
+
);
|
|
284
|
+
expect(v.headers.get("location")).toContain("accountId=acct-1");
|
|
285
|
+
expect((await appService.list("acct-1"))[0]?.lastValidationStatus).toBe(
|
|
286
|
+
"valid",
|
|
287
|
+
);
|
|
288
|
+
await app.request(`${BASE}/apps/installer/delete?accountId=acct-1`, {
|
|
289
|
+
method: "POST",
|
|
290
|
+
});
|
|
291
|
+
expect(await appService.list("acct-1")).toEqual([]);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
172
295
|
const upload = (fields: Record<string, string>, file?: File) => {
|
|
173
296
|
const body = new FormData();
|
|
174
297
|
for (const [k, v] of Object.entries(fields)) body.set(k, v);
|