feat: add manual PI WEB update checks

This commit is contained in:
Federico Jaramillo Martinez
2026-07-12 23:21:43 +02:00
parent 4b79a6d399
commit d72b14f40a
22 changed files with 653 additions and 63 deletions
+38
View File
@@ -0,0 +1,38 @@
import { describe, expect, it, vi } from "vitest";
import type { PiWebStatusResponse } from "../shared/apiTypes.js";
import { buildApp } from "./app.js";
describe("PI WEB status routes", () => {
it("forces a fresh status load when refresh is requested", async () => {
const get = vi.fn(() => Promise.resolve(status("cached")));
const refresh = vi.fn(() => Promise.resolve(status("forced")));
const app = await buildApp({ piWebStatusCache: { get, refresh }, clientDist: false, logger: false });
try {
const cachedResponse = await app.inject({ method: "GET", url: "/api/pi-web/status" });
const forcedResponse = await app.inject({ method: "GET", url: "/api/pi-web/status?refresh=1" });
expect(cachedResponse.json<PiWebStatusResponse>().generatedAt).toBe("cached");
expect(forcedResponse.json<PiWebStatusResponse>().generatedAt).toBe("forced");
expect(get).toHaveBeenCalledOnce();
expect(refresh).toHaveBeenCalledOnce();
expect(refresh).toHaveBeenCalledWith({ force: true });
} finally {
await app.close();
}
});
});
function status(generatedAt: string): PiWebStatusResponse {
return {
packageName: "@jmfederico/pi-web",
generatedAt,
components: {
web: { component: "web", label: "Web/UI", stale: false, available: true },
sessiond: { component: "sessiond", label: "Session daemon", stale: false, available: true },
},
release: { packageName: "@jmfederico/pi-web", updateAvailable: false },
commands: {},
messages: [],
};
}