@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
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * admin/e2e/real/owner-access.real.e2e.ts
3
3
  *
4
- * Real-service e2e, self-serve ON: an account owner (owner1, Account One)
5
- * sees and manages everything in their account, including agents they are not
6
- * an AgentMember of, and nothing in the other account. Direct URLs and requests
4
+ * Real-service e2e, self-serve OFF and ON (the setting must not change it):
5
+ * an account owner (owner1, Account One) sees and manages everything in their
6
+ * account, including agents they are not an AgentMember of, and nothing in the
7
+ * other account. Direct URLs and requests
7
8
  * for Account Two's agents, its chat and the admin-only pages are refused, and
8
9
  * each refusal is shown to have changed nothing.
9
10
  */
@@ -12,226 +13,241 @@ import { expect, test } from "@playwright/test";
12
13
  import { AGENTS, EMAILS, THREADS } from "./constants.ts";
13
14
  import { RealHarness } from "./fixture.ts";
14
15
 
15
- const harness = new RealHarness({
16
- selfServe: true,
17
- adminPort: 3520,
18
- chatPort: 3521,
19
- });
20
-
21
16
  test.describe.configure({ mode: "serial" });
22
17
 
23
- test.beforeAll(async () => {
24
- test.setTimeout(240_000);
25
- await harness.start();
26
- });
27
- test.afterAll(async () => {
28
- await harness.stop();
29
- });
30
-
31
18
  const REFUSED = [403, 404];
32
19
 
33
- test.describe("owner, self-serve on", () => {
34
- test("Agents list shows every agent in their account and none of the other", async ({
35
- page,
36
- context,
37
- }) => {
38
- await harness.signIn(context, EMAILS.owner1);
39
- await page.goto(`${harness.adminUrl}/admin/agents`);
40
- await expect(page.getByText(AGENTS.alpha.name).first()).toBeVisible();
41
- // Beta: same account, owner1 is not an AgentMember of it.
42
- await expect(page.getByText(AGENTS.beta.name).first()).toBeVisible();
43
- await expect(page.getByText(AGENTS.gamma.name)).toHaveCount(0);
44
-
45
- const res = await context.request.get(`${harness.adminUrl}/agents`);
46
- const ids = ((await res.json()) as { id: string }[]).map((a) => a.id);
47
- expect(ids.sort()).toEqual([AGENTS.alpha.id, AGENTS.beta.id].sort());
48
- });
49
-
50
- test("owner opens an agent they are not an AgentMember of", async ({
51
- page,
52
- context,
53
- }) => {
54
- await harness.signIn(context, EMAILS.owner1);
55
- const res = await page.goto(
56
- `${harness.adminUrl}/admin/agents/${AGENTS.beta.id}`,
57
- );
58
- expect(res?.status()).toBe(200);
59
- await expect(page.getByText(AGENTS.beta.name).first()).toBeVisible();
60
- const json = await context.request.get(
61
- `${harness.adminUrl}/agents/${AGENTS.beta.id}`,
62
- );
63
- expect(json.status()).toBe(200);
64
- });
20
+ /** The self-serve setting must not change any of this. */
21
+ const MODES = [
22
+ { selfServe: false, adminPort: 3526, chatPort: 3527 },
23
+ { selfServe: true, adminPort: 3520, chatPort: 3521 },
24
+ ];
25
+
26
+ for (const mode of MODES) {
27
+ test.describe(`self-serve ${mode.selfServe ? "on" : "off"}`, () => {
28
+ test.describe.configure({ mode: "serial" });
29
+ const harness = new RealHarness(mode);
30
+
31
+ test.beforeAll(async () => {
32
+ test.setTimeout(240_000);
33
+ await harness.start();
34
+ });
35
+ test.afterAll(async () => {
36
+ await harness.stop();
37
+ });
38
+
39
+ test.describe("owner", () => {
40
+ test("Agents list shows every agent in their account and none of the other", async ({
41
+ page,
42
+ context,
43
+ }) => {
44
+ await harness.signIn(context, EMAILS.owner1);
45
+ await page.goto(`${harness.adminUrl}/admin/agents`);
46
+ await expect(page.getByText(AGENTS.alpha.name).first()).toBeVisible();
47
+ // Beta: same account, owner1 is not an AgentMember of it.
48
+ await expect(page.getByText(AGENTS.beta.name).first()).toBeVisible();
49
+ await expect(page.getByText(AGENTS.gamma.name)).toHaveCount(0);
50
+
51
+ const res = await context.request.get(`${harness.adminUrl}/agents`);
52
+ const ids = ((await res.json()) as { id: string }[]).map((a) => a.id);
53
+ expect(ids.sort()).toEqual([AGENTS.alpha.id, AGENTS.beta.id].sort());
54
+ });
65
55
 
66
- test("owner Settings, Templates and Account pages open; admin-only items do not", async ({
67
- page,
68
- context,
69
- }) => {
70
- await harness.signIn(context, EMAILS.owner1);
71
- const base = harness.adminUrl;
72
- for (const path of [
73
- "/admin/settings",
74
- "/admin/settings/templates",
75
- "/admin/account",
76
- ]) {
77
- const res = await page.goto(`${base}${path}`);
78
- expect(res?.status(), path).toBe(200);
79
- await expect(page.locator("nav.settings-sidebar")).toBeVisible();
80
- }
81
- const nav = page.locator("nav.settings-sidebar");
82
- await expect(nav.locator('a[href^="/admin/account"]')).toHaveCount(1);
83
- await expect(
84
- nav.locator('a[href^="/admin/settings/templates"]'),
85
- ).toHaveCount(1);
86
- // Admin-only items are not offered.
87
- for (const href of [
88
- "/admin/settings/github-enterprise",
89
- "/admin/accounts",
90
- ]) {
91
- await expect(nav.locator(`a[href^="${href}"]`)).toHaveCount(0);
92
- }
93
- // The owner's Account page shows their own account only.
94
- await page.goto(`${base}/admin/account`);
95
- await expect(page.getByText(EMAILS.member1).first()).toBeVisible();
96
- await expect(page.getByText(EMAILS.owner2)).toHaveCount(0);
97
- });
56
+ test("owner opens an agent they are not an AgentMember of", async ({
57
+ page,
58
+ context,
59
+ }) => {
60
+ await harness.signIn(context, EMAILS.owner1);
61
+ const res = await page.goto(
62
+ `${harness.adminUrl}/admin/agents/${AGENTS.beta.id}`,
63
+ );
64
+ expect(res?.status()).toBe(200);
65
+ await expect(page.getByText(AGENTS.beta.name).first()).toBeVisible();
66
+ const json = await context.request.get(
67
+ `${harness.adminUrl}/agents/${AGENTS.beta.id}`,
68
+ );
69
+ expect(json.status()).toBe(200);
70
+ });
98
71
 
99
- test("owner can open the agent creation form", async ({ page, context }) => {
100
- await harness.signIn(context, EMAILS.owner1);
101
- const form = await page.goto(`${harness.adminUrl}/admin/agents/new`);
102
- expect(form?.status()).toBe(200);
103
- await expect(page.locator("form").first()).toBeVisible();
104
- });
72
+ test("owner Settings, Templates and Account pages open; admin-only items do not", async ({
73
+ page,
74
+ context,
75
+ }) => {
76
+ await harness.signIn(context, EMAILS.owner1);
77
+ const base = harness.adminUrl;
78
+ for (const path of [
79
+ "/admin/settings",
80
+ "/admin/settings/templates",
81
+ "/admin/account",
82
+ ]) {
83
+ const res = await page.goto(`${base}${path}`);
84
+ expect(res?.status(), path).toBe(200);
85
+ await expect(page.locator("nav.settings-sidebar")).toBeVisible();
86
+ }
87
+ const nav = page.locator("nav.settings-sidebar");
88
+ await expect(nav.locator('a[href^="/admin/account"]')).toHaveCount(1);
89
+ await expect(
90
+ nav.locator('a[href^="/admin/settings/templates"]'),
91
+ ).toHaveCount(1);
92
+ // Admin-only items are not offered.
93
+ for (const href of [
94
+ "/admin/settings/github-enterprise",
95
+ "/admin/accounts",
96
+ ]) {
97
+ await expect(nav.locator(`a[href^="${href}"]`)).toHaveCount(0);
98
+ }
99
+ // The owner's Account page shows their own account only.
100
+ await page.goto(`${base}/admin/account`);
101
+ await expect(page.getByText(EMAILS.member1).first()).toBeVisible();
102
+ await expect(page.getByText(EMAILS.owner2)).toHaveCount(0);
103
+ });
105
104
 
106
- test("direct URLs and requests for the other account's agent are refused", async ({
107
- page,
108
- context,
109
- }) => {
110
- await harness.signIn(context, EMAILS.owner1);
111
- const base = harness.adminUrl;
112
- const other = AGENTS.gamma;
113
-
114
- for (const path of [
115
- `/admin/agents/${other.id}`,
116
- `/admin/agents/${other.id}/setup`,
117
- ]) {
118
- const res = await page.goto(`${base}${path}`);
119
- expect(REFUSED, path).toContain(res?.status());
120
- await expect(page.getByText(other.name)).toHaveCount(0);
121
- }
122
-
123
- for (const path of [
124
- `/agents/${other.id}`,
125
- `/agents/${other.id}/envs`,
126
- `/agents/${other.id}/crons`,
127
- `/agents/${other.id}/tokens`,
128
- ]) {
129
- const res = await context.request.get(`${base}${path}`);
130
- expect(REFUSED, `GET ${path}`).toContain(res.status());
131
- expect(await res.text()).not.toContain(other.name);
132
- }
133
-
134
- const writes: [string, string, unknown?][] = [
135
- ["PATCH", `/agents/${other.id}`, { repos: ["evil-org/pwn"] }],
136
- ["POST", `/agents/${other.id}/repos`, { repos: ["evil-org/pwn"] }],
137
- ["DELETE", `/agents/${other.id}`],
138
- ];
139
- for (const [method, path, data] of writes) {
140
- const res = await context.request.fetch(`${base}${path}`, {
141
- method,
142
- ...(data ? { data } : {}),
105
+ test("owner can open the agent creation form", async ({
106
+ page,
107
+ context,
108
+ }) => {
109
+ await harness.signIn(context, EMAILS.owner1);
110
+ const form = await page.goto(`${harness.adminUrl}/admin/agents/new`);
111
+ expect(form?.status()).toBe(200);
112
+ await expect(page.locator("form").first()).toBeVisible();
143
113
  });
144
- expect(REFUSED, `${method} ${path}`).toContain(res.status());
145
- }
146
-
147
- for (const path of [
148
- `/admin/agents/${other.id}/settings`,
149
- `/admin/agents/${other.id}/members`,
150
- `/admin/agents/${other.id}/envs`,
151
- `/admin/agents/${other.id}/delete`,
152
- ]) {
153
- const res = await context.request.post(`${base}${path}`, {
154
- form: { email: "owner1@e2e.test", key: "K", value: "V" },
155
- maxRedirects: 0,
114
+
115
+ test("direct URLs and requests for the other account's agent are refused", async ({
116
+ page,
117
+ context,
118
+ }) => {
119
+ await harness.signIn(context, EMAILS.owner1);
120
+ const base = harness.adminUrl;
121
+ const other = AGENTS.gamma;
122
+
123
+ for (const path of [
124
+ `/admin/agents/${other.id}`,
125
+ `/admin/agents/${other.id}/setup`,
126
+ ]) {
127
+ const res = await page.goto(`${base}${path}`);
128
+ expect(REFUSED, path).toContain(res?.status());
129
+ await expect(page.getByText(other.name)).toHaveCount(0);
130
+ }
131
+
132
+ for (const path of [
133
+ `/agents/${other.id}`,
134
+ `/agents/${other.id}/envs`,
135
+ `/agents/${other.id}/crons`,
136
+ `/agents/${other.id}/tokens`,
137
+ ]) {
138
+ const res = await context.request.get(`${base}${path}`);
139
+ expect(REFUSED, `GET ${path}`).toContain(res.status());
140
+ expect(await res.text()).not.toContain(other.name);
141
+ }
142
+
143
+ const writes: [string, string, unknown?][] = [
144
+ ["PATCH", `/agents/${other.id}`, { repos: ["evil-org/pwn"] }],
145
+ ["POST", `/agents/${other.id}/repos`, { repos: ["evil-org/pwn"] }],
146
+ ["DELETE", `/agents/${other.id}`],
147
+ ];
148
+ for (const [method, path, data] of writes) {
149
+ const res = await context.request.fetch(`${base}${path}`, {
150
+ method,
151
+ ...(data ? { data } : {}),
152
+ });
153
+ expect(REFUSED, `${method} ${path}`).toContain(res.status());
154
+ }
155
+
156
+ for (const path of [
157
+ `/admin/agents/${other.id}/settings`,
158
+ `/admin/agents/${other.id}/members`,
159
+ `/admin/agents/${other.id}/envs`,
160
+ `/admin/agents/${other.id}/delete`,
161
+ ]) {
162
+ const res = await context.request.post(`${base}${path}`, {
163
+ form: { email: "owner1@e2e.test", key: "K", value: "V" },
164
+ maxRedirects: 0,
165
+ });
166
+ expect(REFUSED, `POST ${path}`).toContain(res.status());
167
+ }
156
168
  });
157
- expect(REFUSED, `POST ${path}`).toContain(res.status());
158
- }
159
- });
160
169
 
161
- test("the other account's chat is refused", async ({ page, context }) => {
162
- await harness.signIn(context, EMAILS.owner1);
163
- const base = harness.adminUrl;
164
- const other = AGENTS.gamma;
165
- const seeded = THREADS.gamma;
166
- const threadId = await harness.threadIdByTitle(seeded.title);
167
-
168
- const picked = await page.goto(`${base}/admin/chat?agentId=${other.id}`);
169
- expect(REFUSED).toContain(picked?.status());
170
- await expect(page.getByText(seeded.title)).toHaveCount(0);
171
-
172
- const read = await page.goto(
173
- `${base}/admin/chat/${other.id}/threads/${threadId}`,
174
- );
175
- expect(REFUSED).toContain(read?.status());
176
- await expect(page.getByText(seeded.message)).toHaveCount(0);
177
-
178
- const before = await harness.chatThreads();
179
- for (const path of [
180
- `/admin/chat/${other.id}/threads`,
181
- `/admin/chat/${other.id}/threads/${threadId}/messages`,
182
- `/admin/chat/${other.id}/threads/${threadId}/delete`,
183
- ]) {
184
- const res = await context.request.post(`${base}${path}`, {
185
- form: { title: "pwn thread", body: "pwn message" },
186
- maxRedirects: 0,
170
+ test("the other account's chat is refused", async ({ page, context }) => {
171
+ await harness.signIn(context, EMAILS.owner1);
172
+ const base = harness.adminUrl;
173
+ const other = AGENTS.gamma;
174
+ const seeded = THREADS.gamma;
175
+ const threadId = await harness.threadIdByTitle(seeded.title);
176
+
177
+ const picked = await page.goto(
178
+ `${base}/admin/chat?agentId=${other.id}`,
179
+ );
180
+ expect(REFUSED).toContain(picked?.status());
181
+ await expect(page.getByText(seeded.title)).toHaveCount(0);
182
+
183
+ const read = await page.goto(
184
+ `${base}/admin/chat/${other.id}/threads/${threadId}`,
185
+ );
186
+ expect(REFUSED).toContain(read?.status());
187
+ await expect(page.getByText(seeded.message)).toHaveCount(0);
188
+
189
+ const before = await harness.chatThreads();
190
+ for (const path of [
191
+ `/admin/chat/${other.id}/threads`,
192
+ `/admin/chat/${other.id}/threads/${threadId}/messages`,
193
+ `/admin/chat/${other.id}/threads/${threadId}/delete`,
194
+ ]) {
195
+ const res = await context.request.post(`${base}${path}`, {
196
+ form: { title: "pwn thread", body: "pwn message" },
197
+ maxRedirects: 0,
198
+ });
199
+ expect(REFUSED, `POST ${path}`).toContain(res.status());
200
+ }
201
+ const after = await harness.chatThreads();
202
+ expect(after.map((t) => [t.id, t.title]).sort()).toEqual(
203
+ before.map((t) => [t.id, t.title]).sort(),
204
+ );
205
+ expect(
206
+ (await harness.chatMessages(threadId)).map((m) => m.body),
207
+ ).toEqual([seeded.message]);
187
208
  });
188
- expect(REFUSED, `POST ${path}`).toContain(res.status());
189
- }
190
- const after = await harness.chatThreads();
191
- expect(after.map((t) => [t.id, t.title]).sort()).toEqual(
192
- before.map((t) => [t.id, t.title]).sort(),
193
- );
194
- expect((await harness.chatMessages(threadId)).map((m) => m.body)).toEqual([
195
- seeded.message,
196
- ]);
197
- });
198
209
 
199
- test("admin-only pages are refused", async ({ page, context }) => {
200
- await harness.signIn(context, EMAILS.owner1);
201
- const base = harness.adminUrl;
202
- for (const path of [
203
- "/admin/settings/github-enterprise",
204
- "/admin/accounts",
205
- `/admin/accounts/${AGENTS.gamma.accountId}`,
206
- ]) {
207
- const res = await page.goto(`${base}${path}`);
208
- expect(REFUSED, path).toContain(res?.status());
209
- await expect(page.getByText("Account Two")).toHaveCount(0);
210
- }
211
- for (const path of ["/accounts", `/accounts/${AGENTS.gamma.accountId}`]) {
212
- const res = await context.request.get(`${base}${path}`);
213
- expect(REFUSED, `GET ${path}`).toContain(res.status());
214
- expect(await res.text()).not.toContain("Account Two");
215
- }
216
- const post = await context.request.post(
217
- `${base}/admin/accounts/${AGENTS.gamma.accountId}`,
218
- { form: { name: "pwned" }, maxRedirects: 0 },
219
- );
220
- expect(REFUSED).toContain(post.status());
221
- });
210
+ test("admin-only pages are refused", async ({ page, context }) => {
211
+ await harness.signIn(context, EMAILS.owner1);
212
+ const base = harness.adminUrl;
213
+ for (const path of [
214
+ "/admin/settings/github-enterprise",
215
+ "/admin/accounts",
216
+ `/admin/accounts/${AGENTS.gamma.accountId}`,
217
+ ]) {
218
+ const res = await page.goto(`${base}${path}`);
219
+ expect(REFUSED, path).toContain(res?.status());
220
+ await expect(page.getByText("Account Two")).toHaveCount(0);
221
+ }
222
+ for (const path of [
223
+ "/accounts",
224
+ `/accounts/${AGENTS.gamma.accountId}`,
225
+ ]) {
226
+ const res = await context.request.get(`${base}${path}`);
227
+ expect(REFUSED, `GET ${path}`).toContain(res.status());
228
+ expect(await res.text()).not.toContain("Account Two");
229
+ }
230
+ const post = await context.request.post(
231
+ `${base}/admin/accounts/${AGENTS.gamma.accountId}`,
232
+ { form: { name: "pwned" }, maxRedirects: 0 },
233
+ );
234
+ expect(REFUSED).toContain(post.status());
235
+ });
222
236
 
223
- test("nothing in the other account was changed", async ({ context }) => {
224
- await harness.signIn(context, EMAILS.admin);
225
- const res = await context.request.get(
226
- `${harness.adminUrl}/agents/${AGENTS.gamma.id}`,
227
- );
228
- const row = (await res.json()) as {
229
- name: string;
230
- repos: string[];
231
- accountId: string;
232
- };
233
- expect(row.name).toBe(AGENTS.gamma.name);
234
- expect(row.repos).toEqual([...AGENTS.gamma.repos]);
235
- expect(row.accountId).toBe(AGENTS.gamma.accountId);
237
+ test("nothing in the other account was changed", async ({ context }) => {
238
+ await harness.signIn(context, EMAILS.admin);
239
+ const res = await context.request.get(
240
+ `${harness.adminUrl}/agents/${AGENTS.gamma.id}`,
241
+ );
242
+ const row = (await res.json()) as {
243
+ name: string;
244
+ repos: string[];
245
+ accountId: string;
246
+ };
247
+ expect(row.name).toBe(AGENTS.gamma.name);
248
+ expect(row.repos).toEqual([...AGENTS.gamma.repos]);
249
+ expect(row.accountId).toBe(AGENTS.gamma.accountId);
250
+ });
251
+ });
236
252
  });
237
- });
253
+ }
@@ -9147,7 +9147,7 @@
9147
9147
  }
9148
9148
  },
9149
9149
  "403": {
9150
- "description": "Forbidden (caller has no account, or names another account / the deployment scope)",
9150
+ "description": "Forbidden (caller is not an account owner, or names another account / the deployment scope)",
9151
9151
  "content": {
9152
9152
  "application/json": {
9153
9153
  "schema": {
@@ -9225,7 +9225,7 @@
9225
9225
  }
9226
9226
  },
9227
9227
  "403": {
9228
- "description": "Forbidden (caller has no account, or names another account / the deployment scope)",
9228
+ "description": "Forbidden (caller is not an account owner, or names another account / the deployment scope)",
9229
9229
  "content": {
9230
9230
  "application/json": {
9231
9231
  "schema": {
@@ -9296,7 +9296,7 @@
9296
9296
  }
9297
9297
  },
9298
9298
  "403": {
9299
- "description": "Forbidden (caller has no account, or names another account / the deployment scope)",
9299
+ "description": "Forbidden (caller is not an account owner, or names another account / the deployment scope)",
9300
9300
  "content": {
9301
9301
  "application/json": {
9302
9302
  "schema": {
@@ -9348,7 +9348,7 @@
9348
9348
  }
9349
9349
  },
9350
9350
  "403": {
9351
- "description": "Forbidden (caller has no account, or names another account / the deployment scope)",
9351
+ "description": "Forbidden (caller is not an account owner, or names another account / the deployment scope)",
9352
9352
  "content": {
9353
9353
  "application/json": {
9354
9354
  "schema": {
@@ -9428,7 +9428,7 @@
9428
9428
  }
9429
9429
  },
9430
9430
  "403": {
9431
- "description": "Forbidden (caller has no account, or names another account / the deployment scope)",
9431
+ "description": "Forbidden (caller is not an account owner, or names another account / the deployment scope)",
9432
9432
  "content": {
9433
9433
  "application/json": {
9434
9434
  "schema": {
@@ -9507,7 +9507,7 @@
9507
9507
  }
9508
9508
  },
9509
9509
  "403": {
9510
- "description": "Forbidden (caller has no account, or names another account / the deployment scope)",
9510
+ "description": "Forbidden (caller is not an account owner, or names another account / the deployment scope)",
9511
9511
  "content": {
9512
9512
  "application/json": {
9513
9513
  "schema": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-admin",
3
- "version": "1.108.0",
3
+ "version": "1.108.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@anthropic-ai/sdk": "0.137.0",
47
- "@app-vitals/agent-lib": "1.108.0",
47
+ "@app-vitals/agent-lib": "1.108.1",
48
48
  "@hono/zod-openapi": "^1.0.0",
49
49
  "@prisma/adapter-pg": "^7.10.0",
50
50
  "@prisma/client": "^7.10.0",
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * admin/src/account-created-notifier.ts
3
- * Best-effort operator notification when self-serve sign-in auto-creates an
3
+ * Best-effort operator notification when self-serve signup auto-creates an
4
4
  * account (SSP-3.3). Reuses the existing web-push wiring — no new integration.
5
5
  * When push isn't configured, the structured `account_created` log emitted by
6
6
  * the Google callback (SSP-3.1) is the only signal.
@@ -98,4 +98,73 @@ describeOrSkip("AccountOnboardingService (integration)", () => {
98
98
  expect(results.every((r) => r.accountId === owner.id)).toBe(true);
99
99
  expect(results.filter((r) => r.kind === "joined")).toHaveLength(1);
100
100
  });
101
+
102
+ describe("joinForEmail (signup off)", () => {
103
+ it("returns null for an unknown email and creates nothing", async () => {
104
+ expect(await onboarding.joinForEmail("Stranger@x.com")).toBeNull();
105
+ expect(await prisma.account.count()).toBe(0);
106
+ expect(await prisma.accountMember.count()).toBe(0);
107
+ });
108
+
109
+ it("joins the invited account as member and marks the invite accepted", async () => {
110
+ const owner = await new AccountService(prisma).create(
111
+ "Acme",
112
+ "o@acme.com",
113
+ );
114
+ await new AccountInviteService(prisma).create(
115
+ owner.id,
116
+ "invitee@acme.com",
117
+ "o@acme.com",
118
+ );
119
+ expect(await onboarding.joinForEmail("Invitee@Acme.com")).toEqual({
120
+ kind: "joined",
121
+ accountId: owner.id,
122
+ });
123
+ expect(await prisma.account.count()).toBe(1);
124
+ const member = await prisma.accountMember.findUniqueOrThrow({
125
+ where: { email: "invitee@acme.com" },
126
+ });
127
+ expect(member.role).toBe("member");
128
+ const invite = await prisma.accountInvite.findFirstOrThrow({
129
+ where: { email: "invitee@acme.com" },
130
+ });
131
+ expect(invite.acceptedAt).not.toBeNull();
132
+ });
133
+
134
+ it("returns existing for an account owner with no agents", async () => {
135
+ const owner = await new AccountService(prisma).create(
136
+ "Acme",
137
+ "o@acme.com",
138
+ );
139
+ expect(await onboarding.joinForEmail("O@acme.com")).toEqual({
140
+ kind: "existing",
141
+ accountId: owner.id,
142
+ });
143
+ expect(await prisma.account.count()).toBe(1);
144
+ });
145
+
146
+ it("concurrent joins with a pending invite join once", async () => {
147
+ const owner = await new AccountService(prisma).create(
148
+ "Acme",
149
+ "o@acme.com",
150
+ );
151
+ await new AccountInviteService(prisma).create(
152
+ owner.id,
153
+ "race@acme.com",
154
+ "o@acme.com",
155
+ );
156
+ const results = await Promise.all(
157
+ Array.from({ length: 6 }, () =>
158
+ onboarding.joinForEmail("race@acme.com"),
159
+ ),
160
+ );
161
+ expect(new Set(results.map((r) => r?.accountId))).toEqual(
162
+ new Set([owner.id]),
163
+ );
164
+ expect(await prisma.account.count()).toBe(1);
165
+ expect(
166
+ await prisma.accountMember.count({ where: { email: "race@acme.com" } }),
167
+ ).toBe(1);
168
+ });
169
+ });
101
170
  });