mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-20 21:43:56 +08:00
- 新增 JMX/Endpoint/Agent 三种 JVM 连接模式与配置归一化链路 - 支持资源浏览、变更预览、写入应用、审计记录与只读约束 - 接入 AI 结构化写入计划与诊断计划回填能力 - 新增 Agent Bridge、Arthas Tunnel、JMX Helper 诊断传输实现 - 增加诊断控制台、命令模板、输出历史与自动补全交互 - 补齐前后端契约、运行夹具与 JVM 相关回归测试
120 lines
3.1 KiB
TypeScript
120 lines
3.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
parseJVMDiagnosticPlan,
|
|
resolveJVMDiagnosticPlanTargetTabId,
|
|
} from "./jvmDiagnosticPlan";
|
|
|
|
describe("jvmDiagnosticPlan", () => {
|
|
it("parses arthas-style diagnostic plan payload", () => {
|
|
const plan = parseJVMDiagnosticPlan(`{
|
|
"intent": "trace_slow_method",
|
|
"transport": "agent-bridge",
|
|
"command": "trace com.foo.OrderService submitOrder '#cost > 100'",
|
|
"riskLevel": "medium",
|
|
"reason": "定位慢调用"
|
|
}`);
|
|
|
|
expect(plan?.command).toContain("trace com.foo.OrderService");
|
|
expect(plan?.riskLevel).toBe("medium");
|
|
});
|
|
|
|
it("parses fenced json blocks mixed with analysis text", () => {
|
|
const plan = parseJVMDiagnosticPlan(
|
|
[
|
|
"建议先观察再做下一步:",
|
|
"```json",
|
|
'{"intent":"dump_threads","transport":"arthas-tunnel","command":"thread -n 5","riskLevel":"low","reason":"观察阻塞线程","expectedSignals":["Top N busy threads"]}',
|
|
"```",
|
|
].join("\n"),
|
|
);
|
|
|
|
expect(plan).toEqual({
|
|
intent: "dump_threads",
|
|
transport: "arthas-tunnel",
|
|
command: "thread -n 5",
|
|
riskLevel: "low",
|
|
reason: "观察阻塞线程",
|
|
expectedSignals: ["Top N busy threads"],
|
|
});
|
|
});
|
|
|
|
it("returns null for malformed diagnostic payload", () => {
|
|
expect(parseJVMDiagnosticPlan('{"command":1}')).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("resolveJVMDiagnosticPlanTargetTabId", () => {
|
|
it("prefers the original diagnostic tab when context still matches", () => {
|
|
expect(
|
|
resolveJVMDiagnosticPlanTargetTabId(
|
|
[
|
|
{
|
|
id: "tab-diagnostic",
|
|
title: "诊断控制台",
|
|
type: "jvm-diagnostic",
|
|
connectionId: "conn-orders",
|
|
},
|
|
],
|
|
[
|
|
{
|
|
id: "conn-orders",
|
|
config: {
|
|
type: "jvm",
|
|
host: "orders.internal",
|
|
port: 9010,
|
|
user: "",
|
|
jvm: {
|
|
diagnostic: {
|
|
transport: "agent-bridge",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
{
|
|
tabId: "tab-diagnostic",
|
|
connectionId: "conn-orders",
|
|
transport: "agent-bridge",
|
|
},
|
|
),
|
|
).toBe("tab-diagnostic");
|
|
});
|
|
|
|
it("rejects fallback tabs whose connection transport does not match", () => {
|
|
expect(
|
|
resolveJVMDiagnosticPlanTargetTabId(
|
|
[
|
|
{
|
|
id: "tab-diagnostic",
|
|
title: "诊断控制台",
|
|
type: "jvm-diagnostic",
|
|
connectionId: "conn-orders",
|
|
},
|
|
],
|
|
[
|
|
{
|
|
id: "conn-orders",
|
|
config: {
|
|
type: "jvm",
|
|
host: "orders.internal",
|
|
port: 9010,
|
|
user: "",
|
|
jvm: {
|
|
diagnostic: {
|
|
transport: "arthas-tunnel",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
],
|
|
{
|
|
tabId: "tab-missing",
|
|
connectionId: "conn-orders",
|
|
transport: "agent-bridge",
|
|
},
|
|
),
|
|
).toBe("");
|
|
});
|
|
});
|