Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,27 @@ Viva 桌面端现在把插件声明的工具链接进了设置和构建执行:

`desktop/internal/workbench/toolchains.go` 把启用插件清单交给 Core,Build 的 `toolchain` 候选按 Core 顺序解析;解析结果直接进入进程启动,导出变量只补消费者未显式设置的值,PATH 前置来自声明的 `pathPrepend`。Provider Run 的 `launch.executable.kind == "toolchain"` 走同一入口。设置页的检测值从不用作启动许可。

### Windows 回归测试覆盖用户目录和 shell 来源

Windows 的工具发现和构建模型测试要保留两条真实本机边界:从 PATH(命令搜索目录)或环境变量找到可执行文件并读取版本,以及通过 `.cmd` 批处理脚本启动工具并解码模型。只注入查找结果或版本输出,无法检查 Windows 的路径和进程启动规则。

`path_windows_test.go` 把合成运行时放在含空格的安装目录,分别通过 PATH 和合成工具自己的环境变量提供;`HOME`、`USERPROFILE` 指向含空格或中文的临时用户目录,不依赖本机装了什么工具。查找、版本进程和 Core 候选规则均走生产入口,只把全局配置根放进测试私有目录。

`build_command_windows_test.go` 用现有工作台测试驱动打开同类临时项目,从 PATH 找到 `.cmd`,让脚本将带空格和中文的参数传给合成构建工具,再通过生产命令模型入口解码结果并检查终态记录。脚本从 Unicode 环境读取工具路径,不依赖机器当前的控制台代码页。

正确做法是用合成清单和测试可执行文件走这些边界。不要读取某个真实插件的包,也不要因本机没装某个工具就跳过用例。

临时程序只链接或复制当前测试可执行文件,始终只读;进程由有截止时间的生产启动器回收,临时目录由 Go 测试清理。工作台驱动沿用项目关闭和后台任务清理。测试不改真实用户配置,也不创建可跨工作树复用的资源。现有 Windows CI 的 `check.sh` 已运行这些包,无需增加第二个 Windows 构建作业。

打包平台的通用覆盖诊断由 Core 提供,契约和检查命令只在 [Core 工具链契约](https://github.com/Lithe-IDEA/Lithe-core-rust/blob/main/shared/plugins/contract/v1/toolchains/README.md) 维护;宿主不复制校验逻辑,也不为某个插件补专属扫描规则。这项静态诊断不替代插件仓库自己的真实工具验收。

## 考虑过的备选方案

- **在 Go 里扫描目录并维护 Maven/JDK 优先规则。** 能最快让界面有内容,但会重造 Core 已校验的四层选择和工具知识,第二个工具就要再改宿主,因此不采用。
- **只做设置页,不接 Build。** 页面可展示但用户仍无法使用所选路径;无法验证“探测结果与启动目标一致”,因此先接执行。
- **声明 `toolchainProviders` 后再补查询。** 会让市场允许带后端的工具链插件安装,但本客户端无法发 `toolchains/query`,首次使用才失败;所以本批不声明该能力。
- **用文件监听做实时刷新。** 会新增常驻监听和失效规则;本批在打开页面和显式 Reload 时读取,避免未验收的 watcher 生命周期。
- **在宿主 CI 下载真实插件和工具做 Windows 回归。** 会引入具体插件依赖、网络与安装布局,不能稳定控制失败形态;宿主只测试合成工具的通用流程,真实工具在插件仓库验收。

## 后果

Expand All @@ -83,12 +98,15 @@ node scripts/i18n/generate-i18n.mjs --check

`settings_toolchains_test.go` 的三个行为回归在修复前失败:切换项目写入错误来源、关闭项目误报成功、保存中切换后的回读来源错误;修复后与设置页冲突草稿保留用例通过逐项计时。

Windows 运行 `./.agents/skills/write-stable-tests/scripts/test-stability-windows.ps1 -Scope DesktopGo -GoPackages ./internal/toolchain,./internal/workbench -GoTestPattern '^(TestToolchainCandidatesUseNativeShellPathsInUserProfiles|TestBuildModelLoadsFromPathOnlyBatchToolInUserProfiles)$'`:检查 PATH/环境变量两种来源、空格/中文两种用户目录、批处理模型和逐项报告。移除 `commandHomes` 传递或恢复普通 Windows 参数引用时,新用例必须失败;恢复修复后通过。此证据只覆盖合成工作流,功能矩阵的完整原生验收状态保持独立。

## 适用范围

- `desktop/internal/core/toolchain.go`
- `desktop/internal/toolchain/`
- `desktop/internal/settingswindow/toolchains_view.go`
- `desktop/internal/workbench/toolchains.go`、`settings_toolchains.go`、`build.go`
- `desktop/internal/toolchain/path_windows_test.go`、`desktop/internal/workbench/build_command_windows_test.go`
- `desktop/internal/pluginservice/toolchains.go`
- `shared/platform-feature-matrix/features/plugin-injected-toolchains.json`

Expand Down
129 changes: 129 additions & 0 deletions desktop/internal/toolchain/path_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
//go:build windows

package toolchain

import (
"context"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
"testing"
"time"

"github.com/1lck/Lithe-IDEA/desktop/internal/core"
)

const nativeToolchainHelper = "LITHE_TEST_NATIVE_TOOLCHAIN"
const nativeToolchainCommand = "lithe-test-vm"

// The copied executable is a synthetic runtime, not an installed tool. Its
// version flags are intentionally not Go testing flags: production probes must
// execute the command they found on PATH without a test-only probe callback.
func TestMain(m *testing.M) {
if os.Getenv(nativeToolchainHelper) == "1" && filepath.Base(os.Args[0]) == nativeToolchainCommand+".exe" {
if len(os.Args) != 2 || os.Args[1] != "-version" {
os.Exit(21)
}
fmt.Println("fictional-vm 8.0.1")
os.Exit(0)
}
os.Exit(m.Run())
}

func copyNativeToolchain(t *testing.T, destination string) {
t.Helper()
// The fixture never writes the executable; link it when possible so the
// native loader can reuse the already validated test binary's identity.
if err := os.Link(os.Args[0], destination); err == nil {
return
}
source, err := os.Open(os.Args[0])
if err != nil {
t.Fatal(err)
}
defer func() {
if err := source.Close(); err != nil {
t.Error(err)
}
}()
target, err := os.Create(destination)
if err != nil {
t.Fatal(err)
}
_, copyErr := io.Copy(target, source)
closeErr := target.Close()
if copyErr != nil {
t.Fatal(copyErr)
}
if closeErr != nil {
t.Fatal(closeErr)
}
}

func TestToolchainCandidatesUseNativeShellPathsInUserProfiles(t *testing.T) {
for _, profileName := range []string{"User With Spaces", "用户 甲"} {
for _, source := range []string{"PATH", "environment"} {
t.Run(profileName+"/"+source, func(t *testing.T) {
profile := filepath.Join(t.TempDir(), profileName)
home := filepath.Join(profile, "Program Files", "Fictional VM")
bin := filepath.Join(home, "bin")
workspace := filepath.Join(profile, "Projects", "sample project")
for _, directory := range []string{bin, workspace} {
if err := os.MkdirAll(directory, 0o755); err != nil {
t.Fatal(err)
}
}
copyNativeToolchain(t, filepath.Join(bin, nativeToolchainCommand+".exe"))
t.Setenv(nativeToolchainHelper, "1")
t.Setenv("HOME", profile)
t.Setenv("USERPROFILE", profile)
// Setenv registers restoration; Unsetenv tests genuine absence.
t.Setenv("LITHE_TEST_VM_HOME", "")
if err := os.Unsetenv("LITHE_TEST_VM_HOME"); err != nil {
t.Fatal(err)
}
if source == "PATH" {
t.Setenv("PATH", bin+string(os.PathListSeparator)+os.Getenv("PATH"))
} else {
t.Setenv("LITHE_TEST_VM_HOME", home)
}
manifest := json.RawMessage(`{
"schemaVersion":0,"id":"dev.lithe.test.native-toolchain","displayName":"Synthetic VM",
"version":"1.0.0","pluginAPIVersion":0,"requires":{"toolDefinitions":0},
"vendor":{"id":"dev.lithe.test","displayName":"Test","signatureRequirement":"publisherPackage"},
"permissions":[],"toolDefinitions":[{
"id":"vm","displayName":"Synthetic VM","executableLayouts":[{"path":"bin/lithe-test-vm.exe"}],
"executables":[
{"id":"shell","kind":"command","command":"lithe-test-vm"},
{"id":"environment","kind":"environment","variable":"LITHE_TEST_VM_HOME","path":"bin/lithe-test-vm.exe"},
{"id":"installed","kind":"toolchain","scope":"installed"}
],
"version":{"arguments":["-version"],"pattern":"fictional-vm (\\d+(?:\\.\\d+)*)"},
"commands":["lithe-test-vm"],"homeVariable":"LITHE_TEST_VM_HOME",
"discovery":[{"root":{"kind":"home"},"pattern":"managed/*"}],
"launch":["${executable}","${arguments}"]
}]
}`)
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
// Home, Environment, Lookup and Probe all use the native defaults.
// The private catalog keeps existing user configuration out of the test.
snapshot, err := Load(ctx, core.NewClient(), workspace, ".", []json.RawMessage{manifest}, Options{
GlobalRoot: filepath.Join(profile, "Lithe data"),
})
if err != nil {
t.Fatal(err)
}
if len(snapshot.Tools) != 1 || len(snapshot.Tools[0].Installations) != 1 {
t.Fatalf("native shell installation missing: %+v", snapshot.Tools)
}
installation := snapshot.Tools[0].Installations[0]
if filepath.Clean(installation.Home) != canonical(t, home) || installation.Version != "8.0.1" || installation.Provider != "host:shell" {
t.Fatalf("installation = %+v, want native %s home %s", installation, source, home)
}
})
}
}
}
8 changes: 7 additions & 1 deletion desktop/internal/workbench/build_command_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ func TestBuildCommandRunner(t *testing.T) {
// buildCommandHarness opens an empty project in a window whose plugin kernel hands the test
// every recorded result, with a private plugin root for the build state.
func buildCommandHarness(t *testing.T) (*harness, *recordingPluginKernel, *project) {
t.Helper()
return buildCommandHarnessAt(t, t.TempDir())
}

// buildCommandHarnessAt also lets native path tests control the project's parent directories.
func buildCommandHarnessAt(t *testing.T, workspace string) (*harness, *recordingPluginKernel, *project) {
t.Helper()
dir := t.TempDir()
if err := os.WriteFile(filepath.Join(dir, settingsFile), []byte(`{"theme":"dark"}`), 0o600); err != nil {
Expand All @@ -115,7 +121,7 @@ func buildCommandHarness(t *testing.T) (*harness, *recordingPluginKernel, *proje
Store: store.At(dir),
Languages: []string{"zh-Hans"},
})
h.open(t.TempDir())
h.open(workspace)
return h, plugins, h.app.project
}

Expand Down
91 changes: 91 additions & 0 deletions desktop/internal/workbench/build_command_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//go:build windows

package workbench

import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"slices"
"strings"
"testing"

"github.com/1lck/Lithe-IDEA/desktop/internal/core"
)

const nativeModelHelper = "LITHE_TEST_NATIVE_MODEL_COMMAND"

// A real .cmd forwards quoted paths to this synthetic build tool. It returns a
// contract model only if both arguments survived cmd.exe and the working
// directory is the project the model belongs to.
func TestWindowsModelCommandHelper(t *testing.T) {
if os.Getenv(nativeModelHelper) != "1" {
return
}
index := slices.Index(os.Args, "--")
root, err := os.Getwd()
if err != nil || index < 0 || len(os.Args[index+1:]) != 2 {
os.Exit(21)
}
arguments := os.Args[index+1:]
if !strings.EqualFold(filepath.Clean(arguments[0]), root) || !strings.EqualFold(filepath.Clean(arguments[1]), filepath.Join(root, "model out.json")) {
os.Exit(22)
}
fmt.Print(`{"format":"litheBuildModel","version":0,"projects":[{"path":".","name":"native-path-model"}]}`)
os.Exit(0)
}

func TestBuildModelLoadsFromPathOnlyBatchToolInUserProfiles(t *testing.T) {
for _, profileName := range []string{"User With Spaces", "用户 甲"} {
t.Run(profileName, func(t *testing.T) {
profile := filepath.Join(t.TempDir(), profileName)
bin := filepath.Join(profile, "Program Files", "Build Tool", "bin")
workspace := filepath.Join(profile, "Projects", "sample project")
for _, directory := range []string{bin, workspace} {
if err := os.MkdirAll(directory, 0o755); err != nil {
t.Fatal(err)
}
}
helper := filepath.Join(bin, "model-helper.exe")
copyTestBinary(t, helper)
// Keep the script ASCII. cmd expands the Unicode helper path from its
// Unicode environment, without depending on the machine's code page.
body := "@echo off\r\n\"%LITHE_TEST_MODEL_HELPER%\" \"-test.run=^TestWindowsModelCommandHelper$\" -- %*\r\nexit /b %ERRORLEVEL%\r\n"
if err := os.WriteFile(filepath.Join(bin, "fixture-build.cmd"), []byte(body), 0o600); err != nil {
t.Fatal(err)
}
t.Setenv(nativeModelHelper, "1")
t.Setenv("LITHE_TEST_MODEL_HELPER", helper)
t.Setenv("HOME", profile)
t.Setenv("USERPROFILE", profile)
t.Setenv("PATHEXT", ".COM;.EXE;.BAT;.CMD")
t.Setenv("PATH", bin+string(os.PathListSeparator)+os.Getenv("PATH"))
h, plugins, p := buildCommandHarnessAt(t, workspace)
instance := buildCommandInstance(".", false)
var manifest map[string]any
if err := json.Unmarshal(instance.Manifest, &manifest); err != nil {
t.Fatal(err)
}
system := manifest["buildSystems"].([]any)[0].(map[string]any)
system["model"].(map[string]any)["arguments"] = []string{p.root, filepath.Join(p.root, "model out.json")}
var err error
instance.Manifest, err = json.Marshal(manifest)
if err != nil {
t.Fatal(err)
}
model, err := h.app.commandModel(buildLoadContext(t, "native-path-model", pluginOperationWait), p, instance, h.app.kernel, nil, h.app.text.Build)
if err != nil {
t.Fatal(err)
}
if len(model.Projects) != 1 || model.Projects[0].Name != "native-path-model" {
t.Fatalf("model = %+v, want the model returned by the batch tool", model)
}
wantPluginOperation(t, plugins.next(t, "batch model decoded"), core.PluginOperation{
PluginID: buildCommandPluginID, Operation: core.OperationBuildModel,
Outcome: "finished", OperationID: "native-path-model",
})
plugins.none(t)
})
}
}
2 changes: 2 additions & 0 deletions docs/ci-builds.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ SDK 的构建输出,以及对当前工作树的 Core 运行的端到端测试
(`node shared/plugins/scripts/sdk-e2e.mjs`)都属于 Core 仓库,
本仓库不构建 SDK,也不复制这些目录。

Windows 工具链和批处理模型的集成测试在 Go `t.TempDir()` 下创建含空格或中文的用户目录、安装目录与项目目录。合成工具只读地硬链接当前测试可执行文件;跨文件系统等情况下回退为复制,脚本与私有工具链配置也只属于该测试。子进程由有界上下文和工作台清理关闭后,Go 删除临时目录。它们不是下载缓存或可封存构建产物,不跨工作树复制或共享,不进入安装包,不改真实用户配置、代码签名或增量更新基线。

全局 SDK 登记 `<platform-preferences>/toolchains/global.json` 属于本机用户设置,最多 256 KiB、64 个工具、每个工具 32 个目录;读取不创建来源,确认保存才条件原子写入并重新解析。没有可复用的构建身份,不允许跨工作树复制,不进入安装包,也不写入 SDK 或签名及增量更新基线。

原生插件设置的暂存目录:
Expand Down
Loading
Loading