Add runtime detection and unified mcp and probe CLI commands

This commit is contained in:
gitea committed 2026-08-25 13:49:00 +08:00
1 parent 551fb9177f
commit b109f3f49f
8 files changed
+118 -19

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
import { describe, expect, test } from "bun:test";
import { isCompiledBinary, resolveAppRoot, resolveDefaultLauncher } from "./runtime.js";
describe("runtime detection and launcher", () => {
test("isCompiledBinary detects bun runtime executable vs standalone binary", () => {
expect(isCompiledBinary("/Users/user/.bun/bin/bun", "file:///Users/user/code/src/cli.ts")).toBe(false);
expect(isCompiledBinary("C:\\Users\\user\\.bun\\bin\\bun.exe", "file:///C:/code/src/cli.ts")).toBe(false);
expect(isCompiledBinary("/usr/local/bin/seal-home", "file:///Users/user/code/src/cli.ts")).toBe(true);
expect(isCompiledBinary("/Users/user/.bun/bin/bun", "file:///$bunfs/root/src/cli.ts")).toBe(true);
});
test("resolveAppRoot returns cwd for compiled binary and project root for source", () => {
const sourceRoot = resolveAppRoot("/Users/user/code/src/cli.ts", false);
expect(sourceRoot).toBe("/Users/user/code");
const binaryRoot = resolveAppRoot(undefined, true);
expect(binaryRoot).toBe(process.cwd());
});
test("resolveDefaultLauncher configures args based on compiled mode", () => {
const sourceLauncher = resolveDefaultLauncher("/Users/user/code/src/cli.ts", false, "/path/to/bun");
expect(sourceLauncher).toEqual({
command: "/path/to/bun",
args: ["/Users/user/code/src/cli.ts"]
});
const binaryLauncher = resolveDefaultLauncher("/ignored", true, "/usr/local/bin/seal-home");
expect(binaryLauncher).toEqual({
command: "/usr/local/bin/seal-home",
args: []
});
});
});
+40
View File
@@ -0,0 +1,40 @@
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
export function isCompiledBinary(execPath = process.execPath, metaUrl = import.meta.url): boolean {
if (metaUrl.includes("/$bunfs/") || metaUrl.includes("\\$bunfs\\")) {
return true;
}
const lower = execPath.toLowerCase().replace(/\\/g, "/");
return !lower.endsWith("/bun") && !lower.endsWith("/bun.exe");
}
export function resolveAppRoot(entryFile?: string, isCompiled = isCompiledBinary()): string {
if (isCompiled) {
return process.cwd();
}
const file = entryFile || fileURLToPath(import.meta.url);
return dirname(dirname(file));
}
export type LauncherConfig = {
command: string;
args?: string[];
};
export function resolveDefaultLauncher(
entryFile: string,
isCompiled = isCompiledBinary(),
execPath = process.execPath
): LauncherConfig {
if (isCompiled) {
return {
command: execPath,
args: []
};
}
return {
command: execPath,
args: [entryFile]
};
}