mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-08 19:12:22 +00:00
test: manage update startup env
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
// Covers startup update check and auto-update behavior.
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { formatCliCommand } from "../cli/command-format.js";
|
||||
import { createSuiteTempRootTracker } from "../test-helpers/temp-dir.js";
|
||||
import { captureEnv } from "../test-utils/env.js";
|
||||
import {
|
||||
createOpenClawTestState,
|
||||
type OpenClawTestState,
|
||||
} from "../test-utils/openclaw-test-state.js";
|
||||
import type { UpdateCheckResult } from "./update-check.js";
|
||||
|
||||
const {
|
||||
@@ -78,9 +80,8 @@ vi.mock("./update-managed-service-handoff.js", () => ({
|
||||
}));
|
||||
|
||||
describe("update-startup", () => {
|
||||
const suiteRootTracker = createSuiteTempRootTracker({ prefix: "openclaw-update-check-suite-" });
|
||||
let tempDir: string;
|
||||
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||
let testState: OpenClawTestState;
|
||||
|
||||
let resolveOpenClawPackageRoot: (typeof import("./openclaw-root.js"))["resolveOpenClawPackageRoot"];
|
||||
let checkUpdateStatus: (typeof import("./update-check.js"))["checkUpdateStatus"];
|
||||
@@ -100,33 +101,26 @@ describe("update-startup", () => {
|
||||
return call;
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
await suiteRootTracker.setup();
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.useFakeTimers();
|
||||
vi.setSystemTime(new Date("2026-01-17T10:00:00Z"));
|
||||
tempDir = await suiteRootTracker.make("case");
|
||||
envSnapshot = captureEnv([
|
||||
"OPENCLAW_NO_AUTO_UPDATE",
|
||||
"OPENCLAW_STATE_DIR",
|
||||
"OPENCLAW_SERVICE_KIND",
|
||||
"OPENCLAW_SERVICE_MARKER",
|
||||
"OPENCLAW_GATEWAY_SERVICE_PID",
|
||||
"OPENCLAW_LAUNCHD_LABEL",
|
||||
"OPENCLAW_SYSTEMD_UNIT",
|
||||
"OPENCLAW_WINDOWS_TASK_NAME",
|
||||
"INVOCATION_ID",
|
||||
"NODE_ENV",
|
||||
"VITEST",
|
||||
]);
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
process.env.NODE_ENV = "test";
|
||||
|
||||
// Ensure update checks don't short-circuit in test mode.
|
||||
delete process.env.VITEST;
|
||||
testState = await createOpenClawTestState({
|
||||
layout: "state-only",
|
||||
prefix: "openclaw-update-check-suite-",
|
||||
env: {
|
||||
OPENCLAW_NO_AUTO_UPDATE: undefined,
|
||||
OPENCLAW_SERVICE_KIND: undefined,
|
||||
OPENCLAW_SERVICE_MARKER: undefined,
|
||||
OPENCLAW_GATEWAY_SERVICE_PID: undefined,
|
||||
OPENCLAW_LAUNCHD_LABEL: undefined,
|
||||
OPENCLAW_SYSTEMD_UNIT: undefined,
|
||||
OPENCLAW_WINDOWS_TASK_NAME: undefined,
|
||||
INVOCATION_ID: undefined,
|
||||
NODE_ENV: "test",
|
||||
VITEST: undefined,
|
||||
},
|
||||
});
|
||||
tempDir = testState.stateDir;
|
||||
|
||||
// Perf: load mocked modules once (after timers/env are set up).
|
||||
if (!loaded) {
|
||||
@@ -160,14 +154,10 @@ describe("update-startup", () => {
|
||||
|
||||
afterEach(async () => {
|
||||
vi.useRealTimers();
|
||||
envSnapshot.restore();
|
||||
await testState.cleanup();
|
||||
resetUpdateAvailableStateForTest();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await suiteRootTracker.cleanup();
|
||||
});
|
||||
|
||||
function mockPackageUpdateStatus(tag = "latest", version = "2.0.0") {
|
||||
mockPackageInstallStatus();
|
||||
mockNpmChannelTag(tag, version);
|
||||
|
||||
Reference in New Issue
Block a user