@app-vitals/agent-admin 1.107.0 → 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/package.json +2 -2
- package/playwright.config.ts +11 -0
- package/src/admin-ui.ts +2 -1
- package/src/secrets-equal.ts +8 -0
- package/src/secrets-equal.unit.test.ts +15 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/e2e/real/admin-access.real.e2e.ts
|
|
3
|
+
*
|
|
4
|
+
* Real-service e2e, self-serve OFF (matches production): the platform admin
|
|
5
|
+
* (on the allowlist, in no account) sees agents from both accounts, every
|
|
6
|
+
* platform Settings item, and can open the agent creation form.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { expect, test } from "@playwright/test";
|
|
10
|
+
import { AGENTS, EMAILS } from "./constants.ts";
|
|
11
|
+
import { RealHarness } from "./fixture.ts";
|
|
12
|
+
|
|
13
|
+
const harness = new RealHarness({
|
|
14
|
+
selfServe: false,
|
|
15
|
+
adminPort: 3518,
|
|
16
|
+
chatPort: 3519,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test.describe.configure({ mode: "serial" });
|
|
20
|
+
|
|
21
|
+
test.beforeAll(async () => {
|
|
22
|
+
test.setTimeout(240_000);
|
|
23
|
+
await harness.start();
|
|
24
|
+
});
|
|
25
|
+
test.afterAll(async () => {
|
|
26
|
+
await harness.stop();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const SETTINGS_ITEMS = [
|
|
30
|
+
"/admin/settings/github-enterprise",
|
|
31
|
+
"/admin/settings/templates",
|
|
32
|
+
"/admin/settings/slack-config-token",
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
test.describe("platform admin, self-serve off", () => {
|
|
36
|
+
test("Agents list shows agents from both accounts", async ({
|
|
37
|
+
page,
|
|
38
|
+
context,
|
|
39
|
+
}) => {
|
|
40
|
+
await harness.signIn(context, EMAILS.admin);
|
|
41
|
+
await page.goto(`${harness.adminUrl}/admin/agents`);
|
|
42
|
+
for (const agent of Object.values(AGENTS)) {
|
|
43
|
+
await expect(page.getByText(agent.name).first()).toBeVisible();
|
|
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(
|
|
48
|
+
Object.values(AGENTS)
|
|
49
|
+
.map((a) => a.id)
|
|
50
|
+
.sort(),
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("every platform Settings item is in the nav and opens", async ({
|
|
55
|
+
page,
|
|
56
|
+
context,
|
|
57
|
+
}) => {
|
|
58
|
+
await harness.signIn(context, EMAILS.admin);
|
|
59
|
+
const base = harness.adminUrl;
|
|
60
|
+
const landing = await page.goto(`${base}/admin/settings`);
|
|
61
|
+
expect(landing?.status()).toBe(200);
|
|
62
|
+
await expect(page.locator("nav.settings-sidebar")).toBeVisible();
|
|
63
|
+
for (const href of SETTINGS_ITEMS) {
|
|
64
|
+
await expect(
|
|
65
|
+
page.locator(`nav.settings-sidebar a[href^="${href}"]`),
|
|
66
|
+
href,
|
|
67
|
+
).toHaveCount(1);
|
|
68
|
+
}
|
|
69
|
+
for (const path of SETTINGS_ITEMS) {
|
|
70
|
+
const res = await page.goto(`${base}${path}`);
|
|
71
|
+
expect(res?.status(), path).toBe(200);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test("the admin can open the agent creation form", async ({
|
|
76
|
+
page,
|
|
77
|
+
context,
|
|
78
|
+
}) => {
|
|
79
|
+
await harness.signIn(context, EMAILS.admin);
|
|
80
|
+
await page.goto(`${harness.adminUrl}/admin/agents`);
|
|
81
|
+
await expect(
|
|
82
|
+
page.locator('a[href="/admin/agents/new"]').first(),
|
|
83
|
+
).toBeVisible();
|
|
84
|
+
const form = await page.goto(`${harness.adminUrl}/admin/agents/new`);
|
|
85
|
+
expect(form?.status()).toBe(200);
|
|
86
|
+
await expect(page.locator("form").first()).toBeVisible();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/e2e/real/agents-real.real.e2e.ts
|
|
3
|
+
*
|
|
4
|
+
* Real-service e2e: the actual admin app + chat service on temporary Postgres
|
|
5
|
+
* databases, seeded roles, signed in with a minted admin_session cookie.
|
|
6
|
+
* Runs with self-serve off and on.
|
|
7
|
+
*
|
|
8
|
+
* 1. A request with no session is refused (redirect to /admin/login).
|
|
9
|
+
* 2. A seeded member signs in and the Agents page lists only the agents they
|
|
10
|
+
* are on, from real data; agents in other scopes are absent.
|
|
11
|
+
* 3. The platform admin sees the whole fleet.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { type ChildProcess, spawn } from "node:child_process";
|
|
15
|
+
import { dirname, resolve } from "node:path";
|
|
16
|
+
import { fileURLToPath } from "node:url";
|
|
17
|
+
import { expect, test } from "@playwright/test";
|
|
18
|
+
import { AGENTS, EMAILS, SESSION_COOKIE } from "./constants.ts";
|
|
19
|
+
import { mintSessionCookie } from "./session.ts";
|
|
20
|
+
|
|
21
|
+
const MODES = [
|
|
22
|
+
{ name: "self-serve off", selfServe: false, adminPort: 3510, chatPort: 3511 },
|
|
23
|
+
{ name: "self-serve on", selfServe: true, adminPort: 3512, chatPort: 3513 },
|
|
24
|
+
] as const;
|
|
25
|
+
|
|
26
|
+
for (const mode of MODES) {
|
|
27
|
+
test.describe(`real services, ${mode.name}`, () => {
|
|
28
|
+
test.describe.configure({ mode: "serial" });
|
|
29
|
+
const harness = { adminUrl: `http://localhost:${mode.adminPort}` };
|
|
30
|
+
let proc: ChildProcess | null = null;
|
|
31
|
+
|
|
32
|
+
// The harness is a bun process (it imports the Prisma client and the real
|
|
33
|
+
// apps); Playwright's node runner only spawns it, like the fake-server specs.
|
|
34
|
+
test.beforeAll(async () => {
|
|
35
|
+
test.setTimeout(240_000);
|
|
36
|
+
proc = spawn(
|
|
37
|
+
"bun",
|
|
38
|
+
["run", resolve(dirname(fileURLToPath(import.meta.url)), "harness.ts")],
|
|
39
|
+
{
|
|
40
|
+
env: {
|
|
41
|
+
...process.env,
|
|
42
|
+
ADMIN_E2E_SELF_SERVE: mode.selfServe ? "on" : "off",
|
|
43
|
+
ADMIN_E2E_PORT: String(mode.adminPort),
|
|
44
|
+
ADMIN_E2E_CHAT_PORT: String(mode.chatPort),
|
|
45
|
+
},
|
|
46
|
+
stdio: "pipe",
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
let ready: () => void = () => {};
|
|
50
|
+
let failed: (e: Error) => void = () => {};
|
|
51
|
+
const up = new Promise<void>((res, rej) => {
|
|
52
|
+
ready = res;
|
|
53
|
+
failed = rej;
|
|
54
|
+
});
|
|
55
|
+
proc.stdout?.on("data", (d: Buffer) => {
|
|
56
|
+
const msg = d.toString();
|
|
57
|
+
console.log("[real-harness]", msg.trim());
|
|
58
|
+
if (msg.includes("real harness up")) ready();
|
|
59
|
+
});
|
|
60
|
+
proc.stderr?.on("data", (d: Buffer) =>
|
|
61
|
+
console.error("[real-harness]", d.toString().trim()),
|
|
62
|
+
);
|
|
63
|
+
proc.on("exit", (code) => failed(new Error(`harness exited ${code}`)));
|
|
64
|
+
await up;
|
|
65
|
+
});
|
|
66
|
+
test.afterAll(async () => {
|
|
67
|
+
if (!proc) return;
|
|
68
|
+
const p = proc;
|
|
69
|
+
proc = null;
|
|
70
|
+
const exited = new Promise<void>((r) => p.once("exit", () => r()));
|
|
71
|
+
p.kill("SIGTERM");
|
|
72
|
+
await Promise.race([exited, new Promise((r) => setTimeout(r, 15_000))]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
async function signIn(
|
|
76
|
+
context: import("@playwright/test").BrowserContext,
|
|
77
|
+
email: string,
|
|
78
|
+
) {
|
|
79
|
+
await context.addCookies([
|
|
80
|
+
{
|
|
81
|
+
name: SESSION_COOKIE,
|
|
82
|
+
value: await mintSessionCookie(email),
|
|
83
|
+
url: harness.adminUrl,
|
|
84
|
+
httpOnly: true,
|
|
85
|
+
sameSite: "Lax",
|
|
86
|
+
},
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
test("no session is refused", async ({ page }) => {
|
|
91
|
+
await page.goto(`${harness.adminUrl}/admin/agents`);
|
|
92
|
+
await expect(page).toHaveURL(/\/admin\/login/);
|
|
93
|
+
await expect(page.getByText(AGENTS.alpha.name)).toHaveCount(0);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("member loads the Agents page from real data", async ({
|
|
97
|
+
page,
|
|
98
|
+
context,
|
|
99
|
+
}) => {
|
|
100
|
+
await signIn(context, EMAILS.member1);
|
|
101
|
+
await page.goto(`${harness.adminUrl}/admin/agents`);
|
|
102
|
+
await expect(page).toHaveURL(/\/admin\/agents$/);
|
|
103
|
+
await expect(page.getByText(AGENTS.alpha.name).first()).toBeVisible();
|
|
104
|
+
await expect(page.getByText(AGENTS.beta.name)).toHaveCount(0);
|
|
105
|
+
await expect(page.getByText(AGENTS.gamma.name)).toHaveCount(0);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test("platform admin sees every agent", async ({ page, context }) => {
|
|
109
|
+
await signIn(context, EMAILS.admin);
|
|
110
|
+
await page.goto(`${harness.adminUrl}/admin/agents`);
|
|
111
|
+
for (const agent of Object.values(AGENTS)) {
|
|
112
|
+
await expect(page.getByText(agent.name).first()).toBeVisible();
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/e2e/real/constants.ts
|
|
3
|
+
*
|
|
4
|
+
* Shared constants for the real-service admin e2e layer: seeded identities,
|
|
5
|
+
* ids and the throwaway secrets. Nothing here is a real credential; the whole
|
|
6
|
+
* layer runs against temporary Postgres databases on the CI service container.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const SESSION_SECRET = "e2e-real-session-secret-32chars!!!!";
|
|
10
|
+
export const CHAT_ADMIN_TOKEN = "e2e-real-chat-admin-token";
|
|
11
|
+
export const SESSION_COOKIE = "admin_session";
|
|
12
|
+
|
|
13
|
+
export const EMAILS = {
|
|
14
|
+
/** Platform admin: on the admin allowlist, in no account. */
|
|
15
|
+
admin: "admin@e2e.test",
|
|
16
|
+
owner1: "owner1@e2e.test",
|
|
17
|
+
member1: "member1@e2e.test",
|
|
18
|
+
owner2: "owner2@e2e.test",
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
21
|
+
export const ACCOUNTS = {
|
|
22
|
+
one: { id: "acct-e2e-1", name: "Account One" },
|
|
23
|
+
two: { id: "acct-e2e-2", name: "Account Two" },
|
|
24
|
+
} as const;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Agents with different repo access. member1 is an AgentMember of
|
|
28
|
+
* `alpha` only; `beta` is in the same account but the member is not on it;
|
|
29
|
+
* `gamma` is in the second account.
|
|
30
|
+
*/
|
|
31
|
+
export const AGENTS = {
|
|
32
|
+
alpha: {
|
|
33
|
+
id: "agent-e2e-alpha",
|
|
34
|
+
name: "Alpha Agent",
|
|
35
|
+
repos: ["e2e-org/alpha"],
|
|
36
|
+
accountId: ACCOUNTS.one.id,
|
|
37
|
+
},
|
|
38
|
+
beta: {
|
|
39
|
+
id: "agent-e2e-beta",
|
|
40
|
+
name: "Beta Agent",
|
|
41
|
+
repos: ["e2e-org/beta"],
|
|
42
|
+
accountId: ACCOUNTS.one.id,
|
|
43
|
+
},
|
|
44
|
+
gamma: {
|
|
45
|
+
id: "agent-e2e-gamma",
|
|
46
|
+
name: "Gamma Agent",
|
|
47
|
+
repos: ["e2e-org/gamma"],
|
|
48
|
+
accountId: ACCOUNTS.two.id,
|
|
49
|
+
},
|
|
50
|
+
} as const;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Chat threads seeded through the real chat service (seed.ts `seedChatService`),
|
|
54
|
+
* one per agent. Specs find the generated thread ids by listing the chat
|
|
55
|
+
* service (CHAT_ADMIN_TOKEN) and matching on title.
|
|
56
|
+
*/
|
|
57
|
+
export const THREADS = {
|
|
58
|
+
alpha: {
|
|
59
|
+
title: "Alpha seeded thread",
|
|
60
|
+
message: "alpha seeded message body",
|
|
61
|
+
agent: "alpha",
|
|
62
|
+
},
|
|
63
|
+
beta: {
|
|
64
|
+
title: "Beta seeded thread",
|
|
65
|
+
message: "beta seeded message body",
|
|
66
|
+
agent: "beta",
|
|
67
|
+
},
|
|
68
|
+
gamma: {
|
|
69
|
+
title: "Gamma seeded thread",
|
|
70
|
+
message: "gamma seeded message body",
|
|
71
|
+
agent: "gamma",
|
|
72
|
+
},
|
|
73
|
+
} as const;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/e2e/real/fixture.ts
|
|
3
|
+
*
|
|
4
|
+
* Shared plumbing for the real-service specs: boots harness.ts (a bun process;
|
|
5
|
+
* Playwright's node runner only spawns it), signs a context in with a minted
|
|
6
|
+
* admin_session cookie, and reads chat state straight from the real chat
|
|
7
|
+
* service so specs can prove a refused request changed nothing.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { type ChildProcess, spawn } from "node:child_process";
|
|
11
|
+
import { dirname, resolve } from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
import type { BrowserContext } from "@playwright/test";
|
|
14
|
+
import { CHAT_ADMIN_TOKEN, SESSION_COOKIE } from "./constants.ts";
|
|
15
|
+
import { mintSessionCookie } from "./session.ts";
|
|
16
|
+
|
|
17
|
+
export interface RealMode {
|
|
18
|
+
selfServe: boolean;
|
|
19
|
+
adminPort: number;
|
|
20
|
+
chatPort: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ChatThreadRow {
|
|
24
|
+
id: string;
|
|
25
|
+
agentId: string;
|
|
26
|
+
title: string | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface ChatMessageRow {
|
|
30
|
+
id: string;
|
|
31
|
+
role: string;
|
|
32
|
+
body: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class RealHarness {
|
|
36
|
+
readonly adminUrl: string;
|
|
37
|
+
readonly chatUrl: string;
|
|
38
|
+
private proc: ChildProcess | null = null;
|
|
39
|
+
|
|
40
|
+
constructor(private readonly mode: RealMode) {
|
|
41
|
+
this.adminUrl = `http://localhost:${mode.adminPort}`;
|
|
42
|
+
this.chatUrl = `http://localhost:${mode.chatPort}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async start(): Promise<void> {
|
|
46
|
+
const proc = spawn(
|
|
47
|
+
"bun",
|
|
48
|
+
["run", resolve(dirname(fileURLToPath(import.meta.url)), "harness.ts")],
|
|
49
|
+
{
|
|
50
|
+
env: {
|
|
51
|
+
...process.env,
|
|
52
|
+
ADMIN_E2E_SELF_SERVE: this.mode.selfServe ? "on" : "off",
|
|
53
|
+
ADMIN_E2E_PORT: String(this.mode.adminPort),
|
|
54
|
+
ADMIN_E2E_CHAT_PORT: String(this.mode.chatPort),
|
|
55
|
+
},
|
|
56
|
+
stdio: "pipe",
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
this.proc = proc;
|
|
60
|
+
let ready: () => void = () => {};
|
|
61
|
+
let failed: (e: Error) => void = () => {};
|
|
62
|
+
const up = new Promise<void>((res, rej) => {
|
|
63
|
+
ready = res;
|
|
64
|
+
failed = rej;
|
|
65
|
+
});
|
|
66
|
+
proc.stdout?.on("data", (d: Buffer) => {
|
|
67
|
+
if (d.toString().includes("real harness up")) ready();
|
|
68
|
+
});
|
|
69
|
+
proc.stderr?.on("data", (d: Buffer) =>
|
|
70
|
+
console.error("[real-harness]", d.toString().trim()),
|
|
71
|
+
);
|
|
72
|
+
proc.on("exit", (code) => failed(new Error(`harness exited ${code}`)));
|
|
73
|
+
await up;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async stop(): Promise<void> {
|
|
77
|
+
if (!this.proc) return;
|
|
78
|
+
const p = this.proc;
|
|
79
|
+
this.proc = null;
|
|
80
|
+
const exited = new Promise<void>((r) => p.once("exit", () => r()));
|
|
81
|
+
p.kill("SIGTERM");
|
|
82
|
+
await Promise.race([exited, new Promise((r) => setTimeout(r, 15_000))]);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async signIn(context: BrowserContext, email: string): Promise<void> {
|
|
86
|
+
await context.addCookies([
|
|
87
|
+
{
|
|
88
|
+
name: SESSION_COOKIE,
|
|
89
|
+
value: await mintSessionCookie(email),
|
|
90
|
+
url: this.adminUrl,
|
|
91
|
+
httpOnly: true,
|
|
92
|
+
sameSite: "Lax",
|
|
93
|
+
},
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private chatFetch(path: string): Promise<Response> {
|
|
98
|
+
return fetch(`${this.chatUrl}${path}`, {
|
|
99
|
+
headers: { Authorization: `Bearer ${CHAT_ADMIN_TOKEN}` },
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Every thread in the real chat service (all agents). */
|
|
104
|
+
async chatThreads(): Promise<ChatThreadRow[]> {
|
|
105
|
+
const res = await this.chatFetch("/threads?limit=200");
|
|
106
|
+
return ((await res.json()) as { threads: ChatThreadRow[] }).threads;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async chatMessages(threadId: string): Promise<ChatMessageRow[]> {
|
|
110
|
+
const res = await this.chatFetch(`/threads/${threadId}/messages`);
|
|
111
|
+
return ((await res.json()) as { messages: ChatMessageRow[] }).messages;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Id of the seeded thread with this exact title. */
|
|
115
|
+
async threadIdByTitle(title: string): Promise<string> {
|
|
116
|
+
const found = (await this.chatThreads()).find((t) => t.title === title);
|
|
117
|
+
if (!found) throw new Error(`seeded thread not found: ${title}`);
|
|
118
|
+
return found.id;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/e2e/real/harness.ts
|
|
3
|
+
*
|
|
4
|
+
* Starts the REAL admin app (admin/src/main.ts) and the REAL chat service
|
|
5
|
+
* (chat/src/main.ts) from environment variables only, against temporary
|
|
6
|
+
* Postgres databases created on the server named by ADMIN_E2E_PG_URL (a CI
|
|
7
|
+
* `services: postgres` container with throwaway credentials). Each app runs
|
|
8
|
+
* its own `prisma migrate deploy` boot preflight. Kubernetes provisioning is
|
|
9
|
+
* off and Google sign-in is unconfigured: specs sign in by minting a session
|
|
10
|
+
* cookie (see session.ts), so no sign-in route is added or exercised.
|
|
11
|
+
*
|
|
12
|
+
* `selfServe` toggles SHIPWRIGHT_SELF_SERVE_ENABLED so the same specs can run
|
|
13
|
+
* with the flag off and on.
|
|
14
|
+
*
|
|
15
|
+
* Library: `startHarness({ selfServe, adminPort, chatPort })`.
|
|
16
|
+
* CLI: `ADMIN_E2E_SELF_SERVE=on bun admin/e2e/real/harness.ts` runs until
|
|
17
|
+
* SIGTERM and prints the base URL.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { type ChildProcess, spawn } from "node:child_process";
|
|
21
|
+
import { randomBytes } from "node:crypto";
|
|
22
|
+
import { resolve } from "node:path";
|
|
23
|
+
import pg from "pg";
|
|
24
|
+
import { CHAT_ADMIN_TOKEN, EMAILS, SESSION_SECRET } from "./constants.ts";
|
|
25
|
+
import { seedAdminDb, seedChatService } from "./seed.ts";
|
|
26
|
+
|
|
27
|
+
const REPO_ROOT = resolve(import.meta.dir, "..", "..", "..");
|
|
28
|
+
const DEFAULT_PG_URL = "postgres://postgres:postgres@localhost:5432/postgres";
|
|
29
|
+
|
|
30
|
+
export interface HarnessOptions {
|
|
31
|
+
selfServe: boolean;
|
|
32
|
+
adminPort: number;
|
|
33
|
+
chatPort: number;
|
|
34
|
+
/** Server (any database on it) used to create the temporary databases. */
|
|
35
|
+
pgUrl?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface Harness {
|
|
39
|
+
adminUrl: string;
|
|
40
|
+
chatUrl: string;
|
|
41
|
+
stop(): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function withDatabase(url: string, database: string): string {
|
|
45
|
+
const u = new URL(url);
|
|
46
|
+
u.pathname = `/${database}`;
|
|
47
|
+
return u.toString();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function waitFor(url: string, proc: ChildProcess, label: string) {
|
|
51
|
+
const deadline = Date.now() + 120_000;
|
|
52
|
+
while (Date.now() < deadline) {
|
|
53
|
+
if (proc.exitCode !== null) {
|
|
54
|
+
throw new Error(`${label} exited early with code ${proc.exitCode}`);
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const res = await fetch(url);
|
|
58
|
+
if (res.status < 500) return;
|
|
59
|
+
} catch {
|
|
60
|
+
// not up yet
|
|
61
|
+
}
|
|
62
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
63
|
+
}
|
|
64
|
+
throw new Error(`${label} did not become healthy at ${url}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function launch(
|
|
68
|
+
label: string,
|
|
69
|
+
script: string,
|
|
70
|
+
env: Record<string, string>,
|
|
71
|
+
): ChildProcess {
|
|
72
|
+
const proc = spawn("bun", ["run", script], {
|
|
73
|
+
cwd: REPO_ROOT,
|
|
74
|
+
env: { ...process.env, ...env },
|
|
75
|
+
stdio: "pipe",
|
|
76
|
+
});
|
|
77
|
+
const relay = (stream: "log" | "error") => (data: Buffer) => {
|
|
78
|
+
const msg = data.toString().trim();
|
|
79
|
+
if (msg) console[stream](`[${label}]`, msg);
|
|
80
|
+
};
|
|
81
|
+
proc.stdout?.on("data", relay("log"));
|
|
82
|
+
proc.stderr?.on("data", relay("error"));
|
|
83
|
+
return proc;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function startHarness(opts: HarnessOptions): Promise<Harness> {
|
|
87
|
+
const pgUrl = opts.pgUrl ?? process.env.ADMIN_E2E_PG_URL ?? DEFAULT_PG_URL;
|
|
88
|
+
const suffix = randomBytes(4).toString("hex");
|
|
89
|
+
const adminDb = `admin_e2e_${suffix}`;
|
|
90
|
+
const chatDb = `chat_e2e_${suffix}`;
|
|
91
|
+
|
|
92
|
+
const root = new pg.Client({ connectionString: pgUrl });
|
|
93
|
+
await root.connect();
|
|
94
|
+
await root.query(`CREATE DATABASE ${adminDb}`);
|
|
95
|
+
await root.query(`CREATE DATABASE ${chatDb}`);
|
|
96
|
+
|
|
97
|
+
const procs: ChildProcess[] = [];
|
|
98
|
+
const stop = async (): Promise<void> => {
|
|
99
|
+
for (const p of procs) p.kill("SIGTERM");
|
|
100
|
+
await Promise.all(
|
|
101
|
+
procs.map(
|
|
102
|
+
(p) =>
|
|
103
|
+
new Promise<void>((done) => {
|
|
104
|
+
if (p.exitCode !== null) return done();
|
|
105
|
+
p.once("exit", () => done());
|
|
106
|
+
setTimeout(done, 5_000);
|
|
107
|
+
}),
|
|
108
|
+
),
|
|
109
|
+
);
|
|
110
|
+
await root.query(`DROP DATABASE IF EXISTS ${adminDb} WITH (FORCE)`);
|
|
111
|
+
await root.query(`DROP DATABASE IF EXISTS ${chatDb} WITH (FORCE)`);
|
|
112
|
+
await root.end();
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
const adminUrl = `http://localhost:${opts.adminPort}`;
|
|
117
|
+
const chatUrl = `http://localhost:${opts.chatPort}`;
|
|
118
|
+
|
|
119
|
+
const chat = launch("e2e-chat", "chat/src/main.ts", {
|
|
120
|
+
PORT: String(opts.chatPort),
|
|
121
|
+
DATABASE_URL_SHIPWRIGHT_CHAT: withDatabase(pgUrl, chatDb),
|
|
122
|
+
CHAT_SEED_ADMIN_TOKEN: CHAT_ADMIN_TOKEN,
|
|
123
|
+
});
|
|
124
|
+
procs.push(chat);
|
|
125
|
+
|
|
126
|
+
// The admin boot preflight migrates its database; the seed needs the
|
|
127
|
+
// schema, so migrate first (idempotent: the boot run is then a no-op).
|
|
128
|
+
const adminDbUrl = withDatabase(pgUrl, adminDb);
|
|
129
|
+
await migrateAdmin(adminDbUrl);
|
|
130
|
+
await seedAdminDb(adminDbUrl);
|
|
131
|
+
|
|
132
|
+
const admin = launch("e2e-admin", "admin/src/main.ts", {
|
|
133
|
+
PORT: String(opts.adminPort),
|
|
134
|
+
DATABASE_URL_SHIPWRIGHT_ADMIN: adminDbUrl,
|
|
135
|
+
SHIPWRIGHT_SESSION_SECRET: SESSION_SECRET,
|
|
136
|
+
SHIPWRIGHT_ADMIN_ALLOWED_EMAILS: EMAILS.admin,
|
|
137
|
+
SHIPWRIGHT_ADMIN_APP_BASE_URL: adminUrl,
|
|
138
|
+
SHIPWRIGHT_SELF_SERVE_ENABLED: opts.selfServe ? "enabled" : "disabled",
|
|
139
|
+
SHIPWRIGHT_K8S_PROVISIONING: "disabled",
|
|
140
|
+
SHIPWRIGHT_CHAT_SERVICE_URL: chatUrl,
|
|
141
|
+
SHIPWRIGHT_CHAT_SERVICE_ADMIN_TOKEN: CHAT_ADMIN_TOKEN,
|
|
142
|
+
SHIPWRIGHT_SPECIALTIES_DIR: resolve(
|
|
143
|
+
REPO_ROOT,
|
|
144
|
+
"admin/e2e/fixtures/specialties",
|
|
145
|
+
),
|
|
146
|
+
SHIPWRIGHT_DEFAULT_AGENT_TYPE: "specialist",
|
|
147
|
+
NODE_ENV: "test",
|
|
148
|
+
});
|
|
149
|
+
procs.push(admin);
|
|
150
|
+
|
|
151
|
+
await Promise.all([
|
|
152
|
+
waitFor(`${chatUrl}/health`, chat, "chat"),
|
|
153
|
+
waitFor(`${adminUrl}/health`, admin, "admin"),
|
|
154
|
+
]);
|
|
155
|
+
await seedChatService(chatUrl);
|
|
156
|
+
return { adminUrl, chatUrl, stop };
|
|
157
|
+
} catch (err) {
|
|
158
|
+
await stop().catch(() => {});
|
|
159
|
+
throw err;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
async function migrateAdmin(databaseUrl: string): Promise<void> {
|
|
164
|
+
const proc = spawn(
|
|
165
|
+
"bunx",
|
|
166
|
+
["prisma", "migrate", "deploy", "--schema=prisma/schema"],
|
|
167
|
+
{
|
|
168
|
+
cwd: resolve(REPO_ROOT, "admin"),
|
|
169
|
+
env: { ...process.env, DATABASE_URL_SHIPWRIGHT_ADMIN: databaseUrl },
|
|
170
|
+
stdio: "pipe",
|
|
171
|
+
},
|
|
172
|
+
);
|
|
173
|
+
let err = "";
|
|
174
|
+
proc.stderr?.on("data", (d: Buffer) => {
|
|
175
|
+
err += d.toString();
|
|
176
|
+
});
|
|
177
|
+
const code = await new Promise<number | null>((r) => proc.on("exit", r));
|
|
178
|
+
if (code !== 0) throw new Error(`admin migrate failed: ${err}`);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (import.meta.main) {
|
|
182
|
+
const harness = await startHarness({
|
|
183
|
+
selfServe: process.env.ADMIN_E2E_SELF_SERVE === "on",
|
|
184
|
+
adminPort: Number(process.env.ADMIN_E2E_PORT ?? 3510),
|
|
185
|
+
chatPort: Number(process.env.ADMIN_E2E_CHAT_PORT ?? 3511),
|
|
186
|
+
});
|
|
187
|
+
console.log(`[admin-e2e] real harness up: ${harness.adminUrl}`);
|
|
188
|
+
const shutdown = () => harness.stop().then(() => process.exit(0));
|
|
189
|
+
process.on("SIGTERM", shutdown);
|
|
190
|
+
process.on("SIGINT", shutdown);
|
|
191
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/e2e/real/member-access-self-serve.real.e2e.ts
|
|
3
|
+
*
|
|
4
|
+
* Real-service e2e, self-serve ON: a member (member1, an AgentMember of Alpha
|
|
5
|
+
* only) stays limited. They see only their agent, cannot open the Account or
|
|
6
|
+
* owner-only pages, and cannot create agents, even though self-serve is on.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { expect, test } from "@playwright/test";
|
|
10
|
+
import { AGENTS, EMAILS } from "./constants.ts";
|
|
11
|
+
import { RealHarness } from "./fixture.ts";
|
|
12
|
+
|
|
13
|
+
const harness = new RealHarness({
|
|
14
|
+
selfServe: true,
|
|
15
|
+
adminPort: 3522,
|
|
16
|
+
chatPort: 3523,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test.describe.configure({ mode: "serial" });
|
|
20
|
+
|
|
21
|
+
test.beforeAll(async () => {
|
|
22
|
+
test.setTimeout(240_000);
|
|
23
|
+
await harness.start();
|
|
24
|
+
});
|
|
25
|
+
test.afterAll(async () => {
|
|
26
|
+
await harness.stop();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const REFUSED = [403, 404];
|
|
30
|
+
|
|
31
|
+
test.describe("member, self-serve on", () => {
|
|
32
|
+
test("Agents list shows only the member's agents", async ({
|
|
33
|
+
page,
|
|
34
|
+
context,
|
|
35
|
+
}) => {
|
|
36
|
+
await harness.signIn(context, EMAILS.member1);
|
|
37
|
+
await page.goto(`${harness.adminUrl}/admin/agents`);
|
|
38
|
+
await expect(page.getByText(AGENTS.alpha.name).first()).toBeVisible();
|
|
39
|
+
await expect(page.getByText(AGENTS.beta.name)).toHaveCount(0);
|
|
40
|
+
await expect(page.getByText(AGENTS.gamma.name)).toHaveCount(0);
|
|
41
|
+
await expect(page.locator('a[href="/admin/agents/new"]')).toHaveCount(0);
|
|
42
|
+
|
|
43
|
+
const res = await context.request.get(`${harness.adminUrl}/agents`);
|
|
44
|
+
const ids = ((await res.json()) as { id: string }[]).map((a) => a.id);
|
|
45
|
+
expect(ids).toEqual([AGENTS.alpha.id]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("Account and owner-only pages are not offered and are refused", async ({
|
|
49
|
+
page,
|
|
50
|
+
context,
|
|
51
|
+
}) => {
|
|
52
|
+
await harness.signIn(context, EMAILS.member1);
|
|
53
|
+
const base = harness.adminUrl;
|
|
54
|
+
await page.goto(`${base}/admin/agents`);
|
|
55
|
+
for (const href of [
|
|
56
|
+
"/admin/settings/github-enterprise",
|
|
57
|
+
"/admin/settings/templates",
|
|
58
|
+
"/admin/settings/slack-config-token",
|
|
59
|
+
"/admin/accounts",
|
|
60
|
+
"/admin/account",
|
|
61
|
+
]) {
|
|
62
|
+
await expect(page.locator(`a[href^="${href}"]`)).toHaveCount(0);
|
|
63
|
+
}
|
|
64
|
+
for (const path of [
|
|
65
|
+
"/admin/account",
|
|
66
|
+
"/admin/settings/templates",
|
|
67
|
+
"/admin/settings/slack-config-token",
|
|
68
|
+
"/admin/settings/github-enterprise",
|
|
69
|
+
"/admin/accounts",
|
|
70
|
+
]) {
|
|
71
|
+
const res = await page.goto(`${base}${path}`);
|
|
72
|
+
expect(REFUSED, path).toContain(res?.status());
|
|
73
|
+
await expect(page.locator("nav.settings-sidebar")).toHaveCount(0);
|
|
74
|
+
await expect(page.getByText("Account One")).toHaveCount(0);
|
|
75
|
+
}
|
|
76
|
+
for (const path of [
|
|
77
|
+
"/admin/account/name",
|
|
78
|
+
"/admin/settings/templates/items",
|
|
79
|
+
]) {
|
|
80
|
+
const res = await context.request.post(`${base}${path}`, {
|
|
81
|
+
form: { name: "pwned" },
|
|
82
|
+
maxRedirects: 0,
|
|
83
|
+
});
|
|
84
|
+
expect(REFUSED, `POST ${path}`).toContain(res.status());
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("a member cannot create agents", async ({ page, context }) => {
|
|
89
|
+
await harness.signIn(context, EMAILS.member1);
|
|
90
|
+
const base = harness.adminUrl;
|
|
91
|
+
const form = await page.goto(`${base}/admin/agents/new`);
|
|
92
|
+
expect(REFUSED).toContain(form?.status());
|
|
93
|
+
const post = await context.request.post(`${base}/admin/agents`, {
|
|
94
|
+
form: { name: "Hax Agent", type: "specialist", repos: "evil-org/pwn" },
|
|
95
|
+
maxRedirects: 0,
|
|
96
|
+
});
|
|
97
|
+
expect(REFUSED).toContain(post.status());
|
|
98
|
+
const api = await context.request.post(`${base}/agents`, {
|
|
99
|
+
data: { name: "Hax Agent Two", specialty: "specialist" },
|
|
100
|
+
});
|
|
101
|
+
expect(REFUSED).toContain(api.status());
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("no agent was created", async ({ context }) => {
|
|
105
|
+
await harness.signIn(context, EMAILS.admin);
|
|
106
|
+
const res = await context.request.get(`${harness.adminUrl}/agents`);
|
|
107
|
+
const names = ((await res.json()) as { name: string }[]).map((a) => a.name);
|
|
108
|
+
expect(names.sort()).toEqual(
|
|
109
|
+
Object.values(AGENTS)
|
|
110
|
+
.map((a) => a.name)
|
|
111
|
+
.sort(),
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
});
|