webRemoteTerminalProbe.test.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { execFile } from "node:child_process";
  2. import { promisify } from "node:util";
  3. import { describe, expect, it } from "vitest";
  4. import { buildTerminalProbeCommand } from "#e2e/helpers/web-remote-terminal-probe";
  5. const run = promisify(execFile);
  6. describe("MRO04 按终端目标选择探针", () => {
  7. it("本地探针通过 Node 输出真实父进程、目录和标记,不要求 POSIX shell", async () => {
  8. const command = buildTerminalProbeCommand("LOCAL", "local");
  9. // 本地 PowerShell 与 POSIX shell 共用 Node CLI;提取实际脚本执行,不复制探针逻辑。
  10. const script = command.match(/^node -e "([^"]+)"$/u)?.[1];
  11. expect(script).toBeTruthy();
  12. expect(command).not.toContain("E2E_MRO04_LOCAL");
  13. const { stdout } = await run(process.execPath, ["-e", script!]);
  14. expect(stdout.trim().split(/\r?\n/u)).toEqual([
  15. `PTY_OWNER=${process.pid}`,
  16. process.cwd(),
  17. "E2E_MRO04_LOCAL",
  18. ]);
  19. });
  20. it.skipIf(process.platform === "win32")(
  21. "Linux SSH 探针无需远端 Node,输出 shell PID、目录和标记",
  22. async () => {
  23. const command = buildTerminalProbeCommand("SSH", "linux-ssh");
  24. expect(command).not.toContain("E2E_MRO04_SSH");
  25. expect(command).not.toContain("node");
  26. const { stdout } = await run("/bin/sh", ["-c", command]);
  27. const [pid, cwd, marker] = stdout.trim().split(/\r?\n/u);
  28. expect(pid).toMatch(/^PTY_OWNER=[1-9]\d*$/u);
  29. expect(cwd).toBe(process.cwd());
  30. expect(marker).toBe("E2E_MRO04_SSH");
  31. },
  32. );
  33. });