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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ node scripts/language-import/test.mjs <Lithe检出> <Java插件目录> <托管JD
后端脚本测试覆盖成功抑制、真实失败唯一性、可选文件缺失及损坏/超大属性文件,也覆盖主动中止与异常大报文后的进程清理。
驱动限制帧 16 MiB、stderr 尾部 64 KiB、诊断 1000 条;Windows 用系统进程树终止,避免对负 PID 的 Unix 操作失效后留下 JVM。
这些生命周期回归已在实际 Java 8 和原生 Windows 的 Java 8 后端运行。
既有测试驱动的未使用 Maven 分支另见 [#1880](https://github.com/1lck/Lithe-IDEA/issues/1880)。
`scripts/backend-client.mjs` 直接启动 Gradle JAR,默认协商 `litheFunctions` 0;当前文件运行测试显式选择 `litheBuild` 1。
同一迁移后 JAR、同一 Java 8、六对交错测量,仅改变 JVM 堆选项:初始化并执行八次真实配置查询后的 RSS 中位数从
45.98 MiB 变为 43.80 MiB(-4.72%,benchstat p=0.002);初始化加八次查询的时间为 78.39/78.44 ms,无显著差异(p=0.485)。
这是配置后端的单点 RSS,不是峰值或整套 Java 支持的内存;128 MiB 是 Java 堆上限,不是进程总内存上限。
Expand Down
18 changes: 9 additions & 9 deletions scripts/backend-client.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Talks to lib/lithe-maven-backend.jar the way Lithe does: LSP base-protocol
// frames over the process's stdio, `initialize` offering litheBuild 1, then
// lithe/build/* requests. Every wait is bounded, and the backend runs in its
// own process group so a test can always end whatever it left behind.
// Drives the Gradle settings backend and current-file run provider over LSP
// stdio frames. Settings tests offer litheFunctions 0 by default; the run
// provider test explicitly offers litheBuild 1. Every wait is bounded, and
// the backend runs in its own process group for cleanup after a failure.
import { execFileSync, spawn } from "node:child_process";
import { pathToFileURL } from "node:url";

Expand All @@ -18,12 +18,12 @@ export class BackendClient {
stderr = "";
diagnostics = [];

/** Starts `java -jar <jar> --state <state>` (or `args`); `javaOptions` go before `-jar`. */
constructor({ java = "java", jar, state, env = process.env, javaOptions = [], timeoutMs = WAIT_MS, args, hostRequests = {} }) {
/** Starts `java -jar <jar>`; `javaOptions` go before `-jar`. */
constructor({ java = "java", jar, env = process.env, javaOptions = [], timeoutMs = WAIT_MS, hostRequests = {} }) {
this.timeoutMs = timeoutMs;
// Answers to requests the backend sends to the host, keyed by method.
this.hostRequests = hostRequests;
this.child = spawn(java, [...javaOptions, "-jar", jar, ...(args ?? ["--state", state])], {
this.child = spawn(java, [...javaOptions, "-jar", jar], {
env, stdio: ["pipe", "pipe", "pipe"], detached: process.platform !== "win32", windowsHide: true,
});
this.exited = new Promise((resolve) => this.child.once("exit", (code, signal) => {
Expand Down Expand Up @@ -75,12 +75,12 @@ export class BackendClient {
this.notify("$/cancelRequest", { id });
}

async initialize(root, { functions = false, buildVersion = 0 } = {}) {
async initialize(root, { buildVersion } = {}) {
const result = await this.request("initialize", {
processId: process.pid,
rootUri: pathToFileURL(root).href,
capabilities: { experimental: {
...(functions ? { litheFunctions: { versions: [0] } } : { litheBuild: { versions: [buildVersion] } }),
...(buildVersion === undefined ? { litheFunctions: { versions: [0] } } : { litheBuild: { versions: [buildVersion] } }),
litheLogging: { versions: [0] },
} },
});
Expand Down
8 changes: 4 additions & 4 deletions scripts/test-backend.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const step = async (name, body) => {
};
try {
client = new BackendClient({
java, jar, args: [],
java, jar,
// The Java tool definition owns the JAR entry switch. This SDK probe
// exercises the packaged JVM options; Viva integration tests additionally
// verify Core's tool-template instantiation and the real entry path.
Expand Down Expand Up @@ -87,7 +87,7 @@ try {
},
},
});
const initialized = await client.initialize(workspace, { functions: true });
const initialized = await client.initialize(workspace);
assert.deepEqual(initialized.capabilities.experimental.litheFunctions.functions, [{ id: "compiler.prepareSettings" }, { id: "compiler.settings" }, { id: "languageImport.settings" }, { id: "libraries.settings" }]);
const invoke = (workspaceRoot, context = { contextID: "ctx", generation: 1 }, caller) => client.send("lithe/function/invoke", {
functionID: "languageImport.settings", operationID: `op-${Math.random()}`, params: { workspaceRoot }, ...(context ? { context } : {}), ...(caller ? { caller } : {}),
Expand Down Expand Up @@ -190,9 +190,9 @@ try {
});
for (const fault of ["abort", "oversized frame"]) {
await step(`the driver reaps a backend after ${fault}`, async () => {
const peer = new BackendClient({java, jar, args: [], javaOptions: [`-Duser.home=${home}`]});
const peer = new BackendClient({java, jar, javaOptions: [`-Duser.home=${home}`]});
try {
await peer.initialize(workspace, {functions: true});
await peer.initialize(workspace);
if (fault === "abort") peer.kill();
else peer.child.stdout.emit("data", Buffer.from("Content-Length: 1000000000\r\n\r\n"));
await bounded(peer.exited, "faulted backend disposal", 2000);
Expand Down
2 changes: 1 addition & 1 deletion scripts/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ try {
"Gradle must handle current-file Run and Debug through its build provider");
const client = new BackendClient({
jar: join(pluginDir, "lib", "lithe-gradle-run-provider.jar"),
args: [], timeoutMs: COMMAND_TIMEOUT_MS,
timeoutMs: COMMAND_TIMEOUT_MS,
});
try {
const initialized = await client.initialize(realpathSync(root), { buildVersion: 1 });
Expand Down
Loading