From cb00809763681ea647ddd48541c4e63131f2929b Mon Sep 17 00:00:00 2001 From: "lithe-support[bot]" <356900028+lithe-support[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:25:36 +0000 Subject: [PATCH 1/3] refactor(plugins): centralize writable state directories (#1841) --- desktop/internal/pluginpkg/install.go | 15 +++++++++++- desktop/internal/pluginpkg/install_test.go | 23 +++++++++++++++++++ desktop/internal/pluginservice/backendhost.go | 2 +- .../internal/pluginservice/backendlaunch.go | 3 ++- desktop/internal/pluginservice/backends.go | 6 +---- desktop/internal/pluginservice/hostmethods.go | 3 ++- desktop/internal/pluginservice/pages.go | 4 +++- .../internal/pluginservice/pluginservice.go | 4 ++-- desktop/internal/workbench/build.go | 3 ++- desktop/internal/workbench/debug_start.go | 3 ++- desktop/internal/workbench/vcs.go | 3 ++- 11 files changed, 54 insertions(+), 15 deletions(-) diff --git a/desktop/internal/pluginpkg/install.go b/desktop/internal/pluginpkg/install.go index 54e1253ecc..9a9a153bca 100644 --- a/desktop/internal/pluginpkg/install.go +++ b/desktop/internal/pluginpkg/install.go @@ -21,6 +21,19 @@ const ( StateDirectory = ".state" ) +// StateRoot returns the writable state directory of one installed plugin. +// It is outside every installed version, and RemoveState owns its cleanup. +// The caller must supply a validated plugin identity. +func StateRoot(root, pluginID string) string { + return filepath.Join(root, StateDirectory, pluginID) +} + +// VersionStateRoot returns the writable state directory of one plugin version. +// The caller must supply validated plugin and version identities. +func VersionStateRoot(root, pluginID, version string) string { + return filepath.Join(StateRoot(root, pluginID), version) +} + // Installed is one plugin package version present in the root. type Installed struct { // ID is the plugin identifier the package was installed under. @@ -172,7 +185,7 @@ func RemoveState(root, id string) error { if err := CheckIdentity("plugin ID", id); err != nil { return err } - target := filepath.Join(root, StateDirectory, id) + target := StateRoot(root, id) switch info, err := os.Lstat(target); { case errors.Is(err, fs.ErrNotExist): return nil diff --git a/desktop/internal/pluginpkg/install_test.go b/desktop/internal/pluginpkg/install_test.go index 1d8f7fda24..837908809f 100644 --- a/desktop/internal/pluginpkg/install_test.go +++ b/desktop/internal/pluginpkg/install_test.go @@ -95,6 +95,29 @@ func TestInstallRefusesRelativePaths(t *testing.T) { } } +func TestStateRootsFollowRemovalLayout(t *testing.T) { + root := t.TempDir() + const id = "dev.lithe.test.sample" + const version = "1.2.3" + wantRoot := filepath.Join(root, StateDirectory, id) + if got := StateRoot(root, id); got != wantRoot { + t.Fatalf("StateRoot = %q, want %q", got, wantRoot) + } + wantVersion := filepath.Join(wantRoot, version) + if got := VersionStateRoot(root, id, version); got != wantVersion { + t.Fatalf("VersionStateRoot = %q, want %q", got, wantVersion) + } + if err := os.MkdirAll(wantVersion, 0o700); err != nil { + t.Fatal(err) + } + if err := RemoveState(root, id); err != nil { + t.Fatalf("RemoveState = %v", err) + } + if _, err := os.Stat(wantVersion); !errors.Is(err, os.ErrNotExist) { + t.Fatalf("version state survived removal: %v", err) + } +} + func TestUninstallRemovesVersionAndEmptyID(t *testing.T) { root := t.TempDir() if _, err := Install(root, "example", "1.0.0", newStaging(t, root)); err != nil { diff --git a/desktop/internal/pluginservice/backendhost.go b/desktop/internal/pluginservice/backendhost.go index ed08b276a8..e172ca940f 100644 --- a/desktop/internal/pluginservice/backendhost.go +++ b/desktop/internal/pluginservice/backendhost.go @@ -609,7 +609,7 @@ func (d pluginDirectories) create() error { // The log directory is the log session's, which the log store has already created. func (s *Service) backendDirectories(ctx context.Context, pluginID, version string) pluginDirectories { return pluginDirectories{ - state: filepath.Join(s.Root, pluginStateDirectory, pluginID, version), + state: pluginpkg.VersionStateRoot(s.Root, pluginID, version), log: s.logDirectory(ctx, pluginID), } } diff --git a/desktop/internal/pluginservice/backendlaunch.go b/desktop/internal/pluginservice/backendlaunch.go index e6e839f65c..4a37bb766d 100644 --- a/desktop/internal/pluginservice/backendlaunch.go +++ b/desktop/internal/pluginservice/backendlaunch.go @@ -10,6 +10,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginbackend" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginpkg" ) // backendLaunch is a decoded backend-resolved launch and the directories it uses. @@ -32,7 +33,7 @@ func (s *Service) resolveBackendLaunch(ctx context.Context, pluginID, version st if workspace.ContextID == "" { return backendLaunch{}, fmt.Errorf("%w: a backend-resolved server needs an open workspace", pluginbackend.ErrRequest) } - base := filepath.Join(s.Root, pluginStateDirectory, pluginID) + base := pluginpkg.StateRoot(s.Root, pluginID) temporary, err := os.MkdirTemp("", "lithe-server-") if err != nil { return backendLaunch{}, err diff --git a/desktop/internal/pluginservice/backends.go b/desktop/internal/pluginservice/backends.go index 1106c4f9a6..82c8e2f700 100644 --- a/desktop/internal/pluginservice/backends.go +++ b/desktop/internal/pluginservice/backends.go @@ -87,7 +87,7 @@ func (s *Service) StartLanguageServer(ctx context.Context, entries []pluginmanag // State lives beside the installed versions, never inside one: an installed // package is read-only for the host, and a version directory that changed // would no longer match the digest the user approved. - stateDirectory := filepath.Join(s.Root, pluginStateDirectory, entry.Installed.ID, entry.Installed.Version) + stateDirectory := pluginpkg.VersionStateRoot(s.Root, entry.Installed.ID, entry.Installed.Version) if stateErr := os.MkdirAll(stateDirectory, 0o700); stateErr != nil { return fail(stateErr) } @@ -177,10 +177,6 @@ func (s *Service) StopLanguageServer(ctx context.Context, session *LanguageSessi return s.Backend.Stop(ctx, session.Session) } -// pluginStateDirectory is the reserved directory below the plugin root where -// running servers keep their state. It starts with a dot, so List never reads it -// as an installed plugin; uninstalling a plugin removes its part of it. -const pluginStateDirectory = pluginpkg.StateDirectory type languageServerDeclaration struct { LanguageServers []struct { diff --git a/desktop/internal/pluginservice/hostmethods.go b/desktop/internal/pluginservice/hostmethods.go index 264ee568fa..1845d259b3 100644 --- a/desktop/internal/pluginservice/hostmethods.go +++ b/desktop/internal/pluginservice/hostmethods.go @@ -11,6 +11,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginhost" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginpkg" ) // Host service grants and methods this client answers. A launch plan lists @@ -128,7 +129,7 @@ func (s *Service) contextJSON(pluginID string, workspace WorkspaceContext) conte // plugin package and the application bundle. It is created on first use here and // nowhere else, so listing contexts leaves no directories behind. func (s *Service) contextState(pluginID string, workspace WorkspaceContext) (string, error) { - directory := filepath.Join(s.Root, pluginStateDirectory, pluginID, "backend", "workspaces", WorkspaceKey(workspace.Path)) + directory := filepath.Join(pluginpkg.StateRoot(s.Root, pluginID), "backend", "workspaces", WorkspaceKey(workspace.Path)) if err := os.MkdirAll(directory, 0o700); err != nil { return "", err } diff --git a/desktop/internal/pluginservice/pages.go b/desktop/internal/pluginservice/pages.go index c77b9ffdad..be4e10860a 100644 --- a/desktop/internal/pluginservice/pages.go +++ b/desktop/internal/pluginservice/pages.go @@ -9,6 +9,8 @@ import ( "os" "path/filepath" "time" + + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginpkg" ) // Plugin web pages (`ui` 2) reach a plugin's backend and keep a small state @@ -40,7 +42,7 @@ func (s *Service) CallFromPage(ctx context.Context, pluginID, function string, p // bundle. The window ID is a digest, so it is one path component. func (s *Service) pageStatePath(pluginID, windowID, workspacePath string) string { sum := sha256.Sum256([]byte(windowID)) - return filepath.Join(s.Root, pluginStateDirectory, pluginID, "pages", "workspaces", WorkspaceKey(workspacePath), hex.EncodeToString(sum[:])[:24]+".json") + return filepath.Join(pluginpkg.StateRoot(s.Root, pluginID), "pages", "workspaces", WorkspaceKey(workspacePath), hex.EncodeToString(sum[:])[:24]+".json") } // PageState returns the stored state of a window, nil when there is none. diff --git a/desktop/internal/pluginservice/pluginservice.go b/desktop/internal/pluginservice/pluginservice.go index af5c5e57d5..e3d45359d0 100644 --- a/desktop/internal/pluginservice/pluginservice.go +++ b/desktop/internal/pluginservice/pluginservice.go @@ -175,7 +175,7 @@ func open(kernel Kernel, preferences *store.Store, root string, first bool) (*Se Manager: pluginmanager.New(kernel, root, approvals, state), Installer: plugininstall.New(kernel, NewReviewer(kernel), approvals, pluginhost.Declared()), Backend: pluginbackend.New(kernel, hostServices), - Commands: &pluginhost.CommandStore{State: filepath.Join(root, pluginStateDirectory)}, + Commands: &pluginhost.CommandStore{State: filepath.Join(root, pluginpkg.StateDirectory)}, Settings: pluginsettings.New(kernel, preferences.Dir()), HostServices: hostServices, Credentials: credentials.Default(), @@ -187,7 +187,7 @@ func open(kernel Kernel, preferences *store.Store, root string, first bool) (*Se service.Backend.SetCommandStore(service.Commands) service.Host = newBackendHost(service) service.Runs = newRuns(service) - service.Contexts = newWorkspaceContexts(filepath.Join(root, pluginStateDirectory)) + service.Contexts = newWorkspaceContexts(filepath.Join(root, pluginpkg.StateDirectory)) service.Contexts.SetObserver(service.contextsChanged) service.Contexts.SetClosedObserver(service.resources.releaseContext) if err := service.registerHostServices(); err != nil { diff --git a/desktop/internal/workbench/build.go b/desktop/internal/workbench/build.go index cf5154516c..892051775e 100644 --- a/desktop/internal/workbench/build.go +++ b/desktop/internal/workbench/build.go @@ -21,6 +21,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginbackend" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginpkg" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice" "github.com/1lck/Lithe-IDEA/desktop/internal/processledger" "github.com/1lck/Lithe-IDEA/desktop/internal/toolchain" @@ -333,7 +334,7 @@ func workspaceDigest(root string) string { } func buildStateDirectory(pluginRoot, workspace string, instance buildInstance) string { - return filepath.Join(pluginRoot, ".state", instance.PluginID, instance.Version, "build", workspaceDigest(workspace)) + return filepath.Join(pluginpkg.VersionStateRoot(pluginRoot, instance.PluginID, instance.Version), "build", workspaceDigest(workspace)) } // buildProvider starts a provider process, or attaches to the language server diff --git a/desktop/internal/workbench/debug_start.go b/desktop/internal/workbench/debug_start.go index ca6307619e..2285b6a4c3 100644 --- a/desktop/internal/workbench/debug_start.go +++ b/desktop/internal/workbench/debug_start.go @@ -19,6 +19,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginhost" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginpkg" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice" "github.com/vivaui/viva/ui" ) @@ -460,7 +461,7 @@ func (a *App) beginDebug(p *project, start debugStart) { if start.parent != nil { parentSessionID = start.parent.id } - stateRoot := filepath.Join(pluginRoot, ".state", adapter.PluginID, adapter.Version) + stateRoot := pluginpkg.VersionStateRoot(pluginRoot, adapter.PluginID, adapter.Version) // Only a stdio adapter is written through its standard input; the other // transports are written through their TCP stream. var stdinReader *os.File diff --git a/desktop/internal/workbench/vcs.go b/desktop/internal/workbench/vcs.go index 654dfd7b7b..d35c8e22fb 100644 --- a/desktop/internal/workbench/vcs.go +++ b/desktop/internal/workbench/vcs.go @@ -17,6 +17,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/core" "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginbackend" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginpkg" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginservice" "github.com/vivaui/viva/ui" ) @@ -388,7 +389,7 @@ func (r *vcsRuntime) session(ctx context.Context, runner *pluginbackend.Runner, if client != nil && !client.Closed() { return client, nil } - state := filepath.Join(pluginRoot, ".state", window.PluginID, window.Version, "vcs", workspaceDigest(root)) + state := filepath.Join(pluginpkg.VersionStateRoot(pluginRoot, window.PluginID, window.Version), "vcs", workspaceDigest(root)) workspaceState := filepath.Join(state, "workspace") temporaryDirectory := filepath.Join(state, "tmp") for _, directory := range []string{state, workspaceState, temporaryDirectory} { From 1bc1afc589fa87068dbc357d8157f1ad26f6d868 Mon Sep 17 00:00:00 2001 From: "lithe-support[bot]" <356900028+lithe-support[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:37:10 +0000 Subject: [PATCH 2/3] fix(ci): format plugin state paths and document matrix evidence --- desktop/internal/pluginservice/backends.go | 1 - .../features/plugin-extension-management.json | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/desktop/internal/pluginservice/backends.go b/desktop/internal/pluginservice/backends.go index 82c8e2f700..ad66abaf0d 100644 --- a/desktop/internal/pluginservice/backends.go +++ b/desktop/internal/pluginservice/backends.go @@ -177,7 +177,6 @@ func (s *Service) StopLanguageServer(ctx context.Context, session *LanguageSessi return s.Backend.Stop(ctx, session.Session) } - type languageServerDeclaration struct { LanguageServers []struct { LanguageID string `json:"languageID"` diff --git a/shared/platform-feature-matrix/features/plugin-extension-management.json b/shared/platform-feature-matrix/features/plugin-extension-management.json index b39b68a5f7..d385ed3d06 100644 --- a/shared/platform-feature-matrix/features/plugin-extension-management.json +++ b/shared/platform-feature-matrix/features/plugin-extension-management.json @@ -16,6 +16,7 @@ "desktop/internal/settingswindow/installed_view.go", "desktop/internal/pluginservice/lifecycle.go", "desktop/internal/pluginpkg/install.go", + "desktop/internal/pluginpkg/install_test.go", "desktop/internal/workbench/plugins.go", "desktop/internal/workbench/plugin_displace.go", "desktop/internal/pluginmanager/pluginmanager_test.go", @@ -38,6 +39,7 @@ "desktop/internal/settingswindow/installed_view.go", "desktop/internal/pluginservice/lifecycle.go", "desktop/internal/pluginpkg/install.go", + "desktop/internal/pluginpkg/install_test.go", "desktop/internal/workbench/plugins.go", "desktop/internal/workbench/plugin_displace.go", "desktop/internal/pluginmanager/pluginmanager_test.go", @@ -48,7 +50,7 @@ ] }, "owner": "Extensions", - "verification": "Viva:从插件市场安装一个带语言服务器的社区插件,在审查框确认后插件立即显示“已启用”,打开对应文件即启动语言服务器;先禁用再安装新版本,确认仍为禁用;卸载后重新安装,确认又是启用。卸载时确认先停止语言服务器和插件后端,再删除插件包和 `<插件根>/.state/<插件 ID>`(含插件写入的缓存与下载物等),其他插件的状态和 `.state/host-secret` 保留;卸载后再触发跳转不会打开定义,也不会重新拉起进程。禁用插件时同样停止它的后端。 macOS 全新安装时打开插件页,确认“已安装”标签不再显示未安装插件的占位项(改由“插件市场”标签提供安装),齿轮菜单可“从磁盘安装插件”选择已签名的插件包;社区插件在“已安装”中显示来源仓库与社区维护提示,可卸载;安装后可搜索并启用、禁用该插件,确认状态与重启恢复,且页面不显示无恢复路径的卸载操作;同时打开一个插件提供的工具窗口确认插件内容不被遮挡。Windows 检查扩展管理入口和持久化。契约 v1 插件在设置的独立“声明式插件”页管理(启用/停用/卸载/回滚,与 Worker 扩展分开列出,隔离原因直接展示),管理命令走 plugin_host 的 Tauri 命令。 Windows 缺少 Bun 或语言服务器时更新扩展,确认旧扩展的安装、启用和待更新状态保留,错误给出安装依赖后重试的提示;预检期间禁用或卸载扩展,确认返回后不会继续安装或重新启用;手动将 Marksman 等语言服务器安装到 PATH 后重启,确认能识别并启用。 Windows 契约插件:同时在两个产品窗口启动语言服务/运行任务,在启动尚未返回时分别禁用、卸载、更新和回滚;确认先撤销入口、等待两窗口所有进程和原生探测退出,再改包目录。停止失败、窗口断开或确认超时发生在改包前,文件保留且插件继续阻断;改包后重新扫描失败也必须报错并保持阻断,不能使用旧目录缓存;重试可恢复,不能出现占用可执行文件导致的半删除。 不同插件并发管理时,全盘扫描必须从读取到提交缓存串行,最终缓存包含所有已经成功安装的包;检查 tests.rs 的有序发布回归。 同一语言只由一个已启用插件提供语言服务器:先启用为某语言声明语言服务器的插件 A 并打开该语言的文件,再启用(或安装)为同一语言声明语言服务器的插件 B,确认 A 变为禁用、其语言服务器与后端退出、出现“已停用「A」:「B」也提供该语言的语言服务器”提示,已打开的文件改由 B 的服务器同步;再启用 A 时反向成立。两个插件在规则之前都被启用时,只有按 ID 排在前面的一个运行;停用它后另一个接手。scripts/desktop/desktop-go.sh test ./internal/pluginmanager -run 'TestEnable|TestEarlierChoices|TestUnreadableManifest' 覆盖记录、顶替与旧状态;./internal/workbench -run TestInstallingAPluginTurnsOffTheOneServingTheSameLanguage 覆盖从磁盘安装第二个插件后停用第一个、提示文案,以及再启用第一个时反向停用。", + "verification": "Viva:从插件市场安装一个带语言服务器的社区插件,在审查框确认后插件立即显示“已启用”,打开对应文件即启动语言服务器;先禁用再安装新版本,确认仍为禁用;卸载后重新安装,确认又是启用。卸载时确认先停止语言服务器和插件后端,再删除插件包和 `<插件根>/.state/<插件 ID>`(含插件写入的缓存与下载物等),其他插件的状态和 `.state/host-secret` 保留;卸载后再触发跳转不会打开定义,也不会重新拉起进程。禁用插件时同样停止它的后端。 macOS 全新安装时打开插件页,确认“已安装”标签不再显示未安装插件的占位项(改由“插件市场”标签提供安装),齿轮菜单可“从磁盘安装插件”选择已签名的插件包;社区插件在“已安装”中显示来源仓库与社区维护提示,可卸载;安装后可搜索并启用、禁用该插件,确认状态与重启恢复,且页面不显示无恢复路径的卸载操作;同时打开一个插件提供的工具窗口确认插件内容不被遮挡。Windows 检查扩展管理入口和持久化。契约 v1 插件在设置的独立“声明式插件”页管理(启用/停用/卸载/回滚,与 Worker 扩展分开列出,隔离原因直接展示),管理命令走 plugin_host 的 Tauri 命令。 Windows 缺少 Bun 或语言服务器时更新扩展,确认旧扩展的安装、启用和待更新状态保留,错误给出安装依赖后重试的提示;预检期间禁用或卸载扩展,确认返回后不会继续安装或重新启用;手动将 Marksman 等语言服务器安装到 PATH 后重启,确认能识别并启用。 Windows 契约插件:同时在两个产品窗口启动语言服务/运行任务,在启动尚未返回时分别禁用、卸载、更新和回滚;确认先撤销入口、等待两窗口所有进程和原生探测退出,再改包目录。停止失败、窗口断开或确认超时发生在改包前,文件保留且插件继续阻断;改包后重新扫描失败也必须报错并保持阻断,不能使用旧目录缓存;重试可恢复,不能出现占用可执行文件导致的半删除。 不同插件并发管理时,全盘扫描必须从读取到提交缓存串行,最终缓存包含所有已经成功安装的包;检查 tests.rs 的有序发布回归。 同一语言只由一个已启用插件提供语言服务器:先启用为某语言声明语言服务器的插件 A 并打开该语言的文件,再启用(或安装)为同一语言声明语言服务器的插件 B,确认 A 变为禁用、其语言服务器与后端退出、出现“已停用「A」:「B」也提供该语言的语言服务器”提示,已打开的文件改由 B 的服务器同步;再启用 A 时反向成立。两个插件在规则之前都被启用时,只有按 ID 排在前面的一个运行;停用它后另一个接手。scripts/desktop/desktop-go.sh test ./internal/pluginmanager -run 'TestEnable|TestEarlierChoices|TestUnreadableManifest' 覆盖记录、顶替与旧状态;./internal/workbench -run TestInstallingAPluginTurnsOffTheOneServingTheSameLanguage 覆盖从磁盘安装第二个插件后停用第一个、提示文案,以及再启用第一个时反向停用。 桌面宿主状态目录路径回归:scripts/desktop/desktop-go.sh test ./internal/pluginpkg -run '^TestStateRootsFollowRemovalLayout$' -count=1,断言插件与版本目录路径保持兼容并可由 RemoveState 清理;此项仅为代码测试,不代替 macOS/Windows 的原生插件卸载验收。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { From f3b99f4efad55d409aee06a0557fcc0d0af04369 Mon Sep 17 00:00:00 2001 From: "lithe-support[bot]" <356900028+lithe-support[bot]@users.noreply.github.com> Date: Sun, 15 Nov 2026 11:41:24 +0000 Subject: [PATCH 3/3] fix(test): update remaining plugin state directory references (#1841) --- desktop/internal/pluginservice/hostmethods_test.go | 5 +++-- desktop/internal/pluginservice/lifecycle_test.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/desktop/internal/pluginservice/hostmethods_test.go b/desktop/internal/pluginservice/hostmethods_test.go index 91bdcdfb8d..eb81773b9c 100644 --- a/desktop/internal/pluginservice/hostmethods_test.go +++ b/desktop/internal/pluginservice/hostmethods_test.go @@ -14,6 +14,7 @@ import ( "github.com/1lck/Lithe-IDEA/desktop/internal/credentials" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginbackend" "github.com/1lck/Lithe-IDEA/desktop/internal/pluginhost" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginpkg" "github.com/1lck/Lithe-IDEA/desktop/internal/store" "github.com/1lck/Lithe-IDEA/desktop/internal/winpath" ) @@ -75,7 +76,7 @@ func TestWorkspaceContextsAreScopedToTheCallingPlugin(t *testing.T) { if listed.Contexts[0].StateDirectory != "" { t.Fatal("listing contexts created or revealed a state directory") } - if entries, _ := os.ReadDir(filepath.Join(service.Root, pluginStateDirectory, "a")); len(entries) != 0 { + if entries, _ := os.ReadDir(pluginpkg.StateRoot(service.Root, "a")); len(entries) != 0 { t.Fatalf("listing left directories behind: %v", entries) } rootA := listed.Contexts[0].Folders[0].RootID @@ -94,7 +95,7 @@ func TestWorkspaceContextsAreScopedToTheCallingPlugin(t *testing.T) { StateDirectory string `json:"stateDirectory"` } _ = json.Unmarshal(result, &detailed) - pluginRoot := filepath.Join(service.Root, pluginStateDirectory) + string(filepath.Separator) + pluginRoot := filepath.Join(service.Root, pluginpkg.StateDirectory) + string(filepath.Separator) if !strings.HasPrefix(detailed.StateDirectory, pluginRoot) { t.Fatalf("state directory %q is outside the plugin storage %q", detailed.StateDirectory, pluginRoot) } diff --git a/desktop/internal/pluginservice/lifecycle_test.go b/desktop/internal/pluginservice/lifecycle_test.go index 9a24381944..b90dc55ada 100644 --- a/desktop/internal/pluginservice/lifecycle_test.go +++ b/desktop/internal/pluginservice/lifecycle_test.go @@ -53,7 +53,7 @@ func runningBackend(service *Service, id string, stopped func()) *BackendSession // the backend cannot write the state again; another plugin's backend runs on. func TestUninstallStopsTheBackendBeforeRemovingThePlugin(t *testing.T) { service, root := lifecycleService(t) - state := filepath.Join(root, pluginStateDirectory, "example", "1.0.0", "cache") + state := filepath.Join(pluginpkg.VersionStateRoot(root, "example", "1.0.0"), "cache") if err := os.MkdirAll(state, 0o700); err != nil { t.Fatal(err) } @@ -76,7 +76,7 @@ func TestUninstallStopsTheBackendBeforeRemovingThePlugin(t *testing.T) { if service.Host.Running("other") == nil { t.Fatal("the other plugin's backend stopped") } - if _, err := os.Stat(filepath.Join(root, pluginStateDirectory, "example")); !errors.Is(err, os.ErrNotExist) { + if _, err := os.Stat(pluginpkg.StateRoot(root, "example")); !errors.Is(err, os.ErrNotExist) { t.Fatalf("the state survived: %v", err) } }