mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-30 22:00:21 +00:00
test: speed up core runtime suites
This commit is contained in:
@@ -1,21 +1,22 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, describe, expect, it, vi } from "vitest";
|
||||
|
||||
afterEach(() => {
|
||||
vi.resetModules();
|
||||
vi.doUnmock("./launchd.js");
|
||||
});
|
||||
const resolveGatewayLogPathsMock = vi.fn(() => ({
|
||||
stdoutPath: "C:\\tmp\\openclaw-state\\logs\\gateway.log",
|
||||
stderrPath: "C:\\tmp\\openclaw-state\\logs\\gateway.err.log",
|
||||
}));
|
||||
|
||||
vi.mock("./launchd.js", () => ({
|
||||
resolveGatewayLogPaths: resolveGatewayLogPathsMock,
|
||||
}));
|
||||
|
||||
let buildPlatformRuntimeLogHints: typeof import("./runtime-hints.js").buildPlatformRuntimeLogHints;
|
||||
|
||||
describe("buildPlatformRuntimeLogHints", () => {
|
||||
it("strips windows drive prefixes from darwin display paths", async () => {
|
||||
vi.doMock("./launchd.js", () => ({
|
||||
resolveGatewayLogPaths: () => ({
|
||||
stdoutPath: "C:\\tmp\\openclaw-state\\logs\\gateway.log",
|
||||
stderrPath: "C:\\tmp\\openclaw-state\\logs\\gateway.err.log",
|
||||
}),
|
||||
}));
|
||||
|
||||
const { buildPlatformRuntimeLogHints } = await import("./runtime-hints.js");
|
||||
beforeAll(async () => {
|
||||
({ buildPlatformRuntimeLogHints } = await import("./runtime-hints.js"));
|
||||
});
|
||||
|
||||
it("strips windows drive prefixes from darwin display paths", () => {
|
||||
expect(
|
||||
buildPlatformRuntimeLogHints({
|
||||
platform: "darwin",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { execSchtasks } from "./schtasks-exec.js";
|
||||
|
||||
const runCommandWithTimeout = vi.hoisted(() => vi.fn());
|
||||
|
||||
@@ -6,8 +7,6 @@ vi.mock("../process/exec.js", () => ({
|
||||
runCommandWithTimeout: (...args: unknown[]) => runCommandWithTimeout(...args),
|
||||
}));
|
||||
|
||||
const { execSchtasks } = await import("./schtasks-exec.js");
|
||||
|
||||
beforeEach(() => {
|
||||
runCommandWithTimeout.mockReset();
|
||||
});
|
||||
|
||||
@@ -12,6 +12,7 @@ import { splitArgsPreservingQuotes } from "./arg-split.js";
|
||||
import { parseSystemdExecStart } from "./systemd-unit.js";
|
||||
import {
|
||||
isNonFatalSystemdInstallProbeError,
|
||||
isSystemdServiceEnabled,
|
||||
isSystemdUserServiceAvailable,
|
||||
parseSystemdShow,
|
||||
readSystemdServiceExecStart,
|
||||
@@ -71,7 +72,6 @@ function assertMachineUserSystemctlArgs(args: string[], user: string, ...command
|
||||
}
|
||||
|
||||
async function readManagedServiceEnabled(env: NodeJS.ProcessEnv = { HOME: TEST_MANAGED_HOME }) {
|
||||
const { isSystemdServiceEnabled } = await import("./systemd.js");
|
||||
vi.spyOn(fs, "access").mockResolvedValue(undefined);
|
||||
return isSystemdServiceEnabled({ env });
|
||||
}
|
||||
@@ -180,7 +180,6 @@ describe("isSystemdServiceEnabled", () => {
|
||||
});
|
||||
|
||||
it("returns false without calling systemctl when the managed unit file is missing", async () => {
|
||||
const { isSystemdServiceEnabled } = await import("./systemd.js");
|
||||
const err = new Error("missing unit") as NodeJS.ErrnoException;
|
||||
err.code = "ENOENT";
|
||||
vi.spyOn(fs, "access").mockRejectedValueOnce(err);
|
||||
@@ -286,7 +285,6 @@ describe("isSystemdServiceEnabled", () => {
|
||||
});
|
||||
|
||||
it("throws when systemctl is-enabled fails for non-state errors", async () => {
|
||||
const { isSystemdServiceEnabled } = await import("./systemd.js");
|
||||
vi.spyOn(fs, "access").mockResolvedValue(undefined);
|
||||
execFileMock
|
||||
.mockImplementationOnce((_cmd, args, _opts, cb) => {
|
||||
@@ -309,7 +307,6 @@ describe("isSystemdServiceEnabled", () => {
|
||||
});
|
||||
|
||||
it("returns false when systemctl is-enabled exits with code 4 (not-found)", async () => {
|
||||
const { isSystemdServiceEnabled } = await import("./systemd.js");
|
||||
vi.spyOn(fs, "access").mockResolvedValue(undefined);
|
||||
execFileMock.mockImplementationOnce((_cmd, _args, _opts, cb) => {
|
||||
// On Ubuntu 24.04, `systemctl --user is-enabled <unit>` exits with
|
||||
|
||||
Reference in New Issue
Block a user