@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
@@ -1,274 +0,0 @@
1
- import { describe, expect, test } from "bun:test";
2
- import { planReconcile, type ReconcilePlanInput } from "./reconcile-planner.ts";
3
- import {
4
- type OrgAccessResult,
5
- SELECTED_REPOS_REASON,
6
- type UserRepoAccessResult,
7
- } from "./user-repo-access-resolver.ts";
8
-
9
- const repo = (fullName: string, canPush: boolean) => ({
10
- fullName,
11
- canPush,
12
- level: canPush ? ("write" as const) : ("read" as const),
13
- });
14
-
15
- const org = (
16
- name: string,
17
- repos: ReturnType<typeof repo>[],
18
- extra: Partial<OrgAccessResult> = {},
19
- ): OrgAccessResult => ({
20
- org: name,
21
- status: "ok",
22
- repos,
23
- unresolved: 0,
24
- ...extra,
25
- });
26
-
27
- const access = (
28
- orgs: OrgAccessResult[],
29
- extra: Partial<UserRepoAccessResult> = {},
30
- ): UserRepoAccessResult => ({
31
- username: "octo",
32
- outcome: "ok",
33
- userVerified: true,
34
- orgs,
35
- unresolved: 0,
36
- complete: orgs.every((o) => o.status === "ok"),
37
- checkedAt: "2026-11-11T00:00:00.000Z",
38
- ...extra,
39
- });
40
-
41
- const base = (over: Partial<ReconcilePlanInput> = {}): ReconcilePlanInput => ({
42
- username: "octo",
43
- access: access([org("acme", [repo("acme/a", true), repo("acme/b", false)])]),
44
- agentRepos: ["acme/a", "acme/b"],
45
- installationRepos: { acme: ["acme/a", "acme/b"] },
46
- ...over,
47
- });
48
-
49
- describe("planReconcile", () => {
50
- test("removes repos the user cannot push to, from config and installation", () => {
51
- const p = planReconcile(base());
52
- expect(p.diff.configRemoves).toEqual(["acme/b"]);
53
- expect(p.diff.installationRemoves).toEqual(["acme/b"]);
54
- expect(p.diff.configAdds).toEqual([]);
55
- });
56
-
57
- test("never adds newly accessible repos that were not named", () => {
58
- const p = planReconcile(
59
- base({
60
- access: access([
61
- org("acme", [
62
- repo("acme/a", true),
63
- repo("acme/b", true),
64
- repo("acme/new", true),
65
- ]),
66
- ]),
67
- }),
68
- );
69
- expect(p.empty).toBe(true);
70
- expect(p.diff.configAdds).toEqual([]);
71
- });
72
-
73
- test("skips removals for a partial org with a reason", () => {
74
- const p = planReconcile(
75
- base({
76
- access: access([
77
- org("acme", [repo("acme/a", true)], {
78
- status: "partial",
79
- unresolved: 1,
80
- }),
81
- ]),
82
- }),
83
- );
84
- expect(p.diff.configRemoves).toEqual([]);
85
- expect(p.skippedOrgs).toEqual([
86
- { org: "acme", reason: "access listing is incomplete" },
87
- ]);
88
- });
89
-
90
- test("skips removals for failed and unchecked orgs", () => {
91
- const failed = planReconcile(
92
- base({ access: access([org("acme", [], { status: "error" })]) }),
93
- );
94
- expect(failed.diff.configRemoves).toEqual([]);
95
- expect(failed.skippedOrgs[0].reason).toContain("error");
96
- const unchecked = planReconcile(base({ access: access([]) }));
97
- expect(unchecked.diff.configRemoves).toEqual([]);
98
- expect(unchecked.skippedOrgs[0].reason).toBe("org was not checked");
99
- });
100
-
101
- test("skips removals for a selected-only lookup installation", () => {
102
- const p = planReconcile(
103
- base({
104
- access: access([
105
- org("acme", [repo("acme/a", true)], {
106
- status: "partial",
107
- reason: SELECTED_REPOS_REASON,
108
- }),
109
- ]),
110
- }),
111
- );
112
- expect(p.diff.configRemoves).toEqual([]);
113
- expect(p.skippedOrgs[0].reason).toContain("selected repositories");
114
- });
115
-
116
- test("only the incomplete org is skipped; other orgs still reconcile", () => {
117
- const p = planReconcile(
118
- base({
119
- access: access([
120
- org("acme", [repo("acme/a", true)], { status: "partial" }),
121
- org("beta", [repo("beta/x", false)]),
122
- ]),
123
- agentRepos: ["acme/b", "beta/x"],
124
- installationRepos: { acme: ["acme/b"], beta: ["beta/x"] },
125
- }),
126
- );
127
- expect(p.diff.configRemoves).toEqual(["beta/x"]);
128
- expect(p.skippedOrgs.map((s) => s.org)).toEqual(["acme"]);
129
- });
130
-
131
- test("named add: accepted when push-capable, installs when absent", () => {
132
- const p = planReconcile(
133
- base({
134
- access: access([
135
- org("acme", [
136
- repo("acme/a", true),
137
- repo("acme/c", true),
138
- repo("acme/b", true),
139
- ]),
140
- ]),
141
- namedAdds: ["acme/c"],
142
- }),
143
- );
144
- expect(p.diff.configAdds).toEqual(["acme/c"]);
145
- expect(p.diff.installationAdds).toEqual(["acme/c"]);
146
- });
147
-
148
- test("named add: rejected when not push-capable", () => {
149
- const p = planReconcile(
150
- base({
151
- access: access([
152
- org("acme", [repo("acme/a", true), repo("acme/c", false)]),
153
- ]),
154
- agentRepos: ["acme/a"],
155
- namedAdds: ["acme/c", "acme/unknown"],
156
- }),
157
- );
158
- expect(p.diff.configAdds).toEqual([]);
159
- expect(p.rejectedAdds.map((r) => r.repo)).toEqual([
160
- "acme/c",
161
- "acme/unknown",
162
- ]);
163
- });
164
-
165
- test("named add: rejected on basename collision with kept repo or another add", () => {
166
- const p = planReconcile(
167
- base({
168
- access: access([
169
- org("acme", [repo("acme/a", true)]),
170
- org("beta", [repo("beta/a", true), repo("beta/z", true)]),
171
- org("gamma", [repo("gamma/z", true)]),
172
- ]),
173
- agentRepos: ["acme/a"],
174
- installationRepos: { acme: ["acme/a"] },
175
- namedAdds: ["beta/a", "beta/z", "gamma/z"],
176
- }),
177
- );
178
- expect(p.diff.configAdds).toEqual(["beta/z"]);
179
- expect(p.rejectedAdds).toEqual([
180
- { repo: "beta/a", reason: "basename collides with acme/a" },
181
- { repo: "gamma/z", reason: "basename collides with beta/z" },
182
- ]);
183
- });
184
-
185
- test("a repo being removed does not block a colliding add", () => {
186
- const p = planReconcile(
187
- base({
188
- access: access([
189
- org("acme", [repo("acme/a", false)]),
190
- org("beta", [repo("beta/a", true)]),
191
- ]),
192
- agentRepos: ["acme/a"],
193
- installationRepos: { acme: ["acme/a"], beta: ["beta/a"] },
194
- namedAdds: ["beta/a"],
195
- }),
196
- );
197
- expect(p.diff.configRemoves).toEqual(["acme/a"]);
198
- expect(p.diff.configAdds).toEqual(["beta/a"]);
199
- });
200
-
201
- test("subset invariant: config repos missing from installation are dropped", () => {
202
- const p = planReconcile(
203
- base({ agentRepos: ["acme/a"], installationRepos: { acme: [] } }),
204
- );
205
- expect(p.diff.configRemoves).toEqual(["acme/a"]);
206
- expect(p.diff.installationRemoves).toEqual([]);
207
- expect(p.warnings.join()).toContain("not in the agent installation");
208
- });
209
-
210
- test("subset invariant: result is always within the installation", () => {
211
- const input = base({
212
- access: access([
213
- org("acme", [
214
- repo("acme/a", true),
215
- repo("acme/b", false),
216
- repo("acme/c", true),
217
- ]),
218
- ]),
219
- namedAdds: ["acme/c"],
220
- });
221
- const p = planReconcile(input);
222
- const installed = new Set(
223
- (input.installationRepos.acme ?? [])
224
- .filter((r) => !p.diff.installationRemoves.includes(r))
225
- .concat(p.diff.installationAdds),
226
- );
227
- const finalConfig = input.agentRepos
228
- .filter((r) => !p.diff.configRemoves.includes(r))
229
- .concat(p.diff.configAdds);
230
- for (const r of finalConfig) expect(installed.has(r)).toBe(true);
231
- });
232
-
233
- test("idempotent: reconciled state yields an empty diff and same hash", () => {
234
- const first = planReconcile(base());
235
- const reconciled = base({
236
- agentRepos: ["acme/a"],
237
- installationRepos: { acme: ["acme/a"] },
238
- });
239
- const second = planReconcile(reconciled);
240
- const third = planReconcile(reconciled);
241
- expect(first.empty).toBe(false);
242
- expect(second.empty).toBe(true);
243
- expect(second.planHash).toBe(third.planHash);
244
- expect(second.planHash).not.toBe(first.planHash);
245
- });
246
-
247
- test("hash is independent of input ordering", () => {
248
- const a = planReconcile(base({ agentRepos: ["acme/a", "acme/b"] }));
249
- const b = planReconcile(base({ agentRepos: ["acme/b", "acme/a"] }));
250
- expect(a.planHash).toBe(b.planHash);
251
- });
252
-
253
- test("unbound username yields a skipped plan", () => {
254
- for (const username of [null, undefined, " "]) {
255
- const p = planReconcile(base({ username }));
256
- expect(p.skipped).toBe(true);
257
- expect(p.skipReason).toContain("no GitHub username");
258
- expect(p.empty).toBe(true);
259
- }
260
- });
261
-
262
- test("unresolved access, unknown user and unverified user skip the plan", () => {
263
- expect(planReconcile(base({ access: null })).skipped).toBe(true);
264
- expect(
265
- planReconcile(base({ access: access([], { outcome: "user_not_found" }) }))
266
- .skipped,
267
- ).toBe(true);
268
- const unverified = planReconcile(
269
- base({ access: access([], { userVerified: false }) }),
270
- );
271
- expect(unverified.skipped).toBe(true);
272
- expect(unverified.diff.configRemoves).toEqual([]);
273
- });
274
- });