@app-vitals/agent-admin 1.34.0 → 1.35.1
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 +2 -392
- package/package.json +2 -2
- package/src/admin-boot.ts +1 -12
- package/src/admin-extension.ts +3 -3
- package/src/admin-ui-github-identity.smoke.test.ts +0 -114
- package/src/admin-ui-installation-repos-pages.ts +404 -0
- package/src/admin-ui-installation-repos-pages.unit.test.ts +57 -0
- package/src/admin-ui-installation-repos.smoke.test.ts +496 -0
- package/src/admin-ui-pages.ts +57 -9
- package/src/admin-ui.ts +236 -50
- package/src/agents-api.smoke.test.ts +2 -352
- package/src/agents-api.ts +5 -269
- package/src/github-enterprise-isolation.unit.test.ts +4 -4
- package/src/{github-reconcile-wiring.ts → github-installation-wiring.ts} +18 -38
- package/src/github-installation-wiring.unit.test.ts +111 -0
- package/src/github-installation.fixtures.ts +76 -0
- 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 +12 -12
- package/src/installation-repos-service.unit.test.ts +3 -3
- package/src/lost-access-removal.ts +9 -9
- package/src/lost-access-removal.unit.test.ts +7 -7
- 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 -222
- package/src/github-reconcile-routes.integration.test.ts +0 -206
- package/src/github-reconcile-wiring.unit.test.ts +0 -170
- 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
package/src/reconcile-planner.ts
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* admin/src/reconcile-planner.ts
|
|
3
|
-
* ReconcilePlanner: pure planning half of the repo reconcile (GHE-3.2). Turns
|
|
4
|
-
* a UserRepoAccessResolver result, the agent's repos and the agent App's
|
|
5
|
-
* installation repositories into a diff plus a stable plan hash. No I/O.
|
|
6
|
-
*
|
|
7
|
-
* Rules:
|
|
8
|
-
* - Desired agent repos = current repos kept only where the bound user can
|
|
9
|
-
* push. Newly accessible repos are never added; adds happen only when the
|
|
10
|
-
* admin names them, and only if push-capable and not basename-colliding.
|
|
11
|
-
* - Removals never come from incomplete knowledge: an org whose resolver
|
|
12
|
-
* result is missing, partial, failed, or whose lookup installation is
|
|
13
|
-
* selected-only is skipped (with a reason); so is everything when the
|
|
14
|
-
* user is unbound, not found or unverified.
|
|
15
|
-
* - Agent repos stay a subset of installation repos. A removed repo leaves
|
|
16
|
-
* the installation too; an add is installed first when absent.
|
|
17
|
-
* - Planning over an already-reconciled state is an empty diff with the same
|
|
18
|
-
* hash.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import { createHash } from "node:crypto";
|
|
22
|
-
import {
|
|
23
|
-
type OrgAccessResult,
|
|
24
|
-
SELECTED_REPOS_REASON,
|
|
25
|
-
type UserRepoAccessResult,
|
|
26
|
-
} from "./user-repo-access-resolver.ts";
|
|
27
|
-
|
|
28
|
-
export interface ReconcilePlanInput {
|
|
29
|
-
/** Bound GitHub username; null/empty yields a skipped plan. */
|
|
30
|
-
username: string | null | undefined;
|
|
31
|
-
/** Null when the resolver was not run (no bound user). */
|
|
32
|
-
access: UserRepoAccessResult | null;
|
|
33
|
-
/** The agent's configured repos, owner/repo. */
|
|
34
|
-
agentRepos: readonly string[];
|
|
35
|
-
/** Repos the agent App's installation covers, per org login. */
|
|
36
|
-
installationRepos: Readonly<Record<string, readonly string[]>>;
|
|
37
|
-
/** Repos the admin explicitly asks to add, owner/repo. */
|
|
38
|
-
namedAdds?: readonly string[];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export interface OrgSkip {
|
|
42
|
-
org: string;
|
|
43
|
-
reason: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export interface RejectedAdd {
|
|
47
|
-
repo: string;
|
|
48
|
-
reason: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface ReconcileDiff {
|
|
52
|
-
installationAdds: string[];
|
|
53
|
-
installationRemoves: string[];
|
|
54
|
-
configAdds: string[];
|
|
55
|
-
configRemoves: string[];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface ReconcilePlan {
|
|
59
|
-
skipped: boolean;
|
|
60
|
-
/** Set when the whole plan is skipped. */
|
|
61
|
-
skipReason?: string;
|
|
62
|
-
diff: ReconcileDiff;
|
|
63
|
-
skippedOrgs: OrgSkip[];
|
|
64
|
-
rejectedAdds: RejectedAdd[];
|
|
65
|
-
warnings: string[];
|
|
66
|
-
empty: boolean;
|
|
67
|
-
planHash: string;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const EMPTY_DIFF = (): ReconcileDiff => ({
|
|
71
|
-
installationAdds: [],
|
|
72
|
-
installationRemoves: [],
|
|
73
|
-
configAdds: [],
|
|
74
|
-
configRemoves: [],
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
export function repoOrg(fullName: string): string {
|
|
78
|
-
return fullName.split("/")[0] ?? "";
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function repoBasename(fullName: string): string {
|
|
82
|
-
return (fullName.split("/")[1] ?? fullName).toLowerCase();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const sorted = (xs: Iterable<string>): string[] => [...xs].sort();
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Why removals in one org must be skipped (unknown is never none): the org
|
|
89
|
-
* was not checked, its listing is partial or failed, or the lookup App is
|
|
90
|
-
* installed on selected repositories only. Undefined when the listing is
|
|
91
|
-
* complete. Shared with the lost-access removal (IRM-1.3).
|
|
92
|
-
*/
|
|
93
|
-
export function orgSkipReason(
|
|
94
|
-
result: OrgAccessResult | undefined,
|
|
95
|
-
): string | undefined {
|
|
96
|
-
if (!result) return "org was not checked";
|
|
97
|
-
if (result.reason === SELECTED_REPOS_REASON) {
|
|
98
|
-
return "lookup app is installed on selected repositories only";
|
|
99
|
-
}
|
|
100
|
-
if (result.status === "partial") return "access listing is incomplete";
|
|
101
|
-
if (result.status !== "ok") return `access lookup failed: ${result.status}`;
|
|
102
|
-
return undefined;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function hashPlan(
|
|
106
|
-
username: string,
|
|
107
|
-
diff: ReconcileDiff,
|
|
108
|
-
skippedOrgs: OrgSkip[],
|
|
109
|
-
rejectedAdds: RejectedAdd[],
|
|
110
|
-
skipReason: string | undefined,
|
|
111
|
-
): string {
|
|
112
|
-
const canonical = JSON.stringify({
|
|
113
|
-
username: username.toLowerCase(),
|
|
114
|
-
diff,
|
|
115
|
-
skippedOrgs,
|
|
116
|
-
rejectedAdds,
|
|
117
|
-
skipReason: skipReason ?? null,
|
|
118
|
-
});
|
|
119
|
-
return createHash("sha256").update(canonical).digest("hex");
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function finish(
|
|
123
|
-
username: string,
|
|
124
|
-
plan: Omit<ReconcilePlan, "empty" | "planHash">,
|
|
125
|
-
): ReconcilePlan {
|
|
126
|
-
const d = plan.diff;
|
|
127
|
-
const empty =
|
|
128
|
-
d.installationAdds.length +
|
|
129
|
-
d.installationRemoves.length +
|
|
130
|
-
d.configAdds.length +
|
|
131
|
-
d.configRemoves.length ===
|
|
132
|
-
0;
|
|
133
|
-
return {
|
|
134
|
-
...plan,
|
|
135
|
-
empty,
|
|
136
|
-
planHash: hashPlan(
|
|
137
|
-
username,
|
|
138
|
-
d,
|
|
139
|
-
plan.skippedOrgs,
|
|
140
|
-
plan.rejectedAdds,
|
|
141
|
-
plan.skipReason,
|
|
142
|
-
),
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function skippedPlan(username: string, reason: string): ReconcilePlan {
|
|
147
|
-
return finish(username, {
|
|
148
|
-
skipped: true,
|
|
149
|
-
skipReason: reason,
|
|
150
|
-
diff: EMPTY_DIFF(),
|
|
151
|
-
skippedOrgs: [],
|
|
152
|
-
rejectedAdds: [],
|
|
153
|
-
warnings: [],
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Why a whole plan must be skipped: no bound user, access not resolved, user
|
|
159
|
-
* not found or not verified. Undefined when the access result is usable.
|
|
160
|
-
* Shared with the lost-access removal (IRM-1.3).
|
|
161
|
-
*/
|
|
162
|
-
export function accessSkipReason(
|
|
163
|
-
username: string | null | undefined,
|
|
164
|
-
access: UserRepoAccessResult | null,
|
|
165
|
-
): string | undefined {
|
|
166
|
-
if (!username?.trim()) return "no GitHub username bound to the agent";
|
|
167
|
-
if (!access) return "access was not resolved";
|
|
168
|
-
if (access.outcome === "user_not_found") return "GitHub user not found";
|
|
169
|
-
if (!access.userVerified) return "GitHub user could not be verified";
|
|
170
|
-
return undefined;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export function planReconcile(input: ReconcilePlanInput): ReconcilePlan {
|
|
174
|
-
const username = input.username?.trim() ?? "";
|
|
175
|
-
const skipReason = accessSkipReason(username, input.access);
|
|
176
|
-
if (skipReason) return skippedPlan(username, skipReason);
|
|
177
|
-
const access = input.access as UserRepoAccessResult;
|
|
178
|
-
|
|
179
|
-
const orgResults = new Map(access.orgs.map((o) => [o.org, o]));
|
|
180
|
-
const pushable = new Set<string>();
|
|
181
|
-
for (const o of access.orgs) {
|
|
182
|
-
for (const r of o.repos) if (r.canPush) pushable.add(r.fullName);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const installation = new Set<string>();
|
|
186
|
-
for (const repos of Object.values(input.installationRepos)) {
|
|
187
|
-
for (const r of repos) installation.add(r);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const warnings: string[] = [];
|
|
191
|
-
const skipReasons = new Map<string, string>();
|
|
192
|
-
const checkOrg = (org: string): string | undefined => {
|
|
193
|
-
if (!skipReasons.has(org)) {
|
|
194
|
-
const reason = orgSkipReason(orgResults.get(org));
|
|
195
|
-
if (reason) skipReasons.set(org, reason);
|
|
196
|
-
}
|
|
197
|
-
return skipReasons.get(org);
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
const agentRepos = new Set(input.agentRepos);
|
|
201
|
-
const configRemoves = new Set<string>();
|
|
202
|
-
for (const repo of sorted(agentRepos)) {
|
|
203
|
-
const org = repoOrg(repo);
|
|
204
|
-
if (checkOrg(org)) continue; // Unknown is never none.
|
|
205
|
-
if (!pushable.has(repo)) {
|
|
206
|
-
configRemoves.add(repo);
|
|
207
|
-
} else if (!installation.has(repo)) {
|
|
208
|
-
// Keeps agent repos a subset of installation repos.
|
|
209
|
-
configRemoves.add(repo);
|
|
210
|
-
warnings.push(`${repo} is not in the agent installation; dropping it`);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
const kept = new Set([...agentRepos].filter((r) => !configRemoves.has(r)));
|
|
214
|
-
|
|
215
|
-
const configAdds = new Set<string>();
|
|
216
|
-
const installationAdds = new Set<string>();
|
|
217
|
-
const rejectedAdds: RejectedAdd[] = [];
|
|
218
|
-
const reject = (repo: string, reason: string) =>
|
|
219
|
-
rejectedAdds.push({ repo, reason });
|
|
220
|
-
const basenames = new Map<string, string>();
|
|
221
|
-
for (const r of sorted(kept)) basenames.set(repoBasename(r), r);
|
|
222
|
-
|
|
223
|
-
for (const repo of sorted(new Set(input.namedAdds ?? []))) {
|
|
224
|
-
if (kept.has(repo)) continue; // Already present: nothing to add.
|
|
225
|
-
if (!pushable.has(repo)) {
|
|
226
|
-
reject(repo, "user cannot push to this repo");
|
|
227
|
-
continue;
|
|
228
|
-
}
|
|
229
|
-
const clash = basenames.get(repoBasename(repo));
|
|
230
|
-
if (clash) {
|
|
231
|
-
reject(repo, `basename collides with ${clash}`);
|
|
232
|
-
continue;
|
|
233
|
-
}
|
|
234
|
-
basenames.set(repoBasename(repo), repo);
|
|
235
|
-
configAdds.add(repo);
|
|
236
|
-
if (!installation.has(repo)) installationAdds.add(repo);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
// Installation removals follow config removals, only for installed repos.
|
|
240
|
-
const installationRemoves = [...configRemoves].filter((r) =>
|
|
241
|
-
installation.has(r),
|
|
242
|
-
);
|
|
243
|
-
|
|
244
|
-
const skippedOrgs = sorted(skipReasons.keys()).map((org) => ({
|
|
245
|
-
org,
|
|
246
|
-
reason: skipReasons.get(org) as string,
|
|
247
|
-
}));
|
|
248
|
-
for (const s of skippedOrgs) {
|
|
249
|
-
warnings.push(`${s.org}: removals skipped (${s.reason})`);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return finish(username, {
|
|
253
|
-
skipped: false,
|
|
254
|
-
diff: {
|
|
255
|
-
installationAdds: sorted(installationAdds),
|
|
256
|
-
installationRemoves: sorted(installationRemoves),
|
|
257
|
-
configAdds: sorted(configAdds),
|
|
258
|
-
configRemoves: sorted(configRemoves),
|
|
259
|
-
},
|
|
260
|
-
skippedOrgs,
|
|
261
|
-
rejectedAdds,
|
|
262
|
-
warnings,
|
|
263
|
-
});
|
|
264
|
-
}
|
|
@@ -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
|
-
});
|