Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions desktop/internal/i18n/shared.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions desktop/internal/pluginservice/toolchains_partial_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
})
}
}
11 changes: 10 additions & 1 deletion desktop/internal/settingswindow/toolchains_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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) {
Expand Down
30 changes: 30 additions & 0 deletions desktop/internal/settingswindow/toolchains_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 8 additions & 5 deletions desktop/internal/toolchain/toolchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"-"`
Expand Down
2 changes: 1 addition & 1 deletion desktop/internal/workbench/command_installers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions desktop/internal/workbench/debug_launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions desktop/internal/workbench/new_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions desktop/internal/workbench/runs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 11 additions & 7 deletions desktop/internal/workbench/settings_toolchains.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
82 changes: 78 additions & 4 deletions desktop/internal/workbench/settings_toolchains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down
Loading
Loading