fix(agents): import standalone JRE offline packages
This commit is contained in:
20 files changed
+306
-13
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({ invoke: vi.fn() }));
|
||||
vi.mock("@tauri-apps/api/core", () => ({ invoke: mocks.invoke }));
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("offline Agent and standalone JRE import", () => {
|
||||
it("returns separate driver and JRE counts from the desktop command", async () => {
|
||||
const { importAgentsFromZip } = await import("../tauri");
|
||||
mocks.invoke.mockResolvedValue({ count: 0, jreCount: 1 });
|
||||
expect(await importAgentsFromZip("/tmp/renamed.tar.zst", "import-1")).toEqual({ count: 0, jreCount: 1 });
|
||||
expect(mocks.invoke).toHaveBeenCalledWith("import_agents_from_zip", { path: "/tmp/renamed.tar.zst", operationId: "import-1" });
|
||||
});
|
||||
|
||||
it("uploads standalone JRE packages and preserves both result counts", async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify({ count: 0, jreCount: 1 })));
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
const { importAgentsFromZip } = await import("../http");
|
||||
const file = new File(["archive"], "renamed.tar.zst");
|
||||
expect(await importAgentsFromZip(file, "import-2")).toEqual({ count: 0, jreCount: 1 });
|
||||
const [url, request] = fetchMock.mock.calls[0];
|
||||
expect(url).toContain("/api/agents/import-offline");
|
||||
expect(request.method).toBe("POST");
|
||||
expect(request.body.get("operationId")).toBe("import-2");
|
||||
expect(request.body.get("file").name).toBe(file.name);
|
||||
});
|
||||
|
||||
it("remains compatible with web backends that only return a driver count", async () => {
|
||||
vi.stubGlobal("fetch", vi.fn().mockResolvedValue(new Response(JSON.stringify({ count: 2 }))));
|
||||
const { importAgentsFromZip } = await import("../http");
|
||||
expect(await importAgentsFromZip(new File(["archive"], "drivers.zip"))).toEqual({ count: 2, jreCount: 0 });
|
||||
});
|
||||
});
|
||||
@@ -69,6 +69,7 @@ import type {
|
||||
DriverStoreUsage,
|
||||
DriverRuntimeSummary,
|
||||
UpgradeAllAgentDriversResult,
|
||||
AgentOfflineImportResult,
|
||||
AgentUpdateBlocker,
|
||||
AgentOfflineExportPreview,
|
||||
AgentOfflineExportResult,
|
||||
@@ -861,7 +862,7 @@ export async function invalidateAgentRegistryCache(): Promise<void> {
|
||||
await post("/api/agents/invalidate-registry-cache", {});
|
||||
}
|
||||
|
||||
export async function importAgentsFromZip(fileOrPath: string | File, operationId?: string): Promise<number> {
|
||||
export async function importAgentsFromZip(fileOrPath: string | File, operationId?: string): Promise<AgentOfflineImportResult> {
|
||||
if (typeof fileOrPath === "string") {
|
||||
throw new Error("Offline package import in web mode requires a File object, not a file path");
|
||||
}
|
||||
@@ -873,8 +874,8 @@ export async function importAgentsFromZip(fileOrPath: string | File, operationId
|
||||
body: formData,
|
||||
});
|
||||
if (!res.ok) throw await backendResponseError(res);
|
||||
const result: { count: number } = await res.json();
|
||||
return result.count;
|
||||
const result: AgentOfflineImportResult = await res.json();
|
||||
return { count: result.count, jreCount: result.jreCount ?? 0 };
|
||||
}
|
||||
|
||||
export async function previewAgentOfflineExport(): Promise<AgentOfflineExportPreview> {
|
||||
|
||||
@@ -200,6 +200,11 @@ export interface AgentOfflineExportResult {
|
||||
bytes: number;
|
||||
}
|
||||
|
||||
export interface AgentOfflineImportResult {
|
||||
count: number;
|
||||
jreCount: number;
|
||||
}
|
||||
|
||||
export type JavaRuntimeMode = "managed" | "system" | "custom";
|
||||
|
||||
export interface JavaRuntimeConfig {
|
||||
@@ -2511,7 +2516,7 @@ export async function invalidateAgentRegistryCache(): Promise<void> {
|
||||
return invoke("invalidate_agent_registry_cache");
|
||||
}
|
||||
|
||||
export async function importAgentsFromZip(path: string | File, operationId?: string): Promise<number> {
|
||||
export async function importAgentsFromZip(path: string | File, operationId?: string): Promise<AgentOfflineImportResult> {
|
||||
if (typeof path !== "string") {
|
||||
throw new Error("Desktop offline package import requires a local file path");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user