From 93aad6f98857091317326e0ea83e31dfb7ba9b56 Mon Sep 17 00:00:00 2001 From: Bart van Helvert Date: Thu, 5 Nov 2026 23:50:22 +0100 Subject: [PATCH] fix(testing): refresh discovered tests at startup Discovery can finish before the test UI subscribes. Reconcile open files once at registration so an earlier suite-only highlight is refreshed. Exercise incremental child discovery after the suite marker is drawn. Refs #77 --- .../testing/ui/CodeBridgeTestingActivity.kt | 2 ++ .../workbench-probe-extension/testing-probe.js | 17 ++++++++++++++++- .../uitest/runtime/SplitModeTestingTest.kt | 7 +++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/runtime/testrunner/backend/src/main/kotlin/me/helvert/codebridge/testing/ui/CodeBridgeTestingActivity.kt b/src/runtime/testrunner/backend/src/main/kotlin/me/helvert/codebridge/testing/ui/CodeBridgeTestingActivity.kt index faefc3f0..ea265cba 100644 --- a/src/runtime/testrunner/backend/src/main/kotlin/me/helvert/codebridge/testing/ui/CodeBridgeTestingActivity.kt +++ b/src/runtime/testrunner/backend/src/main/kotlin/me/helvert/codebridge/testing/ui/CodeBridgeTestingActivity.kt @@ -35,6 +35,8 @@ internal class CodeBridgeTestingUi(private val project: Project, private val sco val testing = HostedTesting.getInstance(project) testing.setRunOpener({ run -> CodeBridgeTestRuns.show(project, run) }, this) testing.addChangeListener(::changed, this) + // Discovery may finish before this startup activity registers its listener. + changed(emptySet()) } /** diff --git a/src/test-extensions/workbench-probe-extension/testing-probe.js b/src/test-extensions/workbench-probe-extension/testing-probe.js index aa75394f..12cf15c8 100644 --- a/src/test-extensions/workbench-probe-extension/testing-probe.js +++ b/src/test-extensions/workbench-probe-extension/testing-probe.js @@ -11,11 +11,24 @@ exports.install = context => { const controller = vscode.tests.createTestController('probeTests', 'Probe tests'); context.subscriptions.push(controller); context.subscriptions.push(vscode.commands.registerCommand('probe.testState', () => state)); + let childrenReady = false; + let pendingChildren = []; + const publishChildren = () => { + const children = pendingChildren; + pendingChildren = []; + children.forEach(([parent, item]) => parent.children.add(item)); + }; + context.subscriptions.push(vscode.commands.registerCommand('probe.discoverChildTests', () => { + childrenReady = true; + publishChildren(); + return true; + })); const discover = document => { if (document.languageId !== 'codebridgeactions') return; const file = controller.createTestItem(document.uri.toString(), document.uri.path.split('/').pop(), document.uri); let suite; + const children = []; for (let line = 0; line < document.lineCount; line++) { const match = /^(suite|test) (\w+)/.exec(document.lineAt(line).text); if (!match) continue; @@ -24,9 +37,11 @@ exports.install = context => { if (match[1] === 'suite') { suite = item; file.children.add(item); - } else (suite ?? file).children.add(item); + } else children.push([suite ?? file, item]); } controller.items.replace([file]); + pendingChildren = children; + if (childrenReady) publishChildren(); }; controller.resolveHandler = async item => { if (!item) vscode.workspace.textDocuments.forEach(discover); diff --git a/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/runtime/SplitModeTestingTest.kt b/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/runtime/SplitModeTestingTest.kt index b392fc8c..036824c6 100644 --- a/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/runtime/SplitModeTestingTest.kt +++ b/src/ui-test/src/test/kotlin/me/helvert/codebridge/uitest/runtime/SplitModeTestingTest.kt @@ -10,6 +10,7 @@ import com.intellij.ide.starter.junit5.RemoteDevRun import me.helvert.codebridge.uitest.awaitProbeValue import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import kotlin.test.assertEquals /** * `vscode.tests` as the user meets it in a JetBrains Client: Run in the gutter of each test an @@ -48,6 +49,12 @@ class SplitModeTestingTest { fun requested() = command("probe.testState") + // Publish children only after the suite was drawn, so their markers require an update + // rather than sharing the editor's initial highlighting pass. + awaitProbeValue("the suite's marker before child discovery", ::markers) { + it == mapOf(0 to "Run probe") + } + assertEquals("true", command("probe.discoverChildTests")) awaitProbeValue("a Run marker on the suite and on each test", ::markers) { it == mapOf(0 to "Run probe", 1 to "Run passes", 2 to "Run fails") }