diff --git a/docs/tasks/T-1200/T-1266-screen-panel-polish/brief.md b/docs/tasks/T-1200/T-1266-screen-panel-polish/brief.md new file mode 100644 index 00000000..b9014216 --- /dev/null +++ b/docs/tasks/T-1200/T-1266-screen-panel-polish/brief.md @@ -0,0 +1,34 @@ +## 运行环境(云沙箱,必读) +- 开工先在 worktree 根目录运行 依赖准备脚本(镜像自带,把预装依赖链进 node_modules),之后 `pnpm exec tsc` 才可用。 +- 这里没有 systemd、Docker,`systemd-run --scope ... --` 前缀一律去掉直接运行;一次只跑一个测试文件。 +- 报告只写三样:改了什么(文件列表与 git status 一致)、为什么、测试命令与结果摘要。 +- 不提交 git。 +- 本仓库是公开仓库:代码、注释、报告里不得出现内部域名、IP、邮箱、人名、真实钥匙、沙箱主目录绝对路径。 + +# T-1266:Cry Bot 屏幕面板三处小问题(T-1253 上线截图发现) + +## 现象(共用电脑模式:`config.localVm.mode === "shared"` 且屏数 > 1;智能体工作位置选「vm」但还没分到屏) +1. 「这个智能体目前没有分配屏幕。」出现两次:`src/components/AssignLocalVmScreen.tsx` 在按钮上方有一行 `role="status"` 提示,同时下面的预览框(`src/components/ComputerPanel.tsx` 约 1300 行一带,`vm-waiting` 阶段的空态)里又显示同一句。 +2. 「现在分配屏幕」按钮底边紧贴下面的预览框,没有间距,手机 390 宽度更明显。 +3. 下方「工作位置」卡里,选中的「vm」选项仍叫「私有桌面」,卡片底部说明仍是 `place.view.vm.line`「本设备上的私有 Linux 桌面,与你自己的屏幕分开。」。共用模式下智能体用的是共用电脑里的一块屏,这个叫法和说明都不对。T-1248 只把网格里的小字描述换成了 `computer.dest.vmScreenDesc`(见 `src/lib/place.ts` 的 `vmDescriptionKey`),标题和底部说明漏了。 + +## 要改的 +1. 去重:未分配屏幕时这句话只出现一次。保留预览框里的空态提示或按钮上方那行二选一(建议保留按钮上方那行,因为排队位置、出错提示也在那里;预览框在这种状态下不要再重复这句话,可以只留图标或换成不重复的简短说明)。排队中(有 queue_position)的提示照常。 +2. 间距:「现在分配屏幕」按钮(含出错提示)与下面预览框之间留出和面板其他块一致的间距(例如 mb-3 / gap-3 一类),桌面和 390/360 手机都不能贴边。 +3. 共用模式叫法:与 `vmDescriptionKey` 同一判定口径(抽成一个共用的判定函数,不要再写一份字符串比较),共用模式下: + - 工作位置网格里 vm 选项的标题改用新文案键(中文「共用电脑」,英文「Shared computer」); + - 卡片底部说明(place view 的 vm 那行,`shared/place-view.ts` / `src/lib/place-view.ts`)改用新说明(中文「共用电脑里分给它的一块屏幕,与你自己的屏幕分开。」,英文对应);短说明同理如有显示。 + - 面板里其他在共用模式下仍会显示「私有桌面」的地方(例如 `remote-desktop-panel.tsx` 266 行、`ComputerPanel.tsx` 1297 行在未分到屏号时的回退文字),一并按同一判定改成共用叫法。 + - 非共用模式(按智能体私有桌面、单屏共享)保持现状不变。 + - 新文案键按仓库现有规矩补齐 zh/en、`src/locales/source-hashes.json` 及相关文案测试;iOS 端若用到同一键,按仓库已有做法同步。 +4. 不改服务端逻辑,不改分配/排队流程。 + +## 测试(沉淀进仓库) +- `AssignLocalVmScreen` / `ComputerPanel` 现有测试(如 `src/components/ComputerPanel.takeover.test.ts`、`src/components/remote-desktop-panel.screen.test.ts`)里补用例:未分配屏幕时那句话在渲染结果里只出现一次;排队提示不受影响。 +- `WorksOnGrid` / place view 相关单测补用例:共用多屏模式 vm 选项标题与底部说明为共用叫法;按智能体模式仍为「私有桌面」。 +- 跑改动相关的测试文件和 `pnpm exec tsc`,报告里写结果摘要。 + +## 验收 +- 共用多屏模式、智能体未分屏:提示只出现一次;按钮与预览框之间有明显间距(1440 桌面、390、360 手机)。 +- 共用多屏模式:工作位置卡选中项显示「共用电脑」,底部说明不再出现「私有 Linux 桌面」。 +- 按智能体模式下文案与之前一致。 diff --git a/docs/tasks/T-1200/T-1266-screen-panel-polish/r2.md b/docs/tasks/T-1200/T-1266-screen-panel-polish/r2.md new file mode 100644 index 00000000..1db9358e --- /dev/null +++ b/docs/tasks/T-1200/T-1266-screen-panel-polish/r2.md @@ -0,0 +1,18 @@ +## 运行环境(云沙箱,必读) +- 开工先在 worktree 根目录运行 依赖准备脚本(镜像自带,把预装依赖链进 node_modules),之后 `pnpm exec vitest` / `pnpm exec tsc` 才可用。 +- 这里**没有** systemd、Docker,说明里出现的 `systemd-run --scope ... --` 前缀一律去掉直接运行;机器 8G/4 核,一次只跑一个测试文件。 +- 若本轮沙箱已放开(能联网、能监听端口),交回前必须把改动相关的测试全部跑过,包括需要端口的 e2e;涉及的 e2e 连跑 3 次都要过。跑不了的写明原因。 +- 报告只写三样:改了什么(文件列表与 git status 一致)、为什么、测试命令与结果摘要。不要写长篇分析;完整输出放 verification 文本文件即可。 +- 不提交 git。 + +# T-1266 第 2 轮返工:补齐两处共用模式叫法 + +分支已有第 1 轮改动(已提交),在此基础上继续改,不要回退已有改动。原说明见 `docs/tasks/T-1200/T-1266-screen-panel-polish/brief.md` 第 3 条:面板里其他在共用模式下仍会显示「私有桌面」的地方一并按同一判定改成共用叫法。审核发现还有两处漏了: + +1. `src/components/bot-panel/ComputerTab.tsx` 约 62 行 `placeLabel`:vm 选项标题走 `worksOnSimpleLabel(place, platform)`,共用多屏模式下仍是「私有桌面」。改为与 `src/lib/place.ts` 的 `vmLabelKey(config)` 同一判定(用 `state.config`),非共用模式不变。 +2. `src/components/PlaceChip.tsx` 约 84 行:菜单项 `label: t(placeLabelKey(place))` 与 `place.followBotDetail` 里的 `placeLabelKey(botDefault)`,vm 在共用多屏模式下应使用 `vmLabelKey(state.config)`;非共用模式不变。 +3. 再全仓搜一遍前端里 vm 标题(`placeLabelKey`、`worksOnSimpleLabel` 等对 vm 的取名)在共用多屏模式下仍会显示「私有桌面」的入口,同样处理;不改服务端、不改分配/排队流程。 + +## 测试 +- 给 ComputerTab、PlaceChip 补用例:共用多屏模式 vm 显示「共用电脑」,按智能体模式仍为「私有桌面」。 +- 跑改动相关测试文件、`pnpm exec tsc`、`pnpm i18n:check`,报告写结果摘要。 diff --git a/docs/tasks/T-1200/T-1266-screen-panel-polish/r3.md b/docs/tasks/T-1200/T-1266-screen-panel-polish/r3.md new file mode 100644 index 00000000..303450a6 --- /dev/null +++ b/docs/tasks/T-1200/T-1266-screen-panel-polish/r3.md @@ -0,0 +1,17 @@ +## 运行环境(云沙箱,必读) +- 开工先在 worktree 根目录运行 依赖准备脚本(镜像自带,把预装依赖链进 node_modules),之后 `pnpm exec vitest` / `pnpm exec tsc` 才可用。 +- 这里**没有** systemd、Docker,说明里出现的 `systemd-run --scope ... --` 前缀一律去掉直接运行;机器 8G/4 核,一次只跑一个测试文件。 +- 若本轮沙箱已放开(能联网、能监听端口),交回前必须把改动相关的测试全部跑过,包括需要端口的 e2e;涉及的 e2e 连跑 3 次都要过。跑不了的写明原因。 +- 报告只写三样:改了什么(文件列表与 git status 一致)、为什么、测试命令与结果摘要。不要写长篇分析;完整输出放 verification 文本文件即可。 +- 不提交 git。 + +# T-1266 第 3 轮返工:设置页智能体桌面目的地摘要漏改 + +分支已有第 1、2 轮改动(已提交),在此基础上继续改,不要回退已有改动。原说明见 `docs/tasks/T-1200/T-1266-screen-panel-polish/brief.md` 第 3 条及 `r2.md`。第 2 轮审核发现还有一处漏改: + +1. `src/components/LocalComputerSection.tsx` 约 138–141 行 `destinationLabelKeys.vm` 固定为 `"vm.dest.vm"`,约 580 行 `vm.perBot.destination` 用它显示每个智能体的目的地摘要。共用多屏模式下应显示「共用电脑」:vm 改用 `src/lib/place.ts` 的 `vmLabelKey(config)`(取组件已有的配置,没有就从 store 的 `state.config` 取),非共用模式仍为「私有桌面」。其他目的地不变。 +2. 改完再全仓搜一遍 `"vm.dest.vm"` 的直接使用,确认除 `vmLabelKey` 本身及非共用分支的静态表外,没有共用多屏模式下仍会显示「私有桌面」的前端入口;不改服务端、不改分配/排队流程。 + +## 测试 +- 给 LocalComputerSection 补用例:共用多屏模式目的地摘要显示「共用电脑」,按智能体模式仍为「私有桌面」。 +- 跑改动相关测试文件、`pnpm exec tsc`、`pnpm i18n:check`,报告只写结果摘要(不要把完整输出写进 docs/)。 diff --git a/shared/place-view.test.ts b/shared/place-view.test.ts index 659e1346..bb2c126e 100644 --- a/shared/place-view.test.ts +++ b/shared/place-view.test.ts @@ -274,3 +274,20 @@ it("omits Boat setup and team desktop hints under provider lock while retaining expect(placeView(facts({ providerLock: true, backend: "vps" })).state).toBe("vps"); expect(placeView(facts({ providerLock: true, place: "vm" })).state).toBe("vm"); }); + + +it("describes shared VM screens without changing the private desktop view", () => { + const shared = placeView(facts({ place: "vm", sharedVmScreen: true })); + expect(shared).toMatchObject({ + state: "vm", short: "A screen in a shared computer", + line: "A screen assigned to this bot in a shared computer, separate from your own screen.", + }); + expect(shared.action).toEqual({ id: "open-vm-settings", label: "Shared computer settings" }); + for (const sharedVmScreen of [false, undefined]) { + expect(placeView(facts({ place: "vm", sharedVmScreen }))).toMatchObject({ + short: en["place.view.vm.short"], line: en["place.view.vm.line"], action: { id: "open-vm-settings", label: en["place.action.openVmSettings"] }, + }); + } + expect(placeView(facts({ place: "vm", sharedVmScreen: true, engine: { ...facts().engine, computer: false } })).line) + .toContain("can't use a shared computer"); +}); diff --git a/shared/place-view.ts b/shared/place-view.ts index 3ee5d5a6..c660c209 100644 --- a/shared/place-view.ts +++ b/shared/place-view.ts @@ -79,6 +79,8 @@ export type ServerKind = "my-cloud" | "mac" | "pc" | "linux" | "remote"; export interface PlaceFacts { /** The place to describe: Auto, Off, or one of the four places. */ place: Place | "auto" | "off"; + /** The local desktop is one of multiple screens in a shared computer. */ + sharedVmScreen?: boolean; server: ServerKind; bot: string; /** Desktop only: signed in to a paid Cry Bot Cloud plan (the desktop bridge). */ @@ -174,6 +176,10 @@ export const PLACE_EN = { "place.view.local.line": "Uses your screen, mouse, and keyboard.", "place.view.localUnavailable.short": "Can't use it yet", "place.view.localUnavailable.line": "{reason}", + "place.action.openSharedVmSettings": "Shared computer settings", + "place.view.vmScreen.short": "A screen in a shared computer", + "place.view.vmScreen.line": "A screen assigned to this bot in a shared computer, separate from your own screen.", + "place.view.vmScreenCannot.line": "{model} can't use a shared computer. Choose a model that supports computer use.", "place.view.vm.short": "Separate from your screen", "place.view.vm.line": "A private Linux desktop on this device, separate from your own screen.", "place.view.vmCannot.short": "Not with this model", @@ -396,6 +402,8 @@ function templateParams(params: PlaceParams, locale: string): Record + return

{queuePosition ? t("vm.screens.queued", { position: queuePosition }) : t(pending ? "settings.updates.opening" : "vm.screens.unassignedBot")} {queuePosition ? ` ${t("vm.screens.queueDetail")}` : null} diff --git a/src/components/BotSettingsDialog.simple.test.ts b/src/components/BotSettingsDialog.simple.test.ts index c3025e24..a4794849 100644 --- a/src/components/BotSettingsDialog.simple.test.ts +++ b/src/components/BotSettingsDialog.simple.test.ts @@ -2,6 +2,7 @@ import { Children, createElement, isValidElement, type ReactElement, type ReactN import { renderToStaticMarkup } from "react-dom/server"; import { afterAll, beforeEach, describe, expect, it, vi } from "vitest"; +import { setLocale } from "@/lib/i18n"; import type { Routine } from "@/lib/routines"; import type { MemoryDoc } from "@/lib/memory"; import type { Bot, BotSettingsSection, InstanceInfo } from "@/state/store"; @@ -1001,6 +1002,29 @@ describe("the Where it works page", () => { expect(where(makeBot()).html).toContain('role="radiogroup"'); }); + it.each([ + ["shared", 4, true], + ["shared", 1, false], + ["shared", undefined, false], + ["per-bot", 4, false], + ] as const)("names the VM in the choices, summary and live location for %s / %s", (mode, screens, shared) => { + fixture.storeState = { ...fixture.storeState, config: { localVm: { mode, screens, maxInstances: 1 } } }; + try { + for (const locale of ["en", "zh"] as const) { + setLocale(locale); + const label = locale === "zh" ? shared ? "共用电脑" : "私有桌面" : shared ? "Shared computer" : "Private desktop"; + const bot = makeBot({ computer: "vm" }); + expect(find(where(bot), "data-panel-choice", "vm").props.title).toBe(label); + expect(find(computer(bot), "data-panel-page", "where").props.value).toBe(label); + const liveBot = makeBot({ computer: "cloud", tasks: [{ threadId: "thread-scout", title: "Main", surface: "vm" }] as Bot["tasks"] }); + expect(where(liveBot).html).toContain(label); + expect(find(computer(liveBot), "data-panel-page", "where").props.hint).toContain(label); + } + } finally { + setLocale("en"); + } + }); + it("saves each place through the bot patch, and sends nothing for the place already chosen", () => { const rendered = where(makeBot()); choose(rendered, "cloud"); diff --git a/src/components/ChatView.screen.test.ts b/src/components/ChatView.screen.test.ts index 15fa2194..722712c1 100644 --- a/src/components/ChatView.screen.test.ts +++ b/src/components/ChatView.screen.test.ts @@ -1,16 +1,17 @@ import { createElement } from "react"; import { renderToStaticMarkup } from "react-dom/server"; -import { afterAll, describe, expect, it, vi } from "vitest"; +import { afterAll, afterEach, describe, expect, it, vi } from "vitest"; import type { AppState, Bot, InstanceInfo, Message } from "@/state/store"; -vi.hoisted(() => { +const fixture = vi.hoisted(() => { vi.stubGlobal("window", {}); vi.stubGlobal("localStorage", { getItem: () => null, setItem: () => {} }); + return { config: null as AppState["config"] }; }); vi.mock("@/state/store", async (importOriginal) => { const original = await importOriginal(); return { ...original, useStore: () => ({ - state: { ...original.initialState, instances: [{ instanceId: "test", driverKind: "codex", displayName: "Test" } as InstanceInfo] }, + state: { ...original.initialState, config: fixture.config, instances: [{ instanceId: "test", driverKind: "codex", displayName: "Test" } as InstanceInfo] }, dispatch: vi.fn(), }) }; }); @@ -24,6 +25,7 @@ vi.mock("./ModelPicker", () => ({ ModelPicker: () => null })); const { ChatView } = await import("./ChatView"); const { initialState, reducer } = await import("@/state/store"); afterAll(() => vi.unstubAllGlobals()); +afterEach(() => { fixture.config = null; }); const IMAGE = 'src="/api/threads/t1/messages/shot/image"'; const greeting: Message = { id: "hi", role: "bot", kind: "text", text: "Hello", at: 1 }; @@ -62,3 +64,17 @@ describe("ChatView screenshot", () => { expect(markup).not.toContain("/messages/shot/image"); }); }); + + +it.each([ + ["shared", 4, "Shared computer"], + ["shared", 1, "Private desktop"], + ["per-bot", 4, "Private desktop"], +] as const)("passes the VM name to transcript tool icons for %s / %s", (mode, screens, label) => { + fixture.config = { features: { showToolCalls: true }, localVm: { mode, screens, maxInstances: 1 } } as AppState["config"]; + const markup = render({ ...bot([greeting, { + id: "tool", parentId: "hi", role: "bot", kind: "activity", at: 2, tool: { name: "screenshot", ok: true }, + }]), computer: "vm" }); + expect(markup).toContain('data-testid="tool-place"'); + expect(markup).toContain(`aria-label="${label}"`); +}); diff --git a/src/components/ChatView.tsx b/src/components/ChatView.tsx index e2efe8d3..04de7ae3 100644 --- a/src/components/ChatView.tsx +++ b/src/components/ChatView.tsx @@ -140,7 +140,7 @@ import { isBotTextRow, joinedCorners, needsStamp, quietRow, simpleRowLayout, SIM interface ChatRows { botId: string; threadId: string; botName: string; botColor: Bot["color"]; voiceId?: string; - tts: ConfigStatus["tts"]; localVoice: boolean; + tts: ConfigStatus["tts"]; localVoice: boolean; localVm?: ConfigStatus["localVm"]; hasMore: boolean; bots: readonly Bot[]; mentionPeers: readonly MentionPeer[]; mentionPerson: { profileName?: string }; /** A shared workspace's viewer key: another person's line carries their name. */ @@ -246,7 +246,7 @@ function PlaceFailedRow({ place, botId, threadId, onRetry }: { const { capabilities } = useDesktopCapabilities(); const seat = usePlaceSeat(config, capabilities); const computer = useStoreSelector((state) => state.bots.find((candidate) => candidate.id === botId)?.computer); - const view = placeRowViewFor(place, seat, worksOnSimpleLabel(computer, capabilities.host.platform)); + const view = placeRowViewFor(place, seat, worksOnSimpleLabel(computer, capabilities.host.platform, config)); const id = view.action?.id; const onClick = !id ? undefined : id === "try-again" ? onRetry @@ -615,13 +615,13 @@ function PeerLabel({ peer }: { peer: PeerLine }) { } const ActivityChip = memo(function ActivityChip({ message, place = "auto" }: { message: Message; place?: EffectivePlace }) { - const { bots, dispatch, threadId } = useChatRows(), liveTools = use(LiveToolsContext); + const { bots, dispatch, threadId, localVm } = useChatRows(), liveTools = use(LiveToolsContext); const tool = message.tool; if (!tool) return null; if (message.threadRef) return ; if (message.relay) return ; const comm = message.comm; if (comm) return ; - return ; + return ; }); const RoomHandoffChip = ({ message, comm, bots, dispatch }: { message: Message; comm: NonNullable; bots: readonly Bot[]; dispatch: Dispatch }) => { const store = useStoreRef(); return openRoomThread(dispatch, comm, store.state().groups)} />; }; @@ -898,8 +898,8 @@ export const ChatView = memo(function ChatView({ bot: profile }: { bot: Bot }) { const profileName = useSessionDisplayName() ?? state.config?.profile?.name; const speakerViewer = reactor !== "user" ? reactor : null; const rows = useMemo( - () => ({ botId: bot.id, threadId: bot.threadId, botName: bot.name, botColor: bot.color, voiceId: bot.voice, tts, localVoice, hasMore, bots, mentionPeers, mentionPerson: { profileName }, focus, showToolCalls, locale, dispatch, onBranch, bubbleStyle, conversational: isConversational(bot.replyStyle), simple: !advanced, canReact: canWrite !== false, openedAt, speakerViewer }), - [bot.id, bot.threadId, bot.name, bot.color, bot.voice, tts, localVoice, hasMore, bots, mentionPeers, profileName, focus, showToolCalls, locale, dispatch, onBranch, bubbleStyle, bot.replyStyle, advanced, canWrite, openedAt, speakerViewer], + () => ({ botId: bot.id, threadId: bot.threadId, botName: bot.name, botColor: bot.color, voiceId: bot.voice, tts, localVoice, localVm: state.config?.localVm, hasMore, bots, mentionPeers, mentionPerson: { profileName }, focus, showToolCalls, locale, dispatch, onBranch, bubbleStyle, conversational: isConversational(bot.replyStyle), simple: !advanced, canReact: canWrite !== false, openedAt, speakerViewer }), + [bot.id, bot.threadId, bot.name, bot.color, bot.voice, tts, localVoice, state.config?.localVm, hasMore, bots, mentionPeers, profileName, focus, showToolCalls, locale, dispatch, onBranch, bubbleStyle, bot.replyStyle, advanced, canWrite, openedAt, speakerViewer], ); const currentTask = bot.tasks?.find((task) => task.threadId === bot.threadId), place = effectivePlace(bot, currentTask), team = state.config?.team, privateChat = Boolean(team) && (currentTask?.private === true || (ownChatStarted(bot.threadId) && !currentTask?.shared)), ownHelper = Boolean(team) && !privateChat && Boolean(bot.defaultBot?.person), sharedChat = Boolean(team) && !privateChat && !ownHelper; diff --git a/src/components/ComputerPanel.takeover.test.ts b/src/components/ComputerPanel.takeover.test.ts index 46d0f131..d865f6a9 100644 --- a/src/components/ComputerPanel.takeover.test.ts +++ b/src/components/ComputerPanel.takeover.test.ts @@ -5,10 +5,11 @@ import { flushSync } from "react-dom"; import { createRoot, type Root } from "react-dom/client"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { ApiError } from "@/state/api"; -import { t } from "@/lib/i18n"; +import { setLocale, t } from "@/lib/i18n"; import type { Action, AppState, Bot, InstanceInfo } from "@/state/store"; const fixture = vi.hoisted(() => ({ + advanced: false, vm: {} as Record, vmRequests: [] as string[], vmForegroundRequests: 0, @@ -54,7 +55,7 @@ vi.mock("./DesktopCapabilities", async (importOriginal) => ({ }, }), })); -vi.mock("@/lib/interface-mode", () => ({ useAdvancedMode: () => false, setAdvancedMode: () => {} })); +vi.mock("@/lib/interface-mode", () => ({ useAdvancedMode: () => fixture.advanced, setAdvancedMode: () => {} })); vi.mock("./CloudScreenPreview", () => ({ CloudScreenPreview: ({ onOpen }: { onOpen: () => void }) => createElement("button", { "data-preview": "", onClick: onOpen }, "preview"), })); @@ -203,6 +204,8 @@ beforeEach(() => { setItem: (key: string, value: string) => void saved.set(key, value), removeItem: (key: string) => void saved.delete(key), }); + fixture.advanced = false; + setLocale("en"); fixture.vm = {}; fixture.vmRequests = []; fixture.vmForegroundRequests = 0; @@ -235,6 +238,7 @@ beforeEach(() => { })); }); afterEach(() => { + setLocale("en"); root?.unmount(); root = null; document.body.innerHTML = ""; @@ -759,3 +763,54 @@ it.each([ expect(resolved).not.toHaveBeenCalled(); expect(fixture.controls).toHaveLength(taking ? 1 : 0); }); + + +it.each(["en", "zh"] as const)("shows one unassigned or queued message in %s", async locale => { + vi.useFakeTimers(); + setLocale(locale); + fixture.vm = { mode: "shared", screen: null }; + state.config = { ...state.config!, localVm: { mode: "shared", screens: 4, maxInstances: 1 } }; + await open(makeBot({ computer: "vm" })); + expect(document.body.textContent!.split(t("vm.screens.unassignedBot"))).toHaveLength(2); + const assignment = document.querySelector('[role="status"]')!.parentElement!; + expect(assignment.classList.contains("mb-3")).toBe(true); + fixture.assignment = { screen: null, queue_position: 2 }; + await press(t("vm.screens.assignNow")); + expect(document.body.textContent!.split(t("vm.screens.queued", { position: 2 }))).toHaveLength(2); + expect(document.body.textContent).toContain(t("vm.screens.queueDetail")); + expect(document.body.textContent).not.toContain(t("vm.screens.unassignedBot")); + fixture.vm = { statusError: "Assignment unavailable" }; + await vi.advanceTimersByTimeAsync(2000); + await settle(); + expect(assignment.querySelector('[role="alert"]')?.textContent).toBe("Assignment unavailable"); + expect(assignment.classList.contains("mb-3")).toBe(true); +}); + +it.each([ + ["shared", 4, true], ["shared", 1, false], ["shared", undefined, false], ["per-bot", 4, false], +] as const)("uses the correct VM title and footer for %s with %s screens", async (mode, screens, shared) => { + vi.useFakeTimers(); + fixture.vm = { mode, screen: null }; + state.config = { ...state.config!, localVm: { mode, screens, maxInstances: 1 } }; + await open(makeBot({ computer: "vm" })); + for (const locale of ["en", "zh"] as const) { + setLocale(locale); + for (const advanced of [false, true]) { + fixture.advanced = advanced; + draw(); + await settle(); + const selected = [...document.querySelectorAll('button[aria-pressed="true"]')]; + expect(selected.some(node => node.textContent?.includes(t(shared ? "vm.dest.shared" : "vm.dest.vm")))).toBe(true); + expect(document.querySelector('[data-testid="place-line"]')?.textContent).toContain(t(shared ? "place.view.vmScreen.line" : "place.view.vm.line")); + if (shared) expect(document.body.textContent).not.toContain(t("vm.dest.vm")); + } + } +}); + +it("uses the shared title when a ready VM response omits its screen number", async () => { + vi.useFakeTimers(); + state.config = { ...state.config!, localVm: { mode: "shared", screens: 4, maxInstances: 1 } }; + await open(makeBot({ computer: "vm" })); + expect(document.body.textContent).toContain("Shared computer"); + expect(document.body.textContent).not.toContain("Private desktop"); +}); diff --git a/src/components/ComputerPanel.tsx b/src/components/ComputerPanel.tsx index c7dd0ba7..5b057745 100644 --- a/src/components/ComputerPanel.tsx +++ b/src/components/ComputerPanel.tsx @@ -11,7 +11,7 @@ import { api, ApiError, currentTaskBot, useStore, type Bot, type ConfigStatus } import { setAdvancedMode, useAdvancedMode } from "@/lib/interface-mode"; import { SIMPLE_ONLY } from "@/lib/simple-only"; import { ComputerFilesPane } from "./ComputerFilesPane"; -import { effectivePlace, personPin, placeLabelKey, placeOffered } from "@/lib/place"; +import { effectivePlace, personPin, placeLabelKey, placeOffered, vmLabelKey } from "@/lib/place"; import type { CloudBackend } from "../../shared/wire"; import { KeyRow } from "./keys/KeyRow"; import { openKeySettings } from "./keys/key-focus"; import { cn } from "@/lib/cn"; @@ -1129,7 +1129,7 @@ export function ComputerPanel({ const disabled = Boolean(managedBy) || placeBlocked(view); const issue = !managedBy && placeHasIssue(view); const unavailableTitle = managedBy ?? (issue ? view.line : mode === "browser" ? t("computer.browserOnlyTitle") : undefined); - return { mode, labelKey, descriptionKey, Icon, simpleLabel: providerLock && mode === "cloud" ? t("botAccess.cloud.selfHostedVps") : worksOnSimpleLabel(mode ?? undefined, capabilities.host.platform), selected, managedBy, disabled, unavailableTitle, view, issue }; + return { mode, labelKey, descriptionKey, Icon, simpleLabel: providerLock && mode === "cloud" ? t("botAccess.cloud.selfHostedVps") : worksOnSimpleLabel(mode ?? undefined, capabilities.host.platform, state.config), selected, managedBy, disabled, unavailableTitle, view, issue }; }); const worksOnView = placeOptions.find(({ selected }) => selected)?.view ?? autoView; const runPlaceAction = (id: PlaceActionId) => { @@ -1294,7 +1294,7 @@ export function ComputerPanel({ {currentTeamComputer && {autoView.short}} {phase === "local" && {t("computer.badge.local")}} {liveHere && {t("computer.inControl")}} - {phase === "vm" && !liveHere && {vmStatus?.screen?.screen ? t("vm.screens.number", { screen: vmStatus.screen.screen }) : t("vm.dest.vm")}} + {phase === "vm" && !liveHere && {vmStatus?.screen?.screen ? t("vm.screens.number", { screen: vmStatus.screen.screen }) : t(vmLabelKey(state.config))}} {(phase === "show-ready-boat" || phase === "show-sleeping-boat" || phase === "show-pending-boat") && ( {t("computer.badge.autoBoat")} )} @@ -1367,7 +1367,7 @@ export function ComputerPanel({ ) : ( )} - + {phase !== "vm-waiting" && {currentTeamComputer ? autoView.line : cloudPreviewReady @@ -1385,7 +1385,7 @@ export function ComputerPanel({ : vmResumable ? t(pending === "vm-start" ? "vm.setup.starting" : "computer.phase.vmStopped") : emptyState[phase]} - + } {currentTeamComputer && placeActionButton(autoView)} {bot.computer === "cloud" && (phase === "unconfigured" || phase === "error") && cloudView.action?.id !== "add-boat-key" && placeActionButton(cloudView)} { setError(null); setRetry((n) => n + 1); }} view={{ computer: bot.computer, cloudBackend, canManage: canManageCloud, busy: profileBot.busy === true, pending: pending !== null, phase, boatState, refusal: cloudRefused?.state }} /> @@ -1676,7 +1676,7 @@ export function ComputerPanel({ {livePin && (

- {t("place.pinnedNote", { place: t(placeLabelKey(livePin)) })} + {t("place.pinnedNote", { place: t(placeLabelKey(livePin, state.config)) })}

)}
@@ -1734,7 +1734,7 @@ export function ComputerPanel({

{t("place.pinnedNoteSimple", { - place: placeOptions.find(({ mode }) => mode === heldPin)?.simpleLabel ?? t(placeLabelKey(heldPin)), + place: placeOptions.find(({ mode }) => mode === heldPin)?.simpleLabel ?? t(placeLabelKey(heldPin, state.config)), })}

diff --git a/src/components/FailedTurnRow.place.test.ts b/src/components/FailedTurnRow.place.test.ts index a9facccf..808106b6 100644 --- a/src/components/FailedTurnRow.place.test.ts +++ b/src/components/FailedTurnRow.place.test.ts @@ -88,6 +88,17 @@ describe("J11: a failed place's row", () => { expect(show(pinned).buttons[0]).toContain("Clear this conversation's place"); }); + it.each([ + ["shared", 4, "Shared computer"], + ["shared", 1, "Private desktop"], + ["per-bot", 4, "Private desktop"], + ] as const)("names the bot's VM in the pin recovery action for %s / %s", (mode, screens, label) => { + fixture.config = { localVm: { mode, screens, maxInstances: 1 } }; + fixture.bots[0]!.computer = "vm"; + const pinned = stored({ state: "cc-no-start", params: { bot: "Scout" }, source: "pin" }); + expect(show(pinned).buttons[0]).toContain(`Use ${label}`); + }); + it("gives a User no button that changes a setting, and says who can", () => { fixture.ownerOrAdmin = false; const { html, buttons } = show(stored(hours), vi.fn()); diff --git a/src/components/LocalComputerSection.test.ts b/src/components/LocalComputerSection.test.ts index 3ccbd9e6..a12f5631 100644 --- a/src/components/LocalComputerSection.test.ts +++ b/src/components/LocalComputerSection.test.ts @@ -178,6 +178,30 @@ describe("Local VM inventory UI", () => { expect(markup).not.toMatch(/viewer_url|workspace_path|password=/); }); + it.each([ + [{ localVm: { mode: "shared", screens: 2, maxInstances: 4 } }, "共用电脑"], + [{ localVm: { mode: "per-bot", screens: 2, maxInstances: 4 } }, "私有桌面"], + ] as const)("uses the configured label for a VM destination: %j", (config, label) => { + setLocale("zh"); + storeFixture.config = config; + try { + const markup = renderToStaticMarkup(createElement(LocalVmInventoryCard, { + instances: [{ ...cloudVm, destination: "vm" }], + maxInstances: 4, + loading: false, + deletingBotId: null, + error: null, + unavailableReason: null, + onRefresh: vi.fn(), + onDelete: vi.fn(), + })); + + expect(markup).toContain(`当前目的地:${label}`); + } finally { + storeFixture.config = null; + } + }); + it("keeps state labels honest", () => { expect(localVmInventoryState(cloudVm)).toBe("Running"); expect(localVmInventoryState({ ...cloudVm, ready: false })).toBe("Needs attention"); diff --git a/src/components/LocalComputerSection.tsx b/src/components/LocalComputerSection.tsx index 6cf226a9..fdf31511 100644 --- a/src/components/LocalComputerSection.tsx +++ b/src/components/LocalComputerSection.tsx @@ -22,6 +22,7 @@ import { Select } from "./Select"; import { cn } from "@/lib/cn"; import { localizeComputerProblem } from "@/lib/computer-messages"; import { computerInventoryRequest, jsonPostRequest, type ComputerApiRequest } from "@/lib/computer-requests"; +import { vmLabelKey } from "@/lib/place"; import { useStore } from "@/state/store"; import { VpsComputersCard } from "./VpsComputersCard"; import { KeysLink } from "./keys/KeysLink"; import { LocalVmScreenSetting, LocalVmScreens, saveScreens } from "./LocalVmScreens"; @@ -135,15 +136,21 @@ interface VpsComputerInventoryPayload { instances: VpsComputerInventoryInstance[]; } -const destinationLabelKeys: Record = { +const destinationLabelKeys: Record, LocaleKey> = { auto: "vm.dest.auto", cloud: "place.cloud", - vm: "vm.dest.vm", local: "vm.dest.local", browser: "vm.dest.browser", off: "vm.dest.off", }; +function destinationLabelKey( + destination: LocalVmInventoryInstance["destination"], + config: Parameters[0], +): LocaleKey { + return destination === "vm" ? vmLabelKey(config) : destinationLabelKeys[destination]; +} + export type ComputerStateKind = | "unmanaged" | "in-use" @@ -487,6 +494,7 @@ export function LocalVmInventoryCard({ unavailableReason, onRefresh, onDelete, + config, }: { instances: LocalVmInventoryInstance[]; maxInstances: number; @@ -496,7 +504,10 @@ export function LocalVmInventoryCard({ unavailableReason: string | null; onRefresh: () => void; onDelete: (instance: LocalVmInventoryInstance) => void; + config?: Parameters[0]; }) { + const storeConfig = useStore().state.config; + const destinationConfig = config ?? storeConfig; return (
- {t("vm.perBot.destination", { destination: t(destinationLabelKeys[instance.destination]) })} + {t("vm.perBot.destination", { destination: t(destinationLabelKey(instance.destination, destinationConfig)) })}
{!managed && (
@@ -1314,6 +1325,7 @@ export function LocalComputerSection({ privateOnly = false }: { privateOnly?: bo unavailableReason={inventoryUnavailableReason} onRefresh={() => setInventoryRefreshKey((key) => key + 1)} onDelete={(instance) => void deletePerBotVm(instance)} + config={config} /> )} diff --git a/src/components/PlaceChip.test.ts b/src/components/PlaceChip.test.ts index 20b166bf..e090dc7f 100644 --- a/src/components/PlaceChip.test.ts +++ b/src/components/PlaceChip.test.ts @@ -1,6 +1,7 @@ import { createElement, type ComponentProps } from "react"; import { renderToStaticMarkup } from "react-dom/server"; import { afterAll, afterEach, describe, expect, it, vi } from "vitest"; +import { setLocale, t } from "@/lib/i18n"; import type { Bot, InstanceInfo } from "@/state/store"; vi.stubGlobal("window", {}); @@ -253,3 +254,34 @@ it.each([ const choice = worksOnChoices({ localVm: { mode, screens, maxInstances: 1 } }, {} as DesktopCapabilities).find(([place]) => place === "vm")!; expect(t(choice[2])).toBe(description); }); + + +describe("VM names in desktop and phone place menus", () => { + afterEach(() => { fixture.config = null; fixture.menuOpen = false; setLocale("en"); }); + + it.each([ + ["shared", 4, true], + ["shared", 1, false], + ["shared", undefined, false], + ["per-bot", 4, false], + ] as const)("uses the configured name for %s / %s screens", (mode, screens, shared) => { + fixture.config = { localVm: { mode, screens, maxInstances: 1 } }; + fixture.menuOpen = true; + const vmBot = { ...bot, computer: "vm" as const }; + for (const locale of ["en", "zh"] as const) { + setLocale(locale); + const label = locale === "zh" ? shared ? "共用电脑" : "私有桌面" : shared ? "Shared computer" : "Private desktop"; + const html = renderToStaticMarkup(createElement(PlaceChip, { bot: vmBot, live: false, onPin: vi.fn() })); + expect(html).toContain(`aria-label="${t("place.chipAria", { place: label })}"`); + expect(html).toContain(t("place.followBotDetail", { place: label })); + expect(html.split('role="menuitemradio"').slice(2).some(row => row.includes(`>${label}`))).toBe(true); + if (shared) expect(html).not.toMatch(/私有桌面|Private desktop/); + let item: ReturnType | undefined; + function Menu() { item = usePlaceMenuItem({ bot: vmBot, onPin: vi.fn() }); return null; } + renderToStaticMarkup(createElement(Menu)); + expect(item!.subtitle).toBe(label); + expect(item!.submenu!.find(row => row.key === "place:vm")!.label).toBe(label); + expect(item!.submenu!.find(row => row.key === "place:follow")!.note).toBe(t("place.followBotDetail", { place: label })); + } + }); +}); diff --git a/src/components/PlaceChip.tsx b/src/components/PlaceChip.tsx index 99c93c01..c5b26985 100644 --- a/src/components/PlaceChip.tsx +++ b/src/components/PlaceChip.tsx @@ -63,7 +63,7 @@ export function usePlaceMenuItem({ bot, task, disabled = false, onPin }: { return { key: "place", label: t("computer.worksOn"), - subtitle: t(placeLabelKey(effective)), + subtitle: t(placeLabelKey(effective, state.config)), icon: