mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 11:18:37 +00:00
refactor(infra): dedupe update startup test setup
This commit is contained in:
@@ -107,12 +107,20 @@ describe("update-startup", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function mockPackageUpdateStatus(tag = "latest", version = "2.0.0") {
|
function mockPackageUpdateStatus(tag = "latest", version = "2.0.0") {
|
||||||
|
mockPackageInstallStatus();
|
||||||
|
mockNpmChannelTag(tag, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
function mockPackageInstallStatus() {
|
||||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue("/opt/openclaw");
|
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue("/opt/openclaw");
|
||||||
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
||||||
root: "/opt/openclaw",
|
root: "/opt/openclaw",
|
||||||
installKind: "package",
|
installKind: "package",
|
||||||
packageManager: "npm",
|
packageManager: "npm",
|
||||||
} satisfies UpdateCheckResult);
|
} satisfies UpdateCheckResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
function mockNpmChannelTag(tag: string, version: string) {
|
||||||
vi.mocked(resolveNpmChannelTag).mockResolvedValue({
|
vi.mocked(resolveNpmChannelTag).mockResolvedValue({
|
||||||
tag,
|
tag,
|
||||||
version,
|
version,
|
||||||
@@ -173,6 +181,20 @@ describe("update-startup", () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function runStableUpdateCheck(params: {
|
||||||
|
onUpdateAvailableChange?: ReturnType<typeof vi.fn>;
|
||||||
|
}) {
|
||||||
|
await runGatewayUpdateCheck({
|
||||||
|
cfg: { update: { channel: "stable" } },
|
||||||
|
log: { info: vi.fn() },
|
||||||
|
isNixMode: false,
|
||||||
|
allowInTests: true,
|
||||||
|
...(params.onUpdateAvailableChange
|
||||||
|
? { onUpdateAvailableChange: params.onUpdateAvailableChange }
|
||||||
|
: {}),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
{
|
{
|
||||||
name: "stable channel",
|
name: "stable channel",
|
||||||
@@ -232,12 +254,7 @@ describe("update-startup", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("emits update change callback when update state clears", async () => {
|
it("emits update change callback when update state clears", async () => {
|
||||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue("/opt/openclaw");
|
mockPackageInstallStatus();
|
||||||
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
|
||||||
root: "/opt/openclaw",
|
|
||||||
installKind: "package",
|
|
||||||
packageManager: "npm",
|
|
||||||
} satisfies UpdateCheckResult);
|
|
||||||
vi.mocked(resolveNpmChannelTag)
|
vi.mocked(resolveNpmChannelTag)
|
||||||
.mockResolvedValueOnce({
|
.mockResolvedValueOnce({
|
||||||
tag: "latest",
|
tag: "latest",
|
||||||
@@ -249,21 +266,9 @@ describe("update-startup", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const onUpdateAvailableChange = vi.fn();
|
const onUpdateAvailableChange = vi.fn();
|
||||||
await runGatewayUpdateCheck({
|
await runStableUpdateCheck({ onUpdateAvailableChange });
|
||||||
cfg: { update: { channel: "stable" } },
|
|
||||||
log: { info: vi.fn() },
|
|
||||||
isNixMode: false,
|
|
||||||
allowInTests: true,
|
|
||||||
onUpdateAvailableChange,
|
|
||||||
});
|
|
||||||
vi.setSystemTime(new Date("2026-01-18T11:00:00Z"));
|
vi.setSystemTime(new Date("2026-01-18T11:00:00Z"));
|
||||||
await runGatewayUpdateCheck({
|
await runStableUpdateCheck({ onUpdateAvailableChange });
|
||||||
cfg: { update: { channel: "stable" } },
|
|
||||||
log: { info: vi.fn() },
|
|
||||||
isNixMode: false,
|
|
||||||
allowInTests: true,
|
|
||||||
onUpdateAvailableChange,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(onUpdateAvailableChange).toHaveBeenNthCalledWith(1, {
|
expect(onUpdateAvailableChange).toHaveBeenNthCalledWith(1, {
|
||||||
currentVersion: "1.0.0",
|
currentVersion: "1.0.0",
|
||||||
@@ -362,16 +367,8 @@ describe("update-startup", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("uses current runtime + entrypoint for default auto-update command execution", async () => {
|
it("uses current runtime + entrypoint for default auto-update command execution", async () => {
|
||||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue("/opt/openclaw");
|
mockPackageInstallStatus();
|
||||||
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
mockNpmChannelTag("beta", "2.0.0-beta.1");
|
||||||
root: "/opt/openclaw",
|
|
||||||
installKind: "package",
|
|
||||||
packageManager: "npm",
|
|
||||||
} satisfies UpdateCheckResult);
|
|
||||||
vi.mocked(resolveNpmChannelTag).mockResolvedValue({
|
|
||||||
tag: "beta",
|
|
||||||
version: "2.0.0-beta.1",
|
|
||||||
});
|
|
||||||
vi.mocked(runCommandWithTimeout).mockResolvedValue({
|
vi.mocked(runCommandWithTimeout).mockResolvedValue({
|
||||||
stdout: "{}",
|
stdout: "{}",
|
||||||
stderr: "",
|
stderr: "",
|
||||||
|
|||||||
Reference in New Issue
Block a user