@app-vitals/agent-admin 1.34.0 → 1.35.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/openapi.platform.json +2 -392
- package/package.json +2 -2
- package/src/admin-boot.ts +1 -12
- package/src/admin-extension.ts +3 -3
- package/src/admin-ui-github-identity.smoke.test.ts +0 -114
- package/src/admin-ui-installation-repos-pages.ts +404 -0
- package/src/admin-ui-installation-repos-pages.unit.test.ts +57 -0
- package/src/admin-ui-installation-repos.smoke.test.ts +496 -0
- package/src/admin-ui-pages.ts +57 -9
- package/src/admin-ui.ts +236 -50
- package/src/agents-api.smoke.test.ts +2 -352
- package/src/agents-api.ts +5 -269
- package/src/github-enterprise-isolation.unit.test.ts +4 -4
- package/src/{github-reconcile-wiring.ts → github-installation-wiring.ts} +18 -38
- package/src/github-installation-wiring.unit.test.ts +111 -0
- package/src/github-installation.fixtures.ts +76 -0
- package/src/installation-ports.integration.test.ts +89 -0
- package/src/installation-ports.ts +207 -0
- package/src/installation-ports.unit.test.ts +51 -0
- package/src/installation-repos-service.ts +12 -12
- package/src/installation-repos-service.unit.test.ts +3 -3
- package/src/lost-access-removal.ts +9 -9
- package/src/lost-access-removal.unit.test.ts +7 -7
- package/src/reconcile-open-work.ts +5 -7
- package/src/repo-access-rules.ts +58 -0
- package/src/repo-access-rules.unit.test.ts +98 -0
- package/src/admin-ui-github-reconcile-pages.ts +0 -208
- package/src/admin-ui-github-reconcile-pages.unit.test.ts +0 -222
- package/src/github-reconcile-routes.integration.test.ts +0 -206
- package/src/github-reconcile-wiring.unit.test.ts +0 -170
- package/src/reconcile-apply-service.integration.test.ts +0 -271
- package/src/reconcile-apply-service.ts +0 -439
- package/src/reconcile-apply-service.unit.test.ts +0 -279
- package/src/reconcile-planner.ts +0 -264
- package/src/reconcile-planner.unit.test.ts +0 -274
|
@@ -27,14 +27,8 @@ import { PLATFORM_OPS_ROUTES } from "./api-auth.ts";
|
|
|
27
27
|
import {
|
|
28
28
|
createGithubInstallationRepos,
|
|
29
29
|
createGithubLostAccessRemoval,
|
|
30
|
-
|
|
31
|
-
} from "./github-
|
|
32
|
-
import {
|
|
33
|
-
accessFor,
|
|
34
|
-
envWith,
|
|
35
|
-
fakeOpenWork,
|
|
36
|
-
fakePrisma,
|
|
37
|
-
} from "./github-reconcile-wiring.unit.test.ts";
|
|
30
|
+
} from "./github-installation-wiring.ts";
|
|
31
|
+
import { accessFor, envWith } from "./github-installation.fixtures.ts";
|
|
38
32
|
import type { OpenWorkPort } from "./reconcile-open-work.ts";
|
|
39
33
|
import {
|
|
40
34
|
repoLostAccessBlockReason,
|
|
@@ -7137,350 +7131,6 @@ describe("admin API — GET /agents/:id/github-access (GHE-2.4)", () => {
|
|
|
7137
7131
|
});
|
|
7138
7132
|
});
|
|
7139
7133
|
|
|
7140
|
-
// ─── GHE-3.4: POST /agents/:id/github-reconcile/{plan,apply} ─────────────────
|
|
7141
|
-
|
|
7142
|
-
describe("admin API — GitHub reconcile routes (GHE-3.4)", () => {
|
|
7143
|
-
const OPS = "ghr-ops-token";
|
|
7144
|
-
const READER = "ghr-read-token";
|
|
7145
|
-
const AGENT_KEY = "ghr-agent-token";
|
|
7146
|
-
const DIFF = {
|
|
7147
|
-
installationAdds: ["acme/api"],
|
|
7148
|
-
installationRemoves: [],
|
|
7149
|
-
configAdds: ["acme/api"],
|
|
7150
|
-
configRemoves: ["acme/old"],
|
|
7151
|
-
};
|
|
7152
|
-
const PLAN = {
|
|
7153
|
-
skipped: false,
|
|
7154
|
-
diff: DIFF,
|
|
7155
|
-
skippedOrgs: [],
|
|
7156
|
-
rejectedAdds: [],
|
|
7157
|
-
warnings: ["heads up"],
|
|
7158
|
-
empty: false,
|
|
7159
|
-
planHash: "hash-1",
|
|
7160
|
-
};
|
|
7161
|
-
const SKIPPED_PLAN = {
|
|
7162
|
-
...PLAN,
|
|
7163
|
-
skipped: true,
|
|
7164
|
-
skipReason: "agent has no bound GitHub username",
|
|
7165
|
-
diff: {
|
|
7166
|
-
installationAdds: [],
|
|
7167
|
-
installationRemoves: [],
|
|
7168
|
-
configAdds: [],
|
|
7169
|
-
configRemoves: [],
|
|
7170
|
-
},
|
|
7171
|
-
warnings: [],
|
|
7172
|
-
empty: true,
|
|
7173
|
-
planHash: "hash-skip",
|
|
7174
|
-
};
|
|
7175
|
-
type Reconcile = NonNullable<AdminDeps["githubReconcile"]>;
|
|
7176
|
-
|
|
7177
|
-
function setup(reconcile?: Partial<Reconcile>) {
|
|
7178
|
-
const base = makeMockDeps();
|
|
7179
|
-
const calls: { fn: string; args: unknown[] }[] = [];
|
|
7180
|
-
const port: Reconcile = {
|
|
7181
|
-
planWithOpenWork: async (...args) => {
|
|
7182
|
-
calls.push({ fn: "plan", args });
|
|
7183
|
-
return {
|
|
7184
|
-
plan: PLAN,
|
|
7185
|
-
openWork: [{ id: "T-1", repo: "acme/old", title: "fix it" }],
|
|
7186
|
-
};
|
|
7187
|
-
},
|
|
7188
|
-
apply: async (input) => {
|
|
7189
|
-
calls.push({ fn: "apply", args: [input] });
|
|
7190
|
-
return {
|
|
7191
|
-
status: "applied",
|
|
7192
|
-
plan: PLAN,
|
|
7193
|
-
auditId: "audit-1",
|
|
7194
|
-
warnings: [],
|
|
7195
|
-
};
|
|
7196
|
-
},
|
|
7197
|
-
...reconcile,
|
|
7198
|
-
};
|
|
7199
|
-
const deps: AdminDeps = {
|
|
7200
|
-
...base,
|
|
7201
|
-
adminApiKeys: parseAdminApiKeys(
|
|
7202
|
-
`root:${ADMIN_API_KEY}:*,operator:${OPS}:platform.ops,reader:${READER}:platform.read`,
|
|
7203
|
-
),
|
|
7204
|
-
agentTokenService: {
|
|
7205
|
-
...base.agentTokenService,
|
|
7206
|
-
validate: async (t: string) =>
|
|
7207
|
-
t === AGENT_KEY ? { agentId: AGENT_ID } : null,
|
|
7208
|
-
},
|
|
7209
|
-
githubReconcile: reconcile === undefined ? undefined : port,
|
|
7210
|
-
};
|
|
7211
|
-
return { app: createAdminApp(deps), calls, port };
|
|
7212
|
-
}
|
|
7213
|
-
const withPort = () => setup({});
|
|
7214
|
-
|
|
7215
|
-
const post = (
|
|
7216
|
-
app: ReturnType<typeof createAdminApp>,
|
|
7217
|
-
action: "plan" | "apply",
|
|
7218
|
-
headers: Record<string, string>,
|
|
7219
|
-
body: unknown = {},
|
|
7220
|
-
id = AGENT_ID,
|
|
7221
|
-
) =>
|
|
7222
|
-
app.request(`/agents/${id}/github-reconcile/${action}`, {
|
|
7223
|
-
method: "POST",
|
|
7224
|
-
headers: { "Content-Type": "application/json", ...headers },
|
|
7225
|
-
body: JSON.stringify(body),
|
|
7226
|
-
});
|
|
7227
|
-
const asAdmin = { Authorization: `Bearer ${ADMIN_API_KEY}` };
|
|
7228
|
-
|
|
7229
|
-
it("403 for a session member, ops key, read key and agent key", async () => {
|
|
7230
|
-
const { app, calls } = withPort();
|
|
7231
|
-
const memberApp = createAdminApp({
|
|
7232
|
-
...makeMockDeps(),
|
|
7233
|
-
callerScopeResolver: async () => ({
|
|
7234
|
-
kind: "scoped",
|
|
7235
|
-
accountId: "acct-a",
|
|
7236
|
-
agentIds: [AGENT_ID],
|
|
7237
|
-
}),
|
|
7238
|
-
});
|
|
7239
|
-
const cookie = await sign(
|
|
7240
|
-
{
|
|
7241
|
-
isAdmin: false,
|
|
7242
|
-
userId: "user-acct",
|
|
7243
|
-
email: "owner@acct-a.example.com",
|
|
7244
|
-
iat: Math.floor(Date.now() / 1000),
|
|
7245
|
-
exp: Math.floor(Date.now() / 1000) + 3600,
|
|
7246
|
-
},
|
|
7247
|
-
SESSION_SECRET,
|
|
7248
|
-
"HS256",
|
|
7249
|
-
);
|
|
7250
|
-
for (const action of ["plan", "apply"] as const) {
|
|
7251
|
-
const res = await post(
|
|
7252
|
-
memberApp,
|
|
7253
|
-
action,
|
|
7254
|
-
{ Cookie: `admin_session=${cookie}` },
|
|
7255
|
-
{ planHash: "x" },
|
|
7256
|
-
);
|
|
7257
|
-
expect(res.status).toBe(403);
|
|
7258
|
-
for (const key of [OPS, READER, AGENT_KEY]) {
|
|
7259
|
-
const r = await post(
|
|
7260
|
-
app,
|
|
7261
|
-
action,
|
|
7262
|
-
{ Authorization: `Bearer ${key}` },
|
|
7263
|
-
{ planHash: "x" },
|
|
7264
|
-
);
|
|
7265
|
-
expect(r.status).toBe(403);
|
|
7266
|
-
}
|
|
7267
|
-
}
|
|
7268
|
-
expect(calls).toEqual([]);
|
|
7269
|
-
});
|
|
7270
|
-
|
|
7271
|
-
it("plan returns the diff, warnings, hash and affected open work", async () => {
|
|
7272
|
-
const { app, calls } = withPort();
|
|
7273
|
-
const res = await post(app, "plan", asAdmin, { addRepos: ["acme/api"] });
|
|
7274
|
-
expect(res.status).toBe(200);
|
|
7275
|
-
const body = (await res.json()) as Record<string, unknown>;
|
|
7276
|
-
expect(body).toMatchObject({
|
|
7277
|
-
status: "planned",
|
|
7278
|
-
planHash: "hash-1",
|
|
7279
|
-
warnings: ["heads up"],
|
|
7280
|
-
diff: DIFF,
|
|
7281
|
-
empty: false,
|
|
7282
|
-
affectedOpenWork: [{ id: "T-1", repo: "acme/old", title: "fix it" }],
|
|
7283
|
-
});
|
|
7284
|
-
expect(calls).toEqual([{ fn: "plan", args: [AGENT_ID, ["acme/api"]] }]);
|
|
7285
|
-
});
|
|
7286
|
-
|
|
7287
|
-
it("plan with no body works", async () => {
|
|
7288
|
-
const { app } = withPort();
|
|
7289
|
-
const res = await app.request(`/agents/${AGENT_ID}/github-reconcile/plan`, {
|
|
7290
|
-
method: "POST",
|
|
7291
|
-
headers: asAdmin,
|
|
7292
|
-
});
|
|
7293
|
-
expect(res.status).toBe(200);
|
|
7294
|
-
});
|
|
7295
|
-
|
|
7296
|
-
it("plan on a skipped state is 200 with status skipped and a reason", async () => {
|
|
7297
|
-
const { app } = setup({
|
|
7298
|
-
planWithOpenWork: async () => ({ plan: SKIPPED_PLAN, openWork: [] }),
|
|
7299
|
-
});
|
|
7300
|
-
const res = await post(app, "plan", asAdmin);
|
|
7301
|
-
expect(res.status).toBe(200);
|
|
7302
|
-
expect(await res.json()).toMatchObject({
|
|
7303
|
-
status: "skipped",
|
|
7304
|
-
reason: "agent has no bound GitHub username",
|
|
7305
|
-
});
|
|
7306
|
-
});
|
|
7307
|
-
|
|
7308
|
-
it("with no reconcile port wired, plan and apply are skipped, not errors", async () => {
|
|
7309
|
-
const { app } = setup();
|
|
7310
|
-
for (const action of ["plan", "apply"] as const) {
|
|
7311
|
-
const res = await post(app, action, asAdmin, { planHash: "x" });
|
|
7312
|
-
expect(res.status).toBe(200);
|
|
7313
|
-
const body = (await res.json()) as { status: string; reason: string };
|
|
7314
|
-
expect(body.status).toBe("skipped");
|
|
7315
|
-
expect(body.reason).toContain("not configured");
|
|
7316
|
-
}
|
|
7317
|
-
});
|
|
7318
|
-
|
|
7319
|
-
it("404 for an unknown agent", async () => {
|
|
7320
|
-
const { app } = setup({
|
|
7321
|
-
planWithOpenWork: async () => {
|
|
7322
|
-
throw new Error("agent no-such-agent not found");
|
|
7323
|
-
},
|
|
7324
|
-
apply: async () => ({ status: "agent_not_found" }),
|
|
7325
|
-
});
|
|
7326
|
-
expect((await post(app, "plan", asAdmin, {}, "no-such-agent")).status).toBe(
|
|
7327
|
-
404,
|
|
7328
|
-
);
|
|
7329
|
-
expect(
|
|
7330
|
-
(await post(app, "apply", asAdmin, { planHash: "x" }, "no-such-agent"))
|
|
7331
|
-
.status,
|
|
7332
|
-
).toBe(404);
|
|
7333
|
-
});
|
|
7334
|
-
|
|
7335
|
-
it("apply returns the audit id and result and passes the caller", async () => {
|
|
7336
|
-
const { app, calls } = withPort();
|
|
7337
|
-
const res = await post(app, "apply", asAdmin, {
|
|
7338
|
-
planHash: "hash-1",
|
|
7339
|
-
addRepos: ["acme/api"],
|
|
7340
|
-
confirmRemovals: true,
|
|
7341
|
-
});
|
|
7342
|
-
expect(res.status).toBe(200);
|
|
7343
|
-
expect(await res.json()).toMatchObject({
|
|
7344
|
-
status: "applied",
|
|
7345
|
-
auditId: "audit-1",
|
|
7346
|
-
planHash: "hash-1",
|
|
7347
|
-
diff: DIFF,
|
|
7348
|
-
warnings: [],
|
|
7349
|
-
});
|
|
7350
|
-
const input = calls[0]?.args[0] as Record<string, unknown>;
|
|
7351
|
-
expect(input).toMatchObject({
|
|
7352
|
-
agentId: AGENT_ID,
|
|
7353
|
-
planHash: "hash-1",
|
|
7354
|
-
namedAdds: ["acme/api"],
|
|
7355
|
-
confirmRemovals: true,
|
|
7356
|
-
});
|
|
7357
|
-
expect(typeof input.caller).toBe("string");
|
|
7358
|
-
});
|
|
7359
|
-
|
|
7360
|
-
it("apply on a skipped or noop plan is 200 with that status", async () => {
|
|
7361
|
-
const skipped = setup({
|
|
7362
|
-
apply: async () => ({ status: "skipped", plan: SKIPPED_PLAN }),
|
|
7363
|
-
});
|
|
7364
|
-
const r1 = await post(skipped.app, "apply", asAdmin, { planHash: "x" });
|
|
7365
|
-
expect(r1.status).toBe(200);
|
|
7366
|
-
expect(await r1.json()).toMatchObject({
|
|
7367
|
-
status: "skipped",
|
|
7368
|
-
reason: "agent has no bound GitHub username",
|
|
7369
|
-
});
|
|
7370
|
-
const noop = setup({
|
|
7371
|
-
apply: async () => ({ status: "noop", plan: { ...PLAN, empty: true } }),
|
|
7372
|
-
});
|
|
7373
|
-
const r2 = await post(noop.app, "apply", asAdmin, { planHash: "x" });
|
|
7374
|
-
expect(r2.status).toBe(200);
|
|
7375
|
-
expect(((await r2.json()) as { status: string }).status).toBe("noop");
|
|
7376
|
-
});
|
|
7377
|
-
|
|
7378
|
-
it("apply 409 on a stale plan hash, 422 over the removal cap", async () => {
|
|
7379
|
-
const stale = setup({
|
|
7380
|
-
apply: async () => ({ status: "stale_plan", plan: PLAN }),
|
|
7381
|
-
});
|
|
7382
|
-
expect(
|
|
7383
|
-
(await post(stale.app, "apply", asAdmin, { planHash: "old" })).status,
|
|
7384
|
-
).toBe(409);
|
|
7385
|
-
const cap = setup({
|
|
7386
|
-
apply: async () => ({ status: "removal_cap", plan: PLAN, removals: 11 }),
|
|
7387
|
-
});
|
|
7388
|
-
const res = await post(cap.app, "apply", asAdmin, { planHash: "hash-1" });
|
|
7389
|
-
expect(res.status).toBe(422);
|
|
7390
|
-
expect(((await res.json()) as { error: string }).error).toContain(
|
|
7391
|
-
"confirmRemovals",
|
|
7392
|
-
);
|
|
7393
|
-
});
|
|
7394
|
-
|
|
7395
|
-
it("apply failure is reported with the audit id", async () => {
|
|
7396
|
-
const { app } = setup({
|
|
7397
|
-
apply: async () => ({
|
|
7398
|
-
status: "failed",
|
|
7399
|
-
plan: PLAN,
|
|
7400
|
-
auditId: "audit-2",
|
|
7401
|
-
error: "boom",
|
|
7402
|
-
}),
|
|
7403
|
-
});
|
|
7404
|
-
const res = await post(app, "apply", asAdmin, { planHash: "hash-1" });
|
|
7405
|
-
expect(res.status).toBe(200);
|
|
7406
|
-
expect(await res.json()).toMatchObject({
|
|
7407
|
-
status: "failed",
|
|
7408
|
-
auditId: "audit-2",
|
|
7409
|
-
});
|
|
7410
|
-
});
|
|
7411
|
-
|
|
7412
|
-
it("400 when apply has no planHash", async () => {
|
|
7413
|
-
const { app } = withPort();
|
|
7414
|
-
expect((await post(app, "apply", asAdmin, {})).status).toBe(400);
|
|
7415
|
-
});
|
|
7416
|
-
});
|
|
7417
|
-
|
|
7418
|
-
describe("admin API — reconcile open-work seam, in-process composition (GHE-3.9)", () => {
|
|
7419
|
-
const compose = (
|
|
7420
|
-
openWork?: ReturnType<typeof fakeOpenWork>["port"],
|
|
7421
|
-
env: Record<string, string> | undefined = { GH_APP_ID: "42" },
|
|
7422
|
-
) => {
|
|
7423
|
-
const { prisma, state } = fakePrisma(["acme/old"]);
|
|
7424
|
-
const githubReconcile = createGithubReconcile({
|
|
7425
|
-
prisma,
|
|
7426
|
-
appService: { get: async () => null, getPrivateKey: async () => null },
|
|
7427
|
-
access: accessFor(["acme/api"]),
|
|
7428
|
-
agentEnv: envWith(env),
|
|
7429
|
-
installation: {
|
|
7430
|
-
listRepos: async () => ({ acme: ["acme/old", "acme/api"] }),
|
|
7431
|
-
addRepos: async () => {},
|
|
7432
|
-
removeRepos: async () => {},
|
|
7433
|
-
},
|
|
7434
|
-
openWork,
|
|
7435
|
-
});
|
|
7436
|
-
const app = createAdminApp({
|
|
7437
|
-
...makeMockDeps(),
|
|
7438
|
-
adminApiKeys: parseAdminApiKeys(`root:${ADMIN_API_KEY}:*`),
|
|
7439
|
-
githubReconcile,
|
|
7440
|
-
});
|
|
7441
|
-
const plan = () =>
|
|
7442
|
-
app.request(`/agents/${AGENT_ID}/github-reconcile/plan`, {
|
|
7443
|
-
method: "POST",
|
|
7444
|
-
headers: { Authorization: `Bearer ${ADMIN_API_KEY}` },
|
|
7445
|
-
});
|
|
7446
|
-
return { plan, state };
|
|
7447
|
-
};
|
|
7448
|
-
|
|
7449
|
-
it("plan returns the port's items and retires nothing", async () => {
|
|
7450
|
-
const { port, calls } = fakeOpenWork();
|
|
7451
|
-
const { plan, state } = compose(port);
|
|
7452
|
-
const res = await plan();
|
|
7453
|
-
expect(res.status).toBe(200);
|
|
7454
|
-
const body = (await res.json()) as { affectedOpenWork: unknown[] };
|
|
7455
|
-
expect(body.affectedOpenWork).toEqual([
|
|
7456
|
-
{ id: "T-1", repo: "acme/old", title: "fix it" },
|
|
7457
|
-
]);
|
|
7458
|
-
expect(calls.map((c) => c.fn)).toEqual(["list"]);
|
|
7459
|
-
expect(state.repos).toEqual(["acme/old"]);
|
|
7460
|
-
});
|
|
7461
|
-
|
|
7462
|
-
it("plans for an agent whose GH_APP_ID is in its stored env", async () => {
|
|
7463
|
-
const res = await compose(undefined, { GH_APP_ID: "42" }).plan();
|
|
7464
|
-
expect(res.status).toBe(200);
|
|
7465
|
-
expect(await res.json()).toMatchObject({ status: "planned" });
|
|
7466
|
-
});
|
|
7467
|
-
|
|
7468
|
-
it("reports skipped naming GH_APP_ID for an agent without one", async () => {
|
|
7469
|
-
const res = await compose(undefined, {}).plan();
|
|
7470
|
-
expect(res.status).toBe(200);
|
|
7471
|
-
const body = (await res.json()) as { status: string; reason?: string };
|
|
7472
|
-
expect(body.status).toBe("skipped");
|
|
7473
|
-
expect(body.reason).toContain("GH_APP_ID");
|
|
7474
|
-
});
|
|
7475
|
-
|
|
7476
|
-
it("without a port plan lists nothing", async () => {
|
|
7477
|
-
const res = await compose().plan();
|
|
7478
|
-
expect(res.status).toBe(200);
|
|
7479
|
-
const body = (await res.json()) as { affectedOpenWork: unknown[] };
|
|
7480
|
-
expect(body.affectedOpenWork).toEqual([]);
|
|
7481
|
-
});
|
|
7482
|
-
});
|
|
7483
|
-
|
|
7484
7134
|
// ─── IRM-1.2: /agents/:id/github-installation/repos ───────────────────────────
|
|
7485
7135
|
|
|
7486
7136
|
describe("admin API — agent App installation repos (IRM-1.2)", () => {
|