@app-vitals/agent-admin 1.50.0 → 1.52.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/e2e/plugins-section.e2e.ts +14 -0
- package/e2e/settings-nav.e2e.ts +277 -0
- package/e2e/test-server.ts +83 -0
- package/package.json +2 -2
- package/src/admin-ui-account-nav.ts +3 -14
- package/src/admin-ui-account-nav.unit.test.ts +5 -14
- package/src/admin-ui-account-pages.ts +21 -10
- package/src/admin-ui-account-pages.unit.test.ts +12 -12
- package/src/admin-ui-account.smoke.test.ts +4 -0
- package/src/admin-ui-account.ts +5 -0
- package/src/admin-ui-accounts-pages.ts +36 -16
- package/src/admin-ui-accounts-pages.unit.test.ts +29 -0
- package/src/admin-ui-accounts.smoke.test.ts +2 -0
- package/src/admin-ui-accounts.ts +10 -1
- package/src/admin-ui-settings-layout.ts +25 -7
- package/src/admin-ui-settings-layout.unit.test.ts +1 -0
- package/src/admin-ui-settings.smoke.test.ts +28 -0
- package/src/admin-ui-styles.ts +7 -5
- package/src/admin-ui-styles.unit.test.ts +8 -0
- package/src/admin-ui.ts +27 -35
|
@@ -145,3 +145,17 @@ test("a malformed spec redirects with an error and adds nothing", async ({
|
|
|
145
145
|
await page.waitForURL(/\?error=/);
|
|
146
146
|
await expect(table(page).locator("tbody tr")).toHaveCount(before);
|
|
147
147
|
});
|
|
148
|
+
|
|
149
|
+
test("settings content grows with the viewport width", async ({
|
|
150
|
+
page,
|
|
151
|
+
context,
|
|
152
|
+
}) => {
|
|
153
|
+
const contentWidth = async () =>
|
|
154
|
+
(await page.locator(".settings-content").boundingBox())?.width ?? 0;
|
|
155
|
+
await page.setViewportSize({ width: 1200, height: 900 });
|
|
156
|
+
await loadAgentPage(page, context);
|
|
157
|
+
const narrow = await contentWidth();
|
|
158
|
+
await page.setViewportSize({ width: 1800, height: 900 });
|
|
159
|
+
const wide = await contentWidth();
|
|
160
|
+
expect(wide).toBeGreaterThan(narrow);
|
|
161
|
+
});
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/e2e/settings-nav.e2e.ts
|
|
3
|
+
* Admin UI — settings shell navigation E2E (SGL-2.4)
|
|
4
|
+
*
|
|
5
|
+
* Real browser journeys through the settings layout (sidebar + active pill):
|
|
6
|
+
* 1. Agent detail: click through General, Automation, Configuration, Access
|
|
7
|
+
* and Extensions; the URL and the aria-current pill follow each click.
|
|
8
|
+
* 2. One write action per section; each POST redirects back to the section
|
|
9
|
+
* that owns the form.
|
|
10
|
+
* 3. /admin/settings redirects to the first nav item; the Account and
|
|
11
|
+
* Platform items are reachable from the sidebar.
|
|
12
|
+
* 4. Mobile (375px): the sidebar collapses into a <details> disclosure.
|
|
13
|
+
*
|
|
14
|
+
* Spawns admin/e2e/test-server.ts with ADMIN_E2E_SETTINGS=1 (own port) and
|
|
15
|
+
* mints session cookies directly; no DB or OAuth.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { type ChildProcess, spawn } from "node:child_process";
|
|
19
|
+
import { dirname, resolve } from "node:path";
|
|
20
|
+
import { fileURLToPath } from "node:url";
|
|
21
|
+
import { type BrowserContext, expect, type Page, test } from "@playwright/test";
|
|
22
|
+
import { sign } from "hono/jwt";
|
|
23
|
+
|
|
24
|
+
const PORT = 3498;
|
|
25
|
+
const BASE_URL = `http://localhost:${PORT}`;
|
|
26
|
+
const SESSION_SECRET = "e2e-admin-test-secret-32chars!!!";
|
|
27
|
+
const SESSION_COOKIE = "admin_session";
|
|
28
|
+
const AGENT_ID = "agent-e2e-1";
|
|
29
|
+
const AGENT_BASE = `/admin/agents/${AGENT_ID}`;
|
|
30
|
+
|
|
31
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
32
|
+
|
|
33
|
+
let serverProcess: ChildProcess | null = null;
|
|
34
|
+
|
|
35
|
+
async function waitForServer(url: string, maxWaitMs: number): Promise<void> {
|
|
36
|
+
const start = Date.now();
|
|
37
|
+
while (Date.now() - start < maxWaitMs) {
|
|
38
|
+
try {
|
|
39
|
+
const res = await fetch(url);
|
|
40
|
+
if (res.status < 500) return;
|
|
41
|
+
} catch {
|
|
42
|
+
// Not ready yet
|
|
43
|
+
}
|
|
44
|
+
await new Promise((r) => setTimeout(r, 300));
|
|
45
|
+
}
|
|
46
|
+
throw new Error(`Server at ${url} did not start within ${maxWaitMs}ms`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
test.beforeAll(async () => {
|
|
50
|
+
serverProcess = spawn("bun", ["run", resolve(__dirname, "test-server.ts")], {
|
|
51
|
+
env: {
|
|
52
|
+
...process.env,
|
|
53
|
+
ADMIN_E2E_PORT: String(PORT),
|
|
54
|
+
ADMIN_E2E_SESSION_SECRET: SESSION_SECRET,
|
|
55
|
+
ADMIN_E2E_SETTINGS: "1",
|
|
56
|
+
},
|
|
57
|
+
stdio: "pipe",
|
|
58
|
+
cwd: resolve(__dirname, "../.."),
|
|
59
|
+
});
|
|
60
|
+
serverProcess.stderr?.on("data", (d: Buffer) => {
|
|
61
|
+
if (d.toString().trim())
|
|
62
|
+
console.error("[admin-e2e-settings-server]", d.toString().trim());
|
|
63
|
+
});
|
|
64
|
+
await waitForServer(`${BASE_URL}/health`, 15_000);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test.afterAll(() => {
|
|
68
|
+
serverProcess?.kill("SIGTERM");
|
|
69
|
+
serverProcess = null;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
async function signIn(context: BrowserContext): Promise<void> {
|
|
73
|
+
const nowSec = Math.floor(Date.now() / 1000);
|
|
74
|
+
const token = await sign(
|
|
75
|
+
{
|
|
76
|
+
userId: "google-sub-e2e",
|
|
77
|
+
email: "admin@example.com",
|
|
78
|
+
isAdmin: true,
|
|
79
|
+
iat: nowSec,
|
|
80
|
+
exp: nowSec + 3600,
|
|
81
|
+
},
|
|
82
|
+
SESSION_SECRET,
|
|
83
|
+
"HS256",
|
|
84
|
+
);
|
|
85
|
+
await context.addCookies([
|
|
86
|
+
{
|
|
87
|
+
name: SESSION_COOKIE,
|
|
88
|
+
value: token,
|
|
89
|
+
domain: "localhost",
|
|
90
|
+
path: "/",
|
|
91
|
+
httpOnly: true,
|
|
92
|
+
sameSite: "Lax",
|
|
93
|
+
},
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** The desktop sidebar's links (the mobile <details> duplicates them). */
|
|
98
|
+
const sidebar = (page: Page) => page.locator("nav.settings-sidebar");
|
|
99
|
+
const activePill = (page: Page) =>
|
|
100
|
+
sidebar(page).locator('a[aria-current="page"]');
|
|
101
|
+
|
|
102
|
+
const SECTIONS = [
|
|
103
|
+
{ label: "General", path: AGENT_BASE },
|
|
104
|
+
{ label: "Automation", path: `${AGENT_BASE}/automation` },
|
|
105
|
+
{ label: "Configuration", path: `${AGENT_BASE}/configuration` },
|
|
106
|
+
{ label: "Access", path: `${AGENT_BASE}/access` },
|
|
107
|
+
{ label: "Extensions", path: `${AGENT_BASE}/extensions` },
|
|
108
|
+
];
|
|
109
|
+
|
|
110
|
+
test.describe("agent detail sections", () => {
|
|
111
|
+
test("sidebar navigation moves the URL and the active pill through all five sections", async ({
|
|
112
|
+
page,
|
|
113
|
+
context,
|
|
114
|
+
}) => {
|
|
115
|
+
await signIn(context);
|
|
116
|
+
await page.goto(`${BASE_URL}${AGENT_BASE}`);
|
|
117
|
+
await expect(sidebar(page).locator("a.settings-nav-link")).toHaveText(
|
|
118
|
+
SECTIONS.map((s) => s.label),
|
|
119
|
+
);
|
|
120
|
+
await expect(activePill(page)).toHaveText("General");
|
|
121
|
+
|
|
122
|
+
for (const s of SECTIONS.slice(1)) {
|
|
123
|
+
await sidebar(page).getByRole("link", { name: s.label }).click();
|
|
124
|
+
await expect(page).toHaveURL(`${BASE_URL}${s.path}`);
|
|
125
|
+
await expect(activePill(page)).toHaveCount(1);
|
|
126
|
+
await expect(activePill(page)).toHaveText(s.label);
|
|
127
|
+
await expect(page.locator("h1")).toContainText("Test Agent");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// And back to General via the bare agent path.
|
|
131
|
+
await sidebar(page).getByRole("link", { name: "General" }).click();
|
|
132
|
+
await expect(page).toHaveURL(`${BASE_URL}${AGENT_BASE}`);
|
|
133
|
+
await expect(activePill(page)).toHaveText("General");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("a write action in each section lands back on that section", async ({
|
|
137
|
+
page,
|
|
138
|
+
context,
|
|
139
|
+
}) => {
|
|
140
|
+
await signIn(context);
|
|
141
|
+
|
|
142
|
+
// General: Sync Manifest with a malformed token redirects back with an error.
|
|
143
|
+
await page.goto(`${BASE_URL}${AGENT_BASE}`);
|
|
144
|
+
await page.locator("summary", { hasText: "Sync Manifest" }).click();
|
|
145
|
+
await page.locator('input[name="xoxpToken"]').fill("not-a-slack-token");
|
|
146
|
+
await page.getByRole("button", { name: "Confirm Sync" }).click();
|
|
147
|
+
await page.waitForURL(new RegExp(`${AGENT_BASE}\\?error=`));
|
|
148
|
+
await expect(activePill(page)).toHaveText("General");
|
|
149
|
+
|
|
150
|
+
// Automation: add a cron.
|
|
151
|
+
await sidebar(page).getByRole("link", { name: "Automation" }).click();
|
|
152
|
+
await page.locator('input[name="schedule"]').first().fill("5 4 * * *");
|
|
153
|
+
await page
|
|
154
|
+
.locator('form[action$="/crons"] input[name="prompt"]')
|
|
155
|
+
.fill("nightly check");
|
|
156
|
+
await page.getByRole("button", { name: "Add Cron" }).click();
|
|
157
|
+
await page.waitForURL(`${BASE_URL}${AGENT_BASE}/automation`);
|
|
158
|
+
await expect(activePill(page)).toHaveText("Automation");
|
|
159
|
+
|
|
160
|
+
// Configuration: set an env var.
|
|
161
|
+
await sidebar(page).getByRole("link", { name: "Configuration" }).click();
|
|
162
|
+
await page
|
|
163
|
+
.locator('form[action$="/envs"] input[name="key"]')
|
|
164
|
+
.fill("E2E_KEY");
|
|
165
|
+
await page
|
|
166
|
+
.locator('form[action$="/envs"] input[name="value"]')
|
|
167
|
+
.fill("e2e-value");
|
|
168
|
+
await page.locator('form[action$="/envs"] button[type="submit"]').click();
|
|
169
|
+
await page.waitForURL(`${BASE_URL}${AGENT_BASE}/configuration`);
|
|
170
|
+
await expect(activePill(page)).toHaveText("Configuration");
|
|
171
|
+
|
|
172
|
+
// Access: add a review-author allowlist entry.
|
|
173
|
+
await sidebar(page).getByRole("link", { name: "Access" }).click();
|
|
174
|
+
await page
|
|
175
|
+
.locator(
|
|
176
|
+
'form[action$="/review-author-allowlist/add"] input[name="login"]',
|
|
177
|
+
)
|
|
178
|
+
.fill("octocat");
|
|
179
|
+
await page
|
|
180
|
+
.locator('form[action$="/review-author-allowlist/add"] button')
|
|
181
|
+
.click();
|
|
182
|
+
await page.waitForURL(`${BASE_URL}${AGENT_BASE}/access`);
|
|
183
|
+
await expect(activePill(page)).toHaveText("Access");
|
|
184
|
+
|
|
185
|
+
// Extensions: add a plugin.
|
|
186
|
+
await sidebar(page).getByRole("link", { name: "Extensions" }).click();
|
|
187
|
+
await page
|
|
188
|
+
.locator("#add-plugin-form input[name='spec']")
|
|
189
|
+
.fill("nav-e2e@seeded-remote");
|
|
190
|
+
await page.locator("#add-plugin-form").getByRole("button").click();
|
|
191
|
+
await page.waitForURL(`${BASE_URL}${AGENT_BASE}/extensions`);
|
|
192
|
+
await expect(activePill(page)).toHaveText("Extensions");
|
|
193
|
+
await expect(page.locator("body")).toContainText("nav-e2e@seeded-remote");
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test.describe("/admin/settings", () => {
|
|
198
|
+
test("redirects to the first item and moves between Account and Platform items", async ({
|
|
199
|
+
page,
|
|
200
|
+
context,
|
|
201
|
+
}) => {
|
|
202
|
+
await signIn(context);
|
|
203
|
+
await page.goto(`${BASE_URL}/admin/settings`);
|
|
204
|
+
await expect(page).toHaveURL(`${BASE_URL}/admin/account`);
|
|
205
|
+
await expect(activePill(page)).toHaveText("Account");
|
|
206
|
+
await expect(page.locator("h1")).toHaveText("E2E Account");
|
|
207
|
+
|
|
208
|
+
const groups = sidebar(page).locator(".settings-nav-label");
|
|
209
|
+
await expect(groups).toHaveText(["Account", "Platform"]);
|
|
210
|
+
|
|
211
|
+
const items = [
|
|
212
|
+
{ label: "GitHub Enterprise", path: "/admin/settings/github-enterprise" },
|
|
213
|
+
{ label: "Templates", path: "/admin/settings/templates" },
|
|
214
|
+
{ label: "Accounts", path: "/admin/accounts" },
|
|
215
|
+
{ label: "Account", path: "/admin/account" },
|
|
216
|
+
];
|
|
217
|
+
for (const item of items) {
|
|
218
|
+
await sidebar(page)
|
|
219
|
+
.getByRole("link", { name: item.label, exact: true })
|
|
220
|
+
.click();
|
|
221
|
+
await expect(page).toHaveURL(`${BASE_URL}${item.path}`);
|
|
222
|
+
await expect(activePill(page)).toHaveCount(1);
|
|
223
|
+
await expect(activePill(page)).toHaveText(item.label);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test("mobile (375px): sidebar collapses into a disclosure that navigates", async ({
|
|
228
|
+
page,
|
|
229
|
+
context,
|
|
230
|
+
}) => {
|
|
231
|
+
await signIn(context);
|
|
232
|
+
await page.setViewportSize({ width: 375, height: 812 });
|
|
233
|
+
await page.goto(`${BASE_URL}/admin/account`);
|
|
234
|
+
|
|
235
|
+
const disclosure = page.locator("details.settings-nav-mobile");
|
|
236
|
+
await expect(sidebar(page)).toBeHidden();
|
|
237
|
+
await expect(disclosure).toBeVisible();
|
|
238
|
+
await expect(disclosure.locator("summary")).toHaveText("Account");
|
|
239
|
+
await expect(disclosure).not.toHaveAttribute("open", "");
|
|
240
|
+
await expect(
|
|
241
|
+
disclosure.getByRole("link", { name: "Templates" }),
|
|
242
|
+
).toBeHidden();
|
|
243
|
+
|
|
244
|
+
await disclosure.locator("summary").click();
|
|
245
|
+
await expect(disclosure).toHaveAttribute("open", "");
|
|
246
|
+
await expect(disclosure.locator('a[aria-current="page"]')).toHaveText(
|
|
247
|
+
"Account",
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
await disclosure.getByRole("link", { name: "Templates" }).click();
|
|
251
|
+
await expect(page).toHaveURL(`${BASE_URL}/admin/settings/templates`);
|
|
252
|
+
// The new page renders collapsed again, labelled with the active item.
|
|
253
|
+
await expect(
|
|
254
|
+
page.locator("details.settings-nav-mobile summary"),
|
|
255
|
+
).toHaveText("Templates");
|
|
256
|
+
await expect(
|
|
257
|
+
page.locator("details.settings-nav-mobile"),
|
|
258
|
+
).not.toHaveAttribute("open", "");
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test("mobile (375px): agent sections are reachable from the disclosure", async ({
|
|
262
|
+
page,
|
|
263
|
+
context,
|
|
264
|
+
}) => {
|
|
265
|
+
await signIn(context);
|
|
266
|
+
await page.setViewportSize({ width: 375, height: 812 });
|
|
267
|
+
await page.goto(`${BASE_URL}${AGENT_BASE}`);
|
|
268
|
+
const disclosure = page.locator("details.settings-nav-mobile");
|
|
269
|
+
await expect(disclosure.locator("summary")).toHaveText("General");
|
|
270
|
+
await disclosure.locator("summary").click();
|
|
271
|
+
await disclosure.getByRole("link", { name: "Access" }).click();
|
|
272
|
+
await expect(page).toHaveURL(`${BASE_URL}${AGENT_BASE}/access`);
|
|
273
|
+
await expect(
|
|
274
|
+
page.locator("details.settings-nav-mobile summary"),
|
|
275
|
+
).toHaveText("Access");
|
|
276
|
+
});
|
|
277
|
+
});
|
package/e2e/test-server.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* Usage:
|
|
10
10
|
* ADMIN_E2E_PORT=3490 bun run admin/e2e/test-server.ts
|
|
11
11
|
* ADMIN_E2E_AGENTS_MODE=1 ADMIN_E2E_PORT=3490 bun run admin/e2e/test-server.ts
|
|
12
|
+
* ADMIN_E2E_SETTINGS=1 ADMIN_E2E_PORT=3498 bun run admin/e2e/test-server.ts
|
|
12
13
|
*
|
|
13
14
|
* The server exposes:
|
|
14
15
|
* GET /health → 200 OK
|
|
@@ -241,6 +242,87 @@ function buildMockChatClient(): ChatClient {
|
|
|
241
242
|
// are exercising the real UI, not a silently-degraded fallback.
|
|
242
243
|
const CHAT_CLIENT_ABSENT = process.env.ADMIN_E2E_CHAT_CLIENT_ABSENT === "1";
|
|
243
244
|
|
|
245
|
+
// ─── Settings-shell fixtures (SGL-2.4) ───────────────────────────────────────
|
|
246
|
+
// When ADMIN_E2E_SETTINGS=1 the server wires the optional services that turn on
|
|
247
|
+
// the /admin/settings sidebar: GitHub Enterprise, Templates (Platform) and
|
|
248
|
+
// Account/Accounts (self-serve). Off by default so other suites are unchanged.
|
|
249
|
+
const SETTINGS_MODE = process.env.ADMIN_E2E_SETTINGS === "1";
|
|
250
|
+
|
|
251
|
+
const MOCK_ACCOUNT = {
|
|
252
|
+
id: "acct-e2e-1",
|
|
253
|
+
name: "E2E Account",
|
|
254
|
+
status: "active",
|
|
255
|
+
maxAgents: 5,
|
|
256
|
+
plan: null,
|
|
257
|
+
trialExpiresAt: null,
|
|
258
|
+
trialExpiryWarnedAt: null,
|
|
259
|
+
createdAt: new Date("2024-01-01"),
|
|
260
|
+
updatedAt: new Date("2024-01-01"),
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
function buildSettingsDeps(): Partial<AdminUIDeps> {
|
|
264
|
+
const members = [
|
|
265
|
+
{
|
|
266
|
+
id: "am-e2e-1",
|
|
267
|
+
accountId: MOCK_ACCOUNT.id,
|
|
268
|
+
email: "admin@example.com",
|
|
269
|
+
role: "owner",
|
|
270
|
+
createdAt: new Date("2024-01-01"),
|
|
271
|
+
},
|
|
272
|
+
];
|
|
273
|
+
const counts = { ...MOCK_ACCOUNT, agentCount: 1, memberCount: 1 };
|
|
274
|
+
return {
|
|
275
|
+
selfServe: {
|
|
276
|
+
enabled: true,
|
|
277
|
+
defaultMaxAgents: 5,
|
|
278
|
+
contactEmail: "contact@example.com",
|
|
279
|
+
},
|
|
280
|
+
templateService: {
|
|
281
|
+
list: async () => [],
|
|
282
|
+
replace: async () => {
|
|
283
|
+
throw new Error("not used in e2e tests");
|
|
284
|
+
},
|
|
285
|
+
putItem: async () => {
|
|
286
|
+
throw new Error("not used in e2e tests");
|
|
287
|
+
},
|
|
288
|
+
deleteItem: async () => {
|
|
289
|
+
throw new Error("not used in e2e tests");
|
|
290
|
+
},
|
|
291
|
+
delete: async () => {
|
|
292
|
+
throw new Error("not used in e2e tests");
|
|
293
|
+
},
|
|
294
|
+
} as unknown as AdminUIDeps["templateService"],
|
|
295
|
+
githubEnterpriseApi: async (path: string) =>
|
|
296
|
+
path === "/github-enterprise/apps"
|
|
297
|
+
? Response.json({ configured: false, installer: null, lookup: null })
|
|
298
|
+
: Response.json({}, { status: 404 }),
|
|
299
|
+
accountServices: {
|
|
300
|
+
accounts: {
|
|
301
|
+
getByMemberEmail: async () => MOCK_ACCOUNT,
|
|
302
|
+
update: async () => MOCK_ACCOUNT,
|
|
303
|
+
countAgents: async () => 1,
|
|
304
|
+
listWithCounts: async () => [counts],
|
|
305
|
+
getWithCounts: async () => counts,
|
|
306
|
+
listAgents: async () => [],
|
|
307
|
+
},
|
|
308
|
+
members: {
|
|
309
|
+
listByAccount: async () => members,
|
|
310
|
+
getByEmail: async () => members[0],
|
|
311
|
+
add: async () => members[0],
|
|
312
|
+
remove: async () => {},
|
|
313
|
+
promote: async () => {},
|
|
314
|
+
demote: async () => {},
|
|
315
|
+
},
|
|
316
|
+
invites: {
|
|
317
|
+
create: async () => ({}),
|
|
318
|
+
listPending: async () => [],
|
|
319
|
+
revoke: async () => {},
|
|
320
|
+
},
|
|
321
|
+
lifecycle: { update: async () => MOCK_ACCOUNT },
|
|
322
|
+
} as unknown as AdminUIDeps["accountServices"],
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
|
|
244
326
|
// ─── Mock deps factory ────────────────────────────────────────────────────────
|
|
245
327
|
|
|
246
328
|
function buildMockDeps(chatClient: ChatClient | undefined): AdminUIDeps {
|
|
@@ -485,6 +567,7 @@ function buildMockDeps(chatClient: ChatClient | undefined): AdminUIDeps {
|
|
|
485
567
|
},
|
|
486
568
|
appBaseUrl: `http://localhost:${ADMIN_E2E_PORT}`,
|
|
487
569
|
chatClient,
|
|
570
|
+
...(SETTINGS_MODE ? buildSettingsDeps() : {}),
|
|
488
571
|
};
|
|
489
572
|
}
|
|
490
573
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.52.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/app-vitals/agent.git",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@anthropic-ai/sdk": "0.135.0",
|
|
45
|
-
"@app-vitals/agent-lib": "1.
|
|
45
|
+
"@app-vitals/agent-lib": "1.52.0",
|
|
46
46
|
"@hono/zod-openapi": "^1.0.0",
|
|
47
47
|
"@prisma/adapter-pg": "^7.10.0",
|
|
48
48
|
"@prisma/client": "^7.10.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* admin/src/admin-ui-account-nav.ts
|
|
3
|
-
* Per-request "show the
|
|
3
|
+
* Per-request "show the Settings nav entry" flag. renderAdminToolbar()
|
|
4
4
|
* is called from dozens of page renderers; rather than thread a parameter
|
|
5
5
|
* through all of them, an admin-ui middleware wraps each /admin/* request in
|
|
6
6
|
* runWithAccountNav() and the toolbar reads the flag back. Outside any
|
|
@@ -10,26 +10,15 @@
|
|
|
10
10
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
11
11
|
|
|
12
12
|
interface NavFlags {
|
|
13
|
-
|
|
14
|
-
/** GHE-1.4: the admin-only "Settings" entry. */
|
|
13
|
+
/** The "Settings" entry (admins and account members). */
|
|
15
14
|
showSettings: boolean;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
const storage = new AsyncLocalStorage<NavFlags>();
|
|
19
18
|
|
|
20
|
-
export function runWithAccountNav<T>(showAccount: boolean, fn: () => T): T {
|
|
21
|
-
const showSettings = storage.getStore()?.showSettings === true;
|
|
22
|
-
return storage.run({ showAccount, showSettings }, fn);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function shouldShowAccountNav(): boolean {
|
|
26
|
-
return storage.getStore()?.showAccount === true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
19
|
/** Wrap a request so the toolbar shows (or hides) the admin Settings entry. */
|
|
30
20
|
export function runWithSettingsNav<T>(showSettings: boolean, fn: () => T): T {
|
|
31
|
-
|
|
32
|
-
return storage.run({ showAccount, showSettings }, fn);
|
|
21
|
+
return storage.run({ showSettings }, fn);
|
|
33
22
|
}
|
|
34
23
|
|
|
35
24
|
export function shouldShowSettingsNav(): boolean {
|
|
@@ -1,31 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* admin/src/admin-ui-account-nav.unit.test.ts
|
|
3
|
-
* Flag plumbing for the toolbar
|
|
3
|
+
* Flag plumbing for the toolbar Settings entry.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { describe, expect, test } from "bun:test";
|
|
7
7
|
import {
|
|
8
|
-
runWithAccountNav,
|
|
9
8
|
runWithSettingsNav,
|
|
10
|
-
shouldShowAccountNav,
|
|
11
9
|
shouldShowSettingsNav,
|
|
12
10
|
} from "./admin-ui-account-nav.ts";
|
|
13
11
|
|
|
14
|
-
describe("
|
|
15
|
-
test("
|
|
16
|
-
expect(shouldShowAccountNav()).toBe(false);
|
|
12
|
+
describe("settings-nav flag", () => {
|
|
13
|
+
test("hidden outside any context", () => {
|
|
17
14
|
expect(shouldShowSettingsNav()).toBe(false);
|
|
18
15
|
});
|
|
19
|
-
test("
|
|
16
|
+
test("reflects the wrapper value, including nested", () => {
|
|
20
17
|
runWithSettingsNav(true, () => {
|
|
21
|
-
|
|
22
|
-
expect(shouldShowSettingsNav()).toBe(true);
|
|
23
|
-
expect(shouldShowAccountNav()).toBe(false);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
runWithAccountNav(true, () => {
|
|
18
|
+
expect(shouldShowSettingsNav()).toBe(true);
|
|
27
19
|
runWithSettingsNav(false, () => {
|
|
28
|
-
expect(shouldShowAccountNav()).toBe(true);
|
|
29
20
|
expect(shouldShowSettingsNav()).toBe(false);
|
|
30
21
|
});
|
|
31
22
|
});
|
|
@@ -8,7 +8,12 @@ import type { AccountInvite } from "./account-invites.ts";
|
|
|
8
8
|
import type { AccountMember } from "./account-members.ts";
|
|
9
9
|
import type { Account } from "./accounts.ts";
|
|
10
10
|
import { renderAdminPage } from "./admin-ui-layout.ts";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
buildSettingsNav,
|
|
13
|
+
renderSettingsLayout,
|
|
14
|
+
type SettingsNav,
|
|
15
|
+
} from "./admin-ui-settings-layout.ts";
|
|
16
|
+
import { escapeHtml } from "./admin-ui-styles.ts";
|
|
12
17
|
|
|
13
18
|
export const ACCOUNT_PATH = "/admin/account";
|
|
14
19
|
|
|
@@ -21,6 +26,10 @@ interface AccountPageOpts {
|
|
|
21
26
|
/** True when the viewer is an owner; members get a read-only page. */
|
|
22
27
|
isOwner: boolean;
|
|
23
28
|
error?: string;
|
|
29
|
+
/** Settings sidebar nav; defaults to the base Account/Accounts nav. */
|
|
30
|
+
nav?: SettingsNav;
|
|
31
|
+
/** Platform admin viewing (shows adminOnly nav items). */
|
|
32
|
+
isAdmin?: boolean;
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
function emailForm(
|
|
@@ -88,13 +97,15 @@ export function renderAccountPage(opts: AccountPageOpts): string {
|
|
|
88
97
|
: "";
|
|
89
98
|
|
|
90
99
|
return renderAdminPage({
|
|
91
|
-
title: "Account — Shipwright Admin",
|
|
92
|
-
body:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
100
|
+
title: "Account — Settings — Shipwright Admin",
|
|
101
|
+
body: renderSettingsLayout({
|
|
102
|
+
userName: opts.userEmail,
|
|
103
|
+
title: account.name,
|
|
104
|
+
nav: opts.nav ?? buildSettingsNav({ accounts: true }),
|
|
105
|
+
active: ACCOUNT_PATH,
|
|
106
|
+
toolbarPath: "/admin/settings",
|
|
107
|
+
isAdmin: opts.isAdmin ?? false,
|
|
108
|
+
body: `${errorHtml}
|
|
98
109
|
<div class="card">
|
|
99
110
|
<div class="card-title">Account</div>
|
|
100
111
|
<p>Agents: <strong>${opts.agentCount} / ${account.maxAgents}</strong></p>
|
|
@@ -118,8 +129,8 @@ export function renderAccountPage(opts: AccountPageOpts): string {
|
|
|
118
129
|
</table>
|
|
119
130
|
</div>
|
|
120
131
|
${inviteForm}
|
|
121
|
-
</div
|
|
122
|
-
|
|
132
|
+
</div>`,
|
|
133
|
+
}),
|
|
123
134
|
});
|
|
124
135
|
}
|
|
125
136
|
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
renderZeroQuotaNotice,
|
|
10
10
|
} from "./admin-ui-account-pages.ts";
|
|
11
11
|
import { renderAdminToolbar } from "./admin-ui-styles.ts";
|
|
12
|
-
import { runWithAccountNav } from "./admin-ui-account-nav.ts";
|
|
13
12
|
|
|
14
13
|
const d = new Date("2026-01-01T00:00:00Z");
|
|
15
14
|
const account = {
|
|
@@ -92,21 +91,22 @@ describe("renderZeroQuotaNotice", () => {
|
|
|
92
91
|
});
|
|
93
92
|
|
|
94
93
|
describe("renderAdminToolbar account nav", () => {
|
|
95
|
-
test("no Account entry
|
|
94
|
+
test("no top-level Account entry (Settings covers it, SGL-2.3)", () => {
|
|
96
95
|
expect(renderAdminToolbar("u", "/admin/agents")).not.toContain(
|
|
97
|
-
"/admin/account",
|
|
96
|
+
'href="/admin/account"',
|
|
98
97
|
);
|
|
99
98
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("renderAccountPage in the settings shell", () => {
|
|
102
|
+
test("renders inside the layout with Account active and Settings in the toolbar", () => {
|
|
103
|
+
const html = render(true);
|
|
104
|
+
expect(html).toContain("settings-sidebar");
|
|
105
|
+
expect(html).toContain(
|
|
106
|
+
'<a class="settings-nav-link" href="/admin/account" aria-current="page">Account</a>',
|
|
103
107
|
);
|
|
104
|
-
expect(html).toContain('href="/admin/account"');
|
|
105
108
|
});
|
|
106
|
-
test("
|
|
107
|
-
|
|
108
|
-
renderAdminToolbar("u", "/admin/agents"),
|
|
109
|
-
);
|
|
110
|
-
expect(html).not.toContain("/admin/account");
|
|
109
|
+
test("Accounts nav item only for admins", () => {
|
|
110
|
+
expect(render(true)).not.toContain('href="/admin/accounts"');
|
|
111
111
|
});
|
|
112
112
|
});
|
|
@@ -178,6 +178,10 @@ describe("/admin/account", () => {
|
|
|
178
178
|
const body = await res.text();
|
|
179
179
|
expect(body).toContain("Acme");
|
|
180
180
|
expect(body).toContain("1 / 2");
|
|
181
|
+
// SGL-2.3: rendered inside the settings shell; no top-level Account link.
|
|
182
|
+
expect(body).toContain("settings-sidebar");
|
|
183
|
+
expect(body).toContain('href="/admin/account" aria-current="page"');
|
|
184
|
+
expect(body).not.toContain('class="vos-nav-link" href="/admin/account"');
|
|
181
185
|
});
|
|
182
186
|
|
|
183
187
|
it("owner can invite, see it pending, and revoke it", async () => {
|
package/src/admin-ui-account.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { normalizeEmail } from "./account-email.ts";
|
|
|
19
19
|
import type { Account, AccountService } from "./accounts.ts";
|
|
20
20
|
import { ACCOUNT_PATH, renderAccountPage } from "./admin-ui-account-pages.ts";
|
|
21
21
|
import type { AdminUIEnv } from "./admin-ui.ts";
|
|
22
|
+
import type { SettingsNav } from "./admin-ui-settings-layout.ts";
|
|
22
23
|
|
|
23
24
|
export interface AccountRouteDeps {
|
|
24
25
|
/** SHIPWRIGHT_SELF_SERVE_ENABLED === "enabled". */
|
|
@@ -30,6 +31,8 @@ export interface AccountRouteDeps {
|
|
|
30
31
|
"listByAccount" | "getByEmail" | "remove" | "promote" | "demote"
|
|
31
32
|
>;
|
|
32
33
|
invites: Pick<AccountInviteService, "create" | "listPending" | "revoke">;
|
|
34
|
+
/** Settings sidebar nav (SGL-2.3). */
|
|
35
|
+
settingsNav?: SettingsNav;
|
|
33
36
|
html: (content: string, opts?: { status?: number }) => Response;
|
|
34
37
|
}
|
|
35
38
|
|
|
@@ -71,6 +74,8 @@ export function registerAccountRoutes(
|
|
|
71
74
|
invites,
|
|
72
75
|
isOwner,
|
|
73
76
|
error,
|
|
77
|
+
isAdmin: c.var.isAdmin === true,
|
|
78
|
+
...(deps.settingsNav ? { nav: deps.settingsNav } : {}),
|
|
74
79
|
}),
|
|
75
80
|
{ status },
|
|
76
81
|
);
|
|
@@ -8,7 +8,12 @@ import type { AccountInvite } from "./account-invites.ts";
|
|
|
8
8
|
import type { AccountMember } from "./account-members.ts";
|
|
9
9
|
import type { AccountWithCounts } from "./accounts.ts";
|
|
10
10
|
import { renderAdminPage } from "./admin-ui-layout.ts";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
buildSettingsNav,
|
|
13
|
+
renderSettingsLayout,
|
|
14
|
+
type SettingsNav,
|
|
15
|
+
} from "./admin-ui-settings-layout.ts";
|
|
16
|
+
import { escapeHtml } from "./admin-ui-styles.ts";
|
|
12
17
|
|
|
13
18
|
export const ADMIN_ACCOUNTS_PATH = "/admin/accounts";
|
|
14
19
|
|
|
@@ -36,6 +41,8 @@ interface AccountsListPageOpts {
|
|
|
36
41
|
accounts: AccountWithCounts[];
|
|
37
42
|
/** accountId -> owner emails. */
|
|
38
43
|
owners: Map<string, string[]>;
|
|
44
|
+
/** Settings sidebar nav; defaults to the base Account/Accounts nav. */
|
|
45
|
+
nav?: SettingsNav;
|
|
39
46
|
}
|
|
40
47
|
|
|
41
48
|
export function renderAccountsListPage(opts: AccountsListPageOpts): string {
|
|
@@ -60,16 +67,20 @@ export function renderAccountsListPage(opts: AccountsListPageOpts): string {
|
|
|
60
67
|
|
|
61
68
|
return renderAdminPage({
|
|
62
69
|
title: "Accounts — Shipwright Admin",
|
|
63
|
-
body:
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
body: renderSettingsLayout({
|
|
71
|
+
userName: opts.userEmail,
|
|
72
|
+
title: "Accounts",
|
|
73
|
+
nav: opts.nav ?? buildSettingsNav({ accounts: true }),
|
|
74
|
+
active: ADMIN_ACCOUNTS_PATH,
|
|
75
|
+
toolbarPath: "/admin/settings",
|
|
76
|
+
isAdmin: true,
|
|
77
|
+
body: `<div class="card">
|
|
67
78
|
<table class="data-table">
|
|
68
79
|
<thead><tr><th>Name</th><th>Owner</th><th>Members</th><th>Agents</th><th>Status</th><th>Trial expires</th><th>Created</th><th></th></tr></thead>
|
|
69
80
|
<tbody>${rows}</tbody>
|
|
70
81
|
</table>
|
|
71
|
-
</div
|
|
72
|
-
|
|
82
|
+
</div>`,
|
|
83
|
+
}),
|
|
73
84
|
});
|
|
74
85
|
}
|
|
75
86
|
|
|
@@ -80,6 +91,8 @@ interface AccountDetailPageOpts {
|
|
|
80
91
|
members: AccountMember[];
|
|
81
92
|
invites: AccountInvite[];
|
|
82
93
|
error?: string;
|
|
94
|
+
/** Settings sidebar nav; defaults to the base Account/Accounts nav. */
|
|
95
|
+
nav?: SettingsNav;
|
|
83
96
|
}
|
|
84
97
|
|
|
85
98
|
function postForm(
|
|
@@ -110,8 +123,12 @@ export function renderAccountDetailPage(opts: AccountDetailPageOpts): string {
|
|
|
110
123
|
|
|
111
124
|
const statusAction =
|
|
112
125
|
account.status === "active"
|
|
113
|
-
?
|
|
114
|
-
|
|
126
|
+
? `<div class="settings-danger-zone">
|
|
127
|
+
<div class="settings-section-title">Danger zone</div>
|
|
128
|
+
<p class="help-text">Suspending locks down this account's crons until it is reactivated.</p>
|
|
129
|
+
${postForm(id, "suspend", {}, "Suspend", true)}
|
|
130
|
+
</div>`
|
|
131
|
+
: `<div class="card">${postForm(id, "reactivate", {}, "Reactivate")}</div>`;
|
|
115
132
|
|
|
116
133
|
const memberRows = opts.members
|
|
117
134
|
.map(
|
|
@@ -150,12 +167,14 @@ export function renderAccountDetailPage(opts: AccountDetailPageOpts): string {
|
|
|
150
167
|
|
|
151
168
|
return renderAdminPage({
|
|
152
169
|
title: `${account.name} — Accounts — Shipwright Admin`,
|
|
153
|
-
body:
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
170
|
+
body: renderSettingsLayout({
|
|
171
|
+
userName: opts.userEmail,
|
|
172
|
+
title: account.name,
|
|
173
|
+
nav: opts.nav ?? buildSettingsNav({ accounts: true }),
|
|
174
|
+
active: ADMIN_ACCOUNTS_PATH,
|
|
175
|
+
toolbarPath: "/admin/settings",
|
|
176
|
+
isAdmin: true,
|
|
177
|
+
body: `<p>${statusBadge(account.status)}</p>
|
|
159
178
|
<p><a href="${ADMIN_ACCOUNTS_PATH}">← All accounts</a></p>
|
|
160
179
|
${errorHtml}
|
|
161
180
|
<div class="card">
|
|
@@ -197,6 +216,7 @@ export function renderAccountDetailPage(opts: AccountDetailPageOpts): string {
|
|
|
197
216
|
<tbody>${inviteRows}</tbody>
|
|
198
217
|
</table>
|
|
199
218
|
</div>
|
|
200
|
-
|
|
219
|
+
${statusAction}`,
|
|
220
|
+
}),
|
|
201
221
|
});
|
|
202
222
|
}
|
|
@@ -136,3 +136,32 @@ describe("renderAgentsPage Account column", () => {
|
|
|
136
136
|
expect(html).not.toContain("<th>Account</th>");
|
|
137
137
|
});
|
|
138
138
|
});
|
|
139
|
+
|
|
140
|
+
describe("accounts pages in the settings shell (SGL-2.3)", () => {
|
|
141
|
+
test("list page renders in the layout with Accounts active", () => {
|
|
142
|
+
const html = renderAccountsListPage({
|
|
143
|
+
userEmail: "a@x.com",
|
|
144
|
+
accounts: [],
|
|
145
|
+
owners: new Map(),
|
|
146
|
+
});
|
|
147
|
+
expect(html).toContain("settings-sidebar");
|
|
148
|
+
expect(html).toContain(
|
|
149
|
+
'<a class="settings-nav-link" href="/admin/accounts" aria-current="page">Accounts</a>',
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("detail page puts Suspend in the shared danger box", () => {
|
|
154
|
+
const html = renderAccountDetailPage({
|
|
155
|
+
userEmail: "a@x.com",
|
|
156
|
+
account,
|
|
157
|
+
agents: [],
|
|
158
|
+
members: [],
|
|
159
|
+
invites: [],
|
|
160
|
+
});
|
|
161
|
+
expect(html).toContain("settings-danger-zone");
|
|
162
|
+
expect(html).toContain("/admin/accounts/a1/suspend");
|
|
163
|
+
expect(html).toContain(
|
|
164
|
+
'<a class="settings-nav-link" href="/admin/accounts" aria-current="page">Accounts</a>',
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -250,6 +250,8 @@ describe("/admin/accounts", () => {
|
|
|
250
250
|
const body = await res.text();
|
|
251
251
|
expect(body).toContain("Acme");
|
|
252
252
|
expect(body).toContain("owner@x.com");
|
|
253
|
+
expect(body).toContain("settings-sidebar");
|
|
254
|
+
expect(body).toContain('href="/admin/accounts" aria-current="page"');
|
|
253
255
|
});
|
|
254
256
|
|
|
255
257
|
it("403 for non-admin on every route", async () => {
|
package/src/admin-ui-accounts.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
renderAccountDetailPage,
|
|
24
24
|
renderAccountsListPage,
|
|
25
25
|
} from "./admin-ui-accounts-pages.ts";
|
|
26
|
+
import type { SettingsNav } from "./admin-ui-settings-layout.ts";
|
|
26
27
|
import { reconcileAgentAfterAccountChange } from "./agent-account-assignment.ts";
|
|
27
28
|
import type { AgentProvisioner } from "./agent-provisioner.ts";
|
|
28
29
|
import type { AgentService } from "./agents.ts";
|
|
@@ -46,6 +47,8 @@ export interface AdminAccountsRouteDeps {
|
|
|
46
47
|
/** SSP-5.3: assign/unassign agents (admin only). */
|
|
47
48
|
agents: Pick<AgentService, "getDetail" | "updateFields">;
|
|
48
49
|
provisioner: Pick<AgentProvisioner, "reconcile">;
|
|
50
|
+
/** Settings sidebar nav (SGL-2.3). */
|
|
51
|
+
settingsNav?: SettingsNav;
|
|
49
52
|
html: (content: string, opts?: { status?: number }) => Response;
|
|
50
53
|
}
|
|
51
54
|
|
|
@@ -82,7 +85,12 @@ export function registerAdminAccountsRoutes(
|
|
|
82
85
|
}),
|
|
83
86
|
);
|
|
84
87
|
return deps.html(
|
|
85
|
-
renderAccountsListPage({
|
|
88
|
+
renderAccountsListPage({
|
|
89
|
+
userEmail: c.var.userEmail,
|
|
90
|
+
accounts,
|
|
91
|
+
owners,
|
|
92
|
+
...(deps.settingsNav ? { nav: deps.settingsNav } : {}),
|
|
93
|
+
}),
|
|
86
94
|
);
|
|
87
95
|
});
|
|
88
96
|
|
|
@@ -107,6 +115,7 @@ export function registerAdminAccountsRoutes(
|
|
|
107
115
|
members,
|
|
108
116
|
invites,
|
|
109
117
|
error,
|
|
118
|
+
...(deps.settingsNav ? { nav: deps.settingsNav } : {}),
|
|
110
119
|
}),
|
|
111
120
|
{ status },
|
|
112
121
|
);
|
|
@@ -65,7 +65,7 @@ export function renderSettingsLayout(
|
|
|
65
65
|
?.label ?? opts.title;
|
|
66
66
|
|
|
67
67
|
return `${renderAdminToolbar(opts.userName, opts.toolbarPath ?? opts.active)}
|
|
68
|
-
<div class="vos-page">
|
|
68
|
+
<div class="vos-page vos-page-wide vos-page-settings">
|
|
69
69
|
<div class="settings-layout">
|
|
70
70
|
<nav class="settings-sidebar" aria-label="Settings">${sectionsHtml}</nav>
|
|
71
71
|
<details class="settings-nav-mobile"><summary>${escapeHtml(activeLabel)}</summary>${sectionsHtml}</details>
|
|
@@ -101,11 +101,15 @@ export function mergeSettingsNavItems(
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
export const SETTINGS_GHE_PATH = "/admin/settings/github-enterprise";
|
|
104
|
+
export const SETTINGS_ACCOUNT_PATH = "/admin/account";
|
|
105
|
+
export const SETTINGS_ACCOUNTS_PATH = "/admin/accounts";
|
|
104
106
|
export const SETTINGS_TEMPLATES_PATH = "/admin/settings/templates";
|
|
105
107
|
|
|
106
108
|
export interface BuildSettingsNavOptions {
|
|
107
109
|
/** Include the GitHub Enterprise item (its routes are registered). */
|
|
108
110
|
githubEnterprise?: boolean;
|
|
111
|
+
/** Include Account (members) and, admin-only, Accounts (SGL-2.3). */
|
|
112
|
+
accounts?: boolean;
|
|
109
113
|
/** Include the Templates item (its routes are registered). */
|
|
110
114
|
templates?: boolean;
|
|
111
115
|
/** Extension-contributed items (SGL-2.1). */
|
|
@@ -113,8 +117,9 @@ export interface BuildSettingsNavOptions {
|
|
|
113
117
|
}
|
|
114
118
|
|
|
115
119
|
/**
|
|
116
|
-
* Base settings nav (SGL-2.
|
|
117
|
-
*
|
|
120
|
+
* Base settings nav: Account section (SGL-2.3), Platform section (GitHub
|
|
121
|
+
* Enterprise, Templates, admin-only Accounts) plus extension items. Empty
|
|
122
|
+
* sections are dropped.
|
|
118
123
|
*/
|
|
119
124
|
export function buildSettingsNav(
|
|
120
125
|
opts: BuildSettingsNavOptions = {},
|
|
@@ -130,10 +135,23 @@ export function buildSettingsNav(
|
|
|
130
135
|
if (opts.templates) {
|
|
131
136
|
platform.push({ label: "Templates", path: SETTINGS_TEMPLATES_PATH });
|
|
132
137
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
138
|
+
if (opts.accounts) {
|
|
139
|
+
platform.push({
|
|
140
|
+
label: "Accounts",
|
|
141
|
+
path: SETTINGS_ACCOUNTS_PATH,
|
|
142
|
+
adminOnly: true,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const sections: SettingsNavSection[] = [];
|
|
146
|
+
if (opts.accounts) {
|
|
147
|
+
sections.push({
|
|
148
|
+
label: "Account",
|
|
149
|
+
items: [{ label: "Account", path: SETTINGS_ACCOUNT_PATH }],
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
if (platform.length > 0)
|
|
153
|
+
sections.push({ label: "Platform", items: platform });
|
|
154
|
+
const base: SettingsNav = { sections };
|
|
137
155
|
return mergeSettingsNavItems(base, [...(opts.extraItems ?? [])]);
|
|
138
156
|
}
|
|
139
157
|
|
|
@@ -60,6 +60,7 @@ describe("renderSettingsLayout", () => {
|
|
|
60
60
|
expect(html).toContain("Profile</h1>");
|
|
61
61
|
expect(html).toContain("<p>BODY</p>");
|
|
62
62
|
expect(html).toContain('class="vos-page');
|
|
63
|
+
expect(html).toContain('class="vos-page vos-page-wide vos-page-settings"');
|
|
63
64
|
expect(html).toContain("vos-toolbar");
|
|
64
65
|
});
|
|
65
66
|
|
|
@@ -191,3 +191,31 @@ describe("toolbar Settings entry", () => {
|
|
|
191
191
|
);
|
|
192
192
|
});
|
|
193
193
|
});
|
|
194
|
+
|
|
195
|
+
describe("GET /admin/settings with accounts (SGL-2.3)", () => {
|
|
196
|
+
const selfServe = { enabled: true, contactEmail: "c@x.com" };
|
|
197
|
+
const build = (member: string | null) =>
|
|
198
|
+
createAdminUIApp(
|
|
199
|
+
makeMockDeps({
|
|
200
|
+
templateService,
|
|
201
|
+
selfServe,
|
|
202
|
+
accountServices: memberAccounts(member),
|
|
203
|
+
} as never),
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
it("lands an account member on Account", async () => {
|
|
207
|
+
const res = await build("m@acme.com").request("/admin/settings", {
|
|
208
|
+
headers: { cookie: await userCookie("m@acme.com") },
|
|
209
|
+
});
|
|
210
|
+
expect(res.status).toBe(302);
|
|
211
|
+
expect(res.headers.get("location")).toBe("/admin/account");
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("skips Account for an admin without an account", async () => {
|
|
215
|
+
const res = await build(null).request("/admin/settings", {
|
|
216
|
+
headers: { cookie: await adminCookie() },
|
|
217
|
+
});
|
|
218
|
+
expect(res.status).toBe(302);
|
|
219
|
+
expect(res.headers.get("location")).toBe("/admin/settings/templates");
|
|
220
|
+
});
|
|
221
|
+
});
|
package/src/admin-ui-styles.ts
CHANGED
|
@@ -3,10 +3,7 @@ import {
|
|
|
3
3
|
renderShipwrightToolbar,
|
|
4
4
|
baseStyles as toolbarBaseStyles,
|
|
5
5
|
} from "@app-vitals/agent-lib/web/toolbar.ts";
|
|
6
|
-
import {
|
|
7
|
-
shouldShowAccountNav,
|
|
8
|
-
shouldShowSettingsNav,
|
|
9
|
-
} from "./admin-ui-account-nav.ts";
|
|
6
|
+
import { shouldShowSettingsNav } from "./admin-ui-account-nav.ts";
|
|
10
7
|
|
|
11
8
|
export { escapeHtml };
|
|
12
9
|
|
|
@@ -618,6 +615,12 @@ export function baseStyles(): string {
|
|
|
618
615
|
font-weight: 600;
|
|
619
616
|
}
|
|
620
617
|
.settings-content { flex: 1 1 auto; min-width: 0; }
|
|
618
|
+
.settings-content .form-input,
|
|
619
|
+
.settings-content input[type="text"],
|
|
620
|
+
.settings-content input[type="email"],
|
|
621
|
+
.settings-content input[type="password"],
|
|
622
|
+
.settings-content input[type="number"],
|
|
623
|
+
.settings-content input[type="search"] { max-width: 640px; }
|
|
621
624
|
.settings-content h1 {
|
|
622
625
|
font-size: 24px;
|
|
623
626
|
font-weight: 600;
|
|
@@ -686,7 +689,6 @@ export function renderAdminToolbar(userName: string, activePath = ""): string {
|
|
|
686
689
|
activePath,
|
|
687
690
|
logoutAction: "/admin/logout",
|
|
688
691
|
metricsUrl: process.env.METRICS_DASHBOARD_URL ?? "/dashboard",
|
|
689
|
-
showAccount: shouldShowAccountNav(),
|
|
690
692
|
showSettings: shouldShowSettingsNav(),
|
|
691
693
|
});
|
|
692
694
|
}
|
|
@@ -122,6 +122,14 @@ describe("baseStyles — SGL-1.1 settings layout", () => {
|
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
124
|
|
|
125
|
+
test("full-width modifier and input cap", () => {
|
|
126
|
+
expect(css).toMatch(
|
|
127
|
+
/\.vos-page-wide\s*{\s*max-width:\s*none;\s*width:\s*100%;/,
|
|
128
|
+
);
|
|
129
|
+
expect(block).toMatch(/\.settings-content \.form-input[^}]*max-width: 640px/);
|
|
130
|
+
expect(block).toContain('.settings-content input[type="search"]');
|
|
131
|
+
});
|
|
132
|
+
|
|
125
133
|
test("mobile media block references the settings classes", () => {
|
|
126
134
|
const media = block.slice(
|
|
127
135
|
block.indexOf(`@media (max-width: ${BREAKPOINT_MOBILE_MAX}px)`),
|
package/src/admin-ui.ts
CHANGED
|
@@ -46,15 +46,13 @@ import {
|
|
|
46
46
|
renderAgentDetailCardSlots,
|
|
47
47
|
} from "./admin-extension.ts";
|
|
48
48
|
import { registerAccountRoutes } from "./admin-ui-account.ts";
|
|
49
|
-
import {
|
|
50
|
-
runWithAccountNav,
|
|
51
|
-
runWithSettingsNav,
|
|
52
|
-
} from "./admin-ui-account-nav.ts";
|
|
49
|
+
import { runWithSettingsNav } from "./admin-ui-account-nav.ts";
|
|
53
50
|
import { renderZeroQuotaNotice } from "./admin-ui-account-pages.ts";
|
|
54
51
|
import { registerAdminAccountsRoutes } from "./admin-ui-accounts.ts";
|
|
55
52
|
import {
|
|
56
53
|
buildSettingsNav,
|
|
57
54
|
firstVisibleSettingsItem,
|
|
55
|
+
SETTINGS_ACCOUNT_PATH,
|
|
58
56
|
} from "./admin-ui-settings-layout.ts";
|
|
59
57
|
import { registerAdminGithubEnterpriseRoutes } from "./admin-ui-github-enterprise.ts";
|
|
60
58
|
import { registerAdminTemplatesRoutes } from "./admin-ui-templates.ts";
|
|
@@ -949,10 +947,11 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
949
947
|
devAuthEnabled,
|
|
950
948
|
});
|
|
951
949
|
|
|
952
|
-
|
|
953
|
-
|
|
950
|
+
const accountNavEnabled = Boolean(selfServe?.enabled && accountServices);
|
|
951
|
+
|
|
952
|
+
// GHE-1.4: the admin-only "Settings" toolbar entry.
|
|
954
953
|
// SGL-2.2: shown to admins and to account members.
|
|
955
|
-
if (githubEnterpriseApi || templateService) {
|
|
954
|
+
if (githubEnterpriseApi || templateService || accountNavEnabled) {
|
|
956
955
|
app.use("/admin/*", async (c, next) => {
|
|
957
956
|
const token = getCookie(c, SESSION_COOKIE);
|
|
958
957
|
const user = token ? await getSessionUser(token, sessionSecret) : null;
|
|
@@ -970,28 +969,6 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
970
969
|
});
|
|
971
970
|
}
|
|
972
971
|
|
|
973
|
-
// SSP-3.2: show the toolbar's "Account" entry only for signed-in users who
|
|
974
|
-
// belong to an account, and only while self-serve is on. The flag is carried
|
|
975
|
-
// in AsyncLocalStorage so renderAdminToolbar() needs no extra parameter.
|
|
976
|
-
const accountNavEnabled = Boolean(selfServe?.enabled && accountServices);
|
|
977
|
-
if (accountNavEnabled && accountServices) {
|
|
978
|
-
app.use("/admin/*", async (c, next) => {
|
|
979
|
-
const token = getCookie(c, SESSION_COOKIE);
|
|
980
|
-
const user = token ? await getSessionUser(token, sessionSecret) : null;
|
|
981
|
-
let showAccount = false;
|
|
982
|
-
if (user) {
|
|
983
|
-
try {
|
|
984
|
-
showAccount =
|
|
985
|
-
(await accountServices.accounts.getByMemberEmail(user.email)) !==
|
|
986
|
-
null;
|
|
987
|
-
} catch {
|
|
988
|
-
// nav is cosmetic — never fail the page over the lookup
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
return runWithAccountNav(showAccount, () => next());
|
|
992
|
-
});
|
|
993
|
-
}
|
|
994
|
-
|
|
995
972
|
// Extracted Slack app-manifest-creation/OAuth/app-token orchestration
|
|
996
973
|
// (UAP-1.1) — shared by the legacy /admin/provision/* wizard's Slack
|
|
997
974
|
// branch and the new per-agent /admin/agents/:id/connect-slack routes so
|
|
@@ -3977,16 +3954,29 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
3977
3954
|
const settingsNav = buildSettingsNav({
|
|
3978
3955
|
githubEnterprise: Boolean(githubEnterpriseApi),
|
|
3979
3956
|
templates: Boolean(templateService),
|
|
3957
|
+
accounts: accountNavEnabled,
|
|
3980
3958
|
extraItems: deps.settingsNavItems ?? [],
|
|
3981
3959
|
});
|
|
3982
3960
|
|
|
3983
3961
|
// SGL-2.2: /admin/settings lands on the first nav item the viewer can see.
|
|
3984
|
-
if (githubEnterpriseApi || templateService) {
|
|
3985
|
-
app.get("/admin/settings", requireAuth, (c) => {
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3962
|
+
if (githubEnterpriseApi || templateService || accountNavEnabled) {
|
|
3963
|
+
app.get("/admin/settings", requireAuth, async (c) => {
|
|
3964
|
+
// Admins without an account would 404 on the Account item; skip it.
|
|
3965
|
+
let nav = settingsNav;
|
|
3966
|
+
if (accountNavEnabled && accountServices) {
|
|
3967
|
+
const account = await accountServices.accounts
|
|
3968
|
+
.getByMemberEmail(c.var.userEmail)
|
|
3969
|
+
.catch(() => null);
|
|
3970
|
+
if (!account) {
|
|
3971
|
+
nav = {
|
|
3972
|
+
sections: settingsNav.sections.map((sec) => ({
|
|
3973
|
+
...sec,
|
|
3974
|
+
items: sec.items.filter((i) => i.path !== SETTINGS_ACCOUNT_PATH),
|
|
3975
|
+
})),
|
|
3976
|
+
};
|
|
3977
|
+
}
|
|
3978
|
+
}
|
|
3979
|
+
const first = firstVisibleSettingsItem(nav, c.var.isAdmin === true);
|
|
3990
3980
|
if (!first) {
|
|
3991
3981
|
return new Response("No settings are available for your account.", {
|
|
3992
3982
|
status: 404,
|
|
@@ -4025,12 +4015,14 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
4025
4015
|
registerAccountRoutes(app, {
|
|
4026
4016
|
enabled: accountNavEnabled,
|
|
4027
4017
|
requireAuth,
|
|
4018
|
+
settingsNav,
|
|
4028
4019
|
...accountServices,
|
|
4029
4020
|
html,
|
|
4030
4021
|
});
|
|
4031
4022
|
registerAdminAccountsRoutes(app, {
|
|
4032
4023
|
enabled: accountNavEnabled,
|
|
4033
4024
|
requireAuth,
|
|
4025
|
+
settingsNav,
|
|
4034
4026
|
...accountServices,
|
|
4035
4027
|
agents: agentService,
|
|
4036
4028
|
provisioner,
|