@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.
- package/e2e/real/admin-access.real.e2e.ts +77 -68
- package/e2e/real/agent-management.real.e2e.ts +165 -143
- package/e2e/real/owner-access.real.e2e.ts +228 -212
- package/openapi.platform.json +6 -6
- package/package.json +2 -2
- package/src/account-created-notifier.ts +1 -1
- package/src/account-onboarding.integration.test.ts +69 -0
- package/src/account-onboarding.ts +29 -3
- package/src/account-trial-expiry-sweeper.ts +1 -1
- package/src/accounts-api.integration.test.ts +5 -2
- package/src/accounts-api.smoke.test.ts +21 -5
- package/src/accounts-api.ts +12 -15
- package/src/admin-boot-config.ts +2 -0
- package/src/admin-boot-config.unit.test.ts +27 -0
- package/src/admin-boot.ts +11 -10
- package/src/admin-ui-account.smoke.test.ts +7 -3
- package/src/admin-ui-account.ts +10 -15
- package/src/admin-ui-accounts.smoke.test.ts +4 -4
- package/src/admin-ui-accounts.ts +7 -11
- package/src/admin-ui-settings-nav-context.smoke.test.ts +24 -0
- package/src/admin-ui-settings.smoke.test.ts +17 -1
- package/src/admin-ui.smoke.test.ts +168 -2
- package/src/admin-ui.ts +39 -26
- package/src/agent-management-access.integration.test.ts +18 -6
- package/src/agent-manifest.ts +2 -1
- package/src/agent-provisioner.integration.test.ts +10 -10
- package/src/agent-provisioner.ts +10 -1
- package/src/agent-provisioner.unit.test.ts +110 -36
- package/src/agent-templates-api.integration.test.ts +23 -5
- package/src/agent-templates-api.ts +11 -8
- package/src/caller-scope.integration.test.ts +8 -6
- package/src/caller-scope.ts +32 -26
- package/src/caller-scope.unit.test.ts +15 -11
- package/src/platform-routes.ts +2 -2
|
@@ -125,7 +125,7 @@ describe("KubernetesAgentProvisioner.provision() — default PVC naming", () =>
|
|
|
125
125
|
describe("KubernetesAgentProvisioner.provision() — templated PVC naming", () => {
|
|
126
126
|
it("creates a PVC named by the template when slug is provided via opts", async () => {
|
|
127
127
|
const agentId = "cmqalfjcm000m4101iharq28k";
|
|
128
|
-
const slug = "
|
|
128
|
+
const slug = "widget";
|
|
129
129
|
|
|
130
130
|
const config: KubernetesAgentProvisionerConfig = {
|
|
131
131
|
...BASE_CONFIG,
|
|
@@ -143,7 +143,7 @@ describe("KubernetesAgentProvisioner.provision() — templated PVC naming", () =
|
|
|
143
143
|
|
|
144
144
|
// PVC must use the slug, not the sanitized agentId
|
|
145
145
|
await expect(
|
|
146
|
-
k8s.getPvc(NAMESPACE, "acme-agent-
|
|
146
|
+
k8s.getPvc(NAMESPACE, "acme-agent-widget-home"),
|
|
147
147
|
).resolves.toBeDefined();
|
|
148
148
|
|
|
149
149
|
// The default name must NOT exist
|
|
@@ -155,8 +155,8 @@ describe("KubernetesAgentProvisioner.provision() — templated PVC naming", () =
|
|
|
155
155
|
|
|
156
156
|
it("Deployment is created alongside the template-derived PVC", async () => {
|
|
157
157
|
const agentId = "cmqalfjcm000m4101iharq28k";
|
|
158
|
-
const slug = "
|
|
159
|
-
const expectedPvcName = "acme-agent-
|
|
158
|
+
const slug = "widget";
|
|
159
|
+
const expectedPvcName = "acme-agent-widget-home";
|
|
160
160
|
|
|
161
161
|
const config: KubernetesAgentProvisionerConfig = {
|
|
162
162
|
...BASE_CONFIG,
|
|
@@ -973,8 +973,8 @@ describe("KubernetesAgentProvisioner.deprovision() — PVC deletion", () => {
|
|
|
973
973
|
|
|
974
974
|
it("calls deletePvc with the templated name derived from slug", async () => {
|
|
975
975
|
const agentId = "cmqalfjcm000m4101iharq28k";
|
|
976
|
-
const slug = "
|
|
977
|
-
const expectedPvcName = "acme-agent-
|
|
976
|
+
const slug = "widget";
|
|
977
|
+
const expectedPvcName = "acme-agent-widget-home";
|
|
978
978
|
|
|
979
979
|
const config: KubernetesAgentProvisionerConfig = {
|
|
980
980
|
...BASE_CONFIG,
|
|
@@ -1172,11 +1172,12 @@ describe("canProvision", () => {
|
|
|
1172
1172
|
});
|
|
1173
1173
|
});
|
|
1174
1174
|
|
|
1175
|
-
describe("KubernetesAgentProvisioner
|
|
1175
|
+
describe("KubernetesAgentProvisioner — tenant pod restrictions (SSP-7.1)", () => {
|
|
1176
1176
|
const agentId = "cmqalfjcm000m4101iharq28k";
|
|
1177
1177
|
const resourceName = sanitizeAgentName(agentId);
|
|
1178
|
+
const TENANT = "shipwright.dev/tenant";
|
|
1178
1179
|
|
|
1179
|
-
|
|
1180
|
+
function build(tenantPodRestrictions?: boolean) {
|
|
1180
1181
|
const k8s = new RecordedKubernetesClient({
|
|
1181
1182
|
deployments: {},
|
|
1182
1183
|
secrets: {},
|
|
@@ -1185,43 +1186,116 @@ describe("KubernetesAgentProvisioner.reconcile() — tenant drift (SSP-7.1)", ()
|
|
|
1185
1186
|
const provisioner = new KubernetesAgentProvisioner(
|
|
1186
1187
|
k8s,
|
|
1187
1188
|
stubTokens() as AgentTokenService,
|
|
1188
|
-
|
|
1189
|
+
{
|
|
1190
|
+
...BASE_CONFIG,
|
|
1191
|
+
...(tenantPodRestrictions === undefined
|
|
1192
|
+
? {}
|
|
1193
|
+
: { tenantPodRestrictions }),
|
|
1194
|
+
},
|
|
1189
1195
|
);
|
|
1190
|
-
await provisioner.provision(agentId); // created as a platform agent
|
|
1191
1196
|
return { k8s, provisioner };
|
|
1192
1197
|
}
|
|
1193
1198
|
|
|
1194
|
-
|
|
1195
|
-
const
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
]);
|
|
1199
|
+
async function seededWithPlatformManifest(tenantPodRestrictions?: boolean) {
|
|
1200
|
+
const built = build(tenantPodRestrictions);
|
|
1201
|
+
await built.provisioner.provision(agentId); // created as a platform agent
|
|
1202
|
+
return built;
|
|
1203
|
+
}
|
|
1200
1204
|
|
|
1201
|
-
|
|
1205
|
+
async function deployment(
|
|
1206
|
+
k8s: RecordedKubernetesClient,
|
|
1207
|
+
): Promise<Record<string, string | undefined>> {
|
|
1202
1208
|
const dep = await k8s.getDeployment(NAMESPACE, resourceName);
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
});
|
|
1209
|
+
return {
|
|
1210
|
+
podLabel: dep.spec.template.metadata.labels[TENANT],
|
|
1211
|
+
deploymentLabel: dep.metadata.labels?.[TENANT],
|
|
1212
|
+
cpuLimit: dep.spec.template.spec.containers[0]?.resources?.limits?.cpu,
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1210
1215
|
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
{
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1216
|
+
describe("restrictions on (self-serve signup enabled)", () => {
|
|
1217
|
+
it("provisions an account agent with the tenant label and a CPU limit", async () => {
|
|
1218
|
+
const { k8s, provisioner } = build(true);
|
|
1219
|
+
await provisioner.provision(agentId, { accountId: "acct_1" });
|
|
1220
|
+
expect(await deployment(k8s)).toEqual({
|
|
1221
|
+
podLabel: "true",
|
|
1222
|
+
deploymentLabel: "true",
|
|
1223
|
+
cpuLimit: "2",
|
|
1224
|
+
});
|
|
1225
|
+
});
|
|
1219
1226
|
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1227
|
+
it("detects a missing tenant label + CPU limit as drift and patches", async () => {
|
|
1228
|
+
const { k8s, provisioner } = await seededWithPlatformManifest(true);
|
|
1229
|
+
|
|
1230
|
+
const result = await provisioner.reconcile([
|
|
1231
|
+
{ id: agentId, accountId: "acct_1" },
|
|
1232
|
+
]);
|
|
1233
|
+
|
|
1234
|
+
expect(result.updated).toEqual([agentId]);
|
|
1235
|
+
const dep = await deployment(k8s);
|
|
1236
|
+
expect(dep.podLabel).toBe("true");
|
|
1237
|
+
expect(dep.cpuLimit).toBe("2");
|
|
1238
|
+
});
|
|
1239
|
+
|
|
1240
|
+
it("is a no-op once the tenant Deployment matches", async () => {
|
|
1241
|
+
const { provisioner } = await seededWithPlatformManifest(true);
|
|
1242
|
+
await provisioner.reconcile([{ id: agentId, accountId: "acct_1" }]);
|
|
1243
|
+
const second = await provisioner.reconcile([
|
|
1244
|
+
{ id: agentId, accountId: "acct_1" },
|
|
1245
|
+
]);
|
|
1246
|
+
expect(second.updated).toEqual([]);
|
|
1247
|
+
});
|
|
1248
|
+
|
|
1249
|
+
it("does not touch platform agents (no accountId)", async () => {
|
|
1250
|
+
const { provisioner } = await seededWithPlatformManifest(true);
|
|
1251
|
+
const result = await provisioner.reconcile([{ id: agentId }]);
|
|
1252
|
+
expect(result.updated).toEqual([]);
|
|
1253
|
+
});
|
|
1224
1254
|
});
|
|
1255
|
+
|
|
1256
|
+
const offCases: Array<[string, boolean | undefined]> = [
|
|
1257
|
+
["restrictions off", false],
|
|
1258
|
+
["restrictions unset", undefined],
|
|
1259
|
+
];
|
|
1260
|
+
for (const [label, setting] of offCases) {
|
|
1261
|
+
describe(`${label} (self-serve signup disabled)`, () => {
|
|
1262
|
+
it("provisions an account agent with no tenant label and no CPU limit", async () => {
|
|
1263
|
+
const { k8s, provisioner } = build(setting);
|
|
1264
|
+
await provisioner.provision(agentId, { accountId: "acct_1" });
|
|
1265
|
+
expect(await deployment(k8s)).toEqual({
|
|
1266
|
+
podLabel: undefined,
|
|
1267
|
+
deploymentLabel: undefined,
|
|
1268
|
+
cpuLimit: undefined,
|
|
1269
|
+
});
|
|
1270
|
+
});
|
|
1271
|
+
|
|
1272
|
+
it("reconciling an account agent adds no tenant label and no CPU limit", async () => {
|
|
1273
|
+
const { k8s, provisioner } = await seededWithPlatformManifest(setting);
|
|
1274
|
+
const result = await provisioner.reconcile([
|
|
1275
|
+
{ id: agentId, accountId: "acct_1" },
|
|
1276
|
+
]);
|
|
1277
|
+
expect(result.updated).toEqual([]);
|
|
1278
|
+
expect(await deployment(k8s)).toEqual({
|
|
1279
|
+
podLabel: undefined,
|
|
1280
|
+
deploymentLabel: undefined,
|
|
1281
|
+
cpuLimit: undefined,
|
|
1282
|
+
});
|
|
1283
|
+
});
|
|
1284
|
+
|
|
1285
|
+
it("recreating a missing account agent adds no tenant label and no CPU limit", async () => {
|
|
1286
|
+
const { k8s, provisioner } = build(setting);
|
|
1287
|
+
const result = await provisioner.reconcile([
|
|
1288
|
+
{ id: agentId, accountId: "acct_1" },
|
|
1289
|
+
]);
|
|
1290
|
+
expect(result.recreated).toEqual([agentId]);
|
|
1291
|
+
expect(await deployment(k8s)).toEqual({
|
|
1292
|
+
podLabel: undefined,
|
|
1293
|
+
deploymentLabel: undefined,
|
|
1294
|
+
cpuLimit: undefined,
|
|
1295
|
+
});
|
|
1296
|
+
});
|
|
1297
|
+
});
|
|
1298
|
+
}
|
|
1225
1299
|
});
|
|
1226
1300
|
|
|
1227
1301
|
// ─── Claude policy drift + reconcile patch ──────────────────────────────────
|
|
@@ -86,11 +86,18 @@ describeOrSkip("/templates (integration)", () => {
|
|
|
86
86
|
callerScopeResolver: async (email, isAdmin) =>
|
|
87
87
|
isAdmin
|
|
88
88
|
? { kind: "all" }
|
|
89
|
-
:
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
: email === "member-a@example.com"
|
|
90
|
+
? {
|
|
91
|
+
kind: "scoped",
|
|
92
|
+
accountId: accountA,
|
|
93
|
+
agentIds: [],
|
|
94
|
+
role: "member",
|
|
95
|
+
}
|
|
96
|
+
: {
|
|
97
|
+
kind: "scoped",
|
|
98
|
+
accountId: accountByEmail[email] ?? null,
|
|
99
|
+
agentIds: [],
|
|
100
|
+
},
|
|
94
101
|
sessionSecret: SECRET,
|
|
95
102
|
adminApiKeys: parseAdminApiKeys("root:tok-admin:*,bot:tok-agent:agent-1"),
|
|
96
103
|
agentTokenService: { validate: async () => null },
|
|
@@ -505,4 +512,15 @@ describeOrSkip("/templates (integration)", () => {
|
|
|
505
512
|
expect(((await res.json()) as { accountId: null }).accountId).toBeNull();
|
|
506
513
|
});
|
|
507
514
|
});
|
|
515
|
+
|
|
516
|
+
it("an account member (not owner) is refused on read and write", async () => {
|
|
517
|
+
const member = await cookie("member-a@example.com");
|
|
518
|
+
expect((await call("GET", "/templates", member)).status).toBe(403);
|
|
519
|
+
const put = await call("PUT", "/templates", member, {
|
|
520
|
+
accountId: accountA,
|
|
521
|
+
items: [{ kind: "env", key: "FOO", payload: { value: "x" } }],
|
|
522
|
+
});
|
|
523
|
+
expect(put.status).toBe(403);
|
|
524
|
+
expect(await prisma.agentTemplate.count()).toBe(0);
|
|
525
|
+
});
|
|
508
526
|
});
|
|
@@ -4,15 +4,16 @@
|
|
|
4
4
|
* templates and their items.
|
|
5
5
|
*
|
|
6
6
|
* Auth: platform admins (admin key or admin session) manage every template,
|
|
7
|
-
* including deployment-wide ones.
|
|
8
|
-
*
|
|
9
|
-
* account's templates. Every other caller
|
|
10
|
-
* members without an account)
|
|
7
|
+
* including deployment-wide ones. An account owner session (resolved through
|
|
8
|
+
* the caller-scope resolver, never from the request) manages only that
|
|
9
|
+
* account's templates, like the Settings > Templates page. Every other caller
|
|
10
|
+
* (agent keys, platform.* keys, account members, users without an account)
|
|
11
|
+
* gets 403.
|
|
11
12
|
*/
|
|
12
13
|
|
|
13
14
|
import { createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
|
14
15
|
import { HTTPException } from "hono/http-exception";
|
|
15
|
-
import {
|
|
16
|
+
import { createAccountIdFromScope } from "./account-agent-create.ts";
|
|
16
17
|
import type {
|
|
17
18
|
AgentTemplateService,
|
|
18
19
|
TemplateActor,
|
|
@@ -54,7 +55,7 @@ const errorResponses = {
|
|
|
54
55
|
401: { description: "Unauthorized", ...jsonError },
|
|
55
56
|
403: {
|
|
56
57
|
description:
|
|
57
|
-
"Forbidden (caller
|
|
58
|
+
"Forbidden (caller is not an account owner, or names another account / the deployment scope)",
|
|
58
59
|
...jsonError,
|
|
59
60
|
},
|
|
60
61
|
404: {
|
|
@@ -231,12 +232,14 @@ export function createAgentTemplatesApp(
|
|
|
231
232
|
}): Promise<TemplateActor> {
|
|
232
233
|
if (c.get("isAdmin") === true) return { kind: "admin" };
|
|
233
234
|
const email = c.get("callerEmail");
|
|
235
|
+
// Owners only (members use agents, they do not manage account settings):
|
|
236
|
+
// the same rule as agent creation.
|
|
234
237
|
const accountId =
|
|
235
238
|
email === undefined
|
|
236
239
|
? null
|
|
237
|
-
:
|
|
240
|
+
: createAccountIdFromScope(await callerScopeResolver(email, false));
|
|
238
241
|
if (accountId === null) {
|
|
239
|
-
throw new ForbiddenError("Admin or account access required");
|
|
242
|
+
throw new ForbiddenError("Admin or account owner access required");
|
|
240
243
|
}
|
|
241
244
|
return { kind: "account", accountId };
|
|
242
245
|
}
|
|
@@ -72,7 +72,7 @@ describeOrSkip("caller scope role resolver (integration)", () => {
|
|
|
72
72
|
expect(await role("stranger@x.com")).toBeNull();
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
-
it("owner gets account agents; member only AgentMember agents (flag on)", async () => {
|
|
75
|
+
it("owner gets account agents; member only AgentMember agents (flag off and on)", async () => {
|
|
76
76
|
const scope = (email: string, flagEnabled: boolean) =>
|
|
77
77
|
resolveCallerScope({ email, isAdmin: false, flagEnabled }, deps);
|
|
78
78
|
|
|
@@ -88,11 +88,13 @@ describeOrSkip("caller scope role resolver (integration)", () => {
|
|
|
88
88
|
agentIds: [sideAgentId],
|
|
89
89
|
role: "member",
|
|
90
90
|
});
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
// The self-serve flag no longer changes the scope.
|
|
92
|
+
expect(await scope("owner@acme.com", false)).toEqual(
|
|
93
|
+
await scope("owner@acme.com", true),
|
|
94
|
+
);
|
|
95
|
+
expect(await scope("member@acme.com", false)).toEqual(
|
|
96
|
+
await scope("member@acme.com", true),
|
|
97
|
+
);
|
|
96
98
|
});
|
|
97
99
|
|
|
98
100
|
it("unions and dedupes Agent.repos across the caller's agents", async () => {
|
package/src/caller-scope.ts
CHANGED
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Resolved per request from the caller's email — the account is deliberately
|
|
9
9
|
* NOT stored in the session JWT, so membership changes take effect
|
|
10
|
-
* immediately. Account agents contribute to the scope only for account
|
|
11
|
-
*
|
|
12
|
-
* the
|
|
10
|
+
* immediately. Account agents contribute to the scope only for account
|
|
11
|
+
* owners; members get exactly the AgentMember-only scope. The self-serve
|
|
12
|
+
* setting does not change the scope (it controls only signup and the tenant
|
|
13
|
+
* pod restrictions).
|
|
13
14
|
*/
|
|
14
15
|
|
|
15
16
|
import type { AccountService } from "./accounts.ts";
|
|
@@ -28,7 +29,11 @@ export type CallerScope =
|
|
|
28
29
|
interface CallerScopeInput {
|
|
29
30
|
email: string;
|
|
30
31
|
isAdmin: boolean;
|
|
31
|
-
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated Ignored. The self-serve setting no longer changes the scope;
|
|
34
|
+
* kept optional so existing callers keep compiling.
|
|
35
|
+
*/
|
|
36
|
+
flagEnabled?: boolean;
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
/** I/O boundary of the resolver — injected so the logic stays unit-testable. */
|
|
@@ -55,7 +60,7 @@ export type ViewerRole = "admin" | "owner" | "member";
|
|
|
55
60
|
/**
|
|
56
61
|
* The caller's role: `admin` for allowlisted callers, otherwise the
|
|
57
62
|
* AccountMember.role (`owner` | `member`), or null when the caller has no
|
|
58
|
-
* account. Independent of the self-serve
|
|
63
|
+
* account. Independent of the self-serve setting.
|
|
59
64
|
*/
|
|
60
65
|
export async function resolveViewerRole(
|
|
61
66
|
input: { email: string; isAdmin: boolean },
|
|
@@ -78,9 +83,7 @@ export async function resolveCallerScope(
|
|
|
78
83
|
if (input.isAdmin) return { kind: "all" };
|
|
79
84
|
const email = input.email.toLowerCase();
|
|
80
85
|
|
|
81
|
-
const accountId =
|
|
82
|
-
? await deps.getAccountIdByEmail(email)
|
|
83
|
-
: null;
|
|
86
|
+
const accountId = await deps.getAccountIdByEmail(email);
|
|
84
87
|
// Only owners get account-wide agents; with no role dep the role is unknown
|
|
85
88
|
// and the legacy behavior (account agents contribute) is kept.
|
|
86
89
|
const role = accountId
|
|
@@ -114,9 +117,8 @@ export function scopeIncludesAgent(
|
|
|
114
117
|
* The single "may manage this agent" predicate (settings, members,
|
|
115
118
|
* credentials, tools, crons, tokens, delete): platform admins, or the owner
|
|
116
119
|
* of the agent's own account. Everything else (members, owners of another
|
|
117
|
-
* account, callers with no account) only uses the agent.
|
|
118
|
-
* an
|
|
119
|
-
* manage. An unknown role or an agent with no account fails closed.
|
|
120
|
+
* account, callers with no account) only uses the agent. An unknown role or
|
|
121
|
+
* an agent with no account fails closed.
|
|
120
122
|
*/
|
|
121
123
|
export function scopeCanManageAgent(
|
|
122
124
|
scope: CallerScope,
|
|
@@ -134,7 +136,7 @@ export function scopeCanManageAgent(
|
|
|
134
136
|
/**
|
|
135
137
|
* How a caller may read the admin UI's task-store views — Tasks, PRs and
|
|
136
138
|
* Sessions (SSP-6.8). Platform admins see every account; an account user
|
|
137
|
-
* (
|
|
139
|
+
* (the resolver produced an accountId) sees exactly
|
|
138
140
|
* their account, filtered server-side via the task-store's `?accountId=`;
|
|
139
141
|
* anyone else keeps today's admin-only gate.
|
|
140
142
|
*/
|
|
@@ -173,18 +175,22 @@ export async function resolveMemberRepoScope(
|
|
|
173
175
|
}
|
|
174
176
|
}
|
|
175
177
|
|
|
176
|
-
/** Per-request resolver
|
|
178
|
+
/** Per-request resolver for the caller's scope. */
|
|
177
179
|
export type CallerScopeResolver = (
|
|
178
180
|
email: string,
|
|
179
181
|
isAdmin: boolean,
|
|
180
182
|
) => Promise<CallerScope>;
|
|
181
183
|
|
|
184
|
+
/**
|
|
185
|
+
* `_flagEnabled` is deprecated and ignored (the self-serve setting no longer
|
|
186
|
+
* changes the scope); it stays as an optional parameter so existing callers
|
|
187
|
+
* keep compiling.
|
|
188
|
+
*/
|
|
182
189
|
export function createCallerScopeResolver(
|
|
183
190
|
deps: CallerScopeDeps,
|
|
184
|
-
|
|
191
|
+
_flagEnabled?: boolean,
|
|
185
192
|
): CallerScopeResolver {
|
|
186
|
-
return (email, isAdmin) =>
|
|
187
|
-
resolveCallerScope({ email, isAdmin, flagEnabled }, deps);
|
|
193
|
+
return (email, isAdmin) => resolveCallerScope({ email, isAdmin }, deps);
|
|
188
194
|
}
|
|
189
195
|
|
|
190
196
|
/** Wire the resolver's I/O to the real services. */
|
|
@@ -210,19 +216,19 @@ export function callerScopeDepsFromServices(services: {
|
|
|
210
216
|
};
|
|
211
217
|
}
|
|
212
218
|
|
|
213
|
-
/**
|
|
219
|
+
/**
|
|
220
|
+
* Resolver backed only by AgentMember rows, for hosts without account
|
|
221
|
+
* services (no account ever contributes agents).
|
|
222
|
+
*/
|
|
214
223
|
export function memberOnlyCallerScopeResolver(
|
|
215
224
|
agentMemberService: Pick<AgentMemberService, "listByEmail">,
|
|
216
225
|
): CallerScopeResolver {
|
|
217
|
-
return createCallerScopeResolver(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
},
|
|
224
|
-
false,
|
|
225
|
-
);
|
|
226
|
+
return createCallerScopeResolver({
|
|
227
|
+
getAccountIdByEmail: async () => null,
|
|
228
|
+
listAgentIdsByAccount: async () => [],
|
|
229
|
+
listMemberAgentIds: async (email) =>
|
|
230
|
+
(await agentMemberService.listByEmail(email)).map((m) => m.agentId),
|
|
231
|
+
});
|
|
226
232
|
}
|
|
227
233
|
|
|
228
234
|
/** Wire the repo-scope resolver's I/O to Prisma. */
|
|
@@ -2,6 +2,7 @@ import { describe, expect, it } from "bun:test";
|
|
|
2
2
|
import {
|
|
3
3
|
type CallerScope,
|
|
4
4
|
type CallerScopeDeps,
|
|
5
|
+
createCallerScopeResolver,
|
|
5
6
|
resolveCallerScope,
|
|
6
7
|
resolveMemberRepoScope,
|
|
7
8
|
resolveViewerRole,
|
|
@@ -120,16 +121,19 @@ describe("resolveCallerScope", () => {
|
|
|
120
121
|
});
|
|
121
122
|
});
|
|
122
123
|
|
|
123
|
-
it("flag
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
it("the self-serve flag does not change the scope", async () => {
|
|
125
|
+
for (const email of ["a@x.com", "both@x.com", "mem@x.com", "m@x.com"]) {
|
|
126
|
+
expect(await run(email, false, false)).toEqual(await run(email));
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("createCallerScopeResolver works without a flag", async () => {
|
|
131
|
+
const resolve = createCallerScopeResolver(deps);
|
|
132
|
+
expect(await resolve("a@x.com", false)).toEqual({
|
|
130
133
|
kind: "scoped",
|
|
131
|
-
accountId:
|
|
132
|
-
agentIds: [],
|
|
134
|
+
accountId: "acct-a",
|
|
135
|
+
agentIds: ["ag-1", "ag-2"],
|
|
136
|
+
role: "owner",
|
|
133
137
|
});
|
|
134
138
|
});
|
|
135
139
|
});
|
|
@@ -209,9 +213,9 @@ describe("resolveViewerRole", () => {
|
|
|
209
213
|
describe("resolveCallerScope matrix: role x flag", () => {
|
|
210
214
|
const cases: Array<[string, boolean, string[], string | null]> = [
|
|
211
215
|
["a@x.com", true, ["ag-1", "ag-2"], "acct-a"], // owner, flag on
|
|
212
|
-
["a@x.com", false, [],
|
|
216
|
+
["a@x.com", false, ["ag-1", "ag-2"], "acct-a"], // owner, flag off
|
|
213
217
|
["memboth@x.com", true, ["ag-9"], "acct-a"], // member, flag on
|
|
214
|
-
["memboth@x.com", false, ["ag-9"],
|
|
218
|
+
["memboth@x.com", false, ["ag-9"], "acct-a"], // member, flag off
|
|
215
219
|
["none@x.com", true, [], null], // no account
|
|
216
220
|
["none@x.com", false, [], null],
|
|
217
221
|
];
|
package/src/platform-routes.ts
CHANGED
|
@@ -96,7 +96,7 @@ export function mountPlatformApis(
|
|
|
96
96
|
const adminApiApp = createAdminApp(deps.adminApi);
|
|
97
97
|
mount({ name: "admin", prefix: "/", app: adminApiApp, inSpec: true });
|
|
98
98
|
|
|
99
|
-
// Platform OpenAPI document — GET /doc
|
|
99
|
+
// Platform OpenAPI document — GET /doc (mounted when the host supplies doc deps).
|
|
100
100
|
if (deps.doc) mountPlatformDoc(root, deps.doc);
|
|
101
101
|
|
|
102
102
|
mount({
|
|
@@ -105,7 +105,7 @@ export function mountPlatformApis(
|
|
|
105
105
|
app: createAccountsApp(deps.accounts),
|
|
106
106
|
inSpec: false,
|
|
107
107
|
specExclusion:
|
|
108
|
-
"
|
|
108
|
+
"account administration (admin-only); never part of the committed platform spec",
|
|
109
109
|
});
|
|
110
110
|
// The three apps below own disjoint prefixes, so their relative order does
|
|
111
111
|
// not affect routing; it is fixed to keep the committed spec's key order.
|