Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

0.6.3 polish: Settings beside the space rail, Ctrl+N in Settings, room for row actions, Remove from team asks first

Pixel (kwant bot)03eb12ee3895
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index 44540a7f..3d32b0a2 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -3042,7 +3042,7 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({
const showPhoneList = isPhone && phoneView === 'list' && !needsSetup;
return (
- <div className="flex-1 min-w-0 h-full flex flex-col bg-zinc-950 text-zinc-100 overflow-hidden" data-space={space.id}>
+ <div className="relative flex-1 min-w-0 h-full flex flex-col bg-zinc-950 text-zinc-100 overflow-hidden" data-space={space.id}>
{/* The open space's colour, so it's clear where a message goes */}
<div className="h-[3px] shrink-0 opacity-60" style={{ background: spaceColor(space) }} aria-hidden="true" />
@@ -3229,6 +3229,7 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({
</Suspense>
}
routineFocus={routineFocus}
+ isPhone={isPhone}
onApprovalsChanged={refreshRoster}
onImported={() => {
// New bots, teams and their team chats.
diff --git a/frontend/src/Shell.tsx b/frontend/src/Shell.tsx
index b14c18c4..192be189 100644
--- a/frontend/src/Shell.tsx
+++ b/frontend/src/Shell.tsx
@@ -4,7 +4,7 @@
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { AlertTriangle, Loader2 } from 'lucide-react';
import { SpaceApp, SpaceTarget } from './App';
-import { SpaceView, sameView } from './nav';
+import { SpaceView, sameView, viewAfterSpaceSwitch } from './nav';
import { ArchivedSpacesModal, NewSpaceModal, SpaceRail } from './components/Spaces';
import { Toasts, Toast } from './components/Toasts';
import { InstallHint } from './components/InstallHint';
@@ -138,7 +138,8 @@ export const App: React.FC = () => {
(id: string, to?: SpaceTarget | null) => {
if (id === currentRef.current && !to) return;
playSfx('click');
- open(id, to);
+ // A plain switch (rail, Ctrl/⌘ 1–9) keeps Settings open; a link to a chat opens that chat.
+ open(id, to, false, to ? null : viewAfterSpaceSwitch(viewRef.current));
reload();
},
[open, reload],
diff --git a/frontend/src/components/ManageTeamModal.tsx b/frontend/src/components/ManageTeamModal.tsx
index ab5dbc6c..2cefb54b 100644
--- a/frontend/src/components/ManageTeamModal.tsx
+++ b/frontend/src/components/ManageTeamModal.tsx
@@ -1,7 +1,7 @@
import React, { useState, useEffect, useRef } from 'react';
import { X, Users, Trash2, Check, AlertTriangle, ShieldCheck, Folder, GitBranch, FolderSearch } from 'lucide-react';
import { ModernAvatar } from './ModernAvatar';
-import { Team, Kwant } from './Sidebar';
+import { Team, Kwant, memberIdsOf } from './Sidebar';
import { FolderBrowserModal } from './FolderBrowserModal';
import { playSfx } from '../audio/chiptune';
import { InstructionsField } from './Instructions';
@@ -128,6 +128,12 @@ export const ManageTeamModal: React.FC<ManageTeamModalProps> = ({
if (!isOpen || !team) return null;
+ const savedMembers = memberIdsOf(team);
+ const removedNames = savedMembers
+ .filter((id) => !memberIds.includes(id))
+ .map((id) => kwants.find((k) => k.id === id)?.name)
+ .filter((n): n is string => !!n);
+
const handleToggleMember = (kwantId: string) => {
playSfx('click');
if (memberIds.includes(kwantId)) {
@@ -491,6 +497,13 @@ export const ManageTeamModal: React.FC<ManageTeamModalProps> = ({
</div>
</div>
+ {/* Unticked members only leave on Save; say who, so Save is the confirm */}
+ {removedNames.length > 0 && (
+ <p data-team-removals className="text-[11px] text-amber-200/90">
+ Saving removes {removedNames.join(', ')} from @{team.name}. {removedNames.length === 1 ? 'The bot stays' : 'They stay'} in this space and {removedNames.length === 1 ? 'keeps its' : 'keep their'} chats.
+ </p>
+ )}
+
{/* Action Buttons & Danger Zone */}
<div className="pt-2 border-t border-zinc-800 flex items-center justify-between gap-3">
<button
diff --git a/frontend/src/components/Sidebar.tsx b/frontend/src/components/Sidebar.tsx
index c6c21db1..26223cd1 100644
--- a/frontend/src/components/Sidebar.tsx
+++ b/frontend/src/components/Sidebar.tsx
@@ -332,7 +332,8 @@ export const Sidebar: React.FC<SidebarProps> = ({
const active = !isChannel && selectedId === k.id;
const status = statusOf(k.id, botStatus, canRun);
const isLead = !!team && k.id === team.lead_kwant_id;
- const memberIds = team ? memberIdsOf(team) : [];
+ const canRemove = !!team && !isLead && !!onUpdateTeamMembers;
+ const hasRowActions = !!onEditKwant || canRemove;
return (
<div
key={`${team?.id ?? 'none'}:${k.id}`}
@@ -349,7 +350,8 @@ export const Sidebar: React.FC<SidebarProps> = ({
<ModernAvatar role={k.avatar_sprite} name={k.name} size={28} status={status} kwantId={k.id} />
</span>
<div className="flex-1 min-w-0">
- <div className="flex items-start gap-1">
+ {/* Desktop: on hover or focus the name makes room for Edit and Remove instead of sitting under them */}
+ <div data-bot-name-line className={`flex items-start gap-1 ${!phone && hasRowActions ? 'group-hover/fleet:pr-9 group-focus-within/fleet:pr-9' : ''}`}>
{/* The full name, on up to two lines (QA a); what it runs on is in the tooltip */}
<span data-bot-name className="min-w-0 text-xs font-semibold leading-4 text-zinc-200 line-clamp-2 [overflow-wrap:anywhere]" title={`${k.name} · ${engineTip(k.preferred_model)}`}>
{k.name}
@@ -372,7 +374,7 @@ export const Sidebar: React.FC<SidebarProps> = ({
{approvalsOff(k) && <ApprovalsOffBadge compact title={`${k.name} acts without asking. Payments still ask you.`} />}
{/* Over the row's right edge, so a long name gets the full width until you hover */}
{!phone && (
- <span className="absolute right-1.5 top-1.5 flex items-center gap-0.5 rounded-md bg-zinc-800/95 opacity-0 group-hover/fleet:opacity-100 focus-within:opacity-100 empty:hidden">
+ <span className="absolute right-1.5 top-1.5 flex items-center gap-0.5 rounded-md bg-zinc-800/95 opacity-0 group-hover/fleet:opacity-100 group-focus-within/fleet:opacity-100 empty:hidden">
{onEditKwant && (
<button
type="button"
@@ -380,23 +382,25 @@ export const Sidebar: React.FC<SidebarProps> = ({
e.stopPropagation();
onEditKwant(k);
}}
- className="opacity-0 group-hover/fleet:opacity-100 focus-visible:opacity-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400 p-0.5 rounded text-zinc-500 hover:text-sky-300 hover:bg-sky-500/10 transition-all"
+ className="opacity-0 group-hover/fleet:opacity-100 group-focus-within/fleet:opacity-100 focus-visible:opacity-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400 p-0.5 rounded text-zinc-500 hover:text-sky-300 hover:bg-sky-500/10 transition-all"
title={`Edit or delete ${k.name}`}
aria-label={`Edit or delete ${k.name}`}
>
<Pencil size={11} />
</button>
)}
- {team && !isLead && onUpdateTeamMembers && (
+ {canRemove && (
<button
type="button"
+ data-remove-member={k.id}
onClick={(e) => {
e.stopPropagation();
- onUpdateTeamMembers(team, memberIds.filter((id) => id !== k.id));
+ // Asks first, like the phone sheet: a stray click can't take a bot out of its team.
+ setMemberMenu({ team: team!, kwant: k, confirmRemove: true });
}}
- className="opacity-0 group-hover/fleet:opacity-100 focus-visible:opacity-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400 p-0.5 rounded text-zinc-500 hover:text-rose-300 hover:bg-rose-500/10 transition-all"
- title={`Remove ${k.name} from @${team.name}`}
- aria-label={`Remove ${k.name} from @${team.name}`}
+ className="opacity-0 group-hover/fleet:opacity-100 group-focus-within/fleet:opacity-100 focus-visible:opacity-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400 p-0.5 rounded text-zinc-500 hover:text-rose-300 hover:bg-rose-500/10 transition-all"
+ title={`Remove ${k.name} from @${team!.name}`}
+ aria-label={`Remove ${k.name} from @${team!.name}`}
>
<X size={11} />
</button>
@@ -855,8 +859,9 @@ export const Sidebar: React.FC<SidebarProps> = ({
);
};
-/** Phones: a team member's actions as a bottom sheet. Removing asks once more, away from the
- * other buttons, so a stray tap can't take a bot out of its team. */
+/** A team member's actions as a bottom sheet on phones. Removing asks once more, away from the
+ * other buttons, so a stray tap can't take a bot out of its team; desktop's Remove opens straight
+ * on that question, as a small centred dialog. */
const MemberSheet: React.FC<{
team: Team;
kwant: Kwant;
@@ -880,13 +885,13 @@ const MemberSheet: React.FC<{
const item = 'w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-left text-sm transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400';
const titleId = `member-sheet-${kwant.id}`;
return (
- <div className="fixed inset-0 z-50 bg-black/60 flex items-end" onMouseDown={(e) => e.target === e.currentTarget && onClose()}>
+ <div className="fixed inset-0 z-50 bg-black/60 flex items-end md:items-center md:justify-center md:p-4" onMouseDown={(e) => e.target === e.currentTarget && onClose()}>
<div
ref={ref}
role="dialog"
aria-modal="true"
aria-labelledby={titleId}
- className="kw-sheet w-full max-h-[80vh] overflow-y-auto rounded-t-2xl bg-zinc-900 border-t border-zinc-800 p-3 shadow-2xl"
+ className="kw-sheet w-full max-h-[80vh] overflow-y-auto rounded-t-2xl bg-zinc-900 border-t border-zinc-800 p-3 shadow-2xl md:max-w-sm md:rounded-2xl md:border"
>
<div className="mx-auto mb-2 h-1 w-10 rounded-full bg-zinc-700" aria-hidden="true" />
<div className="flex items-center gap-3 px-3 pb-3">
diff --git a/frontend/src/components/SpaceSettings.tsx b/frontend/src/components/SpaceSettings.tsx
index 43505239..b32afef0 100644
--- a/frontend/src/components/SpaceSettings.tsx
+++ b/frontend/src/components/SpaceSettings.tsx
@@ -85,6 +85,8 @@ interface Props {
onOpenTools: () => void;
/** Set by a routine card's Edit or Pause: opens that routine in Routines. */
routineFocus?: RoutineFocus | null;
+ /** Phones get a full-screen dialog; desktop keeps the space rail beside Settings. */
+ isPhone?: boolean;
/** After an import or its undo: load bots, teams and chats again. */
onImported?: () => void;
/** After the approvals switch changes: load bots and spaces again (no event fires). */
@@ -123,12 +125,14 @@ export const SpaceSettings: React.FC<Props> = (p) => {
}, []);
return (
+ // A full-screen dialog on phones. On desktop it fills the space's area beside the space rail,
+ // which stays clickable: picking another space keeps Settings open there.
<div
- role="dialog"
- aria-modal="true"
+ role={p.isPhone ? 'dialog' : 'region'}
+ aria-modal={p.isPhone ? true : undefined}
aria-labelledby="space-settings-title"
data-space-settings
- className="fixed inset-0 z-40 bg-zinc-950 text-zinc-100 flex flex-col md:flex-row overflow-hidden"
+ className={`${p.isPhone ? 'fixed' : 'absolute'} inset-0 z-40 bg-zinc-950 text-zinc-100 flex flex-col md:flex-row overflow-hidden`}
>
{/* Tab list: a column on desktop, scrolling chips on phones */}
<div className="md:w-60 shrink-0 border-b md:border-b-0 md:border-r border-zinc-800/80 bg-zinc-900/40 flex flex-col">
diff --git a/frontend/src/nav.ts b/frontend/src/nav.ts
index 6f0cf0da..adea402c 100644
--- a/frontend/src/nav.ts
+++ b/frontend/src/nav.ts
@@ -79,6 +79,14 @@ export function sameView(a: SpaceView | null | undefined, b: SpaceView | null |
return viewSegment(a) === viewSegment(b);
}
+/**
+ * The view to open in a space picked from the rail or with Ctrl/⌘ 1–9. Settings stays open
+ * (This space then shows the new space, All spaces stays as is); anything else opens a chat.
+ */
+export function viewAfterSpaceSwitch(view: SpaceView | null | undefined): SpaceView | null {
+ return view?.kind === 'settings' ? view : null;
+}
+
const INSTALL_TIP_KEY = 'kwnt.installTip.dismissed';
/** The desktop "Install app" tip shows until it is dismissed or the app is installed. */
diff --git a/frontend/tests/polish063.test.mjs b/frontend/tests/polish063.test.mjs
new file mode 100644
index 00000000..f1d2122f
--- /dev/null
+++ b/frontend/tests/polish063.test.mjs
@@ -0,0 +1,208 @@
+// 0.6.3 polish (Rigel's #206 observations): Settings beside the space rail, Ctrl/⌘ 1–9 inside
+// Settings, room for Edit and Remove beside a bot's name, and Remove from team always asks first.
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { readFileSync } from 'node:fs';
+import { JSDOM } from 'jsdom';
+import { loadBundled } from './bundle.mjs';
+
+const dom = new JSDOM('<!doctype html><html><body></body></html>', { url: 'http://localhost/', pretendToBeVisual: true });
+const g = globalThis;
+for (const k of ['window', 'document', 'navigator', 'HTMLElement', 'Node', 'Event', 'MouseEvent', 'KeyboardEvent', 'requestAnimationFrame', 'cancelAnimationFrame', 'getComputedStyle', 'localStorage', 'sessionStorage']) {
+ if (!(k in dom.window)) continue;
+ Object.defineProperty(g, k, { value: dom.window[k], configurable: true, writable: true });
+}
+g.fetch = async () => new Response('[]', { status: 200, headers: { 'Content-Type': 'application/json' } });
+g.window.fetch = g.fetch;
+
+const m = await loadBundled(`
+ export { default as React } from 'react';
+ export { createRoot } from 'react-dom/client';
+ export { act } from 'react';
+ export { renderToStaticMarkup } from 'react-dom/server.browser';
+ export { Sidebar } from './src/components/Sidebar';
+ export { SpaceSettings } from './src/components/SpaceSettings';
+ export { ManageTeamModal } from './src/components/ManageTeamModal';
+ export { viewAfterSpaceSwitch, sameView } from './src/nav';
+ export { spacePath, parseSpacePath } from './src/spaces';
+`);
+const { React } = m;
+const src = (f) => readFileSync(new URL(`../src/${f}`, import.meta.url), 'utf8');
+const noop = () => {};
+const settle = async () => {
+ for (let i = 0; i < 10; i++) await new Promise((r) => setTimeout(r, 0));
+};
+const click = async (el) => {
+ el.dispatchEvent(new MouseEvent('click', { bubbles: true }));
+ await settle();
+};
+
+const space = { id: 'spc_default', name: 'Default', icon: '💼', color: '#f59e0b', sort: 0, is_default: true, archived_at: null,
+ created_at: '', general_channel_id: null, counts: { bots: 0, ready_accounts: 0, unread: 0 } };
+const bot = (id, name) => ({ id, name, title: 'Role', persona_prompt: '', avatar_sprite: 'mouse', driver_type: 'claude', preferred_model: '' });
+const kwants = [bot('k1', 'Ada-Lead'), bot('k2', 'Customer-Success-Manager-Extraordinaire'), bot('k3', 'Loner')];
+const team = { id: 't1', name: 'Ship', icon: '🚢', lead_kwant_id: 'k1', member_kwants: ['k1', 'k2'] };
+const sidebarProps = (over = {}) => ({
+ space, spaces: [space], onSwitchSpace: noop, onCreateSpace: noop, onOpenSpaceSettings: noop, onOpenArchived: noop, onOpenSearch: noop,
+ kwants, channels: [], teams: [team], selectedId: '', isChannel: true, onSelectKwant: noop, onSelectChannel: noop, onSelectTeam: noop,
+ onSummonKwant: noop, onCreateTeam: noop, onOpenInbox: noop, onOpenParallel: noop, onOpenMissions: noop, missionBoard: true,
+ onEditKwant: noop,
+ ...over,
+});
+
+const mount = async (C, props) => {
+ const host = document.createElement('div');
+ document.body.appendChild(host);
+ const root = m.createRoot(host);
+ root.render(React.createElement(C, props));
+ await settle();
+ return { host, unmount: () => { root.unmount(); host.remove(); } };
+};
+
+// ---------------------------------------------------------------------------
+// 1. Settings beside the rail
+
+const settingsProps = (over = {}) => ({
+ space, spaces: [space], scope: 'space', onScope: noop, tab: 'general', onTab: noop, onClose: noop,
+ connections: 'C', appSettings: 'A', onOpenArchived: noop, kwants, channels: [], teams: [team],
+ onSpaceSaved: noop, onArchived: noop, onNewBot: noop, onEditBot: noop, onOpenSkills: noop, onNewTeam: noop, onManageTeam: noop, onOpenTools: noop,
+ ...over,
+});
+
+test('1: on desktop Settings fills the space area and leaves the space rail uncovered', () => {
+ const html = m.renderToStaticMarkup(React.createElement(m.SpaceSettings, settingsProps()));
+ const root = html.match(/<div[^>]*data-space-settings[^>]*>/)[0];
+ assert.match(root, /class="absolute inset-0 /, 'positioned inside the space, not over the whole window');
+ assert.doesNotMatch(root, /\bfixed\b/);
+ assert.doesNotMatch(root, /aria-modal/, 'the rail beside it stays usable, so it is not a modal');
+ assert.match(root, /role="region"/);
+ // The space app it sits in is the positioning box; the rail is its sibling in the shell.
+ assert.match(src('App.tsx'), /<div className="relative flex-1 min-w-0 h-full flex flex-col[^"]*" data-space=\{space\.id\}>/);
+ assert.match(src('Shell.tsx'), /<SpaceRail [\s\S]*?\/>\s*<SpaceApp/);
+});
+
+test('1: on phones Settings is still a full-screen dialog', () => {
+ const html = m.renderToStaticMarkup(React.createElement(m.SpaceSettings, settingsProps({ isPhone: true })));
+ const root = html.match(/<div[^>]*data-space-settings[^>]*>/)[0];
+ assert.match(root, /class="fixed inset-0 /);
+ assert.match(root, /role="dialog"/);
+ assert.match(root, /aria-modal="true"/);
+});
+
+test('1: picking another space keeps Settings open: This space follows the new space, All spaces stays', () => {
+ const accounts = { kind: 'settings', scope: 'space', tab: 'accounts' };
+ const app = { kind: 'settings', scope: 'app' };
+ assert.deepEqual(m.viewAfterSpaceSwitch(accounts), accounts);
+ assert.deepEqual(m.viewAfterSpaceSwitch(app), app);
+ // Anything else lands in a chat, as before.
+ for (const v of [null, undefined, { kind: 'inbox', tab: 'new' }, { kind: 'board' }, { kind: 'parallel' }]) assert.equal(m.viewAfterSpaceSwitch(v), null);
+ // The new space opens on that view: its address names the new space and the same Settings tab.
+ assert.equal(m.spacePath('spc_b', null, accounts), '/s/spc_b/settings/accounts');
+ const r = m.parseSpacePath('/s/spc_b/settings/accounts');
+ assert.equal(r.spaceId, 'spc_b');
+ assert.ok(m.sameView(r.view, accounts));
+});
+
+// ---------------------------------------------------------------------------
+// 2. Ctrl/⌘ 1–9 inside Settings behaves like the rail
+
+test('2: the rail and Ctrl/⌘ 1–9 both go through the one switch, which carries Settings over', () => {
+ const shell = src('Shell.tsx');
+ assert.match(shell, /<SpaceRail [^>]*onSwitch=\{switchTo\}/, 'the rail switches with switchTo');
+ const keys = shell.match(/\/\/ Ctrl\/⌘ 1–9 switches spaces\.[\s\S]*?\}, \[spaces, switchTo\]\);/)[0];
+ assert.match(keys, /switchTo\(s\.id\)/, 'so does the shortcut');
+ const sw = shell.match(/const switchTo = useCallback\([\s\S]*?\[open, reload\],/)[0];
+ assert.match(sw, /open\(id, to, false, to \? null : viewAfterSpaceSwitch\(viewRef\.current\)\)/);
+});
+
+test('2: Back after a switch inside Settings steps back to the old space, then out of Settings, without looping', () => {
+ const view = { kind: 'settings', scope: 'space', tab: 'accounts' };
+ // History: chat in A → Settings in A → (Ctrl+2) Settings in B.
+ const stack = ['/s/spc_a/c/ch1', m.spacePath('spc_a', null, view), m.spacePath('spc_b', null, m.viewAfterSpaceSwitch(view))];
+ assert.equal(new Set(stack).size, 3, 'three distinct entries: Back always moves');
+ const back1 = m.parseSpacePath(stack[1]);
+ assert.equal(back1.spaceId, 'spc_a');
+ assert.ok(m.sameView(back1.view, view), 'Back once: Settings in the old space');
+ const back2 = m.parseSpacePath(stack[0]);
+ assert.equal(back2.spaceId, 'spc_a');
+ assert.equal(back2.view ?? null, null, 'Back twice: the chat');
+ // The space opened from Back is not pushed again (no new entry, so Forward still works).
+ const pop = src('Shell.tsx').match(/const onPop = \(\) => \{[\s\S]*?\n \};/)[0];
+ assert.doesNotMatch(pop, /pushState/);
+});
+
+// ---------------------------------------------------------------------------
+// 3. Room for Edit and Remove
+
+test('3: on desktop the name line makes room for the hover buttons; phone rows are unchanged', () => {
+ const desk = m.renderToStaticMarkup(React.createElement(m.Sidebar, sidebarProps({ onUpdateTeamMembers: noop })));
+ const lines = [...desk.matchAll(/<div data-bot-name-line="[^"]*" class="([^"]*)"/g)].map((x) => x[1]);
+ assert.ok(lines.length >= 3);
+ for (const cls of lines) {
+ assert.match(cls, /group-hover\/fleet:pr-9/);
+ assert.match(cls, /group-focus-within\/fleet:pr-9/);
+ }
+ const phone = m.renderToStaticMarkup(React.createElement(m.Sidebar, sidebarProps({ onUpdateTeamMembers: noop, phone: true })));
+ for (const [, cls] of phone.matchAll(/<div data-bot-name-line="[^"]*" class="([^"]*)"/g)) assert.doesNotMatch(cls, /pr-9/);
+});
+
+// ---------------------------------------------------------------------------
+// 4. Remove from team asks first, on every path
+
+test('4: desktop ✕ on a team member asks first; Cancel keeps the bot, Remove takes it out', async () => {
+ const calls = [];
+ const v = await mount(m.Sidebar, sidebarProps({ onUpdateTeamMembers: (t, ids) => calls.push([t.id, ids]) }));
+ const x = () => v.host.querySelector('[data-remove-member="k2"]');
+ assert.ok(x(), 'a non-lead member has the ✕');
+ assert.equal(v.host.querySelector('[data-remove-member="k1"]'), null, 'the lead has none');
+
+ await click(x());
+ assert.deepEqual(calls, [], 'the click alone removes nothing');
+ let dlg = document.querySelector('[role="dialog"]');
+ assert.ok(dlg, 'a confirm opens');
+ assert.match(dlg.textContent, /Remove Customer-Success-Manager-Extraordinaire from @Ship\? The bot stays in this space and keeps its chats\./);
+ const btn = (label) => [...document.querySelectorAll('[role="dialog"] button')].find((b) => b.textContent.trim() === label);
+ assert.equal(document.activeElement, btn('Cancel'), 'focus starts on Cancel, so Enter does not remove');
+ await click(btn('Cancel'));
+ assert.deepEqual(calls, []);
+ assert.equal(document.querySelector('[role="dialog"]'), null);
+
+ await click(x());
+ await click(btn('Remove'));
+ assert.deepEqual(calls, [['t1', ['k1']]]);
+ v.unmount();
+});
+
+test('4: phone member sheet still asks before removing', async () => {
+ const calls = [];
+ const v = await mount(m.Sidebar, sidebarProps({ phone: true, onUpdateTeamMembers: (t, ids) => calls.push([t.id, ids]) }));
+ const more = [...v.host.querySelectorAll('button')].find((b) => /Customer-Success-Manager-Extraordinaire/.test(b.getAttribute('aria-label') ?? '') && /action|more|options/i.test(b.getAttribute('aria-label') ?? ''));
+ assert.ok(more, 'the member row has its actions button');
+ await click(more);
+ const btn = (re) => [...document.querySelectorAll('[role="dialog"] button')].find((b) => re.test(b.textContent));
+ await click(btn(/Remove from @Ship/));
+ assert.deepEqual(calls, [], 'the menu item only asks');
+ await click(btn(/^Remove$/));
+ assert.deepEqual(calls, [['t1', ['k1']]]);
+ v.unmount();
+});
+
+test('4: Manage team names who Save will remove before it happens', async () => {
+ const saved = [];
+ const v = await mount(m.ManageTeamModal, { isOpen: true, team, kwants, onClose: noop, onUpdateTeam: async (id, d) => saved.push(d.member_kwants), onDeleteTeam: async () => {} });
+ assert.equal(document.querySelector('[data-team-removals]'), null);
+ const row = [...document.querySelectorAll('div')].find((d) => d.className.includes('cursor-pointer') && d.textContent.includes('Customer-Success-Manager-Extraordinaire'));
+ await click(row);
+ assert.deepEqual(saved, [], 'unticking saves nothing');
+ assert.match(document.querySelector('[data-team-removals]').textContent, /Saving removes Customer-Success-Manager-Extraordinaire from @Ship\./);
+ v.unmount();
+});
+
+test('4: no other code path takes a bot out of a team without a confirm', () => {
+ const sidebar = src('components/Sidebar.tsx');
+ // Every call that hands onUpdateTeamMembers a shorter list sits in the confirm's Remove handler.
+ const removals = [...sidebar.matchAll(/onUpdateTeamMembers\([^;]*?\.filter\(\(id\) => id !== [^;]*;/g)];
+ assert.equal(removals.length, 1, 'one removal call');
+ const at = removals[0].index;
+ assert.ok(sidebar.lastIndexOf('onRemove={', at) > sidebar.lastIndexOf('onClick={', at), 'and it is the confirm sheet\'s Remove');
+});