Skip to content

refactor(build): 删除 KNOWN_RUNTIME_TOOLS,go、node 运行时依赖按工具定义解析 - #69

Merged
xiaoyumuxi merged 2 commits into
mainfrom
refactor/1856-runtime-tool-definitions
Nov 16, 2026
Merged

xiaoyumuxi merged 2 commits into
mainfrom
refactor/1856-runtime-tool-definitions

Conversation

@xiaoyumuxi

Copy link
Copy Markdown
Contributor

关联 Issue / Linked issue

#1856 要求把 Core 里剩下的 5 类语言专属默认值移出 Core。本 PR 只做第 3 项(go、node 运行时)。第 5 项在 #66,第 2 项在 #68;第 1、4 项(忽略目录、运行发现)不在本 PR,#1856 保持打开。

PR 类型 / Type

  • fix:缺陷修复(去掉 Core 里的工具特判;已发布插件的构建行为不变,见下方“复现与根因”)

改动说明 / What changes

背景 / Why

构建系统的 invocation.runtimeDependencies 原来把 go、node 当作“宿主管理的运行时”(build/src/manifest/invocation.rs 的 KNOWN_RUNTIME_TOOLS = ["go", "node"]):

  • build.invocationPlan 给它们返回 { "kind": "runtime" } 候选、hostManaged: true,以及 Core 写死的版本参数:go 是 ["version"],node 是 ["--version"];
  • build.checkToolVersion 用 reported_version 从输出里取第一个点分数字;
  • 清单里不许给它们写 executables 或 version。

这是 Core 认识具体工具的写死逻辑,违反“Core 对语言和工具零特判”。其他运行时早就能按同 ID 的工具定义解析,只有这两个例外。

改动 / Changes

build

  • 删除 KNOWN_RUNTIME_TOOLS、RuntimeDependency::is_host_managed 和校验里的宿主运行时分支。names_tool_definition() 现在就是“没有 executables”,checked_by_tool_definition() 也不再排除 go、node。
  • 删除 host_runtime_version_arguments。runtime() 不再为 go、node 生成 { "kind": "runtime" } 候选,运行时计划删掉 hostManaged 字段。
  • check_version 只用清单声明的 version.pattern。没有探测、按工具定义解析的运行时(现在也包括 go、node)照旧以 plugin.build.unavailable 拒绝。

plugin-model:删除只有上面这处在用的 reported_version(连同 lib.rs 的导出)。

行为:runtimeDependencies 里不写 executables 的运行时,一律是同 ID 工具定义的隐式引用:

原来(go、node) 现在(任何 ID)
计划里的候选 { "kind": "runtime", "runtime": "go" } { "kind": "toolchain", "toolchainID": "go", "root": <root> }
version { "arguments": ["version"] } null
hostManaged true 字段删除
pathVariable LITHE_GO_PATH 不变
版本下限 Core 探测 + reported_version 工具定义解析时检查 minimumVersion
写了 executables plugin.manifest.invalid(“由宿主发现”) 按普通运行时校验

测试(core/src/tests/build_runtime_versions.rs)

  • vm、go、node 在三个平台上走同一条路径:都得到 toolchain 候选、version: null、LITHE_<ID>_PATH;checkToolVersion 都以 plugin.build.unavailable 拒绝。
  • 新增 described_runtime_reads_its_own_probe:叫 go 但自己写了 executables 和 version 的运行时,按它自己的 pattern 读版本,并判断是否满足下限。
  • 删除只测宿主运行时的两个用例:探测参数、reported_version。

契约

  • contract/v1/README.md:工具链小节和构建系统字段表里的 runtimeDependencies 一行,去掉 “node and go are host-managed” 和 hostManaged,写明 Core 不认识任何具体运行时。
  • build-plans.json:go 的计划用例改为 toolchain 候选;两个 go 版本用例合并成一个“版本由工具定义检查”的拒绝用例;gradle 两个用例去掉 hostManaged: false。
  • invalid-manifests.json:“host-managed runtime with its own executables” 改名为 “runtime minimum version with a command candidate but no probe”。它现在因为通用规则被拒绝(有 minimumVersion 的 command 候选需要探测),期望结果不变。
  • reference/domains/build-systems.md 中英两行、protocol-changelog.md(API-23,buildSystems 0 内的修正)同步。
  • 顺手修正:build、vcs、debug 三处 runtime_tools 字段的注释还写着 “host runtimes or tool-definition IDs”,实际只有 requiresTools 里的工具定义 ID,改成准确描述。

兼容性与发布顺序 / Compatibility and rollout

  • 已发布插件不用改:官方 Go 插件 1.0.1 的构建系统写的是 runtimeDependencies: [{ "id": "go", "minimumVersion": "1.21" }],它自己在 toolDefinitions 里提供 go,并在 requiresTools 里列出。is_tool_id("go") 成立,所以清单照常通过;计划里的 toolchain 候选解析到插件自己的 go 工具定义,版本下限由它检查。仓库里没有声明 node 运行时依赖的已发布插件。
  • 桌面端不需要改代码:桌面端原来就处理 "toolchain" 候选(resolveToolchainSelection(..., minimum));version 为 null 时不再额外探测;hostManaged 一直只解码、不使用。合入后只需要升级 PINNED_CORE_REVISION,同一个桌面端 PR 里顺手删掉已经不用的 BuildRuntimeRequirement.HostManaged,以及 "runtime" 候选里查不到 runtimes 时退回工具定义、再退回 PATH 的分支(Core 校验保证 "runtime" 候选一定指向已声明的运行时依赖,而运行时依赖自己不会再是 "runtime" 候选)。
  • 行为变化:唯一变化的情况是插件声明了 go 或 node 运行时依赖,却既没有提供也没有依赖同名工具定义。原来桌面端会退回 PATH 上的 go、node,现在报“找不到可执行文件”。这正是 #1856 要求的:运行时依赖一律引用工具定义 ID。

不在本 PR 范围内 / Out of scope

  • #1856 第 1、4 项。
  • 桌面端固定版本升级和上面说的两处死代码清理,合入后在桌面端做。

类型专属:fix

复现与根因

  • 复现:插件想要一个由自己描述的 go 运行时(例如用自己的 executables 指向特定位置),清单会以“go is discovered by the host”被拒绝;node、go 的版本探测参数和读法写死在 Core 里,插件改不了。
  • 根因:KNOWN_RUNTIME_TOOLS 把两个具体工具写死在 Core 里。
  • 影响平台:macOS、Windows(同一个 Viva 桌面端)。

检查项

  • 回归测试:见上方“测试”;fixture 的 go 计划、go 版本、命令候选缺探测三个用例覆盖契约面。
  • 已搜索 KNOWN_RUNTIME_TOOLS、is_host_managed、host_runtime_version_arguments、reported_version、hostManaged 的全部调用方:Core 里只剩本 PR 改掉的这些;桌面端只有 desktop/internal/core/build.go 的 HostManaged 字段,没有读它的代码。
  • 另一平台:Viva 桌面端是 macOS 和 Windows 共用的同一份代码。
  • 只改了去掉这个特判所需的代码,外加修正三条过时注释。

范围检查 / Scope checks

插件契约 / Plugin contract

  • 改了 shared/plugins/contract/v1/:README、fixture 都在本 PR;协议更新记录已登记(buildSystems 0 内的修正,API-23)。schema 里 runtimeDependencies 没有提到 go、node,不用改。
  • 没有新增字段、方法、通知或能力版本;计划输出少了 hostManaged 一个字段,唯一的宿主(Viva 桌面端)不读它。

逻辑归属 / Logic placement

  • Core 里不再出现任何具体运行时的名字和版本参数;查找可执行文件、检查版本都由插件提供的工具定义完成。

无用代码与重构 / Dead code and refactoring

  • reported_version、host_runtime_version_arguments 和宿主运行时校验分支已删除;桌面端两处随之变成死代码的地方,在升级固定版本的 PR 里删除(见上)。

其他组(功能矩阵、UI、日志、i18n、性能、设置、发行包):N/A,Core 这边没有涉及。


验证 / Verification

命令或操作 平台 结果
cargo fmt --all --check macOS arm64 通过
cargo test -p lithe-build -p lithe-plugin-model -p lithe-core macOS arm64 通过(lithe-core 820 个,含 build-plans 与 invalid-manifests fixture;lithe-build 7 个;lithe-plugin-model 23 个;另有 3 个集成测试文件 31 个)
cargo clippy --workspace --all-targets --features lithe-remote/server -- -D warnings macOS arm64 通过
bash scripts/rust-core/verify-rust-core-comments.sh macOS arm64 通过
node scripts/rust-core/verify-platform-tests.mjs macOS arm64 通过(52 个 crate)
node shared/plugins/scripts/verify-docs.mjs macOS arm64 通过
node scripts/rust-core/affected-crates.mjs --base origin/main macOS arm64 Linux:--workspace;macOS、Windows:lithe-platform 一组
桌面端 1lck/Lithe-IDEA main(b6b4a49,固定本分支的基点 957a349):LITHE_CORE_RUST_DIR=<本分支> scripts/desktop/desktop-go.sh test -count=1 ./internal/core ./internal/pluginbackend ./internal/marketplace ./internal/pluginservice ./internal/workbench macOS arm64 通过(5 个包,workbench 192 秒),桌面端代码未改
官方 Go 插件 1.0.1(lithe-plugin-go main 4d10cd1,已发布的清单原样打包)的宿主 e2e:LITHE_CORE_RUST_DIR=<本分支> node scripts/e2e-host.mjs --ref b6b4a490191beb35525d28b3357b418f32a954c9 macOS arm64 通过(projectgen 5 个、workbench 2 个;TestOfficialGoPluginBuildsAndServesAModule 用 go 运行时依赖做了真实的 build、vet、run,并覆盖 Go 可执行文件设置)

未能执行的检查和原因: 完整的 cargo test --workspace 由 Draft 的 Linux CI 运行。Windows 没有在本机执行,ready 后由 CI 覆盖。node 运行时依赖没有已发布插件可以做 e2e,由 runtime_without_executables_becomes_a_toolchain_candidate 和 runtime_named_by_tool_definition_has_no_core_probe 两个单元测试覆盖。

提交前确认 / Final checks

  • 分支从最新的 main(957a349)创建,目标分支 main
  • 以 Draft 提交
  • 没有无关改动和构建产物
  • 没有启动 Lithe 应用

构建系统的 runtimeDependencies 原来把 go、node 当作宿主管理的运行时:
计划返回 { kind: runtime } 候选和 Core 自带的版本参数(go version、
node --version),checkToolVersion 用 reported_version 读版本,清单里
不许给它们写 executables。这是 Core 认识具体工具的写死逻辑。

现在 Core 不认识任何具体运行时:没有 executables 的运行时一律是同 ID
工具定义的隐式引用,计划返回 toolchain 候选、version 为 null,版本由
工具定义检查;写了 executables 的按普通运行时校验。

- build:删除 KNOWN_RUNTIME_TOOLS、is_host_managed、宿主运行时校验分支、
  host_runtime_version_arguments 和计划里的 hostManaged 字段
- plugin-model:删除只服务于它的 reported_version
- 测试:go、node、vm 走同一条路径;自己描述的运行时按自己的 pattern 读版本
- 契约:README、build-plans 与 invalid-manifests fixture、build-systems
  参考页和协议更新记录;三处 runtime_tools 注释改成准确描述

Refs 1lck/Lithe-IDEA#1856
@xiaoyumuxi
xiaoyumuxi marked this pull request as ready for review November 16, 2026 11:25
…-tool-definitions

# Conflicts:
#	shared/plugins/reference/protocol-changelog.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant