@app-vitals/agent-admin 1.35.0 → 1.36.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 +136 -766
- package/package.json +2 -2
- package/src/admin-boot.ts +4 -15
- package/src/admin-extension.ts +3 -3
- package/src/admin-ui-github-identity.smoke.test.ts +24 -116
- package/src/admin-ui-installation-repos-pages.ts +198 -231
- package/src/admin-ui-installation-repos-pages.unit.test.ts +199 -0
- package/src/admin-ui-installation-repos.smoke.test.ts +166 -173
- package/src/admin-ui-pages.ts +2 -2
- package/src/admin-ui.ts +103 -171
- package/src/agents-api.smoke.test.ts +195 -642
- package/src/agents-api.ts +86 -477
- package/src/github-enterprise-isolation.unit.test.ts +4 -4
- package/src/{github-reconcile-wiring.ts → github-installation-wiring.ts} +24 -46
- package/src/github-installation-wiring.unit.test.ts +115 -0
- package/src/github-installation.fixtures.ts +76 -0
- package/src/github-sync.ts +407 -0
- package/src/{lost-access-removal.unit.test.ts → github-sync.unit.test.ts} +220 -115
- 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 +10 -105
- package/src/installation-repos-service.unit.test.ts +5 -90
- 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 -226
- package/src/github-reconcile-routes.integration.test.ts +0 -206
- package/src/github-reconcile-wiring.unit.test.ts +0 -170
- package/src/lost-access-removal.ts +0 -333
- 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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* admin/src/github-enterprise-isolation.unit.test.ts
|
|
3
3
|
* Isolation exception guard (GHE-1.3): the GitHub Enterprise App private key
|
|
4
4
|
* is reachable only from the enterprise service, its admin API, the boot
|
|
5
|
-
* wiring and the
|
|
5
|
+
* wiring and the installation wiring. Agent config bundle, agent-bearer routes and env serialization must
|
|
6
6
|
* never import the service, touch its table or call getPrivateKey().
|
|
7
7
|
*/
|
|
8
8
|
|
|
@@ -17,7 +17,7 @@ const ALLOWED = new Set([
|
|
|
17
17
|
"admin/src/github-enterprise-apps.ts",
|
|
18
18
|
"admin/src/github-enterprise-api.ts",
|
|
19
19
|
"admin/src/admin-boot.ts",
|
|
20
|
-
"admin/src/github-
|
|
20
|
+
"admin/src/github-installation-wiring.ts",
|
|
21
21
|
]);
|
|
22
22
|
|
|
23
23
|
function sources(dir: string, out: string[] = []): string[] {
|
|
@@ -67,7 +67,7 @@ describe("GitHub Enterprise key isolation", () => {
|
|
|
67
67
|
expect(offenders).toEqual([]);
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
it("getPrivateKey() is only called by the enterprise API and
|
|
70
|
+
it("getPrivateKey() is only called by the enterprise API and installation wiring", () => {
|
|
71
71
|
const callers = files
|
|
72
72
|
.map((f) => relative(REPO, f))
|
|
73
73
|
.filter((rel) =>
|
|
@@ -75,7 +75,7 @@ describe("GitHub Enterprise key isolation", () => {
|
|
|
75
75
|
);
|
|
76
76
|
expect(callers.sort()).toEqual([
|
|
77
77
|
"admin/src/github-enterprise-api.ts",
|
|
78
|
-
"admin/src/github-
|
|
78
|
+
"admin/src/github-installation-wiring.ts",
|
|
79
79
|
]);
|
|
80
80
|
});
|
|
81
81
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* admin/src/github-
|
|
3
|
-
* Composition of the
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* admin/src/github-installation-wiring.ts
|
|
3
|
+
* Composition of the installation repos list and GitHub Sync services for
|
|
4
|
+
* admin boot, from the stored installer App and an optional host-supplied
|
|
5
|
+
* OpenWorkPort. The agent App id comes from each agent's own stored
|
|
6
|
+
* GH_APP_ID; without an open-work port nothing is listed or blocked.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { PrismaClient } from "../prisma/client/client.ts";
|
|
@@ -14,29 +14,25 @@ import { GithubEnterpriseClient } from "./github-enterprise-client.ts";
|
|
|
14
14
|
import {
|
|
15
15
|
createInstallationPort,
|
|
16
16
|
type InstallationRepoClient,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
type ReconcileInstallationPort,
|
|
21
|
-
} from "./reconcile-apply-service.ts";
|
|
17
|
+
PrismaInstallationAgents,
|
|
18
|
+
PrismaInstallationAudit,
|
|
19
|
+
} from "./installation-ports.ts";
|
|
22
20
|
import {
|
|
23
21
|
createInstallationReposPort,
|
|
24
22
|
type InstalledOrgsClient,
|
|
25
23
|
InstallationReposService,
|
|
26
24
|
type InstallationReposPort,
|
|
27
25
|
} from "./installation-repos-service.ts";
|
|
28
|
-
import {
|
|
26
|
+
import { GithubSyncService } from "./github-sync.ts";
|
|
29
27
|
import type { OpenWorkPort } from "./reconcile-open-work.ts";
|
|
30
28
|
|
|
31
|
-
export interface
|
|
29
|
+
export interface GithubInstallationWiringDeps {
|
|
32
30
|
prisma: PrismaClient;
|
|
33
31
|
appService: Pick<GitHubEnterpriseAppService, "get" | "getPrivateKey">;
|
|
34
32
|
access: GithubAccessPreviewFn;
|
|
35
33
|
/** Reads each agent's stored GH_APP_ID (its own GitHub App). */
|
|
36
34
|
agentEnv: Pick<AgentEnvService, "getConfigBundle">;
|
|
37
35
|
openWork?: OpenWorkPort;
|
|
38
|
-
/** Test seam: replaces the installer-App-backed installation port. */
|
|
39
|
-
installation?: ReconcileInstallationPort;
|
|
40
36
|
/** Test seams; default to the real GitHub API. */
|
|
41
37
|
fetchFn?: typeof fetch;
|
|
42
38
|
apiBase?: string;
|
|
@@ -46,7 +42,7 @@ export interface GithubReconcileWiringDeps {
|
|
|
46
42
|
/** Builds the installer client per call so key rotations are picked up. */
|
|
47
43
|
function lazyInstallerClient(
|
|
48
44
|
deps: Pick<
|
|
49
|
-
|
|
45
|
+
GithubInstallationWiringDeps,
|
|
50
46
|
"appService" | "fetchFn" | "apiBase" | "now"
|
|
51
47
|
>,
|
|
52
48
|
): InstallationRepoClient & InstalledOrgsClient {
|
|
@@ -81,64 +77,46 @@ function lazyInstallerClient(
|
|
|
81
77
|
};
|
|
82
78
|
}
|
|
83
79
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
* per agent from its stored GH_APP_ID, so this is always wired.
|
|
87
|
-
*/
|
|
88
|
-
export function createGithubReconcile(
|
|
89
|
-
deps: GithubReconcileWiringDeps,
|
|
90
|
-
): ReconcileApplyService {
|
|
91
|
-
return new ReconcileApplyService({
|
|
92
|
-
agents: new PrismaReconcileAgents(deps.prisma, deps.agentEnv),
|
|
93
|
-
access: deps.access,
|
|
94
|
-
installation:
|
|
95
|
-
deps.installation ?? createInstallationPort(lazyInstallerClient(deps)),
|
|
96
|
-
audit: new PrismaReconcileAudit(deps.prisma),
|
|
97
|
-
...(deps.openWork ? { openWork: deps.openWork } : {}),
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export interface InstallationReposWiringDeps extends GithubReconcileWiringDeps {
|
|
80
|
+
export interface InstallationReposWiringDeps
|
|
81
|
+
extends GithubInstallationWiringDeps {
|
|
102
82
|
/** Test seam: replaces the installer-App-backed port. */
|
|
103
83
|
installationRepos?: InstallationReposPort;
|
|
104
84
|
}
|
|
105
85
|
|
|
106
86
|
/**
|
|
107
87
|
* The `githubInstallationRepos` dep for createAdminApp (IRM-1.2): direct
|
|
108
|
-
* list
|
|
109
|
-
* audit table.
|
|
88
|
+
* list the repos on the agent App's installation.
|
|
110
89
|
*/
|
|
111
90
|
export function createGithubInstallationRepos(
|
|
112
91
|
deps: InstallationReposWiringDeps,
|
|
113
92
|
): InstallationReposService {
|
|
114
93
|
const client = lazyInstallerClient(deps);
|
|
115
94
|
return new InstallationReposService({
|
|
116
|
-
agents: new
|
|
95
|
+
agents: new PrismaInstallationAgents(deps.prisma, deps.agentEnv),
|
|
117
96
|
access: deps.access,
|
|
118
97
|
installation:
|
|
119
98
|
deps.installationRepos ??
|
|
120
99
|
createInstallationReposPort(createInstallationPort(client), client),
|
|
121
|
-
audit: new PrismaReconcileAudit(deps.prisma),
|
|
122
100
|
});
|
|
123
101
|
}
|
|
124
102
|
|
|
125
103
|
/**
|
|
126
|
-
* The `
|
|
127
|
-
* repos the bound user can
|
|
128
|
-
*
|
|
129
|
-
*
|
|
104
|
+
* The `githubSync` dep for createAdminApp (IRM-3.1): installation adds and
|
|
105
|
+
* removes plus agent-repo removals for the repos the bound user can or can no
|
|
106
|
+
* longer push to, audited once and blocking open work through the optional
|
|
107
|
+
* host OpenWorkPort.
|
|
130
108
|
*/
|
|
131
|
-
export function
|
|
109
|
+
export function createGithubSync(
|
|
132
110
|
deps: InstallationReposWiringDeps,
|
|
133
|
-
):
|
|
111
|
+
): GithubSyncService {
|
|
134
112
|
const client = lazyInstallerClient(deps);
|
|
135
|
-
return new
|
|
136
|
-
agents: new
|
|
113
|
+
return new GithubSyncService({
|
|
114
|
+
agents: new PrismaInstallationAgents(deps.prisma, deps.agentEnv),
|
|
137
115
|
access: deps.access,
|
|
138
116
|
installation:
|
|
139
117
|
deps.installationRepos ??
|
|
140
118
|
createInstallationReposPort(createInstallationPort(client), client),
|
|
141
|
-
audit: new
|
|
119
|
+
audit: new PrismaInstallationAudit(deps.prisma),
|
|
142
120
|
...(deps.openWork ? { openWork: deps.openWork } : {}),
|
|
143
121
|
});
|
|
144
122
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
accessFor,
|
|
4
|
+
envWith,
|
|
5
|
+
fakeOpenWork,
|
|
6
|
+
fakePrisma,
|
|
7
|
+
} from "./github-installation.fixtures.ts";
|
|
8
|
+
import {
|
|
9
|
+
createGithubInstallationRepos,
|
|
10
|
+
createGithubSync,
|
|
11
|
+
} from "./github-installation-wiring.ts";
|
|
12
|
+
import type { InstallationReposPort } from "./installation-repos-service.ts";
|
|
13
|
+
|
|
14
|
+
const noApp = { get: async () => null, getPrivateKey: async () => null };
|
|
15
|
+
|
|
16
|
+
const portWith = (
|
|
17
|
+
seen: number[],
|
|
18
|
+
repos: string[] = ["acme/old", "acme/api"],
|
|
19
|
+
): InstallationReposPort => ({
|
|
20
|
+
listRepos: async (appId) => {
|
|
21
|
+
seen.push(appId);
|
|
22
|
+
return { acme: repos };
|
|
23
|
+
},
|
|
24
|
+
listInstalled: async (appId) => {
|
|
25
|
+
seen.push(appId);
|
|
26
|
+
return [{ org: "acme", repos }];
|
|
27
|
+
},
|
|
28
|
+
addRepos: async () => {},
|
|
29
|
+
removeRepos: async () => {},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("createGithubInstallationRepos", () => {
|
|
33
|
+
it("lists from the agent's own stored GH_APP_ID", async () => {
|
|
34
|
+
const seen: number[] = [];
|
|
35
|
+
const { prisma } = fakePrisma(["acme/old"]);
|
|
36
|
+
const svc = createGithubInstallationRepos({
|
|
37
|
+
prisma,
|
|
38
|
+
appService: noApp,
|
|
39
|
+
access: accessFor(["acme/api"]),
|
|
40
|
+
agentEnv: envWith({ GH_APP_ID: " 77 " }),
|
|
41
|
+
installationRepos: portWith(seen),
|
|
42
|
+
});
|
|
43
|
+
const res = await svc.list("a1");
|
|
44
|
+
expect(seen).toEqual([77]);
|
|
45
|
+
expect(res.status).toBe("ok");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("reports an agent with no GH_APP_ID, naming the missing var", async () => {
|
|
49
|
+
const { prisma } = fakePrisma(["acme/old"]);
|
|
50
|
+
const envs: (Record<string, string> | undefined)[] = [
|
|
51
|
+
undefined,
|
|
52
|
+
{ OTHER: "x" },
|
|
53
|
+
{ GH_APP_ID: "abc" },
|
|
54
|
+
];
|
|
55
|
+
for (const env of envs) {
|
|
56
|
+
const svc = createGithubInstallationRepos({
|
|
57
|
+
prisma,
|
|
58
|
+
appService: noApp,
|
|
59
|
+
access: accessFor([]),
|
|
60
|
+
agentEnv: envWith(env),
|
|
61
|
+
installationRepos: portWith([]),
|
|
62
|
+
});
|
|
63
|
+
const res = await svc.list("a1");
|
|
64
|
+
expect(res.status).toBe("no_app_id");
|
|
65
|
+
if (res.status === "no_app_id") expect(res.reason).toContain("GH_APP_ID");
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe("createGithubSync", () => {
|
|
71
|
+
const build = (openWork?: ReturnType<typeof fakeOpenWork>["port"]) => {
|
|
72
|
+
const { prisma, state } = fakePrisma(["acme/old", "acme/api"]);
|
|
73
|
+
const svc = createGithubSync({
|
|
74
|
+
prisma,
|
|
75
|
+
appService: noApp,
|
|
76
|
+
access: accessFor(["acme/api"]),
|
|
77
|
+
agentEnv: envWith({ GH_APP_ID: "42" }),
|
|
78
|
+
installationRepos: portWith([]),
|
|
79
|
+
openWork,
|
|
80
|
+
});
|
|
81
|
+
return { svc, state };
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
it("with a port: preview lists affected open work and apply blocks it", async () => {
|
|
85
|
+
const { port, calls } = fakeOpenWork();
|
|
86
|
+
const { svc, state } = build(port);
|
|
87
|
+
const preview = await svc.preview("a1");
|
|
88
|
+
expect(preview.status).toBe("previewed");
|
|
89
|
+
const res = await svc.apply({
|
|
90
|
+
agentId: "a1",
|
|
91
|
+
caller: "root",
|
|
92
|
+
appAdds: [],
|
|
93
|
+
appRemoves: ["acme/old"],
|
|
94
|
+
agentRemoves: ["acme/old"],
|
|
95
|
+
});
|
|
96
|
+
expect(res.status).toBe("applied");
|
|
97
|
+
expect(state.repos).toEqual(["acme/api"]);
|
|
98
|
+
const block = calls.find((c) => c.fn === "block");
|
|
99
|
+
expect(block?.args[0]).toBe("a1");
|
|
100
|
+
expect(block?.args[1]).toEqual(["acme/old"]);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("without a port: nothing is blocked, apply still works", async () => {
|
|
104
|
+
const { svc, state } = build();
|
|
105
|
+
const res = await svc.apply({
|
|
106
|
+
agentId: "a1",
|
|
107
|
+
caller: "root",
|
|
108
|
+
appAdds: [],
|
|
109
|
+
appRemoves: [],
|
|
110
|
+
agentRemoves: ["acme/old"],
|
|
111
|
+
});
|
|
112
|
+
expect(res.status).toBe("applied");
|
|
113
|
+
expect(state.repos).toEqual(["acme/api"]);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/github-installation.fixtures.ts
|
|
3
|
+
* Shared fakes for the installation repos / GitHub Sync wiring tests.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { PrismaClient } from "../prisma/client/client.ts";
|
|
7
|
+
import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
|
|
8
|
+
import type { OpenWorkPort } from "./reconcile-open-work.ts";
|
|
9
|
+
|
|
10
|
+
export const accessFor = (pushable: string[]): GithubAccessPreviewFn => {
|
|
11
|
+
return async () => ({
|
|
12
|
+
status: "ok",
|
|
13
|
+
access: {
|
|
14
|
+
username: "dev",
|
|
15
|
+
outcome: "ok",
|
|
16
|
+
userVerified: true,
|
|
17
|
+
complete: true,
|
|
18
|
+
unresolved: 0,
|
|
19
|
+
checkedAt: "2026-11-11T00:00:00.000Z",
|
|
20
|
+
orgs: [
|
|
21
|
+
{
|
|
22
|
+
org: "acme",
|
|
23
|
+
status: "ok",
|
|
24
|
+
unresolved: 0,
|
|
25
|
+
repos: pushable.map((fullName) => ({
|
|
26
|
+
fullName,
|
|
27
|
+
level: "write" as const,
|
|
28
|
+
canPush: true,
|
|
29
|
+
})),
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function fakePrisma(repos: string[]) {
|
|
37
|
+
const state = { repos: [...repos], audits: 0 };
|
|
38
|
+
const prisma = {
|
|
39
|
+
agent: {
|
|
40
|
+
findUnique: async () => ({
|
|
41
|
+
id: "a1",
|
|
42
|
+
repos: state.repos,
|
|
43
|
+
githubUsername: "dev",
|
|
44
|
+
}),
|
|
45
|
+
update: async (args: { data: { repos: string[] } }) => {
|
|
46
|
+
state.repos = args.data.repos;
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
gitHubReconcileAudit: {
|
|
50
|
+
create: async () => {
|
|
51
|
+
state.audits += 1;
|
|
52
|
+
return { id: "audit-1" };
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
} as unknown as PrismaClient;
|
|
56
|
+
return { prisma, state };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function fakeOpenWork() {
|
|
60
|
+
const calls: { fn: string; args: unknown[] }[] = [];
|
|
61
|
+
const port: OpenWorkPort = {
|
|
62
|
+
listOpenWork: async (...args) => {
|
|
63
|
+
calls.push({ fn: "list", args });
|
|
64
|
+
return [{ id: "T-1", repo: "acme/old", title: "fix it" }];
|
|
65
|
+
},
|
|
66
|
+
blockOpenWork: async (...args) => {
|
|
67
|
+
calls.push({ fn: "block", args });
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
return { port, calls };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const envWith = (env?: Record<string, string>) => ({
|
|
74
|
+
getConfigBundle: async (agentId: string) =>
|
|
75
|
+
env ? { env, agentId, allowedTools: [] } : null,
|
|
76
|
+
});
|