Repository navigation
fix(desktop): 宿主启动的进程和终端用工作目录作 PWD - #1958
Merged
Merged
Conversation
buildprocess 给子进程传了自己的环境,os/exec 因此不再补 PWD, 子进程继承宿主的 PWD(指向别的目录),只能从内核拿到解析过符号链接的路径。 项目路径经过符号链接(例如 macOS 的 /var 是 /private/var)时,子进程里的工具 看到的目录和宿主传给它的路径写法不同:Delve 用 /private/var/... 构建、 宿主传 /var/...,go 报 "directory ... outside main module"。 - 非 Windows、工作目录非空时把 PWD 设成工作目录的绝对路径,和 os/exec 在环境为空时的做法一致;提供者在 Environment 里显式给的 PWD 优先。 - 新增 TestProcessSeesItsDirectoryAsTheHostSpelledIt(经符号链接启动, 子进程的 PWD 和 os.Getwd 都是宿主给的写法)和 TestSpecEnvironmentKeepsItsOwnPWD。 Refs #1953
终端在通过符号链接打开的项目里启动 shell 时,pwd 显示的是链接目标的规范路径 (macOS 上 /var/... 变成 /private/var/...),而不是用户打开的路径。 根因与上一个提交相同:startBackend 同时设置了 cmd.Dir 和 cmd.Env,os/exec 只在 Env 为空时才补 PWD,shell 于是继承了宿主自己的 PWD;它不指向当前目录,shell 就 退回到内核给出的规范路径。 修复:去掉继承的 PWD,改为工作目录的绝对路径,再应用插件终端的 Unset 和 Env, 插件仍可覆盖或删除 PWD。Windows 没有 PWD,这个文件只在非 Windows 编译。 测试: - TestShellSeesItsDirectoryAsTheHostSpelledIt:修复前输出 /private/var/.../002, 修复后为 .../001/project - TestPluginTerminalKeepsItsOwnPWD:插件设置的 PWD 原样传入,Unset 的 PWD 不传 Refs #1953
xiaoyumuxi
marked this pull request as ready for review
November 15, 2026 05:52
xiaoyumuxi
added a commit
to Lithe-IDEA/lithe-plugin-go
that referenced
this pull request
Nov 15, 2026
- debugAdapters[delve]:启动 PATH 里的 dlv dap,传输方式 tcpAnnounced, 从 stdout 读取 DAP 地址公告;program 绑定 target.directory(当前文件所在的包)。 - projectGenerators[go-module]:新建项目左侧的 Go,只写 go.mod、.gitignore 和可选的 main.go,不运行 go mod init,创建时不需要联网或安装 go。 - 插件版本 0.1.0,v0.1.0 发成预发布;新增 l10n/zh-Hans.json 翻译插件设置。 - e2e/host:固定宿主 cebbe0def(1lck/Lithe-IDEA#1958),新增 Delve 调试端到端测试 和生成器集成测试;构建输出改从运行控制台读取。 - 功能矩阵新增 go-debug-delve、go-project-generator。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue / Linked issue
PR 类型 / Type
改动说明 / What changes
背景 / Why
在 macOS 上用 Go 插件的 Delve 适配器调试项目时,Delve 编译阶段就失败了,调试会话起不来:
项目路径只要经过一次符号链接(macOS 的
/var就是指向/private/var的链接,用户自己的项目目录也可能是链接)就会复现。原因是宿主启动子进程时同时设置了
Dir和Env。Go 的os/exec只在Env为空时才自动补上PWD,所以子进程继承的是宿主自己的PWD。这个PWD指向的不是子进程的当前目录,子进程只好用内核给出的规范路径(/private/var/...),而宿主传给它的参数用的是用户打开时的路径(/var/...)。Go 认为这是两个目录,判定包在模块之外。终端也有同样的问题:在经过符号链接的项目里打开终端,
pwd显示的是链接目标,不是用户打开的路径。改动 / Changes
desktop/internal/buildprocess/process.go:mergedEnvironment多接收一个工作目录参数,把PWD设为它的绝对路径。优先级:登录 shell 的变量 < 工作目录的PWD<Spec.Environment,调用方自己给的PWD仍然生效。工作目录为空时不动PWD,这时子进程和宿主在同一个目录,继承的值本来就对。Windows 没有PWD,不设置。buildprocess.Start启动的进程都受影响:构建(workbench/build.go)、调试适配器(workbench/debug_start.go、debug_lookup_darwin.go)、测试(workbench/tests.go)、项目生成器(projectgen/run.go)、插件运行(pluginservice/runs.go)、工具链探测(toolchain/probe.go)。desktop/internal/localshell/backend_unix.go:终端启动 shell 时,先去掉继承的PWD,换成工作目录的绝对路径,再应用插件终端的Unset和Env,插件仍然可以覆盖或删除PWD。新增workingDirectoryVariable(这个文件只在非 Windows 下编译)。buildprocess/process_test.go:新增测试辅助进程模式pwd,用来打印PWD和os.Getwd()。新增TestProcessSeesItsDirectoryAsTheHostSpelledIt(工作目录是符号链接时,子进程看到的是链接路径)和TestSpecEnvironmentKeepsItsOwnPWD(调用方给的PWD优先,且只有一项)。localshell/shell_unix_test.go:新增TestShellSeesItsDirectoryAsTheHostSpelledIt(在经过符号链接的目录里,shell 的pwd是链接路径)和TestPluginTerminalKeepsItsOwnPWD(用/usr/bin/env检查程序实际收到的环境:插件设的PWD原样传入,Unset的PWD不传)。不在本 PR 范围内 / Out of scope
PWD,子进程不会因此看到另一种路径写法。类型专属:fix
复现与根因
/var/folders/...(或任何经过符号链接的目录)下的 Go 模块,装好 Go 插件,在main.go打断点后启动 Delve 调试。实际:调试控制台输出directory /var/... outside main module or its selected dependencies,Delve 退出。期望:停在断点。pwd。实际:显示/private/var/...(链接目标)。期望:显示用户打开的路径。git log -S或git blame查):两处都来自 0faecba(Epic(0.7.0): 基于 Viva 框架的跨平台方案的迁移(#1794) #1799,Viva 迁移,2026-11-12)。buildprocess.Start的command.Env = mergedEnvironment(...)和localshell的cmd.Env = append(withoutVariables(os.Environ(), ...))都同时设置了Dir和Env,没有补PWD。检查项
desktop/internal/buildprocess/process_test.goTestProcessSeesItsDirectoryAsTheHostSpelledIt,修复前:子进程的PWD是宿主自己的目录(测试进程所在的desktop/internal/buildprocess),os.Getwd()退回到/private/var/folders/.../001,期望两者都是/var/folders/.../002/projectdesktop/internal/localshell/shell_unix_test.goTestShellSeesItsDirectoryAsTheHostSpelledIt,修复前:dir=/private/var/folders/.../TestShellSeesItsDirectoryAsTheHostSpelledIt360510256/002,期望.../001/projectPWD的控制mergedEnvironment只在Start里调用;buildprocess.Start的 7 个调用方见上文“改动”;localshell.Start只由termview调用;Windows 后端backend_windows.go不涉及PWDPWD,没有同类缺陷;同一类问题在终端也有,已在本 PR 一并修复.agents/notes/implemented/bug-fix/记录:两个启动入口的注释已说明为什么要设PWD,回归测试覆盖了这两个入口;宿主没有其他同时设置Dir和Env的启动入口范围检查 / Scope checks
功能矩阵 / Feature matrix
N/A:缺陷修复,没有新增能力,也没有改变任何矩阵条目的实现或验证状态。
插件归属 / Plugin ownership
develop-lithe第三节“插件归属与宿主零依赖”的自查命令,结果为空/bin/sh和/usr/bin/env)shared/i18n/;插件的构建步骤、资源路径和补丁没有写进scripts/resources/、docs/ci-builds.md、Agent Note 或 Skille2e/host/lithe-host.json固定本分支 cebbe0d)全部 5 个测试通过:TestGoPluginGeneratesAModuleWithSampleCode、TestGoPluginGeneratesAnEmptyModule、TestGoPluginFormRejectsAModulePathWithSpaces、TestOfficialGoPluginDebugsAModuleWithDelve、TestOfficialGoPluginBuildsAndServesAModule。修复前 Delve 调试测试因 “outside main module” 失败UI 验证 / UI evidence
N/A:没有界面变化。
统一日志系统 / Structured logging
N/A:没有新增或改动生命周期里程碑、终态或失败路径。
界面文案 / i18n
N/A:没有新增或修改用户可见文字(
verify-app-language-localization.mjs和generate-i18n.mjs --check均通过)。逻辑归属 / Logic placement
PWD是 POSIX 约定,对所有子进程一视同仁,没有针对 Go 或 Delve 的分支)性能与内存 / Performance and memory
N/A:没有新增后台功能、子进程、缓存或依赖;每次启动进程只多一次
filepath.Abs。设置 / Settings
N/A:没有设置项变化。
插件契约 / Plugin contract
N/A:没有改契约、能力版本、插件函数协议或宿主方法。
发行包与资源 / Bundle and resources
N/A:没有新增运行时资源、缓存或下载物。
无用代码与重构 / Dead code and refactoring
refactor标签的 Issue:没有发现验证 / Verification
scripts/desktop/desktop-go.sh test ./internal/buildprocess ./internal/localshell -run '...HostSpelledIt'(恢复修复前的代码)scripts/desktop/desktop-go.sh test ./internal/localshell ./internal/buildprocess -count=1scripts/desktop/desktop-go.sh test -race ./internal/localshell ./internal/buildprocess -count=1scripts/desktop/desktop-go.sh test ./internal/localshell -run '<3 个目录测试>' -count=20scripts/desktop/desktop-go.sh test ./internal/termview -count=1scripts/desktop/desktop-go.sh test ./internal/workbench -run 'Debug|Announced|Build'scripts/desktop/desktop-go.sh test ./... -count=1GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go -C desktop vet ./internal/localshell ./internal/buildprocessGOOS=linux GOARCH=amd64 CGO_ENABLED=0 go -C desktop vet ./internal/localshell ./internal/buildprocessgofmt -l desktop/internal/localshell desktop/internal/buildprocessdevelop-lithe第三节插件归属自查rgnode scripts/i18n/verify-app-language-localization.mjs、node scripts/i18n/generate-i18n.mjs --checknode scripts/e2e-host.mjs,Delve 1.27.2、Go、gopls 在 PATH 上)未能执行的检查和原因:
backend_unix.go只在非 Windows 下编译,workingDirectoryVariable在 Windows 直接返回空),只做了交叉编译 vet。完整的 Windows CI 等标记 ready 后运行。提交前确认 / Final checks
preview创建;目标分支:feat、fix、docs 为preview,release 以发布流程要求为准(基于当时最新的 preview c21374c;之后合入的 fix(desktop): panic、窗口循环错误和致命崩溃全部接入统一日志 #1955 没有改本 PR 涉及的文件).build/、target/、dist/、.artifacts/等产物,没有凭据、个人路径和未脱敏的日志或截图dlv、gopls和测试启动的 Lithe 残留)