Published source
Download source ZIP
CH-J Server Manager
Browse directories and files for a specific application release.
Source is provided under the CH-J Proprietary Software License 1.14. Its availability does not change the license terms or grant additional rights.
1
"use strict";3
const test = require("node:test");4
const assert = require("node:assert/strict");5
const { PluginService } = require("../src/main/plugins/pluginService");7
test("plugin service offers a newer artifact with the same semantic version", () => {8
const installedSha = "a".repeat(128);9
const catalogSha = "b".repeat(128);10
const service = new PluginService({11
appVersion: "0.0.1",12
configStore: {}, installer: {}, providerFactory: () => {}, runtime: {},13
registry: { listInstalled: () => [{ id: "chj.key-generator", version: "0.0.1", installedReleaseId: "old-release", installedSha512: installedSha }] }14
});15
service.catalog = [{ id: "chj.key-generator", version: "0.0.1", releaseId: "new-release", sha512: catalogSha }];16
const plugin = service.getState().catalog[0];17
assert.equal(plugin.installed, false);18
assert.equal(plugin.updateAvailable, true);19
assert.equal(plugin.installedReleaseId, "old-release");21
service.catalog[0].sha512 = installedSha;22
const identical = service.getState().catalog[0];23
assert.equal(identical.installed, true);24
assert.equal(identical.updateAvailable, false);25
});27
test("plugin service removes the verified package only after installation succeeds", async () => {28
const removed = [];29
const plugin = {30
id: "chj.test", version: "0.0.1", releaseId: "release-1", sha512: "a".repeat(128)31
};32
const service = new PluginService({33
appVersion: "0.0.1",34
configStore: { get: () => ({ updates: {} }) },35
registry: { listInstalled: () => [] },36
runtime: {},37
installer: { install: () => ({ manifest: { id: plugin.id }, reused: false }) },38
providerFactory: () => ({39
downloadAndVerify: async () => ({ path: "/cache/test.chjplugin" }),40
removeDownloadedPackage: (filePath) => { removed.push(filePath); return { removed: true }; }41
})42
});43
service.catalog = [plugin];45
await service.install("release-1");46
assert.deepEqual(removed, ["/cache/test.chjplugin"]);47
});49
test("plugin service keeps the verified package when installation fails", async () => {50
let cleanupCalled = false;51
const plugin = {52
id: "chj.test", version: "0.0.1", releaseId: "release-1", sha512: "a".repeat(128)53
};54
const service = new PluginService({55
appVersion: "0.0.1",56
configStore: { get: () => ({ updates: {} }) },57
registry: { listInstalled: () => [] },58
runtime: {},59
installer: { install: () => { throw new Error("installation failed"); } },60
providerFactory: () => ({61
downloadAndVerify: async () => ({ path: "/cache/test.chjplugin" }),62
removeDownloadedPackage: () => { cleanupCalled = true; }63
})64
});65
service.catalog = [plugin];67
await assert.rejects(() => service.install("release-1"), /installation failed/);68
assert.equal(cleanupCalled, false);69
});SHA-256: 489a0cef4ffa814946d6926bcbc4c6314c0dfe707941bbf0dcf1a1b8ba0159af
Archive SHA-256: 5ac91caf4fa32a6fdb114f2430deed486fbe7489d5eea343d1f034169fafb5e0