@app-vitals/agent-admin 1.88.0 → 1.89.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.json +253 -0
- package/openapi.platform.json +297 -0
- package/package.json +2 -2
- package/src/admin-boot.ts +11 -0
- package/src/agents-api.smoke.test.ts +88 -0
- package/src/agents-api.ts +15 -0
- package/src/fixtures/github-enterprise-cassette.json +16 -0
- package/src/github-enterprise-api.integration.test.ts +127 -0
- package/src/github-enterprise-api.smoke.test.ts +188 -5
- package/src/github-enterprise-api.ts +212 -4
- package/src/github-enterprise-client.ts +23 -1
- package/src/github-enterprise-client.unit.test.ts +65 -0
- package/src/github-installation-wiring.ts +5 -0
- package/src/github-sync-switch.integration.test.ts +297 -0
- package/src/github-sync-switch.unit.test.ts +467 -0
- package/src/github-sync.ts +205 -24
- package/src/github-uninstall.ts +70 -0
- package/src/github-uninstall.unit.test.ts +78 -0
- package/src/installation-ports.ts +41 -0
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/src/github-sync-switch.unit.test.ts
|
|
3
|
+
* GIS-1.2: Sync switches "all" installations to "selected". Pure planning
|
|
4
|
+
* (planGithubSync / planSelectionSwitches) and the service apply order over
|
|
5
|
+
* in-memory ports and a cache port. The existing selected-org tests in
|
|
6
|
+
* github-sync.unit.test.ts stay as the regression guard.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, expect, it } from "bun:test";
|
|
10
|
+
import {
|
|
11
|
+
EMPTY_SWITCH_TARGET_REASON,
|
|
12
|
+
GithubSyncService,
|
|
13
|
+
MAX_SELECTION_PATCH_REPOS,
|
|
14
|
+
planGithubSync,
|
|
15
|
+
planSelectionSwitches,
|
|
16
|
+
STILL_PUSHABLE_REASON,
|
|
17
|
+
SWITCH_PERMISSION_MESSAGE,
|
|
18
|
+
} from "./github-sync.ts";
|
|
19
|
+
import type {
|
|
20
|
+
InstallationAuditEntry,
|
|
21
|
+
AppIdentity,
|
|
22
|
+
} from "./installation-ports.ts";
|
|
23
|
+
import type { InstallationReposPort } from "./installation-repos-service.ts";
|
|
24
|
+
import type { OpenWorkPort } from "./reconcile-open-work.ts";
|
|
25
|
+
import type { UserRepoAccessResult } from "./user-repo-access-resolver.ts";
|
|
26
|
+
|
|
27
|
+
type Sel = "all" | "selected" | null;
|
|
28
|
+
|
|
29
|
+
const accessFor = (
|
|
30
|
+
pushable: string[],
|
|
31
|
+
all: string[],
|
|
32
|
+
): UserRepoAccessResult => ({
|
|
33
|
+
username: "octo",
|
|
34
|
+
outcome: "ok",
|
|
35
|
+
userVerified: true,
|
|
36
|
+
orgs: [
|
|
37
|
+
{
|
|
38
|
+
org: "acme",
|
|
39
|
+
status: "ok",
|
|
40
|
+
unresolved: 0,
|
|
41
|
+
repos: all.map((fullName) => ({
|
|
42
|
+
fullName,
|
|
43
|
+
canPush: pushable.includes(fullName),
|
|
44
|
+
level: pushable.includes(fullName)
|
|
45
|
+
? ("write" as const)
|
|
46
|
+
: ("read" as const),
|
|
47
|
+
})),
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
unresolved: 0,
|
|
51
|
+
complete: true,
|
|
52
|
+
checkedAt: "2026-11-25T00:00:00.000Z",
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const INSTALLED = ["acme/a", "acme/b", "acme/c"];
|
|
56
|
+
const plan = (
|
|
57
|
+
selection: Sel | undefined,
|
|
58
|
+
over: {
|
|
59
|
+
pushable?: string[];
|
|
60
|
+
installed?: string[];
|
|
61
|
+
requested?: {
|
|
62
|
+
appAdds: string[];
|
|
63
|
+
appRemoves: string[];
|
|
64
|
+
agentRemoves: string[];
|
|
65
|
+
};
|
|
66
|
+
} = {},
|
|
67
|
+
) => {
|
|
68
|
+
const installed = over.installed ?? INSTALLED;
|
|
69
|
+
return planGithubSync({
|
|
70
|
+
username: "octo",
|
|
71
|
+
access: accessFor(over.pushable ?? ["acme/a"], installed),
|
|
72
|
+
agentRepos: [],
|
|
73
|
+
installationRepos: { acme: installed },
|
|
74
|
+
...(selection === undefined ? {} : { selections: { acme: selection } }),
|
|
75
|
+
...(over.requested ? { requested: over.requested } : {}),
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
describe("planGithubSync selection switches", () => {
|
|
80
|
+
it("an 'all' org switches to installed minus the removes; removes still count", () => {
|
|
81
|
+
const p = plan("all");
|
|
82
|
+
expect(p.selectionSwitches).toEqual([{ org: "acme", repos: ["acme/a"] }]);
|
|
83
|
+
expect(p.appRemoves).toEqual(["acme/b", "acme/c"]);
|
|
84
|
+
expect(p.removedRepos).toEqual(["acme/b", "acme/c"]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("a 'selected' org has no switch", () => {
|
|
88
|
+
const p = plan("selected");
|
|
89
|
+
expect(p.selectionSwitches).toEqual([]);
|
|
90
|
+
expect(p.appRemoves).toEqual(["acme/b", "acme/c"]);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("null or missing selection is never treated as 'all'", () => {
|
|
94
|
+
expect(plan(null).selectionSwitches).toEqual([]);
|
|
95
|
+
expect(plan(undefined).selectionSwitches).toEqual([]);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("matches the selection key case-insensitively", () => {
|
|
99
|
+
const p = planGithubSync({
|
|
100
|
+
username: "octo",
|
|
101
|
+
access: accessFor(["acme/a"], INSTALLED),
|
|
102
|
+
agentRepos: [],
|
|
103
|
+
installationRepos: { acme: INSTALLED },
|
|
104
|
+
selections: { ACME: "all" },
|
|
105
|
+
});
|
|
106
|
+
expect(p.selectionSwitches).toHaveLength(1);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("an empty target skips the org with a warning pointing to Uninstall and drops its removes", () => {
|
|
110
|
+
const p = plan("all", { pushable: [] });
|
|
111
|
+
expect(p.selectionSwitches).toEqual([]);
|
|
112
|
+
expect(p.skippedOrgs).toEqual([
|
|
113
|
+
{ org: "acme", reason: EMPTY_SWITCH_TARGET_REASON },
|
|
114
|
+
]);
|
|
115
|
+
expect(p.warnings.join()).toContain("Uninstall");
|
|
116
|
+
expect(p.appRemoves).toEqual([]);
|
|
117
|
+
expect(p.removedRepos).toEqual([]);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("an empty target with a requested list reports the dropped removes as not applied", () => {
|
|
121
|
+
const p = plan("all", {
|
|
122
|
+
pushable: [],
|
|
123
|
+
requested: { appAdds: [], appRemoves: INSTALLED, agentRemoves: [] },
|
|
124
|
+
});
|
|
125
|
+
expect(p.notApplied.map((n) => n.repo)).toEqual(INSTALLED);
|
|
126
|
+
expect(p.notApplied[0]?.reason).toBe(EMPTY_SWITCH_TARGET_REASON);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("lists more than 50 repos in full (the apply splits them)", () => {
|
|
130
|
+
const many = Array.from(
|
|
131
|
+
{ length: 60 },
|
|
132
|
+
(_, i) => `acme/r${String(i).padStart(2, "0")}`,
|
|
133
|
+
);
|
|
134
|
+
const p = plan("all", { installed: many, pushable: many });
|
|
135
|
+
expect(p.selectionSwitches?.[0]?.repos).toHaveLength(60);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("an org whose access was not usable is not switched", () => {
|
|
139
|
+
const p = planGithubSync({
|
|
140
|
+
username: "octo",
|
|
141
|
+
access: { ...accessFor([], []), orgs: [] },
|
|
142
|
+
agentRepos: [],
|
|
143
|
+
installationRepos: { acme: INSTALLED },
|
|
144
|
+
selections: { acme: "all" },
|
|
145
|
+
});
|
|
146
|
+
expect(p.selectionSwitches).toEqual([]);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("planSelectionSwitches ignores ineligible orgs", () => {
|
|
150
|
+
expect(
|
|
151
|
+
planSelectionSwitches({
|
|
152
|
+
installationRepos: { acme: ["acme/a"] },
|
|
153
|
+
selections: { acme: "all" },
|
|
154
|
+
appRemoves: [],
|
|
155
|
+
eligible: () => false,
|
|
156
|
+
}),
|
|
157
|
+
).toEqual({ switches: [], emptyOrgs: [] });
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// ─── service apply ───────────────────────────────────────────────────────────
|
|
162
|
+
|
|
163
|
+
const NOW = new Date("2026-11-25T12:00:00.000Z");
|
|
164
|
+
|
|
165
|
+
function harness(opts: {
|
|
166
|
+
selection?: Sel;
|
|
167
|
+
installed?: string[];
|
|
168
|
+
pushable?: string[];
|
|
169
|
+
/** verifyPush answer per repo; default: definitively false for non-pushable. */
|
|
170
|
+
verify?: (repo: string) => boolean | undefined;
|
|
171
|
+
switchError?: unknown;
|
|
172
|
+
addError?: boolean;
|
|
173
|
+
noSwitchPort?: boolean;
|
|
174
|
+
agentRepos?: string[];
|
|
175
|
+
}) {
|
|
176
|
+
const installed = opts.installed ?? INSTALLED;
|
|
177
|
+
const pushable = opts.pushable ?? ["acme/a"];
|
|
178
|
+
const calls: unknown[][] = [];
|
|
179
|
+
const audits: InstallationAuditEntry[] = [];
|
|
180
|
+
const port: InstallationReposPort = {
|
|
181
|
+
listRepos: async () => ({ acme: installed }),
|
|
182
|
+
listInstalled: async () => ({
|
|
183
|
+
status: "found",
|
|
184
|
+
orgs: [{ org: "acme", repos: installed }],
|
|
185
|
+
}),
|
|
186
|
+
addRepos: async (_a, org, repos) => {
|
|
187
|
+
calls.push(["addRepos", org, [...repos]]);
|
|
188
|
+
if (opts.addError) throw new Error("add failed");
|
|
189
|
+
},
|
|
190
|
+
removeRepos: async (_a, org, repos) => {
|
|
191
|
+
calls.push(["removeRepos", org, [...repos]]);
|
|
192
|
+
},
|
|
193
|
+
...(opts.noSwitchPort
|
|
194
|
+
? {}
|
|
195
|
+
: {
|
|
196
|
+
setRepositorySelection: async (
|
|
197
|
+
_a: number,
|
|
198
|
+
org: string,
|
|
199
|
+
repos: readonly string[],
|
|
200
|
+
_id?: AppIdentity,
|
|
201
|
+
) => {
|
|
202
|
+
calls.push(["switch", org, [...repos]]);
|
|
203
|
+
if (opts.switchError) throw opts.switchError;
|
|
204
|
+
},
|
|
205
|
+
}),
|
|
206
|
+
};
|
|
207
|
+
const openWork: OpenWorkPort = {
|
|
208
|
+
listOpenWork: async () => [{ id: "T-1", repo: "acme/b", title: "x" }],
|
|
209
|
+
blockOpenWork: async (...a) => {
|
|
210
|
+
calls.push(["block", ...a]);
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
const svc = new GithubSyncService({
|
|
214
|
+
agents: {
|
|
215
|
+
get: async () => ({
|
|
216
|
+
id: "ag",
|
|
217
|
+
githubUsername: "octo",
|
|
218
|
+
appId: 7,
|
|
219
|
+
repos:
|
|
220
|
+
opts.agentRepos ?? (installed.includes("acme/b") ? ["acme/b"] : []),
|
|
221
|
+
}),
|
|
222
|
+
setRepos: async (_id, repos) => {
|
|
223
|
+
calls.push(["setRepos", [...repos]]);
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
access: async () => {
|
|
227
|
+
throw new Error("live resolver must not be used");
|
|
228
|
+
},
|
|
229
|
+
cache: {
|
|
230
|
+
listAgentSnapshots: async () => [
|
|
231
|
+
{
|
|
232
|
+
org: "acme",
|
|
233
|
+
completedAt: new Date(NOW.getTime() - 1000),
|
|
234
|
+
totalCount: installed.length,
|
|
235
|
+
lastError: null,
|
|
236
|
+
rateLimitResetAt: null,
|
|
237
|
+
repositorySelection: opts.selection ?? null,
|
|
238
|
+
repos: installed.map((fullName) => ({ fullName })),
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
getAccessRows: async () =>
|
|
242
|
+
installed.map((f) => ({
|
|
243
|
+
repo: f.split("/")[1] as string,
|
|
244
|
+
status: "ok",
|
|
245
|
+
canPush: pushable.includes(f),
|
|
246
|
+
checkedAt: new Date(NOW.getTime() - 1000),
|
|
247
|
+
})),
|
|
248
|
+
},
|
|
249
|
+
lookupRepos: async () => [
|
|
250
|
+
{
|
|
251
|
+
org: "acme",
|
|
252
|
+
completedAt: new Date(NOW.getTime() - 1000),
|
|
253
|
+
repos: installed,
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
now: () => NOW,
|
|
257
|
+
verifyPush: async (_u, repo) =>
|
|
258
|
+
opts.verify ? opts.verify(repo) : pushable.includes(repo),
|
|
259
|
+
installation: port,
|
|
260
|
+
audit: {
|
|
261
|
+
write: async (e) => {
|
|
262
|
+
calls.push(["audit"]);
|
|
263
|
+
audits.push(e);
|
|
264
|
+
return `audit-${audits.length}`;
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
openWork,
|
|
268
|
+
});
|
|
269
|
+
return { svc, calls, audits };
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const apply = (
|
|
273
|
+
svc: GithubSyncService,
|
|
274
|
+
lists: {
|
|
275
|
+
appAdds?: string[];
|
|
276
|
+
appRemoves?: string[];
|
|
277
|
+
agentRemoves?: string[];
|
|
278
|
+
} = {},
|
|
279
|
+
confirmRemovals?: boolean,
|
|
280
|
+
) =>
|
|
281
|
+
svc.apply({
|
|
282
|
+
agentId: "ag",
|
|
283
|
+
caller: "root",
|
|
284
|
+
appAdds: [],
|
|
285
|
+
appRemoves: ["acme/b", "acme/c"],
|
|
286
|
+
agentRemoves: ["acme/b"],
|
|
287
|
+
...lists,
|
|
288
|
+
...(confirmRemovals === undefined ? {} : { confirmRemovals }),
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
describe("GithubSyncService selection switch", () => {
|
|
292
|
+
it("previews the switch for an 'all' org read from the cache", async () => {
|
|
293
|
+
const { svc, calls } = harness({ selection: "all" });
|
|
294
|
+
const r = await svc.preview("ag");
|
|
295
|
+
if (r.status !== "previewed") throw new Error(r.status);
|
|
296
|
+
expect(r.plan.selectionSwitches).toEqual([
|
|
297
|
+
{ org: "acme", repos: ["acme/a"] },
|
|
298
|
+
]);
|
|
299
|
+
expect(calls).toEqual([]);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it("applies switches, adds, removes, agent repos, audit, open work in that order, folding the removes", async () => {
|
|
303
|
+
const { svc, calls, audits } = harness({ selection: "all" });
|
|
304
|
+
const r = await apply(svc);
|
|
305
|
+
expect(r.status).toBe("applied");
|
|
306
|
+
expect(calls.map((c) => c[0])).toEqual([
|
|
307
|
+
"switch",
|
|
308
|
+
"setRepos",
|
|
309
|
+
"audit",
|
|
310
|
+
"block",
|
|
311
|
+
"block",
|
|
312
|
+
]);
|
|
313
|
+
expect(calls[0]).toEqual(["switch", "acme", ["acme/a"]]);
|
|
314
|
+
expect(audits[0]?.diff).toMatchObject({
|
|
315
|
+
installationAdds: [],
|
|
316
|
+
installationRemoves: ["acme/b", "acme/c"],
|
|
317
|
+
selectionSwitches: [{ org: "acme", repos: ["acme/a"] }],
|
|
318
|
+
});
|
|
319
|
+
expect(audits[0]?.result).toEqual({ status: "applied" });
|
|
320
|
+
// open work is blocked for the removed repos, including the folded ones
|
|
321
|
+
expect(JSON.stringify(calls.filter((c) => c[0] === "block"))).toContain(
|
|
322
|
+
"acme/b",
|
|
323
|
+
);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it("a 'selected' org still removes the usual way and records no switch", async () => {
|
|
327
|
+
const { svc, calls, audits } = harness({ selection: "selected" });
|
|
328
|
+
await apply(svc);
|
|
329
|
+
expect(calls.map((c) => c[0])).toEqual([
|
|
330
|
+
"removeRepos",
|
|
331
|
+
"setRepos",
|
|
332
|
+
"audit",
|
|
333
|
+
"block",
|
|
334
|
+
"block",
|
|
335
|
+
]);
|
|
336
|
+
expect(audits[0]?.diff.selectionSwitches).toBeUndefined();
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it("an unknown selection triggers no switch", async () => {
|
|
340
|
+
const { svc, calls } = harness({ selection: null });
|
|
341
|
+
await apply(svc);
|
|
342
|
+
expect(calls.some((c) => c[0] === "switch")).toBe(false);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it("switch removals still count toward the >10 cap", async () => {
|
|
346
|
+
const installed = Array.from({ length: 12 }, (_, i) => `acme/r${i}`);
|
|
347
|
+
const { svc, calls } = harness({
|
|
348
|
+
selection: "all",
|
|
349
|
+
installed: [...installed, "acme/keep"],
|
|
350
|
+
pushable: ["acme/keep"],
|
|
351
|
+
});
|
|
352
|
+
const r = await apply(svc, { appRemoves: installed, agentRemoves: [] });
|
|
353
|
+
expect(r.status).toBe("removal_cap");
|
|
354
|
+
expect(calls).toEqual([]);
|
|
355
|
+
const ok = await apply(
|
|
356
|
+
svc,
|
|
357
|
+
{ appRemoves: installed, agentRemoves: [] },
|
|
358
|
+
true,
|
|
359
|
+
);
|
|
360
|
+
expect(ok.status).toBe("applied");
|
|
361
|
+
expect(calls[0]).toEqual(["switch", "acme", ["acme/keep"]]);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it("a re-verified removal the user can still push to stays in the target", async () => {
|
|
365
|
+
const { svc, calls } = harness({
|
|
366
|
+
selection: "all",
|
|
367
|
+
verify: (repo) => repo === "acme/c",
|
|
368
|
+
});
|
|
369
|
+
const r = await apply(svc);
|
|
370
|
+
if (r.status !== "applied") throw new Error(r.status);
|
|
371
|
+
expect(r.plan.notApplied).toContainEqual({
|
|
372
|
+
repo: "acme/c",
|
|
373
|
+
reason: STILL_PUSHABLE_REASON,
|
|
374
|
+
});
|
|
375
|
+
expect(r.plan.removedRepos).toEqual(["acme/b"]);
|
|
376
|
+
expect(calls[0]).toEqual(["switch", "acme", ["acme/a", "acme/c"]]);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it("a switch-only change is not a noop", async () => {
|
|
380
|
+
const { svc } = harness({ selection: "all", pushable: INSTALLED });
|
|
381
|
+
const r = await apply(svc, { appRemoves: [], agentRemoves: [] });
|
|
382
|
+
expect(r.status).toBe("applied");
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it("an empty target is skipped, left on 'all', with a warning", async () => {
|
|
386
|
+
const { svc, calls } = harness({ selection: "all", pushable: [] });
|
|
387
|
+
const r = await apply(svc, {
|
|
388
|
+
appRemoves: INSTALLED,
|
|
389
|
+
agentRemoves: [],
|
|
390
|
+
});
|
|
391
|
+
expect(r.status).toBe("noop");
|
|
392
|
+
expect(calls).toEqual([]);
|
|
393
|
+
if (r.status !== "noop") return;
|
|
394
|
+
expect(r.plan.skippedOrgs[0]?.reason).toBe(EMPTY_SWITCH_TARGET_REASON);
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it("sends the first 50 in the PATCH and the rest through the batched add", async () => {
|
|
398
|
+
const many = Array.from(
|
|
399
|
+
{ length: 120 },
|
|
400
|
+
(_, i) => `acme/r${String(i).padStart(3, "0")}`,
|
|
401
|
+
);
|
|
402
|
+
const { svc, calls, audits } = harness({
|
|
403
|
+
selection: "all",
|
|
404
|
+
installed: many,
|
|
405
|
+
pushable: many,
|
|
406
|
+
agentRepos: [],
|
|
407
|
+
});
|
|
408
|
+
const r = await apply(svc, { appRemoves: [], agentRemoves: [] });
|
|
409
|
+
expect(r.status).toBe("applied");
|
|
410
|
+
const sw = calls[0] as [string, string, string[]];
|
|
411
|
+
expect(sw[2]).toHaveLength(MAX_SELECTION_PATCH_REPOS);
|
|
412
|
+
expect(calls[1]).toEqual(["addRepos", "acme", many.slice(50)]);
|
|
413
|
+
expect(audits[0]?.diff.selectionSwitches?.[0]?.repos).toEqual(
|
|
414
|
+
[...many].sort(),
|
|
415
|
+
);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it("a failed add after the PATCH records only the repos that landed", async () => {
|
|
419
|
+
const many = Array.from(
|
|
420
|
+
{ length: 60 },
|
|
421
|
+
(_, i) => `acme/r${String(i).padStart(2, "0")}`,
|
|
422
|
+
);
|
|
423
|
+
const { svc, audits } = harness({
|
|
424
|
+
selection: "all",
|
|
425
|
+
installed: many,
|
|
426
|
+
pushable: many,
|
|
427
|
+
agentRepos: [],
|
|
428
|
+
addError: true,
|
|
429
|
+
});
|
|
430
|
+
const r = await apply(svc, { appRemoves: [], agentRemoves: [] });
|
|
431
|
+
expect(r.status).toBe("failed");
|
|
432
|
+
expect(audits[0]?.result.status).toBe("failed");
|
|
433
|
+
expect(audits[0]?.diff.selectionSwitches?.[0]?.repos).toHaveLength(50);
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it("maps a 403 on the switch to the missing-permission message and a failed audit with nothing landed", async () => {
|
|
437
|
+
const err = Object.assign(new Error("Resource not accessible"), {
|
|
438
|
+
kind: "permission",
|
|
439
|
+
status: 403,
|
|
440
|
+
});
|
|
441
|
+
const { svc, calls, audits } = harness({
|
|
442
|
+
selection: "all",
|
|
443
|
+
switchError: err,
|
|
444
|
+
});
|
|
445
|
+
const r = await apply(svc);
|
|
446
|
+
if (r.status !== "failed") throw new Error(r.status);
|
|
447
|
+
expect(r.error).toBe(SWITCH_PERMISSION_MESSAGE("acme"));
|
|
448
|
+
expect(r.error).toContain(
|
|
449
|
+
"enterprise_organization_installation_repositories",
|
|
450
|
+
);
|
|
451
|
+
expect(audits[0]?.result).toEqual({ status: "failed", error: r.error });
|
|
452
|
+
expect(audits[0]?.diff).toEqual({
|
|
453
|
+
installationAdds: [],
|
|
454
|
+
installationRemoves: [],
|
|
455
|
+
configAdds: [],
|
|
456
|
+
configRemoves: [],
|
|
457
|
+
});
|
|
458
|
+
expect(calls.map((c) => c[0])).toEqual(["switch", "audit"]);
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it("fails clearly when the port cannot switch", async () => {
|
|
462
|
+
const { svc } = harness({ selection: "all", noSwitchPort: true });
|
|
463
|
+
const r = await apply(svc);
|
|
464
|
+
if (r.status !== "failed") throw new Error(r.status);
|
|
465
|
+
expect(r.error).toContain("cannot switch acme");
|
|
466
|
+
});
|
|
467
|
+
});
|