fix: harden CLI parsing, MCP startup and release integrity
This commit is contained in:
1 parent
f0902f5f20
commit
103ead0fe5
53 files changed
+3713
-1945
No files matched your search
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bun
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtempSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { resolve, join } from "node:path";
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { Client } from "@modelcontextprotocol/client";
|
||||
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
||||
|
||||
const binary = resolve(process.argv[2] || "dist/bin/hose-use");
|
||||
const plugin = process.argv.includes("--plugin");
|
||||
const command = plugin ? process.execPath : binary;
|
||||
const prefix = plugin ? [binary] : [];
|
||||
const cwd = mkdtempSync(join(tmpdir(), "hose-binary-smoke-"));
|
||||
// The binary must work without Bun on PATH or a source checkout in cwd.
|
||||
const env = { PATH: process.platform === "win32" ? process.env.SystemRoot || "C:\\Windows" : "/usr/bin:/bin", HOSE_USE_MCP_ENABLED: "true", HOSE_CONFIG_FILE: join(cwd, "config.json"), HOSE_ENTERPRISES_DIR: cwd };
|
||||
const client = new Client({ name: "hose-binary-smoke", version: "1.0.0" });
|
||||
const transport = new StdioClientTransport({ command, args: plugin ? prefix : ["mcp", "serve"], cwd, env, stderr: "pipe" });
|
||||
let stderr = "";
|
||||
transport.stderr?.on("data", chunk => { stderr += chunk.toString(); });
|
||||
const deadline = setTimeout(() => { void client.close(); }, 15_000);
|
||||
try {
|
||||
const version = spawnSync(command, [...prefix, ...(plugin ? ["--hose-use-cli"] : []), "version", "--json"], { cwd, env, encoding: "utf8", timeout: 5000 });
|
||||
assert.equal(version.status, 0, version.stderr);
|
||||
assert.ok(JSON.parse(version.stdout).version);
|
||||
await client.connect(transport, { timeout: 5000 });
|
||||
const tools = await client.listTools();
|
||||
assert.deepEqual(tools.tools.map(tool => tool.name), ["hose_cli"]);
|
||||
const result = await client.callTool({ name: "hose_cli", arguments: { command: "version --json" } });
|
||||
assert.ok(!result.isError, JSON.stringify(result));
|
||||
const text = (result.content as Array<{ type: string; text?: string }>).find(c => c.type === "text")?.text;
|
||||
assert.equal(JSON.parse(text || "").version, JSON.parse(version.stdout).version);
|
||||
const invalid = await client.callTool({ name: "hose_cli", arguments: { command: "bill list --limitt 5 --json" } });
|
||||
assert.equal(invalid.isError, true);
|
||||
assert.match(JSON.stringify(invalid.content), /未知选项/);
|
||||
console.log(plugin ? "Plugin bundle version and MCP stdio verified with its Bun runtime." : "Binary version and MCP stdio verified without Bun or source files.");
|
||||
} catch (error) {
|
||||
throw new Error(`Binary smoke failed: ${error instanceof Error ? error.message : error}\n${stderr}`);
|
||||
} finally {
|
||||
clearTimeout(deadline);
|
||||
await client.close();
|
||||
rmSync(cwd, { recursive: true, force: true });
|
||||
}
|
||||
Reference in new issue
Block a user