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 @@ -194,6 +194,17 @@ capability → Rust 以 LSP request ID 关联 deadline,用不透明 operation
ID 投影 terminal result。停止 session 时先 `shutdown` 后 `exit`,服务器
无响应则由超时路径强制停止,不直接用 `terminate()` 代替。

进程创建后启动失败(initialize 出错、索引被替换或取消)时,进程必须在有界期限内
确认退出才算清理完成,不能只发信号就丢弃会话。普通 `lsp.startServer` 调用方拿不到
会话 ID,因此 Core 把未完成清理的会话记在内部待清理列表,下一次显式启动前最多重试
一次有界释放,仍未完成就拒绝再启动新进程,并保留原始启动错误。进程内原生调用方
(`start_lsp_owned`)在注册回调里先拿到会话 ID,启动返回错误时仍持有该 ID,自行重试
`lsp.destroyServer`。macOS 等非 Windows 平台的释放在期限内轮询根进程退出,因为发出
SIGKILL 后子进程是异步回收的;Windows 等待整个进程树退出。回归见 `engine.rs` 中的
`native_owner_keeps_failed_initialize_identity_until_verified_disposal`、
`wire_owner_retries_failed_initialize_disposal_before_another_start` 和
`wire_owner_cleans_at_most_one_failed_start_before_rejecting_a_backlog`。

### Java 导入安静期与 Windows 跳转缓存

#1052 的两次导入在 Maven 23% 时因连续约 45 秒没有变化的进度通知而被
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ JDT 直启流程。继承插件的库模块、只有测试入口的模块和入
原问题换成一次不确定的错误运行。JDT 对模块化项目返回的
`module/name.Type` 会转换为 JVM 需要的 `-m module/name.Type`。

`java.main` 收到 `javaLaunch` 时同样按 JDT 直启处理,不再以 Maven reactor 字段
作为准入条件:Core 保留 JDT 返回的类路径与模块路径,只有 Maven 项目且请求没有
`buildPrepared` 回执时才追加原有资源处理步骤,Gradle 和无构建系统的目录直接从
JDT 路径启动。没有 `javaLaunch` 的单文件计划保持原有的编译后运行。不要为了
Gradle 再单独编译当前文件,否则同工程的其他类和依赖会缺失。回归见
`java_launch_without_maven_consumes_jdt_paths_without_recompiling_one_file`。

### 阶段 D 的 Provider 资源准备

macOS 已把资源步骤切入 Maven Provider 的公开项目任务:先保存文档、等待当前
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,15 @@ JDT 尚未完成发现时,已有确认入口可沿用上次生成结果;没
悄悄改变返回格式,所以版本必须锁定,并用契约测试和真实 JDT 测试盯住。
- 插件在内部出错时可能返回空列表,产品层无法和“确实没有入口”区分。只能靠
状态机不让失败覆盖旧结果、真实 JDT 测试和日志关联降低风险。
- 传给 `vscode.java.resolveMainClass` 的作用域必须是解析符号链接之后的工作区
目录。JDT 把项目放在规范路径(例如 macOS 的 `/private/tmp`、`/private/var`),
Java Debug 插件再按路径前缀逐字比较“项目是否在作用域内”;如果作用域写的是
`/tmp` 或 `/var` 这样的链接路径,所有项目都会被过滤,结果是一个不带任何诊断
的空列表,运行时表现为“当前文件没有 main 方法”。因此 Rust 引擎在发请求前用
`java_entrypoint_scope_uri` 解析工作区路径,目录无法解析时才原样发送。平台
- `vscode.java.resolveMainClass` 使用当前 JDT 会话的完整查询(空 arguments),
然后由既有 Core normalizer 按打开的工作区与解析链接后的目录筛选源码归属。
2026-11-03 Windows 实机中,同一会话的路径查询返回空,完整查询和项目名查询
都返回 Main。检查打包的 Java Debug 0.53.2 字节码确认:路径查询先用项目自身
所在目录缩小搜索范围,plain Java 的隐式项目位于 JDT 可写缓存,因此在检查
链接源码前就被过滤。仅解析工作区链接仍不能修复此问题。
不按空结果猜测源码、不新增 Main,也不绑定不稳定的 JDT 项目名;使用上游已有
完整查询后仍拒绝相邻或外部工作区的源码。既有链接路径回归继续保护 macOS
`/tmp`、`/var` 等路径;新增真实 plain 文件夹回归保护隐式项目入口发现。平台
代码不要自己拼作用域,也不要假设打开时的路径就是 JDT 看到的路径。
- 同一个根因也影响诊断:JDT 以规范路径发布 `textDocument/publishDiagnostics`
(`/private/tmp/...`),宿主却是用 `/tmp/...` 打开的文档,客户端归约器按文本匹配
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Rust Core 负责校验声明、识别工程、展开每一条命令行,并把

没有声明的能力不报错,也不会出现在界面上。例如 Cargo fixture 没有声明依赖树,Build 工具窗口就不显示依赖区。

`build.detect` 对普通文件根或不存在的根保留空实例结果,这属于检测入口的既有兼容边界。共用工作区扫描器后仍在此入口区分根的类型;真实目录的读取、权限或扫描失败继续返回拒绝,不能把所有 I/O 错误当作“未检测到项目”。不要为了修复某个平台的非目录错误而放宽共用扫描器,也不要让宿主按操作系统错误码猜测空结果。回归见 `detection_returns_empty_for_non_directory_and_missing_workspace_roots`。

字段全集只写在 `shared/contracts/plugins/v1/README.md` 的 “API level 3: build systems” 一节和 `plugin-manifest.schema.json` 里,本 Note 不重复。四个 fixture 各示范一种模型来源,按能力命名而不是按真实插件命名:`build-static-file`(读项目文件,内容用 Cargo)、`build-command-stdout`(解码命令输出,内容用 Go)、`build-command-output-file`(解码命令写出的文件,内容用 Gradle)、`build-host-integration`(交给宿主集成,内容用 Maven)。`build-provider`、`build-provider-language-server` 分别示范 Provider 的两种写法。

### 2. Core 与宿主的分工
Expand Down
11 changes: 11 additions & 0 deletions .agents/skills/write-stable-tests/references/windows-and-rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ and clones a real local repository. The cache retry then exhausted the existing
suite deadline; that secondary timeout does not justify extending the whole
suite. Keep every checkout/clone assertion and the existing request deadlines.

`real_jdtls_lists_entrypoints_in_a_plain_java_folder` gets 240 seconds in the
real-JDT lane. Like the Java 25 case, it cold-starts a real JDT LS, waits up to
90 seconds for readiness, then up to 120 seconds for the plain folder's
invisible project to import and list its entry point. Windows run 41817286665
terminated it at 15.144 seconds under the default watchdog without an
assertion failure, while the same revision passed it in 6.0 seconds on macOS
arm64; the Java 25 case took 39.4 seconds in that run. The budget covers both
in-test deadlines so a silent server fails with the test's own diagnostic
rather than the watchdog. Other real-JDT cases and the suite deadline keep
their budgets.

## Windows verification

Run the PowerShell harness in a real Windows environment. A macOS boundary
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ jobs:
--max-ms 15000 `
--test-prefix lsp::interface::engine::real_jdt_tests:: `
--test-budget lsp::interface::engine::real_jdt_tests::real_jdtls_discovers_builds_and_launches_java_25_entrypoints=600000 `
--test-budget lsp::interface::engine::real_jdt_tests::real_jdtls_lists_entrypoints_in_a_plain_java_folder=240000 `
--build-timeout-ms 600000 `
--suite-timeout-ms 1200000 `
--report .artifacts/test-stability/windows-real-jdt.json
Expand Down
208 changes: 208 additions & 0 deletions macos/Tests/LitheTests/PluginSignatureVectorTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
import CryptoKit
import Foundation
import LithePluginPackageSigning
import Testing

/// Cross-platform acceptance for the package signature: the same fixed
/// vectors answer identically on Swift/CryptoKit and the Windows Rust host.
/// The vectors live in
/// `shared/contracts/plugins/v1/fixtures/signature-vectors.json` and anchor
/// the Ed25519 primitive to the public RFC 8032 test key, so neither
/// platform's own round-trip can drift.
///
/// CryptoKit signs Ed25519 with fresh randomness, so its signature bytes
/// never equal the deterministic RFC 8032 signatures recorded in the
/// fixture. Swift therefore proves equivalence by verification: a recorded
/// signature verifies only over the exact payload it was made for.
struct PluginSignatureVectorTests {
private struct Fixture: Codable {
struct Ed25519: Codable {
let seedHex: String
let publicKeyHex: String
let messageEmptySignatureHex: String
}
struct CanonicalPayload: Codable {
let keyID: String
let pluginID: String
let pluginVersion: String
let files: [String: String]
let payloadBase64: String
let signatureBase64: String
}
struct ContentDigest: Codable {
let files: [String: String]
let digest: String
}

let ed25519: Ed25519
let packageFiles: [String: String]
let canonicalPayload: CanonicalPayload
let contentDigest: ContentDigest
}

private static func fixture() throws -> Fixture {
let url = DeclarativePluginTestSupport.repositoryRoot
.appendingPathComponent("shared/contracts/plugins/v1/fixtures/signature-vectors.json")
return try JSONDecoder().decode(Fixture.self, from: Data(contentsOf: url))
}

private static func bytes(fromHex hex: String) -> Data {
var data = Data()
var index = hex.startIndex
while index < hex.endIndex {
let next = hex.index(index, offsetBy: 2)
data.append(UInt8(hex[index..<next], radix: 16)!)
index = next
}
return data
}

private static func privateKey(from fixture: Fixture) throws -> Curve25519.Signing.PrivateKey {
let seed = bytes(fromHex: fixture.ed25519.seedHex)
return try #require(try? Curve25519.Signing.PrivateKey(rawRepresentation: seed))
}

@Test
func primitiveMatchesTheRFC8032Anchor() throws {
let fixture = try Self.fixture()
let privateKey = try Self.privateKey(from: fixture)
let publicKey = try #require(
try? Curve25519.Signing.PublicKey(rawRepresentation: privateKey.publicKey.rawRepresentation)
)
#expect(Data(publicKey.rawRepresentation).hex == fixture.ed25519.publicKeyHex)
let recorded = Self.bytes(fromHex: fixture.ed25519.messageEmptySignatureHex)
#expect(publicKey.isValidSignature(recorded, for: Data()))
let fresh = try privateKey.signature(for: Data())
#expect(publicKey.isValidSignature(fresh, for: Data()))
}

/// The canonical payload Swift builds from the fixed package is the one
/// the recorded signature covers: the path sorting, token encoding, and
/// file digests are identical across platforms.
@Test
func recordedSignatureCoversTheSwiftCanonicalPayload() throws {
let fixture = try Self.fixture()
let privateKey = try Self.privateKey(from: fixture)
let publicKey = privateKey.publicKey
let root = try makePackage(fixture)
defer { try? FileManager.default.removeItem(at: root) }

let recordedPayload = try #require(Data(base64Encoded: fixture.canonicalPayload.payloadBase64))
let recordedSignature = try #require(Data(base64Encoded: fixture.canonicalPayload.signatureBase64))
#expect(publicKey.isValidSignature(recordedSignature, for: recordedPayload))

let document = try PluginPackageSignature.makeDocument(
packageAt: root,
pluginID: fixture.canonicalPayload.pluginID,
pluginVersion: fixture.canonicalPayload.pluginVersion,
privateKey: privateKey,
keyID: fixture.canonicalPayload.keyID
)
#expect(document.files == fixture.canonicalPayload.files)
try PluginPackageSignature.verify(
packageAt: root,
pluginID: fixture.canonicalPayload.pluginID,
pluginVersion: fixture.canonicalPayload.pluginVersion,
document: document,
publicKey: publicKey
)

// The recorded signature over Swift's own payload proves the payload
// bytes match, because Ed25519 accepts no other message.
let recordedDocument = PluginPackageSignature.Document(
keyID: document.keyID,
pluginID: document.pluginID,
pluginVersion: document.pluginVersion,
files: document.files,
signature: fixture.canonicalPayload.signatureBase64
)
try PluginPackageSignature.verify(
packageAt: root,
pluginID: fixture.canonicalPayload.pluginID,
pluginVersion: fixture.canonicalPayload.pluginVersion,
document: recordedDocument,
publicKey: publicKey
)
}

/// The content digest over the fixed package matches the shared answer,
/// including the non-ASCII file names.
@Test
func contentDigestMatchesTheSharedVector() throws {
let fixture = try Self.fixture()
let root = try makePackage(fixture)
defer { try? FileManager.default.removeItem(at: root) }

let digest = try PluginPackageSignature.contentDigest(packageAt: root)
#expect(digest == fixture.contentDigest.digest)
}

/// The signature document of the shared vector also verifies after a
/// write/read round trip through the on-disk format.
@Test
func recordedDocumentVerifiesAfterWriteAndRead() throws {
let fixture = try Self.fixture()
let privateKey = try Self.privateKey(from: fixture)
let root = try makePackage(fixture)
defer { try? FileManager.default.removeItem(at: root) }

var files: [String: String] = [:]
for (path, digest) in fixture.canonicalPayload.files {
files[path] = digest
}
let document = PluginPackageSignature.Document(
keyID: fixture.canonicalPayload.keyID,
pluginID: fixture.canonicalPayload.pluginID,
pluginVersion: fixture.canonicalPayload.pluginVersion,
files: files,
signature: fixture.canonicalPayload.signatureBase64
)
try PluginPackageSignature.write(document, to: root)
let read = try PluginPackageSignature.read(from: root)
try PluginPackageSignature.verify(
packageAt: root,
pluginID: fixture.canonicalPayload.pluginID,
pluginVersion: fixture.canonicalPayload.pluginVersion,
document: read,
trustedKeys: [
fixture.canonicalPayload.keyID: privateKey.publicKey
]
)

// Any changed file is rejected with the same digest mismatch the
// Windows host reports.
try Data("changed".utf8).write(to: root.appendingPathComponent("plugin.json"))
#expect(throws: PluginPackageSignature.Error.self) {
try PluginPackageSignature.verify(
packageAt: root,
pluginID: fixture.canonicalPayload.pluginID,
pluginVersion: fixture.canonicalPayload.pluginVersion,
document: read,
trustedKeys: [
fixture.canonicalPayload.keyID: privateKey.publicKey
]
)
}
}

/// Materializes the fixture's package tree with its UTF-8 file contents.
private func makePackage(_ fixture: Fixture) throws -> URL {
let root = FileManager.default.temporaryDirectory
.appendingPathComponent("lithe-signature-vector-\(UUID().uuidString)", isDirectory: true)
for (relativePath, content) in fixture.packageFiles {
let target = root.appendingPathComponent(relativePath)
try FileManager.default.createDirectory(
at: target.deletingLastPathComponent(),
withIntermediateDirectories: true
)
try Data(content.utf8).write(to: target)
}
return root
}
}

extension Data {
fileprivate var hex: String {
map { String(format: "%02x", $0) }.joined()
}
}
58 changes: 56 additions & 2 deletions rust/lithe-core/src/build/detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ use super::manifest::{BuildSystemDeclaration, ModelSource, Nesting, OptionKind,
use super::options;
use super::outputs::{model_value, read_model, source_marker};
use crate::plugins::declarative::{validate_manifest_value, PluginRejection, Validation};
use crate::protocol::CoreError;
use serde::Deserialize;
use serde_json::{json, Value};
use std::collections::{BTreeMap, BTreeSet};
use std::io::ErrorKind;
use std::path::Path;

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
Expand Down Expand Up @@ -136,6 +139,32 @@ fn instance(
instance
}

// Detection historically accepts absent/non-directory roots as an empty view.
// Keep that boundary local: scans of real directories must still report I/O
// failures, and the shared run scanner retains its required-root semantics.
// The check goes through workspace I/O so a remote root, including one opened
// through a host symbolic link, is examined on the owning host rather than in
// the unmaterialized local projection.
fn scan_directory_root(
root: &Path,
scan: impl FnOnce(&Path) -> Result<Vec<crate::execution::DirectoryContext>, CoreError>,
) -> Validation<Vec<crate::execution::DirectoryContext>> {
match crate::remote::workspace_io::metadata(root) {
Ok(metadata) if !metadata.is_dir() => return Ok(Vec::new()),
Err(error) if matches!(error.kind(), ErrorKind::NotFound | ErrorKind::NotADirectory) => {
return Ok(Vec::new());
}
Err(error) => {
return Err(PluginRejection::new(
"plugin.build.invalidSelection",
error.to_string(),
));
}
Ok(_) => {}
}
scan(root).map_err(|error| PluginRejection::new("plugin.build.invalidSelection", error.message))
}

/// `build.detect`: every instance of every build system the enabled plugins
/// declare. Invalid manifests are reported, not fatal; when two plugins
/// declare one build-system ID, the higher priority answers for it.
Expand Down Expand Up @@ -192,8 +221,7 @@ pub(crate) fn detect(request: DetectRequest) -> Validation<Value> {
if owners.is_empty() {
return Ok(json!({ "instances": [], "rejected": rejected, "shadowed": shadowed }));
}
let directories = crate::execution::scan(&workspace.path)
.map_err(|error| PluginRejection::new("plugin.build.invalidSelection", error.message))?;
let directories = scan_directory_root(&workspace.path, crate::execution::scan)?;
let empty = BTreeMap::new();
let mut seen = BTreeSet::new();
let mut instances = Vec::new();
Expand Down Expand Up @@ -243,3 +271,29 @@ pub(crate) fn detect(request: DetectRequest) -> Validation<Value> {
"shadowed": shadowed,
}))
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn existing_directory_scan_errors_are_not_empty_detections() {
// A real readable directory passes metadata. Inject the subsequent
// failure so ACL differences and elevated test users cannot bypass it.
let root = Path::new(env!("CARGO_MANIFEST_DIR"));
assert!(root.is_dir());
for kind in [
ErrorKind::PermissionDenied,
ErrorKind::NotFound,
ErrorKind::Other,
] {
let error = scan_directory_root(root, |scanned| {
assert_eq!(scanned, root);
Err(std::io::Error::new(kind, "controlled directory scan failure").into())
})
.expect_err("an existing directory's scan failure must reject detection");
assert_eq!(error.code, "plugin.build.invalidSelection");
assert_eq!(error.message, "controlled directory scan failure");
}
}
}
Loading
Loading