@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
package/e2e/real/seed.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/e2e/real/seed.ts
|
|
3
|
+
*
|
|
4
|
+
* Seeds the admin database for the real-service e2e layer: two accounts, a
|
|
5
|
+
* platform admin (allowlist only, no row), an owner and a member in account
|
|
6
|
+
* one, an owner in account two, and three agents with different repos. The
|
|
7
|
+
* member is on `alpha` only; `beta` (same account) and `gamma` (other account)
|
|
8
|
+
* are agents the member is not on.
|
|
9
|
+
*
|
|
10
|
+
* Standalone: `ADMIN_E2E_SEED_URL=postgres://... bun admin/e2e/real/seed.ts`.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { createAdminPrismaClient } from "../../src/prisma-client.ts";
|
|
14
|
+
import {
|
|
15
|
+
ACCOUNTS,
|
|
16
|
+
AGENTS,
|
|
17
|
+
CHAT_ADMIN_TOKEN,
|
|
18
|
+
EMAILS,
|
|
19
|
+
THREADS,
|
|
20
|
+
} from "./constants.ts";
|
|
21
|
+
|
|
22
|
+
const MEMBER1_ID = "member-e2e-member1";
|
|
23
|
+
|
|
24
|
+
export async function seedAdminDb(databaseUrl: string): Promise<void> {
|
|
25
|
+
const prisma = createAdminPrismaClient(databaseUrl);
|
|
26
|
+
try {
|
|
27
|
+
for (const account of Object.values(ACCOUNTS)) {
|
|
28
|
+
await prisma.account.create({
|
|
29
|
+
data: { id: account.id, name: account.name, maxAgents: 5 },
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
await prisma.accountMember.createMany({
|
|
33
|
+
data: [
|
|
34
|
+
{ accountId: ACCOUNTS.one.id, email: EMAILS.owner1, role: "owner" },
|
|
35
|
+
{
|
|
36
|
+
id: MEMBER1_ID,
|
|
37
|
+
accountId: ACCOUNTS.one.id,
|
|
38
|
+
email: EMAILS.member1,
|
|
39
|
+
role: "member",
|
|
40
|
+
},
|
|
41
|
+
{ accountId: ACCOUNTS.two.id, email: EMAILS.owner2, role: "owner" },
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
for (const agent of Object.values(AGENTS)) {
|
|
45
|
+
await prisma.agent.create({
|
|
46
|
+
data: {
|
|
47
|
+
id: agent.id,
|
|
48
|
+
name: agent.name,
|
|
49
|
+
repos: [...agent.repos],
|
|
50
|
+
accountId: agent.accountId,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
await prisma.agentMember.create({
|
|
55
|
+
// AgentMember reads key on memberId (AccountMember.id), not email.
|
|
56
|
+
data: {
|
|
57
|
+
agentId: AGENTS.alpha.id,
|
|
58
|
+
email: EMAILS.member1,
|
|
59
|
+
memberId: MEMBER1_ID,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
} finally {
|
|
63
|
+
await prisma.$disconnect();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Seeds one chat thread (with one message) per agent through the real chat
|
|
69
|
+
* service HTTP API, using the seeded admin token. Additive to seedAdminDb.
|
|
70
|
+
*/
|
|
71
|
+
export async function seedChatService(chatUrl: string): Promise<void> {
|
|
72
|
+
const headers = {
|
|
73
|
+
Authorization: `Bearer ${CHAT_ADMIN_TOKEN}`,
|
|
74
|
+
"Content-Type": "application/json",
|
|
75
|
+
};
|
|
76
|
+
for (const t of Object.values(THREADS)) {
|
|
77
|
+
const created = await fetch(`${chatUrl}/threads`, {
|
|
78
|
+
method: "POST",
|
|
79
|
+
headers,
|
|
80
|
+
body: JSON.stringify({ agentId: AGENTS[t.agent].id, title: t.title }),
|
|
81
|
+
});
|
|
82
|
+
if (!created.ok) {
|
|
83
|
+
throw new Error(`seed thread ${t.title} failed: ${created.status}`);
|
|
84
|
+
}
|
|
85
|
+
const thread = (await created.json()) as { id: string };
|
|
86
|
+
const msg = await fetch(`${chatUrl}/threads/${thread.id}/messages`, {
|
|
87
|
+
method: "POST",
|
|
88
|
+
headers,
|
|
89
|
+
body: JSON.stringify({ role: "user", body: t.message }),
|
|
90
|
+
});
|
|
91
|
+
if (!msg.ok) {
|
|
92
|
+
throw new Error(`seed message for ${t.title} failed: ${msg.status}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (import.meta.main) {
|
|
98
|
+
const url = process.env.ADMIN_E2E_SEED_URL;
|
|
99
|
+
if (!url) {
|
|
100
|
+
console.error("ADMIN_E2E_SEED_URL is required");
|
|
101
|
+
process.exit(1);
|
|
102
|
+
}
|
|
103
|
+
await seedAdminDb(url);
|
|
104
|
+
console.log("[admin-e2e] seeded");
|
|
105
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* admin/e2e/real/session.ts
|
|
3
|
+
*
|
|
4
|
+
* Mints an `admin_session` cookie value with the test session secret, in the
|
|
5
|
+
* same shape the admin app issues after a real sign-in (HS256 JWT). No sign-in
|
|
6
|
+
* route is involved; `isAdmin` must agree with the harness allowlist because
|
|
7
|
+
* the admin app re-derives it from the allowlist when it renews a session.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { sign } from "hono/jwt";
|
|
11
|
+
import { EMAILS, SESSION_SECRET } from "./constants.ts";
|
|
12
|
+
|
|
13
|
+
export async function mintSessionCookie(
|
|
14
|
+
email: string,
|
|
15
|
+
secret: string = SESSION_SECRET,
|
|
16
|
+
): Promise<string> {
|
|
17
|
+
const now = Math.floor(Date.now() / 1000);
|
|
18
|
+
return sign(
|
|
19
|
+
{
|
|
20
|
+
userId: `e2e-${email}`,
|
|
21
|
+
email,
|
|
22
|
+
isAdmin: email === EMAILS.admin,
|
|
23
|
+
iat: now,
|
|
24
|
+
exp: now + 3600,
|
|
25
|
+
},
|
|
26
|
+
secret,
|
|
27
|
+
"HS256",
|
|
28
|
+
);
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.107.
|
|
3
|
+
"version": "1.107.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.107.
|
|
47
|
+
"@app-vitals/agent-lib": "1.107.1",
|
|
48
48
|
"@hono/zod-openapi": "^1.0.0",
|
|
49
49
|
"@prisma/adapter-pg": "^7.10.0",
|
|
50
50
|
"@prisma/client": "^7.10.0",
|
package/playwright.config.ts
CHANGED
|
@@ -18,7 +18,18 @@ export default defineConfig({
|
|
|
18
18
|
},
|
|
19
19
|
projects: [
|
|
20
20
|
{
|
|
21
|
+
// Fake-data specs: each boots admin/e2e/test-server.ts (in-memory deps).
|
|
21
22
|
name: "chromium",
|
|
23
|
+
testIgnore: "**/*.real.e2e.ts",
|
|
24
|
+
use: { browserName: "chromium" },
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
// Real-service specs: real admin + chat on temporary Postgres databases
|
|
28
|
+
// (ADMIN_E2E_PG_URL), seeded roles. See e2e/real/harness.ts.
|
|
29
|
+
name: "real-services",
|
|
30
|
+
testMatch: "**/*.real.e2e.ts",
|
|
31
|
+
timeout: 60_000,
|
|
32
|
+
retries: 0,
|
|
22
33
|
use: { browserName: "chromium" },
|
|
23
34
|
},
|
|
24
35
|
],
|
package/src/admin-ui.ts
CHANGED
|
@@ -171,6 +171,7 @@ import {
|
|
|
171
171
|
renderPwaHeadTags,
|
|
172
172
|
sanitizeStartUrl,
|
|
173
173
|
} from "./pwa.ts";
|
|
174
|
+
import { secretsEqual } from "./secrets-equal.ts";
|
|
174
175
|
import {
|
|
175
176
|
DEFAULT_SELF_SERVE_CONTACT_EMAIL,
|
|
176
177
|
type SelfServeConfig,
|
|
@@ -5420,7 +5421,7 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
5420
5421
|
}
|
|
5421
5422
|
const auth = c.req.header("authorization") ?? "";
|
|
5422
5423
|
const presented = auth.startsWith("Bearer ") ? auth.slice(7) : "";
|
|
5423
|
-
if (!presented || presented
|
|
5424
|
+
if (!presented || !secretsEqual(presented, pushWebhookToken)) {
|
|
5424
5425
|
return c.json({ error: "unauthorized" }, 401);
|
|
5425
5426
|
}
|
|
5426
5427
|
let body: {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createHash, timingSafeEqual } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
/** Constant-time string compare; hashes first so length doesn't leak. */
|
|
4
|
+
export function secretsEqual(a: string, b: string): boolean {
|
|
5
|
+
const ha = createHash("sha256").update(a).digest();
|
|
6
|
+
const hb = createHash("sha256").update(b).digest();
|
|
7
|
+
return timingSafeEqual(ha, hb);
|
|
8
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { secretsEqual } from "./secrets-equal.ts";
|
|
3
|
+
|
|
4
|
+
describe("secretsEqual", () => {
|
|
5
|
+
test("equal strings match", () => {
|
|
6
|
+
expect(secretsEqual("abc", "abc")).toBe(true);
|
|
7
|
+
});
|
|
8
|
+
test("different strings of same length differ", () => {
|
|
9
|
+
expect(secretsEqual("abc", "abd")).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
test("different lengths differ without throwing", () => {
|
|
12
|
+
expect(secretsEqual("abc", "abcd")).toBe(false);
|
|
13
|
+
expect(secretsEqual("", "abc")).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
});
|