@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.
- package/openapi.platform.json +136 -766
- package/package.json +2 -2
- package/src/admin-boot.ts +4 -15
- package/src/admin-extension.ts +3 -3
- package/src/admin-ui-github-identity.smoke.test.ts +24 -116
- 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 -173
- package/src/admin-ui-pages.ts +2 -2
- package/src/admin-ui.ts +103 -171
- package/src/agents-api.smoke.test.ts +195 -642
- package/src/agents-api.ts +86 -477
- package/src/github-enterprise-isolation.unit.test.ts +4 -4
- package/src/{github-reconcile-wiring.ts → github-installation-wiring.ts} +24 -46
- package/src/github-installation-wiring.unit.test.ts +115 -0
- package/src/github-installation.fixtures.ts +76 -0
- package/src/github-sync.ts +407 -0
- package/src/{lost-access-removal.unit.test.ts → github-sync.unit.test.ts} +220 -115
- 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 +10 -105
- package/src/installation-repos-service.unit.test.ts +5 -90
- 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 -226
- package/src/github-reconcile-routes.integration.test.ts +0 -206
- package/src/github-reconcile-wiring.unit.test.ts +0 -170
- package/src/lost-access-removal.ts +0 -333
- 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
|
@@ -6,9 +6,16 @@
|
|
|
6
6
|
import { describe, expect, it } from "bun:test";
|
|
7
7
|
import {
|
|
8
8
|
actuallyBlockedWork,
|
|
9
|
+
APP_ID_MISMATCH_MESSAGE,
|
|
10
|
+
NO_USERNAME_REASON,
|
|
11
|
+
renderGithubSyncCard,
|
|
12
|
+
renderInstallationReposBody,
|
|
9
13
|
renderOpenWorkByRepo,
|
|
14
|
+
renderSyncConfirm,
|
|
15
|
+
renderSyncResult,
|
|
10
16
|
uncoveredRepos,
|
|
11
17
|
} from "./admin-ui-installation-repos-pages.ts";
|
|
18
|
+
import { MISSING_APP_ID_REASON } from "./installation-ports.ts";
|
|
12
19
|
|
|
13
20
|
describe("uncoveredRepos", () => {
|
|
14
21
|
it("returns agent repos missing from the installation, case-insensitively", () => {
|
|
@@ -55,3 +62,195 @@ describe("renderOpenWorkByRepo", () => {
|
|
|
55
62
|
expect(html).not.toContain("<script>");
|
|
56
63
|
});
|
|
57
64
|
});
|
|
65
|
+
|
|
66
|
+
describe("renderGithubSyncCard", () => {
|
|
67
|
+
const ok = { hasAppId: true, githubUsername: "octo" };
|
|
68
|
+
|
|
69
|
+
it("has one Sync button and no text input", () => {
|
|
70
|
+
const html = renderGithubSyncCard("a1", ok);
|
|
71
|
+
expect(html).toContain('id="github-installation-card"');
|
|
72
|
+
expect(html).toContain('id="github-sync-btn"');
|
|
73
|
+
expect(html).toContain('data-url="/admin/agents/a1/github-sync/confirm"');
|
|
74
|
+
expect(html).not.toContain("<input");
|
|
75
|
+
expect(html).not.toContain("<form");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("shows the missing-App-id reason instead of the button", () => {
|
|
79
|
+
const html = renderGithubSyncCard("a1", {
|
|
80
|
+
hasAppId: false,
|
|
81
|
+
githubUsername: "octo",
|
|
82
|
+
});
|
|
83
|
+
expect(html).toContain('data-reason="missing-app-id"');
|
|
84
|
+
expect(html).toContain(MISSING_APP_ID_REASON);
|
|
85
|
+
expect(html).not.toContain('id="github-sync-btn"');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("shows the no-username reason instead of the button", () => {
|
|
89
|
+
for (const githubUsername of [null, undefined, " "]) {
|
|
90
|
+
const html = renderGithubSyncCard("a1", {
|
|
91
|
+
hasAppId: true,
|
|
92
|
+
githubUsername,
|
|
93
|
+
});
|
|
94
|
+
expect(html).toContain('data-reason="no-username"');
|
|
95
|
+
expect(html).toContain(NO_USERNAME_REASON);
|
|
96
|
+
expect(html).not.toContain('id="github-sync-btn"');
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("missing App id wins over a missing username", () => {
|
|
101
|
+
const html = renderGithubSyncCard("a1", { hasAppId: false });
|
|
102
|
+
expect(html).toContain('data-reason="missing-app-id"');
|
|
103
|
+
expect(html).not.toContain('data-reason="no-username"');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe("renderInstallationReposBody", () => {
|
|
108
|
+
const view = {
|
|
109
|
+
orgs: [
|
|
110
|
+
{
|
|
111
|
+
org: "acme",
|
|
112
|
+
repos: [{ fullName: "acme/<x>", userCanPush: true }],
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
it("lists app repos without any per-repo action", () => {
|
|
118
|
+
const html = renderInstallationReposBody(view);
|
|
119
|
+
expect(html).toContain("acme/<x>");
|
|
120
|
+
expect(html).not.toContain("<button");
|
|
121
|
+
expect(html).not.toContain("data-action=");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("says not installed when the org list is empty", () => {
|
|
125
|
+
const html = renderInstallationReposBody({ orgs: [] });
|
|
126
|
+
expect(html).toContain("not installed on any organization");
|
|
127
|
+
expect(html).not.toContain('data-reason="app-id-mismatch"');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("shows a distinct GH_APP_ID mismatch message", () => {
|
|
131
|
+
const html = renderInstallationReposBody(
|
|
132
|
+
{ orgs: [] },
|
|
133
|
+
{ appIdMismatch: true },
|
|
134
|
+
);
|
|
135
|
+
expect(html).toContain('data-reason="app-id-mismatch"');
|
|
136
|
+
expect(html).toContain(APP_ID_MISMATCH_MESSAGE);
|
|
137
|
+
expect(html).not.toContain("not installed on any organization");
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe("renderSyncConfirm", () => {
|
|
142
|
+
const preview = {
|
|
143
|
+
status: "previewed" as const,
|
|
144
|
+
appAdds: ["acme/new"],
|
|
145
|
+
appRemoves: ["acme/old"],
|
|
146
|
+
agentRemoves: ["acme/gone"],
|
|
147
|
+
skippedOrgs: [{ org: "zed", reason: "access listing is incomplete" }],
|
|
148
|
+
openWork: [{ id: "acme/old#4", repo: "acme/old", title: "Fix <b>" }],
|
|
149
|
+
warnings: ["w1"],
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
it("lists adds, removes, agent removes, blocked work and one confirm", () => {
|
|
153
|
+
const html = renderSyncConfirm("a1", preview);
|
|
154
|
+
expect(html).toContain('data-list="app-adds"');
|
|
155
|
+
expect(html).toContain("acme/new");
|
|
156
|
+
expect(html).toContain('data-list="app-removes"');
|
|
157
|
+
expect(html).toContain("acme/old");
|
|
158
|
+
expect(html).toContain('data-list="agent-removes"');
|
|
159
|
+
expect(html).toContain("acme/gone");
|
|
160
|
+
expect(html).toContain('href="https://github.com/acme/old/pull/4"');
|
|
161
|
+
expect(html).toContain("Fix <b>");
|
|
162
|
+
expect(html).toContain("zed");
|
|
163
|
+
expect(html).toContain("w1");
|
|
164
|
+
expect(html.match(/id="github-sync-confirm-btn"/g)?.length).toBe(1);
|
|
165
|
+
expect(html).toContain(
|
|
166
|
+
'data-url="/admin/agents/a1/github-sync/apply-confirmed"',
|
|
167
|
+
);
|
|
168
|
+
expect(html).not.toContain("github-sync-confirm-removals");
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("carries the exact confirmed lists, escaped", () => {
|
|
172
|
+
const html = renderSyncConfirm("a1", preview);
|
|
173
|
+
const m = /data-body="([^"]*)"/.exec(html);
|
|
174
|
+
const body = JSON.parse(
|
|
175
|
+
(m?.[1] ?? "").replaceAll(""", '"').replaceAll("&", "&"),
|
|
176
|
+
);
|
|
177
|
+
expect(body).toEqual({
|
|
178
|
+
appAdds: ["acme/new"],
|
|
179
|
+
appRemoves: ["acme/old"],
|
|
180
|
+
agentRemoves: ["acme/gone"],
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("requires the over-cap checkbox for more than 10 removals", () => {
|
|
185
|
+
const many = Array.from({ length: 11 }, (_, i) => `acme/r${i}`);
|
|
186
|
+
const html = renderSyncConfirm("a1", {
|
|
187
|
+
...preview,
|
|
188
|
+
appRemoves: many,
|
|
189
|
+
agentRemoves: [],
|
|
190
|
+
});
|
|
191
|
+
expect(html).toContain('id="github-sync-confirm-removals"');
|
|
192
|
+
expect(html).toContain("disabled");
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("counts a repo removed from both places once", () => {
|
|
196
|
+
const ten = Array.from({ length: 10 }, (_, i) => `acme/r${i}`);
|
|
197
|
+
const html = renderSyncConfirm("a1", {
|
|
198
|
+
...preview,
|
|
199
|
+
appRemoves: ten,
|
|
200
|
+
agentRemoves: ten,
|
|
201
|
+
});
|
|
202
|
+
expect(html).not.toContain("github-sync-confirm-removals");
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("says in sync when nothing would change, with no confirm", () => {
|
|
206
|
+
const html = renderSyncConfirm("a1", {
|
|
207
|
+
status: "previewed",
|
|
208
|
+
appAdds: [],
|
|
209
|
+
appRemoves: [],
|
|
210
|
+
agentRemoves: [],
|
|
211
|
+
});
|
|
212
|
+
expect(html).toContain('data-sync="in-sync"');
|
|
213
|
+
expect(html).not.toContain("github-sync-confirm-btn");
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("shows the reason for a skipped preview", () => {
|
|
217
|
+
const html = renderSyncConfirm("a1", {
|
|
218
|
+
status: "skipped",
|
|
219
|
+
reason: "GitHub user not found",
|
|
220
|
+
});
|
|
221
|
+
expect(html).toContain('data-sync="skipped"');
|
|
222
|
+
expect(html).toContain("GitHub user not found");
|
|
223
|
+
expect(html).not.toContain("github-sync-confirm-btn");
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe("renderSyncResult", () => {
|
|
228
|
+
it("reports what changed, what was left alone and blocked work", () => {
|
|
229
|
+
const html = renderSyncResult(
|
|
230
|
+
{
|
|
231
|
+
status: "applied",
|
|
232
|
+
appAdds: ["acme/new"],
|
|
233
|
+
appRemoves: [],
|
|
234
|
+
agentRemoves: ["acme/gone"],
|
|
235
|
+
notApplied: [{ repo: "acme/x", reason: "still pushable" }],
|
|
236
|
+
warnings: ["careful"],
|
|
237
|
+
},
|
|
238
|
+
[{ id: "acme/gone#1", repo: "acme/gone" }],
|
|
239
|
+
);
|
|
240
|
+
expect(html).toContain("acme/new");
|
|
241
|
+
expect(html).toContain("acme/gone");
|
|
242
|
+
expect(html).toContain("acme/x");
|
|
243
|
+
expect(html).toContain("still pushable");
|
|
244
|
+
expect(html).toContain("careful");
|
|
245
|
+
expect(html).toContain("were blocked");
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("covers noop and skipped", () => {
|
|
249
|
+
expect(renderSyncResult({ status: "noop" }, [])).toContain(
|
|
250
|
+
"Nothing was changed",
|
|
251
|
+
);
|
|
252
|
+
expect(
|
|
253
|
+
renderSyncResult({ status: "skipped", reason: "no user" }, []),
|
|
254
|
+
).toContain("no user");
|
|
255
|
+
});
|
|
256
|
+
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* admin/src/admin-ui-installation-repos.smoke.test.ts
|
|
3
|
-
* Smoke tests (app.request()) for the IRM-
|
|
4
|
-
*
|
|
5
|
-
* installation-coverage flag. The agents API is a stubbed seam; no DB, no network.
|
|
3
|
+
* Smoke tests (app.request()) for the IRM-3.2 GitHub Sync card (gating, repos
|
|
4
|
+
* body, the single sync confirm and apply), the repo-removal confirm flow
|
|
5
|
+
* (IRM-1.7) and the installation-coverage flag. The agents API is a stubbed seam; no DB, no network.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { beforeAll, describe, expect, it } from "bun:test";
|
|
@@ -27,6 +27,8 @@ function setup(opts: {
|
|
|
27
27
|
username?: string | null;
|
|
28
28
|
repos?: string[];
|
|
29
29
|
agentsApi?: Api;
|
|
30
|
+
/** Enterprise Apps status; default: both installer and lookup configured. */
|
|
31
|
+
enterprise?: unknown;
|
|
30
32
|
}) {
|
|
31
33
|
const calls: { path: string; init?: RequestInit }[] = [];
|
|
32
34
|
const base = makeMockDeps();
|
|
@@ -56,7 +58,14 @@ function setup(opts: {
|
|
|
56
58
|
secretKeys: [],
|
|
57
59
|
}),
|
|
58
60
|
},
|
|
59
|
-
githubEnterpriseApi: () =>
|
|
61
|
+
githubEnterpriseApi: () =>
|
|
62
|
+
json(
|
|
63
|
+
opts.enterprise ?? {
|
|
64
|
+
configured: true,
|
|
65
|
+
installer: { role: "installer" },
|
|
66
|
+
lookup: { role: "lookup" },
|
|
67
|
+
},
|
|
68
|
+
),
|
|
60
69
|
agentsApi: (path: string, init?: RequestInit) => {
|
|
61
70
|
calls.push({ path, init });
|
|
62
71
|
return opts.agentsApi ? opts.agentsApi(path, init) : json({});
|
|
@@ -79,7 +88,7 @@ const INSTALLED = {
|
|
|
79
88
|
],
|
|
80
89
|
};
|
|
81
90
|
|
|
82
|
-
describe("admin UI —
|
|
91
|
+
describe("admin UI — GitHub sync card (IRM-3.2)", () => {
|
|
83
92
|
let admin: string;
|
|
84
93
|
let member: string;
|
|
85
94
|
beforeAll(async () => {
|
|
@@ -107,19 +116,71 @@ describe("admin UI — installation repos card (IRM-1.4)", () => {
|
|
|
107
116
|
});
|
|
108
117
|
|
|
109
118
|
describe("card presence", () => {
|
|
110
|
-
it("
|
|
119
|
+
it("shows the Sync button and no input when both Apps are configured", async () => {
|
|
111
120
|
const { app } = setup({ agentsApi: () => json(INSTALLED) });
|
|
112
121
|
const html = await (await get(app, "")).text();
|
|
113
122
|
expect(html).toContain('id="github-installation-card"');
|
|
114
|
-
expect(html).
|
|
123
|
+
expect(html).toContain('id="github-sync-btn"');
|
|
124
|
+
const card = html.slice(html.indexOf('id="github-installation-card"'));
|
|
125
|
+
const cardHtml = card.slice(0, card.indexOf("</script>"));
|
|
126
|
+
expect(cardHtml).not.toContain("<input");
|
|
115
127
|
});
|
|
116
128
|
|
|
117
|
-
it("is absent
|
|
118
|
-
const { app } = setup({
|
|
129
|
+
it("is absent when only the installer App is configured", async () => {
|
|
130
|
+
const { app } = setup({
|
|
131
|
+
enterprise: {
|
|
132
|
+
configured: true,
|
|
133
|
+
installer: { role: "installer" },
|
|
134
|
+
lookup: null,
|
|
135
|
+
},
|
|
136
|
+
});
|
|
119
137
|
const html = await (await get(app, "")).text();
|
|
120
138
|
expect(html).not.toContain("github-installation-card");
|
|
121
139
|
});
|
|
122
140
|
|
|
141
|
+
it("is absent when only the lookup App is configured", async () => {
|
|
142
|
+
const { app } = setup({
|
|
143
|
+
enterprise: {
|
|
144
|
+
configured: true,
|
|
145
|
+
installer: null,
|
|
146
|
+
lookup: { role: "lookup" },
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
const html = await (await get(app, "")).text();
|
|
150
|
+
expect(html).not.toContain("github-installation-card");
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("is absent when no App is configured", async () => {
|
|
154
|
+
const { app } = setup({
|
|
155
|
+
enterprise: { configured: false, installer: null, lookup: null },
|
|
156
|
+
});
|
|
157
|
+
const html = await (await get(app, "")).text();
|
|
158
|
+
expect(html).not.toContain("github-installation-card");
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("shows the missing-App-id reason, not the button, with no GH_APP_ID", async () => {
|
|
162
|
+
const { app } = setup({ env: { FOO: "bar" } });
|
|
163
|
+
const html = await (await get(app, "")).text();
|
|
164
|
+
expect(html).toContain('data-reason="missing-app-id"');
|
|
165
|
+
expect(html).not.toContain('id="github-sync-btn"');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("shows the no-username reason, not the button, with no bound user", async () => {
|
|
169
|
+
const { app } = setup({ username: null });
|
|
170
|
+
const html = await (await get(app, "")).text();
|
|
171
|
+
expect(html).toContain('data-reason="no-username"');
|
|
172
|
+
expect(html).not.toContain('id="github-sync-btn"');
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("has no no-username reason when the Apps are not both configured", async () => {
|
|
176
|
+
const { app } = setup({
|
|
177
|
+
username: null,
|
|
178
|
+
enterprise: { configured: true, installer: null, lookup: null },
|
|
179
|
+
});
|
|
180
|
+
const html = await (await get(app, "")).text();
|
|
181
|
+
expect(html).not.toContain('data-reason="no-username"');
|
|
182
|
+
});
|
|
183
|
+
|
|
123
184
|
it("is absent for a non-admin", async () => {
|
|
124
185
|
const { app } = setup({});
|
|
125
186
|
const html = await (await get(app, "", member)).text();
|
|
@@ -142,17 +203,16 @@ describe("admin UI — installation repos card (IRM-1.4)", () => {
|
|
|
142
203
|
expect(html).toContain("user cannot push");
|
|
143
204
|
// acme/docs has no hint: exactly two hint badges
|
|
144
205
|
expect(html.match(/>user can(not)? push</g)?.length).toBe(2);
|
|
145
|
-
expect(html).toContain(
|
|
206
|
+
expect(html).not.toContain("data-action=");
|
|
207
|
+
expect(html).not.toContain("<button");
|
|
146
208
|
});
|
|
147
209
|
|
|
148
|
-
it("
|
|
210
|
+
it("lists repos for an unbound username without hints", async () => {
|
|
149
211
|
const { app } = setup({
|
|
150
212
|
username: null,
|
|
151
213
|
agentsApi: () => json(INSTALLED),
|
|
152
214
|
});
|
|
153
215
|
const html = await (await get(app, "/github-installation")).text();
|
|
154
|
-
expect(html).toContain('data-reason="no-username"');
|
|
155
|
-
expect(html).not.toContain('data-action="lost-access-preview"');
|
|
156
216
|
expect(html).toContain("acme/api");
|
|
157
217
|
});
|
|
158
218
|
|
|
@@ -175,213 +235,146 @@ describe("admin UI — installation repos card (IRM-1.4)", () => {
|
|
|
175
235
|
});
|
|
176
236
|
});
|
|
177
237
|
|
|
178
|
-
describe("
|
|
179
|
-
it("
|
|
238
|
+
describe("GH_APP_ID mismatch", () => {
|
|
239
|
+
it("is explicit when no installation matches but the Installations card has one", async () => {
|
|
180
240
|
const { app, calls } = setup({
|
|
181
|
-
agentsApi: () =>
|
|
182
|
-
|
|
241
|
+
agentsApi: (path) =>
|
|
242
|
+
path.endsWith("/github-installation/repos")
|
|
243
|
+
? json({ appId: 123, orgs: [] })
|
|
244
|
+
: json({ snapshot: { installations: [{ slug: "x" }] } }),
|
|
183
245
|
});
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
expect(c?.path).toBe(`/agents/${AGENT_ID}/github-installation/repos`);
|
|
190
|
-
expect(JSON.parse(String(c?.init?.body))).toEqual({
|
|
191
|
-
repos: ["acme/new"],
|
|
192
|
-
});
|
|
193
|
-
expect(html).toContain("Added to the installation");
|
|
194
|
-
expect(html).toContain("aud-1");
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it("proxies remove and surfaces an API error", async () => {
|
|
198
|
-
const ok = setup({
|
|
199
|
-
agentsApi: () =>
|
|
200
|
-
json({ status: "applied", auditId: "aud-2", repos: ["acme/web"] }),
|
|
201
|
-
});
|
|
202
|
-
const res = await post(ok.app, "/github-installation/repos/remove", {
|
|
203
|
-
repos: ["acme/web"],
|
|
204
|
-
});
|
|
205
|
-
expect(ok.calls.at(-1)?.path).toBe(
|
|
206
|
-
`/agents/${AGENT_ID}/github-installation/repos/remove`,
|
|
246
|
+
const html = await (await get(app, "/github-installation")).text();
|
|
247
|
+
expect(html).toContain('data-reason="app-id-mismatch"');
|
|
248
|
+
expect(html).not.toContain("not installed on any organization");
|
|
249
|
+
expect(calls.some((c) => c.path.endsWith("/github-installations"))).toBe(
|
|
250
|
+
true,
|
|
207
251
|
);
|
|
208
|
-
expect(await res.text()).toContain("Removed from the installation");
|
|
209
|
-
|
|
210
|
-
const bad = setup({
|
|
211
|
-
agentsApi: () => json({ error: "App not installed on org" }, 409),
|
|
212
|
-
});
|
|
213
|
-
const err = await post(bad.app, "/github-installation/repos/remove", {
|
|
214
|
-
repos: ["x/y"],
|
|
215
|
-
});
|
|
216
|
-
expect(err.status).toBe(409);
|
|
217
|
-
expect(await err.text()).toContain("App not installed on org");
|
|
218
252
|
});
|
|
219
253
|
|
|
220
|
-
it("is
|
|
221
|
-
const { app
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
);
|
|
228
|
-
expect(
|
|
229
|
-
expect(
|
|
254
|
+
it("says not installed when there is no installation at all", async () => {
|
|
255
|
+
const { app } = setup({
|
|
256
|
+
agentsApi: (path) =>
|
|
257
|
+
path.endsWith("/github-installation/repos")
|
|
258
|
+
? json({ appId: 123, orgs: [] })
|
|
259
|
+
: json({ error: "none" }, 404),
|
|
260
|
+
});
|
|
261
|
+
const html = await (await get(app, "/github-installation")).text();
|
|
262
|
+
expect(html).toContain("not installed on any organization");
|
|
263
|
+
expect(html).not.toContain("app-id-mismatch");
|
|
230
264
|
});
|
|
231
265
|
});
|
|
232
266
|
|
|
233
|
-
describe("
|
|
234
|
-
const
|
|
235
|
-
{ id: "acme/api#12", repo: "acme/api", title: "Fix <thing>" },
|
|
236
|
-
{ id: "task-9", repo: "acme/api" },
|
|
237
|
-
];
|
|
238
|
-
const preview = (over: Record<string, unknown> = {}) => ({
|
|
267
|
+
describe("sync confirm and apply", () => {
|
|
268
|
+
const PREVIEW = {
|
|
239
269
|
status: "previewed",
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
270
|
+
appAdds: ["acme/new"],
|
|
271
|
+
appRemoves: ["acme/old"],
|
|
272
|
+
agentRemoves: ["acme/gone"],
|
|
243
273
|
skippedOrgs: [],
|
|
244
|
-
openWork:
|
|
274
|
+
openWork: [{ id: "acme/old#4", repo: "acme/old", title: "Open PR" }],
|
|
245
275
|
warnings: [],
|
|
246
|
-
|
|
247
|
-
|
|
276
|
+
};
|
|
277
|
+
const api: Api = (path, init) => {
|
|
278
|
+
if (path.endsWith("/github-sync/preview")) return json(PREVIEW);
|
|
279
|
+
if (path.endsWith("/github-sync/apply") && init?.method === "POST") {
|
|
280
|
+
return json({
|
|
281
|
+
status: "applied",
|
|
282
|
+
appAdds: ["acme/new"],
|
|
283
|
+
appRemoves: ["acme/old"],
|
|
284
|
+
agentRemoves: ["acme/gone"],
|
|
285
|
+
notApplied: [],
|
|
286
|
+
skippedOrgs: [],
|
|
287
|
+
warnings: [],
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
return json({});
|
|
291
|
+
};
|
|
248
292
|
|
|
249
|
-
it("lists
|
|
250
|
-
const { app, calls } = setup({ agentsApi:
|
|
251
|
-
const res = await get(app, "/github-
|
|
293
|
+
it("one confirm lists adds, removes, agent removes and blocked work", async () => {
|
|
294
|
+
const { app, calls } = setup({ agentsApi: api });
|
|
295
|
+
const res = await get(app, "/github-sync/confirm");
|
|
296
|
+
expect(res.status).toBe(200);
|
|
252
297
|
const html = await res.text();
|
|
253
298
|
expect(calls.at(-1)?.path).toBe(
|
|
254
|
-
`/agents/${AGENT_ID}/github-
|
|
299
|
+
`/agents/${AGENT_ID}/github-sync/preview`,
|
|
255
300
|
);
|
|
256
|
-
expect(html).toContain("
|
|
257
|
-
expect(html).toContain('
|
|
258
|
-
expect(html).toContain("
|
|
259
|
-
expect(html).toContain("
|
|
260
|
-
expect(html
|
|
261
|
-
expect(html).toContain('id="github-lost-access-apply-btn"');
|
|
262
|
-
expect(html).not.toContain("github-lost-access-confirm-cap");
|
|
301
|
+
expect(html).toContain('data-list="app-adds"');
|
|
302
|
+
expect(html).toContain('data-list="app-removes"');
|
|
303
|
+
expect(html).toContain('data-list="agent-removes"');
|
|
304
|
+
expect(html).toContain('href="https://github.com/acme/old/pull/4"');
|
|
305
|
+
expect(html.match(/id="github-sync-confirm-btn"/g)?.length).toBe(1);
|
|
263
306
|
});
|
|
264
307
|
|
|
265
|
-
it("
|
|
308
|
+
it("shows the reason for a skipped preview", async () => {
|
|
266
309
|
const { app } = setup({
|
|
267
|
-
agentsApi: () => json(
|
|
310
|
+
agentsApi: () => json({ status: "skipped", reason: "user not found" }),
|
|
268
311
|
});
|
|
269
|
-
const html = await (await get(app, "/github-
|
|
270
|
-
expect(html).toContain(
|
|
271
|
-
expect(html).toContain("
|
|
312
|
+
const html = await (await get(app, "/github-sync/confirm")).text();
|
|
313
|
+
expect(html).toContain("user not found");
|
|
314
|
+
expect(html).not.toContain("github-sync-confirm-btn");
|
|
272
315
|
});
|
|
273
316
|
|
|
274
|
-
it("
|
|
317
|
+
it("surfaces an API failure on the confirm step", async () => {
|
|
275
318
|
const { app } = setup({
|
|
276
|
-
agentsApi: () =>
|
|
277
|
-
json(
|
|
278
|
-
preview({
|
|
279
|
-
openWork: [],
|
|
280
|
-
warnings: ["open work could not be listed: boom"],
|
|
281
|
-
skippedOrgs: [{ org: "partial-org", reason: "partial listing" }],
|
|
282
|
-
}),
|
|
283
|
-
),
|
|
284
|
-
});
|
|
285
|
-
const html = await (await get(app, "/github-lost-access/preview")).text();
|
|
286
|
-
expect(html).toContain("open work could not be listed: boom");
|
|
287
|
-
expect(html).toContain("partial-org");
|
|
288
|
-
expect(html).toContain("partial listing");
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
it("asks for the extra confirmation over the cap", async () => {
|
|
292
|
-
const repos = Array.from({ length: 11 }, (_, i) => `acme/r${i}`);
|
|
293
|
-
const { app } = setup({
|
|
294
|
-
agentsApi: () =>
|
|
295
|
-
json(preview({ repos, installationRemoves: repos, openWork: [] })),
|
|
296
|
-
});
|
|
297
|
-
const html = await (await get(app, "/github-lost-access/preview")).text();
|
|
298
|
-
expect(html).toContain('id="github-lost-access-confirm-cap"');
|
|
299
|
-
expect(html).toContain('data-over-cap="true"');
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
it("renders a skipped preview as a reason", async () => {
|
|
303
|
-
const { app } = setup({
|
|
304
|
-
agentsApi: () =>
|
|
305
|
-
json({ status: "skipped", reason: "GitHub user not found" }),
|
|
319
|
+
agentsApi: () => json({ error: "GitHub Apps are not configured" }, 503),
|
|
306
320
|
});
|
|
307
|
-
const
|
|
308
|
-
expect(
|
|
309
|
-
expect(html).not.toContain("github-lost-access-apply-btn");
|
|
321
|
+
const res = await get(app, "/github-sync/confirm");
|
|
322
|
+
expect(res.status).toBe(503);
|
|
310
323
|
});
|
|
311
324
|
|
|
312
|
-
it("
|
|
313
|
-
const { app, calls } = setup({
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
auditId: "aud-7",
|
|
319
|
-
repos: ["acme/api"],
|
|
320
|
-
notRemoved: [{ repo: "acme/web", reason: "still pushable" }],
|
|
321
|
-
warnings: [],
|
|
322
|
-
})
|
|
323
|
-
: json(preview()),
|
|
324
|
-
});
|
|
325
|
-
const res = await post(app, "/github-lost-access/remove", {
|
|
326
|
-
repos: ["acme/api"],
|
|
325
|
+
it("apply posts the confirmed lists once and shows what was blocked", async () => {
|
|
326
|
+
const { app, calls } = setup({ agentsApi: api });
|
|
327
|
+
const res = await post(app, "/github-sync/apply-confirmed", {
|
|
328
|
+
appAdds: ["acme/new"],
|
|
329
|
+
appRemoves: ["acme/old"],
|
|
330
|
+
agentRemoves: ["acme/gone"],
|
|
327
331
|
confirmRemovals: true,
|
|
328
332
|
});
|
|
333
|
+
expect(res.status).toBe(200);
|
|
329
334
|
const html = await res.text();
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
`/agents/${AGENT_ID}/github-lost-access/remove`,
|
|
335
|
+
const applies = calls.filter((c) =>
|
|
336
|
+
c.path.endsWith("/github-sync/apply"),
|
|
333
337
|
);
|
|
334
|
-
expect(
|
|
335
|
-
|
|
338
|
+
expect(applies.length).toBe(1);
|
|
339
|
+
expect(JSON.parse(String(applies[0]?.init?.body))).toEqual({
|
|
340
|
+
appAdds: ["acme/new"],
|
|
341
|
+
appRemoves: ["acme/old"],
|
|
342
|
+
agentRemoves: ["acme/gone"],
|
|
336
343
|
confirmRemovals: true,
|
|
337
344
|
});
|
|
338
|
-
expect(html).toContain(
|
|
345
|
+
expect(html).toContain('data-sync="applied"');
|
|
339
346
|
expect(html).toContain("were blocked");
|
|
340
|
-
expect(html).toContain(
|
|
341
|
-
expect(html).toContain("still pushable");
|
|
347
|
+
expect(html).toContain("acme/old#4");
|
|
342
348
|
});
|
|
343
349
|
|
|
344
|
-
it("
|
|
345
|
-
const { app } = setup({
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
? json({
|
|
349
|
-
status: "applied",
|
|
350
|
-
auditId: "aud-8",
|
|
351
|
-
repos: ["acme/api"],
|
|
352
|
-
warnings: ["open work for acme/api was not blocked: boom"],
|
|
353
|
-
})
|
|
354
|
-
: json(preview()),
|
|
350
|
+
it("rejects an invalid repo without calling the API", async () => {
|
|
351
|
+
const { app, calls } = setup({ agentsApi: api });
|
|
352
|
+
const res = await post(app, "/github-sync/apply-confirmed", {
|
|
353
|
+
appAdds: ["nope"],
|
|
355
354
|
});
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
).text();
|
|
359
|
-
expect(html).toContain("No open tasks or PRs were blocked");
|
|
360
|
-
expect(html).toContain("was not blocked: boom");
|
|
355
|
+
expect(res.status).toBe(400);
|
|
356
|
+
expect(calls.length).toBe(0);
|
|
361
357
|
});
|
|
362
358
|
|
|
363
|
-
it("
|
|
359
|
+
it("shows the over-cap refusal from the API", async () => {
|
|
364
360
|
const { app } = setup({
|
|
365
|
-
agentsApi: (
|
|
366
|
-
|
|
361
|
+
agentsApi: (path) =>
|
|
362
|
+
path.endsWith("/github-sync/apply")
|
|
367
363
|
? json({ error: "11 repos would be removed" }, 422)
|
|
368
|
-
: json(
|
|
364
|
+
: json(PREVIEW),
|
|
369
365
|
});
|
|
370
|
-
const res = await post(app, "/github-
|
|
371
|
-
|
|
366
|
+
const res = await post(app, "/github-sync/apply-confirmed", {
|
|
367
|
+
appRemoves: ["acme/old"],
|
|
372
368
|
});
|
|
373
369
|
expect(res.status).toBe(422);
|
|
374
370
|
expect(await res.text()).toContain("11 repos would be removed");
|
|
375
371
|
});
|
|
376
372
|
|
|
377
|
-
it("
|
|
373
|
+
it("both routes are forbidden for a non-admin and make no call", async () => {
|
|
378
374
|
const { app, calls } = setup({});
|
|
375
|
+
expect((await get(app, "/github-sync/confirm", member)).status).toBe(403);
|
|
379
376
|
expect(
|
|
380
|
-
(await
|
|
381
|
-
).toBe(403);
|
|
382
|
-
expect(
|
|
383
|
-
(await post(app, "/github-lost-access/remove", { repos: [] }, member))
|
|
384
|
-
.status,
|
|
377
|
+
(await post(app, "/github-sync/apply-confirmed", {}, member)).status,
|
|
385
378
|
).toBe(403);
|
|
386
379
|
expect(calls.length).toBe(0);
|
|
387
380
|
});
|