CH-J ToolsPalvelimen hallinta yli SSH
Valikko
Julkaistu lähde

CH-J Tools

Selaile hakemistoja ja tiedostoja tietyn sovelluksen julkaisua varten.

Lataa lähde ZIP
CH-J / Server Manager 406 tiedostot
core-20261024T135205Z-7c487d719de2 Lisätty: · Rakennettu:
configStore.test.js Lisätty: Kirjaamaton päivä 5,0 KB · 89 rivit
Koodi Lataa tiedosto
1"use strict";
3const test = require("node:test");
4const assert = require("node:assert/strict");
5const fs = require("node:fs");
6const os = require("node:os");
7const path = require("node:path");
8const { ConfigStore, DEFAULT_CONFIG } = require("../src/main/config/configStore");
10test("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});
28test("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});
44test("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});
54test("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});
63test("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});
78test("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-256fc02f2e4423f2bdaff442064e4815349f3d3565a06cc95c14661d0cc8a2b8eac

CH-J Proprietary Software License 1.14 · Lähde ilmoitetaan CH-J Proprietary Software License 1.14-koodilla. Sen saatavuus ei muuta lisenssiehtoja eikä myönnä lisäoikeuksia.

Arkisto SHA-256476ed8aef0f1e96a5acdf223127b6692acdf4492eeaf5d0816b6e2a634fbbda6
Tiedostot