History

Fix self-host live-role scenario

Rhys Sullivan committed 2 months ago

Commit ea31cbe1 parent 0bd654a1 file · +23 −6Browse files

Unified · Split

e2e/selfhost/mcp-browser-approval-live-role.test.ts+23−6
@@ -26,6 +26,7 @@ return JSON.stringify(result); · 25 unmodified lines
2626
2727 interface MemberRow {
2828 readonly id: string;
29+ readonly userId: string;
2930 readonly email: string;
3031 readonly role: string;
3132 }
@@ -52,11 +53,11 @@ scenario( · 20 unmodified lines
5253 const target = yield* Target;
5354 const api = yield* Api;
5455 const mcp = yield* Mcp;
55− const actor = yield* target.newIdentity();
56− const controller = yield* Effect.promise(() =>
57− createInvitedIdentity(target.baseUrl, actor, {
56+ const controller = yield* target.newIdentity();
57+ const actor = yield* Effect.promise(() =>
58+ createInvitedIdentity(target.baseUrl, controller, {
5859 role: "admin",
59− emailPrefix: "approval-role-controller",
60+ emailPrefix: "approval-role-actor",
6061 }),
6162 );
6263 const controllerCookie = controller.headers?.cookie;
@@ -81,11 +82,22 @@ scenario( · 18 unmodified lines
8182 );
8283 const actorMember = membersBody.members.find((member) => member.email === actor.label);
8384 expect(
84− actorMember?.role === "owner" || actorMember?.role === "admin",
85+ actorMember?.role === "admin",
8586 "the actor begins with privileged organization membership",
8687 ).toBe(true);
8788 if (!actorMember) return yield* Effect.die("the actor membership was not listed");
8889
90+ const setGlobalRole = (role: "admin" | "user"): Effect.Effect<Response> =>
91+ Effect.promise(() =>
92+ accountRequest(target.baseUrl, controllerCookie, "/api/auth/admin/set-role", {
93+ method: "POST",
94+ headers: { "content-type": "application/json" },
95+ body: JSON.stringify({ userId: actorMember.userId, role }),
96+ }),
97+ );
98+ const promoted = yield* setGlobalRole("admin");
99+ expect(promoted.status, "the actor has a stale global admin role to distrust").toBe(200);
100+
89101 const setRole = (roleSlug: "admin" | "member"): Effect.Effect<Response> =>
90102 Effect.promise(() =>
91103 accountRequest(
@@ -134,7 +146,11 @@ scenario( · 42 unmodified lines
134146 );
135147
136148 expect(decision.status, "the browser decision reaches the paused execution").toBe(200);
137− expect(resumed.ok, "the resumed workspace mutation is denied at the sink").toBe(false);
149+ expect(resumed.ok, "the resumed sandbox reports the tool result normally").toBe(true);
150+ expect(
151+ resumed.text,
152+ "the resumed workspace mutation preserves the workspace-admin denial",
153+ ).toMatch(/OrgWriteDenied|administrator|admin/i);
138154 const policies = yield* actorClient.policies.list();
139155 expect(
140156 policies.some((policy) => policy.pattern === CREATED_PATTERN),
@@ -149,6 +165,7 @@ scenario( · 8 unmodified lines
149165 payload: { owner: "org" },
150166 }),
151167 ),
168+ Effect.andThen(setGlobalRole("user")),
152169 Effect.ignore,
153170 ),
154171 ),