@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
|
@@ -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,18 +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"');
|
|
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");
|
|
114
127
|
});
|
|
115
128
|
|
|
116
|
-
it("is absent
|
|
117
|
-
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
|
+
});
|
|
118
137
|
const html = await (await get(app, "")).text();
|
|
119
138
|
expect(html).not.toContain("github-installation-card");
|
|
120
139
|
});
|
|
121
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
|
+
|
|
122
184
|
it("is absent for a non-admin", async () => {
|
|
123
185
|
const { app } = setup({});
|
|
124
186
|
const html = await (await get(app, "", member)).text();
|
|
@@ -141,17 +203,16 @@ describe("admin UI — installation repos card (IRM-1.4)", () => {
|
|
|
141
203
|
expect(html).toContain("user cannot push");
|
|
142
204
|
// acme/docs has no hint: exactly two hint badges
|
|
143
205
|
expect(html.match(/>user can(not)? push</g)?.length).toBe(2);
|
|
144
|
-
expect(html).toContain(
|
|
206
|
+
expect(html).not.toContain("data-action=");
|
|
207
|
+
expect(html).not.toContain("<button");
|
|
145
208
|
});
|
|
146
209
|
|
|
147
|
-
it("
|
|
210
|
+
it("lists repos for an unbound username without hints", async () => {
|
|
148
211
|
const { app } = setup({
|
|
149
212
|
username: null,
|
|
150
213
|
agentsApi: () => json(INSTALLED),
|
|
151
214
|
});
|
|
152
215
|
const html = await (await get(app, "/github-installation")).text();
|
|
153
|
-
expect(html).toContain('data-reason="no-username"');
|
|
154
|
-
expect(html).not.toContain('data-action="lost-access-preview"');
|
|
155
216
|
expect(html).toContain("acme/api");
|
|
156
217
|
});
|
|
157
218
|
|
|
@@ -174,213 +235,146 @@ describe("admin UI — installation repos card (IRM-1.4)", () => {
|
|
|
174
235
|
});
|
|
175
236
|
});
|
|
176
237
|
|
|
177
|
-
describe("
|
|
178
|
-
it("
|
|
238
|
+
describe("GH_APP_ID mismatch", () => {
|
|
239
|
+
it("is explicit when no installation matches but the Installations card has one", async () => {
|
|
179
240
|
const { app, calls } = setup({
|
|
180
|
-
agentsApi: () =>
|
|
181
|
-
|
|
241
|
+
agentsApi: (path) =>
|
|
242
|
+
path.endsWith("/github-installation/repos")
|
|
243
|
+
? json({ appId: 123, orgs: [] })
|
|
244
|
+
: json({ snapshot: { installations: [{ slug: "x" }] } }),
|
|
182
245
|
});
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
expect(c?.path).toBe(`/agents/${AGENT_ID}/github-installation/repos`);
|
|
189
|
-
expect(JSON.parse(String(c?.init?.body))).toEqual({
|
|
190
|
-
repos: ["acme/new"],
|
|
191
|
-
});
|
|
192
|
-
expect(html).toContain("Added to the installation");
|
|
193
|
-
expect(html).toContain("aud-1");
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it("proxies remove and surfaces an API error", async () => {
|
|
197
|
-
const ok = setup({
|
|
198
|
-
agentsApi: () =>
|
|
199
|
-
json({ status: "applied", auditId: "aud-2", repos: ["acme/web"] }),
|
|
200
|
-
});
|
|
201
|
-
const res = await post(ok.app, "/github-installation/repos/remove", {
|
|
202
|
-
repos: ["acme/web"],
|
|
203
|
-
});
|
|
204
|
-
expect(ok.calls.at(-1)?.path).toBe(
|
|
205
|
-
`/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,
|
|
206
251
|
);
|
|
207
|
-
expect(await res.text()).toContain("Removed from the installation");
|
|
208
|
-
|
|
209
|
-
const bad = setup({
|
|
210
|
-
agentsApi: () => json({ error: "App not installed on org" }, 409),
|
|
211
|
-
});
|
|
212
|
-
const err = await post(bad.app, "/github-installation/repos/remove", {
|
|
213
|
-
repos: ["x/y"],
|
|
214
|
-
});
|
|
215
|
-
expect(err.status).toBe(409);
|
|
216
|
-
expect(await err.text()).toContain("App not installed on org");
|
|
217
252
|
});
|
|
218
253
|
|
|
219
|
-
it("is
|
|
220
|
-
const { app
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
);
|
|
227
|
-
expect(
|
|
228
|
-
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");
|
|
229
264
|
});
|
|
230
265
|
});
|
|
231
266
|
|
|
232
|
-
describe("
|
|
233
|
-
const
|
|
234
|
-
{ id: "acme/api#12", repo: "acme/api", title: "Fix <thing>" },
|
|
235
|
-
{ id: "task-9", repo: "acme/api" },
|
|
236
|
-
];
|
|
237
|
-
const preview = (over: Record<string, unknown> = {}) => ({
|
|
267
|
+
describe("sync confirm and apply", () => {
|
|
268
|
+
const PREVIEW = {
|
|
238
269
|
status: "previewed",
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
270
|
+
appAdds: ["acme/new"],
|
|
271
|
+
appRemoves: ["acme/old"],
|
|
272
|
+
agentRemoves: ["acme/gone"],
|
|
242
273
|
skippedOrgs: [],
|
|
243
|
-
openWork:
|
|
274
|
+
openWork: [{ id: "acme/old#4", repo: "acme/old", title: "Open PR" }],
|
|
244
275
|
warnings: [],
|
|
245
|
-
|
|
246
|
-
|
|
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
|
+
};
|
|
247
292
|
|
|
248
|
-
it("lists
|
|
249
|
-
const { app, calls } = setup({ agentsApi:
|
|
250
|
-
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);
|
|
251
297
|
const html = await res.text();
|
|
252
298
|
expect(calls.at(-1)?.path).toBe(
|
|
253
|
-
`/agents/${AGENT_ID}/github-
|
|
299
|
+
`/agents/${AGENT_ID}/github-sync/preview`,
|
|
254
300
|
);
|
|
255
|
-
expect(html).toContain("
|
|
256
|
-
expect(html).toContain('
|
|
257
|
-
expect(html).toContain("
|
|
258
|
-
expect(html).toContain("
|
|
259
|
-
expect(html
|
|
260
|
-
expect(html).toContain('id="github-lost-access-apply-btn"');
|
|
261
|
-
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);
|
|
262
306
|
});
|
|
263
307
|
|
|
264
|
-
it("
|
|
308
|
+
it("shows the reason for a skipped preview", async () => {
|
|
265
309
|
const { app } = setup({
|
|
266
|
-
agentsApi: () => json(
|
|
310
|
+
agentsApi: () => json({ status: "skipped", reason: "user not found" }),
|
|
267
311
|
});
|
|
268
|
-
const html = await (await get(app, "/github-
|
|
269
|
-
expect(html).toContain(
|
|
270
|
-
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");
|
|
271
315
|
});
|
|
272
316
|
|
|
273
|
-
it("
|
|
317
|
+
it("surfaces an API failure on the confirm step", async () => {
|
|
274
318
|
const { app } = setup({
|
|
275
|
-
agentsApi: () =>
|
|
276
|
-
json(
|
|
277
|
-
preview({
|
|
278
|
-
openWork: [],
|
|
279
|
-
warnings: ["open work could not be listed: boom"],
|
|
280
|
-
skippedOrgs: [{ org: "partial-org", reason: "partial listing" }],
|
|
281
|
-
}),
|
|
282
|
-
),
|
|
283
|
-
});
|
|
284
|
-
const html = await (await get(app, "/github-lost-access/preview")).text();
|
|
285
|
-
expect(html).toContain("open work could not be listed: boom");
|
|
286
|
-
expect(html).toContain("partial-org");
|
|
287
|
-
expect(html).toContain("partial listing");
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
it("asks for the extra confirmation over the cap", async () => {
|
|
291
|
-
const repos = Array.from({ length: 11 }, (_, i) => `acme/r${i}`);
|
|
292
|
-
const { app } = setup({
|
|
293
|
-
agentsApi: () =>
|
|
294
|
-
json(preview({ repos, installationRemoves: repos, openWork: [] })),
|
|
295
|
-
});
|
|
296
|
-
const html = await (await get(app, "/github-lost-access/preview")).text();
|
|
297
|
-
expect(html).toContain('id="github-lost-access-confirm-cap"');
|
|
298
|
-
expect(html).toContain('data-over-cap="true"');
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
it("renders a skipped preview as a reason", async () => {
|
|
302
|
-
const { app } = setup({
|
|
303
|
-
agentsApi: () =>
|
|
304
|
-
json({ status: "skipped", reason: "GitHub user not found" }),
|
|
319
|
+
agentsApi: () => json({ error: "GitHub Apps are not configured" }, 503),
|
|
305
320
|
});
|
|
306
|
-
const
|
|
307
|
-
expect(
|
|
308
|
-
expect(html).not.toContain("github-lost-access-apply-btn");
|
|
321
|
+
const res = await get(app, "/github-sync/confirm");
|
|
322
|
+
expect(res.status).toBe(503);
|
|
309
323
|
});
|
|
310
324
|
|
|
311
|
-
it("
|
|
312
|
-
const { app, calls } = setup({
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
auditId: "aud-7",
|
|
318
|
-
repos: ["acme/api"],
|
|
319
|
-
notRemoved: [{ repo: "acme/web", reason: "still pushable" }],
|
|
320
|
-
warnings: [],
|
|
321
|
-
})
|
|
322
|
-
: json(preview()),
|
|
323
|
-
});
|
|
324
|
-
const res = await post(app, "/github-lost-access/remove", {
|
|
325
|
-
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"],
|
|
326
331
|
confirmRemovals: true,
|
|
327
332
|
});
|
|
333
|
+
expect(res.status).toBe(200);
|
|
328
334
|
const html = await res.text();
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
`/agents/${AGENT_ID}/github-lost-access/remove`,
|
|
335
|
+
const applies = calls.filter((c) =>
|
|
336
|
+
c.path.endsWith("/github-sync/apply"),
|
|
332
337
|
);
|
|
333
|
-
expect(
|
|
334
|
-
|
|
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"],
|
|
335
343
|
confirmRemovals: true,
|
|
336
344
|
});
|
|
337
|
-
expect(html).toContain(
|
|
345
|
+
expect(html).toContain('data-sync="applied"');
|
|
338
346
|
expect(html).toContain("were blocked");
|
|
339
|
-
expect(html).toContain(
|
|
340
|
-
expect(html).toContain("still pushable");
|
|
347
|
+
expect(html).toContain("acme/old#4");
|
|
341
348
|
});
|
|
342
349
|
|
|
343
|
-
it("
|
|
344
|
-
const { app } = setup({
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
? json({
|
|
348
|
-
status: "applied",
|
|
349
|
-
auditId: "aud-8",
|
|
350
|
-
repos: ["acme/api"],
|
|
351
|
-
warnings: ["open work for acme/api was not blocked: boom"],
|
|
352
|
-
})
|
|
353
|
-
: 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"],
|
|
354
354
|
});
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
).text();
|
|
358
|
-
expect(html).toContain("No open tasks or PRs were blocked");
|
|
359
|
-
expect(html).toContain("was not blocked: boom");
|
|
355
|
+
expect(res.status).toBe(400);
|
|
356
|
+
expect(calls.length).toBe(0);
|
|
360
357
|
});
|
|
361
358
|
|
|
362
|
-
it("
|
|
359
|
+
it("shows the over-cap refusal from the API", async () => {
|
|
363
360
|
const { app } = setup({
|
|
364
|
-
agentsApi: (
|
|
365
|
-
|
|
361
|
+
agentsApi: (path) =>
|
|
362
|
+
path.endsWith("/github-sync/apply")
|
|
366
363
|
? json({ error: "11 repos would be removed" }, 422)
|
|
367
|
-
: json(
|
|
364
|
+
: json(PREVIEW),
|
|
368
365
|
});
|
|
369
|
-
const res = await post(app, "/github-
|
|
370
|
-
|
|
366
|
+
const res = await post(app, "/github-sync/apply-confirmed", {
|
|
367
|
+
appRemoves: ["acme/old"],
|
|
371
368
|
});
|
|
372
369
|
expect(res.status).toBe(422);
|
|
373
370
|
expect(await res.text()).toContain("11 repos would be removed");
|
|
374
371
|
});
|
|
375
372
|
|
|
376
|
-
it("
|
|
373
|
+
it("both routes are forbidden for a non-admin and make no call", async () => {
|
|
377
374
|
const { app, calls } = setup({});
|
|
375
|
+
expect((await get(app, "/github-sync/confirm", member)).status).toBe(403);
|
|
378
376
|
expect(
|
|
379
|
-
(await
|
|
380
|
-
).toBe(403);
|
|
381
|
-
expect(
|
|
382
|
-
(await post(app, "/github-lost-access/remove", { repos: [] }, member))
|
|
383
|
-
.status,
|
|
377
|
+
(await post(app, "/github-sync/apply-confirmed", {}, member)).status,
|
|
384
378
|
).toBe(403);
|
|
385
379
|
expect(calls.length).toBe(0);
|
|
386
380
|
});
|