mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 05:16:23 -06:00
test: speed up and stabilize full suite
This commit is contained in:
@@ -433,6 +433,8 @@ async function runConfigCommand(args: string[]) {
|
||||
describe("config cli", () => {
|
||||
beforeAll(async () => {
|
||||
({ registerConfigCli } = await import("./config-cli.js"));
|
||||
const { resolveConfigSecretTargetByPath } = await import("../secrets/target-registry.js");
|
||||
resolveConfigSecretTargetByPath(["channels", "googlechat", "serviceAccount"]);
|
||||
sharedProgram = new Command();
|
||||
sharedProgram.exitOverride();
|
||||
registerConfigCli(sharedProgram);
|
||||
|
||||
@@ -3,7 +3,7 @@ import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { Command } from "commander";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { withEnvOverride } from "../config/test-helpers.js";
|
||||
import { GatewayLockError } from "../infra/gateway-lock.js";
|
||||
import { registerGatewayCli } from "./gateway-cli.js";
|
||||
@@ -147,6 +147,13 @@ function firstMockArg(mock: { mock: { calls: ReadonlyArray<ReadonlyArray<unknown
|
||||
}
|
||||
|
||||
describe("gateway-cli coverage", () => {
|
||||
beforeAll(async () => {
|
||||
// Gateway startup intentionally primes this large graph before installing
|
||||
// signal handlers. Load it as suite setup so failure-path timings measure
|
||||
// the lifecycle behavior rather than the one-time module parse.
|
||||
await import("./gateway-cli/lifecycle.runtime.js");
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
gatewayProgram = createGatewayProgram();
|
||||
runtimeLogs.length = 0;
|
||||
|
||||
@@ -68,6 +68,9 @@ const legacyConfigRepairMocks = vi.hoisted(() => ({
|
||||
const launchdUpdateCleanupMocks = vi.hoisted(() => ({
|
||||
disableCurrentOpenClawUpdateLaunchdJob: vi.fn(async () => false),
|
||||
}));
|
||||
const restartHealthTestControl = vi.hoisted(() => ({
|
||||
snapshot: undefined as unknown,
|
||||
}));
|
||||
const nodeVersionSatisfiesEngine = vi.fn();
|
||||
const execFile = vi.fn((...args: unknown[]) => {
|
||||
const callback = args.at(-1);
|
||||
@@ -340,6 +343,23 @@ vi.mock("./update-cli/restart-helper.js", () => ({
|
||||
runRestartScript: (...args: unknown[]) => runRestartScript(...args),
|
||||
}));
|
||||
|
||||
vi.mock("./daemon-cli/restart-health.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./daemon-cli/restart-health.js")>();
|
||||
return {
|
||||
...actual,
|
||||
waitForGatewayHealthyRestart: (
|
||||
...args: Parameters<typeof actual.waitForGatewayHealthyRestart>
|
||||
) =>
|
||||
restartHealthTestControl.snapshot === undefined
|
||||
? actual.waitForGatewayHealthyRestart(...args)
|
||||
: Promise.resolve(
|
||||
restartHealthTestControl.snapshot as Awaited<
|
||||
ReturnType<typeof actual.waitForGatewayHealthyRestart>
|
||||
>,
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
// Mock doctor (heavy module; should not run in unit tests)
|
||||
vi.mock("../commands/doctor.js", () => ({
|
||||
doctorCommand: vi.fn(),
|
||||
@@ -781,6 +801,7 @@ describe("update-cli", () => {
|
||||
delete process.env.OPENCLAW_SERVICE_MARKER;
|
||||
delete process.env.OPENCLAW_SERVICE_KIND;
|
||||
delete process.env[GATEWAY_SERVICE_RUNTIME_PID_ENV];
|
||||
restartHealthTestControl.snapshot = undefined;
|
||||
vi.clearAllMocks();
|
||||
resetRuntimeCapture();
|
||||
spawn.mockImplementation(() => {
|
||||
@@ -3722,6 +3743,20 @@ describe("update-cli", () => {
|
||||
pid: 4242,
|
||||
state: "running",
|
||||
});
|
||||
restartHealthTestControl.snapshot = {
|
||||
runtime: { status: "stopped", pid: null, state: "stopped" },
|
||||
portUsage: {
|
||||
port: 18789,
|
||||
status: "busy",
|
||||
listeners: [{ pid: 4242, command: "openclaw-gateway" }],
|
||||
hints: [],
|
||||
},
|
||||
healthy: true,
|
||||
staleGatewayPids: [],
|
||||
gatewayVersion: "1.0.0",
|
||||
waitOutcome: "timeout",
|
||||
elapsedMs: 60_000,
|
||||
};
|
||||
mockGitUpdateAfterMutation();
|
||||
|
||||
await updateCommand({ yes: true });
|
||||
|
||||
Reference in New Issue
Block a user