From db4e19fe42c7f37e191c2217be84281f5257e12c Mon Sep 17 00:00:00 2001 From: Divya Chukkapalli <12871391+divya0795@users.noreply.github.com> Date: Tue, 1 Dec 2026 02:20:07 -0800 Subject: [PATCH] fix: install nested plugin dependencies resolveDepsManifest pushed the array returned by its recursive call without spreading it. When a dependency declares its own dependencies, the confirm dialog showed a blank name and resolveDep received an array, so installPlugin downloaded plugin id "undefined" and the whole install was rolled back. This also happened when the nested dependency was already installed, because the empty array was still pushed. Spread the nested manifests into the flat list. --- src/lib/installPlugin.js | 2 +- tests/unit/installPluginDependencies.test.js | 147 +++++++++++++++++++ 2 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 tests/unit/installPluginDependencies.test.js diff --git a/src/lib/installPlugin.js b/src/lib/installPlugin.js index d3ec9325f..d44fbf6a3 100644 --- a/src/lib/installPlugin.js +++ b/src/lib/installPlugin.js @@ -415,7 +415,7 @@ async function resolveDepsManifest(deps) { const manifests = await resolveDepsManifest( remoteDependency.dependencies, ); - resolved.push(manifests); + resolved.push(...manifests); } resolved.push(remoteDependency); diff --git a/tests/unit/installPluginDependencies.test.js b/tests/unit/installPluginDependencies.test.js new file mode 100644 index 000000000..1ab9037ae --- /dev/null +++ b/tests/unit/installPluginDependencies.test.js @@ -0,0 +1,147 @@ +import JSZip from "jszip"; +import { expect, it, vi } from "vitest"; +import formatDownloadProgress from "../../src/lib/downloadProgress.js"; +import { loadSourceModule } from "../helpers/loadSourceModule"; + +it("installs a dependency that has its own dependency", async () => { + const fixture = await setup(); + await fixture.install("file:///parent.zip"); + expect(fixture.confirm.mock.calls[0][1]).toMatch( + /

Nested, Direct$/, + ); + expect(fixture.downloads).toEqual(["nested", "direct"]); + expect(fixture.loaded.mock.calls).toEqual([ + ["nested", true], + ["direct", true], + ["parent", true], + ]); +}); + +it("installs a dependency whose own dependency is already up to date", async () => { + const fixture = await setup({ installedNestedVersion: "1.0.0" }); + await fixture.install("file:///parent.zip"); + expect(fixture.confirm.mock.calls[0][1]).toMatch(/

Direct$/); + expect(fixture.downloads).toEqual(["direct"]); + expect(fixture.loaded.mock.calls).toEqual([ + ["direct", true], + ["parent", true], + ]); +}); + +async function setup({ installedNestedVersion } = {}) { + const platform = loadSourceModule( + "src/lib/platform.js", + {}, + { Bridge: { platformId: "ios" } }, + ).default; + const manifests = { + direct: { + id: "direct", + name: "Direct", + main: "main.js", + version: "1.0.0", + price: 0, + dependencies: ["nested"], + }, + nested: { + id: "nested", + name: "Nested", + main: "main.js", + version: "1.0.0", + price: 0, + }, + }; + const pluginZip = async (manifest) => { + const zip = new JSZip(); + zip.file("plugin.json", JSON.stringify(manifest)); + zip.file("main.js", ""); + return zip.generateAsync({ type: "uint8array" }); + }; + const files = new Map([ + ["file:///plugins", null], + [ + "file:///parent.zip", + await pluginZip({ + id: "parent", + main: "main.js", + dependencies: ["direct"], + }), + ], + ]); + if (installedNestedVersion) { + files.set("file:///plugins/nested", null); + files.set( + "file:///plugins/nested/plugin.json", + JSON.stringify({ id: "nested", version: installedNestedVersion }), + ); + } + const downloads = []; + const join = (...parts) => + parts.reduce( + (parent, child) => + `${parent.replace(/\/$/, "")}/${String(child).replace(/^\/+/, "")}`, + ); + const fsOperation = (...parts) => { + const url = join(...parts); + return { + exists: async () => files.has(url), + readFile: async (encoding) => { + const api = "https://fixture.invalid/plugin/"; + if (url.startsWith(`${api}download/`)) { + const id = url.slice(`${api}download/`.length).split("?")[0]; + downloads.push(id); + if (!manifests[id]) throw new Error(`404 ${url}`); + return pluginZip(manifests[id]); + } + if (url.startsWith(api)) return manifests[url.slice(api.length)]; + if (!files.has(url)) throw new Error(`Missing fixture: ${url}`); + const data = files.get(url); + return encoding === "json" ? JSON.parse(data) : data; + }, + createDirectory: async (name) => files.set(join(url, name), null), + createFile: async (name) => files.set(join(url, name), ""), + writeFile: async (data) => files.set(url, data), + delete: async () => files.delete(url), + lsDir: async () => [], + }; + }; + const confirm = vi.fn(async () => true); + const loaded = vi.fn(); + const install = loadSourceModule( + "src/lib/installPlugin.js", + { + fileSystem: fsOperation, + "dialogs/alert": vi.fn(), + "dialogs/confirm": confirm, + "dialogs/loader": { + create: () => ({ show() {}, setMessage() {}, destroy() {} }), + }, + "handlers/purchase": vi.fn(), + jszip: JSZip, + "utils/helpers": {}, + "utils/Url": { join }, + "utils/version": { isVersionGreater: (a, b) => a > b }, + "./config": { API_BASE: "https://fixture.invalid" }, + "./downloadProgress": formatDownloadProgress, + "./installState": { + new: async () => ({ + exists: () => false, + isUpdated: async () => true, + save: async () => {}, + clear: async () => {}, + }), + }, + "./loadPlugins": { loadPluginWithTimeout: loaded }, + "./platform": platform, + }, + { + PLUGIN_DIR: "file:///plugins", + DATA_STORAGE: "file:///", + device: { uuid: "fixture", version: "18.6" }, + BuildInfo: { packageName: "com.foxdebug.acode" }, + window: { log: vi.fn() }, + strings: new Proxy({}, { get: (target, key) => key }), + }, + ).default; + return { install, confirm, downloads, loaded }; +}