From e55162c03b24138dea1aad5b2042322cfd7b73fb Mon Sep 17 00:00:00 2001 From: Kris <2040188027@qq.com> Date: Fri, 20 Nov 2026 11:23:46 +0800 Subject: [PATCH 1/2] fix(chatbot): keep the CLI selector visible but disabled once a chat locks its runtime After the first reply, the composer's CLI picker was removed entirely, so a running conversation gave no visible indication of which runtime it was bound to. Keep the picker rendered, disable it, and show the bound runtime with a tooltip explaining that switching requires a new conversation. - App.jsx: render the CLI picker whenever more than one executor exists; when the conversation is pinned to an executor, disable it and set the tooltip, leaving the model, effort and approval pickers untouched. - PermissionPicker: add disabled/title support so a locked picker keeps its current value but never opens its menu. - styles.css: style the disabled selector as non-interactive. - app-render.test.jsx: assert the locked picker is present and disabled, and add a regression test that a locked picker cannot open its menu. --- chatbot/src/App.jsx | 8 +++++-- chatbot/src/PermissionPicker.jsx | 17 +++++++++------ chatbot/src/styles.css | 10 +++++++++ chatbot/tests/app-render.test.jsx | 36 +++++++++++++++++++++++++++++-- 4 files changed, 61 insertions(+), 10 deletions(-) diff --git a/chatbot/src/App.jsx b/chatbot/src/App.jsx index 0c1daf0fe..103ac7703 100644 --- a/chatbot/src/App.jsx +++ b/chatbot/src/App.jsx @@ -2130,7 +2130,7 @@ export default function App() { e.target.value = ""; }} /> - {chat.executors.length > 1 && !pinnedExecutor ? ( + {chat.executors.length > 1 ? ( { @@ -2142,7 +2142,11 @@ export default function App() { : null, }; })} - value={chat.executor} + value={pinnedExecutor ? pinnedExecutor.id : chat.executor} + disabled={Boolean(pinnedExecutor)} + title={pinnedExecutor + ? `当前对话已绑定 ${pinnedExecutor.label},对话开始后不能切换 CLI;换 CLI 请新建对话` + : undefined} onSelect={(id) => { chat.setExecutor(id); input.current?.focus(); diff --git a/chatbot/src/PermissionPicker.jsx b/chatbot/src/PermissionPicker.jsx index 0a37c8305..7e064dbba 100644 --- a/chatbot/src/PermissionPicker.jsx +++ b/chatbot/src/PermissionPicker.jsx @@ -24,14 +24,16 @@ export function rememberApprovalMode(userId, value) { } // `glyph` is a rendered brand mark. Options that only set `icon` keep the Harness icon. -export default function PermissionPicker({ value, onSelect, open, onOpenChange, label = "操作确认方式", icon, options = modes }) { +export default function PermissionPicker({ value, onSelect, open, onOpenChange, label = "操作确认方式", icon, options = modes, disabled = false, title }) { const trigger = useRef(null); const panel = useRef(null); const initialFocus = useRef(null); const callbacks = useRef(null); callbacks.current = { onSelect, onOpenChange }; const identity = `permission-picker-${useId().replaceAll(":", "")}`; - const presence = usePanelPresence(open, 160); + // A disabled picker keeps its current value visible but must never open its menu. + const effectiveOpen = disabled ? false : open; + const presence = usePanelPresence(effectiveOpen, 160); const [position, setPosition] = useState({ top: 0, left: 0, width: 260, maxHeight: 360, placement: "top" }); const current = options.find((mode) => mode.id === value) || options[0]; @@ -65,7 +67,7 @@ export default function PermissionPicker({ value, onSelect, open, onOpenChange, }, [presence.mounted, options.length, place]); useEffect(() => { - if (!open || !presence.mounted) return; + if (!effectiveOpen || !presence.mounted) return; const frame = requestAnimationFrame(() => { const items = [...(panel.current?.querySelectorAll('[role="menuitemradio"]') || [])]; const selected = initialFocus.current === "first" ? items[0] : @@ -99,7 +101,7 @@ export default function PermissionPicker({ value, onSelect, open, onOpenChange, }, [presence.mounted, place]); useEffect(() => { - if (!open) return; + if (!effectiveOpen) return; const inside = (target) => trigger.current?.contains(target) || panel.current?.contains(target); const outside = (event) => { if (!inside(event.target)) callbacks.current.onOpenChange(false); @@ -169,10 +171,13 @@ export default function PermissionPicker({ value, onSelect, open, onOpenChange, className="permission-selector" data-tone={current.tone} aria-label={label} + aria-disabled={disabled || undefined} aria-haspopup="menu" - aria-expanded={open} + aria-expanded={effectiveOpen} aria-controls={identity} - onClick={() => onOpenChange(!open)} + title={title} + disabled={disabled} + onClick={() => onOpenChange(!effectiveOpen)} onKeyDown={(event) => { if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) { if (open && presence.mounted) keyDown(event); diff --git a/chatbot/src/styles.css b/chatbot/src/styles.css index 9125c9f0d..f10231146 100644 --- a/chatbot/src/styles.css +++ b/chatbot/src/styles.css @@ -1306,6 +1306,16 @@ small { [data-theme="dark"] .chat-shell button.permission-selector { --permission-trigger-hover: rgb(237 237 240 / 0.055); } +/* A locked selector stays visible but reads as non-interactive. */ +.chat-shell button.permission-selector:disabled { + cursor: not-allowed; + opacity: .55; + color: var(--muted); +} +.chat-shell button.permission-selector:disabled:is(:hover, [aria-expanded="true"]) { + background: transparent; + color: var(--muted); +} .permission-selector > .harness-icon[data-icon="chevron-down"] { transition: rotate 160ms ease; } diff --git a/chatbot/tests/app-render.test.jsx b/chatbot/tests/app-render.test.jsx index 6861c8e42..db1916cc6 100644 --- a/chatbot/tests/app-render.test.jsx +++ b/chatbot/tests/app-render.test.jsx @@ -577,7 +577,8 @@ describe("App", () => { }, }); view.rerender(); - expect(screen.queryByRole("button", { name: "CLI" })).not.toBeInTheDocument(); + const lockedCli = screen.getByRole("button", { name: "CLI" }); + expect(lockedCli).toBeDisabled(); expect(document.querySelector(".conversation-engine")).toHaveTextContent("Codex"); // The first reply, still running, locks it the same way. Object.assign(chat, { @@ -586,11 +587,42 @@ describe("App", () => { session: { id: "s2", title: "生成中", executor: "codebuddy", messages: [] }, }); view.rerender(); - expect(screen.queryByRole("button", { name: "CLI" })).not.toBeInTheDocument(); + expect(screen.getByRole("button", { name: "CLI" })).toBeDisabled(); expect(document.querySelector(".conversation-engine")).toHaveTextContent("CodeBuddy"); Object.assign(chat, previous); }); + test("a locked CLI selector stays visible, disabled, and cannot open", async () => { + const user = userEvent.setup(); + const previous = { ...chat }; + chat.executors = [ + ...previous.executors, + { id: "pi", icon: "terminal", label: "Pi", detail: "Pi" }, + ]; + Object.assign(chat, { + executor: "pi", + session: { + id: "s1", + title: "已开始", + executor: "pi", + messages: [{ id: "a1", role: "assistant", model: "m1", content: "hi" }], + }, + }); + const view = render(); + const cli = screen.getByRole("button", { name: "CLI" }); + expect(cli).toBeDisabled(); + expect(cli).toHaveAttribute( + "title", + "当前对话已绑定 Pi,对话开始后不能切换 CLI;换 CLI 请新建对话", + ); + // The disabled selector never opens its menu. + await user.click(cli); + expect(screen.queryByRole("menu")).not.toBeInTheDocument(); + expect(screen.queryByRole("menuitemradio", { name: "Pi" })).not.toBeInTheDocument(); + view.unmount(); + Object.assign(chat, previous); + }); + test("covers credential, local upload, read-only, and interrupted states", async () => { const previous = { ...chat }; Object.assign(chat, { From f56d1270eba8d9a5f2b6f526c3c1b42580a5570c Mon Sep 17 00:00:00 2001 From: Kris <2040188027@qq.com> Date: Fri, 20 Nov 2026 11:39:39 +0800 Subject: [PATCH 2/2] fix(chatbot): harden disabled PermissionPicker against a closing menu Review of #1126 found two P2 gaps in the disabled-state handling: - The menu's aria-hidden/inert still read the raw `open` prop, so a picker disabled while open left its closing menu (mounted during the close animation) accessible, and `choose` had no disabled guard, so a focused option could still fire onSelect via Enter. - The focus and outside-click effects keyed on `open` in their dependency arrays, so a disabled toggle did not clean up a queued focus RAF or the outside listeners. Unify on `effectiveOpen`: menu aria-hidden/inert, effect dependencies, and keyboard handling all check it; `choose` refuses while disabled; and a disabled picker that is still open notifies the parent to close it so re-enabling cannot reopen a menu the user did not ask for. Add a regression suite covering the open -> disabled transition. Also add the `internal` sparse-checkout directory so the chatbot suite's devserver-cookie/composer-operations/element-picker tests (which read internal/** sources) run; the full suite now passes 57 files / 409 tests. --- chatbot/src/PermissionPicker.jsx | 19 +++++--- chatbot/tests/permission-disabled.test.jsx | 56 ++++++++++++++++++++++ 2 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 chatbot/tests/permission-disabled.test.jsx diff --git a/chatbot/src/PermissionPicker.jsx b/chatbot/src/PermissionPicker.jsx index 7e064dbba..b247b5156 100644 --- a/chatbot/src/PermissionPicker.jsx +++ b/chatbot/src/PermissionPicker.jsx @@ -77,7 +77,7 @@ export default function PermissionPicker({ value, onSelect, open, onOpenChange, selected?.focus({ preventScroll: true }); }); return () => cancelAnimationFrame(frame); - }, [open, presence.mounted]); + }, [effectiveOpen, presence.mounted]); useEffect(() => { if (!presence.mounted) return; @@ -127,13 +127,20 @@ export default function PermissionPicker({ value, onSelect, open, onOpenChange, parentDocument?.removeEventListener("pointerdown", parentOutside, true); parentDocument?.removeEventListener("focusin", parentOutside, true); }; - }, [open]); + }, [effectiveOpen]); + + // A picker that becomes disabled while its menu is open must close it, so + // re-enabling later cannot reopen a menu the user did not ask for. + useEffect(() => { + if (disabled && open) callbacks.current.onOpenChange(false); + }, [disabled, open]); function close(returnFocus = false) { if (returnFocus) trigger.current?.focus({ preventScroll: true }); callbacks.current.onOpenChange(false); } function choose(id) { + if (disabled) return; callbacks.current.onSelect(id); close(true); } @@ -180,13 +187,13 @@ export default function PermissionPicker({ value, onSelect, open, onOpenChange, onClick={() => onOpenChange(!effectiveOpen)} onKeyDown={(event) => { if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) { - if (open && presence.mounted) keyDown(event); + if (effectiveOpen && presence.mounted) keyDown(event); else { event.preventDefault(); initialFocus.current = ["ArrowUp", "End"].includes(event.key) ? "last" : "first"; onOpenChange(true); } - } else if (open && ["Escape", "Tab"].includes(event.key)) keyDown(event); + } else if (effectiveOpen && ["Escape", "Tab"].includes(event.key)) keyDown(event); }} > {current.glyph ||