diff --git a/desktop/internal/i18n/shared.generated.go b/desktop/internal/i18n/shared.generated.go index b12c1fb2a..6e87fcb85 100644 --- a/desktop/internal/i18n/shared.generated.go +++ b/desktop/internal/i18n/shared.generated.go @@ -2897,6 +2897,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.toolchains.description": "Tools declared by enabled plugins. The effective value and its source come from the shared Core resolver; nothing is written until Save.", "desktop.toolchains.directory": "Installation directory", "desktop.toolchains.directoryHelp": "Choose the installation root containing the tool executable, such as a JDK directory rather than its bin folder. Checking the version only updates the draft; Save writes the project selection.", + "desktop.toolchains.discoveryIncomplete": "Some enabled plugins could not be read. The tool list may be incomplete; check the logs and reload after fixing them.", "desktop.toolchains.effective": "Effective: {value}", "desktop.toolchains.global": "Global defaults", "desktop.toolchains.globalHelp": "Manage detected and manually added SDKs for all projects. Save writes to the application’s user settings; projects can override the default. Existing processes use the new SDK after restarting.", @@ -6883,6 +6884,7 @@ var sharedCatalogs = map[string]map[string]string{ "desktop.toolchains.description": "已启用插件声明的工具。生效值与来源由共享 Core 解析得出;点击保存前不会写入任何文件。", "desktop.toolchains.directory": "安装目录", "desktop.toolchains.directoryHelp": "选择包含工具程序的安装根目录,例如 JDK 目录,而不是 bin 目录。验证版本只修改草稿;点击保存后才写入项目选择。", + "desktop.toolchains.discoveryIncomplete": "部分已启用插件的配置无法读取,工具列表可能不完整。请查看日志,修复后重新加载。", "desktop.toolchains.effective": "生效:{value}", "desktop.toolchains.global": "全局默认", "desktop.toolchains.globalHelp": "统一管理自动识别和手动添加的 SDK,保存到应用的用户设置。项目可单独覆盖默认版本;已启动的进程需重启后使用新版本。", diff --git a/desktop/internal/pluginservice/toolchains_partial_test.go b/desktop/internal/pluginservice/toolchains_partial_test.go new file mode 100644 index 000000000..2ce4c228d --- /dev/null +++ b/desktop/internal/pluginservice/toolchains_partial_test.go @@ -0,0 +1,82 @@ +package pluginservice + +import ( + "context" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginmanager" + "github.com/1lck/Lithe-IDEA/desktop/internal/pluginpkg" +) + +// Real Core version selection must reject ambiguous/invalid installed facts +// without letting a bad version mask a healthy enabled plugin. +func TestToolchainPluginsKeepValidVersionsAndReportRejectedFacts(t *testing.T) { + root := t.TempDir() + entry := func(id, version string, valid bool) pluginmanager.Entry { + t.Helper() + dir := filepath.Join(root, id, version) + if valid { + if err := os.MkdirAll(dir, 0o700); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(dir, pluginpkg.ManifestFile), []byte(`{"id":"`+id+`"}`), 0o600); err != nil { + t.Fatal(err) + } + } + return pluginmanager.Entry{ + Installed: pluginpkg.Installed{ID: id, Version: version, Path: dir}, + Enabled: true, + } + } + healthy := entry("dev.lithe.test.healthy", "1.0.0", true) + first := entry("dev.lithe.test.duplicate", "2.0.0", true) + duplicate := first + duplicate.Installed.Path = filepath.Join(root, "unreadable-duplicate") + broken := entry("dev.lithe.test.invalid", "not-semver", false) + + for _, tc := range []struct { + name, wantCode string + entries []pluginmanager.Entry + wantIDs []string + }{ + { + name: "same version rejected without replacing the first", + wantCode: "plugin.installed.duplicateVersion", + entries: []pluginmanager.Entry{first, duplicate, healthy}, + wantIDs: []string{first.Installed.ID, healthy.Installed.ID}, + }, + { + name: "invalid version leaves healthy tools", + wantCode: "plugin.installed.invalidVersion", + entries: []pluginmanager.Entry{broken, healthy}, + wantIDs: []string{healthy.Installed.ID}, + }, + } { + t.Run(tc.name, func(t *testing.T) { + service := &Service{kernel: core.NewClient()} + plugins, err := service.ToolchainPlugins(context.Background(), tc.entries) + if err == nil || !strings.Contains(err.Error(), tc.wantCode) { + t.Fatalf("expected %s alongside usable plugins, got %v", tc.wantCode, err) + } + found := make(map[string]bool) + for _, plugin := range plugins { + found[plugin.PluginID] = true + if plugin.PluginID == first.Installed.ID && plugin.Directory != first.Installed.Path { + t.Fatalf("duplicate took precedence: %s", plugin.Directory) + } + } + if len(found) != len(tc.wantIDs) { + t.Fatalf("valid plugin count %d, want %d: %+v", len(found), len(tc.wantIDs), plugins) + } + for _, id := range tc.wantIDs { + if !found[id] { + t.Fatalf("valid plugin %q was lost after rejecting another version", id) + } + } + }) + } +} diff --git a/desktop/internal/settingswindow/toolchains_view.go b/desktop/internal/settingswindow/toolchains_view.go index cbb3f6733..08b078e17 100644 --- a/desktop/internal/settingswindow/toolchains_view.go +++ b/desktop/internal/settingswindow/toolchains_view.go @@ -249,7 +249,7 @@ func (w *window) toolchainsNotices(c ui.C, language i18n.Language, scope *toolch case t.inspecting: busy = i18n.Shared(language, "desktop.toolchains.loading") } - if !banner && scope.failed == nil && t.failed == nil && t.view.failed == nil && busy == "" { + if !banner && !scope.snapshot.DiscoveryIncomplete && scope.failed == nil && t.failed == nil && t.view.failed == nil && busy == "" { return } ui.Column(c).FillWidth().Shrink(0).PadSides(8, 14, 0, 14).Gap(8).Children(func() { @@ -267,6 +267,15 @@ func (w *window) toolchainsNotices(c ui.C, language i18n.Language, scope *toolch } }) } + if scope.loaded && scope.snapshot.DiscoveryIncomplete { + w.box(c.Part("discovery-incomplete"), boxWarn, func(words gfx.Color) { + boxIcon(c, icons.CircleAlert, words) + boxText(c, i18n.Shared(language, "desktop.toolchains.discoveryIncomplete"), words) + if w.button(c.Part("discovery-reload"), buttonSmall, i18n.Shared(language, "desktop.toolchains.reload"), t.busy()) { + t.reload() + } + }) + } if scope.failed != nil { message := toolchainFailureMessage(language, scope.failed) w.box(c.Part("load-failed"), boxErr, func(words gfx.Color) { diff --git a/desktop/internal/settingswindow/toolchains_view_test.go b/desktop/internal/settingswindow/toolchains_view_test.go index de46d44ef..8243df596 100644 --- a/desktop/internal/settingswindow/toolchains_view_test.go +++ b/desktop/internal/settingswindow/toolchains_view_test.go @@ -115,6 +115,36 @@ func (d *windowDriver) applyBuild() { d.pump() } +// An unreadable enabled plugin must not make the remaining valid tools look +// like a complete catalog. The same warning is visible in both scopes. +func TestToolchainsShowPartialDiscoveryWarningInBothScopes(t *testing.T) { + for _, scope := range []string{scopeGlobal, scopeProject} { + t.Run(scope, func(t *testing.T) { + fixture := fixtureSnapshot() + fixture.DiscoveryIncomplete = true + loader := &scopedToolchainLoader{fakeToolchainLoader{snapshot: fixture}} + w, d := toolchainWindow(t, loader) + if scope == scopeProject { + w.toolchains.setScope(scopeProject) + w.inv.Invalidate() + d.until("the project scope", func() bool { + return w.toolchains.current().loaded && w.toolchains.scope == scopeProject + }) + d.pump() + } + if !d.has(en("desktop.toolchains.discoveryIncomplete")) { + t.Fatal("partial tool discovery is not visible to the user") + } + if !d.text("Compiler") { + t.Fatal("the readable tool was hidden by another plugin's missing manifest") + } + if !d.has(en("desktop.toolchains.reload")) { + t.Fatal("no way to reload after repairing the unreadable plugin") + } + }) + } +} + // The chosen tool lists what it falls back to, each installation once and the link that opens // the directory field, which stays closed until it is asked for and writes no draft. func TestToolchainChoicesListAutomaticAndOpenTheDirectoryOnDemand(t *testing.T) { diff --git a/desktop/internal/toolchain/toolchain.go b/desktop/internal/toolchain/toolchain.go index 59126e02e..1d31c6a51 100644 --- a/desktop/internal/toolchain/toolchain.go +++ b/desktop/internal/toolchain/toolchain.go @@ -105,11 +105,14 @@ type Tool struct { type Snapshot struct { Global bool `json:"global,omitempty"` ProjectCodeAllowed bool `json:"projectCodeAllowed,omitempty"` - catalog *catalogSource - Root string `json:"root"` - Directory string `json:"directory"` - Tools []Tool `json:"tools"` - Conflicts []core.ToolchainConflict `json:"conflicts"` + // DiscoveryIncomplete reports that another enabled plugin could not be + // read; usable tools remain available but this is not a complete catalog. + DiscoveryIncomplete bool `json:"discoveryIncomplete,omitempty"` + catalog *catalogSource + Root string `json:"root"` + Directory string `json:"directory"` + Tools []Tool `json:"tools"` + Conflicts []core.ToolchainConflict `json:"conflicts"` // Baseline is the exact bytes of .lithe/toolchains/local.json that the // snapshot was built from, nil when the file did not exist. Baseline []byte `json:"-"` diff --git a/desktop/internal/workbench/command_installers.go b/desktop/internal/workbench/command_installers.go index 69f9047d0..c9fabadcb 100644 --- a/desktop/internal/workbench/command_installers.go +++ b/desktop/internal/workbench/command_installers.go @@ -172,7 +172,7 @@ func commandConsumerCapability(kind string) string { // toolNames are the display names of the enabled plugins' tool definitions by ID; nil when // the registry cannot be read, which shows the IDs. func (s settingsCommandInstalls) toolNames(ctx context.Context) map[string]string { - manifests, _ := s.app.toolchainManifests(ctx) + manifests, _, _ := s.app.usableToolchainManifests(ctx, "command_installer_tool_discovery") if len(manifests) == 0 { return nil } diff --git a/desktop/internal/workbench/debug_launch.go b/desktop/internal/workbench/debug_launch.go index 89d9ccb21..2f2174628 100644 --- a/desktop/internal/workbench/debug_launch.go +++ b/desktop/internal/workbench/debug_launch.go @@ -71,7 +71,7 @@ func (a *App) resolveAdapterProcess(ctx context.Context, adapter debugAdapter, p if _, err := pluginhost.ResolvePackagePaths(adapter.Directory, plan.RequiredPackagePaths); err != nil { return "", nil, nil, err } - manifests, err := a.toolchainManifests(ctx) + manifests, _, err := a.usableToolchainManifests(ctx, "toolchain_debug_discovery") if err != nil { return "", nil, nil, err } @@ -86,7 +86,7 @@ func (a *App) resolveAdapterProcess(ctx context.Context, adapter debugAdapter, p return "", nil, nil, err } } else { - selected, err = a.resolveToolchainSelection(ctx, root, ".", plan.Launch.Tool, plan.Launch.MinimumVersion) + selected, err = a.resolveToolchainSelectionFrom(ctx, root, ".", plan.Launch.Tool, plan.Launch.MinimumVersion, manifests) if err != nil { return "", nil, nil, err } diff --git a/desktop/internal/workbench/new_project.go b/desktop/internal/workbench/new_project.go index ad6631770..a223836b7 100644 --- a/desktop/internal/workbench/new_project.go +++ b/desktop/internal/workbench/new_project.go @@ -319,8 +319,8 @@ func (a *App) loadProjectTools(ctx context.Context, tools []string) (map[string] if a.projectToolLists != nil { return a.projectToolLists(ctx, tools) } - manifests, err := a.toolchainManifests(ctx) - if err != nil && len(manifests) == 0 { + manifests, _, err := a.usableToolchainManifests(ctx, "new_project_toolchain_discovery") + if err != nil { return nil, err } options := a.toolchainOptions(ctx, "", manifests) diff --git a/desktop/internal/workbench/runs.go b/desktop/internal/workbench/runs.go index f361d4aa1..d00ce17c2 100644 --- a/desktop/internal/workbench/runs.go +++ b/desktop/internal/workbench/runs.go @@ -173,18 +173,19 @@ func (a *App) resolveBackendTool(ctx context.Context, _, workingDirectory, tool // resolveBackendToolEntry supplies native installation facts and the verified // entry to Core. The definition, not the host, decides how a tool loads it. func (a *App) resolveBackendToolEntry(ctx context.Context, _ string, workingDirectory string, input pluginbackend.ToolEntryLaunch) (pluginbackend.ToolExecutable, error) { + // Share one validated manifest snapshot between the selected executable + // and Core's launch template, including when one unrelated plugin is unreadable. + manifests, _, err := a.usableToolchainManifests(ctx, "toolchain_run_entry_discovery") + if err != nil { + return pluginbackend.ToolExecutable{}, err + } selection := core.ToolchainSelection{Executable: input.Executable} if selection.Executable == "" { - var err error - selection, err = a.resolveToolchainSelection(ctx, workingDirectory, ".", input.Tool, input.MinimumVersion) + selection, err = a.resolveToolchainSelectionFrom(ctx, workingDirectory, ".", input.Tool, input.MinimumVersion, manifests) if err != nil { return pluginbackend.ToolExecutable{}, err } } - manifests, err := a.toolchainManifests(ctx) - if err != nil { - return pluginbackend.ToolExecutable{}, err - } registry, err := toolchain.RegistryInput(manifests) if err != nil { return pluginbackend.ToolExecutable{}, err diff --git a/desktop/internal/workbench/settings_toolchains.go b/desktop/internal/workbench/settings_toolchains.go index 2c512ed1f..ba155a4b6 100644 --- a/desktop/internal/workbench/settings_toolchains.go +++ b/desktop/internal/workbench/settings_toolchains.go @@ -16,7 +16,7 @@ func (s settingsToolchains) Inspect(ctx context.Context, snapshot toolchain.Snap ctx = s.app.performedIn(ctx, "toolchain.inspectDirectory", surfaceButton) defer func() { s.recordFailure(ctx, "toolchain_settings_inspect", err) }() if snapshot.Global { - manifests, readErr := s.app.toolchainManifests(ctx) + manifests, _, readErr := s.app.usableToolchainManifests(ctx, "toolchain_settings_discovery") if readErr != nil { return selection, readErr } @@ -29,7 +29,7 @@ func (s settingsToolchains) Inspect(ctx context.Context, snapshot toolchain.Snap if err := snapshot.CheckWorkspace(ctx, *root); err != nil { return selection, errors.Join(toolchain.ErrPinConflict, err) } - manifests, err := s.app.toolchainManifests(ctx) + manifests, _, err := s.app.usableToolchainManifests(ctx, "toolchain_settings_discovery") if err != nil { return selection, err } @@ -181,19 +181,23 @@ func (s settingsToolchains) LoadScope(ctx context.Context, scope string) (snapsh return s.Load(ctx) } defer func() { s.recordFailure(ctx, "toolchain_settings_load", err) }() - manifests, err := s.app.toolchainManifests(ctx) + manifests, incomplete, err := s.app.usableToolchainManifests(ctx, "toolchain_settings_discovery") if err != nil { return snapshot, err } - return toolchain.Load(ctx, s.app.kernel, "", ".", manifests, s.app.toolchainOptions(ctx, "", manifests)) + snapshot, err = toolchain.Load(ctx, s.app.kernel, "", ".", manifests, s.app.toolchainOptions(ctx, "", manifests)) + snapshot.DiscoveryIncomplete = incomplete + return snapshot, err } func (s settingsToolchains) loadAt(ctx context.Context, root string) (toolchain.Snapshot, error) { - manifests, err := s.app.toolchainManifests(ctx) - if err != nil && len(manifests) == 0 { + manifests, incomplete, err := s.app.usableToolchainManifests(ctx, "toolchain_settings_discovery") + if err != nil { return toolchain.Snapshot{}, err } - return toolchain.Load(ctx, s.app.kernel, root, ".", manifests, s.app.toolchainOptions(ctx, root, manifests)) + snapshot, err := toolchain.Load(ctx, s.app.kernel, root, ".", manifests, s.app.toolchainOptions(ctx, root, manifests)) + snapshot.DiscoveryIncomplete = incomplete + return snapshot, err } // Save applies all draft changes in one Core edit, against the exact diff --git a/desktop/internal/workbench/settings_toolchains_test.go b/desktop/internal/workbench/settings_toolchains_test.go index 51bff9975..9006a3da8 100644 --- a/desktop/internal/workbench/settings_toolchains_test.go +++ b/desktop/internal/workbench/settings_toolchains_test.go @@ -29,7 +29,7 @@ func (*catalogSourceKernel) ToolchainDiscoveryPlanOf(context.Context, json.RawMe return core.ToolchainDiscoveryPlan{}, nil } -func TestGlobalToolchainsDoNotHideAnUnreadableEnabledPlugin(t *testing.T) { +func TestGlobalToolchainsRetainValidPluginAndReportUnreadableOne(t *testing.T) { preferences, root := store.At(t.TempDir()), t.TempDir() service, err := pluginservice.Open(core.NewClient(), preferences, root) if err != nil { @@ -74,15 +74,89 @@ func TestGlobalToolchainsDoNotHideAnUnreadableEnabledPlugin(t *testing.T) { app := &App{kernel: &catalogSourceKernel{&testKernel{Client: core.NewClient()}}, store: preferences, plugins: service} ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - _, err = (settingsToolchains{app: app}).LoadScope(ctx, "global") - if !errors.Is(err, os.ErrNotExist) { - t.Fatalf("global SDK settings discarded the native read failure: %v", err) + log := &treeRecordingLog{} + app.logSink = log + snapshot, err := (settingsToolchains{app: app}).LoadScope(ctx, "global") + if err != nil { + t.Fatalf("global catalog should retain valid tools: %v", err) + } + if len(snapshot.Tools) == 0 || !snapshot.DiscoveryIncomplete { + t.Fatalf("catalog lost tools or partial warning: %+v", snapshot) + } + log.mu.Lock() + if len(log.events) != 1 || log.events[0].Fields["operation"] != "toolchain_settings_discovery" { + t.Errorf("partial global catalog recorded events %+v", log.events) } + log.mu.Unlock() if _, err := os.Stat(filepath.Join(preferences.Dir(), "toolchains", "global.json")); !errors.Is(err, os.ErrNotExist) { t.Fatalf("a failed read wrote a global catalog: %v", err) } } +// A readable plugin remains in project settings when another plugin's +// manifest disappeared. The partial failure must be logged once at the +// boundary instead of silently turning into a complete-looking tool list. +func TestProjectToolchainPartialManifestReadReportsDegradation(t *testing.T) { + preferences, pluginRoot, projectRoot := store.At(t.TempDir()), t.TempDir(), t.TempDir() + service, err := pluginservice.Open(core.NewClient(), preferences, pluginRoot) + if err != nil { + t.Fatal(err) + } + for _, id := range []string{"dev.example.catalog-readable", "dev.example.catalog-unreadable"} { + staging, err := pluginpkg.NewStaging(pluginRoot) + if err != nil { + t.Fatal(err) + } + fixture, err := os.ReadFile("../toolchain/testdata/compiler.plugin.json") + if err != nil { + t.Fatal(err) + } + var document map[string]any + if err := json.Unmarshal(fixture, &document); err != nil { + t.Fatal(err) + } + document["id"] = id + definition := document["toolDefinitions"].([]any)[0].(map[string]any) + definition["id"] = id + ":compiler" + manifest, err := json.Marshal(document) + if err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(staging, pluginpkg.ManifestFile), manifest, 0o600); err != nil { + t.Fatal(err) + } + installed, err := pluginpkg.Install(pluginRoot, id, "1.0.0", staging) + if err != nil { + t.Fatal(err) + } + if err := pluginstate.New(preferences).SetEnabled(id, true); err != nil { + t.Fatal(err) + } + if id == "dev.example.catalog-unreadable" { + if err := os.Remove(filepath.Join(installed.Path, pluginpkg.ManifestFile)); err != nil { + t.Fatal(err) + } + } + } + log := &treeRecordingLog{} + app := &App{kernel: &catalogSourceKernel{&testKernel{Client: core.NewClient()}}, store: preferences, plugins: service, logSink: log} + app.toolchainRoot.Store(&projectRoot) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + snapshot, err := (settingsToolchains{app: app}).Load(ctx) + if err != nil { + t.Fatalf("readable manifests should still load project settings: %v", err) + } + if len(snapshot.Tools) == 0 || !snapshot.DiscoveryIncomplete { + t.Fatal("the readable plugin was lost or incomplete status was not reported") + } + log.mu.Lock() + defer log.mu.Unlock() + if len(log.events) != 1 || log.events[0].Fields["operation"] != "toolchain_settings_discovery" { + t.Fatalf("missing one degradation event: %+v", log.events) + } +} + func TestToolchainSettingsRejectSaveForAnotherOrClosedProject(t *testing.T) { for _, closed := range []bool{false, true} { name := "another-project" diff --git a/desktop/internal/workbench/toolchains.go b/desktop/internal/workbench/toolchains.go index 35163ae23..4969e6c6f 100644 --- a/desktop/internal/workbench/toolchains.go +++ b/desktop/internal/workbench/toolchains.go @@ -50,6 +50,34 @@ func (a *App) toolchainManifests(ctx context.Context) ([]json.RawMessage, error) return manifests, err } +// usableToolchainManifests is the shared policy for partial plugin reads. A +// missing manifest must not conceal other valid tools; consumers still rely +// on Core to resolve the requested ID. Log the degradation once per discovery. +func (a *App) usableToolchainManifests(ctx context.Context, operation string) ([]json.RawMessage, bool, error) { + manifests, readErr := a.toolchainManifests(ctx) + usable, incomplete, err := partialToolchainCatalog(ctx, manifests, readErr) + if incomplete { + a.backgroundFailedIn(ctx, operation, readErr) + } + return usable, incomplete, err +} + +// partialToolchainCatalog accepts valid manifests from a partially unreadable +// plugin set, but cancellation of the *whole request* is always terminal. +// A nested provider may time out independently without canceling ctx. +func partialToolchainCatalog(ctx context.Context, manifests []json.RawMessage, readErr error) ([]json.RawMessage, bool, error) { + if err := ctx.Err(); err != nil { + return nil, false, err + } + if readErr == nil { + return manifests, false, nil + } + if len(manifests) == 0 { + return nil, false, readErr + } + return manifests, true, nil +} + // resolveToolchainSelection resolves one tool for one operation. A caller may // replace the selector in tests through toolchainResolve. func (a *App) resolveToolchainSelection(ctx context.Context, root, directory, tool, minimumVersion string) (core.ToolchainSelection, error) { @@ -74,10 +102,20 @@ func (a *App) managedToolchainOptions(ctx context.Context, manifests []json.RawM } func (a *App) defaultToolchainSelection(ctx context.Context, root, directory, tool, minimumVersion string) (core.ToolchainSelection, error) { - manifests, err := a.toolchainManifests(ctx) + manifests, _, err := a.usableToolchainManifests(ctx, "toolchain_selection_discovery") if err != nil { return core.ToolchainSelection{}, err } + return a.resolveToolchainSelectionFrom(ctx, root, directory, tool, minimumVersion, manifests) +} + +// resolveToolchainSelectionFrom reuses a catalog read by a run or debugger. +// Looking it up a second time could report the same partial-manifest failure twice, +// or select a different plugin version between resolving and launching a tool. +func (a *App) resolveToolchainSelectionFrom(ctx context.Context, root, directory, tool, minimumVersion string, manifests []json.RawMessage) (core.ToolchainSelection, error) { + if a.toolchainResolve != nil { + return a.toolchainResolve(ctx, root, directory, tool, minimumVersion) + } if directory == "" { directory = "." } diff --git a/desktop/internal/workbench/toolchains_test.go b/desktop/internal/workbench/toolchains_test.go index d83e2197e..c5f263a2d 100644 --- a/desktop/internal/workbench/toolchains_test.go +++ b/desktop/internal/workbench/toolchains_test.go @@ -190,3 +190,35 @@ func TestBuildRuntimeRefusesAnInvalidPinBeforeFallback(t *testing.T) { t.Fatalf("invalid pin fell through to another installation: %v", err) } } + +func TestPartialToolchainCatalogRejectsCancellationAndKeepsValidPlugins(t *testing.T) { + valid := []json.RawMessage{json.RawMessage(`{"id":"dev.example.valid"}`)} + broken := errors.New("another enabled plugin manifest is unreadable") + for _, tc := range []struct { + name string + manifests []json.RawMessage + err error + cancel bool + wantCount int + wantIncomplete bool + wantErr error + }{ + {name: "complete", manifests: valid, wantCount: 1}, + {name: "partial", manifests: valid, err: broken, wantCount: 1, wantIncomplete: true}, + {name: "all missing", err: broken, wantErr: broken}, + {name: "canceled partial", manifests: valid, err: broken, cancel: true, wantErr: context.Canceled}, + {name: "canceled complete", manifests: valid, cancel: true, wantErr: context.Canceled}, + } { + t.Run(tc.name, func(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + if tc.cancel { + cancel() + } + manifests, incomplete, err := partialToolchainCatalog(ctx, tc.manifests, tc.err) + if len(manifests) != tc.wantCount || incomplete != tc.wantIncomplete || !errors.Is(err, tc.wantErr) { + t.Fatalf("manifests=%d incomplete=%v err=%v, want %d %v %v", len(manifests), incomplete, err, tc.wantCount, tc.wantIncomplete, tc.wantErr) + } + }) + } +} diff --git a/shared/i18n/features/build-settings.json b/shared/i18n/features/build-settings.json index f474f6eb4..bab524f67 100644 --- a/shared/i18n/features/build-settings.json +++ b/shared/i18n/features/build-settings.json @@ -1077,6 +1077,13 @@ "parameters": { "count": "string" } + }, + { + "id": "desktop.toolchains.discoveryIncomplete", + "description": "Warning when an enabled plugin manifest is unreadable but other tools remain available.", + "platforms": [ + "desktop" + ] } ], "locales": { @@ -1215,7 +1222,8 @@ "desktop.buildSettings.searchTools": "Tools in Toolchains", "desktop.buildSettings.searchDebuggers": "Debuggers", "desktop.buildSettings.steppingTab": "Debuggers › Stepping", - "desktop.buildSettings.searchAllTools": "View all {count} in Toolchains…" + "desktop.buildSettings.searchAllTools": "View all {count} in Toolchains…", + "desktop.toolchains.discoveryIncomplete": "Some enabled plugins could not be read. The tool list may be incomplete; check the logs and reload after fixing them." }, "zh-CN": { "desktop.buildSettings.directoryNote": "这一页只列子页和状态摘要,不直接展示插件注入的内容。", @@ -1352,7 +1360,8 @@ "desktop.buildSettings.searchTools": "工具链中的工具", "desktop.buildSettings.searchDebuggers": "调试器", "desktop.buildSettings.steppingTab": "调试器 › 单步", - "desktop.buildSettings.searchAllTools": "在工具链中查看全部 {count} 个…" + "desktop.buildSettings.searchAllTools": "在工具链中查看全部 {count} 个…", + "desktop.toolchains.discoveryIncomplete": "部分已启用插件的配置无法读取,工具列表可能不完整。请查看日志,修复后重新加载。" } } } diff --git a/shared/platform-feature-matrix/features/plugin-toolchain-providers.json b/shared/platform-feature-matrix/features/plugin-toolchain-providers.json index 613802649..f7114b309 100644 --- a/shared/platform-feature-matrix/features/plugin-toolchain-providers.json +++ b/shared/platform-feature-matrix/features/plugin-toolchain-providers.json @@ -11,7 +11,8 @@ "desktop/internal/pluginservice/toolchain_provider_test.go", "desktop/internal/toolchain/provider.go", "desktop/internal/toolchain/provider_observation.go", - "desktop/internal/workbench/settings_toolchains.go" + "desktop/internal/workbench/settings_toolchains.go", + "desktop/internal/workbench/settings_toolchains_test.go" ] }, "windows": { @@ -23,10 +24,11 @@ "desktop/internal/toolchain/provider.go", "desktop/internal/toolchain/provider_observation.go", "desktop/internal/toolchain/native_path_windows.go", - "desktop/internal/workbench/settings_toolchains.go" + "desktop/internal/workbench/settings_toolchains.go", + "desktop/internal/workbench/settings_toolchains_test.go" ] }, "owner": "Plugins", - "verification": "使用 TestToolchainProviderQueriesThroughSharedBackendAndReobservesSources 核对合成插件协商、安装与项目版本要求、生效层、全局发现、源文件变化、复用和关闭清理。使用 TestToolchainProviderCancellationDoesNotCompleteTheNextQuery 核对取消与迟到回复。使用 TestToolchainProviderQueriesTheInstalledVersionAfterUpgrade 核对升级后的版本和路径,使用 TestNewProjectOnlyDiscoversToolsRequestedByTheForm 核对表单工具范围。原生设置工作流还需核对打开项目、改写版本要求、重新加载和关闭窗口。", - "notes": "Core 从提供方回包与本机文件事实得出候选和有效安装。桌面按选定清单版本启动共享后端,并为短期缓存观察输入变化。查询期限耗尽时保留已完成的答复和本机候选,由 TestToolchainProviderRoundPreservesAnswersAtItsDeadline 覆盖。安装与工作区目录沿用原有信任检查。" + "verification": "使用 TestToolchainProviderQueriesThroughSharedBackendAndReobservesSources 核对合成插件协商、安装与项目版本要求、生效层、全局发现、源文件变化、复用和关闭清理。使用 TestToolchainProviderCancellationDoesNotCompleteTheNextQuery 核对取消与迟到回复。使用 TestToolchainProviderQueriesTheInstalledVersionAfterUpgrade 核对升级后的版本和路径,使用 TestNewProjectOnlyDiscoversToolsRequestedByTheForm 核对表单工具范围。原生设置工作流还需核对打开项目、改写版本要求、重新加载和关闭窗口。 #1986:TestProjectToolchainPartialManifestReadReportsDegradation 使用两个合成插件(一项清单缺失)要求保留可读工具并只记录一次降级事件;完整 Go 1.27 测试、macOS/Windows 原生设置提示待验证。", + "notes": "Core 从提供方回包与本机文件事实得出候选和有效安装。桌面按选定清单版本启动共享后端,并为短期缓存观察输入变化。查询期限耗尽时保留已完成的答复和本机候选,由 TestToolchainProviderRoundPreservesAnswersAtItsDeadline 覆盖。安装与工作区目录沿用原有信任检查。 #1986 第一阶段:项目工具链页遇到部分启用插件清单无法读取,仍显示可用工具,但会用 toolchain_settings_discovery 记一次错误,不再把部分发现当成完整成功;设置页显式遗漏提示与执行消费者策略仍待统一。" }