Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
21faca0
feat(build): run declared test discovery commands
Mucheen Nov 19, 2026
9e1f9c3
Merge remote-tracking branch 'upstream/main' into codex/2122-desktop-…
Mucheen Nov 19, 2026
9907199
build(core): pin the command discovery contract
Mucheen Nov 19, 2026
5d27e46
test(pluginhost): expect command test discovery capability
Mucheen Nov 19, 2026
21c0536
Merge branch 'main' into codex/2122-desktop-command-test-discovery
Mucheen Nov 19, 2026
aa8e0d9
fix(build): drain test discovery before stopping a plugin
Mucheen Nov 19, 2026
c061d79
build(core): pin merged test discovery and toolchain contracts
Mucheen Nov 19, 2026
193a321
fix(build): await discovery cleanup after workspace close
Mucheen Nov 19, 2026
faea31f
Merge desktop main and retain its Core revision
Mucheen Nov 19, 2026
84b6c65
Merge branch 'main' into codex/2122-desktop-command-test-discovery
Mucheen Nov 19, 2026
fe0445a
Merge branch 'main' into codex/2122-desktop-command-test-discovery
Mucheen Nov 19, 2026
954c320
Merge branch 'main' into codex/2122-desktop-command-test-discovery
Mucheen Nov 19, 2026
8bdf61f
fix(terminal): wait for shell hangup before closing the PTY
Mucheen Nov 19, 2026
5dad944
Merge commit '3fe59a9d1' into codex/2122-desktop-command-test-discovery
Mucheen Nov 19, 2026
7efa8f3
fix(build): make command test discovery honor workspace trust
Mucheen Nov 19, 2026
f6b320b
fix(workspace): display trust locations with native path separators
Mucheen Nov 19, 2026
d5b08a9
fix(terminal): retry a missed hangup at the Bash prompt
Mucheen Nov 19, 2026
49d3933
Merge branch 'main' into codex/2122-desktop-command-test-discovery
Mucheen Nov 19, 2026
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 @@ -32,6 +32,12 @@ Core 继续校验工程/目标/模型任务选择、路径与生效选项,返

插件显式声明 `test.discovery`,同时支持套件和用例筛选,原生窗口才提供发现入口。用户展开“已发现的测试”或点击发现时,宿主通过协议 3 的 `lithe/build/discoverTests` 请求整个实例的清单;不会在打开工程时扫描源码或后台执行工具。列表里的每个条目都必须能通过同一测试计划精确运行,Core(共享校验层)拒绝错误范围、路径、筛选类型和超限清单,不用部分成功假装已经列全测试。

Viva 也支持插件声明一次性发现命令。它适合能直接请现有测试引擎列出用例的工具,因而可以沿用同一测试树而无需为了发现常驻后端。用户点击发现后,宿主用共享构建进程运行 Core 生成的参数,报告放进插件的工作区可写状态,以临时目录隔离并在操作结束后清理。Core 把命令报告和后端结果交给同一套选择校验。宿主按统一日志记录命令终态,源码或实例变化时取消在途命令并丢弃旧结果。

一次性发现沿用插件的原生启动登记,由各工作台持有到进程退出和报告目录清理完毕。关闭项目会取消命令,随后卸载仍能等待该工作台的登记,包括已离开标签栏的工作台。停用、被替换为其他语言服务提供方或卸载时,先撤销该插件的发现结果、阻断新命令,再等待清理。用 `TestPluginTeardownWaitsForBuildCommandDiscovery` 和 `TestPluginTeardownWaitsForDiscoveryAfterProjectCloses` 验证共用的清理入口。

命令发现计划使用当前工作区信任。Core 会在安全模式拒绝标明执行项目代码的命令。`TestBuildCommandDiscoversExactTestsAndRecordsItsResult` 覆盖信任项目下的发现与精确执行计划,以及安全模式的拒绝。

插件复用其已选择的上游测试引擎回答套件、用例、工程及目标;宿主只显示现有共享树的节点。不增加另一套 Java 注解扫描、框架探测、工程图或 Test Explorer。条目身份包括工程和目标,所以两个模块中的同名测试不会互相覆盖。

发现和执行共用唯一原生操作槽及工作区进程,避免又建一个后台任务运行时。加载状态、成功空列表和失败是不同结果;失败可由用户重试。发现缓存仅在同一插件包、生效选项、启动设置及配置代次下可用,任何工作区源码修改都会清除清单,并取消正在进行的发现。旧工具栏选择运行前必须用 ID 重新查验当前清单,不能只保存旧请求然后直接执行。停用、更新、工作区重开和退出继续通过既有会话释放资源;报告和清单不写进插件包。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ Motty 有开关。没有采用:只在命令行输入区、单击且未拖动

- 收益:本地 bash/zsh、WSL 和带 PSReadLine 的 PowerShell 里,提示符处调整大小不再留下重复提示符;单击命令行可以移动光标。Windows PowerShell/cmd 的提示符上报首次真正启用。
- 代价:每次启动本地 bash/zsh 多运行一次 `sh`(随即变成 Shell,不常驻);`TMPDIR` 下会短暂出现一个私有目录;第一个提示符上点击不生效。
- 关闭时等 Shell 回到提示符再挂断(#2005):bash 只在“算作交互状态”时把挂断转给后台任务,它运行 `PROMPT_COMMAND`(集成也用它)期间不算。挂断如果落在这段时间里,bash 会退出,但后台任务留了下来。因此 `localshell.Shell` 在读输出时跟踪本会话带令牌的 A–D 标记(`prompt_marks.go`)。Shell 显示过提示符后,如果关闭时它正处在“命令结束到下一个提示符出现”之间(上一个标记不是 B,也不是“C 之后前台还有程序在跑”),挂断就推迟到它打出 B 标记、自己结束,或者最多等 1 秒(`promptGrace`),然后照常挂断,0.5 秒后强制结束。到 B 时 bash 已经回到交互状态,会把挂断转给后台任务。还没出过第一个提示符、或者没有集成的 Shell,照旧立即挂断。关闭后读端继续读输出但直接丢弃,这样内存不会增长,也能看到 B 标记。窗口退出要等每个 Shell 结束,所以最多多等约 1 秒。
- 关闭集成终端时等 Shell 回到提示符再挂断(#2005、[#2054](https://github.com/1lck/Lithe-IDEA/issues/2054))。Bash 运行 `PROMPT_COMMAND` 时可能无法把挂断转给后台任务。提示符钩子也能启动前台程序,所以前台进程组无法区分正在运行的用户命令和提示符钩子。显示过提示符的 Shell 如还未打出下一个 B 标记,就继续读取并丢弃输出,最多等原有的 1 秒宽限再发送 SIGHUP。未经集成或还没有提示符的 Shell 立即挂断。
- 伪终端主端(PTY master)留到 Shell 退出并完成有界输出排空。Unix 上关闭主端会让 Shell 的读端看到 EOF 或 EIO,与 Bash 处理 SIGHUP 的顺序产生竞争。保留主端使 Bash 有机会把信号转给自己的任务。Linux 并发复现显示,Bash 打出 B 标记后仍可能错过第一次 SIGHUP,0.5 秒后被强制结束而后台任务仍在运行。集成 Bash 在提示符处挂断后,若 100 毫秒内仍未完成关闭,再给 Shell 发一次 SIGHUP,让进入输入循环的 Bash 转发;0.5 秒强制结束宽限不变。
- 不要这样做:给会话里所有进程组都发挂断。用户 `disown` 掉的任务会被一起结束;挂断交给 Shell 转发,`disown`/`disown -h` 的语义才能保留。其他终端(如 Ghostty)也只挂断 Shell 自己的进程组。
- 仍然存在的限制:没有集成、但用户自己配了 `PROMPT_COMMAND` 的 bash 不变。zsh 只有在后台任务刚 fork、还没 exec 的约 1 毫秒里被挂断时才会留下任务,这个窗口没有标记可以等,不处理。一直不回提示符的 Shell(例如在 `PROMPT_COMMAND` 里死循环)在 1 秒后照常挂断。
- 没有消费方的回调和目录上报已由 #1984 删除,见“只上报有消费方的内容”。
Expand All @@ -116,6 +117,7 @@ Motty 有开关。没有采用:只在命令行输入区、单击且未拖动
## 验证

- `./scripts/desktop/desktop-go.sh test ./internal/localshell/... ./internal/term/... ./internal/termview/... -count=1`:真实 bash/zsh 经垫片启动并上报提示符和命令,第一个提示符出现时启动目录已删除;挂断能结束 Shell 和后台任务;命令刚结束、bash 还在运行 `PROMPT_COMMAND`(包括慢的 `PROMPT_COMMAND`)时关闭,后台任务也会结束(`TestClosingAnIntegratedShellRightAfterACommandHangsUpItsJobs`,关掉推迟后 bash 的三个用例都会失败);一直不回提示符的 Shell 在宽限期后结束(`TestClosingAnIntegratedShellThatNeverPromptsStillEndsIt`);标记识别跨分片、只认本会话令牌(`TestPromptMarks*`、`TestPromptMarksAcrossEverySplit`);命令结束只在退出码有效时收回输入模式(`TestACommandEndReclaimsOnlyWithAValidStatus`);WSL 脚本在起始目录启动登录 Shell(`TestWSLScriptStartsTheLoginShellInTheStartFolder`);启动文件还在运行时关闭,Shell 被结束、目录被删除(`TestClosingAShellDuringItsStartupRemovesItsPrivateDirectory`);令牌每次启动更换;提示符处尺寸保持后只发一次;点击按条件发送方向键。
- `TestCloseLetsTheShellHandleHangupBeforeReleasingThePTY` 用可控后端验证关闭顺序。即使提示符钩子占用前台进程组,也先等 B 标记,发出挂断后再等 Shell 退出,最后关闭主端。
- 运行 `./internal/workbench/` 测试前后统计 `TMPDIR` 下的 `motty-shell.*` 目录,数量不变。
- `scripts/desktop/verify/verify-runtime-bundle-immutability.sh`:确认运行时没有写入发行目录。
- 在 Windows 上运行 `TestWindowsShellsMarkTheirPromptsUnderTheToken`(PowerShell 在下一个提示符前标记命令开始、屏幕开启两项功能,cmd 不标记)、`TestPowerShellReadLineIntegrationMarksTheCommandStart`、`TestPowerShellPromptIntegrationPreservesCustomPromptAndExitStatus`,它们只在 Windows 编译。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Maven 这类命令来源的模型会运行 `mvn`,pom 里的扩展和插件就

## 决策

- **三种状态由 Core 判定。** Core 的工具链目录记着信任过的工作区、明确不信任的工作区和信任的位置(父文件夹)。`toolchains.catalogState` 返回 `workspaceTrust`(`trusted`、`distrusted`、`unknown`,以及可以提供的父文件夹);显式决定优先于位置,和 IDEA 的 `TrustedPaths` 一致。根目录、盘符和网络共享根不作为可信位置提供。
- **三种状态由 Core 判定。** Core 的工具链目录记着信任过的工作区、明确不信任的工作区和信任的位置(父文件夹)。`toolchains.catalogState` 返回 `workspaceTrust`(`trusted`、`distrusted`、`unknown`,以及可以提供的父文件夹);显式决定优先于位置,和 IDEA 的 `TrustedPaths` 一致。根目录、盘符和网络共享根不作为可信位置提供。Core 返回的父文件夹路径在生成复选框标签时转换为当前平台的显示格式,再缩写主目录或长路径。
- **Core 拒绝会运行项目代码的计划。** 计划请求带 `projectCodeAllowed`;为假时,命令模型(清单标了 `executesProjectCode`)、执行类提供者计划和声明了运行项目代码的提供者都会被拒绝,错误码 `plugin.build.untrustedWorkspace`。宿主只负责把项目当前的信任带进请求(`desktop/internal/workbench` 中 11 处请求都填 `p.trust.allowed()`),不自己判断哪些计划危险。
- **先问再打开。** `openProjectHere` 先读信任(`toolchain.ReadWorkspaceTrust`),再决定直接打开、以安全模式打开或提问;选“不打开”时当前项目原样保留,新开的项目页签直接关掉。“以安全模式预览”记成不信任,下次打开不再问,和 IDEA 的 `setProjectTrusted(false)` 相同。
- **安全模式下的动作先问。** `startRun`、`runBuildTask`、`startTests`、运行当前文件和重新加载模型前,安全模式会弹出“信任项目?/ 保持安全模式”。信任保存成功后才执行原动作;保存失败按未信任处理。自动加载的模型不运行,构建窗口在模型位置显示安全模式说明。
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/desktop-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,25 @@ jobs:
- name: Vet and test
run: ./scripts/desktop/check.sh

- name: Run command test discovery headless
id: build-command-discovery-visual
if: ${{ !cancelled() && steps.rust.outcome == 'success' }}
timeout-minutes: 5
env:
LITHE_VISUAL_OUTPUT_DIR: ${{ github.workspace }}/.artifacts/build-command-discovery-visual
run: |
./scripts/desktop/desktop-go.sh test -v -tags 'vivahead lithevisual' ./internal/workbench \
-run '^TestVisualBuildCommandDiscovery$' -count=1 -timeout=120s

- name: Upload command test discovery screenshots
if: ${{ !cancelled() && steps.build-command-discovery-visual.outcome != 'skipped' }}
uses: actions/upload-artifact@v7
with:
name: build-command-discovery-visual-${{ runner.os }}-${{ runner.arch }}
path: .artifacts/build-command-discovery-visual/*.png
if-no-files-found: error
retention-days: 14

- name: Run LSP editor headless tests
id: lsp-visual
# Capture evidence even when an unrelated test in the full suite fails.
Expand Down
2 changes: 2 additions & 0 deletions desktop/internal/core/plugin_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const (
OperationDebugAdapterStart PluginOperationName = "debugAdapter/start"
// OperationBuildModel is one model load of a buildSystems[].model command source.
OperationBuildModel PluginOperationName = "lithe/build/model"
// OperationBuildTestDiscovery is one test discovery command.
OperationBuildTestDiscovery PluginOperationName = "lithe/build/discoverTests"
// OperationBuildDependencies is one dependency tree load of a command source.
OperationBuildDependencies PluginOperationName = "lithe/build/dependencies"
// OperationCommandInstallerInstall is one commandInstallers[] installation the user
Expand Down
2 changes: 1 addition & 1 deletion desktop/internal/core/plugin_operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TestCoreTakesEveryResultTheHostRecords(t *testing.T) {
}
contributions := map[PluginOperationName]map[PluginStage]string{
OperationLanguageServerStart: processStart, OperationDebugAdapterStart: processStart,
OperationBuildModel: commandRun, OperationBuildDependencies: commandRun,
OperationBuildModel: commandRun, OperationBuildDependencies: commandRun, OperationBuildTestDiscovery: commandRun,
}
allStages := []PluginStage{StagePlan, StageResolve, StageLaunch, StageInitialize, StageTimeout, StageExit, StageDecode}
want := map[string]string{} // op -> code, "" for finished
Expand Down
11 changes: 6 additions & 5 deletions desktop/internal/core/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (c *Client) DecodeBuildTestResults(ctx context.Context, manifest json.RawMe
return *result.Results, nil
}

// BuildDiscoveredTest is one exact test a provider discovered. Core accepted it only after the
// BuildDiscoveredTest is one exact test discovered by a command or provider. Core accepted it only after the
// ordinary test plan could run it, so Suite, Case, Project and Target go back into
// BuildTestRequest unchanged. ID tells tests with equal names in sibling modules apart.
type BuildDiscoveredTest struct {
Expand All @@ -146,22 +146,23 @@ type BuildTestDiscovery struct {
}

// BuildDecodeTestDiscoveryRequest carries the plan context the discovery ran with and the
// litheTestDiscovery document the provider answered.
// litheTestDiscovery document returned by a command or provider.
type BuildDecodeTestDiscoveryRequest struct {
Root string `json:"root"`
Options map[string]json.RawMessage `json:"options,omitempty"`
PluginDirectory string `json:"pluginDirectory,omitempty"`
WorkspaceStateDirectory string `json:"workspaceStateDirectory,omitempty"`
Result json.RawMessage `json:"result"`
OutputFile string `json:"outputFile,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
}

// PlanBuildTestDiscovery plans the provider request that lists the instance's tests. Only a
// PlanBuildTestDiscovery plans how to list the instance's tests. Only a
// declaration with test discovery accepts it, and it always addresses the whole instance.
func (c *Client) PlanBuildTestDiscovery(ctx context.Context, manifest json.RawMessage, buildSystemID string, request BuildPlanRequest) (BuildPlan, error) {
return c.planBuild(ctx, "build.testDiscoveryPlan", manifest, buildSystemID, request)
}

// DecodeBuildTestDiscovery validates a provider's discovered tests. Core rejects the whole
// DecodeBuildTestDiscovery validates the discovered tests. Core rejects the whole
// document rather than publish a partial list.
func (c *Client) DecodeBuildTestDiscovery(ctx context.Context, manifest json.RawMessage, buildSystemID string, request BuildDecodeTestDiscoveryRequest) (BuildTestDiscovery, error) {
const command = "build.decodeTestDiscovery"
Expand Down
4 changes: 3 additions & 1 deletion desktop/internal/localshell/backend_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func startBackend(config Config) (backend, error) {
}
env := append(withoutVariables(inherited, config.Unset), "TERM=xterm-256color", "COLORTERM=truecolor")
env = withUTF8Locale(append(env, config.Env...))
bash := filepath.Base(program) == "bash"
args := config.Args
// runtime is the private directory of an integrated shell's startup files:
// it is made here and removed once the shell has ended, however it ended,
Expand Down Expand Up @@ -117,7 +118,8 @@ func startBackend(config Config) (backend, error) {
})
return readErr == nil && err == nil && group > 0 && group != cmd.Process.Pid
},
promptToken: promptToken,
promptToken: promptToken,
retryHangupAtPrompt: bash && promptToken != "",
}, nil
}

Expand Down
Loading
Loading