@app-vitals/agent-admin 1.36.1 → 1.36.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/admin-ui-installation-repos-pages.ts +1 -1
- package/src/admin-ui-installation-repos.smoke.test.ts +11 -0
- package/src/agents-api.ts +4 -0
- package/src/github-installation-wiring.unit.test.ts +1 -1
- package/src/github-sync.ts +3 -1
- package/src/github-sync.unit.test.ts +35 -2
- package/src/installation-ports-fixture.integration.test.ts +5 -4
- package/src/installation-repos-service.ts +24 -3
- package/src/installation-repos-service.unit.test.ts +18 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.36.
|
|
3
|
+
"version": "1.36.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/app-vitals/agent.git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@anthropic-ai/sdk": "0.135.0",
|
|
45
|
-
"@app-vitals/agent-lib": "1.36.
|
|
45
|
+
"@app-vitals/agent-lib": "1.36.2",
|
|
46
46
|
"@hono/zod-openapi": "^1.0.0",
|
|
47
47
|
"@prisma/adapter-pg": "^7.10.0",
|
|
48
48
|
"@prisma/client": "^7.10.0",
|
|
@@ -88,7 +88,7 @@ export const NO_USERNAME_REASON =
|
|
|
88
88
|
"No GitHub username is bound to this agent, so there is nothing to sync against. Bind one under Owner and identities.";
|
|
89
89
|
|
|
90
90
|
export const APP_ID_MISMATCH_MESSAGE =
|
|
91
|
-
"No installation
|
|
91
|
+
"No installation of the agent GitHub App was found on any org the installer can reach, although the Installations card lists one. The App is matched by client id or slug: check the App installation and the agent GH_APP_CLIENT_ID / GH_APP_SLUG.";
|
|
92
92
|
|
|
93
93
|
/** JSON body of GET /agents/:id/github-sync/preview. */
|
|
94
94
|
export interface GithubSyncPreviewView {
|
|
@@ -314,6 +314,17 @@ describe("admin UI — GitHub sync card (IRM-3.2)", () => {
|
|
|
314
314
|
expect(html).not.toContain("github-sync-confirm-btn");
|
|
315
315
|
});
|
|
316
316
|
|
|
317
|
+
it("shows the no-installation reason, never 'Already in sync'", async () => {
|
|
318
|
+
const reason = "No installation of the agent GitHub App was found";
|
|
319
|
+
const { app } = setup({
|
|
320
|
+
agentsApi: () => json({ status: "skipped", reason }),
|
|
321
|
+
});
|
|
322
|
+
const html = await (await get(app, "/github-sync/confirm")).text();
|
|
323
|
+
expect(html).toContain('data-sync="skipped"');
|
|
324
|
+
expect(html).toContain("No installation of the agent GitHub App");
|
|
325
|
+
expect(html).not.toContain("Already in sync");
|
|
326
|
+
});
|
|
327
|
+
|
|
317
328
|
it("surfaces an API failure on the confirm step", async () => {
|
|
318
329
|
const { app } = setup({
|
|
319
330
|
agentsApi: () => json({ error: "GitHub Apps are not configured" }, 503),
|
package/src/agents-api.ts
CHANGED
|
@@ -3251,6 +3251,10 @@ export function createAdminApp(deps: AdminDeps): OpenAPIHono<AdminAuthEnv> {
|
|
|
3251
3251
|
const svc = installationReposService(c);
|
|
3252
3252
|
const { id: agentId } = c.req.valid("param");
|
|
3253
3253
|
const result = await svc.list(agentId);
|
|
3254
|
+
if (result.status === "skipped") {
|
|
3255
|
+
// No installation matched: the listing stays empty (additive shape).
|
|
3256
|
+
return c.json({ appId: result.appId, orgs: [] }, 200);
|
|
3257
|
+
}
|
|
3254
3258
|
if (result.status !== "ok") return installationFailure(agentId, result);
|
|
3255
3259
|
return c.json({ appId: result.appId, orgs: result.orgs }, 200);
|
|
3256
3260
|
});
|
package/src/github-sync.ts
CHANGED
|
@@ -28,6 +28,7 @@ import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
|
|
|
28
28
|
import {
|
|
29
29
|
identityOf,
|
|
30
30
|
type InstallationReposPort,
|
|
31
|
+
NO_INSTALLATION_REASON,
|
|
31
32
|
} from "./installation-repos-service.ts";
|
|
32
33
|
import {
|
|
33
34
|
MAX_UNCONFIRMED_REMOVALS,
|
|
@@ -393,12 +394,13 @@ export class GithubSyncService {
|
|
|
393
394
|
agent.appId,
|
|
394
395
|
identityOf(agent),
|
|
395
396
|
);
|
|
397
|
+
if (installed.status === "none") return skippedPlan(NO_INSTALLATION_REASON);
|
|
396
398
|
return planGithubSync({
|
|
397
399
|
username,
|
|
398
400
|
access: preview.access,
|
|
399
401
|
agentRepos: agent.repos,
|
|
400
402
|
installationRepos: Object.fromEntries(
|
|
401
|
-
installed.map(({ org, repos }) => [org, repos]),
|
|
403
|
+
installed.orgs.map(({ org, repos }) => [org, repos]),
|
|
402
404
|
),
|
|
403
405
|
...(requested
|
|
404
406
|
? {
|
|
@@ -13,7 +13,10 @@ import type {
|
|
|
13
13
|
InstallationAgentRecord,
|
|
14
14
|
InstallationAuditEntry,
|
|
15
15
|
} from "./installation-ports.ts";
|
|
16
|
-
import
|
|
16
|
+
import {
|
|
17
|
+
type InstallationReposPort,
|
|
18
|
+
NO_INSTALLATION_REASON,
|
|
19
|
+
} from "./installation-repos-service.ts";
|
|
17
20
|
import type { OpenWorkPort } from "./reconcile-open-work.ts";
|
|
18
21
|
import { repoLostAccessBlockReason } from "./repo-removal-open-work.ts";
|
|
19
22
|
import {
|
|
@@ -249,6 +252,7 @@ function harness(
|
|
|
249
252
|
agent?: Partial<InstallationAgentRecord> | null;
|
|
250
253
|
access?: Awaited<ReturnType<GithubAccessPreviewFn>>;
|
|
251
254
|
installed?: { org: string; repos: string[] }[];
|
|
255
|
+
noInstallation?: boolean;
|
|
252
256
|
removeFails?: boolean;
|
|
253
257
|
openWork?: Partial<OpenWorkPort> | null;
|
|
254
258
|
} = {},
|
|
@@ -269,7 +273,9 @@ function harness(
|
|
|
269
273
|
> = {
|
|
270
274
|
listInstalled: async (appId) => {
|
|
271
275
|
calls.push(["listInstalled", appId]);
|
|
272
|
-
return
|
|
276
|
+
return opts.noInstallation
|
|
277
|
+
? { status: "none" }
|
|
278
|
+
: { status: "found", orgs: installed };
|
|
273
279
|
},
|
|
274
280
|
addRepos: async (appId, o, r) => {
|
|
275
281
|
calls.push(["addRepos", appId, o, [...r]]);
|
|
@@ -339,6 +345,33 @@ const applyInput = (
|
|
|
339
345
|
...extra,
|
|
340
346
|
});
|
|
341
347
|
|
|
348
|
+
describe("GithubSyncService with no installation", () => {
|
|
349
|
+
it("preview is skipped with the no-installation reason", async () => {
|
|
350
|
+
const { svc } = harness({ noInstallation: true });
|
|
351
|
+
expect(await svc.preview("ag")).toEqual({
|
|
352
|
+
status: "skipped",
|
|
353
|
+
reason: NO_INSTALLATION_REASON,
|
|
354
|
+
});
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it("apply is skipped, not noop, and changes nothing", async () => {
|
|
358
|
+
const { svc, calls, audits } = harness({ noInstallation: true });
|
|
359
|
+
expect(await svc.apply(applyInput({}))).toEqual({
|
|
360
|
+
status: "skipped",
|
|
361
|
+
reason: NO_INSTALLATION_REASON,
|
|
362
|
+
});
|
|
363
|
+
expect(calls.map((c) => c[0])).toEqual(["listInstalled"]);
|
|
364
|
+
expect(audits).toEqual([]);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it("an App matched to an org with nothing to change still returns noop", async () => {
|
|
368
|
+
const { svc } = harness({
|
|
369
|
+
installed: [{ org: "acme", repos: ["acme/a", "acme/b"] }],
|
|
370
|
+
});
|
|
371
|
+
expect((await svc.apply(applyInput({}))).status).toBe("noop");
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
|
|
342
375
|
describe("GithubSyncService.preview", () => {
|
|
343
376
|
it("returns all three lists plus the open work removals block, changing nothing", async () => {
|
|
344
377
|
const { svc, calls, audits } = harness();
|
|
@@ -53,9 +53,10 @@ describe("installation ports with the no-app_id fixture", () => {
|
|
|
53
53
|
});
|
|
54
54
|
await port.addRepos(7, ORG, [`${ORG}/repo-b`], identity);
|
|
55
55
|
await port.removeRepos(7, ORG, [`${ORG}/repo-c`], identity);
|
|
56
|
-
expect(await reposPort.listInstalled(7, identity)).toEqual(
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
expect(await reposPort.listInstalled(7, identity)).toEqual({
|
|
57
|
+
status: "found",
|
|
58
|
+
orgs: [{ org: ORG, repos: [`${ORG}/repo-a`] }],
|
|
59
|
+
});
|
|
59
60
|
expect(calls).toEqual([
|
|
60
61
|
"list:1000001",
|
|
61
62
|
"add:1000001:repo-b",
|
|
@@ -73,6 +74,6 @@ describe("installation ports with the no-app_id fixture", () => {
|
|
|
73
74
|
await expect(
|
|
74
75
|
port.addRepos(7, ORG, [`${ORG}/x`], {}),
|
|
75
76
|
).rejects.toBeInstanceOf(AppNotInstalledError);
|
|
76
|
-
expect(await reposPort.listInstalled(7)).toEqual(
|
|
77
|
+
expect(await reposPort.listInstalled(7)).toEqual({ status: "none" });
|
|
77
78
|
});
|
|
78
79
|
});
|
|
@@ -18,14 +18,25 @@ import type {
|
|
|
18
18
|
UserRepoAccessResult,
|
|
19
19
|
} from "./user-repo-access-resolver.ts";
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* The orgs the agent App is installed on, or "none" when the App matched no
|
|
23
|
+
* org the installer can reach (distinct from an installation with no changes).
|
|
24
|
+
*/
|
|
25
|
+
export type InstalledOrgsResult =
|
|
26
|
+
| { status: "found"; orgs: { org: string; repos: string[] }[] }
|
|
27
|
+
| { status: "none" };
|
|
28
|
+
|
|
21
29
|
/** Installation port plus discovery of the orgs the agent App is installed on. */
|
|
22
30
|
export interface InstallationReposPort extends AppInstallationPort {
|
|
23
31
|
listInstalled(
|
|
24
32
|
appId: number,
|
|
25
33
|
identity?: AppIdentity,
|
|
26
|
-
): Promise<
|
|
34
|
+
): Promise<InstalledOrgsResult>;
|
|
27
35
|
}
|
|
28
36
|
|
|
37
|
+
export const NO_INSTALLATION_REASON =
|
|
38
|
+
"No installation of the agent GitHub App was found on any org the installer can reach (matched by client id or slug). Check the App installation and the agent GH_APP_CLIENT_ID / GH_APP_SLUG.";
|
|
39
|
+
|
|
29
40
|
export interface InstallationRepoView {
|
|
30
41
|
fullName: string;
|
|
31
42
|
/** Present only when the bound user's access to this repo is known. */
|
|
@@ -40,6 +51,7 @@ export interface InstallationOrgView {
|
|
|
40
51
|
export type InstallationListResult =
|
|
41
52
|
| { status: "agent_not_found" }
|
|
42
53
|
| { status: "no_app_id"; reason: string }
|
|
54
|
+
| { status: "skipped"; appId: number; reason: string }
|
|
43
55
|
| { status: "ok"; appId: number; orgs: InstallationOrgView[] };
|
|
44
56
|
|
|
45
57
|
export interface InstallationReposDeps {
|
|
@@ -107,6 +119,13 @@ export class InstallationReposService {
|
|
|
107
119
|
agent.appId,
|
|
108
120
|
identityOf(agent),
|
|
109
121
|
);
|
|
122
|
+
if (installed.status === "none") {
|
|
123
|
+
return {
|
|
124
|
+
status: "skipped",
|
|
125
|
+
appId: agent.appId,
|
|
126
|
+
reason: NO_INSTALLATION_REASON,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
110
129
|
const username = agent.githubUsername?.trim();
|
|
111
130
|
let access: UserRepoAccessResult | undefined;
|
|
112
131
|
if (username) {
|
|
@@ -120,7 +139,7 @@ export class InstallationReposService {
|
|
|
120
139
|
return {
|
|
121
140
|
status: "ok",
|
|
122
141
|
appId: agent.appId,
|
|
123
|
-
orgs: installed.map(({ org, repos }) => ({
|
|
142
|
+
orgs: installed.orgs.map(({ org, repos }) => ({
|
|
124
143
|
org,
|
|
125
144
|
repos: userPushHints(access, org, repos),
|
|
126
145
|
})),
|
|
@@ -154,7 +173,9 @@ export function createInstallationReposPort(
|
|
|
154
173
|
throw err;
|
|
155
174
|
}
|
|
156
175
|
}
|
|
157
|
-
return out
|
|
176
|
+
return out.length === 0
|
|
177
|
+
? { status: "none" }
|
|
178
|
+
: { status: "found", orgs: out };
|
|
158
179
|
},
|
|
159
180
|
};
|
|
160
181
|
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { describe, expect, it } from "bun:test";
|
|
8
8
|
import {
|
|
9
9
|
InstallationReposService,
|
|
10
|
+
NO_INSTALLATION_REASON,
|
|
10
11
|
type InstallationReposPort,
|
|
11
12
|
userPushHints,
|
|
12
13
|
} from "./installation-repos-service.ts";
|
|
@@ -103,6 +104,7 @@ function noHint(r: { userCanPush?: boolean }): boolean {
|
|
|
103
104
|
function build(
|
|
104
105
|
opts: {
|
|
105
106
|
agent?: { githubUsername: string | null; appId?: number } | null;
|
|
107
|
+
noInstallation?: boolean;
|
|
106
108
|
access?: () => Promise<
|
|
107
109
|
| { status: "unconfigured" }
|
|
108
110
|
| { status: "ok"; access: UserRepoAccessResult }
|
|
@@ -110,9 +112,13 @@ function build(
|
|
|
110
112
|
} = {},
|
|
111
113
|
) {
|
|
112
114
|
const installation: InstallationReposPort = {
|
|
113
|
-
listInstalled: async () =>
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
listInstalled: async () =>
|
|
116
|
+
opts.noInstallation
|
|
117
|
+
? { status: "none" }
|
|
118
|
+
: {
|
|
119
|
+
status: "found",
|
|
120
|
+
orgs: [{ org: "acme", repos: ["acme/push", "acme/unlisted"] }],
|
|
121
|
+
},
|
|
116
122
|
listRepos: async () => ({}),
|
|
117
123
|
addRepos: async () => {},
|
|
118
124
|
removeRepos: async () => {},
|
|
@@ -175,6 +181,15 @@ describe("InstallationReposService.list", () => {
|
|
|
175
181
|
}
|
|
176
182
|
});
|
|
177
183
|
|
|
184
|
+
it("is skipped with a reason when the App matches no installation", async () => {
|
|
185
|
+
const r = await build({ noInstallation: true }).svc.list("a1");
|
|
186
|
+
expect(r).toEqual({
|
|
187
|
+
status: "skipped",
|
|
188
|
+
appId: 42,
|
|
189
|
+
reason: NO_INSTALLATION_REASON,
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
178
193
|
it("reports unknown agent and a missing GH_APP_ID distinctly", async () => {
|
|
179
194
|
expect(await build({ agent: null }).svc.list("x")).toEqual({
|
|
180
195
|
status: "agent_not_found",
|