mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 15:34:31 +00:00
refactor(core): dedupe shared config and runtime helpers
This commit is contained in:
@@ -109,7 +109,7 @@ describe("update-startup", () => {
|
||||
suiteCase = 0;
|
||||
});
|
||||
|
||||
it("logs update hint for npm installs when newer tag exists", async () => {
|
||||
async function runUpdateCheckAndReadState(channel: "stable" | "beta") {
|
||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue("/opt/openclaw");
|
||||
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
||||
root: "/opt/openclaw",
|
||||
@@ -123,49 +123,35 @@ describe("update-startup", () => {
|
||||
|
||||
const log = { info: vi.fn() };
|
||||
await runGatewayUpdateCheck({
|
||||
cfg: { update: { channel: "stable" } },
|
||||
cfg: { update: { channel } },
|
||||
log,
|
||||
isNixMode: false,
|
||||
allowInTests: true,
|
||||
});
|
||||
|
||||
const statePath = path.join(tempDir, "update-check.json");
|
||||
const parsed = JSON.parse(await fs.readFile(statePath, "utf-8")) as {
|
||||
lastNotifiedVersion?: string;
|
||||
lastNotifiedTag?: string;
|
||||
};
|
||||
return { log, parsed };
|
||||
}
|
||||
|
||||
it("logs update hint for npm installs when newer tag exists", async () => {
|
||||
const { log, parsed } = await runUpdateCheckAndReadState("stable");
|
||||
|
||||
expect(log.info).toHaveBeenCalledWith(
|
||||
expect.stringContaining("update available (latest): v2.0.0"),
|
||||
);
|
||||
|
||||
const statePath = path.join(tempDir, "update-check.json");
|
||||
const raw = await fs.readFile(statePath, "utf-8");
|
||||
const parsed = JSON.parse(raw) as { lastNotifiedVersion?: string };
|
||||
expect(parsed.lastNotifiedVersion).toBe("2.0.0");
|
||||
});
|
||||
|
||||
it("uses latest when beta tag is older than release", async () => {
|
||||
vi.mocked(resolveOpenClawPackageRoot).mockResolvedValue("/opt/openclaw");
|
||||
vi.mocked(checkUpdateStatus).mockResolvedValue({
|
||||
root: "/opt/openclaw",
|
||||
installKind: "package",
|
||||
packageManager: "npm",
|
||||
} satisfies UpdateCheckResult);
|
||||
vi.mocked(resolveNpmChannelTag).mockResolvedValue({
|
||||
tag: "latest",
|
||||
version: "2.0.0",
|
||||
});
|
||||
|
||||
const log = { info: vi.fn() };
|
||||
await runGatewayUpdateCheck({
|
||||
cfg: { update: { channel: "beta" } },
|
||||
log,
|
||||
isNixMode: false,
|
||||
allowInTests: true,
|
||||
});
|
||||
const { log, parsed } = await runUpdateCheckAndReadState("beta");
|
||||
|
||||
expect(log.info).toHaveBeenCalledWith(
|
||||
expect.stringContaining("update available (latest): v2.0.0"),
|
||||
);
|
||||
|
||||
const statePath = path.join(tempDir, "update-check.json");
|
||||
const raw = await fs.readFile(statePath, "utf-8");
|
||||
const parsed = JSON.parse(raw) as { lastNotifiedTag?: string };
|
||||
expect(parsed.lastNotifiedTag).toBe("latest");
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user