diff --git a/crates/ide-host/tests/vcs_roots.rs b/crates/ide-host/tests/vcs_roots.rs index c13f85d33..4853a3d94 100644 --- a/crates/ide-host/tests/vcs_roots.rs +++ b/crates/ide-host/tests/vcs_roots.rs @@ -432,6 +432,14 @@ async fn patches_read_and_write_the_requested_repository() { }) .collect::(); let root = Some(roots[0].clone()); + // Automatic mappings wait for indexing; the new folders and exclude rule may start a rescan. + tokio::time::sleep(Duration::from_millis(200)).await; + for _ in 0..500 { + if !project.index.status().indexing { + break; + } + tokio::time::sleep(Duration::from_millis(10)).await; + } let preview = vcs::vcs_patch_preview(&host, "main", root.clone(), patch.clone(), None, None).await.unwrap(); assert!(preview.files.iter().all(|file| file.applies && !file.missing_base)); assert_eq!(preview.automatic_mappings.len(), 1); diff --git a/crates/ide-sdk/src/discover.rs b/crates/ide-sdk/src/discover.rs index a5374cb2b..0160837d8 100644 --- a/crates/ide-sdk/src/discover.rs +++ b/crates/ide-sdk/src/discover.rs @@ -1605,7 +1605,10 @@ mod pipenv_tests { #[test] fn environments_are_named_as_pipenv_names_them() { // `sanitize(folder)[:42] + "-" + urlsafe_b64encode(sha256(Pipfile path).digest()[:6])`, from pipenv. + #[cfg(unix)] assert_eq!(pipenv_env_name(Path::new("/home/me/My Shop (2)")), "My_Shop__2_-6rNTtAUD"); + #[cfg(windows)] + assert_eq!(pipenv_env_name(Path::new(r"C:\Users\me\My Shop (2)")), "My_Shop__2_-ED1rXUDC"); } #[test] diff --git a/crates/ide-sdk/src/tests.rs b/crates/ide-sdk/src/tests.rs index b30c52b5e..c2fce42e2 100644 --- a/crates/ide-sdk/src/tests.rs +++ b/crates/ide-sdk/src/tests.rs @@ -597,7 +597,7 @@ fn saved_python_configs_keep_their_explicit_interpreter() { config.cwd = Some(Path::new("member").into()); apply_to_run_configs(std::slice::from_mut(&mut config), root, &settings); assert_eq!(config.command, command); - assert_eq!(config.env["VIRTUAL_ENV"], root.join("member/.override").to_string_lossy()); + assert_eq!(config.env["VIRTUAL_ENV"], root.join("member").join(".override").to_string_lossy()); let saved = without_derived(&config, root, &settings); assert_eq!(saved.command, command); } diff --git a/src-tauri/src/events.rs b/src-tauri/src/events.rs index c66793446..fa8b28d58 100644 --- a/src-tauri/src/events.rs +++ b/src-tauri/src/events.rs @@ -228,6 +228,14 @@ mod tests { (coalescing_sink(Arc::new(move |event| saved.lock().push(event)), tokio::runtime::Handle::current()), events) } + /// Waits for the coalescing window to flush `n` events (a fixed sleep is too short on slow CI timers). + async fn wait_for_events(events: &Mutex>, n: usize) { + let deadline = std::time::Instant::now() + Duration::from_secs(5); + while events.lock().len() < n && std::time::Instant::now() < deadline { + tokio::time::sleep(Duration::from_millis(5)).await; + } + } + fn diagnostics(path: &str, source: &str, message: &str) -> IdeEvent { IdeEvent::Diagnostics { path: IpcPath::from(path), @@ -316,9 +324,7 @@ mod tests { sink.emit(diagnostics("/p/b.rs", "rust-analyzer", "other")); assert!(events.lock().is_empty()); - tokio::task::yield_now().await; - tokio::time::sleep(Duration::from_millis(30)).await; - tokio::task::yield_now().await; + wait_for_events(&events, 3).await; { let saved_events = events.lock(); @@ -381,7 +387,7 @@ mod tests { } assert_eq!(events.lock().len(), MAX_PENDING_DIAGNOSTICS); - tokio::time::sleep(Duration::from_millis(30)).await; + wait_for_events(&events, MAX_PENDING_DIAGNOSTICS + 1).await; assert_eq!(events.lock().len(), MAX_PENDING_DIAGNOSTICS + 1); } diff --git a/src/features/agents/McpPicker.tsx b/src/features/agents/McpPicker.tsx index 658e871b8..838a8ea58 100644 --- a/src/features/agents/McpPicker.tsx +++ b/src/features/agents/McpPicker.tsx @@ -64,7 +64,7 @@ export function McpPicker({ testData, }: McpPickerProps) { const tx = useTx(); - useMcpCatalogSync(); + useMcpCatalogSync(!hideTrigger); const catalogServers = useMcpCatalog((s) => s.servers); const catalogSources = useMcpCatalog((s) => s.sources); const projectIdeMcp = useProject((s) => s.settings?.mcpServer?.enabled ?? false); diff --git a/src/features/agents/Session.module.css b/src/features/agents/Session.module.css index ffed7e30a..15fc08d02 100644 --- a/src/features/agents/Session.module.css +++ b/src/features/agents/Session.module.css @@ -412,6 +412,8 @@ .reply { position: relative; + /* Keep WebKit's selection gap fill from extending across reply boundaries. */ + transform: translateX(0); } .replyFooter { position: absolute; diff --git a/src/features/agents/SessionPicker.tsx b/src/features/agents/SessionPicker.tsx index 310b6ac4b..1ff9518b4 100644 --- a/src/features/agents/SessionPicker.tsx +++ b/src/features/agents/SessionPicker.tsx @@ -176,7 +176,7 @@ export function SessionPicker({ )} -
{children(query, controls)}
+
{open && children(query, controls)}
diff --git a/src/features/agents/SkillsPicker.tsx b/src/features/agents/SkillsPicker.tsx index 8210296a2..401c39070 100644 --- a/src/features/agents/SkillsPicker.tsx +++ b/src/features/agents/SkillsPicker.tsx @@ -67,7 +67,7 @@ export function SkillsPicker({ testData, }: SkillsPickerProps) { const tx = useTx(); - useSkillsCatalogSync(backend); + useSkillsCatalogSync(!hideTrigger, backend); const catalogSkills = useSkillsCatalog((s) => s.skills); const skills = testData?.skills ?? catalogSkills; const resolved = useMemo(() => resolveSessionSkills(skills, overrides ?? {}), [skills, overrides]); diff --git a/src/features/agents/composerCommands.test.tsx b/src/features/agents/composerCommands.test.tsx index 48daa9cd4..0e8413298 100644 --- a/src/features/agents/composerCommands.test.tsx +++ b/src/features/agents/composerCommands.test.tsx @@ -3,10 +3,13 @@ import { sendKeyAction } from "./Composer"; import { act, fireEvent, render, screen, waitFor, within } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { EditorView } from "@codemirror/view"; -import type { AgentCommand, AgentProvider } from "@/bindings"; +import type { AgentCommand, AgentProvider, AgentSkillState } from "@/bindings"; const agentCommands = vi.fn(); const agentCreate = vi.fn(); +const agentMcpList = vi.fn(); +const agentMcpDiscoverSources = vi.fn(); +const agentSkillsList = vi.fn(); const vcsBranches = vi.fn(); const vcsBranchInfo = vi.fn(); const clipboardImage = vi.fn(); @@ -20,6 +23,9 @@ vi.mock("@/platform/ipc", async (importOriginal) => { ...real.commands, agentCommands: (provider: string, task: string | null) => agentCommands(provider, task), agentCreate: (request: unknown) => agentCreate(request), + agentMcpList: () => agentMcpList(), + agentMcpDiscoverSources: () => agentMcpDiscoverSources(), + agentSkillsList: () => agentSkillsList(), agentRefreshModels: async (provider: string) => ({ status: "ok", data: { @@ -108,6 +114,9 @@ beforeEach(() => { }), ); agentCommands.mockReset(); + for (const request of [agentMcpList, agentMcpDiscoverSources, agentSkillsList]) { + request.mockReset().mockResolvedValue({ status: "ok", data: [] }); + } clipboardImage.mockReset().mockResolvedValue({ status: "ok", data: "data:image/png;base64,iVBORw0KGgo=", @@ -174,6 +183,8 @@ describe("New Task composer commands", () => { it("opens the per-session MCP picker when /mcp is completed in the composer", async () => { agentCommands.mockResolvedValue({ status: "ok", data: [] }); render(); + expect(agentMcpList).not.toHaveBeenCalled(); + expect(agentMcpDiscoverSources).not.toHaveBeenCalled(); const box = screen.getByRole("textbox"); typeIn(box, "/mc"); const list = await screen.findByRole("listbox", { name: "Commands" }); @@ -181,11 +192,14 @@ describe("New Task composer commands", () => { fireEvent.keyDown(box, { key: "Enter" }); expect(textOf(box)).toBe(""); expect(await screen.findByText("Session MCP Servers")).toBeInTheDocument(); + expect(agentMcpList).toHaveBeenCalledOnce(); + expect(agentMcpDiscoverSources).toHaveBeenCalledOnce(); }); it("opens the per-session skills picker when /skills is completed in the composer", async () => { agentCommands.mockResolvedValue({ status: "ok", data: [] }); render(); + expect(agentSkillsList).not.toHaveBeenCalled(); const box = screen.getByRole("textbox"); typeIn(box, "/sk"); const list = await screen.findByRole("listbox", { name: "Commands" }); @@ -193,6 +207,7 @@ describe("New Task composer commands", () => { fireEvent.keyDown(box, { key: "Enter" }); expect(textOf(box)).toBe(""); expect(await screen.findByText("Session Skills")).toBeInTheDocument(); + expect(agentSkillsList).toHaveBeenCalledOnce(); }); it("names the icon-only Start action and disables it while starting", async () => { @@ -331,34 +346,32 @@ describe("New Task composer commands", () => { expect(agentCreate.mock.calls[0]![0]).toMatchObject({ idle: true, prompt: { text: "!gi" } }); }); - it("reflects per-session draft skillOverrides immediately in / completion", async () => { + it.each(["saved", "edited"])("reflects %s draft skill overrides in / completion", async (source) => { agentCommands.mockResolvedValue({ status: "ok", data: [command("triage", "Triage issues", "skill"), command("compact", "Compact")], }); - useSkillsCatalog.setState({ - loaded: true, - skills: [ - { - skill: { - name: "impeccable", - description: "Muted globally, enabled for this draft", - path: "/skills/impeccable", - source: "user", - valid: true, - warnings: [], - }, - mode: "off", - origin: "user", + const skills: AgentSkillState[] = [ + { + skill: { + name: "impeccable", + description: "Muted globally, enabled for this draft", + path: "/skills/impeccable", + source: "user", + valid: true, + warnings: [], }, - ], - }); + mode: "off", + origin: "user", + }, + ]; + const overrides = { triage: "off", impeccable: "auto" } as const; + agentSkillsList.mockResolvedValue({ status: "ok", data: skills }); + useSkillsCatalog.setState({ loaded: source === "edited", skills: source === "edited" ? skills : [] }); + if (source === "saved") setDraftSkillOverrides(overrides); render(); await waitFor(() => expect(agentCommands).toHaveBeenCalled()); - - act(() => { - setDraftSkillOverrides({ triage: "off", impeccable: "auto" }); - }); + if (source === "edited") act(() => setDraftSkillOverrides(overrides)); const box = screen.getByRole("textbox"); typeIn(box, "/"); diff --git a/src/features/agents/mcpModel.ts b/src/features/agents/mcpModel.ts index 689f34e0f..2055ae83e 100644 --- a/src/features/agents/mcpModel.ts +++ b/src/features/agents/mcpModel.ts @@ -239,13 +239,15 @@ export async function refreshMcpCatalog(): Promise { })); } -export function useMcpCatalogSync(): void { +export function useMcpCatalogSync(eager: boolean): void { const root = useProject((s) => s.project?.root); useEffect(() => { if (!isTauri()) return; - void refreshMcpCatalog(); const onFocus = () => void refreshMcpCatalog(); - window.addEventListener("focus", onFocus); + if (eager) { + onFocus(); + window.addEventListener("focus", onFocus); + } if (!listenerAttached && typeof onIdeEvent === "function") { listenerAttached = true; onIdeEvent("settingsChanged", (e) => { @@ -255,5 +257,5 @@ export function useMcpCatalogSync(): void { }); } return () => window.removeEventListener("focus", onFocus); - }, [root]); + }, [eager, root]); } diff --git a/src/features/agents/session/Stream.tsx b/src/features/agents/session/Stream.tsx index 0b5dbe972..7eb21082a 100644 --- a/src/features/agents/session/Stream.tsx +++ b/src/features/agents/session/Stream.tsx @@ -575,6 +575,41 @@ export function Stream({ ), [task, lastIndex, busy, thinking, onDiagramDrawn, renderRow], ); + const agentName = providerName(task.provider); + // Switching tabs changes visibility without changing the conversation rows. + const renderedRows = useMemo( + () => + rows.map((row) => { + const images = toolImages(row); + return ( +
+ {authorHeaders.has(row.index) && ( +
+
+ + {agentName} +
+
+ )} + {renderConversationRow(row)} + {images.length > 0 && ( +
+ +
+ )} +
+ ); + }), + [rows, authorHeaders, task.provider, agentName, renderConversationRow], + ); return ( @@ -675,38 +710,7 @@ export function Stream({ ) : entries.length === 0 && !busy && !loadError ? ( ) : ( - - {rows.map((row) => { - const images = toolImages(row); - return ( -
- {authorHeaders.has(row.index) && ( -
-
- - {providerName(task.provider)} -
-
- )} - {renderConversationRow(row)} - {images.length > 0 && ( -
- -
- )} -
- ); - })} -
+ {renderedRows} )}
diff --git a/src/features/agents/skillsModel.ts b/src/features/agents/skillsModel.ts index c80b5cb34..8a1341282 100644 --- a/src/features/agents/skillsModel.ts +++ b/src/features/agents/skillsModel.ts @@ -153,13 +153,15 @@ export async function refreshSkillsCatalog(backend: SkillsBackend = defaultSkill if (skills) useSkillsCatalog.setState({ skills, loaded: true }); } -export function useSkillsCatalogSync(backend: SkillsBackend = defaultSkillsBackend): void { +export function useSkillsCatalogSync(eager: boolean, backend: SkillsBackend = defaultSkillsBackend): void { const root = useProject((s) => s.project?.root); useEffect(() => { if (!isTauri()) return; - void refreshSkillsCatalog(backend); const onFocus = () => void refreshSkillsCatalog(backend); - window.addEventListener("focus", onFocus); + if (eager) { + onFocus(); + window.addEventListener("focus", onFocus); + } if (!listenerAttached && typeof onIdeEvent === "function") { listenerAttached = true; onIdeEvent("settingsChanged", (e) => { @@ -169,5 +171,5 @@ export function useSkillsCatalogSync(backend: SkillsBackend = defaultSkillsBacke }); } return () => window.removeEventListener("focus", onFocus); - }, [root, backend]); + }, [eager, root, backend]); } diff --git a/src/features/agents/store.ts b/src/features/agents/store.ts index 832c6f104..39d6ad3e9 100644 --- a/src/features/agents/store.ts +++ b/src/features/agents/store.ts @@ -27,7 +27,7 @@ import { auxiliaryWindow, windowLabel } from "@/platform/auxWindow"; import { routeToWindow, taskWindowDraft, taskWindowFocused, updateTaskWindowDraft } from "./taskWindowRouting"; import { clearAgentTaskFontZoom, resetAllAgentFontZoom } from "./fontZoom"; import { clearDismissedAssets } from "./sessionAssetsModel"; -import { useSkillsCatalog } from "./skillsModel"; +import { useSkillsCatalog, useSkillsCatalogSync } from "./skillsModel"; import { basename, useProject } from "@/platform/project"; import { projectLocation } from "@/platform/remote"; import { defaultTaskProject } from "./project"; @@ -1067,6 +1067,8 @@ export function useAgentCommands( offered: readonly AgentCommand[], ): readonly AgentCommand[] { const skillOverrides = useAgents((s) => (task ? s.tasks.get(task)?.skillOverrides : s.draft.skillOverrides)); + // The server's draft commands omit skills that only this draft has enabled. + useSkillsCatalogSync(task === null && Object.values(skillOverrides ?? {}).some((mode) => mode !== "off")); const catalogSkills = useSkillsCatalog((s) => s.skills); const [found, setFound] = useState<{ for: unknown[];