@app-vitals/agent-admin 1.35.1 → 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 +55 -295
- package/package.json +2 -2
- package/src/admin-boot.ts +3 -3
- package/src/admin-extension.ts +1 -1
- package/src/admin-ui-github-identity.smoke.test.ts +24 -2
- 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 -172
- package/src/admin-ui-pages.ts +2 -2
- package/src/admin-ui.ts +103 -89
- package/src/agents-api.smoke.test.ts +193 -290
- package/src/agents-api.ts +83 -210
- package/src/github-installation-wiring.ts +10 -12
- package/src/github-installation-wiring.unit.test.ts +13 -9
- package/src/github-installation.fixtures.ts +1 -1
- package/src/github-sync.ts +407 -0
- package/src/{lost-access-removal.unit.test.ts → github-sync.unit.test.ts} +214 -109
- package/src/installation-ports.ts +1 -1
- package/src/installation-repos-service.ts +3 -98
- package/src/installation-repos-service.unit.test.ts +5 -90
- package/src/reconcile-open-work.ts +1 -1
- package/src/repo-access-rules.ts +1 -1
- package/src/lost-access-removal.ts +0 -333
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { describe, expect, it, test } from "bun:test";
|
|
2
2
|
import type { GithubAccessPreviewFn } from "./github-access-preview.ts";
|
|
3
|
-
import type { InstallationReposPort } from "./installation-repos-service.ts";
|
|
4
3
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
GITHUB_SYNC_AUDIT_PLAN_HASH,
|
|
5
|
+
GithubSyncService,
|
|
6
|
+
NOT_ADDABLE_REASON,
|
|
8
7
|
NOT_PRESENT_REASON,
|
|
9
|
-
|
|
8
|
+
planGithubSync,
|
|
10
9
|
STILL_PUSHABLE_REASON,
|
|
11
|
-
|
|
10
|
+
type GithubSyncPlanInput,
|
|
11
|
+
} from "./github-sync.ts";
|
|
12
12
|
import type {
|
|
13
13
|
InstallationAgentRecord,
|
|
14
14
|
InstallationAuditEntry,
|
|
15
15
|
} from "./installation-ports.ts";
|
|
16
|
+
import type { InstallationReposPort } from "./installation-repos-service.ts";
|
|
16
17
|
import type { OpenWorkPort } from "./reconcile-open-work.ts";
|
|
17
18
|
import { repoLostAccessBlockReason } from "./repo-removal-open-work.ts";
|
|
18
19
|
import {
|
|
@@ -53,15 +54,18 @@ const access = (
|
|
|
53
54
|
...extra,
|
|
54
55
|
});
|
|
55
56
|
|
|
57
|
+
// The user can push to a, d, e; not to b, c.
|
|
56
58
|
const ACME = org("acme", [
|
|
57
59
|
repo("acme/a", true),
|
|
58
60
|
repo("acme/b", false),
|
|
59
61
|
repo("acme/c", false),
|
|
62
|
+
repo("acme/d", true),
|
|
63
|
+
repo("acme/e", true),
|
|
60
64
|
]);
|
|
61
65
|
|
|
62
66
|
const base = (
|
|
63
|
-
over: Partial<
|
|
64
|
-
):
|
|
67
|
+
over: Partial<GithubSyncPlanInput> = {},
|
|
68
|
+
): GithubSyncPlanInput => ({
|
|
65
69
|
username: "octo",
|
|
66
70
|
access: access([ACME]),
|
|
67
71
|
agentRepos: ["acme/a", "acme/b"],
|
|
@@ -69,71 +73,104 @@ const base = (
|
|
|
69
73
|
...over,
|
|
70
74
|
});
|
|
71
75
|
|
|
72
|
-
describe("
|
|
73
|
-
test("
|
|
74
|
-
const p =
|
|
76
|
+
describe("planGithubSync (preview)", () => {
|
|
77
|
+
test("lists app adds, app removes and agent removes", () => {
|
|
78
|
+
const p = planGithubSync(base());
|
|
75
79
|
expect(p.skipped).toBe(false);
|
|
76
|
-
expect(p.
|
|
77
|
-
expect(p.
|
|
78
|
-
expect(p.
|
|
80
|
+
expect(p.appAdds).toEqual(["acme/d", "acme/e"]);
|
|
81
|
+
expect(p.appRemoves).toEqual(["acme/b", "acme/c"]);
|
|
82
|
+
expect(p.agentRemoves).toEqual(["acme/b"]);
|
|
83
|
+
expect(p.removedRepos).toEqual(["acme/b", "acme/c"]);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test("agent repos are never added", () => {
|
|
87
|
+
const p = planGithubSync(base({ agentRepos: [] }));
|
|
88
|
+
expect(p.appAdds).toEqual(["acme/d", "acme/e"]);
|
|
89
|
+
expect(p.agentRemoves).toEqual([]);
|
|
90
|
+
expect("agentAdds" in p).toBe(false);
|
|
79
91
|
});
|
|
80
92
|
|
|
81
|
-
test("
|
|
82
|
-
const
|
|
83
|
-
|
|
93
|
+
test("adds have no cap", () => {
|
|
94
|
+
const many = Array.from({ length: 40 }, (_, i) => repo(`acme/n${i}`, true));
|
|
95
|
+
const p = planGithubSync(
|
|
96
|
+
base({
|
|
97
|
+
access: access([org("acme", many)]),
|
|
98
|
+
agentRepos: [],
|
|
99
|
+
installationRepos: { acme: [] },
|
|
100
|
+
}),
|
|
84
101
|
);
|
|
85
|
-
expect(p.
|
|
86
|
-
expect(p.configRemoves).toEqual([]);
|
|
102
|
+
expect(p.appAdds).toHaveLength(40);
|
|
87
103
|
});
|
|
88
104
|
|
|
89
|
-
test("
|
|
90
|
-
const p =
|
|
91
|
-
base({
|
|
105
|
+
test("nothing to do once the lists are applied", () => {
|
|
106
|
+
const p = planGithubSync(
|
|
107
|
+
base({
|
|
108
|
+
agentRepos: ["acme/a"],
|
|
109
|
+
installationRepos: { acme: ["acme/a", "acme/d", "acme/e"] },
|
|
110
|
+
}),
|
|
92
111
|
);
|
|
93
|
-
expect(p.
|
|
112
|
+
expect([p.appAdds, p.appRemoves, p.agentRemoves]).toEqual([[], [], []]);
|
|
94
113
|
});
|
|
95
114
|
|
|
96
|
-
test("push checks ignore case", () => {
|
|
97
|
-
const p =
|
|
115
|
+
test("push checks and installed lookups ignore case", () => {
|
|
116
|
+
const p = planGithubSync(
|
|
98
117
|
base({ agentRepos: ["ACME/A"], installationRepos: { acme: ["Acme/a"] } }),
|
|
99
118
|
);
|
|
100
|
-
expect(p.
|
|
119
|
+
expect(p.appRemoves).toEqual([]);
|
|
120
|
+
expect(p.agentRemoves).toEqual([]);
|
|
121
|
+
expect(p.appAdds).not.toContain("acme/a");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test("a repo missing from a complete org listing counts as no access", () => {
|
|
125
|
+
const p = planGithubSync(
|
|
126
|
+
base({ agentRepos: ["acme/gone"], installationRepos: { acme: [] } }),
|
|
127
|
+
);
|
|
128
|
+
expect(p.agentRemoves).toEqual(["acme/gone"]);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("orgs without the agent App installed get no adds", () => {
|
|
132
|
+
const p = planGithubSync(
|
|
133
|
+
base({
|
|
134
|
+
access: access([ACME, org("other", [repo("other/x", true)])]),
|
|
135
|
+
installationRepos: { acme: [] },
|
|
136
|
+
}),
|
|
137
|
+
);
|
|
138
|
+
expect(p.appAdds.every((r) => r.startsWith("acme/"))).toBe(true);
|
|
139
|
+
expect(p.appAdds).not.toContain("other/x");
|
|
101
140
|
});
|
|
102
141
|
|
|
103
142
|
test.each([
|
|
104
143
|
["partial", { status: "partial" as const, unresolved: 1 }],
|
|
105
144
|
["failed", { status: "rate_limited" as const }],
|
|
145
|
+
["not installed", { status: "lookup_app_not_installed" as const }],
|
|
106
146
|
[
|
|
107
147
|
"selected-only",
|
|
108
148
|
{ status: "error" as const, reason: SELECTED_REPOS_REASON },
|
|
109
149
|
],
|
|
110
|
-
])("skips a %s org and reports it", (
|
|
111
|
-
const p =
|
|
112
|
-
base({
|
|
150
|
+
])("skips a %s org for adds and removes and reports it", (_l, extra) => {
|
|
151
|
+
const p = planGithubSync(
|
|
152
|
+
base({
|
|
153
|
+
access: access([
|
|
154
|
+
org("acme", [repo("acme/d", true), repo("acme/b", false)], extra),
|
|
155
|
+
]),
|
|
156
|
+
}),
|
|
113
157
|
);
|
|
114
|
-
expect(p.
|
|
158
|
+
expect([p.appAdds, p.appRemoves, p.agentRemoves]).toEqual([[], [], []]);
|
|
115
159
|
expect(p.skippedOrgs).toHaveLength(1);
|
|
116
160
|
expect(p.skippedOrgs[0]?.org).toBe("acme");
|
|
117
161
|
expect(p.warnings[0]).toContain("acme");
|
|
118
162
|
});
|
|
119
163
|
|
|
120
|
-
test("selected-only reason matches the shared access-rules wording", () => {
|
|
121
|
-
const p = planLostAccessRemoval(
|
|
122
|
-
base({
|
|
123
|
-
access: access([org("acme", [], { reason: SELECTED_REPOS_REASON })]),
|
|
124
|
-
}),
|
|
125
|
-
);
|
|
126
|
-
expect(p.skippedOrgs[0]?.reason).toContain("selected repositories");
|
|
127
|
-
});
|
|
128
|
-
|
|
129
164
|
test("an org missing from the access result is skipped, not emptied", () => {
|
|
130
|
-
const p =
|
|
165
|
+
const p = planGithubSync(
|
|
131
166
|
base({
|
|
132
167
|
agentRepos: ["other/x"],
|
|
133
168
|
installationRepos: { other: ["other/x"] },
|
|
169
|
+
access: access([]),
|
|
134
170
|
}),
|
|
135
171
|
);
|
|
136
|
-
expect(p.
|
|
172
|
+
expect(p.appRemoves).toEqual([]);
|
|
173
|
+
expect(p.agentRemoves).toEqual([]);
|
|
137
174
|
expect(p.skippedOrgs).toEqual([
|
|
138
175
|
{ org: "other", reason: "org was not checked" },
|
|
139
176
|
]);
|
|
@@ -153,30 +190,55 @@ describe("planLostAccessRemoval", () => {
|
|
|
153
190
|
],
|
|
154
191
|
["unresolved", { access: null }, "not resolved"],
|
|
155
192
|
])("a %s user skips the whole plan", (_l, over, reason) => {
|
|
156
|
-
const p =
|
|
193
|
+
const p = planGithubSync(base(over as Partial<GithubSyncPlanInput>));
|
|
157
194
|
expect(p.skipped).toBe(true);
|
|
158
195
|
expect(p.skipReason).toContain(reason);
|
|
159
|
-
expect(p.
|
|
196
|
+
expect([p.appAdds, p.appRemoves, p.agentRemoves]).toEqual([[], [], []]);
|
|
160
197
|
});
|
|
198
|
+
});
|
|
161
199
|
|
|
162
|
-
|
|
163
|
-
|
|
200
|
+
describe("planGithubSync (confirmed lists)", () => {
|
|
201
|
+
it("re-checks every confirmed repo and reports the ones left alone", () => {
|
|
202
|
+
const p = planGithubSync(
|
|
164
203
|
base({
|
|
165
204
|
agentRepos: ["acme/a", "acme/b", "other/x"],
|
|
166
|
-
requested:
|
|
167
|
-
|
|
205
|
+
requested: {
|
|
206
|
+
appAdds: ["acme/d", "acme/b", "acme/c", "other/y"],
|
|
207
|
+
appRemoves: ["acme/b", "acme/a", "acme/zzz"],
|
|
208
|
+
agentRemoves: ["acme/b", "acme/a", "other/x"],
|
|
209
|
+
},
|
|
168
210
|
}),
|
|
169
211
|
);
|
|
170
|
-
expect(p.
|
|
171
|
-
expect(p.
|
|
172
|
-
expect(p.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
212
|
+
expect(p.appAdds).toEqual(["acme/d"]);
|
|
213
|
+
expect(p.appRemoves).toEqual(["acme/b"]);
|
|
214
|
+
expect(p.agentRemoves).toEqual(["acme/b"]);
|
|
215
|
+
expect(p.notApplied).toContainEqual({
|
|
216
|
+
repo: "acme/b",
|
|
217
|
+
reason: NOT_ADDABLE_REASON,
|
|
218
|
+
});
|
|
219
|
+
expect(p.notApplied).toContainEqual({
|
|
220
|
+
repo: "acme/a",
|
|
221
|
+
reason: STILL_PUSHABLE_REASON,
|
|
222
|
+
});
|
|
223
|
+
expect(p.notApplied).toContainEqual({
|
|
224
|
+
repo: "acme/zzz",
|
|
225
|
+
reason: NOT_PRESENT_REASON,
|
|
226
|
+
});
|
|
227
|
+
expect(p.notApplied).toContainEqual({
|
|
228
|
+
repo: "other/x",
|
|
229
|
+
reason: "skipped for org: org was not checked",
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("a confirmed add is never applied to the agent's repos", () => {
|
|
234
|
+
const p = planGithubSync(
|
|
235
|
+
base({
|
|
236
|
+
agentRepos: [],
|
|
237
|
+
requested: { appAdds: ["acme/d"], appRemoves: [], agentRemoves: [] },
|
|
238
|
+
}),
|
|
239
|
+
);
|
|
240
|
+
expect(p.appAdds).toEqual(["acme/d"]);
|
|
241
|
+
expect(p.agentRemoves).toEqual([]);
|
|
180
242
|
});
|
|
181
243
|
});
|
|
182
244
|
|
|
@@ -194,31 +256,35 @@ function harness(
|
|
|
194
256
|
const calls: unknown[][] = [];
|
|
195
257
|
const audits: InstallationAuditEntry[] = [];
|
|
196
258
|
let repos = opts.agent?.repos ?? ["acme/a", "acme/b"];
|
|
259
|
+
let installed = opts.installed ?? [
|
|
260
|
+
{ org: "acme", repos: ["acme/a", "acme/b", "acme/c"] },
|
|
261
|
+
];
|
|
197
262
|
const agent: InstallationAgentRecord | null =
|
|
198
263
|
opts.agent === null
|
|
199
264
|
? null
|
|
200
|
-
: {
|
|
201
|
-
id: "ag",
|
|
202
|
-
githubUsername: "octo",
|
|
203
|
-
appId: 7,
|
|
204
|
-
...opts.agent,
|
|
205
|
-
repos,
|
|
206
|
-
};
|
|
265
|
+
: { id: "ag", githubUsername: "octo", appId: 7, ...opts.agent, repos };
|
|
207
266
|
const installation: Pick<
|
|
208
267
|
InstallationReposPort,
|
|
209
|
-
"listInstalled" | "removeRepos"
|
|
268
|
+
"listInstalled" | "addRepos" | "removeRepos"
|
|
210
269
|
> = {
|
|
211
270
|
listInstalled: async (appId) => {
|
|
212
271
|
calls.push(["listInstalled", appId]);
|
|
213
|
-
return
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
272
|
+
return installed;
|
|
273
|
+
},
|
|
274
|
+
addRepos: async (appId, o, r) => {
|
|
275
|
+
calls.push(["addRepos", appId, o, [...r]]);
|
|
276
|
+
installed = installed.map((i) =>
|
|
277
|
+
i.org === o ? { ...i, repos: [...i.repos, ...r] } : i,
|
|
217
278
|
);
|
|
218
279
|
},
|
|
219
280
|
removeRepos: async (appId, o, r) => {
|
|
220
281
|
calls.push(["removeRepos", appId, o, [...r]]);
|
|
221
282
|
if (opts.removeFails) throw new Error("github says no");
|
|
283
|
+
installed = installed.map((i) =>
|
|
284
|
+
i.org === o
|
|
285
|
+
? { ...i, repos: i.repos.filter((x) => !r.includes(x)) }
|
|
286
|
+
: i,
|
|
287
|
+
);
|
|
222
288
|
},
|
|
223
289
|
};
|
|
224
290
|
const openWork: OpenWorkPort | undefined =
|
|
@@ -234,7 +300,7 @@ function harness(
|
|
|
234
300
|
},
|
|
235
301
|
...opts.openWork,
|
|
236
302
|
};
|
|
237
|
-
const svc = new
|
|
303
|
+
const svc = new GithubSyncService({
|
|
238
304
|
agents: {
|
|
239
305
|
get: async () => (agent ? { ...agent, repos } : null),
|
|
240
306
|
setRepos: async (_id, next) => {
|
|
@@ -256,22 +322,36 @@ function harness(
|
|
|
256
322
|
return { svc, calls, audits, repos: () => repos };
|
|
257
323
|
}
|
|
258
324
|
|
|
259
|
-
const
|
|
325
|
+
const applyInput = (
|
|
326
|
+
lists: {
|
|
327
|
+
appAdds?: string[];
|
|
328
|
+
appRemoves?: string[];
|
|
329
|
+
agentRemoves?: string[];
|
|
330
|
+
},
|
|
331
|
+
extra = {},
|
|
332
|
+
) => ({
|
|
260
333
|
agentId: "ag",
|
|
261
334
|
caller: "root",
|
|
262
|
-
|
|
335
|
+
appAdds: [],
|
|
336
|
+
appRemoves: [],
|
|
337
|
+
agentRemoves: [],
|
|
338
|
+
...lists,
|
|
263
339
|
...extra,
|
|
264
340
|
});
|
|
265
341
|
|
|
266
|
-
describe("
|
|
267
|
-
it("returns
|
|
342
|
+
describe("GithubSyncService.preview", () => {
|
|
343
|
+
it("returns all three lists plus the open work removals block, changing nothing", async () => {
|
|
268
344
|
const { svc, calls, audits } = harness();
|
|
269
345
|
const r = await svc.preview("ag");
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
expect(r.plan.
|
|
346
|
+
if (r.status !== "previewed") throw new Error(r.status);
|
|
347
|
+
expect(r.plan.appAdds).toEqual(["acme/d", "acme/e"]);
|
|
348
|
+
expect(r.plan.appRemoves).toEqual(["acme/b", "acme/c"]);
|
|
349
|
+
expect(r.plan.agentRemoves).toEqual(["acme/b"]);
|
|
273
350
|
expect(r.openWork).toEqual([{ id: "T-1", repo: "acme/b", title: "fix" }]);
|
|
274
|
-
expect(calls
|
|
351
|
+
expect(calls).toEqual([
|
|
352
|
+
["listInstalled", 7],
|
|
353
|
+
["list", "ag", ["acme/b", "acme/c"]],
|
|
354
|
+
]);
|
|
275
355
|
expect(audits).toEqual([]);
|
|
276
356
|
});
|
|
277
357
|
|
|
@@ -302,7 +382,6 @@ describe("LostAccessRemovalService.preview", () => {
|
|
|
302
382
|
const noApp = await harness({ agent: { appId: undefined } }).svc.preview(
|
|
303
383
|
"ag",
|
|
304
384
|
);
|
|
305
|
-
expect(noApp).toMatchObject({ status: "skipped" });
|
|
306
385
|
expect(JSON.stringify(noApp)).toContain("GH_APP_ID");
|
|
307
386
|
});
|
|
308
387
|
|
|
@@ -313,10 +392,16 @@ describe("LostAccessRemovalService.preview", () => {
|
|
|
313
392
|
});
|
|
314
393
|
});
|
|
315
394
|
|
|
316
|
-
describe("
|
|
317
|
-
it("removes
|
|
395
|
+
describe("GithubSyncService.apply", () => {
|
|
396
|
+
it("adds, removes, removes agent repos, audits once, then blocks open work", async () => {
|
|
318
397
|
const { svc, calls, audits, repos } = harness();
|
|
319
|
-
const r = await svc.
|
|
398
|
+
const r = await svc.apply(
|
|
399
|
+
applyInput({
|
|
400
|
+
appAdds: ["acme/d"],
|
|
401
|
+
appRemoves: ["acme/b", "acme/c"],
|
|
402
|
+
agentRemoves: ["acme/b"],
|
|
403
|
+
}),
|
|
404
|
+
);
|
|
320
405
|
expect(r).toMatchObject({
|
|
321
406
|
status: "applied",
|
|
322
407
|
auditId: "audit-1",
|
|
@@ -324,6 +409,7 @@ describe("LostAccessRemovalService.remove", () => {
|
|
|
324
409
|
});
|
|
325
410
|
expect(calls).toEqual([
|
|
326
411
|
["listInstalled", 7],
|
|
412
|
+
["addRepos", 7, "acme", ["acme/d"]],
|
|
327
413
|
["removeRepos", 7, "acme", ["acme/b", "acme/c"]],
|
|
328
414
|
["setRepos", ["acme/a"]],
|
|
329
415
|
["audit"],
|
|
@@ -335,9 +421,9 @@ describe("LostAccessRemovalService.remove", () => {
|
|
|
335
421
|
{
|
|
336
422
|
agentId: "ag",
|
|
337
423
|
caller: "root",
|
|
338
|
-
planHash:
|
|
424
|
+
planHash: GITHUB_SYNC_AUDIT_PLAN_HASH,
|
|
339
425
|
diff: {
|
|
340
|
-
installationAdds: [],
|
|
426
|
+
installationAdds: ["acme/d"],
|
|
341
427
|
installationRemoves: ["acme/b", "acme/c"],
|
|
342
428
|
configAdds: [],
|
|
343
429
|
configRemoves: ["acme/b"],
|
|
@@ -345,22 +431,30 @@ describe("LostAccessRemovalService.remove", () => {
|
|
|
345
431
|
result: { status: "applied" },
|
|
346
432
|
},
|
|
347
433
|
]);
|
|
434
|
+
// A second preview has nothing left to do.
|
|
435
|
+
const again = await svc.preview("ag");
|
|
436
|
+
if (again.status !== "previewed") throw new Error(again.status);
|
|
437
|
+
expect(again.plan.appRemoves).toEqual([]);
|
|
438
|
+
expect(again.plan.agentRemoves).toEqual([]);
|
|
439
|
+
expect(again.plan.appAdds).toEqual(["acme/e"]);
|
|
348
440
|
});
|
|
349
441
|
|
|
350
|
-
it("leaves
|
|
351
|
-
const { svc
|
|
352
|
-
const r = await svc.
|
|
442
|
+
it("leaves confirmed repos that no longer qualify alone and reports them", async () => {
|
|
443
|
+
const { svc } = harness();
|
|
444
|
+
const r = await svc.apply(
|
|
445
|
+
applyInput({ appRemoves: ["acme/a", "acme/b"], appAdds: ["acme/b"] }),
|
|
446
|
+
);
|
|
353
447
|
if (r.status !== "applied") throw new Error(r.status);
|
|
354
|
-
expect(r.plan.
|
|
355
|
-
expect(r.plan.
|
|
356
|
-
|
|
448
|
+
expect(r.plan.appRemoves).toEqual(["acme/b"]);
|
|
449
|
+
expect(r.plan.notApplied.map((n) => n.repo).sort()).toEqual([
|
|
450
|
+
"acme/a",
|
|
451
|
+
"acme/b",
|
|
357
452
|
]);
|
|
358
|
-
expect(repos()).toEqual(["acme/a"]);
|
|
359
453
|
});
|
|
360
454
|
|
|
361
|
-
it("noop with no audit when nothing
|
|
455
|
+
it("noop with no audit when nothing confirmed still applies", async () => {
|
|
362
456
|
const { svc, calls, audits } = harness();
|
|
363
|
-
const r = await svc.
|
|
457
|
+
const r = await svc.apply(applyInput({ appRemoves: ["acme/a"] }));
|
|
364
458
|
expect(r.status).toBe("noop");
|
|
365
459
|
expect(audits).toEqual([]);
|
|
366
460
|
expect(calls.map((c) => c[0])).toEqual(["listInstalled"]);
|
|
@@ -382,40 +476,45 @@ describe("LostAccessRemovalService.remove", () => {
|
|
|
382
476
|
},
|
|
383
477
|
}),
|
|
384
478
|
]) {
|
|
385
|
-
const r = await h.svc.
|
|
479
|
+
const r = await h.svc.apply(applyInput({ appRemoves: ["acme/b"] }));
|
|
386
480
|
expect(r.status).toBe("skipped");
|
|
387
481
|
expect(h.audits).toEqual([]);
|
|
388
482
|
expect(h.calls.filter((c) => c[0] !== "listInstalled")).toEqual([]);
|
|
389
483
|
}
|
|
390
484
|
});
|
|
391
485
|
|
|
392
|
-
it("skipped orgs
|
|
486
|
+
it("skipped orgs get neither adds nor removes", async () => {
|
|
393
487
|
const { svc, audits } = harness({
|
|
394
488
|
access: {
|
|
395
489
|
status: "ok",
|
|
396
490
|
access: access([
|
|
397
|
-
org("acme", [
|
|
491
|
+
org("acme", [repo("acme/d", true)], {
|
|
492
|
+
reason: SELECTED_REPOS_REASON,
|
|
493
|
+
status: "error",
|
|
494
|
+
}),
|
|
398
495
|
]),
|
|
399
496
|
},
|
|
400
497
|
});
|
|
401
|
-
const r = await svc.
|
|
402
|
-
|
|
403
|
-
|
|
498
|
+
const r = await svc.apply(
|
|
499
|
+
applyInput({ appAdds: ["acme/d"], appRemoves: ["acme/b"] }),
|
|
500
|
+
);
|
|
501
|
+
if (r.status !== "noop") throw new Error(r.status);
|
|
404
502
|
expect(r.plan.skippedOrgs[0]?.org).toBe("acme");
|
|
405
503
|
expect(audits).toEqual([]);
|
|
406
504
|
});
|
|
407
505
|
|
|
408
|
-
it("more than 10 removals need confirmRemovals", async () => {
|
|
506
|
+
it("more than 10 removals need confirmRemovals; adds do not count", async () => {
|
|
409
507
|
const many = Array.from({ length: 11 }, (_, i) => `acme/r${i}`);
|
|
410
508
|
const h = harness({
|
|
411
509
|
agent: { repos: many },
|
|
412
510
|
installed: [{ org: "acme", repos: many }],
|
|
413
511
|
});
|
|
414
|
-
const
|
|
512
|
+
const lists = { appRemoves: many, agentRemoves: many, appAdds: ["acme/d"] };
|
|
513
|
+
const r = await h.svc.apply(applyInput(lists));
|
|
415
514
|
expect(r).toMatchObject({ status: "removal_cap", removals: 11 });
|
|
416
515
|
expect(h.audits).toEqual([]);
|
|
417
516
|
expect(h.repos()).toEqual(many);
|
|
418
|
-
const ok = await h.svc.
|
|
517
|
+
const ok = await h.svc.apply(applyInput(lists, { confirmRemovals: true }));
|
|
419
518
|
expect(ok.status).toBe("applied");
|
|
420
519
|
expect(h.repos()).toEqual([]);
|
|
421
520
|
});
|
|
@@ -428,30 +527,36 @@ describe("LostAccessRemovalService.remove", () => {
|
|
|
428
527
|
},
|
|
429
528
|
},
|
|
430
529
|
});
|
|
431
|
-
const r = await svc.
|
|
432
|
-
|
|
433
|
-
if (r.status !== "applied") return;
|
|
530
|
+
const r = await svc.apply(applyInput({ agentRemoves: ["acme/b"] }));
|
|
531
|
+
if (r.status !== "applied") throw new Error(r.status);
|
|
434
532
|
expect(r.warnings[0]).toContain("acme/b");
|
|
435
533
|
expect(r.warnings[0]).toContain("store down");
|
|
436
534
|
expect(audits).toHaveLength(1);
|
|
437
535
|
});
|
|
438
536
|
|
|
439
537
|
it("works without an open-work port", async () => {
|
|
440
|
-
const r = await harness({ openWork: null }).svc.
|
|
441
|
-
|
|
538
|
+
const r = await harness({ openWork: null }).svc.apply(
|
|
539
|
+
applyInput({ agentRemoves: ["acme/b"] }),
|
|
442
540
|
);
|
|
443
541
|
expect(r).toMatchObject({ status: "applied", warnings: [] });
|
|
444
542
|
});
|
|
445
543
|
|
|
446
544
|
it("a GitHub failure writes a failed audit with only what landed and blocks nothing", async () => {
|
|
447
545
|
const { svc, calls, audits, repos } = harness({ removeFails: true });
|
|
448
|
-
const r = await svc.
|
|
546
|
+
const r = await svc.apply(
|
|
547
|
+
applyInput({
|
|
548
|
+
appAdds: ["acme/d"],
|
|
549
|
+
appRemoves: ["acme/b"],
|
|
550
|
+
agentRemoves: ["acme/b"],
|
|
551
|
+
}),
|
|
552
|
+
);
|
|
449
553
|
expect(r).toMatchObject({ status: "failed", auditId: "audit-1" });
|
|
450
554
|
expect(repos()).toEqual(["acme/a", "acme/b"]);
|
|
451
555
|
expect(audits[0]?.result).toEqual({
|
|
452
556
|
status: "failed",
|
|
453
557
|
error: "github says no",
|
|
454
558
|
});
|
|
559
|
+
expect(audits[0]?.diff.installationAdds).toEqual(["acme/d"]);
|
|
455
560
|
expect(audits[0]?.diff.installationRemoves).toEqual([]);
|
|
456
561
|
expect(audits[0]?.diff.configRemoves).toEqual([]);
|
|
457
562
|
expect(calls.some((c) => c[0] === "block")).toBe(false);
|
|
@@ -459,7 +564,7 @@ describe("LostAccessRemovalService.remove", () => {
|
|
|
459
564
|
|
|
460
565
|
it("removes an agent repo even when the App is not installed on its org", async () => {
|
|
461
566
|
const { svc, calls, repos } = harness({ installed: [] });
|
|
462
|
-
const r = await svc.
|
|
567
|
+
const r = await svc.apply(applyInput({ agentRemoves: ["acme/b"] }));
|
|
463
568
|
expect(r.status).toBe("applied");
|
|
464
569
|
expect(calls.some((c) => c[0] === "removeRepos")).toBe(false);
|
|
465
570
|
expect(repos()).toEqual(["acme/a"]);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* admin/src/installation-ports.ts
|
|
3
3
|
* Ports and Prisma/GitHub-backed adapters shared by the installation repos
|
|
4
|
-
* service (IRM-1.2) and
|
|
4
|
+
* service (IRM-1.2) and GitHub Sync (IRM-3.1): the agent record
|
|
5
5
|
* with its own GH_APP_ID, installation list/add/remove scoped to that App, and
|
|
6
6
|
* the audit table (GitHubReconcileAudit) every change is recorded in.
|
|
7
7
|
*/
|