mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 13:21:36 +00:00
refactor(test): reuse env helper in update cli tests
This commit is contained in:
@@ -3,7 +3,7 @@ import path from "node:path";
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import type { OpenClawConfig, ConfigFileSnapshot } from "../config/types.openclaw.js";
|
import type { OpenClawConfig, ConfigFileSnapshot } from "../config/types.openclaw.js";
|
||||||
import type { UpdateRunResult } from "../infra/update-runner.js";
|
import type { UpdateRunResult } from "../infra/update-runner.js";
|
||||||
import { captureEnv } from "../test-utils/env.js";
|
import { withEnvAsync } from "../test-utils/env.js";
|
||||||
|
|
||||||
const confirm = vi.fn();
|
const confirm = vi.fn();
|
||||||
const select = vi.fn();
|
const select = vi.fn();
|
||||||
@@ -604,30 +604,31 @@ describe("update-cli", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("updateCommand continues after doctor sub-step and clears update flag", async () => {
|
it("updateCommand continues after doctor sub-step and clears update flag", async () => {
|
||||||
const envSnapshot = captureEnv(["OPENCLAW_UPDATE_IN_PROGRESS"]);
|
|
||||||
const randomSpy = vi.spyOn(Math, "random").mockReturnValue(0);
|
const randomSpy = vi.spyOn(Math, "random").mockReturnValue(0);
|
||||||
try {
|
try {
|
||||||
delete process.env.OPENCLAW_UPDATE_IN_PROGRESS;
|
await withEnvAsync({ OPENCLAW_UPDATE_IN_PROGRESS: undefined }, async () => {
|
||||||
vi.mocked(runGatewayUpdate).mockResolvedValue(makeOkUpdateResult());
|
vi.mocked(runGatewayUpdate).mockResolvedValue(makeOkUpdateResult());
|
||||||
vi.mocked(runDaemonRestart).mockResolvedValue(true);
|
vi.mocked(runDaemonRestart).mockResolvedValue(true);
|
||||||
vi.mocked(doctorCommand).mockResolvedValue(undefined);
|
vi.mocked(doctorCommand).mockResolvedValue(undefined);
|
||||||
vi.mocked(defaultRuntime.log).mockClear();
|
vi.mocked(defaultRuntime.log).mockClear();
|
||||||
|
|
||||||
await updateCommand({});
|
await updateCommand({});
|
||||||
|
|
||||||
expect(doctorCommand).toHaveBeenCalledWith(
|
expect(doctorCommand).toHaveBeenCalledWith(
|
||||||
defaultRuntime,
|
defaultRuntime,
|
||||||
expect.objectContaining({ nonInteractive: true }),
|
expect.objectContaining({ nonInteractive: true }),
|
||||||
);
|
);
|
||||||
expect(process.env.OPENCLAW_UPDATE_IN_PROGRESS).toBeUndefined();
|
expect(process.env.OPENCLAW_UPDATE_IN_PROGRESS).toBeUndefined();
|
||||||
|
|
||||||
const logLines = vi.mocked(defaultRuntime.log).mock.calls.map((call) => String(call[0]));
|
const logLines = vi.mocked(defaultRuntime.log).mock.calls.map((call) => String(call[0]));
|
||||||
expect(
|
expect(
|
||||||
logLines.some((line) => line.includes("Leveled up! New skills unlocked. You're welcome.")),
|
logLines.some((line) =>
|
||||||
).toBe(true);
|
line.includes("Leveled up! New skills unlocked. You're welcome."),
|
||||||
|
),
|
||||||
|
).toBe(true);
|
||||||
|
});
|
||||||
} finally {
|
} finally {
|
||||||
randomSpy.mockRestore();
|
randomSpy.mockRestore();
|
||||||
envSnapshot.restore();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -731,10 +732,8 @@ describe("update-cli", () => {
|
|||||||
|
|
||||||
it("updateWizardCommand offers dev checkout and forwards selections", async () => {
|
it("updateWizardCommand offers dev checkout and forwards selections", async () => {
|
||||||
const tempDir = createCaseDir("openclaw-update-wizard");
|
const tempDir = createCaseDir("openclaw-update-wizard");
|
||||||
const envSnapshot = captureEnv(["OPENCLAW_GIT_DIR"]);
|
await withEnvAsync({ OPENCLAW_GIT_DIR: tempDir }, async () => {
|
||||||
try {
|
|
||||||
setTty(true);
|
setTty(true);
|
||||||
process.env.OPENCLAW_GIT_DIR = tempDir;
|
|
||||||
|
|
||||||
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
||||||
root: "/test/path",
|
root: "/test/path",
|
||||||
@@ -760,8 +759,6 @@ describe("update-cli", () => {
|
|||||||
|
|
||||||
const call = vi.mocked(runGatewayUpdate).mock.calls[0]?.[0];
|
const call = vi.mocked(runGatewayUpdate).mock.calls[0]?.[0];
|
||||||
expect(call?.channel).toBe("dev");
|
expect(call?.channel).toBe("dev");
|
||||||
} finally {
|
});
|
||||||
envSnapshot.restore();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user