mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 01:28:27 +00:00
perf(test): optimize heavy suites and stabilize lock timing
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import * as tailscale from "./tailscale.js";
|
||||
|
||||
const {
|
||||
@@ -12,7 +12,18 @@ const {
|
||||
const tailscaleBin = expect.stringMatching(/tailscale$/i);
|
||||
|
||||
describe("tailscale helpers", () => {
|
||||
const originalForcedBinary = process.env.OPENCLAW_TEST_TAILSCALE_BINARY;
|
||||
|
||||
beforeEach(() => {
|
||||
process.env.OPENCLAW_TEST_TAILSCALE_BINARY = "tailscale";
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (originalForcedBinary === undefined) {
|
||||
delete process.env.OPENCLAW_TEST_TAILSCALE_BINARY;
|
||||
} else {
|
||||
process.env.OPENCLAW_TEST_TAILSCALE_BINARY = originalForcedBinary;
|
||||
}
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
@@ -65,7 +76,6 @@ describe("tailscale helpers", () => {
|
||||
it("enableTailscaleServe attempts normal first, then sudo", async () => {
|
||||
// 1. First attempt fails
|
||||
// 2. Second attempt (sudo) succeeds
|
||||
vi.spyOn(tailscale, "getTailscaleBinary").mockResolvedValue("tailscale");
|
||||
const exec = vi
|
||||
.fn()
|
||||
.mockRejectedValueOnce(new Error("permission denied"))
|
||||
@@ -89,7 +99,6 @@ describe("tailscale helpers", () => {
|
||||
});
|
||||
|
||||
it("enableTailscaleServe does NOT use sudo if first attempt succeeds", async () => {
|
||||
vi.spyOn(tailscale, "getTailscaleBinary").mockResolvedValue("tailscale");
|
||||
const exec = vi.fn().mockResolvedValue({ stdout: "" });
|
||||
|
||||
await enableTailscaleServe(3000, exec as never);
|
||||
@@ -103,7 +112,6 @@ describe("tailscale helpers", () => {
|
||||
});
|
||||
|
||||
it("disableTailscaleServe uses fallback", async () => {
|
||||
vi.spyOn(tailscale, "getTailscaleBinary").mockResolvedValue("tailscale");
|
||||
const exec = vi
|
||||
.fn()
|
||||
.mockRejectedValueOnce(new Error("permission denied"))
|
||||
@@ -125,7 +133,6 @@ describe("tailscale helpers", () => {
|
||||
// 1. status (success)
|
||||
// 2. enable (fails)
|
||||
// 3. enable sudo (success)
|
||||
vi.spyOn(tailscale, "getTailscaleBinary").mockResolvedValue("tailscale");
|
||||
const exec = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce({ stdout: JSON.stringify({ BackendState: "Running" }) }) // status
|
||||
@@ -166,7 +173,6 @@ describe("tailscale helpers", () => {
|
||||
});
|
||||
|
||||
it("enableTailscaleServe skips sudo on non-permission errors", async () => {
|
||||
vi.spyOn(tailscale, "getTailscaleBinary").mockResolvedValue("tailscale");
|
||||
const exec = vi.fn().mockRejectedValueOnce(new Error("boom"));
|
||||
|
||||
await expect(enableTailscaleServe(3000, exec as never)).rejects.toThrow("boom");
|
||||
@@ -175,7 +181,6 @@ describe("tailscale helpers", () => {
|
||||
});
|
||||
|
||||
it("enableTailscaleServe rethrows original error if sudo fails", async () => {
|
||||
vi.spyOn(tailscale, "getTailscaleBinary").mockResolvedValue("tailscale");
|
||||
const originalError = Object.assign(new Error("permission denied"), {
|
||||
stderr: "permission denied",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user