@app-vitals/agent-admin 1.109.0 → 1.111.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.json +0 -193
- package/openapi.platform.json +1 -238
- package/package.json +2 -2
- package/src/admin-boot.ts +6 -5
- package/src/admin-ui-github-enterprise-pages.ts +13 -2
- package/src/admin-ui-github-enterprise.smoke.test.ts +20 -1
- package/src/admin-ui-github-enterprise.ts +16 -1
- package/src/admin-ui-github-identity-pages.ts +35 -139
- package/src/admin-ui-github-identity-pages.unit.test.ts +50 -173
- package/src/admin-ui-github-identity.smoke.test.ts +103 -63
- package/src/admin-ui-installation-repos-pages.ts +2 -23
- package/src/admin-ui-installation-repos-pages.unit.test.ts +41 -36
- package/src/admin-ui-installation-repos.smoke.test.ts +9 -8
- package/src/admin-ui-pages.ts +4 -5
- package/src/admin-ui-slack-config-token-pages.ts +11 -2
- package/src/admin-ui-slack-config-token.smoke.test.ts +39 -3
- package/src/admin-ui-slack-config-token.ts +51 -9
- package/src/admin-ui-templates-pages.ts +7 -1
- package/src/admin-ui-templates.smoke.test.ts +31 -5
- package/src/admin-ui-templates.ts +43 -8
- package/src/admin-ui.ts +51 -36
- package/src/agent-templates-api.integration.test.ts +29 -7
- package/src/agent-templates.ts +7 -1
- package/src/agents-api.smoke.test.ts +26 -315
- package/src/agents-api.ts +1 -107
- package/src/deployment-wide-settings.integration.test.ts +309 -0
- package/src/deployment-wide-settings.ts +42 -0
- package/src/github-access-preview.ts +2 -2
- package/src/github-agent-installation-crawler.ts +18 -1
- package/src/github-enterprise-api.integration.test.ts +7 -0
- package/src/github-enterprise-api.smoke.test.ts +26 -0
- package/src/github-enterprise-api.ts +24 -4
- package/src/github-enterprise-apps.integration.test.ts +33 -8
- package/src/github-enterprise-apps.ts +4 -0
- package/src/github-enterprise-client.integration.test.ts +0 -41
- package/src/github-enterprise-client.ts +0 -25
- package/src/github-enterprise-client.unit.test.ts +0 -18
- package/src/github-installation-wiring.ts +48 -13
- package/src/github-installation-wiring.unit.test.ts +38 -1
- package/src/github-sync-all-repos.unit.test.ts +116 -0
- package/src/github-sync-cache.integration.test.ts +9 -2
- package/src/github-sync-snapshot-refresh.integration.test.ts +168 -0
- package/src/github-sync-snapshot-refresh.unit.test.ts +144 -0
- package/src/github-sync.ts +103 -137
- package/src/github-sync.unit.test.ts +82 -1
- package/src/installation-ports.ts +1 -40
- package/src/installation-repos-service.ts +7 -4
- package/src/reconcile-open-work.integration.test.ts +0 -1
- package/src/slack-config-token.integration.test.ts +19 -2
- package/src/slack-config-token.ts +6 -1
- package/src/github-access-preview.integration.test.ts +0 -399
- package/src/github-sync-switch.integration.test.ts +0 -297
- package/src/github-sync-switch.unit.test.ts +0 -467
|
@@ -24,7 +24,6 @@ import type { AgentTokenService } from "./agent-tokens.ts";
|
|
|
24
24
|
import type { AdminDeps } from "./agents-api.ts";
|
|
25
25
|
import { createAdminApp, parseAdminApiKeys } from "./agents-api.ts";
|
|
26
26
|
import { PLATFORM_OPS_ROUTES } from "./api-auth.ts";
|
|
27
|
-
import { createGithubAccessPreview } from "./github-enterprise-api.ts";
|
|
28
27
|
import { accessFor, envWith } from "./github-installation.fixtures.ts";
|
|
29
28
|
import {
|
|
30
29
|
createGithubInstallationRepos,
|
|
@@ -7285,278 +7284,6 @@ describe("admin API — PATCH /agents/:id githubUsername (GHE-2.1)", () => {
|
|
|
7285
7284
|
});
|
|
7286
7285
|
});
|
|
7287
7286
|
|
|
7288
|
-
// ─── GHE-2.4: GET /agents/:id/github-access ──────────────────────────────────
|
|
7289
|
-
|
|
7290
|
-
describe("admin API — GET /agents/:id/github-access (GHE-2.4)", () => {
|
|
7291
|
-
const OPS = "gha-ops-token";
|
|
7292
|
-
const READER = "gha-read-token";
|
|
7293
|
-
const AGENT_KEY = "gha-agent-token";
|
|
7294
|
-
const ACCESS = {
|
|
7295
|
-
username: "octocat",
|
|
7296
|
-
outcome: "ok" as const,
|
|
7297
|
-
userVerified: true,
|
|
7298
|
-
orgs: [
|
|
7299
|
-
{
|
|
7300
|
-
org: "acme-eng",
|
|
7301
|
-
status: "ok" as const,
|
|
7302
|
-
repos: [
|
|
7303
|
-
{ fullName: "acme-eng/api", level: "write" as const, canPush: true },
|
|
7304
|
-
],
|
|
7305
|
-
unresolved: 0,
|
|
7306
|
-
},
|
|
7307
|
-
],
|
|
7308
|
-
unresolved: 0,
|
|
7309
|
-
complete: true,
|
|
7310
|
-
checkedAt: "2026-11-09T12:00:00.000Z",
|
|
7311
|
-
};
|
|
7312
|
-
|
|
7313
|
-
function setup(opts: {
|
|
7314
|
-
githubUsername?: string | null;
|
|
7315
|
-
preview?: AdminDeps["githubAccessPreview"];
|
|
7316
|
-
}) {
|
|
7317
|
-
const base = makeMockDeps();
|
|
7318
|
-
const calls: string[] = [];
|
|
7319
|
-
const deps: AdminDeps = {
|
|
7320
|
-
...base,
|
|
7321
|
-
adminApiKeys: parseAdminApiKeys(
|
|
7322
|
-
`root:${ADMIN_API_KEY}:*,operator:${OPS}:platform.ops,reader:${READER}:platform.read`,
|
|
7323
|
-
),
|
|
7324
|
-
agentTokenService: {
|
|
7325
|
-
...base.agentTokenService,
|
|
7326
|
-
validate: async (t: string) =>
|
|
7327
|
-
t === AGENT_KEY ? { agentId: AGENT_ID } : null,
|
|
7328
|
-
},
|
|
7329
|
-
agentService: {
|
|
7330
|
-
...base.agentService,
|
|
7331
|
-
getDetail: async (id: string) => {
|
|
7332
|
-
const d = await base.agentService.getDetail(id);
|
|
7333
|
-
return d ? { ...d, githubUsername: opts.githubUsername ?? null } : d;
|
|
7334
|
-
},
|
|
7335
|
-
},
|
|
7336
|
-
githubAccessPreview:
|
|
7337
|
-
opts.preview ??
|
|
7338
|
-
(async (u) => {
|
|
7339
|
-
calls.push(u);
|
|
7340
|
-
return { status: "ok", access: ACCESS };
|
|
7341
|
-
}),
|
|
7342
|
-
};
|
|
7343
|
-
return { app: createAdminApp(deps), calls };
|
|
7344
|
-
}
|
|
7345
|
-
|
|
7346
|
-
const get = (
|
|
7347
|
-
app: ReturnType<typeof createAdminApp>,
|
|
7348
|
-
headers: Record<string, string>,
|
|
7349
|
-
id = AGENT_ID,
|
|
7350
|
-
) => app.request(`/agents/${id}/github-access`, { headers });
|
|
7351
|
-
const asAdmin = { Authorization: `Bearer ${ADMIN_API_KEY}` };
|
|
7352
|
-
|
|
7353
|
-
it("platform admin gets the resolver output unchanged", async () => {
|
|
7354
|
-
const { app, calls } = setup({ githubUsername: "octocat" });
|
|
7355
|
-
const res = await get(app, asAdmin);
|
|
7356
|
-
expect(res.status).toBe(200);
|
|
7357
|
-
expect(await res.json()).toEqual({ status: "ok", access: ACCESS });
|
|
7358
|
-
expect(calls).toEqual(["octocat"]);
|
|
7359
|
-
});
|
|
7360
|
-
|
|
7361
|
-
it("403 for a session member, ops key, read key and agent key", async () => {
|
|
7362
|
-
const { app, calls } = setup({ githubUsername: "octocat" });
|
|
7363
|
-
const memberApp = createAdminApp({
|
|
7364
|
-
...makeMockDeps(),
|
|
7365
|
-
callerScopeResolver: async () => ({
|
|
7366
|
-
kind: "scoped",
|
|
7367
|
-
accountId: "acct-a",
|
|
7368
|
-
agentIds: [AGENT_ID],
|
|
7369
|
-
}),
|
|
7370
|
-
});
|
|
7371
|
-
const cookie = await sign(
|
|
7372
|
-
{
|
|
7373
|
-
isAdmin: false,
|
|
7374
|
-
userId: "user-acct",
|
|
7375
|
-
email: "owner@acct-a.example.com",
|
|
7376
|
-
iat: Math.floor(Date.now() / 1000),
|
|
7377
|
-
exp: Math.floor(Date.now() / 1000) + 3600,
|
|
7378
|
-
},
|
|
7379
|
-
SESSION_SECRET,
|
|
7380
|
-
"HS256",
|
|
7381
|
-
);
|
|
7382
|
-
expect(
|
|
7383
|
-
(await get(memberApp, { Cookie: `admin_session=${cookie}` })).status,
|
|
7384
|
-
).toBe(403);
|
|
7385
|
-
for (const key of [OPS, READER, AGENT_KEY]) {
|
|
7386
|
-
const res = await get(app, { Authorization: `Bearer ${key}` });
|
|
7387
|
-
expect(res.status).toBe(403);
|
|
7388
|
-
}
|
|
7389
|
-
expect(calls).toEqual([]);
|
|
7390
|
-
});
|
|
7391
|
-
|
|
7392
|
-
it("404 for an unknown agent", async () => {
|
|
7393
|
-
const { app, calls } = setup({ githubUsername: "octocat" });
|
|
7394
|
-
expect((await get(app, asAdmin, "no-such-agent")).status).toBe(404);
|
|
7395
|
-
expect(calls).toEqual([]);
|
|
7396
|
-
});
|
|
7397
|
-
|
|
7398
|
-
it("422 with a clear message when no githubUsername is bound", async () => {
|
|
7399
|
-
const { app, calls } = setup({ githubUsername: null });
|
|
7400
|
-
const res = await get(app, asAdmin);
|
|
7401
|
-
expect(res.status).toBe(422);
|
|
7402
|
-
expect(((await res.json()) as { error: string }).error).toContain(
|
|
7403
|
-
"githubUsername",
|
|
7404
|
-
);
|
|
7405
|
-
expect(calls).toEqual([]);
|
|
7406
|
-
});
|
|
7407
|
-
|
|
7408
|
-
it("unconfigured is a 200 status, not an error", async () => {
|
|
7409
|
-
const { app } = setup({
|
|
7410
|
-
githubUsername: "octocat",
|
|
7411
|
-
preview: async () => ({ status: "unconfigured" }),
|
|
7412
|
-
});
|
|
7413
|
-
const res = await get(app, asAdmin);
|
|
7414
|
-
expect(res.status).toBe(200);
|
|
7415
|
-
expect(await res.json()).toEqual({ status: "unconfigured" });
|
|
7416
|
-
});
|
|
7417
|
-
|
|
7418
|
-
describe("real preview over a fake GitHub (lookup-only and both Apps)", () => {
|
|
7419
|
-
const { privateKey: PEM } = generateKeyPairSync("rsa", {
|
|
7420
|
-
modulusLength: 2048,
|
|
7421
|
-
privateKeyEncoding: { type: "pkcs8", format: "pem" },
|
|
7422
|
-
publicKeyEncoding: { type: "spki", format: "pem" },
|
|
7423
|
-
});
|
|
7424
|
-
type Role = "installer" | "lookup";
|
|
7425
|
-
const record = (role: Role) => ({
|
|
7426
|
-
role,
|
|
7427
|
-
appId: role === "lookup" ? "555" : "12345",
|
|
7428
|
-
slug: `example-${role}`,
|
|
7429
|
-
enterpriseSlug: role === "installer" ? "acme" : null,
|
|
7430
|
-
});
|
|
7431
|
-
|
|
7432
|
-
function preview(roles: Role[]) {
|
|
7433
|
-
const paths: string[] = [];
|
|
7434
|
-
const json = (body: unknown, status = 200) =>
|
|
7435
|
-
new Response(JSON.stringify(body), {
|
|
7436
|
-
status,
|
|
7437
|
-
headers: { "Content-Type": "application/json" },
|
|
7438
|
-
});
|
|
7439
|
-
const fetchFn = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
7440
|
-
const path = new URL(input.toString()).pathname;
|
|
7441
|
-
paths.push(`${init?.method ?? "GET"} ${path}`);
|
|
7442
|
-
if (path === "/app/installations")
|
|
7443
|
-
return json([
|
|
7444
|
-
{ id: 7001, account: { login: "acme-eng", type: "Organization" } },
|
|
7445
|
-
]);
|
|
7446
|
-
if (path === "/enterprises/acme/installation")
|
|
7447
|
-
return json({
|
|
7448
|
-
id: 4242,
|
|
7449
|
-
access_tokens_url:
|
|
7450
|
-
"https://ghe.test/app/installations/4242/access_tokens",
|
|
7451
|
-
});
|
|
7452
|
-
if (path === "/app/installations/4242/access_tokens")
|
|
7453
|
-
return json({ token: "ghs_i", expires_at: "2099-01-01T00:00:00Z" });
|
|
7454
|
-
if (path === "/enterprises/acme/apps/installable_organizations")
|
|
7455
|
-
return json([{ id: 1, login: "acme-eng" }]);
|
|
7456
|
-
if (path === "/orgs/acme-eng/installation")
|
|
7457
|
-
return json({ id: 7001, repository_selection: "all" });
|
|
7458
|
-
if (path === "/app/installations/7001/access_tokens")
|
|
7459
|
-
return json({ token: "ghs_l", expires_at: "2099-01-01T00:00:00Z" });
|
|
7460
|
-
if (path === "/installation/repositories")
|
|
7461
|
-
return json({
|
|
7462
|
-
total_count: 1,
|
|
7463
|
-
repositories: [
|
|
7464
|
-
{
|
|
7465
|
-
id: 1,
|
|
7466
|
-
name: "api",
|
|
7467
|
-
full_name: "acme-eng/api",
|
|
7468
|
-
private: true,
|
|
7469
|
-
archived: false,
|
|
7470
|
-
},
|
|
7471
|
-
],
|
|
7472
|
-
});
|
|
7473
|
-
if (path === "/users/octocat")
|
|
7474
|
-
return json({ id: 9, login: "octocat", type: "User" });
|
|
7475
|
-
if (path === "/repos/acme-eng/api/collaborators/octocat/permission")
|
|
7476
|
-
return json({ permission: "write", role_name: "write" });
|
|
7477
|
-
return json({ message: "Not Found" }, 404);
|
|
7478
|
-
}) as typeof fetch;
|
|
7479
|
-
const appService = {
|
|
7480
|
-
get: async (role: Role) => (roles.includes(role) ? record(role) : null),
|
|
7481
|
-
getPrivateKey: async (role: Role) =>
|
|
7482
|
-
roles.includes(role) ? PEM : null,
|
|
7483
|
-
} as unknown as Parameters<
|
|
7484
|
-
typeof createGithubAccessPreview
|
|
7485
|
-
>[0]["appService"];
|
|
7486
|
-
return {
|
|
7487
|
-
paths,
|
|
7488
|
-
fn: createGithubAccessPreview({
|
|
7489
|
-
appService,
|
|
7490
|
-
fetchFn,
|
|
7491
|
-
apiBase: "https://ghe.test",
|
|
7492
|
-
now: () => new Date("2026-11-09T12:00:00Z"),
|
|
7493
|
-
}),
|
|
7494
|
-
};
|
|
7495
|
-
}
|
|
7496
|
-
|
|
7497
|
-
const expectedOrgs = [
|
|
7498
|
-
{
|
|
7499
|
-
org: "acme-eng",
|
|
7500
|
-
status: "ok",
|
|
7501
|
-
repos: [{ fullName: "acme-eng/api", level: "write", canPush: true }],
|
|
7502
|
-
unresolved: 0,
|
|
7503
|
-
},
|
|
7504
|
-
];
|
|
7505
|
-
|
|
7506
|
-
it("lookup-only: status ok with the repos the lookup App sees", async () => {
|
|
7507
|
-
const p = preview(["lookup"]);
|
|
7508
|
-
const { app } = setup({ githubUsername: "octocat", preview: p.fn });
|
|
7509
|
-
const res = await get(app, asAdmin);
|
|
7510
|
-
expect(res.status).toBe(200);
|
|
7511
|
-
const body = (await res.json()) as {
|
|
7512
|
-
status: string;
|
|
7513
|
-
access: { orgs: unknown[]; complete: boolean };
|
|
7514
|
-
};
|
|
7515
|
-
expect(body.status).toBe("ok");
|
|
7516
|
-
expect(body.access.orgs).toEqual(expectedOrgs);
|
|
7517
|
-
expect(body.access.complete).toBe(true);
|
|
7518
|
-
expect(p.paths).toContain("GET /app/installations");
|
|
7519
|
-
expect(p.paths.some((x) => x.includes("/enterprises/"))).toBe(false);
|
|
7520
|
-
});
|
|
7521
|
-
|
|
7522
|
-
it("both Apps: same result, orgs come from the installer", async () => {
|
|
7523
|
-
const p = preview(["installer", "lookup"]);
|
|
7524
|
-
const { app } = setup({ githubUsername: "octocat", preview: p.fn });
|
|
7525
|
-
const body = (await (await get(app, asAdmin)).json()) as {
|
|
7526
|
-
status: string;
|
|
7527
|
-
access: { orgs: unknown[] };
|
|
7528
|
-
};
|
|
7529
|
-
expect(body.status).toBe("ok");
|
|
7530
|
-
expect(body.access.orgs).toEqual(expectedOrgs);
|
|
7531
|
-
expect(p.paths).toContain(
|
|
7532
|
-
"GET /enterprises/acme/apps/installable_organizations",
|
|
7533
|
-
);
|
|
7534
|
-
expect(p.paths).not.toContain("GET /app/installations");
|
|
7535
|
-
});
|
|
7536
|
-
|
|
7537
|
-
it("installer-only is unconfigured with no GitHub call", async () => {
|
|
7538
|
-
const p = preview(["installer"]);
|
|
7539
|
-
const { app } = setup({ githubUsername: "octocat", preview: p.fn });
|
|
7540
|
-
const res = await get(app, asAdmin);
|
|
7541
|
-
expect(await res.json()).toEqual({ status: "unconfigured" });
|
|
7542
|
-
expect(p.paths).toEqual([]);
|
|
7543
|
-
});
|
|
7544
|
-
});
|
|
7545
|
-
|
|
7546
|
-
it("user_not_found is passed through", async () => {
|
|
7547
|
-
const access = { ...ACCESS, outcome: "user_not_found" as const, orgs: [] };
|
|
7548
|
-
const { app } = setup({
|
|
7549
|
-
githubUsername: "ghost",
|
|
7550
|
-
preview: async () => ({ status: "user_not_found", access }),
|
|
7551
|
-
});
|
|
7552
|
-
const res = await get(app, asAdmin);
|
|
7553
|
-
expect(res.status).toBe(200);
|
|
7554
|
-
expect(((await res.json()) as { status: string }).status).toBe(
|
|
7555
|
-
"user_not_found",
|
|
7556
|
-
);
|
|
7557
|
-
});
|
|
7558
|
-
});
|
|
7559
|
-
|
|
7560
7287
|
// ─── IRM-1.2 / IRM-3.1: installation repos list and GitHub Sync ───────────────
|
|
7561
7288
|
|
|
7562
7289
|
describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, IRM-3.1)", () => {
|
|
@@ -8304,7 +8031,7 @@ describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, I
|
|
|
8304
8031
|
expect(state.repos).toEqual([]);
|
|
8305
8032
|
});
|
|
8306
8033
|
|
|
8307
|
-
// GIS-1.2: an agent App installed on All repositories is
|
|
8034
|
+
// GIS-1.2: an agent App installed on All repositories is skipped, never switched.
|
|
8308
8035
|
const allSnapshot = () => [
|
|
8309
8036
|
{
|
|
8310
8037
|
org: "acme-eng",
|
|
@@ -8316,61 +8043,45 @@ describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, I
|
|
|
8316
8043
|
repos: [{ fullName: "acme-eng/repo-1" }, { fullName: "acme-eng/repo-2" }],
|
|
8317
8044
|
},
|
|
8318
8045
|
];
|
|
8046
|
+
const ALL_REPOS_MESSAGE =
|
|
8047
|
+
"Sync does not work when the app has access to all repositories; uninstall the app and install again with selected repositories.";
|
|
8319
8048
|
|
|
8320
|
-
it("sync preview
|
|
8321
|
-
const { app,
|
|
8049
|
+
it("sync preview reports an 'all' installation as skipped with the reinstall message", async () => {
|
|
8050
|
+
const { app, gh } = setup({ snapshots: allSnapshot() });
|
|
8322
8051
|
const res = await app.request(previewUrl, { headers: asAdmin });
|
|
8323
8052
|
expect(res.status).toBe(200);
|
|
8324
8053
|
const body = (await res.json()) as {
|
|
8325
|
-
selectionSwitches: unknown[];
|
|
8326
8054
|
appRemoves: string[];
|
|
8055
|
+
skippedOrgs: { org: string; reason: string }[];
|
|
8056
|
+
selectionSwitches?: unknown;
|
|
8327
8057
|
};
|
|
8328
|
-
expect(body.
|
|
8329
|
-
{ org: "acme-eng",
|
|
8058
|
+
expect(body.skippedOrgs).toEqual([
|
|
8059
|
+
{ org: "acme-eng", reason: ALL_REPOS_MESSAGE },
|
|
8330
8060
|
]);
|
|
8331
|
-
expect(body.appRemoves).toEqual([
|
|
8332
|
-
|
|
8333
|
-
expect(
|
|
8061
|
+
expect(body.appRemoves).toEqual([]);
|
|
8062
|
+
expect(body.selectionSwitches).toBeUndefined();
|
|
8063
|
+
expect(gh.filter((c) => c.startsWith("PATCH"))).toEqual([]);
|
|
8334
8064
|
});
|
|
8335
8065
|
|
|
8336
|
-
it("sync apply
|
|
8337
|
-
const { app, audits,
|
|
8066
|
+
it("sync apply on an 'all' installation never calls the installation PATCH", async () => {
|
|
8067
|
+
const { app, audits, gh } = setup({ snapshots: allSnapshot() });
|
|
8338
8068
|
const res = await apply(app, {
|
|
8339
8069
|
appRemoves: ["acme-eng/repo-2"],
|
|
8340
|
-
|
|
8070
|
+
appAdds: ["acme-eng/repo-3"],
|
|
8341
8071
|
});
|
|
8342
8072
|
expect(res.status).toBe(200);
|
|
8343
|
-
|
|
8344
|
-
status:
|
|
8345
|
-
|
|
8346
|
-
selectionSwitches
|
|
8347
|
-
}
|
|
8348
|
-
expect(
|
|
8349
|
-
|
|
8350
|
-
"
|
|
8351
|
-
"audit",
|
|
8352
|
-
"block",
|
|
8073
|
+
const body = (await res.json()) as {
|
|
8074
|
+
status: string;
|
|
8075
|
+
skippedOrgs: { org: string; reason: string }[];
|
|
8076
|
+
selectionSwitches?: unknown;
|
|
8077
|
+
};
|
|
8078
|
+
expect(body.status).toBe("noop");
|
|
8079
|
+
expect(body.skippedOrgs).toEqual([
|
|
8080
|
+
{ org: "acme-eng", reason: ALL_REPOS_MESSAGE },
|
|
8353
8081
|
]);
|
|
8354
|
-
expect(
|
|
8355
|
-
expect(
|
|
8356
|
-
|
|
8357
|
-
selectionSwitches: [{ org: "acme-eng", repos: ["acme-eng/repo-1"] }],
|
|
8358
|
-
});
|
|
8359
|
-
});
|
|
8360
|
-
|
|
8361
|
-
it("sync apply: a 403 on the switch is a 502 naming the missing permission, with a failed audit", async () => {
|
|
8362
|
-
const { app, audits } = setup({
|
|
8363
|
-
snapshots: allSnapshot(),
|
|
8364
|
-
override: { [`PATCH ${INST}/501/repositories`]: "install_selection_403" },
|
|
8365
|
-
});
|
|
8366
|
-
const res = await apply(app, { appRemoves: ["acme-eng/repo-2"] });
|
|
8367
|
-
expect(res.status).toBe(502);
|
|
8368
|
-
expect(JSON.stringify(await res.json())).toContain(
|
|
8369
|
-
"enterprise_organization_installation_repositories",
|
|
8370
|
-
);
|
|
8371
|
-
expect(audits).toHaveLength(1);
|
|
8372
|
-
expect(audits[0]).toMatchObject({ result: { status: "failed" } });
|
|
8373
|
-
expect(audits[0]?.diff).toMatchObject({ installationRemoves: [] });
|
|
8082
|
+
expect(body.selectionSwitches).toBeUndefined();
|
|
8083
|
+
expect(gh.filter((c) => c.startsWith("PATCH"))).toEqual([]);
|
|
8084
|
+
expect(audits).toEqual([]);
|
|
8374
8085
|
});
|
|
8375
8086
|
|
|
8376
8087
|
it("sync apply: noop when nothing confirmed still applies; 400 for bad names", async () => {
|
package/src/agents-api.ts
CHANGED
|
@@ -111,7 +111,6 @@ import {
|
|
|
111
111
|
NotFoundError,
|
|
112
112
|
UnprocessableEntityError,
|
|
113
113
|
} from "./errors.ts";
|
|
114
|
-
import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
|
|
115
114
|
import type { GithubSyncService } from "./github-sync.ts";
|
|
116
115
|
import { normalizeGithubUsername } from "./github-username.ts";
|
|
117
116
|
import type { InstallationReposService } from "./installation-repos-service.ts";
|
|
@@ -276,11 +275,6 @@ export interface AdminDeps {
|
|
|
276
275
|
AgentGitHubInstallationsService,
|
|
277
276
|
"push" | "get"
|
|
278
277
|
>;
|
|
279
|
-
/**
|
|
280
|
-
* GHE-2.4: backs GET /agents/:id/github-access. Optional (additive); absent
|
|
281
|
-
* means the enterprise Apps are not wired, reported as `unconfigured`.
|
|
282
|
-
*/
|
|
283
|
-
githubAccessPreview?: GithubAccessPreviewFn;
|
|
284
278
|
/**
|
|
285
279
|
* IRM-1.7: optional host-supplied open-work port. When an agent's own repos
|
|
286
280
|
* lose a repo (DELETE /agents/{id}/repos/{owner}/{name} or a PATCH that
|
|
@@ -591,46 +585,6 @@ const GitHubInstallationsSnapshotWrapperSchema = z
|
|
|
591
585
|
.object({ snapshot: AgentGitHubInstallationsSnapshotSchema })
|
|
592
586
|
.openapi("GitHubInstallationsSnapshotWrapper");
|
|
593
587
|
|
|
594
|
-
const GithubAccessOrgSchema = z.object({
|
|
595
|
-
org: z.string(),
|
|
596
|
-
status: z.enum([
|
|
597
|
-
"ok",
|
|
598
|
-
"lookup_app_not_installed",
|
|
599
|
-
"rate_limited",
|
|
600
|
-
"partial",
|
|
601
|
-
"error",
|
|
602
|
-
]),
|
|
603
|
-
repos: z.array(
|
|
604
|
-
z.object({
|
|
605
|
-
fullName: z.string(),
|
|
606
|
-
level: z.enum(["admin", "maintain", "write", "triage", "read", "none"]),
|
|
607
|
-
canPush: z.boolean(),
|
|
608
|
-
}),
|
|
609
|
-
),
|
|
610
|
-
unresolved: z.number().int(),
|
|
611
|
-
});
|
|
612
|
-
|
|
613
|
-
const GithubAccessPreviewSchema = z
|
|
614
|
-
.object({
|
|
615
|
-
status: z.enum(["ok", "user_not_found", "unconfigured"]).openapi({
|
|
616
|
-
description:
|
|
617
|
-
"`unconfigured` when the lookup App or its key is not set (no GitHub call was made). The installer App is optional.",
|
|
618
|
-
}),
|
|
619
|
-
access: z
|
|
620
|
-
.object({
|
|
621
|
-
username: z.string(),
|
|
622
|
-
outcome: z.enum(["ok", "user_not_found"]),
|
|
623
|
-
userVerified: z.boolean(),
|
|
624
|
-
orgs: z.array(GithubAccessOrgSchema),
|
|
625
|
-
unresolved: z.number().int(),
|
|
626
|
-
complete: z.boolean(),
|
|
627
|
-
checkedAt: z.string(),
|
|
628
|
-
})
|
|
629
|
-
.optional()
|
|
630
|
-
.openapi({ description: "Resolver output; absent when unconfigured." }),
|
|
631
|
-
})
|
|
632
|
-
.openapi("GithubAccessPreview");
|
|
633
|
-
|
|
634
588
|
const GITHUB_APPS_UNCONFIGURED = "GitHub Apps are not configured";
|
|
635
589
|
|
|
636
590
|
const RepoFullNameSchema = z
|
|
@@ -762,13 +716,6 @@ const SkippedOrgsSchema = z.array(
|
|
|
762
716
|
}),
|
|
763
717
|
);
|
|
764
718
|
|
|
765
|
-
const SelectionSwitchesSchema = z
|
|
766
|
-
.array(z.object({ org: z.string(), repos: z.array(z.string()) }))
|
|
767
|
-
.openapi({
|
|
768
|
-
description:
|
|
769
|
-
"Orgs whose agent App installation is on All repositories. Sync switches each to Selected repositories (first 50 repos in the switch, the rest added in batches) before any add or remove; `repos` is the resulting list: the installed repos minus the org's confirmed removals. An org the bound user can push to nothing in is skipped (see `skippedOrgs`) and stays on All repositories.",
|
|
770
|
-
});
|
|
771
|
-
|
|
772
719
|
const GithubSyncPreviewSchema = z
|
|
773
720
|
.object({
|
|
774
721
|
status: z.enum(["previewed", "skipped"]).openapi({
|
|
@@ -788,10 +735,9 @@ const GithubSyncPreviewSchema = z
|
|
|
788
735
|
description:
|
|
789
736
|
"Configured agent repos the bound user can no longer push to. The agent's repos are never added to.",
|
|
790
737
|
}),
|
|
791
|
-
selectionSwitches: SelectionSwitchesSchema.optional(),
|
|
792
738
|
skippedOrgs: SkippedOrgsSchema.optional().openapi({
|
|
793
739
|
description:
|
|
794
|
-
"Orgs whose access listing is missing, partial or failed, whose cached access data is incomplete or stale, or whose lookup App is not installed or installed on selected repositories only; nothing there is added or removed. `reason` says why (for stale data, when it was checked).",
|
|
740
|
+
"Orgs whose access listing is missing, partial or failed, whose cached access data is incomplete or stale, or whose lookup App is not installed or installed on selected repositories only, or whose agent App installation is on All repositories (uninstall and reinstall with selected repositories); nothing there is added or removed. `reason` says why (for stale data, when it was checked).",
|
|
795
741
|
}),
|
|
796
742
|
openWork: z.array(OpenWorkItemSchema).optional().openapi({
|
|
797
743
|
description:
|
|
@@ -831,7 +777,6 @@ const GithubSyncApplyResultSchema = z
|
|
|
831
777
|
appAdds: z.array(z.string()).optional(),
|
|
832
778
|
appRemoves: z.array(z.string()).optional(),
|
|
833
779
|
agentRemoves: z.array(z.string()).optional(),
|
|
834
|
-
selectionSwitches: SelectionSwitchesSchema.optional(),
|
|
835
780
|
notApplied: z
|
|
836
781
|
.array(z.object({ repo: z.string(), reason: z.string() }))
|
|
837
782
|
.optional()
|
|
@@ -1859,26 +1804,6 @@ const getGitHubInstallationsRoute = createRoute({
|
|
|
1859
1804
|
},
|
|
1860
1805
|
});
|
|
1861
1806
|
|
|
1862
|
-
const getGithubAccessRoute = createRoute({
|
|
1863
|
-
method: "get",
|
|
1864
|
-
path: "/agents/{id}/github-access",
|
|
1865
|
-
summary: "Preview the repos the agent's bound GitHub user can reach",
|
|
1866
|
-
description:
|
|
1867
|
-
"Platform-admin only (session members, ops keys and agent keys get 403): the response lists repo names the bound user can reach. Read-only; nothing is stored. 404 for an unknown agent; 422 when no githubUsername is bound. Returns `status: unconfigured` (not an error, no GitHub call) when the lookup App is not configured (the installer App is optional), and `status: user_not_found` when the user does not exist on GitHub; otherwise `access` is the resolver output (per-org status, repos with level and canPush, unresolved count, complete flag).",
|
|
1868
|
-
request: { params: AgentIdParamSchema },
|
|
1869
|
-
responses: {
|
|
1870
|
-
200: {
|
|
1871
|
-
description: "Access preview",
|
|
1872
|
-
content: { "application/json": { schema: GithubAccessPreviewSchema } },
|
|
1873
|
-
},
|
|
1874
|
-
401: { description: "Unauthorized", ...jsonError },
|
|
1875
|
-
403: { description: "Platform admin required", ...jsonError },
|
|
1876
|
-
404: { description: "Agent not found", ...jsonError },
|
|
1877
|
-
422: { description: "Agent has no githubUsername", ...jsonError },
|
|
1878
|
-
502: { description: "GitHub unavailable or refused", ...jsonError },
|
|
1879
|
-
},
|
|
1880
|
-
});
|
|
1881
|
-
|
|
1882
1807
|
const installationReposErrors = {
|
|
1883
1808
|
401: { description: "Unauthorized", ...jsonError },
|
|
1884
1809
|
403: { description: "Platform admin required", ...jsonError },
|
|
@@ -3512,31 +3437,6 @@ export function createAdminApp(deps: AdminDeps): OpenAPIHono<AdminAuthEnv> {
|
|
|
3512
3437
|
return c.json({ bakedMarketplaces: stored }, 200);
|
|
3513
3438
|
});
|
|
3514
3439
|
|
|
3515
|
-
// GET /agents/:id/github-access — GHE-2.4 read-only preview. Platform admin
|
|
3516
|
-
// only: never session members, ops/read keys or agent keys.
|
|
3517
|
-
app.openapi(getGithubAccessRoute, async (c) => {
|
|
3518
|
-
if (c.get("isAdmin") !== true) {
|
|
3519
|
-
throw new ForbiddenError(
|
|
3520
|
-
"Admin access required to preview GitHub access",
|
|
3521
|
-
);
|
|
3522
|
-
}
|
|
3523
|
-
const { id: agentId } = c.req.valid("param");
|
|
3524
|
-
const agent = await agentService.getDetail(agentId);
|
|
3525
|
-
if (!agent) throw new NotFoundError(`agent ${agentId} not found`);
|
|
3526
|
-
if (!agent.githubUsername) {
|
|
3527
|
-
throw new UnprocessableEntityError(
|
|
3528
|
-
"agent has no githubUsername bound; set one with PATCH /agents/{id}",
|
|
3529
|
-
);
|
|
3530
|
-
}
|
|
3531
|
-
if (!deps.githubAccessPreview)
|
|
3532
|
-
return c.json({ status: "unconfigured" as const }, 200);
|
|
3533
|
-
const preview = await deps.githubAccessPreview(
|
|
3534
|
-
agent.githubUsername,
|
|
3535
|
-
agent.accountId,
|
|
3536
|
-
);
|
|
3537
|
-
return c.json(preview, 200);
|
|
3538
|
-
});
|
|
3539
|
-
|
|
3540
3440
|
// /agents/:id/github-installation/repos — IRM-1.2. Platform admin only;
|
|
3541
3441
|
// responses carry repo names and ids, never tokens.
|
|
3542
3442
|
const installationReposService = (c: {
|
|
@@ -3611,9 +3511,6 @@ export function createAdminApp(deps: AdminDeps): OpenAPIHono<AdminAuthEnv> {
|
|
|
3611
3511
|
appAdds: plan.appAdds,
|
|
3612
3512
|
appRemoves: plan.appRemoves,
|
|
3613
3513
|
agentRemoves: plan.agentRemoves,
|
|
3614
|
-
...(plan.selectionSwitches?.length
|
|
3615
|
-
? { selectionSwitches: plan.selectionSwitches }
|
|
3616
|
-
: {}),
|
|
3617
3514
|
skippedOrgs: plan.skippedOrgs,
|
|
3618
3515
|
openWork: result.openWork,
|
|
3619
3516
|
warnings: result.warnings,
|
|
@@ -3673,9 +3570,6 @@ export function createAdminApp(deps: AdminDeps): OpenAPIHono<AdminAuthEnv> {
|
|
|
3673
3570
|
appAdds: plan.appAdds,
|
|
3674
3571
|
appRemoves: plan.appRemoves,
|
|
3675
3572
|
agentRemoves: plan.agentRemoves,
|
|
3676
|
-
...(plan.selectionSwitches?.length
|
|
3677
|
-
? { selectionSwitches: plan.selectionSwitches }
|
|
3678
|
-
: {}),
|
|
3679
3573
|
notApplied: plan.notApplied,
|
|
3680
3574
|
skippedOrgs: plan.skippedOrgs,
|
|
3681
3575
|
warnings:
|