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
15 changes: 9 additions & 6 deletions desktop/internal/workbench/filetree_openin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ func TestProjectTreeOpenWithListsTheSystemsApplications(t *testing.T) {
writeTreeFiles(t, root, "notes.txt")
h := newHarness(t, &testKernel{Client: core.NewClient()})
h.openTree(t, root)
appsDir := filepath.Join(root, "Apps")
otherDir := filepath.Join(root, "Other")
otherViewer := filepath.Join(otherDir, "Viewer.app")
stub := stubTreeApps(t, []fileapps.App{
{ID: "/Apps/Editor.app", Name: "Editor.app", Default: true},
{ID: "/Apps/Viewer.app", Name: "Viewer.app"},
{ID: "/Other/Viewer.app", Name: "Viewer.app"},
{ID: filepath.Join(appsDir, "Editor.app"), Name: "Editor.app", Default: true},
{ID: filepath.Join(appsDir, "Viewer.app"), Name: "Viewer.app"},
{ID: otherViewer, Name: "Viewer.app"},
}, nil)
language := h.app.language()
file := filepath.Join(root, "notes.txt")
Expand All @@ -104,10 +107,10 @@ func TestProjectTreeOpenWithListsTheSystemsApplications(t *testing.T) {
}
}
h.popupClick(h.shared("desktop.files.openWith"))
other := i18n.SharedFormat(language, "desktop.files.openWithAppPath", map[string]string{"name": "Viewer.app", "path": "/Other"})
other := i18n.SharedFormat(language, "desktop.files.openWithAppPath", map[string]string{"name": "Viewer.app", "path": otherDir})
for _, item := range []string{
i18n.SharedFormat(language, "desktop.files.openWithDefault", map[string]string{"name": "Editor.app"}),
i18n.SharedFormat(language, "desktop.files.openWithAppPath", map[string]string{"name": "Viewer.app", "path": "/Apps"}),
i18n.SharedFormat(language, "desktop.files.openWithAppPath", map[string]string{"name": "Viewer.app", "path": appsDir}),
other,
h.shared("desktop.files.openWithOther"),
} {
Expand All @@ -127,7 +130,7 @@ func TestProjectTreeOpenWithListsTheSystemsApplications(t *testing.T) {
if want := []string{file}; !slices.Equal(asked, want) {
t.Fatalf("asked the system about %q, want %q once", asked, want)
}
if want := []string{file + " with /Other/Viewer.app"}; !slices.Equal(opened, want) {
if want := []string{file + " with " + otherViewer}; !slices.Equal(opened, want) {
t.Fatalf("opened %q, want %q", opened, want)
}
if h.app.notice != "" {
Expand Down
49 changes: 37 additions & 12 deletions desktop/internal/workbench/runconfig_shell_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package workbench

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

"github.com/1lck/Lithe-IDEA/desktop/internal/core"
"github.com/1lck/Lithe-IDEA/desktop/internal/i18n"
"github.com/1lck/Lithe-IDEA/desktop/internal/localshell"
"github.com/1lck/Lithe-IDEA/desktop/internal/shellkind"
Expand Down Expand Up @@ -76,10 +79,20 @@ func TestRunConfigShellChoicesListTheFamilyAndCustom(t *testing.T) {
// the field again.
func TestRunConfigInterpreterListsTheTerminalShells(t *testing.T) {
h, p, root := emptyProcessRunHarness(t)
h.app.listShells = testTerminalShells
// Saving exercises Core's native path validation. Keep the WSL identifier and
// give the file-backed shell choices absolute paths on the test host.
shellDir := t.TempDir()
writeTreeFiles(t, shellDir, "bash")
shells := testTerminalShells()
for i, shell := range shells {
if !strings.HasPrefix(shell.Path, "wsl:") {
shells[i].Path = filepath.Join(shellDir, shell.Name)
}
}
h.app.listShells = func() []localshell.Choice { return slices.Clone(shells) }
f := newRunConfigDraft(t, h, p, runProviderShell)
fillScriptText(t, h, p, f, "Greet", "echo hi\n")
awaitStateWithin(t, h, 10*time.Second, "the terminal's shells", func() bool { return len(h.app.term.shells.list) == len(testTerminalShells()) })
awaitStateWithin(t, h, 10*time.Second, "the terminal's shells", func() bool { return len(h.app.term.shells.list) == len(shells) })
h.settle()
interpreter := f.texts["interpreter"]
if interpreter == nil {
Expand All @@ -100,37 +113,49 @@ func TestRunConfigInterpreterListsTheTerminalShells(t *testing.T) {
choose := func(entry string) {
t.Helper()
h.click(center(h.hitLabeled(label)))
if h.hasPopupItem(shell("pwsh", "/usr/local/bin/pwsh")) || h.hasPopupItem(shell("fish", "/opt/homebrew/bin/fish")) {
if h.hasPopupItem(shell("pwsh", filepath.Join(shellDir, "pwsh"))) || h.hasPopupItem(shell("fish", filepath.Join(shellDir, "fish"))) {
t.Fatal("the list offers a shell of another family")
}
h.click(center(h.popupHit(entry)))
}

choose(shell("bash", "/bin/bash"))
if *interpreter != "/bin/bash" || h.hasPopupItem(custom) {
bashPath := filepath.Join(shellDir, "bash")
choose(shell("bash", bashPath))
if *interpreter != bashPath || h.hasPopupItem(custom) {
t.Fatalf("interpreter %q, custom field shown %v", *interpreter, h.hasPopupItem(custom))
}

choose(i18n.Shared(language, "desktop.runConfig.interpreterCustom"))
if *interpreter != "/bin/bash" || !h.hasPopupItem(custom) {
if *interpreter != bashPath || !h.hasPopupItem(custom) {
t.Fatalf("Custom…: interpreter %q, custom field shown %v", *interpreter, h.hasPopupItem(custom))
}
h.typeInto(custom, func() { *interpreter = "" }, "tools/sh")
if *interpreter != "tools/sh" || !h.hasPopupItem(custom) {
t.Fatalf("typed interpreter %q, custom field shown %v", *interpreter, h.hasPopupItem(custom))
}

choose(shell("bash", "/bin/bash"))
if *interpreter != "/bin/bash" || h.hasPopupItem(custom) {
choose(shell("bash", bashPath))
if *interpreter != bashPath || h.hasPopupItem(custom) {
t.Fatalf("back to bash: interpreter %q, custom field shown %v", *interpreter, h.hasPopupItem(custom))
}
applyDialog(t, h, p, runConfigDialogApply)
saved, err := os.ReadFile(filepath.Join(root, ".lithe", "run", "local.yaml"))
if err != nil || !strings.Contains(string(saved), "/bin/bash") {
t.Fatalf("local.yaml = %s, %v", saved, err)
if _, err := os.Stat(filepath.Join(root, ".lithe", "run", "local.yaml")); err != nil {
t.Fatalf("save local.yaml: %v, dialog failure %q, form failure %q, field errors %v", err, p.runConfigs.dialog.failure, f.failure, f.errors)
}

id := p.runConfigs.dialog.selected
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
saved, err := h.app.kernel.RunEditorForm(ctx, core.RunEditorFormRequest{Root: root, Provider: runProviderShell, ConfigurationID: id})
if err != nil {
t.Fatalf("load configuration %q: %v", id, err)
}
var savedInterpreter string
if err := json.Unmarshal(saved.Values["interpreter"], &savedInterpreter); err != nil || savedInterpreter != bashPath {
t.Fatalf("saved interpreter = %q, want %q: %v", savedInterpreter, bashPath, err)
}

f = p.runConfigs.dialog.drafts[p.runConfigs.dialog.selected].form
f = p.runConfigs.dialog.drafts[id].form
awaitStateWithin(t, h, 10*time.Second, "the saved configuration's form", func() bool { return f != nil && f.ready() })
interpreter = f.texts["interpreter"]
choose(i18n.SharedFormat(language, "desktop.runConfig.automaticValue", map[string]string{"value": automaticInterpreter(t, f)}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@
]
},
"owner": "Run",
"verification": "不装任何插件打开一个空文件夹:标题栏“编辑运行配置…”打开“运行/调试配置”对话框,空白页列出四类内置运行;点“+”新建 Shell 脚本,选“脚本文本”写 echo hello,勾选“存为项目文件”后点对话框的“运行”,确认 .lithe/run/configurations.yaml 出现该配置、Run 窗口控制台输出 hello 并以“进程已结束,退出码 0。”结束、系统临时目录没有残留的 lithe-run-script-*;标题栏运行按钮再次运行同一配置。改为脚本文件(项目内的 .sh,带与不带 #! 首行各一次)、填脚本选项、工作目录和环境变量,确认解释器自动值随首行变化,保存后重开回显一致;展开解释器路径下拉,确认列出终端新建菜单里的同类 shell,选中一个后保存写入其路径,选“自定义…”填 PATH 上的命令名或用浏览选文件后能运行,改回“自动”后字段清空;取消勾选“存为项目文件”后配置移到 .lithe/run/local.yaml。新建可执行程序运行项目内程序与 PATH 上的程序;程序不存在、工作目录出项目或不存在时运行前提示原因。在对话框里连续新建两条配置后点“应用”,确认两条一起保存、对话框不关;选中一条点“−”再点“取消”,确认没有删除,点“确定”后才删除;复制一条配置,确认副本名为“<原名>(副本)”且字段一致;有构建插件生成的运行时复制它,点“应用”后确认 .lithe/run/plugin/<插件>.local.toml 出现副本、原配置仍在。删掉全部配置后重开对话框,确认左右两侧的 IDEA 式空白页,点两个链接和按 ⌃N(Windows 为 Alt+Insert)都弹出类型菜单。选中配置按 ⌫(Windows 为 Delete)删除,“取消”后恢复。选中配置点“新建文件夹”,在右侧把它改名(空名、重名、含 Tab 时提示原因),“应用”后确认配置文件里写入 folder;把另一条配置拖进这个文件夹;选中文件夹点“−”解散。关掉“按字母顺序排序”后拖动调整顺序,“应用”后确认只有 .lithe/run/local.yaml 的 arrangement 变化、标题栏下拉顺序一致,重新打开排序后恢复按名称。macOS/Linux 上新建批处理:类型旁标“仅 Windows”,可编辑保存,编辑器顶部有原因,对话框“运行”和标题栏运行按钮置灰,下拉里该行带警告图标并注明“仅 Windows”,按标题栏运行只提示原因;Windows 上分别运行 .ps1(默认带 -ExecutionPolicy Bypass,取消勾选后不带)、.cmd/.bat(含空格与引号参数)和 .exe。放一份旧版 .lithe/run/configurations.json,确认仍列出,编辑一次后改写为 YAML 并删除 JSON。让一个插件的 TOML 文件写坏,确认内置运行仍列出可运行,运行下拉出现“未读取 <文件名> 中的运行配置”,点击后在编辑器打开该文件。自动化覆盖:runconfig_process_test.go 的端到端测试用真实 Core 和系统 shell(Windows 为 cmd)新建、保存、运行(确认 Run 窗口打开并选中这次运行)并从标题栏再运行;runconfig_dialog_test.go 覆盖对话框的应用、取消、删除(含 ⌫/Delete 键)、复制(含插件运行复制进 <插件>.local.toml)、文件夹新建/重命名/解散、手动顺序与排序开关、IDEA 式空白页与 ⌃N/Alt+Insert、分组折叠,以及批处理在非 Windows 上能编辑保存、不能运行;runconfig_shell_test.go 覆盖解释器下拉只列同类 shell、选中 shell、自定义输入、改回自动和保存;runconfig_process_visual_test.go 生成 docs/assets/builtin-process-runs 的无头截图;单元测试覆盖 PATH 查找跳过相对目录、临时脚本只写在本次目录、工作目录不出项目、浏览路径转为项目相对、字段显示条件和保留未绘制字段的值;TestUnreadablePluginRunDocumentKeepsBuiltInRunsListed 覆盖写坏的插件文件不影响内置运行、下拉列出并打开该文件;buildprocess 测试覆盖批处理参数转义。",
"verification": "不装任何插件打开一个空文件夹:标题栏“编辑运行配置…”打开“运行/调试配置”对话框,空白页列出四类内置运行;点“+”新建 Shell 脚本,选“脚本文本”写 echo hello,勾选“存为项目文件”后点对话框的“运行”,确认 .lithe/run/configurations.yaml 出现该配置、Run 窗口控制台输出 hello 并以“进程已结束,退出码 0。”结束、系统临时目录没有残留的 lithe-run-script-*;标题栏运行按钮再次运行同一配置。改为脚本文件(项目内的 .sh,带与不带 #! 首行各一次)、填脚本选项、工作目录和环境变量,确认解释器自动值随首行变化,保存后重开回显一致;展开解释器路径下拉,确认列出终端新建菜单里的同类 shell,选中一个后保存写入其路径,选“自定义…”填 PATH 上的命令名或用浏览选文件后能运行,改回“自动”后字段清空;取消勾选“存为项目文件”后配置移到 .lithe/run/local.yaml。新建可执行程序运行项目内程序与 PATH 上的程序;程序不存在、工作目录出项目或不存在时运行前提示原因。在对话框里连续新建两条配置后点“应用”,确认两条一起保存、对话框不关;选中一条点“−”再点“取消”,确认没有删除,点“确定”后才删除;复制一条配置,确认副本名为“<原名>(副本)”且字段一致;有构建插件生成的运行时复制它,点“应用”后确认 .lithe/run/plugin/<插件>.local.toml 出现副本、原配置仍在。删掉全部配置后重开对话框,确认左右两侧的 IDEA 式空白页,点两个链接和按 ⌃N(Windows 为 Alt+Insert)都弹出类型菜单。选中配置按 ⌫(Windows 为 Delete)删除,“取消”后恢复。选中配置点“新建文件夹”,在右侧把它改名(空名、重名、含 Tab 时提示原因),“应用”后确认配置文件里写入 folder;把另一条配置拖进这个文件夹;选中文件夹点“−”解散。关掉“按字母顺序排序”后拖动调整顺序,“应用”后确认只有 .lithe/run/local.yaml 的 arrangement 变化、标题栏下拉顺序一致,重新打开排序后恢复按名称。macOS/Linux 上新建批处理:类型旁标“仅 Windows”,可编辑保存,编辑器顶部有原因,对话框“运行”和标题栏运行按钮置灰,下拉里该行带警告图标并注明“仅 Windows”,按标题栏运行只提示原因;Windows 上分别运行 .ps1(默认带 -ExecutionPolicy Bypass,取消勾选后不带)、.cmd/.bat(含空格与引号参数)和 .exe。放一份旧版 .lithe/run/configurations.json,确认仍列出,编辑一次后改写为 YAML 并删除 JSON。让一个插件的 TOML 文件写坏,确认内置运行仍列出可运行,运行下拉出现“未读取 <文件名> 中的运行配置”,点击后在编辑器打开该文件。自动化覆盖:runconfig_process_test.go 的端到端测试用真实 Core 和系统 shell(Windows 为 cmd)新建、保存、运行(确认 Run 窗口打开并选中这次运行)并从标题栏再运行;runconfig_dialog_test.go 覆盖对话框的应用、取消、删除(含 ⌫/Delete 键)、复制(含插件运行复制进 <插件>.local.toml)、文件夹新建/重命名/解散、手动顺序与排序开关、IDEA 式空白页与 ⌃N/Alt+Insert、分组折叠,以及批处理在非 Windows 上能编辑保存、不能运行;runconfig_shell_test.go 覆盖解释器下拉只列同类 shell、选中 shell、自定义输入、改回自动,并用本机绝对路径的文件替身验证保存后从磁盘读取的解释器路径;runconfig_process_visual_test.go 生成 docs/assets/builtin-process-runs 的无头截图;单元测试覆盖 PATH 查找跳过相对目录、临时脚本只写在本次目录、工作目录不出项目、浏览路径转为项目相对、字段显示条件和保留未绘制字段的值;TestUnreadablePluginRunDocumentKeepsBuiltInRunsListed 覆盖写坏的插件文件不影响内置运行、下拉列出并打开该文件;buildprocess 测试覆盖批处理参数转义。",
"notes": "Issue #2100。只内置平台自带的脚本和二进制程序,Python、Node 等其他运行交给插件注入。Windows 上未指定解释器的 Shell 脚本按 PATH 找 bash,可能找到 WSL 的 bash,需要 Git Bash 时从解释器下拉选终端检测到的 Git Bash 或自定义完整路径;cmd 参数转义不处理 %(cmd 会展开环境变量);Core 拆分脚本选项、程序参数和解释器选项时把反斜杠当转义符(只在单引号内按原样保留),Windows 路径要用单引号括起来或把 \\ 写成 \\\\。对话框在应用窗口内以模态层显示。空文件夹只在对话框打开期间存在,不会保存(和 IDEA 一样,文件夹记在配置上)。配置树的行不显示悬停提示(Viva 的树行没有标识),不可运行的原因写在编辑器顶部和无障碍标签里。macOS 原生窗口验收、Windows 与 Linux 实机验证待做。"
}
Loading
Loading