Objavljen izvor
Preuzmi ZIP izvora
CH-J Tools
Pregledaj direktorije i datoteke za određeni programski izdanje.
CH-J / Server Manager
406 datoteke
core-20261024T135205Z-7c487d719de2
Dodano: · Izgrađeno:
1
"use strict";3
const test = require("node:test");4
const assert = require("node:assert/strict");5
const fs = require("node:fs");6
const os = require("node:os");7
const path = require("node:path");8
const { ConfigStore, DEFAULT_CONFIG } = require("../src/main/config/configStore");10
test("config store creates defaults and persists allowed changes", (t) => {11
const root = fs.mkdtempSync(path.join(os.tmpdir(), "chj-config-"));12
t.after(() => fs.rmSync(root, { recursive: true, force: true }));13
const store = new ConfigStore(root);14
assert.equal(store.load().updates.channel, "beta");15
assert.equal(store.load().plugins.channel, "alpha");16
const changed = store.update({ updates: { channel: "all", autoCheck: false }, plugins: { channel: "stable" } });17
assert.equal(changed.updates.channel, "all");18
assert.equal(changed.plugins.channel, "stable");19
assert.equal(changed.updates.autoCheck, false);20
assert.equal(changed.updates.lastLaunchedRelease, null);21
assert.deepEqual(changed.updates.baseUrls, DEFAULT_CONFIG.updates.baseUrls);22
assert.equal(new ConfigStore(root).load().updates.channel, "all");23
assert.equal(new ConfigStore(root).load().plugins.channel, "stable");24
assert.equal(store.update({ ui: { language: "de" } }).ui.language, "de");25
assert.equal(new ConfigStore(root).load().ui.language, "de");26
});28
test("config store records launched update identity without exposing it to UI patches", (t) => {29
const root = fs.mkdtempSync(path.join(os.tmpdir(), "chj-config-"));30
t.after(() => fs.rmSync(root, { recursive: true, force: true }));31
const store = new ConfigStore(root);32
store.load();33
const release = {34
id: "release-1",35
version: "0.0.1",36
publishedAt: "2026-08-08T15:14:02Z",37
sha512: "a".repeat(128)38
};39
store.recordLaunchedRelease(release);40
store.update({ updates: { lastLaunchedRelease: { id: "forged" } } });41
assert.deepEqual(new ConfigStore(root).load().updates.lastLaunchedRelease, release);42
});44
test("config only accepts supported UI languages", (t) => {45
const root = fs.mkdtempSync(path.join(os.tmpdir(), "chj-config-"));46
t.after(() => fs.rmSync(root, { recursive: true, force: true }));47
const store = new ConfigStore(root);48
store.load();49
assert.equal(store.update({ ui: { language: "en" } }).ui.language, "en");50
assert.equal(store.update({ ui: { language: "fr" } }).ui.language, "cs");51
assert.equal(store.update({ ui: { language: "../../x" } }).ui.language, "cs");52
});54
test("untrusted config cannot replace update allowlist", (t) => {55
const root = fs.mkdtempSync(path.join(os.tmpdir(), "chj-config-"));56
t.after(() => fs.rmSync(root, { recursive: true, force: true }));57
const store = new ConfigStore(root);58
store.load();59
const changed = store.update({ updates: { baseUrls: ["https://example.com/"] } });60
assert.deepEqual(changed.updates.baseUrls, DEFAULT_CONFIG.updates.baseUrls);61
});63
test("navigation order and plugin placement survive restart and unrelated settings changes", (t) => {64
const root = fs.mkdtempSync(path.join(os.tmpdir(), "chj-navigation-"));65
t.after(() => fs.rmSync(root, { recursive: true, force: true }));66
const store = new ConfigStore(root); store.load();67
const navigationOrder = ["terminal", "plugin:chj.users", "overview", "settings"];68
const display = { "chj.users": "navigation", "chj.hash-checksum": "hidden", "chj.system-monitor": "visible" };69
store.update({ ui: { navigationOrder }, plugins: { display } });70
store.update({ ui: { language: "en" }, plugins: { channel: "stable" } });71
const loaded = new ConfigStore(root).load();72
assert.deepEqual(loaded.ui.navigationOrder, navigationOrder);73
assert.deepEqual(loaded.plugins.display, display);74
assert.deepEqual(store.update({ ui: { navigationOrder: ["terminal", "terminal", "invalid", "plugin:../../x", 3] }, plugins: { display: { "chj.users": "invalid", "../../x": "hidden" } } }).ui.navigationOrder, ["terminal"]);75
assert.deepEqual(store.get().plugins.display, {});76
});78
test("sidebar layout is normalized, merged with other UI settings and persisted", () => {79
const root = fs.mkdtempSync(path.join(os.tmpdir(), "chj-config-sidebar-"));80
const store = new ConfigStore(root); store.load();81
assert.deepEqual(store.get().ui.sidebar, { mode: "full", hidden: false, width: 248 });82
assert.deepEqual(store.update({ ui: { sidebar: { mode: "split" } } }).ui.sidebar, { mode: "split", hidden: false, width: 248 });83
assert.deepEqual(store.update({ ui: { sidebar: { hidden: true } } }).ui.sidebar, { mode: "split", hidden: true, width: 248 }, "hiding keeps the last mode");84
assert.equal(store.update({ ui: { language: "en" } }).ui.sidebar.mode, "split", "other UI patches keep the sidebar");85
assert.equal(store.update({ ui: { sidebar: { width: 5000 } } }).ui.sidebar.width, 420);86
assert.equal(store.update({ ui: { sidebar: { width: 12 } } }).ui.sidebar.width, 220);87
assert.equal(store.update({ ui: { sidebar: { mode: "<script>", hidden: "yes" } } }).ui.sidebar.mode, "full");88
assert.deepEqual(new ConfigStore(root).load().ui.sidebar, { mode: "full", hidden: false, width: 220 });89
});SHA-256
fc02f2e4423f2bdaff442064e4815349f3d3565a06cc95c14661d0cc8a2b8eacCH-J Proprietary Software License 1.14 · Izvor je osiguran pod CH-J Proprietary Software License 1.14. Njena dostupnost ne mijenja uvjete licenciranja niti daje dodatna prava.
Arhiv SHA-256
476ed8aef0f1e96a5acdf223127b6692acdf4492eeaf5d0816b6e2a634fbbda6