sshHostProbe.test.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. import { runInNewContext } from "node:vm";
  2. import { afterEach, expect, it, vi } from "vitest";
  3. import { readHostProcesses } from "./e2e/helpers/ssh-remote-p0.js";
  4. vi.mock("./e2e/helpers/desktop-app.js", () => ({}));
  5. vi.mock("./e2e/helpers/custom-openai-provider-store.js", () => ({}));
  6. vi.mock("./e2e/helpers/v4-conversation.js", () => ({}));
  7. afterEach(() => vi.unstubAllGlobals());
  8. it("Host 探针只读 Main 指标,不打开资源管理器或切换业务窗口", async () => {
  9. const electron = {
  10. app: {
  11. getAppMetrics: () => [
  12. { pid: 11, type: "Browser" },
  13. {
  14. pid: 22,
  15. type: "Utility",
  16. name: "zcode-host-local-1",
  17. serviceName: "node.mojom.NodeService",
  18. },
  19. { pid: 33, type: "Utility", name: "zcode-cron-scheduler" },
  20. ],
  21. },
  22. };
  23. vi.stubGlobal("browser", {
  24. electron: {
  25. execute: async (fn: (arg: unknown) => unknown) =>
  26. runInNewContext(`(${fn.toString()})(electron)`, { electron }),
  27. },
  28. waitUntil: async (fn: () => Promise<boolean>) => {
  29. expect(await fn()).toBe(true);
  30. },
  31. });
  32. expect(await readHostProcesses()).toEqual([{ pid: 22, name: "zcode-host-local-1" }]);
  33. });