From ed3dd6a1a081110dd702f68cdde6bd99ddad62d1 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Mar 2026 21:11:56 +0000 Subject: [PATCH] test: share install flow failure harness --- src/infra/install-flow.test.ts | 39 ++++++++++++++++------------------ 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/infra/install-flow.test.ts b/src/infra/install-flow.test.ts index 1c3c46ac5ee..a1a7e80e3ad 100644 --- a/src/infra/install-flow.test.ts +++ b/src/infra/install-flow.test.ts @@ -6,6 +6,19 @@ import * as archive from "./archive.js"; import { resolveExistingInstallPath, withExtractedArchiveRoot } from "./install-flow.js"; import * as installSource from "./install-source-utils.js"; +async function runExtractedArchiveFailureCase(configureArchive: () => void) { + vi.spyOn(installSource, "withTempDir").mockImplementation( + async (_prefix, fn) => await fn("/tmp/openclaw-install-flow"), + ); + configureArchive(); + return await withExtractedArchiveRoot({ + archivePath: "/tmp/plugin.tgz", + tempDirPrefix: "openclaw-plugin-", + timeoutMs: 1000, + onExtracted: async () => ({ ok: true as const }), + }); +} + describe("resolveExistingInstallPath", () => { let fixtureRoot = ""; @@ -84,16 +97,8 @@ describe("withExtractedArchiveRoot", () => { }); it("returns extract failure when extraction throws", async () => { - vi.spyOn(installSource, "withTempDir").mockImplementation( - async (_prefix, fn) => await fn("/tmp/openclaw-install-flow"), - ); - vi.spyOn(archive, "extractArchive").mockRejectedValue(new Error("boom")); - - const result = await withExtractedArchiveRoot({ - archivePath: "/tmp/plugin.tgz", - tempDirPrefix: "openclaw-plugin-", - timeoutMs: 1000, - onExtracted: async () => ({ ok: true as const }), + const result = await runExtractedArchiveFailureCase(() => { + vi.spyOn(archive, "extractArchive").mockRejectedValue(new Error("boom")); }); expect(result).toEqual({ @@ -103,17 +108,9 @@ describe("withExtractedArchiveRoot", () => { }); it("returns root-resolution failure when archive layout is invalid", async () => { - vi.spyOn(installSource, "withTempDir").mockImplementation( - async (_prefix, fn) => await fn("/tmp/openclaw-install-flow"), - ); - vi.spyOn(archive, "extractArchive").mockResolvedValue(undefined); - vi.spyOn(archive, "resolvePackedRootDir").mockRejectedValue(new Error("invalid layout")); - - const result = await withExtractedArchiveRoot({ - archivePath: "/tmp/plugin.tgz", - tempDirPrefix: "openclaw-plugin-", - timeoutMs: 1000, - onExtracted: async () => ({ ok: true as const }), + const result = await runExtractedArchiveFailureCase(() => { + vi.spyOn(archive, "extractArchive").mockResolvedValue(undefined); + vi.spyOn(archive, "resolvePackedRootDir").mockRejectedValue(new Error("invalid layout")); }); expect(result).toEqual({