diff --git a/browser-host/relay-broker.mjs b/browser-host/relay-broker.mjs index 1b9fbbbded..b514ccd632 100644 --- a/browser-host/relay-broker.mjs +++ b/browser-host/relay-broker.mjs @@ -336,6 +336,9 @@ async function relayAuthority(fetch, relay) { channelIdentity: Array.isArray(nip11.supported_extensions) && nip11.supported_extensions.includes("nip-cl"), + soloMemberRoleUpdates: + Array.isArray(nip11.supported_extensions) && + nip11.supported_extensions.includes("buzz-solo-member-role"), // NIP-AR sync: REQ with `"artifact": "current"` keeps a set current. artifactSync: nip11.artifacts?.sync?.version === 1, artifactSupport: diff --git a/docs/buzz-help.md b/docs/buzz-help.md index e87e10650e..e39b63fa20 100644 --- a/docs/buzz-help.md +++ b/docs/buzz-help.md @@ -472,6 +472,11 @@ and are asked to sign in again in Buzz. the chat; anyone else outside the chat is only named: not added and not notified, and the picker row says so. People already in the chat are notified as usual. The toolbar's agent menu lists agents only. + In a **Private** Solo chat on a relay that supports role updates, the owner can + use a current member’s menu in **Share access** to lower their access. + The owner can restore **Participating** for a verified + agent and grant **Admin** to their own verified agents. **Viewing only** + gives read-only access to that chat. New chats start **Ongoing** unless **Chat settings** chooses **Temporary**, which archives the chat after a set time without activity. To start every new chat temporary, open the community's **Settings → Local settings** and choose diff --git a/docs/channels.md b/docs/channels.md index af9314f814..152037de32 100644 --- a/docs/channels.md +++ b/docs/channels.md @@ -1040,8 +1040,10 @@ to its underlying conversation/message without that panel. The header **Access** button opens the one access dialog every conversation uses. It is titled **Channel access** in channels and **Chat access** in a Solo chat (see -[Sharing a Solo chat](solo/sharing.md)). A Solo chat owner can remove people and -agents there but cannot change roles. +[Sharing a Solo chat](solo/sharing.md)). A Solo chat owner can remove current +non-owner members. In a Private Solo chat on a relay that supports role updates, +the owner can lower their access, restore participation for verified agents, +and grant Admin to their own verified agents. One search field, with an accessible name but no visible label, filters current members and lists people, agents and Teams to invite under **Not in this channel**. With an empty query, channels and Solo chats show invitations only when the viewer is @@ -1298,18 +1300,21 @@ disposal, but cannot retract a request already sent. Unsent work is canceled; recovery is in-memory, not durable across session disposal or restart. The development broker and native transport advertise a separate -`memberAdministration` capability and admit only exact `9000` Admin/Member/Guest -changes, the signer's own ownership transfer or `9001` other-member removals -through purpose-bound routes. Generic -invitation signing is unchanged; the relay still enforces the authoritative ACL. +`memberAdministration` capability. Its purpose-bound routes admit ordinary +channel `9000` Admin/Member/Guest changes and the signer's own ownership transfer, +as well as `9001` other-member removals. The relay enforces the authoritative ACL. Hosts without this writer can read verified roles but expose no management controls. Native support requires a rebuilt binary; no unrestricted writer fallback is used. -**Accepted protocol limitation:** role commands are existing relay upserts, not -conditional updates. A departure after final preflight can be undone by the role -command re-adding the target; a concurrent role edit can be overwritten. Client -checks/readback reduce uncertainty but do not provide atomic conflict rejection. -Preventing these races requires separately scoped relay support. +In Private Solo chats, the writer uses kind `9050` for role changes when the +relay advertises `buzz-solo-member-role` in its NIP-11 information document. +The command includes the target's expected current role. The relay updates an +existing member only if that role still matches, so it rejects the edit if the +member left or their role changed before the write. + +Ordinary channel `9000` role changes are unconditional relay upserts. A command +can re-add a member who departed after the final preflight or overwrite a +concurrent role edit. Client checks and readback reduce uncertainty. Regression coverage lives in `administration.test.ts`, `MemberAdministration.test.tsx`, `native.test.ts`, and `browser-host/relay-broker-api.test.mjs`; diff --git a/docs/solo/sharing.md b/docs/solo/sharing.md index d40d97ce75..c6f4d97fbe 100644 --- a/docs/solo/sharing.md +++ b/docs/solo/sharing.md @@ -45,8 +45,14 @@ Where the viewer cannot add agents, a note says to mention an agent in the chat instead. Current access uses the channel groups (**People**, **Agents**) with Owner and Admin tags, and each row has the channel members' actions menu, so the chat owner -can remove someone. The verified roster shows loading or failure, never treating a -failed read as an empty audience. +can remove someone. In a Private chat on a relay that supports Solo role updates, +the owner can confirm a lower role for any current non-owner, including people +and agents. +**Viewing only** gives read-only access +to the chat. A verified agent can move from **Viewing only** to **Participating**, +and the chat owner can grant **Admin** to their own verified agents. The +verified roster shows loading or failure, never treating a failed read as an +empty audience. Invitations use the same groups and controls as channels: **Your agents** first, then **People**, **Other agents** and **Your other agents**, omitting empty groups. diff --git a/src-tauri/src/relay/channel_writes.rs b/src-tauri/src/relay/channel_writes.rs index 77ddd5c1bd..56460f791c 100644 --- a/src-tauri/src/relay/channel_writes.rs +++ b/src-tauri/src/relay/channel_writes.rs @@ -127,15 +127,27 @@ fn archive(event: &EventTemplate) -> bool { .all(|b| b.is_ascii_hexdigit() && !b.is_ascii_uppercase()) } fn member_administration(event: &EventTemplate) -> bool { - matches!(event.kind, 9000 | 9001) - && event.content.is_empty() - && event.created_at <= 9_007_199_254_740_991 - && event.tags.len() == if event.kind == 9000 { 3 } else { 2 } - && tag(event, 0, "h").is_some_and(uuid) - && (ownership_transfer(event).is_some() - || (tag(event, 1, "p").is_some_and(super::hex_key) - && (event.kind == 9001 - || matches!(tag(event, 2, "role"), Some("admin" | "member" | "guest"))))) + if !event.content.is_empty() + || event.created_at > 9_007_199_254_740_991 + || !tag(event, 0, "h").is_some_and(uuid) + { + return false; + } + let target = tag(event, 1, "p").is_some_and(super::hex_key); + let role = matches!(tag(event, 2, "role"), Some("admin" | "member" | "guest")); + match (event.kind, event.tags.len()) { + (9000, 3) => ownership_transfer(event).is_some() || (target && role), + (9001, 2) => target, + (9050, 4) => { + target + && role + && matches!( + tag(event, 3, "expected_role"), + Some("admin" | "member" | "guest" | "bot") + ) + } + _ => false, + } } /// The stepping-down owner of `[h, ["p", heir, "owner"], ["p", owner, "admin"]]`. fn ownership_transfer(event: &EventTemplate) -> Option<&str> { diff --git a/src/bundled/channels/MemberAdministration.test.tsx b/src/bundled/channels/MemberAdministration.test.tsx index 3981fea461..bf2c5c27ce 100644 --- a/src/bundled/channels/MemberAdministration.test.tsx +++ b/src/bundled/channels/MemberAdministration.test.tsx @@ -63,10 +63,17 @@ async function setup( messageNavigation = true, initialReads?: { names?: Promise; roster?: Promise }, ownership?: "own" | "other" | "invalid", - visibility: "private" | "public" = "private", + visibility: "private" | "public" | "solo" | "view-only-solo" = "private", targetPicture?: string, targetProfiled = true, ) { + const solo = visibility === "solo" || visibility === "view-only-solo"; + const visibilityFlag = + visibility === "solo" + ? "private" + : visibility === "view-only-solo" + ? "public" + : visibility; const viewer = keypair(), relay = keypair(), target = keypair(), @@ -116,7 +123,14 @@ async function setup( kind: 39000, created_at: tick, content: "", - tags: [["d", id], ["t", "stream"], [visibility], ["name", "Design"]], + tags: [ + ["d", id], + ["t", "stream"], + [visibilityFlag], + ...(solo ? [["t", "buzz.solo"]] : []), + ...(visibility === "view-only-solo" ? [["join_role", "guest"]] : []), + ["name", "Design"], + ], }), signed(relay, { kind: 39001, @@ -184,6 +198,7 @@ async function setup( memberAdministration: { sign: async (template) => signed(viewer, template), publish, + ...(solo ? { soloMemberRoleUpdates: true as const } : {}), }, } : {}), @@ -773,6 +788,106 @@ it("keeps resolved rows and focus while refreshing, and reopens warm without a s } }); +it.each([ + ["owner", true, true], + ["owner", false, true], + ["admin", true, false], +] as const)( + "Solo %s sees downgrade controls for a current Admin (agent=%s)", + async (actor, agent, allowed) => { + const t = await setup( + actor, + "admin", + true, + undefined, + agent, + undefined, + false, + true, + undefined, + undefined, + "solo", + ); + await t.user.click( + screen.getByRole("button", { name: /^Actions for Morgan$/ }), + ); + await screen.findByRole("menuitem", { name: "View profile" }); + expect(screen.queryAllByRole("menuitemradio")).toHaveLength( + allowed ? 3 : 0, + ); + expect( + screen.queryByRole("menuitem", { name: "Transfer ownership" }), + ).not.toBeInTheDocument(); + if (!allowed) return; + await t.user.click( + screen.getByRole("menuitemradio", { name: "Viewing only" }), + ); + const dialog = await screen.findByRole("dialog", { + name: "Change access to Viewing only?", + }); + expect(t.publish).not.toHaveBeenCalled(); + await t.user.click( + within(dialog).getByRole("button", { name: "Set to viewing only" }), + ); + await vi.waitFor(() => + expect( + t.session.memberAdministration.snapshot(id).operation?.status, + ).toBe("confirmed"), + ); + expect(t.publish).toHaveBeenCalledOnce(); + expect(t.publish.mock.calls[0]?.[0]).toMatchObject({ + kind: 9050, + tags: expect.arrayContaining([["expected_role", "admin"]]), + }); + }, +); +it("offers only a downgrade for a Solo participant with an unattested agent profile", async () => { + const t = await setup( + "owner", + "member", + true, + undefined, + true, + undefined, + false, + true, + undefined, + undefined, + "solo", + ); + await t.user.click( + screen.getByRole("button", { name: /^Actions for Morgan$/ }), + ); + await screen.findByRole("menuitemradio", { name: "Viewing only" }); + expect( + screen.getByRole("menuitemradio", { name: "Participating" }), + ).toHaveAttribute("aria-checked", "true"); + expect( + screen.queryByRole("menuitemradio", { name: "Admin" }), + ).not.toBeInTheDocument(); +}); +it("keeps removal in a View only Solo chat without showing role choices", async () => { + const t = await setup( + "owner", + "admin", + true, + undefined, + false, + undefined, + false, + true, + undefined, + undefined, + "view-only-solo", + ); + await t.user.click( + screen.getByRole("button", { name: "Actions for Morgan" }), + ); + expect( + await screen.findByRole("menuitem", { name: "Remove from chat" }), + ).toBeInTheDocument(); + expect(screen.queryAllByRole("menuitemradio")).toHaveLength(0); +}); it("presents verified roles, protects owners/self, and confirms a separate deliberate role intent", async () => { const t = await setup(); await expectProfileOnly(t.user, "Carl"); diff --git a/src/bundled/channels/MemberAdministration.tsx b/src/bundled/channels/MemberAdministration.tsx index 29f68170b8..d02db36651 100644 --- a/src/bundled/channels/MemberAdministration.tsx +++ b/src/bundled/channels/MemberAdministration.tsx @@ -14,7 +14,7 @@ import { } from "react"; import type { RelaySession } from "../../features/relay/session"; import { - canManageMember, + canSetMemberRole, canRemoveMember, canTransferOwnership, editableMemberRoles, @@ -316,8 +316,21 @@ export function MemberRow({ const role = state.authority.roles[pubkey] ?? "unknown"; const permitted = !invitationAction && capability.available && state.status === "ready"; - const canEdit = - permitted && canManageMember(state.authority, session.viewer ?? "", pubkey); + const currentAccess = role === "bot" ? "member" : role; + const roleChanges = permitted + ? editableMemberRoles.filter( + (next) => + next !== currentAccess && + canSetMemberRole( + state.authority, + session.viewer ?? "", + pubkey, + next, + verifiedOwner, + ), + ) + : []; + const canEdit = roleChanges.length > 0; const canTransfer = permitted && canTransferOwnership(state.authority, session.viewer ?? "", pubkey, agent); @@ -371,23 +384,26 @@ export function MemberRow({ {canEdit && ( { - const target = editableMemberRoles.find( - (value) => value === next, - ); - if (target && target !== role) { + const target = roleChanges.find((value) => value === next); + if (target) { // The shared popup outlives the choice; the confirmation takes over. menus.close(); choose(target); } }} > - {editableMemberRoles.map((next) => ( - - {memberAccessLabel(next)} - - ))} + {editableMemberRoles + .filter( + (next) => + next === currentAccess || roleChanges.includes(next), + ) + .map((next) => ( + + {memberAccessLabel(next)} + + ))} )} {canEdit && } diff --git a/src/features/channel-members/administration-contract.json b/src/features/channel-members/administration-contract.json index cc035c0b78..8507b1b1ca 100644 --- a/src/features/channel-members/administration-contract.json +++ b/src/features/channel-members/administration-contract.json @@ -1,5 +1,39 @@ { "accepted": [ + { + "name": "conditional Solo role change", + "event": { + "kind": 9050, + "created_at": 1700000010, + "content": "", + "tags": [ + ["h", "11111111-1111-4111-8111-111111111111"], + [ + "p", + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + ], + ["role", "member"], + ["expected_role", "admin"] + ] + } + }, + { + "name": "conditional Solo role change from bot to admin", + "event": { + "kind": 9050, + "created_at": 1700000010, + "content": "", + "tags": [ + ["h", "11111111-1111-4111-8111-111111111111"], + [ + "p", + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + ], + ["role", "admin"], + ["expected_role", "bot"] + ] + } + }, { "name": "remove", "event": { @@ -65,6 +99,90 @@ } ], "rejected": [ + { + "name": "Solo role change without expected role", + "event": { + "kind": 9050, + "created_at": 1700000010, + "content": "", + "tags": [ + ["h", "11111111-1111-4111-8111-111111111111"], + [ + "p", + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + ], + ["role", "member"] + ] + } + }, + { + "name": "Solo role change with owner as expected role", + "event": { + "kind": 9050, + "created_at": 1700000010, + "content": "", + "tags": [ + ["h", "11111111-1111-4111-8111-111111111111"], + [ + "p", + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + ], + ["role", "member"], + ["expected_role", "owner"] + ] + } + }, + { + "name": "Solo role change with absent as expected role", + "event": { + "kind": 9050, + "created_at": 1700000010, + "content": "", + "tags": [ + ["h", "11111111-1111-4111-8111-111111111111"], + [ + "p", + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + ], + ["role", "member"], + ["expected_role", "absent"] + ] + } + }, + { + "name": "Solo role change with a misnamed expected-role tag", + "event": { + "kind": 9050, + "created_at": 1700000010, + "content": "", + "tags": [ + ["h", "11111111-1111-4111-8111-111111111111"], + [ + "p", + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + ], + ["role", "member"], + ["old_role", "admin"] + ] + } + }, + { + "name": "Solo role change with owner as the new role", + "event": { + "kind": 9050, + "created_at": 1700000010, + "content": "", + "tags": [ + ["h", "11111111-1111-4111-8111-111111111111"], + [ + "p", + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" + ], + ["role", "owner"], + ["expected_role", "admin"] + ] + } + }, { "name": "wrong kind", "event": { diff --git a/src/features/channel-members/administration-protocol.ts b/src/features/channel-members/administration-protocol.ts index 98a173bfbd..3bee31fa7a 100644 --- a/src/features/channel-members/administration-protocol.ts +++ b/src/features/channel-members/administration-protocol.ts @@ -1,5 +1,6 @@ import type { EventTemplate } from "nostr-tools"; import { soloLabels } from "../solo/labels.ts"; +import { channelVisibility } from "../relay/channel-details-protocol.ts"; import { channelIdentity } from "../relay/channel-labels.ts"; import type { RelayEvent } from "../relay/events.ts"; import { @@ -10,6 +11,7 @@ import { } from "../relay/channel-lifecycle-protocol.ts"; export const editableMemberRoles = ["admin", "member", "guest"] as const; +export const SOLO_MEMBER_ROLE_KIND = 9050; export type EditableMemberRole = (typeof editableMemberRoles)[number]; export type MemberRole = EditableMemberRole | "owner" | "bot" | "unknown"; export type MemberChange = Readonly<{ @@ -22,6 +24,8 @@ export type MemberChange = Readonly<{ export type MemberAuthority = Readonly<{ roles: Readonly>; canManage: boolean; + /** Solo owners use the conditional role-update command for current members. */ + canManageSolo: boolean; canRemove: boolean; canRemoveOwnedAgent: boolean; /** A NIP-CL system channel, where administration may also add members. */ @@ -35,6 +39,7 @@ export function memberAuthority( channelId: string, viewer: string, relayAuthor: string, + soloMemberRoleUpdates = false, ): MemberAuthority { if (events.some((event) => ![39000, 39001, 39002].includes(event.kind))) throw new Error("Unexpected channel membership response"); @@ -95,11 +100,17 @@ export function memberAuthority( "Member roles are inconsistent. Refresh members and roles.", ); const activeChannel = type !== "dm" && archived !== "true"; - // In Solo chats only owners and admins remove people; nobody changes roles. const solo = !!soloLabels(channelIdentity(metadata).labels); return Object.freeze({ roles: Object.freeze(roles), canManage: activeChannel && !solo && elevated.has(viewer), + canManageSolo: + soloMemberRoleUpdates && + type === "stream" && + activeChannel && + solo && + channelVisibility(metadata) === "private" && + elevated.get(viewer) === "owner", canRemove: activeChannel && elevated.has(viewer), canRemoveOwnedAgent: activeChannel && !solo && !!roles[viewer] && roles[viewer] !== "unknown", @@ -107,19 +118,25 @@ export function memberAuthority( }); } -export function canManageMember( +function isRoleTarget(state: MemberAuthority, viewer: string, key: string) { + const role = state.roles[key]; + return key !== viewer && !!role && role !== "owner" && role !== "unknown"; +} + +export function canSetMemberRole( state: MemberAuthority, viewer: string, key: string, + next: EditableMemberRole, + agentOwner?: string, ) { - const role = state.roles[key]; - return ( - state.canManage && - key !== viewer && - !!role && - role !== "owner" && - role !== "unknown" - ); + if (!isRoleTarget(state, viewer, key)) return false; + if (state.canManage) return true; + if (!state.canManageSolo) return false; + const current = state.roles[key]; + if (next === "admin") return current !== "admin" && agentOwner === viewer; + if (next === "guest") return current !== "guest"; + return current === "admin" || (current === "guest" && !!agentOwner); } /** Ownership permits removal only; it never grants role-edit authority. */ @@ -154,7 +171,8 @@ export function canTransferOwnership( !state.system && state.roles[viewer] === "owner" && state.roles[key] !== "bot" && - canManageMember(state, viewer, key) + state.canManage && + isRoleTarget(state, viewer, key) ); } @@ -163,8 +181,8 @@ export function authorizeMemberChange( viewer: string, change: MemberChange, owner?: string, - /** Whether `change.pubkey` is an agent; unknown counts as one. */ - agent = true, + /** A possibly-agent target cannot receive ownership. */ + agent?: boolean, ) { if (change.expectedRole === "none") { // This sentinel is reserved for the system-channel setup path. @@ -190,9 +208,15 @@ export function authorizeMemberChange( : change.role === "remove" ? canRemoveMember(state, viewer, change.pubkey, owner) : change.role === "owner" - ? canTransferOwnership(state, viewer, change.pubkey, agent) - : canManageMember(state, viewer, change.pubkey) && - isEditableMemberRole(change.role)) || + ? canTransferOwnership(state, viewer, change.pubkey, agent !== false) + : isEditableMemberRole(change.role) && + canSetMemberRole( + state, + viewer, + change.pubkey, + change.role, + owner, + )) || (change.expectedRole !== "absent" && state.roles[change.pubkey] !== change.expectedRole) || change.expectedRole === change.role @@ -228,10 +252,15 @@ export function memberAdministrationTemplate( channelId: string, viewer: string, change: MemberChange, + soloRoleUpdate = false, ): EventTemplate { const h = ["h", lifecycleChannelId(channelId)]; return { - kind: change.role === "remove" ? 9001 : 9000, + kind: soloRoleUpdate + ? SOLO_MEMBER_ROLE_KIND + : change.role === "remove" + ? 9001 + : 9000, created_at: Math.floor(Date.now() / 1000), content: "", // The relay decides each person in order, so the heir's promotion lets @@ -243,6 +272,7 @@ export function memberAdministrationTemplate( h, ["p", change.pubkey], ...(change.role === "remove" ? [] : [["role", change.role]]), + ...(soloRoleUpdate ? [["expected_role", change.expectedRole]] : []), ], }; } @@ -252,7 +282,8 @@ export function validateMemberAdministrationTemplate( event: EventTemplate, viewer: string, ) { - const [h, p, last] = event?.tags ?? []; + const [h, p, last, expected] = event?.tags ?? []; + const soloRoleUpdate = event?.kind === SOLO_MEMBER_ROLE_KIND; const transfer = event?.kind === 9000 && p?.length === 3 && @@ -264,28 +295,34 @@ export function validateMemberAdministrationTemplate( PUBKEY.test(viewer); if ( !event || - ![9000, 9001].includes(event.kind) || + ![9000, 9001, SOLO_MEMBER_ROLE_KIND].includes(event.kind) || event.content !== "" || !Number.isSafeInteger(event.created_at) || event.created_at < 0 || !Array.isArray(event.tags) || - event.tags.length !== (event.kind === 9000 ? 3 : 2) || + event.tags.length !== (soloRoleUpdate ? 4 : event.kind === 9000 ? 3 : 2) || h?.length !== 2 || h[0] !== "h" || p?.length !== (transfer ? 3 : 2) || p[0] !== "p" || !PUBKEY.test(p[1] ?? "") || p[1] === viewer || - (event.kind === 9000 && + (event.kind !== 9001 && !transfer && (last?.length !== 2 || last[0] !== "role" || - !isEditableMemberRole(last[1]))) + !isEditableMemberRole(last[1]))) || + (soloRoleUpdate && + (expected?.length !== 2 || + expected[0] !== "expected_role" || + !(expected[1] === "bot" || isEditableMemberRole(expected[1])))) ) throw new Error("Invalid member administration command"); lifecycleChannelId(h[1] ?? ""); } -function isEditableMemberRole(role: unknown): role is EditableMemberRole { +export function isEditableMemberRole( + role: unknown, +): role is EditableMemberRole { return editableMemberRoles.some((value) => value === role); } diff --git a/src/features/channel-members/administration.test.ts b/src/features/channel-members/administration.test.ts index 201df030d8..f7b6ededf4 100644 --- a/src/features/channel-members/administration.test.ts +++ b/src/features/channel-members/administration.test.ts @@ -46,7 +46,11 @@ function deferred() { }); return { promise, resolve }; } -function harness(actor = "owner", role: string | undefined = "member") { +function harness( + actor = "owner", + role: string | undefined = "member", + soloMemberRoleUpdates = false, +) { let clock = 100; const record = (kind: number, tags: string[][]) => finalizeEvent({ kind, tags, content: "", created_at: clock++ }, relayKey); @@ -98,7 +102,11 @@ function harness(actor = "owner", role: string | undefined = "member") { const acceptDiscovery = vi.fn(); const owner = createMemberAdministration({ reader: { read }, - writer: { sign, publish }, + writer: { + sign, + publish, + ...(soloMemberRoleUpdates ? { soloMemberRoleUpdates: true } : {}), + }, viewer, relayAuthor: author, canAccess: () => access, @@ -441,7 +449,7 @@ it("lets a Solo chat owner remove a participant", async () => { ], }); }); -it("never lets a Solo chat owner change roles", async () => { +it("never lets a Solo chat owner change a person's role", async () => { const h = soloHarness(); await h.owner.capability.run(id, change); expect(h.sign).not.toHaveBeenCalled(); @@ -552,6 +560,7 @@ it.each(["ack", "lost", "read"])( authority: { roles: {}, canManage: false, + canManageSolo: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -593,6 +602,7 @@ it.each(["access", "invalid ID"])( authority: { roles: {}, canManage: false, + canManageSolo: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -620,6 +630,7 @@ it.each(["clear", "dispose"] as const)( authority: { roles: {}, canManage: false, + canManageSolo: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -808,6 +819,7 @@ it.each(["cache", "access"] as const)( authority: { roles: {}, canManage: false, + canManageSolo: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -823,6 +835,7 @@ it.each(["cache", "access"] as const)( expect(admin.snapshot(id).authority).toEqual({ roles: {}, canManage: false, + canManageSolo: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -933,8 +946,12 @@ function agentProfile(ownerKey = key, created_at = 200, valid = true) { new Uint8Array(32).fill(4), ); } -function ownedAgent(actor = "member", role = "bot") { - const h = harness(actor, role); +function ownedAgent( + actor = "member", + role = "bot", + soloMemberRoleUpdates = false, +) { + const h = harness(actor, role, soloMemberRoleUpdates); let profiles = [agentProfile()]; h.read.mockImplementation(async (filters) => filters.some((filter) => filter.kinds?.includes(0)) ? profiles : h.events(), @@ -1175,6 +1192,166 @@ function transferHarness( h.setProfiles(profiles); return h; } +function soloAgent( + actor = "owner", + role = "bot", + profiles = [agentProfile()], + soloMemberRoleUpdates = true, + visibilityTags = [["private"]], +) { + const h = ownedAgent(actor, role, soloMemberRoleUpdates); + h.setProfiles(profiles); + const setVisibility = (tags: string[][]) => + h.setEvents([ + h.record(39000, [["d", id], ["t", "stream"], ["t", SOLO_LABEL], ...tags]), + ...h.events().slice(1), + ]); + setVisibility(visibilityTags); + return { ...h, setVisibility }; +} +it.each([ + { name: "an older relay", supported: false, tags: [["private"]] }, + { + name: "a View only chat", + supported: true, + tags: [["public"], ["join_role", "guest"]], + }, + { name: "unknown visibility", supported: true, tags: [] }, + { + name: "contradictory visibility", + supported: true, + tags: [["private"], ["public"]], + }, +])( + "refuses a Solo role update before signing with $name and still allows removal", + async ({ supported, tags }) => { + const h = soloAgent("owner", "bot", [agentProfile()], supported, tags); + const capability = h.owner.capability; + await capability.refresh(id); + expect(capability.snapshot(id).authority.canManageSolo).toBe(false); + await capability.run(id, { ...change, expectedRole: "bot", role: "guest" }); + expect(capability.snapshot(id).operation?.status).toBe("failed"); + expect(h.sign).not.toHaveBeenCalled(); + expect(h.publish).not.toHaveBeenCalled(); + await capability.run(id, removeAgent); + expect(capability.snapshot(id).operation?.status).toBe("confirmed"); + expect(h.publish.mock.calls[0]?.[0].kind).toBe(9001); + }, +); +it("discards a Solo role edit if the chat becomes View only during signing", async () => { + const h = soloAgent(); + h.sign.mockImplementationOnce(async (template) => { + h.setVisibility([["public"], ["join_role", "guest"]]); + return finalizeEvent(structuredClone(template), key); + }); + await h.owner.capability.run(id, { + ...change, + expectedRole: "bot", + role: "guest", + }); + expect(h.sign).toHaveBeenCalledOnce(); + expect(h.publish).not.toHaveBeenCalled(); + expect(h.owner.capability.snapshot(id).operation?.status).toBe("failed"); +}); +it.each([ + ["admin", "member", personProfile()], + ["admin", "guest", personProfile()], + ["member", "guest", personProfile()], + ["admin", "member", agentProfile(relayKey)], + ["bot", "guest", agentProfile(relayKey)], + ["guest", "member", agentProfile(relayKey)], + ["bot", "admin", agentProfile()], +] as const)( + "lets a Solo owner change access from %s to %s when permitted", + async (before, role, profile) => { + const h = soloAgent("owner", before, [profile]); + await h.owner.capability.run(id, { ...change, expectedRole: before, role }); + expect(h.publish.mock.calls[0]?.[0]).toMatchObject({ + kind: 9050, + tags: [ + ["h", id], + ["p", target], + ["role", role], + ["expected_role", before], + ], + }); + expect(h.owner.capability.snapshot(id).operation?.status).toBe("confirmed"); + }, +); +it.each([ + ["member", "admin", agentProfile(relayKey)], + ["member", "admin", agentProfile(key, 200, false)], + ["guest", "member", agentProfile(key, 200, false)], + ["guest", "member", personProfile()], +] as const)( + "refuses an unauthorized Solo promotion from %s to %s", + async (before, role, profile) => { + const h = soloAgent("owner", before, [profile]); + await h.owner.capability.run(id, { ...change, expectedRole: before, role }); + expect(h.sign).not.toHaveBeenCalled(); + }, +); +it.each(["admin", "member", "guest"])( + "denies a Solo %s an agent role edit", + async (actor) => { + const h = soloAgent(actor); + await h.owner.capability.run(id, { ...change, expectedRole: "bot" }); + expect(h.sign).not.toHaveBeenCalled(); + }, +); +it.each(["person", "missing", "transfer", "addition"])( + "keeps Solo %s restrictions", + async (failure) => { + const h = soloAgent( + "owner", + "member", + failure === "person" + ? [personProfile()] + : failure === "missing" + ? [] + : [agentProfile()], + ); + await h.owner.capability.run(id, { + ...change, + ...(failure === "transfer" ? { role: "owner" } : {}), + ...(failure === "addition" + ? { pubkey: author, expectedRole: "absent" } + : {}), + }); + expect(h.sign).not.toHaveBeenCalled(); + }, +); +it("rechecks the Solo target profile after signing", async () => { + const h = soloAgent(); + h.sign.mockImplementationOnce(async (template) => { + h.setProfiles([personProfile()]); + return finalizeEvent(structuredClone(template), key); + }); + await h.owner.capability.run(id, { ...change, expectedRole: "bot" }); + expect(h.sign).toHaveBeenCalledOnce(); + expect(h.publish).not.toHaveBeenCalled(); +}); +it("discards a standard role write if the channel becomes Solo while signing", async () => { + const h = harness("owner", "admin"); + h.sign.mockImplementationOnce(async (template) => { + h.setEvents([ + h.record(39000, [ + ["d", id], + ["t", "stream"], + ["t", SOLO_LABEL], + ]), + ...h.events().slice(1), + ]); + return finalizeEvent(structuredClone(template), key); + }); + await h.owner.capability.run(id, { + ...change, + expectedRole: "admin", + role: "guest", + }); + expect(h.sign).toHaveBeenCalledOnce(); + expect(h.publish).not.toHaveBeenCalled(); +}); it("transfers ownership in one event that steps the viewer down to admin", async () => { const h = transferHarness(); await h.owner.capability.run(id, transfer); @@ -1202,6 +1379,7 @@ it("never offers a transfer to a co-owner", () => { const state = { roles: { [viewer]: "owner" as const, [target]: "owner" as const }, canManage: true, + canManageSolo: false, canRemove: true, canRemoveOwnedAgent: false, system: false, @@ -1231,6 +1409,7 @@ it("authorizes a system-channel add only for a non-member other than the viewer const state = { roles: { [viewer]: "owner" as const, [author]: "member" as const }, canManage: true, + canManageSolo: false, canRemove: true, canRemoveOwnedAgent: false, system: true, diff --git a/src/features/channel-members/administration.ts b/src/features/channel-members/administration.ts index b5c9524bb6..1a6383b557 100644 --- a/src/features/channel-members/administration.ts +++ b/src/features/channel-members/administration.ts @@ -1,7 +1,7 @@ import { getEventHash } from "nostr-tools"; import type { RelayReader } from "../relay/reader"; import { retryRead } from "../relay/read-retry"; -import type { RelayWriter } from "../relay/transport"; +import type { ReadTransport } from "../relay/transport"; import { newer, type RelayEvent } from "../relay/events"; import { attestedOwner } from "../agents/owner-attestation"; import { foldProfiles } from "../relay/profiles"; @@ -10,6 +10,8 @@ import { lifecycleChannelId } from "../relay/channel-lifecycle-protocol"; import { authorizeMemberChange, canRemoveMember, + canSetMemberRole, + isEditableMemberRole, memberAdministrationTemplate, memberAuthority, memberChangeConfirmed, @@ -34,6 +36,7 @@ const empty: MemberAdministrationState = Object.freeze({ authority: Object.freeze({ roles: Object.freeze({}), canManage: false, + canManageSolo: false, canRemove: false, canRemoveOwnedAgent: false, system: false, @@ -52,7 +55,7 @@ export function createMemberAdministration({ acceptDiscovery, }: { reader?: RelayReader | undefined; - writer?: RelayWriter | undefined; + writer?: ReadTransport["memberAdministration"]; viewer: string; relayAuthor: string; canAccess(id: string): boolean; @@ -93,7 +96,13 @@ export function createMemberAdministration({ assertAccess(id); return { events, - authority: memberAuthority(events, id, viewer, relayAuthor), + authority: memberAuthority( + events, + id, + viewer, + relayAuthor, + writer?.soloMemberRoleUpdates === true, + ), }; } async function perform( @@ -242,10 +251,47 @@ export function createMemberAdministration({ !event || !!foldProfiles([event]).get(change.pubkey)?.isAgent; if (agent) throw new Error(transferRefusal); } - authorizeMemberChange(authority, viewer, change, owner, agent); + const soloRoleUpdate = + authority.canManageSolo && isEditableMemberRole(change.role); + let targetOwner = owner; + if ( + soloRoleUpdate && + !canSetMemberRole( + authority, + viewer, + change.pubkey, + change.role, + ) && + canSetMemberRole( + authority, + viewer, + change.pubkey, + change.role, + viewer, + ) + ) { + // Promotions require fresh ownership proof on both preflights. + const event = await profile(); + targetOwner = event && (await attestedOwner(event)); + signal.throwIfAborted(); + assertAccess(id); + } + authorizeMemberChange( + authority, + viewer, + change, + targetOwner, + agent, + ); + return soloRoleUpdate; }; - await authorize(); - const template = memberAdministrationTemplate(id, viewer, change); + const soloRoleUpdate = await authorize(); + const template = memberAdministrationTemplate( + id, + viewer, + change, + soloRoleUpdate, + ); validateMemberAdministrationTemplate(template, viewer); const signed = await writer.sign(structuredClone(template), signal); signal.throwIfAborted(); @@ -258,7 +304,10 @@ export function createMemberAdministration({ getEventHash(signed) !== signed.id ) throw new Error("Signer changed the member administration command"); - await authorize(); + if ((await authorize()) !== soloRoleUpdate) + throw new Error( + "Chat type changed. Refresh members and roles before trying again.", + ); signal.throwIfAborted(); if (active?.() === false) throw new DOMException("Member change cancelled", "AbortError"); diff --git a/src/features/relay/native.test.ts b/src/features/relay/native.test.ts index cf35df6a04..6664535f3f 100644 --- a/src/features/relay/native.test.ts +++ b/src/features/relay/native.test.ts @@ -247,6 +247,21 @@ it("reads back expired delivery with strong consistency without re-signing or pu vi.mocked(invoke).mock.calls.some(([command]) => command === "relay_sign"), ).toBe(false); }); +it.each([ + [undefined, undefined], + [["nip-cl"], undefined], + ["buzz-solo-member-role", undefined], + [["nip-cl", "buzz-solo-member-role"], true], +])( + "requires an explicit NIP-11 advertisement for Solo role updates: %o", + async (supported_extensions, expected) => { + discovery = { supported_extensions }; + expect( + (await connectNativeTransport(community)).memberAdministration + ?.soloMemberRoleUpdates, + ).toBe(expected); + }, +); it.each([ {}, { supported_extensions: null }, @@ -2148,14 +2163,15 @@ it("routes member administration through the native purpose-bound writer, never await expect(writer.sign(event, signal)).rejects.toThrow(); const template = memberContract.accepted[0]?.event; assert.exists(template); - const channelTag = template.tags[0]; - assert.exists(channelTag); - await expect( - writer.sign( - { ...template, tags: [channelTag, ["p", viewer.pubkey]] }, - signal, + const selfTarget = { + ...template, + tags: template.tags.map((tag) => + tag[0] === "p" ? ["p", viewer.pubkey] : tag, ), - ).rejects.toThrow(); + }; + await expect(writer.sign(selfTarget, signal)).rejects.toThrow( + "Invalid member administration command", + ); await expect( writer.publish(signed(relay, template), signal), ).rejects.toThrow(); diff --git a/src/features/relay/native.ts b/src/features/relay/native.ts index dc49283ef1..980404ba4c 100644 --- a/src/features/relay/native.ts +++ b/src/features/relay/native.ts @@ -454,6 +454,9 @@ export async function connectNativeTransport( const channelIdentity = Array.isArray(info.supported_extensions) && info.supported_extensions.includes("nip-cl"); + const soloMemberRoleUpdates = + Array.isArray(info.supported_extensions) && + info.supported_extensions.includes("buzz-solo-member-role"); const artifactSupport = Array.isArray(info.supported_extensions) && info.supported_extensions.includes("nip-ar"); @@ -598,9 +601,14 @@ export async function connectNativeTransport( validateLifecycleTemplate, ), channelDetails: commandWriter("channel-details", validateDetailsTemplate), - memberAdministration: commandWriter("member-administration", (event) => - validateMemberAdministrationTemplate(event, transport.viewer ?? ""), - ), + memberAdministration: { + ...commandWriter("member-administration", (event) => + validateMemberAdministrationTemplate(event, transport.viewer ?? ""), + ), + ...(soloMemberRoleUpdates + ? { soloMemberRoleUpdates: true as const } + : {}), + }, identityArchive: commandWriter( "identity-archive", validateArchiveRequestTemplate, diff --git a/src/features/relay/transport.ts b/src/features/relay/transport.ts index 182827f287..feb4544dde 100644 --- a/src/features/relay/transport.ts +++ b/src/features/relay/transport.ts @@ -140,7 +140,10 @@ export interface ReadTransport { readonly channelLifecycle?: RelayWriter; /** Name/about/private-only metadata writer, separate from lifecycle and outbox. */ readonly channelDetails?: RelayWriter; - readonly memberAdministration?: RelayWriter; + readonly memberAdministration?: RelayWriter & { + /** NIP-11 advertises `buzz-solo-member-role` for kind:9050 updates. */ + readonly soloMemberRoleUpdates?: true; + }; /** NIP-AR kind-45010 config artifacts only; never supplied to the outbox. */ readonly configArtifacts?: RelayWriter; /** Narrow NIP-IA 9035/9036 signer/publisher; never supplied to the message outbox. */ @@ -553,6 +556,7 @@ export async function connectBrokerTransport( sidebarMuteWrites?: boolean; channelKit?: boolean; channelIdentity?: boolean; + soloMemberRoleUpdates?: boolean; searchSort?: boolean; artifactSync?: boolean; sidebarPreferenceWrites?: boolean; @@ -1130,7 +1134,14 @@ export async function connectBrokerTransport( ? { channelDetails: routeWriter("channel-details") } : {}), ...(session.memberAdministration === true - ? { memberAdministration: routeWriter("member-administration") } + ? { + memberAdministration: { + ...routeWriter("member-administration"), + ...(session.soloMemberRoleUpdates === true + ? { soloMemberRoleUpdates: true as const } + : {}), + }, + } : {}), ...(session.channelLifecycle === true ? { channelLifecycle: routeWriter("channel-lifecycle") } diff --git a/tests/browser/fixture.mjs b/tests/browser/fixture.mjs index ff2aae97e1..33cef332ca 100644 --- a/tests/browser/fixture.mjs +++ b/tests/browser/fixture.mjs @@ -67,6 +67,7 @@ export const test = base.extend({ sortingSidebar: [false, { option: true }], initialSidebarSort: [{}, { option: true }], channelLifecycle: [false, { option: true }], + memberRoleChanges: [false, { option: true }], leaveRosterBeforeAck: [false, { option: true }], guestPermalinks: [false, { option: true }], lifecycleRole: ["owner", { option: true }], @@ -161,6 +162,7 @@ export const test = base.extend({ sortingSidebar, initialSidebarSort, channelLifecycle, + memberRoleChanges, leaveRosterBeforeAck, guestPermalinks, lifecycleRole, @@ -300,7 +302,7 @@ export const test = base.extend({ }, ); const ownerAgentKey = - lifecycleOwnerAgent || agentMessageDeletion + lifecycleOwnerAgent || agentMessageDeletion || memberRoleChanges ? generateSecretKey() : undefined; const ownerAgent = ownerAgentKey ? getPublicKey(ownerAgentKey) : undefined; @@ -2171,13 +2173,17 @@ export const test = base.extend({ // The production broker advertises read-state writes for every session, // not only tests opting into complete snapshot reads. acceptPublication: acceptReadPublication, - ...(actionProfile || channelLifecycle + ...(actionProfile || channelLifecycle || memberRoleChanges ? { latencyMs: 40, holdOlder: false, acceptPublication: (community, event) => { expect(verifyEvent(event)).toBe(true); expect(event.pubkey).toBe(viewer); + if (memberRoleChanges && event.kind === 9050) { + report.publications.push({ community, event }); + return; + } if ( channelLifecycle && [9002, 9008, 9021, 9022, 41012].includes(event.kind) @@ -2205,8 +2211,13 @@ export const test = base.extend({ discovery: (community) => ({ self: getPublicKey(relayKey), // Solo details publications below retain label changes as well as names. - ...(ownSoloChannels.length - ? { supported_extensions: ["nip-cl"] } + ...(ownSoloChannels.length || memberRoleChanges + ? { + supported_extensions: [ + ...(ownSoloChannels.length ? ["nip-cl"] : []), + ...(memberRoleChanges ? ["buzz-solo-member-role"] : []), + ], + } : {}), ...(readState ? { @@ -2519,7 +2530,7 @@ export const test = base.extend({ communityAliases: fixtureAliases, identity: () => userKey.slice(), agentLibrary: () => ({ definitions: [], identities: [] }), - ...(readState || channelLifecycle + ...(readState || channelLifecycle || memberRoleChanges ? {} : { authority: async () => ({ @@ -2690,6 +2701,7 @@ export const test = base.extend({ return event; }, signRelay: (template) => finalizeEvent(template, relayKey), + ownerAgent, membershipSnapshot(role) { expect(["owner", "admin", "member"]).toContain(role); return sign(13534, [["member", viewer, role]], "", relayKey); diff --git a/tests/browser/solo-agent-roles.spec.mjs b/tests/browser/solo-agent-roles.spec.mjs new file mode 100644 index 0000000000..0356042138 --- /dev/null +++ b/tests/browser/solo-agent-roles.spec.mjs @@ -0,0 +1,174 @@ +import { test, expect } from "./fixture.mjs"; +import { openPage } from "./navigation.mjs"; +import { animationsSettled } from "./animations.mjs"; + +const chat = "33333333-3333-4333-8333-333333333333"; +test.use({ + productionBroker: true, + pluginFixtures: true, + channelLifecycle: true, + memberRoleChanges: true, + channelIds: ["alpha", chat], + channelNames: { alpha: "Project updates", [chat]: "Design review" }, + soloChannels: [chat], + ownSoloChannels: [chat], + historyCounts: { alpha: 0, [chat]: 0 }, + viewport: { width: 1100, height: 900 }, +}); + +async function capture(dialog, info, name) { + await animationsSettled(dialog, { subtree: true }); + await dialog.screenshot({ path: info.outputPath(name) }); +} + +async function openSoloAccess(page, app) { + await page.goto(app.origin); + await openPage(page, "Messages"); + await page.evaluate( + ({ chat, viewer }) => + window.fixtureNavigation.open({ + version: 1, + kind: "conversation", + channelId: chat, + scope: { viewer, communityOrigin: "https://primary.example" }, + }), + { chat, viewer: app.viewer }, + ); + await page.getByRole("button", { name: /^Share access to / }).click(); + return page.getByRole("button", { + name: "Actions for Owner Agent", + exact: true, + }); +} + +// Browser-only: production app routing, portalled menu hit-testing, keyboard +// selection and nested confirmation focus through the real broker signer/write. +// Only upstream signed membership policy is modeled; role matrices live in Vitest. +test("the Solo owner changes an existing agent's access from its menu", async ({ + page, + app, +}, info) => { + const agent = app.ownerAgent; + expect(agent).toBeDefined(); + app.serveMembers(chat, [agent]); + const grants = () => + app.report.publications.filter(({ event }) => event.kind === 9050); + await page.route("**/api/relay/primary/query", async (route) => { + const response = await route.fetch(); + const events = await response.json(); + const role = grants().length ? "admin" : "bot"; + await route.fulfill({ + response, + json: events.map((event) => { + if ( + ![39001, 39002].includes(event.kind) || + !event.tags.some(([tag, value]) => tag === "d" && value === chat) + ) + return event; + const tags = event.tags.filter( + ([tag, key]) => tag !== "p" || key !== agent, + ); + if (event.kind === 39002) tags.push(["p", agent, "", role]); + else if (role === "admin") tags.push(["p", agent, "admin"]); + return app.signRelay({ + ...event, + tags, + created_at: event.created_at + 100 + grants().length, + }); + }), + }); + }); + await page.addInitScript(() => { + localStorage.setItem("buzz-appearance.v1", "dark"); + localStorage.setItem("buzz-accent.v1", "cobalt"); + }); + const actions = await openSoloAccess(page, app); + await actions.click(); + const menu = page.getByRole("menu"); + await expect(menu).toBeVisible(); + await animationsSettled(menu, { subtree: true }); + const share = page.getByRole("dialog", { name: "Share access", exact: true }); + await capture(share, info, "agent-access-menu.png"); + await expect( + menu.getByRole("menuitemradio", { name: "Participating", exact: true }), + ).toHaveAttribute("aria-checked", "true"); + await expect(menu.getByRole("menuitemradio")).toHaveCount(3); + await expect( + menu.getByRole("menuitem", { name: "Transfer ownership" }), + ).toHaveCount(0); + await page.keyboard.press("Escape"); + await expect(actions).toBeFocused(); + await actions.press("Enter"); + const admin = page.getByRole("menuitemradio", { name: "Admin", exact: true }); + await admin.focus(); + await page.keyboard.press("Enter"); + const confirm = page.getByRole("dialog", { name: "Change access to Admin?" }); + const save = confirm.getByRole("button", { + name: "Set as admin", + exact: true, + }); + await expect(save).toBeFocused(); + expect(grants()).toHaveLength(0); + await capture(confirm, info, "agent-access-confirmation.png"); + await confirm.getByRole("button", { name: "Cancel", exact: true }).click(); + await expect(actions).toBeFocused(); + expect(grants()).toHaveLength(0); + await actions.click(); + await page.getByRole("menuitemradio", { name: "Admin", exact: true }).click(); + await save.click(); + await expect(share).toBeVisible(); + await expect.poll(() => grants().length).toBe(1); + expect(grants()[0].event.tags).toEqual([ + ["h", chat], + ["p", agent], + ["role", "admin"], + ["expected_role", "bot"], + ]); + await actions.click(); + await expect( + page.getByRole("menuitemradio", { name: "Admin", exact: true }), + ).toHaveAttribute("aria-checked", "true"); + await page.keyboard.press("Escape"); + for (const theme of ["light", "dark"]) { + for (const width of [1100, 390]) { + await page.setViewportSize({ width, height: 900 }); + await page.evaluate((theme) => { + document.documentElement.dataset.colorMode = theme; + document.documentElement.style.fontSize = "20px"; + }, theme); + await expect(page.locator("html")).toHaveAttribute( + "data-color-mode", + theme, + ); + await actions.click(); + for (const label of ["Admin", "Participating", "Viewing only"]) { + await expect( + page.getByRole("menuitemradio", { name: label, exact: true }), + ).toBeInViewport({ ratio: 1 }); + } + await page.keyboard.press("Escape"); + await expect(actions).toBeFocused(); + } + } + expect(app.report.unexpected).toEqual([]); +}); + +test.describe("relay without Solo role update support", () => { + test.use({ memberRoleChanges: false, lifecycleOwnerAgent: true }); + + test("keeps existing member actions without offering role changes", async ({ + page, + app, + }) => { + const agent = app.ownerAgent; + expect(agent).toBeDefined(); + app.serveMembers(chat, [agent]); + await (await openSoloAccess(page, app)).click(); + const menu = page.getByRole("menu"); + await expect( + menu.getByRole("menuitem", { name: "Remove from chat" }), + ).toBeVisible(); + await expect(menu.getByRole("menuitemradio")).toHaveCount(0); + expect(app.report.unexpected).toEqual([]); + }); +});