@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
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
accessSkipReason,
|
|
4
|
+
orgSkipReason,
|
|
5
|
+
repoOrg,
|
|
6
|
+
} from "./repo-access-rules.ts";
|
|
7
|
+
import {
|
|
8
|
+
type OrgAccessResult,
|
|
9
|
+
SELECTED_REPOS_REASON,
|
|
10
|
+
type UserRepoAccessResult,
|
|
11
|
+
} from "./user-repo-access-resolver.ts";
|
|
12
|
+
|
|
13
|
+
const repo = (fullName: string, canPush: boolean) => ({
|
|
14
|
+
fullName,
|
|
15
|
+
canPush,
|
|
16
|
+
level: canPush ? ("write" as const) : ("read" as const),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const org = (
|
|
20
|
+
name: string,
|
|
21
|
+
repos: ReturnType<typeof repo>[],
|
|
22
|
+
extra: Partial<OrgAccessResult> = {},
|
|
23
|
+
): OrgAccessResult => ({
|
|
24
|
+
org: name,
|
|
25
|
+
status: "ok",
|
|
26
|
+
repos,
|
|
27
|
+
unresolved: 0,
|
|
28
|
+
...extra,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const access = (
|
|
32
|
+
orgs: OrgAccessResult[],
|
|
33
|
+
extra: Partial<UserRepoAccessResult> = {},
|
|
34
|
+
): UserRepoAccessResult => ({
|
|
35
|
+
username: "octo",
|
|
36
|
+
outcome: "ok",
|
|
37
|
+
userVerified: true,
|
|
38
|
+
orgs,
|
|
39
|
+
unresolved: 0,
|
|
40
|
+
complete: orgs.every((o) => o.status === "ok"),
|
|
41
|
+
checkedAt: "2026-11-11T00:00:00.000Z",
|
|
42
|
+
...extra,
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("repoOrg", () => {
|
|
46
|
+
test("returns the owner part of owner/repo", () => {
|
|
47
|
+
expect(repoOrg("acme/a")).toBe("acme");
|
|
48
|
+
expect(repoOrg("")).toBe("");
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe("orgSkipReason", () => {
|
|
53
|
+
test("a complete listing has no skip reason", () => {
|
|
54
|
+
expect(orgSkipReason(org("acme", [repo("acme/a", true)]))).toBeUndefined();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("an unchecked org is skipped", () => {
|
|
58
|
+
expect(orgSkipReason(undefined)).toBe("org was not checked");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test("a selected-repositories-only lookup install is skipped", () => {
|
|
62
|
+
const r = org("acme", [], { reason: SELECTED_REPOS_REASON });
|
|
63
|
+
expect(orgSkipReason(r)).toContain("selected repositories only");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("partial and failed listings are skipped", () => {
|
|
67
|
+
expect(orgSkipReason(org("acme", [], { status: "partial" }))).toContain(
|
|
68
|
+
"incomplete",
|
|
69
|
+
);
|
|
70
|
+
expect(orgSkipReason(org("acme", [], { status: "error" }))).toContain(
|
|
71
|
+
"access lookup failed",
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("accessSkipReason", () => {
|
|
77
|
+
const ok = access([org("acme", [repo("acme/a", true)])]);
|
|
78
|
+
|
|
79
|
+
test("a usable access result has no skip reason", () => {
|
|
80
|
+
expect(accessSkipReason("octo", ok)).toBeUndefined();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("an unbound or blank username is skipped", () => {
|
|
84
|
+
for (const username of [undefined, null, "", " "]) {
|
|
85
|
+
expect(accessSkipReason(username, ok)).toContain("no GitHub username");
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("unresolved access, unknown user and unverified user are skipped", () => {
|
|
90
|
+
expect(accessSkipReason("octo", null)).toBe("access was not resolved");
|
|
91
|
+
expect(
|
|
92
|
+
accessSkipReason("octo", access([], { outcome: "user_not_found" })),
|
|
93
|
+
).toBe("GitHub user not found");
|
|
94
|
+
expect(accessSkipReason("octo", access([], { userVerified: false }))).toBe(
|
|
95
|
+
"GitHub user could not be verified",
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* admin/src/admin-ui-github-reconcile-pages.ts
|
|
3
|
-
* Pure renderers for the agent detail page's GitHub Reconcile card (GHE-3.5).
|
|
4
|
-
* Platform-admin only; the caller renders the card only when a GitHub username
|
|
5
|
-
* is bound and the enterprise apps are configured. The card posts to the
|
|
6
|
-
* admin UI's plan/apply proxy routes; these renderers produce the fragments
|
|
7
|
-
* those routes return. Every dynamic value is escaped. Inputs carry repo names
|
|
8
|
-
* and ids only (no token or key ever reaches this module).
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { escapeHtml } from "./admin-ui-styles.ts";
|
|
12
|
-
|
|
13
|
-
/** Mirrors MAX_UNCONFIRMED_REMOVALS in reconcile-apply-service.ts. */
|
|
14
|
-
export const RECONCILE_REMOVAL_CAP = 10;
|
|
15
|
-
|
|
16
|
-
export interface GithubReconcileDiffView {
|
|
17
|
-
installationAdds: string[];
|
|
18
|
-
installationRemoves: string[];
|
|
19
|
-
configAdds: string[];
|
|
20
|
-
configRemoves: string[];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** JSON body of POST /agents/:id/github-reconcile/plan. */
|
|
24
|
-
export interface GithubReconcilePlanView {
|
|
25
|
-
status: "planned" | "skipped";
|
|
26
|
-
reason?: string;
|
|
27
|
-
planHash?: string;
|
|
28
|
-
empty?: boolean;
|
|
29
|
-
diff?: GithubReconcileDiffView;
|
|
30
|
-
skippedOrgs?: { org: string; reason: string }[];
|
|
31
|
-
rejectedAdds?: { repo: string; reason: string }[];
|
|
32
|
-
warnings?: string[];
|
|
33
|
-
affectedOpenWork?: { id: string; repo: string; title?: string }[];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** JSON body of POST /agents/:id/github-reconcile/apply. */
|
|
37
|
-
export interface GithubReconcileApplyView {
|
|
38
|
-
status: "applied" | "failed" | "noop" | "skipped";
|
|
39
|
-
reason?: string;
|
|
40
|
-
auditId?: string;
|
|
41
|
-
error?: string;
|
|
42
|
-
warnings?: string[];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** The Reconcile card; the buttons talk to the UI plan/apply routes. */
|
|
46
|
-
export function renderGithubReconcileCard(agentId: string): string {
|
|
47
|
-
const base = `/admin/agents/${escapeHtml(agentId)}/github-reconcile`;
|
|
48
|
-
return `<div class="card" id="github-reconcile-card">
|
|
49
|
-
<div class="card-title">Reconcile</div>
|
|
50
|
-
<p style="color:#6b7280;font-size:12px;margin:0 0 12px">Plans the repo changes needed to match this agent's GitHub user access. Nothing changes until you review the plan and confirm.</p>
|
|
51
|
-
<div style="display:flex;gap:8px;flex-wrap:wrap;align-items:center">
|
|
52
|
-
<input name="addRepos" id="github-reconcile-add" type="text" class="form-input mono" placeholder="Repos to add (owner/repo, comma separated; optional)" style="min-width:320px" />
|
|
53
|
-
<button type="button" class="btn btn-primary" id="github-reconcile-plan-btn" data-plan-url="${base}/plan" data-apply-url="${base}/apply">Plan</button>
|
|
54
|
-
</div>
|
|
55
|
-
<div id="github-reconcile-result" style="margin-top:12px"></div>
|
|
56
|
-
<script>
|
|
57
|
-
(function() {
|
|
58
|
-
var btn = document.getElementById('github-reconcile-plan-btn');
|
|
59
|
-
var out = document.getElementById('github-reconcile-result');
|
|
60
|
-
var input = document.getElementById('github-reconcile-add');
|
|
61
|
-
if (!btn || !out || !input) return;
|
|
62
|
-
function show(r) { return r.text().then(function(t) { out.innerHTML = t; }); }
|
|
63
|
-
function fail() { out.textContent = 'The request failed.'; }
|
|
64
|
-
function adds() {
|
|
65
|
-
return input.value.split(/[\\s,]+/).filter(function(s) { return s; });
|
|
66
|
-
}
|
|
67
|
-
btn.addEventListener('click', function() {
|
|
68
|
-
btn.disabled = true;
|
|
69
|
-
out.textContent = 'Loading...';
|
|
70
|
-
fetch(btn.getAttribute('data-plan-url'), {
|
|
71
|
-
method: 'POST',
|
|
72
|
-
credentials: 'same-origin',
|
|
73
|
-
headers: { 'content-type': 'application/json' },
|
|
74
|
-
body: JSON.stringify({ addRepos: adds() })
|
|
75
|
-
}).then(show).catch(fail).then(function() { btn.disabled = false; });
|
|
76
|
-
});
|
|
77
|
-
function sync() {
|
|
78
|
-
var plan = out.querySelector('#github-reconcile-plan');
|
|
79
|
-
var apply = out.querySelector('#github-reconcile-apply-btn');
|
|
80
|
-
var ok = out.querySelector('#github-reconcile-confirm');
|
|
81
|
-
var cap = out.querySelector('#github-reconcile-confirm-removals');
|
|
82
|
-
if (!plan || !apply || !ok) return;
|
|
83
|
-
apply.disabled = !(ok.checked && (!cap || cap.checked));
|
|
84
|
-
}
|
|
85
|
-
out.addEventListener('change', sync);
|
|
86
|
-
out.addEventListener('click', function(e) {
|
|
87
|
-
var t = e.target;
|
|
88
|
-
if (!t || t.id !== 'github-reconcile-apply-btn') return;
|
|
89
|
-
var plan = out.querySelector('#github-reconcile-plan');
|
|
90
|
-
var cap = out.querySelector('#github-reconcile-confirm-removals');
|
|
91
|
-
var add = plan.getAttribute('data-add-repos');
|
|
92
|
-
t.disabled = true;
|
|
93
|
-
fetch(btn.getAttribute('data-apply-url'), {
|
|
94
|
-
method: 'POST',
|
|
95
|
-
credentials: 'same-origin',
|
|
96
|
-
headers: { 'content-type': 'application/json' },
|
|
97
|
-
body: JSON.stringify({
|
|
98
|
-
planHash: plan.getAttribute('data-plan-hash'),
|
|
99
|
-
addRepos: add ? add.split(',') : [],
|
|
100
|
-
confirmRemovals: !!(cap && cap.checked)
|
|
101
|
-
})
|
|
102
|
-
}).then(show).catch(fail);
|
|
103
|
-
});
|
|
104
|
-
})();
|
|
105
|
-
</script>
|
|
106
|
-
</div>`;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function repoList(repos: string[]): string {
|
|
110
|
-
return repos.length === 0
|
|
111
|
-
? `<span style="color:#9ca3af">none</span>`
|
|
112
|
-
: repos.map((r) => `<div class="mono">${escapeHtml(r)}</div>`).join("");
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function diffTable(diff: GithubReconcileDiffView): string {
|
|
116
|
-
const row = (label: string, adds: string[], removes: string[]) =>
|
|
117
|
-
`<tr><td style="width:200px">${label}</td><td>${repoList(adds)}</td><td>${repoList(removes)}</td></tr>`;
|
|
118
|
-
return `<table class="detail-table"><thead><tr><th>Change</th><th>Add</th><th>Remove</th></tr></thead><tbody>${row("Installation", diff.installationAdds, diff.installationRemoves)}${row("Agent config", diff.configAdds, diff.configRemoves)}</tbody></table>`;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function section(title: string, body: string): string {
|
|
122
|
-
return `<div style="margin-top:12px"><div style="font-weight:600;margin-bottom:6px">${title}</div>${body}</div>`;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Fragment for the plan result. `addRepos` is the named-add list the plan was
|
|
127
|
-
* made with; apply must resend it, so it rides along on the plan element.
|
|
128
|
-
*/
|
|
129
|
-
export function renderGithubReconcilePlanResult(
|
|
130
|
-
plan: GithubReconcilePlanView,
|
|
131
|
-
addRepos: string[],
|
|
132
|
-
): string {
|
|
133
|
-
if (plan.status === "skipped" || !plan.diff || !plan.planHash) {
|
|
134
|
-
return `<div class="alert alert-warning">Reconcile skipped: ${escapeHtml(plan.reason ?? "no plan was produced")}.</div>`;
|
|
135
|
-
}
|
|
136
|
-
const parts: string[] = [];
|
|
137
|
-
if (plan.skippedOrgs?.length) {
|
|
138
|
-
parts.push(
|
|
139
|
-
`<div class="alert alert-warning">Skipped organizations:<ul style="margin:6px 0 0 18px">${plan.skippedOrgs.map((o) => `<li><span class="mono">${escapeHtml(o.org)}</span>: ${escapeHtml(o.reason)}</li>`).join("")}</ul></div>`,
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
if (plan.rejectedAdds?.length) {
|
|
143
|
-
parts.push(
|
|
144
|
-
`<div class="alert alert-warning">Rejected additions:<ul style="margin:6px 0 0 18px">${plan.rejectedAdds.map((r) => `<li><span class="mono">${escapeHtml(r.repo)}</span>: ${escapeHtml(r.reason)}</li>`).join("")}</ul></div>`,
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
if (plan.warnings?.length) {
|
|
148
|
-
parts.push(
|
|
149
|
-
`<div class="alert alert-warning">${plan.warnings.map((w) => `<div>${escapeHtml(w)}</div>`).join("")}</div>`,
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
if (plan.empty) {
|
|
153
|
-
parts.push(
|
|
154
|
-
`<p class="empty-state">Nothing to change: the agent already matches its GitHub access.</p>`,
|
|
155
|
-
);
|
|
156
|
-
return parts.join("");
|
|
157
|
-
}
|
|
158
|
-
parts.push(diffTable(plan.diff));
|
|
159
|
-
if (plan.affectedOpenWork?.length) {
|
|
160
|
-
const rows = plan.affectedOpenWork
|
|
161
|
-
.map(
|
|
162
|
-
(w) =>
|
|
163
|
-
`<tr><td class="mono">${escapeHtml(w.id)}</td><td class="mono">${escapeHtml(w.repo)}</td><td>${escapeHtml(w.title ?? "")}</td></tr>`,
|
|
164
|
-
)
|
|
165
|
-
.join("");
|
|
166
|
-
parts.push(
|
|
167
|
-
section(
|
|
168
|
-
"Open tasks and PRs affected by the removals",
|
|
169
|
-
`<table class="detail-table"><thead><tr><th>Id</th><th>Repo</th><th>Title</th></tr></thead><tbody>${rows}</tbody></table>`,
|
|
170
|
-
),
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
const removals = plan.diff.configRemoves.length;
|
|
174
|
-
const overCap = removals > RECONCILE_REMOVAL_CAP;
|
|
175
|
-
const capConfirm = overCap
|
|
176
|
-
? `<label style="display:block;margin-bottom:8px"><input type="checkbox" id="github-reconcile-confirm-removals" /> This plan removes ${removals} repos (more than ${RECONCILE_REMOVAL_CAP}). I confirm the removals.</label>`
|
|
177
|
-
: "";
|
|
178
|
-
parts.push(
|
|
179
|
-
`<div id="github-reconcile-plan" style="margin-top:12px" data-plan-hash="${escapeHtml(plan.planHash)}" data-add-repos="${escapeHtml(addRepos.join(","))}" data-over-cap="${overCap}">
|
|
180
|
-
<label style="display:block;margin-bottom:8px"><input type="checkbox" id="github-reconcile-confirm" /> I have reviewed this plan and want to apply it.</label>
|
|
181
|
-
${capConfirm}
|
|
182
|
-
<button type="button" class="btn btn-danger" id="github-reconcile-apply-btn" disabled>Apply</button>
|
|
183
|
-
</div>`,
|
|
184
|
-
);
|
|
185
|
-
return parts.join("");
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/** Fragment for the apply result. */
|
|
189
|
-
export function renderGithubReconcileApplyResult(
|
|
190
|
-
res: GithubReconcileApplyView,
|
|
191
|
-
): string {
|
|
192
|
-
const audit = res.auditId
|
|
193
|
-
? ` Audit id: <span class="mono">${escapeHtml(res.auditId)}</span>.`
|
|
194
|
-
: "";
|
|
195
|
-
const warnings = (res.warnings ?? [])
|
|
196
|
-
.map((w) => `<div>${escapeHtml(w)}</div>`)
|
|
197
|
-
.join("");
|
|
198
|
-
switch (res.status) {
|
|
199
|
-
case "applied":
|
|
200
|
-
return `<div class="alert alert-success">Reconcile applied.${audit}${warnings}</div>`;
|
|
201
|
-
case "noop":
|
|
202
|
-
return `<div class="alert alert-warning">Nothing to change.${warnings}</div>`;
|
|
203
|
-
case "failed":
|
|
204
|
-
return `<div class="alert alert-error">Reconcile failed${res.error ? `: ${escapeHtml(res.error)}` : ""}.${audit}${warnings}</div>`;
|
|
205
|
-
default:
|
|
206
|
-
return `<div class="alert alert-warning">Reconcile skipped${res.reason ? `: ${escapeHtml(res.reason)}` : ""}.</div>`;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* admin/src/admin-ui-github-reconcile-pages.unit.test.ts
|
|
3
|
-
* Unit tests for the GHE-3.5 Reconcile card and its plan/apply fragments, and
|
|
4
|
-
* for the card's placement in renderAgentDetailPage (inert, plan, over-cap).
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { describe, expect, test } from "bun:test";
|
|
8
|
-
import {
|
|
9
|
-
type GithubReconcilePlanView,
|
|
10
|
-
renderGithubReconcileApplyResult,
|
|
11
|
-
renderGithubReconcileCard,
|
|
12
|
-
renderGithubReconcilePlanResult,
|
|
13
|
-
} from "./admin-ui-github-reconcile-pages.ts";
|
|
14
|
-
import { type AgentDetail, renderAgentDetailPage } from "./admin-ui-pages.ts";
|
|
15
|
-
|
|
16
|
-
const AGENT: AgentDetail = {
|
|
17
|
-
id: "agent-123",
|
|
18
|
-
name: "Test Agent",
|
|
19
|
-
slackId: "U12345",
|
|
20
|
-
selfHosted: false,
|
|
21
|
-
createdAt: new Date("2024-01-01T00:00:00Z"),
|
|
22
|
-
updatedAt: new Date("2024-01-02T00:00:00Z"),
|
|
23
|
-
repos: [],
|
|
24
|
-
authorAllowlist: [],
|
|
25
|
-
patchAuthorAllowlist: [],
|
|
26
|
-
restrictSlackToMembers: false,
|
|
27
|
-
specialty: "coding",
|
|
28
|
-
missingRequiredEnv: [],
|
|
29
|
-
autoPostReviews: true,
|
|
30
|
-
allowSelfReview: false,
|
|
31
|
-
minConfidence: 75,
|
|
32
|
-
maxFindings: 5,
|
|
33
|
-
cleanupMergedWorktrees: true,
|
|
34
|
-
cleanupAfterDays: 14,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
function page(
|
|
38
|
-
isAdmin: boolean,
|
|
39
|
-
configured: boolean,
|
|
40
|
-
githubUsername: string | null,
|
|
41
|
-
): string {
|
|
42
|
-
return renderAgentDetailPage(
|
|
43
|
-
{ ...AGENT, githubUsername },
|
|
44
|
-
{},
|
|
45
|
-
[],
|
|
46
|
-
[],
|
|
47
|
-
[],
|
|
48
|
-
[],
|
|
49
|
-
[],
|
|
50
|
-
"u@x.com",
|
|
51
|
-
isAdmin,
|
|
52
|
-
{ timezone: "UTC", githubEnterpriseConfigured: configured },
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const plan = (over: Partial<GithubReconcilePlanView> = {}) =>
|
|
57
|
-
({
|
|
58
|
-
status: "planned",
|
|
59
|
-
planHash: "hash-1",
|
|
60
|
-
empty: false,
|
|
61
|
-
diff: {
|
|
62
|
-
installationAdds: ["acme/new"],
|
|
63
|
-
installationRemoves: ["acme/old"],
|
|
64
|
-
configAdds: ["acme/new"],
|
|
65
|
-
configRemoves: ["acme/old"],
|
|
66
|
-
},
|
|
67
|
-
...over,
|
|
68
|
-
}) as GithubReconcilePlanView;
|
|
69
|
-
|
|
70
|
-
describe("Reconcile card — inert state", () => {
|
|
71
|
-
test("absent when no username is bound", () => {
|
|
72
|
-
const html = page(true, true, null);
|
|
73
|
-
expect(html).not.toContain("github-reconcile-card");
|
|
74
|
-
expect(html).not.toContain("Reconcile");
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test("absent when the apps are not configured", () => {
|
|
78
|
-
expect(page(true, false, "octo")).not.toContain("github-reconcile-card");
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test("absent for a non-admin", () => {
|
|
82
|
-
expect(page(false, true, "octo")).not.toContain("github-reconcile-card");
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test("the page no longer mounts it (replaced by the installation repos card, IRM-1.4)", () => {
|
|
86
|
-
expect(page(true, true, "octo")).not.toContain("github-reconcile-card");
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test("the card renderer still renders until it is retired (IRM-1.5)", () => {
|
|
90
|
-
const html = renderGithubReconcileCard("a1");
|
|
91
|
-
expect(html).toContain('id="github-reconcile-card"');
|
|
92
|
-
expect(html).toContain('id="github-reconcile-plan-btn"');
|
|
93
|
-
expect(html).toContain('name="addRepos"');
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test("card wires escaped plan and apply URLs and holds no key material", () => {
|
|
97
|
-
const html = renderGithubReconcileCard('a"b');
|
|
98
|
-
expect(html).toContain("/admin/agents/a"b/github-reconcile/plan");
|
|
99
|
-
expect(html).toContain("/admin/agents/a"b/github-reconcile/apply");
|
|
100
|
-
expect(html).not.toMatch(/BEGIN|token|private/i);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe("renderGithubReconcilePlanResult — plan state", () => {
|
|
105
|
-
test("renders the diff table, hash and a confirm gate", () => {
|
|
106
|
-
const html = renderGithubReconcilePlanResult(plan(), []);
|
|
107
|
-
expect(html).toContain("acme/new");
|
|
108
|
-
expect(html).toContain("acme/old");
|
|
109
|
-
expect(html).toContain('data-plan-hash="hash-1"');
|
|
110
|
-
expect(html).toContain('id="github-reconcile-confirm"');
|
|
111
|
-
expect(html).toMatch(/id="github-reconcile-apply-btn"[^>]*disabled/);
|
|
112
|
-
expect(html).not.toContain("github-reconcile-confirm-removals");
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
test("carries the named adds for apply", () => {
|
|
116
|
-
const html = renderGithubReconcilePlanResult(plan(), ["acme/x", "acme/y"]);
|
|
117
|
-
expect(html).toContain('data-add-repos="acme/x,acme/y"');
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
test("renders skip reasons, rejected adds, warnings and open work", () => {
|
|
121
|
-
const html = renderGithubReconcilePlanResult(
|
|
122
|
-
plan({
|
|
123
|
-
skippedOrgs: [{ org: "beta", reason: "lookup app not installed" }],
|
|
124
|
-
rejectedAdds: [{ repo: "zed/q", reason: "not accessible" }],
|
|
125
|
-
warnings: ["careful <b>now</b>"],
|
|
126
|
-
affectedOpenWork: [
|
|
127
|
-
{ id: "T-1", repo: "acme/old", title: "Fix <i>it</i>" },
|
|
128
|
-
],
|
|
129
|
-
}),
|
|
130
|
-
[],
|
|
131
|
-
);
|
|
132
|
-
expect(html).toContain("beta");
|
|
133
|
-
expect(html).toContain("lookup app not installed");
|
|
134
|
-
expect(html).toContain("zed/q");
|
|
135
|
-
expect(html).toContain("careful <b>now</b>");
|
|
136
|
-
expect(html).toContain("T-1");
|
|
137
|
-
expect(html).toContain("Fix <i>it</i>");
|
|
138
|
-
expect(html).not.toContain("<b>now</b>");
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test("empty plan has nothing to apply", () => {
|
|
142
|
-
const html = renderGithubReconcilePlanResult(
|
|
143
|
-
plan({
|
|
144
|
-
empty: true,
|
|
145
|
-
diff: {
|
|
146
|
-
installationAdds: [],
|
|
147
|
-
installationRemoves: [],
|
|
148
|
-
configAdds: [],
|
|
149
|
-
configRemoves: [],
|
|
150
|
-
},
|
|
151
|
-
}),
|
|
152
|
-
[],
|
|
153
|
-
);
|
|
154
|
-
expect(html).toContain("Nothing to change");
|
|
155
|
-
expect(html).not.toContain("github-reconcile-apply-btn");
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
test("skipped plan shows the reason and no apply", () => {
|
|
159
|
-
const html = renderGithubReconcilePlanResult(
|
|
160
|
-
{ status: "skipped", reason: "GitHub Apps are not configured" },
|
|
161
|
-
[],
|
|
162
|
-
);
|
|
163
|
-
expect(html).toContain("GitHub Apps are not configured");
|
|
164
|
-
expect(html).not.toContain("github-reconcile-apply-btn");
|
|
165
|
-
});
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
describe("renderGithubReconcilePlanResult — over-cap confirm", () => {
|
|
169
|
-
const many = Array.from({ length: 11 }, (_, i) => `acme/r${i}`);
|
|
170
|
-
const over = plan({
|
|
171
|
-
diff: {
|
|
172
|
-
installationAdds: [],
|
|
173
|
-
installationRemoves: many,
|
|
174
|
-
configAdds: [],
|
|
175
|
-
configRemoves: many,
|
|
176
|
-
},
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
test("more than 10 config removals requires a second confirmation", () => {
|
|
180
|
-
const html = renderGithubReconcilePlanResult(over, []);
|
|
181
|
-
expect(html).toContain('data-over-cap="true"');
|
|
182
|
-
expect(html).toContain('id="github-reconcile-confirm-removals"');
|
|
183
|
-
expect(html).toContain("11 repos");
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
test("exactly 10 removals does not", () => {
|
|
187
|
-
const ten = many.slice(0, 10);
|
|
188
|
-
const html = renderGithubReconcilePlanResult(
|
|
189
|
-
plan({
|
|
190
|
-
diff: {
|
|
191
|
-
installationAdds: [],
|
|
192
|
-
installationRemoves: ten,
|
|
193
|
-
configAdds: [],
|
|
194
|
-
configRemoves: ten,
|
|
195
|
-
},
|
|
196
|
-
}),
|
|
197
|
-
[],
|
|
198
|
-
);
|
|
199
|
-
expect(html).toContain('data-over-cap="false"');
|
|
200
|
-
expect(html).not.toContain("github-reconcile-confirm-removals");
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
describe("renderGithubReconcileApplyResult", () => {
|
|
205
|
-
test.each([
|
|
206
|
-
["applied", "alert-success"],
|
|
207
|
-
["noop", "alert-warning"],
|
|
208
|
-
["failed", "alert-error"],
|
|
209
|
-
["skipped", "alert-warning"],
|
|
210
|
-
] as const)("%s", (status, cls) => {
|
|
211
|
-
const html = renderGithubReconcileApplyResult({
|
|
212
|
-
status,
|
|
213
|
-
auditId: "aud-1",
|
|
214
|
-
reason: "r <x>",
|
|
215
|
-
error: "boom <x>",
|
|
216
|
-
});
|
|
217
|
-
expect(html).toContain(cls);
|
|
218
|
-
expect(html).not.toContain("<x>");
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
test("applied shows the audit id", () => {
|
|
222
|
-
expect(
|
|
223
|
-
renderGithubReconcileApplyResult({ status: "applied", auditId: "aud-1" }),
|
|
224
|
-
).toContain("aud-1");
|
|
225
|
-
});
|
|
226
|
-
});
|