fix: finish 2.9.0 plugin moves and get every check green

This commit is contained in:
LukeGus committed 2026-09-24 23:35:18 -05:00
1 parent 8c1e02af89
commit 6489b62ece
335 files changed
+29878 -17749

No files matched your search

@@ -0,0 +1,32 @@
import { describe, expect, it } from "vitest";
import { hostPayloadLegacy } from "../../src/backend/host-import.js";
describe("hostPayloadLegacy", () => {
it("rebuilds the 2.8 statsConfig Termix-Mobile reads", () => {
const { statsConfig } = hostPayloadLegacy(
{ metricsEnabled: false, metricsInterval: 45, enabledWidgets: ["cpu"] },
{ statusCheckEnabled: true, statusCheckInterval: null },
) as { statsConfig: Record<string, unknown> };
expect(statsConfig).toMatchObject({
enabledWidgets: ["cpu"],
statusCheckEnabled: true,
useGlobalStatusInterval: true,
metricsEnabled: false,
metricsInterval: 45,
useGlobalMetricsInterval: false,
});
});
it("carries a host's own status interval", () => {
const { statsConfig } = hostPayloadLegacy(
{},
{ statusCheckEnabled: false, statusCheckInterval: 120 },
) as { statsConfig: Record<string, unknown> };
expect(statsConfig).toMatchObject({
statusCheckEnabled: false,
statusCheckInterval: 120,
useGlobalStatusInterval: false,
});
});
});
@@ -54,7 +54,6 @@ vi.mock("../../src/frontend/host-metrics-api", async (importOriginal) => {
vi.mock("@termix/plugin-sdk/ui", async (importOriginal) => ({
...(await importOriginal<object>()),
useAreaPreferences: () => ({ columns: 3 }),
useConfirmation: () => ({ confirmWithToast: vi.fn() }),
logActivity: vi.fn(async () => undefined),
}));
@@ -6,16 +6,24 @@ const api = vi.hoisted(() => ({
get: vi.fn(),
post: vi.fn(),
}));
const remote = vi.hoisted(() => ({
api: { get: vi.fn(), post: vi.fn() },
origin: "local" as "local" | "remote",
remoteId: 70 as number | null,
}));
vi.mock("@termix/plugin-sdk/frontend", async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
usePluginApi: () => api,
usePluginApiFor: () => remote.api,
useTranslation: () => ({ t: (key: string) => key, language: "en" }),
}));
vi.mock("@termix/plugin-sdk/ui", () => ({
cn: (...classes: unknown[]) => classes.filter(Boolean).join(" "),
getPollingEnvironmentMultiplier: () => 1,
resolveConnectionOrigin: async () => remote.origin,
resolveRemoteHostId: async () => remote.remoteId,
runAdaptivePolling: (poll: () => Promise<unknown>) => {
void poll();
return () => {};
@@ -27,6 +35,8 @@ import { TerminalMetricsStatus } from "../../src/frontend/TerminalMetricsStatus"
afterEach(() => {
cleanup();
vi.clearAllMocks();
remote.origin = "local";
remote.remoteId = 70;
});
describe("TerminalMetricsStatus", () => {
@@ -77,4 +87,22 @@ describe("TerminalMetricsStatus", () => {
viewerSessionId: "viewer-2",
});
});
it("polls a remote server's host by its id there", async () => {
remote.origin = "remote";
remote.api.post.mockResolvedValue({ data: { viewerSessionId: "v" } });
remote.api.get.mockResolvedValue({ data: { cpu: { percent: 33 } } });
render(
<TerminalMetricsStatus
host={{ id: 7, connectionOrigin: "remote", syncId: "s-1" }}
isConnected
active
/>,
);
await waitFor(() => expect(screen.getByText("33%")).toBeInTheDocument());
expect(remote.api.post).toHaveBeenCalledWith("/metrics/start/70");
expect(api.post).not.toHaveBeenCalled();
});
});