@app-vitals/agent-admin 1.106.2 → 1.107.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.
- package/e2e/real/admin-access.real.e2e.ts +88 -0
- package/e2e/real/agents-real.real.e2e.ts +116 -0
- package/e2e/real/constants.ts +73 -0
- package/e2e/real/fixture.ts +120 -0
- package/e2e/real/harness.ts +191 -0
- package/e2e/real/member-access-self-serve.real.e2e.ts +114 -0
- package/e2e/real/member-agents.real.e2e.ts +267 -0
- package/e2e/real/member-chat.real.e2e.ts +153 -0
- package/e2e/real/owner-access.real.e2e.ts +237 -0
- package/e2e/real/seed.ts +105 -0
- package/e2e/real/session.ts +29 -0
- package/openapi.json +0 -280
- package/openapi.platform.json +0 -280
- package/package.json +2 -2
- package/playwright.config.ts +11 -0
- package/prisma/client/browser.ts +0 -10
- package/prisma/client/client.ts +0 -10
- package/prisma/client/internal/class.ts +4 -24
- package/prisma/client/internal/prismaNamespace.ts +1 -181
- package/prisma/client/internal/prismaNamespaceBrowser.ts +0 -30
- package/prisma/client/models.ts +0 -2
- package/prisma/migrations/20261129000000_drop_cron_run_transcripts/migration.sql +9 -0
- package/prisma/schema/schema.prisma +0 -34
- package/src/admin-boot.ts +0 -11
- package/src/admin-ui.ts +2 -1
- package/src/agents-api.ts +0 -13
- package/src/api.smoke.test.ts +6 -73
- package/src/api.ts +0 -17
- package/src/cron-run-now.integration.test.ts +163 -0
- package/src/cron-run-transcripts-removed.smoke.test.ts +82 -0
- package/src/drop-cron-run-transcripts-migration.integration.test.ts +114 -0
- package/src/openapi-schemas.ts +0 -55
- package/src/repo-access-config.ts +1 -1
- package/src/secrets-equal.ts +8 -0
- package/src/secrets-equal.unit.test.ts +15 -0
- package/prisma/client/models/AgentCronRunTranscript.ts +0 -1339
- package/prisma/client/models/AgentTranscriptRead.ts +0 -1177
- package/src/cron-run-transcripts.integration.test.ts +0 -220
- package/src/cron-run-transcripts.smoke.test.ts +0 -286
- package/src/cron-run-transcripts.ts +0 -314
- package/src/transcript-config.ts +0 -30
- package/src/transcript-config.unit.test.ts +0 -50
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/e2e/real/member-agents.real.e2e.ts
|
|
3
|
+
*
|
|
4
|
+
* Real-service e2e, self-serve OFF (matches production): what a member
|
|
5
|
+
* (member1, an AgentMember of Alpha only) sees and what is refused on the
|
|
6
|
+
* Agents pages, Settings, Account pages and agent creation. Checks direct URLs
|
|
7
|
+
* and requests, not only navigation, and that each refusal changed nothing
|
|
8
|
+
* (verified as the platform admin afterwards).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { expect, test } from "@playwright/test";
|
|
12
|
+
import { AGENTS, EMAILS } from "./constants.ts";
|
|
13
|
+
import { RealHarness } from "./fixture.ts";
|
|
14
|
+
|
|
15
|
+
const harness = new RealHarness({
|
|
16
|
+
selfServe: false,
|
|
17
|
+
adminPort: 3514,
|
|
18
|
+
chatPort: 3515,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test.describe.configure({ mode: "serial" });
|
|
22
|
+
|
|
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
|
+
const REFUSED = [403, 404];
|
|
32
|
+
|
|
33
|
+
test.describe("member, self-serve off: agents", () => {
|
|
34
|
+
test("Agents list shows only the member's agents", async ({
|
|
35
|
+
page,
|
|
36
|
+
context,
|
|
37
|
+
}) => {
|
|
38
|
+
await harness.signIn(context, EMAILS.member1);
|
|
39
|
+
await page.goto(`${harness.adminUrl}/admin/agents`);
|
|
40
|
+
await expect(page.getByText(AGENTS.alpha.name).first()).toBeVisible();
|
|
41
|
+
await expect(page.getByText(AGENTS.beta.name)).toHaveCount(0);
|
|
42
|
+
await expect(page.getByText(AGENTS.gamma.name)).toHaveCount(0);
|
|
43
|
+
// No create entry point for a member.
|
|
44
|
+
await expect(page.locator('a[href="/admin/agents/new"]')).toHaveCount(0);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("JSON agent list is scoped to the member's agents", async ({
|
|
48
|
+
context,
|
|
49
|
+
}) => {
|
|
50
|
+
await harness.signIn(context, EMAILS.member1);
|
|
51
|
+
const res = await context.request.get(`${harness.adminUrl}/agents`);
|
|
52
|
+
expect(res.status()).toBe(200);
|
|
53
|
+
const ids = ((await res.json()) as { id: string }[]).map((a) => a.id);
|
|
54
|
+
expect(ids).toEqual([AGENTS.alpha.id]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("member opens their own agent page and JSON record", async ({
|
|
58
|
+
page,
|
|
59
|
+
context,
|
|
60
|
+
}) => {
|
|
61
|
+
await harness.signIn(context, EMAILS.member1);
|
|
62
|
+
const res = await page.goto(
|
|
63
|
+
`${harness.adminUrl}/admin/agents/${AGENTS.alpha.id}`,
|
|
64
|
+
);
|
|
65
|
+
expect(res?.status()).toBe(200);
|
|
66
|
+
await expect(page.getByText(AGENTS.alpha.name).first()).toBeVisible();
|
|
67
|
+
const json = await context.request.get(
|
|
68
|
+
`${harness.adminUrl}/agents/${AGENTS.alpha.id}`,
|
|
69
|
+
);
|
|
70
|
+
expect(json.status()).toBe(200);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
for (const other of [AGENTS.beta, AGENTS.gamma]) {
|
|
74
|
+
test(`direct URLs and requests for ${other.name} are refused`, async ({
|
|
75
|
+
page,
|
|
76
|
+
context,
|
|
77
|
+
}) => {
|
|
78
|
+
await harness.signIn(context, EMAILS.member1);
|
|
79
|
+
const base = harness.adminUrl;
|
|
80
|
+
|
|
81
|
+
// Direct page URLs (and sub-pages).
|
|
82
|
+
for (const path of [
|
|
83
|
+
`/admin/agents/${other.id}`,
|
|
84
|
+
`/admin/agents/${other.id}/setup`,
|
|
85
|
+
]) {
|
|
86
|
+
const res = await page.goto(`${base}${path}`);
|
|
87
|
+
expect(REFUSED, path).toContain(res?.status());
|
|
88
|
+
await expect(page.getByText(other.name)).toHaveCount(0);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Direct JSON reads.
|
|
92
|
+
for (const path of [
|
|
93
|
+
`/agents/${other.id}`,
|
|
94
|
+
`/agents/${other.id}/envs`,
|
|
95
|
+
`/agents/${other.id}/crons`,
|
|
96
|
+
`/agents/${other.id}/tokens`,
|
|
97
|
+
]) {
|
|
98
|
+
const res = await context.request.get(`${base}${path}`);
|
|
99
|
+
expect(REFUSED, `GET ${path}`).toContain(res.status());
|
|
100
|
+
expect(await res.text()).not.toContain(other.name);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Writes: JSON API.
|
|
104
|
+
const writes: [string, string, unknown?][] = [
|
|
105
|
+
["PATCH", `/agents/${other.id}`, { repos: ["evil-org/pwn"] }],
|
|
106
|
+
["POST", `/agents/${other.id}/repos`, { repos: ["evil-org/pwn"] }],
|
|
107
|
+
["DELETE", `/agents/${other.id}`],
|
|
108
|
+
];
|
|
109
|
+
for (const [method, path, data] of writes) {
|
|
110
|
+
const res = await context.request.fetch(`${base}${path}`, {
|
|
111
|
+
method,
|
|
112
|
+
...(data ? { data } : {}),
|
|
113
|
+
});
|
|
114
|
+
expect(REFUSED, `${method} ${path}`).toContain(res.status());
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Writes: UI form posts (no redirects followed, so a 302 is visible).
|
|
118
|
+
for (const path of [
|
|
119
|
+
`/admin/agents/${other.id}/settings`,
|
|
120
|
+
`/admin/agents/${other.id}/members`,
|
|
121
|
+
`/admin/agents/${other.id}/envs`,
|
|
122
|
+
`/admin/agents/${other.id}/delete`,
|
|
123
|
+
]) {
|
|
124
|
+
const res = await context.request.post(`${base}${path}`, {
|
|
125
|
+
form: { email: "member1@e2e.test", key: "K", value: "V" },
|
|
126
|
+
maxRedirects: 0,
|
|
127
|
+
});
|
|
128
|
+
expect(REFUSED, `POST ${path}`).toContain(res.status());
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
test("nothing was changed by the refused requests", async ({ context }) => {
|
|
134
|
+
await harness.signIn(context, EMAILS.admin);
|
|
135
|
+
const res = await context.request.get(`${harness.adminUrl}/agents`);
|
|
136
|
+
const agents = (await res.json()) as { id: string }[];
|
|
137
|
+
expect(agents.map((a) => a.id).sort()).toEqual(
|
|
138
|
+
Object.values(AGENTS)
|
|
139
|
+
.map((a) => a.id)
|
|
140
|
+
.sort(),
|
|
141
|
+
);
|
|
142
|
+
for (const seeded of Object.values(AGENTS)) {
|
|
143
|
+
const detail = await context.request.get(
|
|
144
|
+
`${harness.adminUrl}/agents/${seeded.id}`,
|
|
145
|
+
);
|
|
146
|
+
const row = (await detail.json()) as {
|
|
147
|
+
name: string;
|
|
148
|
+
repos: string[];
|
|
149
|
+
accountId: string;
|
|
150
|
+
};
|
|
151
|
+
expect(row.name).toBe(seeded.name);
|
|
152
|
+
expect(row.repos).toEqual([...seeded.repos]);
|
|
153
|
+
expect(row.accountId).toBe(seeded.accountId);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test.describe("member, self-serve off: settings and account", () => {
|
|
159
|
+
test("no settings are available: no nav and refused URLs", async ({
|
|
160
|
+
page,
|
|
161
|
+
context,
|
|
162
|
+
}) => {
|
|
163
|
+
await harness.signIn(context, EMAILS.member1);
|
|
164
|
+
const base = harness.adminUrl;
|
|
165
|
+
|
|
166
|
+
// /admin/settings has no first item for a member and shows no sidebar.
|
|
167
|
+
const landing = await page.goto(`${base}/admin/settings`);
|
|
168
|
+
expect(landing?.status()).toBe(404);
|
|
169
|
+
await expect(page.locator("nav.settings-sidebar")).toHaveCount(0);
|
|
170
|
+
|
|
171
|
+
// A page the member can reach links to none of the admin-only or
|
|
172
|
+
// owner-only items.
|
|
173
|
+
await page.goto(`${base}/admin/agents`);
|
|
174
|
+
for (const href of [
|
|
175
|
+
"/admin/settings/github-enterprise",
|
|
176
|
+
"/admin/settings/templates",
|
|
177
|
+
"/admin/settings/slack-config-token",
|
|
178
|
+
"/admin/accounts",
|
|
179
|
+
"/admin/account",
|
|
180
|
+
]) {
|
|
181
|
+
await expect(page.locator(`a[href^="${href}"]`)).toHaveCount(0);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Admin-only (GitHub Enterprise, Accounts) and owner-only (Templates,
|
|
185
|
+
// Slack config token) items, plus the Account page: refused on GET.
|
|
186
|
+
const paths = [
|
|
187
|
+
"/admin/settings/github-enterprise",
|
|
188
|
+
"/admin/settings/templates",
|
|
189
|
+
"/admin/settings/slack-config-token",
|
|
190
|
+
"/admin/accounts",
|
|
191
|
+
`/admin/accounts/${AGENTS.alpha.accountId}`,
|
|
192
|
+
"/admin/account",
|
|
193
|
+
];
|
|
194
|
+
for (const path of paths) {
|
|
195
|
+
const res = await page.goto(`${base}${path}`);
|
|
196
|
+
expect(REFUSED, path).toContain(res?.status());
|
|
197
|
+
await expect(page.locator("nav.settings-sidebar")).toHaveCount(0);
|
|
198
|
+
await expect(page.getByText("Account One")).toHaveCount(0);
|
|
199
|
+
await expect(page.getByText("Account Two")).toHaveCount(0);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// ...and on writes.
|
|
203
|
+
for (const path of [
|
|
204
|
+
"/admin/settings/github-enterprise/apps/installer",
|
|
205
|
+
"/admin/settings/templates/items",
|
|
206
|
+
"/admin/settings/slack-config-token/save",
|
|
207
|
+
`/admin/accounts/${AGENTS.alpha.accountId}`,
|
|
208
|
+
"/admin/account/name",
|
|
209
|
+
]) {
|
|
210
|
+
const res = await context.request.post(`${base}${path}`, {
|
|
211
|
+
form: { name: "pwned", token: "xoxe-1-pwn" },
|
|
212
|
+
maxRedirects: 0,
|
|
213
|
+
});
|
|
214
|
+
expect(REFUSED, `POST ${path}`).toContain(res.status());
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test("account JSON APIs are unavailable to a member", async ({ context }) => {
|
|
219
|
+
await harness.signIn(context, EMAILS.member1);
|
|
220
|
+
const base = harness.adminUrl;
|
|
221
|
+
for (const path of ["/accounts", `/accounts/${AGENTS.alpha.accountId}`]) {
|
|
222
|
+
const res = await context.request.get(`${base}${path}`);
|
|
223
|
+
expect(REFUSED, path).toContain(res.status());
|
|
224
|
+
expect(await res.text()).not.toContain("Account One");
|
|
225
|
+
}
|
|
226
|
+
const tpl = await context.request.get(`${base}/templates`);
|
|
227
|
+
expect(REFUSED).toContain(tpl.status());
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test.describe("member, self-serve off: agent creation", () => {
|
|
232
|
+
test("UI: no entry point, the form and its post are refused", async ({
|
|
233
|
+
page,
|
|
234
|
+
context,
|
|
235
|
+
}) => {
|
|
236
|
+
await harness.signIn(context, EMAILS.member1);
|
|
237
|
+
const base = harness.adminUrl;
|
|
238
|
+
const form = await page.goto(`${base}/admin/agents/new`);
|
|
239
|
+
expect(form?.status()).toBe(403);
|
|
240
|
+
const post = await context.request.post(`${base}/admin/agents`, {
|
|
241
|
+
form: { name: "Hax Agent", type: "specialist", repos: "evil-org/pwn" },
|
|
242
|
+
maxRedirects: 0,
|
|
243
|
+
});
|
|
244
|
+
expect(REFUSED).toContain(post.status());
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test("JSON API: creating an agent is refused", async ({ context }) => {
|
|
248
|
+
await harness.signIn(context, EMAILS.member1);
|
|
249
|
+
const res = await context.request.post(`${harness.adminUrl}/agents`, {
|
|
250
|
+
data: { name: "Hax Agent Two", specialty: "specialist" },
|
|
251
|
+
});
|
|
252
|
+
expect(REFUSED).toContain(res.status());
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test("no agent was created", async ({ page, context }) => {
|
|
256
|
+
await harness.signIn(context, EMAILS.admin);
|
|
257
|
+
const res = await context.request.get(`${harness.adminUrl}/agents`);
|
|
258
|
+
const names = ((await res.json()) as { name: string }[]).map((a) => a.name);
|
|
259
|
+
expect(names.sort()).toEqual(
|
|
260
|
+
Object.values(AGENTS)
|
|
261
|
+
.map((a) => a.name)
|
|
262
|
+
.sort(),
|
|
263
|
+
);
|
|
264
|
+
await page.goto(`${harness.adminUrl}/admin/agents`);
|
|
265
|
+
await expect(page.getByText("Hax Agent")).toHaveCount(0);
|
|
266
|
+
});
|
|
267
|
+
});
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/e2e/real/member-chat.real.e2e.ts
|
|
3
|
+
*
|
|
4
|
+
* Real-service e2e, self-serve OFF: Chat for a member (member1, an
|
|
5
|
+
* AgentMember of Alpha only) against the real admin app and real chat service
|
|
6
|
+
* with seeded threads. The member can pick and use Alpha; direct URLs and
|
|
7
|
+
* requests for another agent's threads and messages (reads and writes) are
|
|
8
|
+
* refused, and the chat service is checked afterwards to prove nothing changed.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { expect, test } from "@playwright/test";
|
|
12
|
+
import { AGENTS, EMAILS, THREADS } from "./constants.ts";
|
|
13
|
+
import { RealHarness } from "./fixture.ts";
|
|
14
|
+
|
|
15
|
+
const harness = new RealHarness({
|
|
16
|
+
selfServe: false,
|
|
17
|
+
adminPort: 3516,
|
|
18
|
+
chatPort: 3517,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test.describe.configure({ mode: "serial" });
|
|
22
|
+
|
|
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
|
+
const REFUSED = [403, 404];
|
|
32
|
+
|
|
33
|
+
test.describe("member, self-serve off: chat", () => {
|
|
34
|
+
test("picker lists only the member's agents", async ({ page, context }) => {
|
|
35
|
+
await harness.signIn(context, EMAILS.member1);
|
|
36
|
+
await page.goto(`${harness.adminUrl}/admin/chat`);
|
|
37
|
+
const options = await page.locator("#agentId option").allTextContents();
|
|
38
|
+
expect(options.filter((o) => o.trim() && !o.includes("select"))).toEqual([
|
|
39
|
+
AGENTS.alpha.name,
|
|
40
|
+
]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("member uses chat on their agent: threads, read, send, new thread", async ({
|
|
44
|
+
page,
|
|
45
|
+
context,
|
|
46
|
+
}) => {
|
|
47
|
+
await harness.signIn(context, EMAILS.member1);
|
|
48
|
+
await page.goto(`${harness.adminUrl}/admin/chat`);
|
|
49
|
+
await page.locator("#agentId").selectOption(AGENTS.alpha.id);
|
|
50
|
+
await expect(page).toHaveURL(new RegExp(`agentId=${AGENTS.alpha.id}`));
|
|
51
|
+
await expect(page.getByText(THREADS.alpha.title)).toBeVisible();
|
|
52
|
+
// Another agent's threads never appear in the list.
|
|
53
|
+
await expect(page.getByText(THREADS.beta.title)).toHaveCount(0);
|
|
54
|
+
await expect(page.getByText(THREADS.gamma.title)).toHaveCount(0);
|
|
55
|
+
|
|
56
|
+
await page.getByText(THREADS.alpha.title).click();
|
|
57
|
+
await expect(page.getByText(THREADS.alpha.message)).toBeVisible();
|
|
58
|
+
|
|
59
|
+
await page.locator("#message-input").fill("hello from the member");
|
|
60
|
+
await page.locator("#send-btn").click();
|
|
61
|
+
await expect(page.getByText("hello from the member")).toBeVisible();
|
|
62
|
+
|
|
63
|
+
const alphaThread = await harness.threadIdByTitle(THREADS.alpha.title);
|
|
64
|
+
await expect
|
|
65
|
+
.poll(async () =>
|
|
66
|
+
(await harness.chatMessages(alphaThread)).map((m) => m.body),
|
|
67
|
+
)
|
|
68
|
+
.toContain("hello from the member");
|
|
69
|
+
|
|
70
|
+
// Create a new thread through the UI form.
|
|
71
|
+
await page.goto(
|
|
72
|
+
`${harness.adminUrl}/admin/chat?agentId=${AGENTS.alpha.id}`,
|
|
73
|
+
);
|
|
74
|
+
await page.locator('input[name="title"]').first().fill("Member new thread");
|
|
75
|
+
await page
|
|
76
|
+
.getByRole("button", { name: /new thread|create|start/i })
|
|
77
|
+
.click();
|
|
78
|
+
await expect(page).toHaveURL(
|
|
79
|
+
new RegExp(`/admin/chat/${AGENTS.alpha.id}/threads/`),
|
|
80
|
+
);
|
|
81
|
+
const created = (await harness.chatThreads()).find(
|
|
82
|
+
(t) => t.title === "Member new thread",
|
|
83
|
+
);
|
|
84
|
+
expect(created?.agentId).toBe(AGENTS.alpha.id);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
for (const key of ["beta", "gamma"] as const) {
|
|
88
|
+
const agent = AGENTS[key];
|
|
89
|
+
const seeded = THREADS[key];
|
|
90
|
+
|
|
91
|
+
test(`${agent.name}: chat reads are refused`, async ({ page, context }) => {
|
|
92
|
+
await harness.signIn(context, EMAILS.member1);
|
|
93
|
+
const base = harness.adminUrl;
|
|
94
|
+
const threadId = await harness.threadIdByTitle(seeded.title);
|
|
95
|
+
|
|
96
|
+
// Picking another agent in the Chat page.
|
|
97
|
+
const picked = await page.goto(`${base}/admin/chat?agentId=${agent.id}`);
|
|
98
|
+
expect(REFUSED).toContain(picked?.status());
|
|
99
|
+
await expect(page.getByText(seeded.title)).toHaveCount(0);
|
|
100
|
+
|
|
101
|
+
// Its thread, under its own agent id and under the member's agent id.
|
|
102
|
+
for (const agentId of [agent.id, AGENTS.alpha.id]) {
|
|
103
|
+
const path = `/admin/chat/${agentId}/threads/${threadId}`;
|
|
104
|
+
const res = await page.goto(`${base}${path}`);
|
|
105
|
+
expect(REFUSED, path).toContain(res?.status());
|
|
106
|
+
await expect(page.getByText(seeded.message)).toHaveCount(0);
|
|
107
|
+
|
|
108
|
+
const att = await context.request.get(
|
|
109
|
+
`${base}${path}/messages/anything/attachment`,
|
|
110
|
+
);
|
|
111
|
+
expect(REFUSED, `attachment ${path}`).toContain(att.status());
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test(`${agent.name}: chat writes are refused and change nothing`, async ({
|
|
116
|
+
context,
|
|
117
|
+
}) => {
|
|
118
|
+
await harness.signIn(context, EMAILS.member1);
|
|
119
|
+
const base = harness.adminUrl;
|
|
120
|
+
const threadId = await harness.threadIdByTitle(seeded.title);
|
|
121
|
+
const before = await harness.chatThreads();
|
|
122
|
+
|
|
123
|
+
const posts: [string, Record<string, string>][] = [
|
|
124
|
+
[`/admin/chat/${agent.id}/threads`, { title: "pwn thread" }],
|
|
125
|
+
];
|
|
126
|
+
for (const agentId of [agent.id, AGENTS.alpha.id]) {
|
|
127
|
+
const t = `/admin/chat/${agentId}/threads/${threadId}`;
|
|
128
|
+
posts.push(
|
|
129
|
+
[`${t}/messages`, { body: "pwn message" }],
|
|
130
|
+
[`${t}/messages/upload`, { body: "pwn upload" }],
|
|
131
|
+
[`${t}/rename`, { title: "pwned title" }],
|
|
132
|
+
[`${t}/delete`, {}],
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
for (const [path, form] of posts) {
|
|
136
|
+
const res = await context.request.post(`${base}${path}`, {
|
|
137
|
+
form,
|
|
138
|
+
maxRedirects: 0,
|
|
139
|
+
});
|
|
140
|
+
expect(REFUSED, `POST ${path}`).toContain(res.status());
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// The chat service is unchanged: same threads, titles, one message.
|
|
144
|
+
const after = await harness.chatThreads();
|
|
145
|
+
expect(after.map((t) => [t.id, t.agentId, t.title]).sort()).toEqual(
|
|
146
|
+
before.map((t) => [t.id, t.agentId, t.title]).sort(),
|
|
147
|
+
);
|
|
148
|
+
expect((await harness.chatMessages(threadId)).map((m) => m.body)).toEqual(
|
|
149
|
+
[seeded.message],
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
});
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/e2e/real/owner-access.real.e2e.ts
|
|
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
|
|
7
|
+
* for Account Two's agents, its chat and the admin-only pages are refused, and
|
|
8
|
+
* each refusal is shown to have changed nothing.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { expect, test } from "@playwright/test";
|
|
12
|
+
import { AGENTS, EMAILS, THREADS } from "./constants.ts";
|
|
13
|
+
import { RealHarness } from "./fixture.ts";
|
|
14
|
+
|
|
15
|
+
const harness = new RealHarness({
|
|
16
|
+
selfServe: true,
|
|
17
|
+
adminPort: 3520,
|
|
18
|
+
chatPort: 3521,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test.describe.configure({ mode: "serial" });
|
|
22
|
+
|
|
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
|
+
const REFUSED = [403, 404];
|
|
32
|
+
|
|
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
|
+
});
|
|
65
|
+
|
|
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
|
+
});
|
|
98
|
+
|
|
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
|
+
});
|
|
105
|
+
|
|
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 } : {}),
|
|
143
|
+
});
|
|
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,
|
|
156
|
+
});
|
|
157
|
+
expect(REFUSED, `POST ${path}`).toContain(res.status());
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
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,
|
|
187
|
+
});
|
|
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
|
+
|
|
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
|
+
});
|
|
222
|
+
|
|
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);
|
|
236
|
+
});
|
|
237
|
+
});
|