host-rpc-log-level.test.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { describe, expect, it } from "vitest";
  2. import { resolveRpcLogLevel } from "../src/host/rpcLogLevel.js";
  3. describe("host RPC 日志级别映射", () => {
  4. it("后台 Bash 成功轮询仅记 debug,失败仍记 warn", () => {
  5. expect(resolveRpcLogLevel("[rpc:call] zcode-agent.backgroundBashOutputV4 OK (1.5ms)")).toBe(
  6. "debug",
  7. );
  8. expect(resolveRpcLogLevel("[rpc:call] zcode-agent.backgroundBashOutputV4 FAIL (1.5ms)")).toBe(
  9. "warn",
  10. );
  11. expect(
  12. resolveRpcLogLevel("[rpc:call] zcode-agent.otherBackgroundBashOutputV4 OK (1.5ms)"),
  13. ).toBe("info");
  14. });
  15. it("RPC 成功日志应记为 info", () => {
  16. expect(resolveRpcLogLevel("[rpc:call] setting.get OK (1.5ms)")).toBe("info");
  17. });
  18. it("RPC 失败日志应记为 warn", () => {
  19. expect(resolveRpcLogLevel("[rpc:call] setting.get FAIL (1.5ms)")).toBe("warn");
  20. });
  21. it("provider registry 尚未就绪的 runtime identity 查询应记为 info", () => {
  22. const error = Object.assign(new Error("provider not ready"), {
  23. code: "ZCODE_AGENT_PROVIDER_NOT_READY",
  24. });
  25. expect(
  26. resolveRpcLogLevel(
  27. "[rpc:call] zcode-session.getWorkspaceRuntimeIdentity FAIL (12.0ms)",
  28. error,
  29. ),
  30. ).toBe("info");
  31. });
  32. });