diff --git a/.github/workflows/windows-chat-focus.yml b/.github/workflows/windows-chat-focus.yml index 988583b..adea37d 100644 --- a/.github/workflows/windows-chat-focus.yml +++ b/.github/workflows/windows-chat-focus.yml @@ -40,8 +40,8 @@ jobs: runs-on: ubuntu-24.04 timeout-minutes: 90 env: - # Match the extension used in the existing focus investigation. - ZOO_EXTENSION_VERSION: "3.84.0" + # Reproduce the release under investigation with the current Kotlin changes. + ZOO_EXTENSION_VERSION: "3.96.0" # This job packages the plugin; headful tests use the IDE's bundled JCEF. PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1" steps: diff --git a/docs/KNOWN_ISSUES.md b/docs/KNOWN_ISSUES.md index b47fbdc..cd6eb8f 100644 --- a/docs/KNOWN_ISSUES.md +++ b/docs/KNOWN_ISSUES.md @@ -2,6 +2,10 @@ This document records the known issues, limitations, and solutions for the Zoo Code JetBrains project. +The 3.96.0 Marketplace API warnings and JCEF compatibility work are tracked in +[issue #16](https://github.com/Zoo-Code-Org/Zoo-Code-Jetbrains/issues/16). +Release verification and the internal/experimental editor API migration remain open. + ## 1. JCEF Related Issues The current plugin implementation heavily relies on JCEF capabilities. In environments where JCEF cannot function properly, the plugin may fail to load normally. diff --git a/jetbrains_plugin/gradle.properties b/jetbrains_plugin/gradle.properties index eda0347..34c4e75 100644 --- a/jetbrains_plugin/gradle.properties +++ b/jetbrains_plugin/gradle.properties @@ -1,6 +1,6 @@ # Plugin basic information pluginGroup=org.zoocode.jetbrains -pluginVersion=3.78.0 +pluginVersion=3.96.0 # Platform basic information platformVersion=2023.3 diff --git a/jetbrains_plugin/scripts/ui-harness/README.md b/jetbrains_plugin/scripts/ui-harness/README.md index 89c045a..7185243 100644 --- a/jetbrains_plugin/scripts/ui-harness/README.md +++ b/jetbrains_plugin/scripts/ui-harness/README.md @@ -3,8 +3,46 @@ The source and runner in this directory work without the ignored investigation fixture. Prerequisites: a JCEF-enabled IntelliJ installation with JBR `javac` (tested with IU-253.28294.334), `jar`, `unzip`, Xvfb, xdotool, and Openbox. -Build the ZooCode plugin distribution first. Its Kotlin plugin version is -3.78.0; the embedded Zoo Code extension version is 3.84.0. +Supply a complete ZooCode release distribution ZIP. The tested plugin and +embedded extension versions come from that archive, not the harness source. + +## Testing Zoo Code 3.96.0 + +To test the published release, download its JetBrains plugin ZIP and pass it +directly to `PLUGIN_ZIP` on Linux or `-PluginZip` on Windows. This exercises the +released binary, including its bundled extension and runtime. Renaming an older +ZIP or overriding only `pluginVersion` does not produce a 3.96.0 release test. + +On a new checkout, run `./scripts/setup.sh` first. To test the current Kotlin +changes with extension 3.96.0, build from the repository root: + +```sh +ZOO_EXTENSION_VERSION=3.96.0 ./scripts/build.sh --mode release --clean --verbose +``` + +The build downloads that extension version and packages this checkout as 3.96.0. +This is a candidate build, distinct from the published release. The build updates +`gradle.properties` and replaces generated build outputs. Run it in a separate +checkout when retaining another build for comparison. + +Use the resulting ZIP with the Linux instructions below or the Windows command: + +```powershell +./run-windows.ps1 -IdeDir C:/tools/idea -PluginZip C:/build/ZooCode-3.96.0.zip ` + -EvidenceDir C:/temp/focus-3.96.0 +``` + +The credential-free fixture exercises real chat streaming, typing, and editor +opens. Live Solheim testing additionally covers model-driven terminal and diff +operations and needs the provider setup documented below. Gradle tests alone do +not exercise the bundled extension in a running IDE. + +The Windows CI workflow pins extension 3.96.0 and builds the checkout; +it has no input for an existing release ZIP. Its IDEA matrix is 2025.3 and +2026.2.1, so those jobs do not establish compatibility with IDEA 2023.3.8. +Record the exact ZIP, IDE version, and evidence directory when comparing builds. + +## Linux live setup Store the Solheim key in a private file outside the repository (mode 0600). Generate a random per-run local token. Run the `export` line in both shells, with the same value: @@ -25,7 +63,7 @@ In a second shell, export the same `SOLHEIM_RELAY_TOKEN` value. Then run from th ```sh IDE_DIR=/path/to/intellij \ -PLUGIN_ZIP=/path/to/ZooCode-3.78.0.zip \ +PLUGIN_ZIP=/path/to/ZooCode-3.96.0.zip \ HARNESS_WM_BIN=/usr/bin/openbox \ HARNESS_HEAP_MB=768 HARNESS_CPU_COUNT=4 DEADLINE_SECONDS=650 \ bash run-solheim.sh @@ -104,7 +142,7 @@ nothing. ## Windows GitHub Actions regression test (issue #5) `.github/workflows/windows-chat-focus.yml` builds the plugin from the tested -checkout with Zoo Code extension **3.84.0**, then runs the same Java driver on +checkout with Zoo Code extension **3.96.0**, then runs the same Java driver on `windows-2022` with IntelliJ **2025.3** and **2026.2.1**. It runs for pull requests that change the harness or relevant implementation, and supports manual dispatch once the workflow exists on the default branch. It does not publish a plugin. diff --git a/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/events/WorkspaceEvents.kt b/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/events/WorkspaceEvents.kt index 61a38ce..c98f33e 100644 --- a/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/events/WorkspaceEvents.kt +++ b/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/events/WorkspaceEvents.kt @@ -4,7 +4,6 @@ package org.zoocode.jetbrains.events -import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile /** @@ -60,21 +59,3 @@ object WorkspaceDirectoriesChangeEvent: EventType data class WorkspaceFilesChangeData( val changes: List ) - - -/** - * Workspace root change data class - * @param project The changed project - * @param oldPath Original workspace root path - * @param newPath New workspace root path - */ -data class WorkspaceRootChangeData( - val project: Project, - val oldPath: String?, - val newPath: String -) - -/** - * Workspace root change event - */ -object WorkspaceRootChangeEvent : EventType \ No newline at end of file diff --git a/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/ipc/proxy/LazyPromise.kt b/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/ipc/proxy/LazyPromise.kt index dee3b11..7037fd9 100644 --- a/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/ipc/proxy/LazyPromise.kt +++ b/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/ipc/proxy/LazyPromise.kt @@ -5,18 +5,37 @@ package org.zoocode.jetbrains.ipc.proxy import kotlinx.coroutines.CompletableDeferred +import kotlinx.coroutines.DisposableHandle +import kotlinx.coroutines.ExperimentalCoroutinesApi /** * Lazy Promise implementation * Corresponds to LazyPromise in VSCode */ -open class LazyPromise : CompletableDeferred by CompletableDeferred() { +open class LazyPromise { + // Delegating the entire CompletableDeferred interface generates overrides + // for obsolete Job APIs (plus, ChildJob and ChildHandle) in our bytecode. + // Keep the coroutine implementation private and expose only RPC operations. + private val deferred = CompletableDeferred() + + val isCompleted: Boolean get() = deferred.isCompleted + + suspend fun await(): Any? = deferred.await() + + fun cancel() = deferred.cancel() + + fun invokeOnCompletion(handler: (Throwable?) -> Unit): DisposableHandle = + deferred.invokeOnCompletion(handler) + + @OptIn(ExperimentalCoroutinesApi::class) + fun getCompleted(): Any? = deferred.getCompleted() + /** * Resolve Promise successfully * @param value Result value */ fun resolveOk(value: Any?) { - complete(value) + deferred.complete(value) } /** @@ -24,7 +43,7 @@ open class LazyPromise : CompletableDeferred by CompletableDeferred() { * @param err Error object */ fun resolveErr(err: Throwable) { - completeExceptionally(err) + deferred.completeExceptionally(err) } } @@ -35,11 +54,11 @@ open class LazyPromise : CompletableDeferred by CompletableDeferred() { class CanceledLazyPromise : LazyPromise() { init { // Immediately complete with cancellation exception - completeExceptionally(CanceledException()) + resolveErr(CanceledException()) } } /** * Cancellation exception */ -class CanceledException : Exception("Operation cancelled") \ No newline at end of file +class CanceledException : Exception("Operation cancelled") diff --git a/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/terminal/TerminalInstance.kt b/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/terminal/TerminalInstance.kt index e1b2205..8d15a7b 100644 --- a/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/terminal/TerminalInstance.kt +++ b/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/terminal/TerminalInstance.kt @@ -509,7 +509,7 @@ class TerminalInstance( return@invokeLater } hideTerminalToolWindow() - shellWidget?.hide() + shellWidget?.isVisible = false logger.info("✅ Terminal hidden: $extHostTerminalId") } catch (e: Exception) { logger.error("❌ Failed to hide terminal: $extHostTerminalId", e) diff --git a/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/webview/WebViewManager.kt b/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/webview/WebViewManager.kt index 4bf4169..03e1ce5 100644 --- a/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/webview/WebViewManager.kt +++ b/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/webview/WebViewManager.kt @@ -14,6 +14,7 @@ import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.project.Project import com.intellij.openapi.util.Disposer import com.intellij.ui.jcef.JBCefBrowser +import com.intellij.ui.jcef.JBCefBrowserBase import com.intellij.ui.jcef.JBCefJSQuery import org.zoocode.jetbrains.core.PluginContext import org.zoocode.jetbrains.core.ServiceProxyRegistry @@ -946,8 +947,8 @@ class WebViewInstance( } private fun setupJSBridge() { - // Create JS query object to handle messages from webview - jsQuery = JBCefJSQuery.create(browser) + // The cast selects the non-deprecated JBCefBrowserBase overload. + jsQuery = JBCefJSQuery.create(browser as JBCefBrowserBase) // Set callback for receiving messages from webview jsQuery?.addHandler { message -> diff --git a/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/workspace/WorkspaceFileChangeManager.kt b/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/workspace/WorkspaceFileChangeManager.kt index ffd717f..3eee2cf 100644 --- a/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/workspace/WorkspaceFileChangeManager.kt +++ b/jetbrains_plugin/src/main/kotlin/org/zoocode/jetbrains/workspace/WorkspaceFileChangeManager.kt @@ -5,23 +5,17 @@ package org.zoocode.jetbrains.workspace import com.intellij.openapi.Disposable -import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.Service import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.project.Project -import com.intellij.openapi.project.ProjectManager -import com.intellij.openapi.project.ProjectManagerListener -import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.* import com.intellij.openapi.vfs.newvfs.BulkFileListener import com.intellij.openapi.vfs.newvfs.events.* import com.intellij.util.messages.MessageBusConnection import org.zoocode.jetbrains.core.PluginContext import org.zoocode.jetbrains.core.ServiceProxyRegistry -import org.zoocode.jetbrains.core.WorkspaceManager import org.zoocode.jetbrains.events.* import org.zoocode.jetbrains.ipc.proxy.interfaces.FileSystemEvents -import java.util.concurrent.ConcurrentHashMap /** @@ -32,92 +26,23 @@ import java.util.concurrent.ConcurrentHashMap class WorkspaceFileChangeManager(val project: Project) : Disposable { private val logger = Logger.getInstance(WorkspaceFileChangeManager::class.java) - // Record registered file listener connections - private val vfsConnections = ConcurrentHashMap() + private var vfsConnection: MessageBusConnection? = null - // Record project workspace directory paths - private val projectWorkspacePaths = ConcurrentHashMap() - - // Project connection - private var projectConnection: MessageBusConnection? = null - - // Project listener - private val projectListener = object : ProjectManagerListener { - override fun projectOpened(project: Project) { - registerFileListener(project) - // Record initial project workspace directory - project.basePath?.let { projectWorkspacePaths[project] = it } - // Trigger workspace root change event - triggerWorkspaceRootChangeEvent(project, null, project.basePath ?: "") - } - - override fun projectClosed(project: Project) { - unregisterFileListener(project) - // Remove project workspace directory record - projectWorkspacePaths.remove(project) - } - } - init { + // The extension host initializes this project's file watcher on startup. logger.info("Initialize workspace file change manager") - - // Listen for project open/close events - projectConnection = ApplicationManager.getApplication().messageBus.connect(this) - projectConnection?.subscribe(ProjectManager.TOPIC, projectListener) - - // Register file listeners for already opened projects - val openProjects = ProjectManager.getInstance().openProjects - for (project in openProjects) { - registerFileListener(project) - // Record workspace directory for opened projects - project.basePath?.let { projectWorkspacePaths[project] = it } - } - } - - /** - * Trigger workspace root change event - * @param project Project - * @param oldPath Old workspace directory path - * @param newPath New workspace directory path - */ - private fun triggerWorkspaceRootChangeEvent(project: Project, oldPath: String?, newPath: String) { - logger.debug("Trigger workspace root change event: ${project.name}, old path: $oldPath, new path: $newPath") - - // Create workspace root change data - val workspaceChangeData = WorkspaceRootChangeData(project, oldPath, newPath) - - // Send workspace root change event via EventBus - project.getService(ProjectEventBus::class.java).emitInApplication(WorkspaceRootChangeEvent, workspaceChangeData) - - // Get ExtHostWorkspace proxy - val extHostWorkspace = PluginContext.getInstance(project).getRPCProtocol()?.getProxy(ServiceProxyRegistry.ExtHostContext.ExtHostWorkspace) - - // Get current workspace data - val workspaceData = project.getService(WorkspaceManager::class.java).getProjectWorkspaceData(project) - - extHostWorkspace?.let { - if(workspaceData != null) { - logger.debug("Send workspace root change to extension process: ${workspaceData.name}, folders: ${workspaceData.folders.size}") - it.acceptWorkspaceData(workspaceData) - } - } + registerFileListener() } /** * Register file listener - * @param project Project to listen to */ - private fun registerFileListener(project: Project) { - if (vfsConnections.containsKey(project)) { - logger.info("File listener for project ${project.name} already exists, skip registration") - return - } - + private fun registerFileListener() { logger.info("Register file listener for project ${project.name}") try { // Create connection and subscribe to VFS change events - val connection = project.messageBus.connect() + val connection = project.messageBus.connect(this) // Add virtual file system listener connection.subscribe(VirtualFileManager.VFS_CHANGES, object : BulkFileListener { @@ -127,30 +52,13 @@ class WorkspaceFileChangeManager(val project: Project) : Disposable { }) // Save connection for later cleanup - vfsConnections[project] = connection + vfsConnection = connection } catch (e: Exception) { logger.error("Failed to register file listener for project ${project.name}", e) } } - /** - * Unregister file listener - * @param project Project to unregister listener from - */ - private fun unregisterFileListener(project: Project) { - val connection = vfsConnections.remove(project) - if (connection != null) { - logger.info("Unregister file listener for project ${project.name}") - - try { - connection.disconnect() - } catch (e: Exception) { - logger.error("Failed to unregister file listener for project ${project.name}", e) - } - } - } - /** * Process bulk file events * @param events List of file events @@ -357,21 +265,9 @@ class WorkspaceFileChangeManager(val project: Project) : Disposable { logger.info("Release workspace file change manager resources") try { - // Disconnect project listener connection - projectConnection?.disconnect() - projectConnection = null - - // Release all file listener connections - vfsConnections.forEach { (project, connection) -> - try { - logger.info("Unregister file listener for project ${project.name}") - connection.disconnect() - } catch (e: Exception) { - logger.error("Failed to unregister file listener for project ${project.name}", e) - } - } - - vfsConnections.clear() + // Also support the explicit extension-host shutdown path. + vfsConnection?.disconnect() + vfsConnection = null } catch (e: Exception) { logger.error("Failed to release workspace file change manager resources", e) diff --git a/jetbrains_plugin/src/test/kotlin/org/zoocode/jetbrains/ipc/proxy/LazyPromiseTest.kt b/jetbrains_plugin/src/test/kotlin/org/zoocode/jetbrains/ipc/proxy/LazyPromiseTest.kt new file mode 100644 index 0000000..2b866ee --- /dev/null +++ b/jetbrains_plugin/src/test/kotlin/org/zoocode/jetbrains/ipc/proxy/LazyPromiseTest.kt @@ -0,0 +1,114 @@ +package org.zoocode.jetbrains.ipc.proxy + +import kotlinx.coroutines.CancellationException +import kotlinx.coroutines.CoroutineStart +import kotlinx.coroutines.async +import kotlinx.coroutines.runBlocking +import org.zoocode.jetbrains.util.toCompletableFuture +import org.junit.Assert.* +import org.junit.Test +import java.util.concurrent.ExecutionException +import java.util.concurrent.TimeUnit + +class LazyPromiseTest { + @Test + fun `failed reply rejects Java future with original error`() { + val promise = LazyPromise() + val future = promise.toCompletableFuture() + val error = IllegalStateException("remote failure") + + promise.resolveErr(error) + + val actual = assertThrows(ExecutionException::class.java) { + future.get(1, TimeUnit.SECONDS) + } + assertSame(error, actual.cause) + } + + @Test + fun `late Java future subscriber receives original failure`() { + val promise = LazyPromise() + val error = IllegalStateException("remote failure") + promise.resolveErr(error) + + val future = promise.toCompletableFuture() + + val actual = assertThrows(ExecutionException::class.java) { + future.get(1, TimeUnit.SECONDS) + } + assertSame(error, actual.cause) + } + + @Test + fun `cancelling promise cancels bridged Java future`() { + val promise = LazyPromise() + val future = promise.toCompletableFuture() + + promise.cancel() + + assertTrue(future.isCancelled) + assertThrows(CancellationException::class.java) { + future.get(1, TimeUnit.SECONDS) + } + } + + @Test + fun `completion callbacks still bridge replies to Java futures`() { + val promise = LazyPromise() + val future = promise.toCompletableFuture() + assertFalse(future.isDone) + promise.resolveOk("reply") + assertTrue(future.isDone) + assertEquals("reply", future.get()) + assertEquals("reply", promise.toCompletableFuture().get()) + } + + @Test + fun `reply wakes waiting caller and first completion wins`() = runBlocking { + val promise = LazyPromise() + val caller = async(start = CoroutineStart.UNDISPATCHED) { promise.await() } + assertFalse(promise.isCompleted) + assertFalse(caller.isCompleted) + promise.resolveOk("reply") + promise.resolveErr(IllegalStateException("late failure")) + assertEquals("reply", caller.await()) + assertTrue(promise.isCompleted) + } + + @Test + fun `failed reply preserves original error`() = runBlocking { + val error = IllegalStateException("remote failure") + val promise = LazyPromise() + promise.resolveErr(error) + try { + promise.await() + fail("Expected remote failure") + } catch (actual: IllegalStateException) { + assertSame(error, actual) + } + } + + @Test + fun `cancelled promise completes and rejects awaiting callers`() = runBlocking { + val promise = LazyPromise() + assertFalse(promise.isCompleted) + promise.cancel() + assertTrue(promise.isCompleted) + try { + promise.await() + fail("Expected cancellation") + } catch (_: CancellationException) { + } + } + + @Test + fun `pre-cancelled RPC reply keeps its protocol error`() = runBlocking { + val promise = CanceledLazyPromise() + assertTrue(promise.isCompleted) + try { + promise.await() + fail("Expected protocol cancellation") + } catch (_: CanceledException) { + } + } +}