From de836ec63b3da063d93f988ac7eb79219e736068 Mon Sep 17 00:00:00 2001 From: Bart van Helvert Date: Thu, 5 Nov 2026 00:40:20 +0100 Subject: [PATCH 1/4] test(ui-test): wait for hierarchy availability The split-mode hierarchy action can still be disabled immediately after the client moves its caret. Use the driver's bounded action retry while keeping the hierarchy assertions, and capture probe logs on CI failures. Refs #69 --- .github/workflows/ci.yml | 1 + .../codebridge/uitest/vscode/SplitModeTabColorProbe.kt | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2775d68c..b3bfeef3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -313,6 +313,7 @@ jobs: name: ui-test-ide-logs-${{ matrix.os }}-${{ matrix.shard }} path: | out/ide-tests/tests/*/*/*-test/ + out/ide-tests/tests/*/*/*-probe/ !out/ide-tests/tests/**/heap-dump/ out/resource-usage.log retention-days: 7 diff --git a/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/vscode/SplitModeTabColorProbe.kt b/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/vscode/SplitModeTabColorProbe.kt index 3a69f596..a8aba5c6 100644 --- a/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/vscode/SplitModeTabColorProbe.kt +++ b/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/vscode/SplitModeTabColorProbe.kt @@ -6,7 +6,7 @@ import com.intellij.driver.model.OnDispatcher import com.intellij.driver.model.RdTarget import com.intellij.driver.sdk.Project import com.intellij.driver.sdk.VirtualFile -import com.intellij.driver.sdk.invokeAction +import com.intellij.driver.sdk.invokeActionWithRetries import com.intellij.driver.sdk.singleProject import com.intellij.driver.sdk.ui.components.common.codeEditor import com.intellij.driver.sdk.ui.components.common.ideFrame @@ -85,7 +85,8 @@ class SplitModeTabColorProbe { val driver = run.driver val editor = driver.ideFrame { }.codeEditor() editor.goToPosition(1, 24) // The declaration of Shape, whose subtype is Circle. - driver.invokeAction("TypeHierarchy", component = editor.component) + // The action's availability follows the caret across the split after the client moves it. + driver.invokeActionWithRetries("TypeHierarchy", maxAttempts = 120) val texts = awaitValue("Circle in the client's type hierarchy", { driver.ideFrame { }.getAllTexts().map { it.text } }) { values -> values.any { it.contains("Circle") } } From ceb2c058b10dfa9fc7eb72b83b90f053c260c7d4 Mon Sep 17 00:00:00 2001 From: Bart van Helvert Date: Thu, 5 Nov 2026 00:09:48 +0100 Subject: [PATCH 2/4] fix(notebook): restore selection after undo edits The undo RPC reply can arrive before its streamed cell edits. Selecting old views then lets the following splice remove them and lose selection. Send selection through the same ordered flow, only to the editor that requested undo or redo, and keep focus in a cell the user began editing. Exercise repeated undo and redo of a multi-cell move in the UI test. Refs #67 --- .../codebridge/notebook/HostedNotebooks.kt | 5 ++++ .../codebridge/notebook/NotebookEditor.kt | 24 +++++++++---------- .../codebridge/notebook/NotebookApi.kt | 7 +++++- .../uitest/runtime/SplitModeNotebookTest.kt | 13 ++++++++-- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/runtime/notebook/backend/src/main/kotlin/me/helvert/codebridge/notebook/HostedNotebooks.kt b/src/runtime/notebook/backend/src/main/kotlin/me/helvert/codebridge/notebook/HostedNotebooks.kt index 3ed015a9..00e5d0ae 100644 --- a/src/runtime/notebook/backend/src/main/kotlin/me/helvert/codebridge/notebook/HostedNotebooks.kt +++ b/src/runtime/notebook/backend/src/main/kotlin/me/helvert/codebridge/notebook/HostedNotebooks.kt @@ -616,6 +616,11 @@ internal class HostedNotebooks(private val project: Project, private val scope: is NotebookModel.Edit.Outputs -> broadcast(open, NotebookEventDto.Outputs(edit.handle, edit.after.map(NotebookModel::outputDto))) } dirtied(open) + // A separate RPC reply can overtake the edit flow. Restore selection in that flow so + // a move's splice cannot remove the views the client has just selected. + if (replayed.selection.isNotEmpty()) { + open.editors[editorId]?.events?.trySend(NotebookEventDto.Selected(replayed.selection)) + } replayed.selection } diff --git a/src/runtime/notebook/frontend/src/main/kotlin/me/helvert/codebridge/notebook/NotebookEditor.kt b/src/runtime/notebook/frontend/src/main/kotlin/me/helvert/codebridge/notebook/NotebookEditor.kt index c0b31940..5cbce89d 100644 --- a/src/runtime/notebook/frontend/src/main/kotlin/me/helvert/codebridge/notebook/NotebookEditor.kt +++ b/src/runtime/notebook/frontend/src/main/kotlin/me/helvert/codebridge/notebook/NotebookEditor.kt @@ -259,6 +259,16 @@ internal class NotebookEditor( event.cells.forEachIndexed { offset, cell -> insert(event.start + offset, cell) } } is NotebookEventDto.Text -> cell(event.handle)?.setText(event.text) + is NotebookEventDto.Selected -> { + // Keep editing where the user went while the undo or redo was on its way. + if (cellList.isFocusOwner || focused == null) { + event.handles.lastOrNull()?.let(::cell)?.let { last -> + select(last) + anchor = cell(event.handles.first()) + highlight() + } + } + } is NotebookEventDto.Outputs -> cell(event.handle)?.setOutputs(event.outputs) is NotebookEventDto.Run -> { cell(event.handle)?.setRun(event.run) @@ -668,19 +678,9 @@ internal class NotebookEditor( cells.getOrNull(index.coerceIn(0, cells.size - 1))?.let(::select) } - /** Undoes or redoes the notebook's last cell edit, then selects the cells it touched. */ + /** Undoes or redoes the notebook's last cell edit; its flow restores selection after the edits. */ private fun replay(step: suspend NotebookApi.(ProjectId, String) -> List) { - call { projectId -> - val handles = step(projectId, id).ifEmpty { return@call } - // Unless the user went on to edit a cell meanwhile, as VS Code keeps the focus where it is. - whenShown({ it.handle == handles.last() }) { last -> - if (cellList.isFocusOwner || focused == null) { - select(last) - anchor = cell(handles.first()) - highlight() - } - } - } + call { step(it, id) } } private fun runCells(handles: List) { diff --git a/src/runtime/notebook/shared/src/main/kotlin/me/helvert/codebridge/notebook/NotebookApi.kt b/src/runtime/notebook/shared/src/main/kotlin/me/helvert/codebridge/notebook/NotebookApi.kt index da3800dd..94994163 100644 --- a/src/runtime/notebook/shared/src/main/kotlin/me/helvert/codebridge/notebook/NotebookApi.kt +++ b/src/runtime/notebook/shared/src/main/kotlin/me/helvert/codebridge/notebook/NotebookApi.kt @@ -80,7 +80,8 @@ interface NotebookApi : RemoteApi { /** * Takes back the notebook's last insert, delete, move, paste, join or output clearing, made in any of its * editors; cell text is each cell editor's own to undo. The handles of the cells to select for - * it, top to bottom: empty when there was nothing to take back or no cell is left. + * it, top to bottom: empty when there was nothing to take back or no cell is left. Selection + * also arrives as [NotebookEventDto.Selected], after the edit events in this editor's flow. */ suspend fun undo(projectId: ProjectId, editorId: String): List @@ -150,6 +151,10 @@ sealed interface NotebookEventDto { @Serializable data class Spliced(val start: Int, val deleted: Int, val cells: List) : NotebookEventDto + /** Selects [handles] in the editor that undid or redid an edit, after that edit's events. */ + @Serializable + data class Selected(val handles: List) : NotebookEventDto + /** Another editor of the notebook changed cell [handle]'s text. */ @Serializable data class Text(val handle: Int, val text: String) : NotebookEventDto diff --git a/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/runtime/SplitModeNotebookTest.kt b/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/runtime/SplitModeNotebookTest.kt index b588eb94..05afba3a 100644 --- a/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/runtime/SplitModeNotebookTest.kt +++ b/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/runtime/SplitModeNotebookTest.kt @@ -383,9 +383,18 @@ class SplitModeNotebookTest { awaitProbeValue("the move of both undone as one step", ::cells) { it == listOf("two", "three", "one", "two") } hostCells("""["two\n2\n2","three\n3\n3","one\n1\n1","two\n2\n2"]""") - // The undo leaves both selected again, so they are dragged together once more. The cells come - // back from the backend apart from the selection, which may follow them a moment later. + // Selection follows the edit events, so it cannot be cleared by a late splice. awaitProbeValue("both cells selected again by the undo", ::selected) { it == listOf(true, true, false, false) } + repeat(3) { + frame.keyboard { hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_SHIFT, KeyEvent.VK_Z) } + awaitProbeValue("the move of both redone", ::cells) { it == listOf("one", "two", "two", "three") } + hostCells("""["one\n1\n1","two\n2\n2","two\n2\n2","three\n3\n3"]""") + awaitProbeValue("both cells selected again by the redo", ::selected) { it == listOf(false, false, true, true) } + frame.keyboard { hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_Z) } + awaitProbeValue("the move of both undone again", ::cells) { it == listOf("two", "three", "one", "two") } + hostCells("""["two\n2\n2","three\n3\n3","one\n1\n1","two\n2\n2"]""") + awaitProbeValue("both cells selected again by the undo", ::selected) { it == listOf(true, true, false, false) } + } driver.withContext { driver.ui.dragAndDrop(handles()[0], to = handles()[3]) } awaitProbeValue("both cells, still selected, moved last again", ::cells) { it == listOf("one", "two", "two", "three") } hostCells("""["one\n1\n1","two\n2\n2","two\n2\n2","three\n3\n3"]""") From d4eca074d6661480ca011474d654e5694d0ae0f4 Mon Sep 17 00:00:00 2001 From: Bart van Helvert Date: Thu, 5 Nov 2026 00:53:17 +0100 Subject: [PATCH 3/4] test(ui-test): activate cell menus with the keyboard The list fixture's click can leave the popup open without invoking the chosen action. Focus the popup list, select the item and confirm it with Enter, then wait for closure. Repeat copy and undo to exercise activation while keeping the existing notebook and extension-host assertions. Refs #70 --- .../uitest/runtime/SplitModeNotebookTest.kt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/runtime/SplitModeNotebookTest.kt b/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/runtime/SplitModeNotebookTest.kt index 05afba3a..6ac3af87 100644 --- a/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/runtime/SplitModeNotebookTest.kt +++ b/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/runtime/SplitModeNotebookTest.kt @@ -1,6 +1,7 @@ package me.helvert.codebridge.uitest.runtime import com.intellij.driver.client.Remote +import com.intellij.driver.model.OnDispatcher import com.intellij.driver.sdk.ui.components.UiComponent import com.intellij.driver.sdk.ui.components.common.JEditorUiComponent import com.intellij.driver.sdk.ui.components.common.editor.completionList @@ -459,17 +460,23 @@ class SplitModeNotebookTest { awaitProbeValue("'$item' in the cell's menu", { runCatching { menu.rawItems }.getOrDefault(emptyList()) }) { items -> items.any { it.startsWith(item) } } - menu.clickItem(item, fullMatch = false) + driver.withContext(OnDispatcher.EDT) { menu.component.requestFocus() } + awaitProbeValue("the cell menu focused", { menu.isFocusOwner() }) { it } + menu.selectItem(item, fullMatch = false) + menu.keyboard { key(KeyEvent.VK_ENTER) } + awaitProbeValue("the cell menu closed", { menu.present() }) { !it } } awaitProbeValue("the notebook's cells in the client", ::cells) { it == listOf("one", "two") } // Copy Cell Down: a copy below, as one step that undo takes back. - fromMenu("Copy Cell Down") - awaitProbeValue("the copy below the cell", ::cells) { it == listOf("one", "one", "two") } - hostCells("""["one","one","two"]""") - frame.keyboard { hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_Z) } - awaitProbeValue("the copy undone", ::cells) { it == listOf("one", "two") } + repeat(3) { + fromMenu("Copy Cell Down") + awaitProbeValue("the copy below the cell", ::cells) { it == listOf("one", "one", "two") } + hostCells("""["one","one","two"]""") + frame.keyboard { hotKey(KeyEvent.VK_CONTROL, KeyEvent.VK_Z) } + awaitProbeValue("the copy undone", ::cells) { it == listOf("one", "two") } + } // Join With Next Cell: one cell, their texts a line apart. fromMenu("Join With Next Cell") From 2a788858f36de014b23c69ac13a60a6b2f50408c Mon Sep 17 00:00:00 2001 From: Bart van Helvert Date: Thu, 5 Nov 2026 20:07:08 +0100 Subject: [PATCH 4/4] test(ui-test): tolerate busy startup heartbeat gaps Allow a bounded 60-second connection idle margin in both test IDEs. A controlled 25-second backend pause disconnects the default connection but survives with this margin. Refs #71 --- .../me/helvert/codebridge/uitest/PluginUnderTest.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/PluginUnderTest.kt b/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/PluginUnderTest.kt index c6662b3d..f95f3744 100644 --- a/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/PluginUnderTest.kt +++ b/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/PluginUnderTest.kt @@ -108,8 +108,15 @@ internal fun IDERemDevTestContext.install(installed: Installed) { // The driver's robot posts mouse and key events into IdeEventQueue instead of moving the OS // cursor, so a run does not take over the developer's mouse and keyboard. The UI is driven in // the client; the backend gets it too in case a test drives backend UI. - applyVMOptionsPatch { addSystemProperty(INPUT_EVENTS_ROBOT, true) } - frontendIDEContext.applyVMOptionsPatch { addSystemProperty(INPUT_EVENTS_ROBOT, true) } + applyVMOptionsPatch { + addSystemProperty(INPUT_EVENTS_ROBOT, true) + addSystemProperty("rdct.wire.timeout.pings", 60) + } + frontendIDEContext.applyVMOptionsPatch { + addSystemProperty(INPUT_EVENTS_ROBOT, true) + // Busy CI startup can pause a peer beyond the default 15-second heartbeat deadline. + addSystemProperty("rdct.wire.timeout.pings", 60) + } } /** A plugin's directory in a test sandbox, which the Gradle task names in [property]. */