mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 17:04:58 +00:00
test(cli): extract update-cli package-install test helpers
This commit is contained in:
@@ -165,14 +165,10 @@ describe("update-cli", () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const setupNonInteractiveDowngrade = async () => {
|
const mockPackageInstallStatus = (root: string) => {
|
||||||
const tempDir = await createCaseDir("openclaw-update");
|
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue(root);
|
||||||
setTty(false);
|
|
||||||
readPackageVersion.mockResolvedValue("2.0.0");
|
|
||||||
|
|
||||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue(tempDir);
|
|
||||||
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
||||||
root: tempDir,
|
root,
|
||||||
installKind: "package",
|
installKind: "package",
|
||||||
packageManager: "npm",
|
packageManager: "npm",
|
||||||
deps: {
|
deps: {
|
||||||
@@ -182,6 +178,20 @@ describe("update-cli", () => {
|
|||||||
markerPath: null,
|
markerPath: null,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const expectUpdateCallChannel = (channel: string) => {
|
||||||
|
const call = vi.mocked(runGatewayUpdate).mock.calls[0]?.[0];
|
||||||
|
expect(call?.channel).toBe(channel);
|
||||||
|
return call;
|
||||||
|
};
|
||||||
|
|
||||||
|
const setupNonInteractiveDowngrade = async () => {
|
||||||
|
const tempDir = await createCaseDir("openclaw-update");
|
||||||
|
setTty(false);
|
||||||
|
readPackageVersion.mockResolvedValue("2.0.0");
|
||||||
|
|
||||||
|
mockPackageInstallStatus(tempDir);
|
||||||
vi.mocked(resolveNpmChannelTag).mockResolvedValue({
|
vi.mocked(resolveNpmChannelTag).mockResolvedValue({
|
||||||
tag: "latest",
|
tag: "latest",
|
||||||
version: "0.0.1",
|
version: "0.0.1",
|
||||||
@@ -332,25 +342,13 @@ describe("update-cli", () => {
|
|||||||
|
|
||||||
await updateCommand({});
|
await updateCommand({});
|
||||||
|
|
||||||
const call = vi.mocked(runGatewayUpdate).mock.calls[0]?.[0];
|
expectUpdateCallChannel("dev");
|
||||||
expect(call?.channel).toBe("dev");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("defaults to stable channel for package installs when unset", async () => {
|
it("defaults to stable channel for package installs when unset", async () => {
|
||||||
const tempDir = await createCaseDir("openclaw-update");
|
const tempDir = await createCaseDir("openclaw-update");
|
||||||
|
|
||||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue(tempDir);
|
mockPackageInstallStatus(tempDir);
|
||||||
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
|
||||||
root: tempDir,
|
|
||||||
installKind: "package",
|
|
||||||
packageManager: "npm",
|
|
||||||
deps: {
|
|
||||||
manager: "npm",
|
|
||||||
status: "ok",
|
|
||||||
lockfilePath: null,
|
|
||||||
markerPath: null,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
vi.mocked(runGatewayUpdate).mockResolvedValue({
|
vi.mocked(runGatewayUpdate).mockResolvedValue({
|
||||||
status: "ok",
|
status: "ok",
|
||||||
mode: "npm",
|
mode: "npm",
|
||||||
@@ -360,8 +358,7 @@ describe("update-cli", () => {
|
|||||||
|
|
||||||
await updateCommand({ yes: true });
|
await updateCommand({ yes: true });
|
||||||
|
|
||||||
const call = vi.mocked(runGatewayUpdate).mock.calls[0]?.[0];
|
const call = expectUpdateCallChannel("stable");
|
||||||
expect(call?.channel).toBe("stable");
|
|
||||||
expect(call?.tag).toBe("latest");
|
expect(call?.tag).toBe("latest");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -379,29 +376,17 @@ describe("update-cli", () => {
|
|||||||
|
|
||||||
await updateCommand({});
|
await updateCommand({});
|
||||||
|
|
||||||
const call = vi.mocked(runGatewayUpdate).mock.calls[0]?.[0];
|
expectUpdateCallChannel("beta");
|
||||||
expect(call?.channel).toBe("beta");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("falls back to latest when beta tag is older than release", async () => {
|
it("falls back to latest when beta tag is older than release", async () => {
|
||||||
const tempDir = await createCaseDir("openclaw-update");
|
const tempDir = await createCaseDir("openclaw-update");
|
||||||
|
|
||||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue(tempDir);
|
mockPackageInstallStatus(tempDir);
|
||||||
vi.mocked(readConfigFileSnapshot).mockResolvedValue({
|
vi.mocked(readConfigFileSnapshot).mockResolvedValue({
|
||||||
...baseSnapshot,
|
...baseSnapshot,
|
||||||
config: { update: { channel: "beta" } } as OpenClawConfig,
|
config: { update: { channel: "beta" } } as OpenClawConfig,
|
||||||
});
|
});
|
||||||
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
|
||||||
root: tempDir,
|
|
||||||
installKind: "package",
|
|
||||||
packageManager: "npm",
|
|
||||||
deps: {
|
|
||||||
manager: "npm",
|
|
||||||
status: "ok",
|
|
||||||
lockfilePath: null,
|
|
||||||
markerPath: null,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
vi.mocked(resolveNpmChannelTag).mockResolvedValue({
|
vi.mocked(resolveNpmChannelTag).mockResolvedValue({
|
||||||
tag: "latest",
|
tag: "latest",
|
||||||
version: "1.2.3-1",
|
version: "1.2.3-1",
|
||||||
@@ -415,8 +400,7 @@ describe("update-cli", () => {
|
|||||||
|
|
||||||
await updateCommand({});
|
await updateCommand({});
|
||||||
|
|
||||||
const call = vi.mocked(runGatewayUpdate).mock.calls[0]?.[0];
|
const call = expectUpdateCallChannel("beta");
|
||||||
expect(call?.channel).toBe("beta");
|
|
||||||
expect(call?.tag).toBe("latest");
|
expect(call?.tag).toBe("latest");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user