@app-vitals/agent-admin 1.133.0 → 1.135.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 +35 -2
- package/package.json +2 -2
- package/src/admin-ui-agent-detail-help.unit.test.ts +12 -0
- package/src/admin-ui-github-identity-pages.unit.test.ts +1 -3
- package/src/admin-ui-help-catalogue.ts +85 -0
- package/src/admin-ui-help-catalogue.unit.test.ts +24 -1
- package/src/admin-ui-installation-repos-pages.ts +6 -5
- package/src/admin-ui-installation-repos-pages.unit.test.ts +1 -1
- package/src/admin-ui-installation-repos.smoke.test.ts +1 -1
- package/src/admin-ui-new-agent-help.unit.test.ts +10 -2
- package/src/admin-ui-pages.ts +46 -14
- package/src/admin-ui-pages.unit.test.ts +88 -14
- package/src/admin-ui-templates-pages.ts +3 -2
- package/src/admin-ui-templates.smoke.test.ts +1 -1
- package/src/admin-ui.smoke.test.ts +4 -6
- package/src/admin-ui.ts +1 -1
- package/src/agent-github-installations.integration.test.ts +20 -0
- package/src/agents-api.smoke.test.ts +33 -0
- package/src/fixtures/github-enterprise-cassette.json +89 -0
- package/src/github-enterprise-api-apps.unit.test.ts +82 -0
- package/src/github-enterprise-api.integration.test.ts +135 -0
- package/src/github-enterprise-api.smoke.test.ts +200 -0
- package/src/github-enterprise-api.ts +118 -15
- package/src/openapi-schemas.ts +30 -2
|
@@ -2402,7 +2402,7 @@ describe("renderAgentDetailPage — sections", () => {
|
|
|
2402
2402
|
|
|
2403
2403
|
test("Automation renders only the cron jobs card", () => {
|
|
2404
2404
|
const html = render("automation");
|
|
2405
|
-
expect(html).toContain('<div class="card-title">Cron Jobs
|
|
2405
|
+
expect(html).toContain('<div class="card-title">Cron Jobs');
|
|
2406
2406
|
expect(html).toContain('action="/admin/agents/agent-123/crons"');
|
|
2407
2407
|
expect(html).not.toContain('class="stat-strip"');
|
|
2408
2408
|
expect(html).not.toContain("Danger Zone");
|
|
@@ -2414,9 +2414,9 @@ describe("renderAgentDetailPage — sections", () => {
|
|
|
2414
2414
|
const html = render("configuration");
|
|
2415
2415
|
const idx = [
|
|
2416
2416
|
'id="env-vars"',
|
|
2417
|
-
'<div class="card-title">Repos
|
|
2417
|
+
'<div class="card-title">Repos',
|
|
2418
2418
|
'id="ext-config"',
|
|
2419
|
-
'<div class="card-title">Agent Policy
|
|
2419
|
+
'<div class="card-title">Agent Policy',
|
|
2420
2420
|
].map((m) => html.indexOf(m));
|
|
2421
2421
|
expect(idx.every((i) => i > -1)).toBe(true);
|
|
2422
2422
|
expect([...idx].sort((x, y) => x - y)).toEqual(idx);
|
|
@@ -2442,7 +2442,7 @@ describe("renderAgentDetailPage — sections", () => {
|
|
|
2442
2442
|
expect(html).not.toContain('<div class="card-title">Slack access</div>');
|
|
2443
2443
|
expect(html).toContain("Task Store Tokens");
|
|
2444
2444
|
expect(html).toContain('action="/admin/agents/agent-123/tokens"');
|
|
2445
|
-
expect(html).not.toContain('<div class="card-title">Tools
|
|
2445
|
+
expect(html).not.toContain('<div class="card-title">Tools');
|
|
2446
2446
|
expect(html).not.toContain("Cron Jobs");
|
|
2447
2447
|
});
|
|
2448
2448
|
|
|
@@ -2460,8 +2460,8 @@ describe("renderAgentDetailPage — sections", () => {
|
|
|
2460
2460
|
expect(html).toContain('action="/admin/agents/agent-123/tools"');
|
|
2461
2461
|
expect(html).toContain('action="/admin/agents/agent-123/plugins"');
|
|
2462
2462
|
expect(html).toContain('action="/admin/agents/agent-123/marketplaces"');
|
|
2463
|
-
expect(html).toContain('<div class="card-title">Tools
|
|
2464
|
-
expect(html).toContain('<div class="card-title">Plugins
|
|
2463
|
+
expect(html).toContain('<div class="card-title">Tools');
|
|
2464
|
+
expect(html).toContain('<div class="card-title">Plugins');
|
|
2465
2465
|
expect(html).toContain('<div class="card-title">Marketplaces</div>');
|
|
2466
2466
|
expect(html).not.toContain("Task Store Tokens");
|
|
2467
2467
|
});
|
|
@@ -2524,10 +2524,16 @@ describe("renderAgentDetailPage — stat strip", () => {
|
|
|
2524
2524
|
|
|
2525
2525
|
test("stat tiles appear in order: crons active, missing env vars, members, repos", () => {
|
|
2526
2526
|
const html = render();
|
|
2527
|
-
const cronsIndex = html.indexOf(
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
const
|
|
2527
|
+
const cronsIndex = html.indexOf(
|
|
2528
|
+
'<div class="stat-tile-label">crons active</div>',
|
|
2529
|
+
);
|
|
2530
|
+
const envIndex = html.indexOf(
|
|
2531
|
+
'<div class="stat-tile-label">missing env vars</div>',
|
|
2532
|
+
);
|
|
2533
|
+
const membersIndex = html.indexOf(
|
|
2534
|
+
'<div class="stat-tile-label">members</div>',
|
|
2535
|
+
);
|
|
2536
|
+
const reposIndex = html.indexOf('<div class="stat-tile-label">repos</div>');
|
|
2531
2537
|
|
|
2532
2538
|
expect(cronsIndex).toBeGreaterThan(-1);
|
|
2533
2539
|
expect(envIndex).toBeGreaterThan(-1);
|
|
@@ -4528,10 +4534,10 @@ describe("renderAgentDetailPage — configuration card slots", () => {
|
|
|
4528
4534
|
'<div class="card">cfg-one</div>',
|
|
4529
4535
|
'<div class="card">cfg-two</div>',
|
|
4530
4536
|
]);
|
|
4531
|
-
const repos = html.indexOf('<div class="card-title">Repos
|
|
4537
|
+
const repos = html.indexOf('<div class="card-title">Repos');
|
|
4532
4538
|
const one = html.indexOf("cfg-one");
|
|
4533
4539
|
const two = html.indexOf("cfg-two");
|
|
4534
|
-
const policy = html.indexOf('<div class="card-title">Agent Policy
|
|
4540
|
+
const policy = html.indexOf('<div class="card-title">Agent Policy');
|
|
4535
4541
|
expect(repos).toBeGreaterThan(-1);
|
|
4536
4542
|
expect(repos).toBeLessThan(one);
|
|
4537
4543
|
expect(one).toBeLessThan(two);
|
|
@@ -4873,8 +4879,7 @@ describe("renderAgentDetailPage — cron help tooltips", () => {
|
|
|
4873
4879
|
{ timezone: "UTC", section: "automation", cronHelp },
|
|
4874
4880
|
);
|
|
4875
4881
|
}
|
|
4876
|
-
const tipCount = (html: string) =>
|
|
4877
|
-
html.split('class="info-tip-btn"').length - 1;
|
|
4882
|
+
const tipCount = (html: string) => html.split('id="cron-help-').length - 1;
|
|
4878
4883
|
|
|
4879
4884
|
test("a system row and a phase row each get exactly one tooltip", () => {
|
|
4880
4885
|
const html = render([SYSTEM_CRON, PHASE], lookup);
|
|
@@ -4907,3 +4912,72 @@ describe("renderAgentDetailPage — cron help tooltips", () => {
|
|
|
4907
4912
|
expect(tipCount(html)).toBe(0);
|
|
4908
4913
|
});
|
|
4909
4914
|
});
|
|
4915
|
+
|
|
4916
|
+
// ─── renderAgentDetailPage — help tooltips (9.3) ─────────────────────────────
|
|
4917
|
+
|
|
4918
|
+
describe("renderAgentDetailPage — help tooltips", () => {
|
|
4919
|
+
const renderSection = (section: (typeof AGENT_SECTIONS)[number]) =>
|
|
4920
|
+
renderAgentDetailSection(
|
|
4921
|
+
AGENT,
|
|
4922
|
+
{},
|
|
4923
|
+
[SYSTEM_CRON, CUSTOM_CRON],
|
|
4924
|
+
[TOOL_ENABLED],
|
|
4925
|
+
[TOKEN_ACTIVE],
|
|
4926
|
+
[PLUGIN_ENABLED],
|
|
4927
|
+
[],
|
|
4928
|
+
USER_NAME,
|
|
4929
|
+
true,
|
|
4930
|
+
{ timezone: "UTC", template: { detached: false }, section },
|
|
4931
|
+
);
|
|
4932
|
+
const count = (html: string, needle: string) => html.split(needle).length - 1;
|
|
4933
|
+
const EXPECTED: Record<(typeof AGENT_SECTIONS)[number], string[]> = {
|
|
4934
|
+
general: [],
|
|
4935
|
+
automation: [
|
|
4936
|
+
"cron-system-vs-custom",
|
|
4937
|
+
"cron-schedule",
|
|
4938
|
+
"cron-precheck",
|
|
4939
|
+
"cron-target",
|
|
4940
|
+
],
|
|
4941
|
+
configuration: [
|
|
4942
|
+
"template-following-detached",
|
|
4943
|
+
"template-row-source",
|
|
4944
|
+
"repo-uncovered",
|
|
4945
|
+
"agent-policy",
|
|
4946
|
+
],
|
|
4947
|
+
access: ["owner-identities", "task-store-tokens"],
|
|
4948
|
+
extensions: [
|
|
4949
|
+
"tools-pattern",
|
|
4950
|
+
"plugins",
|
|
4951
|
+
"marketplace-ref",
|
|
4952
|
+
"marketplace-origin",
|
|
4953
|
+
],
|
|
4954
|
+
};
|
|
4955
|
+
|
|
4956
|
+
for (const section of AGENT_SECTIONS) {
|
|
4957
|
+
for (const id of EXPECTED[section]) {
|
|
4958
|
+
test(`${section} renders help-${id} once`, () => {
|
|
4959
|
+
expect(count(renderSection(section), `id="help-${id}"`)).toBe(1);
|
|
4960
|
+
});
|
|
4961
|
+
}
|
|
4962
|
+
}
|
|
4963
|
+
|
|
4964
|
+
test("no help tip renders inside a scrolling table wrapper", () => {
|
|
4965
|
+
const html = AGENT_SECTIONS.map(renderSection).join("");
|
|
4966
|
+
const wrappers =
|
|
4967
|
+
html.match(/<div class="data-table-wrapper">[\s\S]*?<\/table>/g) ?? [];
|
|
4968
|
+
expect(wrappers.length).toBeGreaterThan(0);
|
|
4969
|
+
for (const w of wrappers) expect(w).not.toContain('id="help-');
|
|
4970
|
+
});
|
|
4971
|
+
|
|
4972
|
+
test("repeated badges carry no per-badge title", () => {
|
|
4973
|
+
const html = AGENT_SECTIONS.map(renderSection).join("");
|
|
4974
|
+
for (const t of [
|
|
4975
|
+
"Inherited from the agent template",
|
|
4976
|
+
"Set on this agent; overrides the template",
|
|
4977
|
+
"Comes from the agent image",
|
|
4978
|
+
"Removed from this agent; the template no longer re-adds it",
|
|
4979
|
+
]) {
|
|
4980
|
+
expect(html).not.toContain(`title="${t}`);
|
|
4981
|
+
}
|
|
4982
|
+
});
|
|
4983
|
+
});
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* the stored secret.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
import { renderHelpTip } from "./admin-ui-help-catalogue.ts";
|
|
11
12
|
import { renderAdminPage } from "./admin-ui-layout.ts";
|
|
12
13
|
import {
|
|
13
14
|
buildSettingsNav,
|
|
@@ -45,7 +46,7 @@ export function managedByBadge(
|
|
|
45
46
|
item: Pick<TemplateItemRow, "managedBy">,
|
|
46
47
|
): string {
|
|
47
48
|
return item.managedBy === "helm"
|
|
48
|
-
? ` <span class="badge badge-template"
|
|
49
|
+
? ` <span class="badge badge-template">from Helm values</span>`
|
|
49
50
|
: "";
|
|
50
51
|
}
|
|
51
52
|
|
|
@@ -187,7 +188,7 @@ export function renderTemplatesPage(o: TemplatesPageOpts): string {
|
|
|
187
188
|
isOwner: true,
|
|
188
189
|
body: `${error}${notice}${blocked}
|
|
189
190
|
<div class="card">
|
|
190
|
-
<p class="help-text">Default env vars, tools, plugins, crons and plugin marketplaces for new agents in a scope. Secret values are masked after saving; leave <code>***</code> to keep the stored value
|
|
191
|
+
<p class="help-text">Default env vars, tools, plugins, crons and plugin marketplaces for new agents in a scope. Secret values are masked after saving; leave <code>***</code> to keep the stored value.${renderHelpTip("template-managed-by", "from Helm values")}</p>
|
|
191
192
|
${scopePicker(o)}
|
|
192
193
|
${del}
|
|
193
194
|
</div>
|
|
@@ -325,7 +325,7 @@ describe("/admin/settings/templates smoke", () => {
|
|
|
325
325
|
const res = await app.request(BASE);
|
|
326
326
|
expect(res.status).toBe(200);
|
|
327
327
|
const html = await res.text();
|
|
328
|
-
expect(html.match(
|
|
328
|
+
expect(html.match(/>from Helm values</g)).toHaveLength(1);
|
|
329
329
|
const seeded = html.slice(
|
|
330
330
|
html.indexOf('data-key="seeded@example-plugins"'),
|
|
331
331
|
html.indexOf('data-key="manual@example-plugins"'),
|
|
@@ -1894,7 +1894,7 @@ describe("admin UI — authenticated pages", () => {
|
|
|
1894
1894
|
expect(res.status).toBe(200);
|
|
1895
1895
|
const html = await res.text();
|
|
1896
1896
|
// Tools card should appear for self-hosted agents
|
|
1897
|
-
expect(html).toContain('<div class="card-title">Tools
|
|
1897
|
+
expect(html).toContain('<div class="card-title">Tools');
|
|
1898
1898
|
// Tools should be rendered
|
|
1899
1899
|
expect(html).toContain("Bash(git:*)");
|
|
1900
1900
|
});
|
|
@@ -2323,9 +2323,7 @@ describe("admin UI — owner and Anthropic identity section (PAI-2.5)", () => {
|
|
|
2323
2323
|
});
|
|
2324
2324
|
expect(res.status).toBe(200);
|
|
2325
2325
|
const html = await res.text();
|
|
2326
|
-
expect(html).toContain(
|
|
2327
|
-
'<div class="card-title">Owner & identities</div>',
|
|
2328
|
-
);
|
|
2326
|
+
expect(html).toContain('<div class="card-title">Owner & identities');
|
|
2329
2327
|
expect(html).toContain("Owner email");
|
|
2330
2328
|
expect(html).toContain("jane.doe@example.com");
|
|
2331
2329
|
expect(html).toContain("Anthropic identity name");
|
|
@@ -2362,7 +2360,7 @@ describe("admin UI — owner and Anthropic identity section (PAI-2.5)", () => {
|
|
|
2362
2360
|
expect(res.status).toBe(200);
|
|
2363
2361
|
const html = await res.text();
|
|
2364
2362
|
const start = html.indexOf(
|
|
2365
|
-
'<div class="card-title">Owner & identities
|
|
2363
|
+
'<div class="card-title">Owner & identities',
|
|
2366
2364
|
);
|
|
2367
2365
|
expect(start).toBeGreaterThan(-1);
|
|
2368
2366
|
const sectionHtml = html.slice(start, html.indexOf("</table>", start));
|
|
@@ -2384,7 +2382,7 @@ describe("admin UI — agent policy fields", () => {
|
|
|
2384
2382
|
});
|
|
2385
2383
|
expect(res.status).toBe(200);
|
|
2386
2384
|
const html = await res.text();
|
|
2387
|
-
expect(html).toContain('<div class="card-title">Agent Policy
|
|
2385
|
+
expect(html).toContain('<div class="card-title">Agent Policy');
|
|
2388
2386
|
|
|
2389
2387
|
// Booleans default true/false/true — checkboxes reflect DB column defaults.
|
|
2390
2388
|
const autoPostReviewsInput = html.match(
|
package/src/admin-ui.ts
CHANGED
|
@@ -151,6 +151,7 @@ import {
|
|
|
151
151
|
scopeIncludesAgent,
|
|
152
152
|
type ViewerRole,
|
|
153
153
|
} from "./caller-scope.ts";
|
|
154
|
+
import { buildCronHelpLookup } from "./cron-help.ts";
|
|
154
155
|
import {
|
|
155
156
|
creatorFromScope,
|
|
156
157
|
type EnsureAccountMemberResult,
|
|
@@ -210,7 +211,6 @@ import {
|
|
|
210
211
|
SlackProvisioningService,
|
|
211
212
|
} from "./slack-provisioning-service.ts";
|
|
212
213
|
import type { SpecialtyDefaultsResolver } from "./specialty-defaults.ts";
|
|
213
|
-
import { buildCronHelpLookup } from "./cron-help.ts";
|
|
214
214
|
import {
|
|
215
215
|
type SpecialtyTypeResolver,
|
|
216
216
|
SpecialtyTypes,
|
|
@@ -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);
|
|
@@ -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
|
+
});
|
|
@@ -17,6 +17,7 @@ import type { PrismaClient } from "../prisma/client/client.ts";
|
|
|
17
17
|
import type { AdminUIEnv } from "./admin-ui.ts";
|
|
18
18
|
import { registerAdminGithubEnterpriseRoutes } from "./admin-ui-github-enterprise.ts";
|
|
19
19
|
import { AgentEnvService } from "./agent-envs.ts";
|
|
20
|
+
import { AgentGitHubAppService } from "./agent-github-apps.ts";
|
|
20
21
|
import { AgentPluginService } from "./agent-plugins.ts";
|
|
21
22
|
import { AgentService } from "./agents.ts";
|
|
22
23
|
import { createAgentRuntimeApp } from "./api.ts";
|
|
@@ -307,6 +308,51 @@ describeOrSkip("github-enterprise API (integration)", () => {
|
|
|
307
308
|
expect(((await res.json()) as { error: string }).error).toMatch(/private/i);
|
|
308
309
|
});
|
|
309
310
|
|
|
311
|
+
it("install with several stored apps requires appId and installs the named one", async () => {
|
|
312
|
+
const agent = await prisma.agent.create({ data: { name: "Ghe Agent" } });
|
|
313
|
+
const apps = new AgentGitHubAppService(prisma, identityCrypto);
|
|
314
|
+
for (const [id, slug, clientId] of [
|
|
315
|
+
["777", "target-app", "Iv1.targetapp0001"],
|
|
316
|
+
["888", "second-app", "Iv1.secondapp0002"],
|
|
317
|
+
] as const) {
|
|
318
|
+
await apps.create(agent.id, {
|
|
319
|
+
appId: id,
|
|
320
|
+
slug,
|
|
321
|
+
clientId,
|
|
322
|
+
privateKey: PEM,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
const app = createGithubEnterpriseApp({
|
|
326
|
+
appService,
|
|
327
|
+
agentService: new AgentService(prisma),
|
|
328
|
+
agentEnvService: new AgentEnvService(prisma, identityCrypto),
|
|
329
|
+
agentGitHubAppService: apps,
|
|
330
|
+
sessionSecret: "test-secret-32chars-for-ghe-api!!",
|
|
331
|
+
adminApiKeys: parseAdminApiKeys("root:tok-admin:*"),
|
|
332
|
+
agentTokenService: { validate: async () => null },
|
|
333
|
+
fetchFn: replay({
|
|
334
|
+
"GET /enterprises/acme/installation": "enterprise_installation_success",
|
|
335
|
+
"POST /app/installations/4242/access_tokens": "access_token_success",
|
|
336
|
+
"POST /enterprises/acme/apps/organizations/org-1/installations":
|
|
337
|
+
"install_second_created",
|
|
338
|
+
}),
|
|
339
|
+
apiBase: "https://ghe.test",
|
|
340
|
+
});
|
|
341
|
+
await put(app as never);
|
|
342
|
+
const post = (body: object) =>
|
|
343
|
+
app.request("/github-enterprise/orgs/org-1/install", {
|
|
344
|
+
method: "POST",
|
|
345
|
+
headers: { ...ADMIN, "Content-Type": "application/json" },
|
|
346
|
+
body: JSON.stringify({ agentId: agent.id, ...body }),
|
|
347
|
+
});
|
|
348
|
+
expect((await post({})).status).toBe(422);
|
|
349
|
+
const res = await post({ appId: "888" });
|
|
350
|
+
expect(res.status).toBe(200);
|
|
351
|
+
expect(await res.json()).toMatchObject({
|
|
352
|
+
installation: { appSlug: "second-app" },
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
|
|
310
356
|
it("isolation: no agent-facing path returns the stored key", async () => {
|
|
311
357
|
const agent = await prisma.agent.create({ data: { name: "Iso Agent" } });
|
|
312
358
|
const envService = new AgentEnvService(prisma, identityCrypto);
|
|
@@ -454,6 +500,79 @@ describeOrSkip("DELETE /orgs/{org}/install (integration)", () => {
|
|
|
454
500
|
return { agent, del, blocked };
|
|
455
501
|
}
|
|
456
502
|
|
|
503
|
+
async function setupTwoApps() {
|
|
504
|
+
const appService = new GitHubEnterpriseAppService(
|
|
505
|
+
prisma,
|
|
506
|
+
makeStrictTokenCrypto(ENC_KEY),
|
|
507
|
+
);
|
|
508
|
+
await appService.save({
|
|
509
|
+
role: "installer",
|
|
510
|
+
appId: "12345",
|
|
511
|
+
slug: "example-installer",
|
|
512
|
+
enterpriseSlug: "acme",
|
|
513
|
+
privateKey: PEM,
|
|
514
|
+
});
|
|
515
|
+
const envService = new AgentEnvService(prisma, identityCrypto);
|
|
516
|
+
const agent = await prisma.agent.create({
|
|
517
|
+
data: {
|
|
518
|
+
name: "Uninstall Agent",
|
|
519
|
+
repos: ["acme-eng/a", "acme-eng/b", "other/c"],
|
|
520
|
+
},
|
|
521
|
+
});
|
|
522
|
+
const apps = new AgentGitHubAppService(prisma, identityCrypto);
|
|
523
|
+
for (const [id, slug, clientId] of [
|
|
524
|
+
["777", "target-app", "Iv1.targetapp0001"],
|
|
525
|
+
["888", "second-app", "Iv1.secondapp0002"],
|
|
526
|
+
] as const) {
|
|
527
|
+
await apps.create(agent.id, {
|
|
528
|
+
appId: id,
|
|
529
|
+
slug,
|
|
530
|
+
clientId,
|
|
531
|
+
privateKey: PEM,
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
const deleted: string[] = [];
|
|
535
|
+
const fetchFn = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
536
|
+
const u = new URL(input.toString());
|
|
537
|
+
const key = `${init?.method ?? "GET"} ${u.pathname}`;
|
|
538
|
+
const json = (k: string) =>
|
|
539
|
+
new Response(JSON.stringify(cassette[k]?.body), {
|
|
540
|
+
status: cassette[k]?.status,
|
|
541
|
+
});
|
|
542
|
+
if (key === "GET /enterprises/acme/installation")
|
|
543
|
+
return json("enterprise_installation_success");
|
|
544
|
+
if (key === "POST /app/installations/4242/access_tokens")
|
|
545
|
+
return json("access_token_success");
|
|
546
|
+
if (
|
|
547
|
+
key ===
|
|
548
|
+
"GET /enterprises/acme/apps/organizations/acme-eng/installations"
|
|
549
|
+
)
|
|
550
|
+
return json("org_installations_two_apps");
|
|
551
|
+
const m = key.match(/^DELETE .*\/installations\/(\d+)$/);
|
|
552
|
+
if (m) {
|
|
553
|
+
deleted.push(m[1] as string);
|
|
554
|
+
return new Response(null, { status: 204 });
|
|
555
|
+
}
|
|
556
|
+
throw new Error(`no route for ${key}`);
|
|
557
|
+
}) as typeof fetch;
|
|
558
|
+
const app = createGithubEnterpriseApp({
|
|
559
|
+
appService,
|
|
560
|
+
agentService: new AgentService(prisma),
|
|
561
|
+
agentEnvService: envService,
|
|
562
|
+
agentGitHubAppService: apps,
|
|
563
|
+
sessionSecret: "test-secret-32chars-for-ghe-api!!",
|
|
564
|
+
adminApiKeys: parseAdminApiKeys("root:tok-admin:*"),
|
|
565
|
+
agentTokenService: { validate: async () => null },
|
|
566
|
+
uninstall: {
|
|
567
|
+
agents: new PrismaInstallationAgents(prisma, envService),
|
|
568
|
+
audit: new PrismaInstallationAudit(prisma),
|
|
569
|
+
},
|
|
570
|
+
fetchFn,
|
|
571
|
+
apiBase: "https://ghe.test",
|
|
572
|
+
});
|
|
573
|
+
return { agent, app, deleted };
|
|
574
|
+
}
|
|
575
|
+
|
|
457
576
|
it("updates the agent's repos and writes an applied audit row", async () => {
|
|
458
577
|
const { agent, del, blocked } = await setup(204);
|
|
459
578
|
const res = await del();
|
|
@@ -471,6 +590,22 @@ describeOrSkip("DELETE /orgs/{org}/install (integration)", () => {
|
|
|
471
590
|
expect(blocked.sort()).toEqual(["acme-eng/a", "acme-eng/b"]);
|
|
472
591
|
});
|
|
473
592
|
|
|
593
|
+
it("with two stored apps only the named app's installation is deleted and repos are kept", async () => {
|
|
594
|
+
const { agent, app, deleted } = await setupTwoApps();
|
|
595
|
+
const q = (extra: string) =>
|
|
596
|
+
app.request(
|
|
597
|
+
`/github-enterprise/orgs/acme-eng/install?agentId=${agent.id}${extra}`,
|
|
598
|
+
{ method: "DELETE", headers: ADMIN },
|
|
599
|
+
);
|
|
600
|
+
expect((await q("")).status).toBe(422);
|
|
601
|
+
expect((await q("&appId=888")).status).toBe(200);
|
|
602
|
+
expect(deleted).toEqual(["503"]);
|
|
603
|
+
const row = await prisma.agent.findUniqueOrThrow({
|
|
604
|
+
where: { id: agent.id },
|
|
605
|
+
});
|
|
606
|
+
expect(row.repos).toEqual(["acme-eng/a", "acme-eng/b", "other/c"]);
|
|
607
|
+
});
|
|
608
|
+
|
|
474
609
|
it("a GitHub refusal writes a failed audit row and keeps the repos", async () => {
|
|
475
610
|
const { agent, del } = await setup(403);
|
|
476
611
|
const res = await del();
|