@app-vitals/agent-admin 1.108.0 → 1.108.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/e2e/real/admin-access.real.e2e.ts +77 -68
  2. package/e2e/real/agent-management.real.e2e.ts +165 -143
  3. package/e2e/real/owner-access.real.e2e.ts +228 -212
  4. package/openapi.platform.json +6 -6
  5. package/package.json +2 -2
  6. package/src/account-created-notifier.ts +1 -1
  7. package/src/account-onboarding.integration.test.ts +69 -0
  8. package/src/account-onboarding.ts +29 -3
  9. package/src/account-trial-expiry-sweeper.ts +1 -1
  10. package/src/accounts-api.integration.test.ts +5 -2
  11. package/src/accounts-api.smoke.test.ts +21 -5
  12. package/src/accounts-api.ts +12 -15
  13. package/src/admin-boot-config.ts +2 -0
  14. package/src/admin-boot-config.unit.test.ts +27 -0
  15. package/src/admin-boot.ts +11 -10
  16. package/src/admin-ui-account.smoke.test.ts +7 -3
  17. package/src/admin-ui-account.ts +10 -15
  18. package/src/admin-ui-accounts.smoke.test.ts +4 -4
  19. package/src/admin-ui-accounts.ts +7 -11
  20. package/src/admin-ui-settings-nav-context.smoke.test.ts +24 -0
  21. package/src/admin-ui-settings.smoke.test.ts +17 -1
  22. package/src/admin-ui.smoke.test.ts +168 -2
  23. package/src/admin-ui.ts +39 -26
  24. package/src/agent-management-access.integration.test.ts +18 -6
  25. package/src/agent-manifest.ts +2 -1
  26. package/src/agent-provisioner.integration.test.ts +10 -10
  27. package/src/agent-provisioner.ts +10 -1
  28. package/src/agent-provisioner.unit.test.ts +110 -36
  29. package/src/agent-templates-api.integration.test.ts +23 -5
  30. package/src/agent-templates-api.ts +11 -8
  31. package/src/caller-scope.integration.test.ts +8 -6
  32. package/src/caller-scope.ts +32 -26
  33. package/src/caller-scope.unit.test.ts +15 -11
  34. package/src/platform-routes.ts +2 -2
@@ -4,7 +4,9 @@
4
4
  * agent provisioning (SSP-3.1).
5
5
  *
6
6
  * A verified email with no account yet either joins the account that invited
7
- * it (as 'member') or gets a brand-new account (as 'owner'). Everything runs
7
+ * it (as 'member') or, when signup is open, gets a brand-new account (as
8
+ * 'owner'). joinForEmail() is the signup-off variant: it never creates an
9
+ * account. Everything runs
8
10
  * in one transaction, and concurrent first logins for the same email are made
9
11
  * idempotent by UNIQUE(AccountMember.email): the losing transaction rolls back
10
12
  * entirely (including any account it created) and re-reads the winner's row.
@@ -36,12 +38,29 @@ export class AccountOnboardingService {
36
38
  * does, else join via pending invite ("joined"), else create ("created").
37
39
  */
38
40
  async provisionForEmail(rawEmail: string): Promise<OnboardingResult> {
41
+ // With allowCreate the result is never null (the last step creates).
42
+ return (await this.resolve(rawEmail, true)) as OnboardingResult;
43
+ }
44
+
45
+ /**
46
+ * Signup-off sign-in: "existing" if the email already belongs to an
47
+ * account, else join via pending invite ("joined"), else null. Never
48
+ * creates an account.
49
+ */
50
+ async joinForEmail(rawEmail: string): Promise<OnboardingResult | null> {
51
+ return this.resolve(rawEmail, false);
52
+ }
53
+
54
+ private async resolve(
55
+ rawEmail: string,
56
+ allowCreate: boolean,
57
+ ): Promise<OnboardingResult | null> {
39
58
  const email = normalizeEmail(rawEmail);
40
59
  let lastErr: unknown;
41
60
  for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
42
61
  try {
43
62
  return await this.prisma.$transaction((tx) =>
44
- this.provisionInTx(tx, email),
63
+ this.provisionInTx(tx, email, allowCreate),
45
64
  );
46
65
  } catch (err) {
47
66
  if (!isUniqueViolation(err)) throw err;
@@ -59,7 +78,8 @@ export class AccountOnboardingService {
59
78
  private async provisionInTx(
60
79
  tx: Parameters<Parameters<PrismaClient["$transaction"]>[0]>[0],
61
80
  email: string,
62
- ): Promise<OnboardingResult> {
81
+ allowCreate: boolean,
82
+ ): Promise<OnboardingResult | null> {
63
83
  const existing = await tx.accountMember.findUnique({ where: { email } });
64
84
  if (existing) return { kind: "existing", accountId: existing.accountId };
65
85
 
@@ -79,6 +99,12 @@ export class AccountOnboardingService {
79
99
  return { kind: "joined", accountId: invite.accountId };
80
100
  }
81
101
  }
102
+ if (!allowCreate) {
103
+ // A concurrent login may have claimed the invite and committed since
104
+ // the first read (read committed: this statement sees its member row).
105
+ const winner = await tx.accountMember.findUnique({ where: { email } });
106
+ return winner ? { kind: "existing", accountId: winner.accountId } : null;
107
+ }
82
108
 
83
109
  const account = await tx.account.create({
84
110
  data: {
@@ -18,7 +18,7 @@
18
18
  * Idempotent by construction: once an account is trial_expired and its crons
19
19
  * are disabled, neither query matches anything, so a re-run writes nothing.
20
20
  * Never deletes anything (no deleteAgentFully call). Registered via setInterval
21
- * in main.ts, flag-gated on self-serve.
21
+ * in admin-boot.ts; always runs (independent of the self-serve setting).
22
22
  */
23
23
 
24
24
  import type { AccountLifecycle } from "./account-lifecycle.ts";
@@ -24,7 +24,10 @@ import { createAdminPrismaClient } from "./prisma-client.ts";
24
24
  const TEST_DB = process.env.DATABASE_URL_ADMIN_TEST;
25
25
  const describeOrSkip = TEST_DB ? describe : describe.skip;
26
26
 
27
- describeOrSkip("/accounts API (integration)", () => {
27
+ /** Run with the self-serve setting off and on; the outcome must not differ. */
28
+ const SELF_SERVE = [false, true];
29
+
30
+ describeOrSkip.each(SELF_SERVE)("/accounts API, self-serve=%p", (enabled) => {
28
31
  let prisma: PrismaClient;
29
32
  let accounts: AccountService;
30
33
  let app: ReturnType<typeof createAccountsApp>;
@@ -43,7 +46,7 @@ describeOrSkip("/accounts API (integration)", () => {
43
46
  accounts = new AccountService(prisma);
44
47
  app = createAccountsApp({
45
48
  selfServe: {
46
- enabled: true,
49
+ enabled,
47
50
  defaultMaxAgents: 0,
48
51
  contactEmail: "c@x.com",
49
52
  },
@@ -120,11 +120,27 @@ function req(
120
120
  });
121
121
  }
122
122
 
123
- describe("flag off", () => {
124
- it.each(ROUTES)("%s %s -> 404", async (method, path, body) => {
125
- const { app } = build(false);
126
- const res = await req(app, method, path, adminHeaders, body);
127
- expect(res.status).toBe(404);
123
+ describe("self-serve flag off", () => {
124
+ it.each(ROUTES)(
125
+ "%s %s answers exactly as with the flag on",
126
+ async (method, path, body) => {
127
+ const off = await req(build(false).app, method, path, adminHeaders, body);
128
+ const on = await req(build(true).app, method, path, adminHeaders, body);
129
+ expect(off.status).not.toBe(404);
130
+ expect(off.status).toBe(on.status);
131
+ expect(await off.json()).toEqual(await on.json());
132
+ },
133
+ );
134
+
135
+ it.each(ROUTES)("%s %s: non-admin cookie -> 403", async (m, p, b) => {
136
+ const res = await req(
137
+ build(false).app,
138
+ m,
139
+ p,
140
+ { Cookie: `admin_session=${await cookie(false)}` },
141
+ b,
142
+ );
143
+ expect(res.status).toBe(403);
128
144
  });
129
145
  });
130
146
 
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * admin/src/accounts-api.ts
3
3
  * Admin-only /accounts API (SSP-5.1): list/get/create/patch self-serve
4
- * accounts. Flag-gated (404 when SHIPWRIGHT_SELF_SERVE_ENABLED is off, checked
5
- * before auth) and admin-only (admin cookie or scope "*" key); every other
6
- * caller class gets 403.
4
+ * accounts. Admin-only (admin cookie or scope "*" key); every other caller
5
+ * class gets 403. Available whether or not self-serve signup is enabled.
7
6
  *
8
7
  * POST /accounts goes through AccountService.create(), which seeds the owner
9
8
  * AccountMember row — so that owner's first login joins this account instead
@@ -50,6 +49,10 @@ interface AccountsApiDeps {
50
49
  * lockdown/restore side effect (SSP-8.2).
51
50
  */
52
51
  accountLifecycle: Pick<AccountLifecycle, "update">;
52
+ /**
53
+ * @deprecated Ignored: the accounts API no longer depends on the self-serve
54
+ * setting. Kept optional so existing callers keep compiling.
55
+ */
53
56
  selfServe?: SelfServeConfig;
54
57
  sessionSecret: string;
55
58
  adminApiKeys?: Map<string, AdminApiKey>;
@@ -61,7 +64,7 @@ const jsonError = { content: { "application/json": { schema: ErrorSchema } } };
61
64
  const errorResponses = {
62
65
  401: { description: "Unauthorized", ...jsonError },
63
66
  403: { description: "Forbidden (non-admin caller)", ...jsonError },
64
- 404: { description: "Not found (or self-serve disabled)", ...jsonError },
67
+ 404: { description: "Not found", ...jsonError },
65
68
  };
66
69
 
67
70
  const listAccountsRoute = createRoute({
@@ -70,7 +73,7 @@ const listAccountsRoute = createRoute({
70
73
  tags: ["accounts"],
71
74
  summary: "List accounts",
72
75
  description:
73
- "Admin-only, flag-gated. Returns every account with agentCount and memberCount.",
76
+ "Admin-only. Returns every account with agentCount and memberCount.",
74
77
  responses: {
75
78
  200: {
76
79
  description: "Accounts",
@@ -85,7 +88,7 @@ const getAccountRoute = createRoute({
85
88
  path: "/accounts/{id}",
86
89
  tags: ["accounts"],
87
90
  summary: "Get an account",
88
- description: "Admin-only, flag-gated.",
91
+ description: "Admin-only.",
89
92
  request: { params: AccountIdParamSchema },
90
93
  responses: {
91
94
  200: {
@@ -102,7 +105,7 @@ const createAccountRoute = createRoute({
102
105
  tags: ["accounts"],
103
106
  summary: "Create an account",
104
107
  description:
105
- "Admin-only, flag-gated. Creates the account and seeds ownerEmail as its owner member, so that owner's first login joins this account. 409 if ownerEmail already belongs to an account.",
108
+ "Admin-only. Creates the account and seeds ownerEmail as its owner member, so that owner's first login joins this account. 409 if ownerEmail already belongs to an account.",
106
109
  request: {
107
110
  body: {
108
111
  content: { "application/json": { schema: CreateAccountBodySchema } },
@@ -125,7 +128,7 @@ const patchAccountRoute = createRoute({
125
128
  tags: ["accounts"],
126
129
  summary: "Update an account",
127
130
  description:
128
- "Admin-only, flag-gated. Updates name, maxAgents, plan, status and/or trialExpiresAt. status=suspended (or trial_expired) disables every enabled cron of the account's agents with a lockdown marker; status=active re-enables exactly those, and requires trialExpiresAt to be cleared or in the future (422 otherwise). Nothing is deleted.",
131
+ "Admin-only. Updates name, maxAgents, plan, status and/or trialExpiresAt. status=suspended (or trial_expired) disables every enabled cron of the account's agents with a lockdown marker; status=active re-enables exactly those, and requires trialExpiresAt to be cleared or in the future (422 otherwise). Nothing is deleted.",
129
132
  request: {
130
133
  params: AccountIdParamSchema,
131
134
  body: {
@@ -175,7 +178,7 @@ function serialize(a: {
175
178
  export function createAccountsApp(
176
179
  deps: AccountsApiDeps,
177
180
  ): OpenAPIHono<AdminAuthEnv> {
178
- const { accountService, selfServe } = deps;
181
+ const { accountService } = deps;
179
182
 
180
183
  const app = new OpenAPIHono<AdminAuthEnv>({
181
184
  defaultHook: (result, c) => {
@@ -208,13 +211,7 @@ export function createAccountsApp(
208
211
  adminApiKeys: deps.adminApiKeys,
209
212
  });
210
213
 
211
- // Flag gate runs before auth so a disabled deployment reveals nothing.
212
- const flagGate: Parameters<typeof app.use>[1] = async (c, next) => {
213
- if (selfServe?.enabled !== true) return c.json({ error: "Not found" }, 404);
214
- return next();
215
- };
216
214
  // "/accounts/*" also matches the bare "/accounts" path in Hono.
217
- app.use("/accounts/*", flagGate);
218
215
  app.use("/accounts/*", authMiddleware);
219
216
 
220
217
  const requireAdmin = (c: { get: (k: "isAdmin") => unknown }) => {
@@ -204,6 +204,8 @@ export function buildProvisioner(
204
204
 
205
205
  return new KubernetesAgentProvisioner(k8s, agentTokenService, {
206
206
  namespace,
207
+ // Tenant pod label + CPU limit only on deployments with open signup.
208
+ tenantPodRestrictions: env.SHIPWRIGHT_SELF_SERVE_ENABLED === "enabled",
207
209
  image,
208
210
  imageTag,
209
211
  ...(images ? { images } : {}),
@@ -41,3 +41,30 @@ describe("buildProvisioner pod label configuration", () => {
41
41
  ).toThrow("reserved key");
42
42
  });
43
43
  });
44
+
45
+ describe("buildProvisioner tenant pod restrictions", () => {
46
+ const config = (env: Record<string, string>) =>
47
+ (
48
+ buildProvisioner(
49
+ { SHIPWRIGHT_K8S_PROVISIONING: "enabled", ...env },
50
+ {} as AgentTokenService,
51
+ ) as unknown as { config: { tenantPodRestrictions?: boolean } }
52
+ ).config;
53
+
54
+ it("are on only when SHIPWRIGHT_SELF_SERVE_ENABLED is exactly enabled", () => {
55
+ expect(
56
+ config({ SHIPWRIGHT_SELF_SERVE_ENABLED: "enabled" })
57
+ .tenantPodRestrictions,
58
+ ).toBe(true);
59
+ });
60
+
61
+ it.each(["", "true", "disabled"])(
62
+ "are off for SHIPWRIGHT_SELF_SERVE_ENABLED=%p and when unset",
63
+ (value) => {
64
+ expect(
65
+ config({ SHIPWRIGHT_SELF_SERVE_ENABLED: value }).tenantPodRestrictions,
66
+ ).toBe(false);
67
+ expect(config({}).tenantPodRestrictions).toBe(false);
68
+ },
69
+ );
70
+ });
package/src/admin-boot.ts CHANGED
@@ -241,15 +241,14 @@ export async function startAdmin(
241
241
  const agentPluginService = new AgentPluginService(prisma);
242
242
  const agentMarketplaceService = new AgentMarketplaceService(prisma);
243
243
  const agentMemberService = new AgentMemberService(prisma);
244
- // Account-aware caller scope (SSP-2.1). Account membership contributes
245
- // agents only when the self-serve flag is on; off → AgentMember-only.
244
+ // Account-aware caller scope (SSP-2.1). Owners get their account's agents
245
+ // whether or not self-serve signup is enabled.
246
246
  const accountService = new AccountService(prisma);
247
247
  const callerScopeResolver = createCallerScopeResolver(
248
248
  callerScopeDepsFromServices({
249
249
  accountService,
250
250
  agentMemberService,
251
251
  }),
252
- process.env.SHIPWRIGHT_SELF_SERVE_ENABLED === "enabled",
253
252
  );
254
253
  const agentChatTokenService = new AgentChatTokenService(prisma);
255
254
  const agentCronRunStatsService = new AgentCronRunStatsService(prisma);
@@ -297,8 +296,9 @@ export async function startAdmin(
297
296
  .then((v) => v.trim())
298
297
  .catch(() => "0.0.0");
299
298
  const adminApiKeys = parseAdminApiKeys(process.env.SHIPWRIGHT_ADMIN_API_KEYS);
300
- // Self-serve provisioning config (SSP-1.3) — read once at startup and
301
- // injected as deps; no consumers yet.
299
+ // Self-serve config (SSP-1.3), read once at startup. `enabled` controls only
300
+ // open signup (an unknown verified user creating an account); the tenant pod
301
+ // restrictions read the same env var in buildProvisioner.
302
302
  const selfServe = parseSelfServeConfig(process.env);
303
303
  // Account status transitions → cron lockdown/restore (SSP-8.2). Shared by
304
304
  // the /accounts PATCH handler, the admin UI and the account sweepers.
@@ -810,11 +810,12 @@ export async function startAdmin(
810
810
  }
811
811
 
812
812
  // Account trial sweepers (SSP-8.2) — the account-level counterparts of the
813
- // two per-agent sweepers above (which keep running unchanged). Flag-gated:
814
- // accounts only exist when self-serve is enabled. Same cadences as the
815
- // per-agent pair: hourly warning, minutely expiry/lockdown. Registered
816
- // HERE, never inside an app factory. No deleteAgentFully call anywhere.
817
- if (selfServe.enabled) {
813
+ // two per-agent sweepers above (which keep running unchanged). Accounts
814
+ // exist whether or not self-serve signup is enabled, so they always run.
815
+ // Same cadences as the per-agent pair: hourly warning, minutely
816
+ // expiry/lockdown. Registered HERE, never inside an app factory. No
817
+ // deleteAgentFully call anywhere.
818
+ {
818
819
  const accountTrialWarningSweeper = new AccountTrialWarningSweeper({
819
820
  accounts: accountService,
820
821
  agentEnvService,
@@ -153,12 +153,16 @@ function post(
153
153
  }
154
154
 
155
155
  describe("/admin/account", () => {
156
- it("returns 404 for every route when the flag is off", async () => {
156
+ it("serves the page and invites with the self-serve flag off", async () => {
157
157
  const { app } = setup({ enabled: false });
158
- expect((await app.request("/admin/account")).status).toBe(404);
158
+ const res = await app.request("/admin/account", {
159
+ headers: { "x-test-user-email": "owner@x.com" },
160
+ });
161
+ expect(res.status).toBe(200);
162
+ expect(await res.text()).toContain("Acme");
159
163
  expect(
160
164
  (await post(app, "/admin/account/invite", { email: "a@b.co" })).status,
161
- ).toBe(404);
165
+ ).not.toBe(404);
162
166
  });
163
167
 
164
168
  it("returns 404 for a signed-in user without an account", async () => {
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * admin/src/admin-ui-account.ts
3
- * GET/POST /admin/account — self-serve account management (SSP-3.2): name,
4
- * quota, members, pending invites. Owners manage; members are read-only.
3
+ * GET/POST /admin/account — account management (SSP-3.2): name, quota,
4
+ * members, pending invites. Owners manage; members are read-only.
5
5
  *
6
- * Registered into admin-ui.ts's app via registerAccountRoutes(). Flag-gated:
7
- * every route 404s when self-serve is off, and for signed-in users with no
8
- * account.
6
+ * Registered into admin-ui.ts's app via registerAccountRoutes(). Every route
7
+ * 404s for signed-in users with no account. Independent of the self-serve
8
+ * setting.
9
9
  */
10
10
 
11
11
  import type { Context, Hono, MiddlewareHandler } from "hono";
@@ -22,8 +22,11 @@ import type { AdminUIEnv } from "./admin-ui.ts";
22
22
  import type { SettingsNav } from "./admin-ui-settings-layout.ts";
23
23
 
24
24
  export interface AccountRouteDeps {
25
- /** SHIPWRIGHT_SELF_SERVE_ENABLED === "enabled". */
26
- enabled: boolean;
25
+ /**
26
+ * @deprecated Ignored: these routes no longer depend on the self-serve
27
+ * setting. Kept optional so existing callers keep compiling.
28
+ */
29
+ enabled?: boolean;
27
30
  requireAuth: MiddlewareHandler<AdminUIEnv>;
28
31
  accounts: Pick<AccountService, "getByMemberEmail" | "update" | "countAgents">;
29
32
  members: Pick<
@@ -45,14 +48,6 @@ export function registerAccountRoutes(
45
48
  ): void {
46
49
  const notFound = () => new Response("Not Found", { status: 404 });
47
50
 
48
- // Flag-off 404s before auth so the route is indistinguishable from absent.
49
- app.use(`${ACCOUNT_PATH}`, async (_c, next) =>
50
- deps.enabled ? next() : notFound(),
51
- );
52
- app.use(`${ACCOUNT_PATH}/*`, async (_c, next) =>
53
- deps.enabled ? next() : notFound(),
54
- );
55
-
56
51
  async function render(
57
52
  c: Context<AdminUIEnv>,
58
53
  account: Account,
@@ -279,15 +279,15 @@ describe("/admin/accounts", () => {
279
279
  }
280
280
  });
281
281
 
282
- it("404 everywhere when flag is off, even for admin", async () => {
282
+ it("serves every route to admins with the self-serve flag off", async () => {
283
283
  const { app } = setup({ enabled: false });
284
284
  expect(
285
285
  (await app.request("/admin/accounts", { headers: ADMIN })).status,
286
- ).toBe(404);
286
+ ).toBe(200);
287
287
  expect(
288
288
  (await app.request("/admin/accounts/a1", { headers: ADMIN })).status,
289
- ).toBe(404);
290
- expect((await post(app, "/admin/accounts/a1/suspend", {})).status).toBe(
289
+ ).toBe(200);
290
+ expect((await post(app, "/admin/accounts/a1/suspend", {})).status).not.toBe(
291
291
  404,
292
292
  );
293
293
  });
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * admin/src/admin-ui-accounts.ts
3
3
  * GET/POST /admin/accounts[/:id] — platform-admin account management
4
- * (SSP-5.2). Admin only (403 otherwise) and flag-gated (404 when self-serve
5
- * is off). Status and trial edits go through AccountLifecycle (SSP-8.2), so
4
+ * (SSP-5.2). Admin only (403 otherwise), independent of the self-serve
5
+ * setting. Status and trial edits go through AccountLifecycle (SSP-8.2), so
6
6
  * suspend locks down the account's crons and reactivate restores them.
7
7
  */
8
8
 
@@ -30,8 +30,11 @@ import type { AgentService } from "./agents.ts";
30
30
  import { UnprocessableEntityError } from "./errors.ts";
31
31
 
32
32
  export interface AdminAccountsRouteDeps {
33
- /** SHIPWRIGHT_SELF_SERVE_ENABLED === "enabled". */
34
- enabled: boolean;
33
+ /**
34
+ * @deprecated Ignored: these routes no longer depend on the self-serve
35
+ * setting. Kept optional so existing callers keep compiling.
36
+ */
37
+ enabled?: boolean;
35
38
  requireAuth: MiddlewareHandler<AdminUIEnv>;
36
39
  accounts: Pick<
37
40
  AccountService,
@@ -62,13 +65,6 @@ export function registerAdminAccountsRoutes(
62
65
  const notFound = () => new Response("Not Found", { status: 404 });
63
66
  const forbidden = () => new Response("Forbidden", { status: 403 });
64
67
 
65
- app.use(ADMIN_ACCOUNTS_PATH, async (_c, next) =>
66
- deps.enabled ? next() : notFound(),
67
- );
68
- app.use(`${ADMIN_ACCOUNTS_PATH}/*`, async (_c, next) =>
69
- deps.enabled ? next() : notFound(),
70
- );
71
-
72
68
  const requireAdmin: MiddlewareHandler<AdminUIEnv> = async (c, next) =>
73
69
  c.var.isAdmin === true ? next() : forbidden();
74
70
 
@@ -146,6 +146,30 @@ describe("contract: nav item present iff its route is registered", () => {
146
146
  path: SETTINGS_ACCOUNTS_PATH,
147
147
  present: true,
148
148
  },
149
+ {
150
+ name: "Accounts on, self-serve off",
151
+ deps: {
152
+ selfServe: { ...selfServe, enabled: false },
153
+ accountServices: accountServices("admin@example.com"),
154
+ },
155
+ path: SETTINGS_ACCOUNTS_PATH,
156
+ present: true,
157
+ },
158
+ {
159
+ name: "Accounts on, no self-serve config",
160
+ deps: { accountServices: accountServices("admin@example.com") },
161
+ path: SETTINGS_ACCOUNTS_PATH,
162
+ present: true,
163
+ },
164
+ {
165
+ name: "Account page, self-serve off",
166
+ deps: {
167
+ selfServe: { ...selfServe, enabled: false },
168
+ accountServices: accountServices("admin@example.com"),
169
+ },
170
+ path: SETTINGS_ACCOUNT_PATH,
171
+ present: true,
172
+ },
149
173
  {
150
174
  name: "Accounts off",
151
175
  deps: {},
@@ -81,7 +81,8 @@ describe("GET /admin/settings", () => {
81
81
  headers: { cookie: await userCookie() },
82
82
  });
83
83
  expect(res.status).toBe(302);
84
- expect(res.headers.get("location")).toBe("/admin/settings/templates");
84
+ // Account comes first for an owner, with or without self-serve signup.
85
+ expect(res.headers.get("location")).toBe("/admin/account");
85
86
  });
86
87
 
87
88
  it("lands an account member on Notifications (ACM-7.2)", async () => {
@@ -239,6 +240,21 @@ describe("GET /admin/settings with accounts (SGL-2.3)", () => {
239
240
  expect(res.headers.get("location")).toBe("/admin/account");
240
241
  });
241
242
 
243
+ it("lands an account owner on Account with self-serve off", async () => {
244
+ const app = createAdminUIApp(
245
+ makeMockDeps({
246
+ templateService,
247
+ selfServe: { ...selfServe, enabled: false },
248
+ accountServices: memberAccounts("m@acme.com"),
249
+ } as never),
250
+ );
251
+ const res = await app.request("/admin/settings", {
252
+ headers: { cookie: await userCookie("m@acme.com") },
253
+ });
254
+ expect(res.status).toBe(302);
255
+ expect(res.headers.get("location")).toBe("/admin/account");
256
+ });
257
+
242
258
  it("lands an account member on Notifications, not Account (ACM-7.2)", async () => {
243
259
  const app = createAdminUIApp(
244
260
  makeMockDeps({