Archived
feat: add manual PI WEB update checks
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { html, svg } from "lit";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { PluginRuntimeContext } from "@jmfederico/pi-web/plugin-api";
|
||||
import plugin from "./pi-web-plugin.js";
|
||||
|
||||
describe("Updates plugin actions", () => {
|
||||
it("forces an update check through the host runtime context", async () => {
|
||||
const action = plugin.activate({ apiVersion: 1, pluginId: "updates", html, svg }).contributions.actions?.find((candidate) => candidate.id === "check");
|
||||
if (action === undefined) throw new Error("Expected update check action");
|
||||
const checkForPiWebUpdates = vi.fn(() => Promise.resolve());
|
||||
const context = runtimeContext({ checkForPiWebUpdates });
|
||||
|
||||
expect(action.enabled?.(context)).toBe(true);
|
||||
await action.run(context);
|
||||
|
||||
expect(checkForPiWebUpdates).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("disables the action on older hosts without the update-check helper", () => {
|
||||
const action = plugin.activate({ apiVersion: 1, pluginId: "updates", html, svg }).contributions.actions?.find((candidate) => candidate.id === "check");
|
||||
if (action === undefined) throw new Error("Expected update check action");
|
||||
const context = runtimeContext();
|
||||
|
||||
expect(action.enabled?.(context)).toBe(false);
|
||||
expect(action.disabledReason?.(context)).toContain("newer PI WEB gateway");
|
||||
});
|
||||
});
|
||||
|
||||
function runtimeContext(patch: Partial<PluginRuntimeContext> = {}): PluginRuntimeContext {
|
||||
const noop = () => undefined;
|
||||
return {
|
||||
state: {},
|
||||
prompt: { insertText: noop, getText: () => "", getSelection: () => null },
|
||||
openActionPalette: noop,
|
||||
focusPrompt: noop,
|
||||
addProject: noop,
|
||||
configureAuth: noop,
|
||||
logoutAuth: noop,
|
||||
openThemePicker: noop,
|
||||
selectMainView: noop,
|
||||
selectWorkspaceTool: noop,
|
||||
openTerminal: noop,
|
||||
refreshFiles: noop,
|
||||
refreshGit: noop,
|
||||
refreshAppData: noop,
|
||||
reloadPage: noop,
|
||||
startSession: noop,
|
||||
archiveSession: noop,
|
||||
stopActiveWork: noop,
|
||||
...patch,
|
||||
};
|
||||
}
|
||||
@@ -143,6 +143,7 @@ function renderUpdatesPanel(html: HtmlTemplateTag, terminal: WorkspacePanelTermi
|
||||
<section class="updates-meta">
|
||||
<span>Generated ${status.generatedAt}</span>
|
||||
${status.release.latestVersion === undefined ? null : html`<span>Latest npm release ${status.release.latestVersion}</span>`}
|
||||
${status.release.checkedAt === undefined || status.release.skipped === true ? null : html`<span>Release checked ${status.release.checkedAt}</span>`}
|
||||
${status.release.skipped === true ? html`<span>Remote version check skipped.</span>` : null}
|
||||
${status.release.error === undefined ? null : html`<span>Remote version check failed: ${status.release.error}</span>`}
|
||||
</section>
|
||||
@@ -155,6 +156,17 @@ const plugin: PiWebPlugin = {
|
||||
name: "Updates",
|
||||
activate: ({ html, svg }) => ({
|
||||
contributions: {
|
||||
actions: [
|
||||
{
|
||||
id: "check",
|
||||
title: "Check for PI WEB Updates",
|
||||
description: "Bypass cached release data and check the selected machine now",
|
||||
group: "Updates",
|
||||
enabled: (context) => context.checkForPiWebUpdates !== undefined,
|
||||
disabledReason: () => "Update checks require a newer PI WEB gateway",
|
||||
run: (context) => context.checkForPiWebUpdates?.(),
|
||||
},
|
||||
],
|
||||
workspacePanels: [
|
||||
{
|
||||
id: "workspace.updates",
|
||||
|
||||
Reference in New Issue
Block a user