@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.
Files changed (36) hide show
  1. package/openapi.platform.json +136 -766
  2. package/package.json +2 -2
  3. package/src/admin-boot.ts +4 -15
  4. package/src/admin-extension.ts +3 -3
  5. package/src/admin-ui-github-identity.smoke.test.ts +24 -116
  6. package/src/admin-ui-installation-repos-pages.ts +198 -231
  7. package/src/admin-ui-installation-repos-pages.unit.test.ts +199 -0
  8. package/src/admin-ui-installation-repos.smoke.test.ts +166 -173
  9. package/src/admin-ui-pages.ts +2 -2
  10. package/src/admin-ui.ts +103 -171
  11. package/src/agents-api.smoke.test.ts +195 -642
  12. package/src/agents-api.ts +86 -477
  13. package/src/github-enterprise-isolation.unit.test.ts +4 -4
  14. package/src/{github-reconcile-wiring.ts → github-installation-wiring.ts} +24 -46
  15. package/src/github-installation-wiring.unit.test.ts +115 -0
  16. package/src/github-installation.fixtures.ts +76 -0
  17. package/src/github-sync.ts +407 -0
  18. package/src/{lost-access-removal.unit.test.ts → github-sync.unit.test.ts} +220 -115
  19. package/src/installation-ports.integration.test.ts +89 -0
  20. package/src/installation-ports.ts +207 -0
  21. package/src/installation-ports.unit.test.ts +51 -0
  22. package/src/installation-repos-service.ts +10 -105
  23. package/src/installation-repos-service.unit.test.ts +5 -90
  24. package/src/reconcile-open-work.ts +5 -7
  25. package/src/repo-access-rules.ts +58 -0
  26. package/src/repo-access-rules.unit.test.ts +98 -0
  27. package/src/admin-ui-github-reconcile-pages.ts +0 -208
  28. package/src/admin-ui-github-reconcile-pages.unit.test.ts +0 -226
  29. package/src/github-reconcile-routes.integration.test.ts +0 -206
  30. package/src/github-reconcile-wiring.unit.test.ts +0 -170
  31. package/src/lost-access-removal.ts +0 -333
  32. package/src/reconcile-apply-service.integration.test.ts +0 -271
  33. package/src/reconcile-apply-service.ts +0 -439
  34. package/src/reconcile-apply-service.unit.test.ts +0 -279
  35. package/src/reconcile-planner.ts +0 -264
  36. 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 reconcile wiring. Agent config bundle, agent-bearer routes and env serialization must
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-reconcile-wiring.ts",
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 reconcile wiring", () => {
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-reconcile-wiring.ts",
78
+ "admin/src/github-installation-wiring.ts",
79
79
  ]);
80
80
  });
81
81
 
@@ -1,9 +1,9 @@
1
1
  /**
2
- * admin/src/github-reconcile-wiring.ts
3
- * Composition of the GitHub reconcile service for admin boot (GHE-3.9).
4
- * Builds ReconcileApplyService from the stored enterprise Apps and an
5
- * optional host-supplied OpenWorkPort. The agent App id comes from each agent's
6
- * own stored GH_APP_ID; without an open-work port nothing is listed or blocked.
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
- PrismaReconcileAgents,
18
- PrismaReconcileAudit,
19
- ReconcileApplyService,
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 { LostAccessRemovalService } from "./lost-access-removal.ts";
26
+ import { GithubSyncService } from "./github-sync.ts";
29
27
  import type { OpenWorkPort } from "./reconcile-open-work.ts";
30
28
 
31
- export interface GithubReconcileWiringDeps {
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
- GithubReconcileWiringDeps,
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
- * The `githubReconcile` dep for createAdminApp. The agent App id is resolved
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/add/remove on the agent App's installation, audited in the reconcile
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 PrismaReconcileAgents(deps.prisma, deps.agentEnv),
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 `githubLostAccessRemoval` dep for createAdminApp (IRM-1.3): removes the
127
- * repos the bound user can no longer push to from the agent App's
128
- * installation and the agent's repos, blocking open work through the
129
- * optional host OpenWorkPort.
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 createGithubLostAccessRemoval(
109
+ export function createGithubSync(
132
110
  deps: InstallationReposWiringDeps,
133
- ): LostAccessRemovalService {
111
+ ): GithubSyncService {
134
112
  const client = lazyInstallerClient(deps);
135
- return new LostAccessRemovalService({
136
- agents: new PrismaReconcileAgents(deps.prisma, deps.agentEnv),
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 PrismaReconcileAudit(deps.prisma),
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
+ });