CH-J Server ManagerPalvelimen hallinta yli SSH
Valikko
Julkaistu lähde

CH-J Server Manager

Selaile hakemistoja ja tiedostoja tietyn sovelluksen julkaisua varten.

Lataa lähde ZIP
CH-J / Server Manager 377 tiedostot
core-20261019T111616Z-160a00bfcddc Lisätty: · Rakennettu:
virtualMemoryPriority.test.js Lisätty: Kirjaamaton päivä 5,6 KB · 65 rivit
Koodi Lataa tiedosto
1"use strict";
3// Swap priority model of chj.system-monitor: effective (kernel) vs configured (fstab pri=) priority, precedence,
4// and request validation before anything is sent to a server.
5const test = require("node:test");
6const assert = require("node:assert/strict");
7const { parseLinuxInspect, VirtualMemoryService } = require("../src/main/system/virtualMemoryService");
9const inspect = ({ swaps, fstab = [] }) => [
10 "\x1eCHJ_SECTION=meta\nroot=1\nsystemd=1\nbtrfsMkswapfile=0\nos=Ubuntu 24.04\n",
11 "\x1eCHJ_SECTION=swaps\nFilename\tType\tSize\tUsed\tPriority\n" + swaps.map((row) => row.join("\t")).join("\n") + "\n",
12 "\x1eCHJ_SECTION=meminfo\nMemTotal: 4000000 kB\nMemAvailable: 2000000 kB\n",
13 "\x1eCHJ_SECTION=fstab\n" + fstab.join("\n") + (fstab.length ? "\n" : ""),
14 "\x1eCHJ_SECTION=units\n\x1eCHJ_SECTION=files\n\x1eCHJ_SECTION=locations\n\x1eCHJ_SECTION=zram\n\x1eCHJ_SECTION=end\n"
15].join("");
16const area = (state, name) => state.swapAreas.find((entry) => entry.path === name);
18test("two swaps with automatic negative priorities are shown as automatic, not as user input", () => {
19 const state = parseLinuxInspect(inspect({
20 swaps: [["/swapfile-chj", "file", 1048576, 268, -2], ["/swapfile-chj2", "file", 2097152, 0, -3]],
21 fstab: ["3|/swapfile-chj|/swapfile-chj none swap sw 0 0 # CH-J chj.system-monitor", "4|/swapfile-chj2|/swapfile-chj2 none swap sw 0 0 # CH-J chj.system-monitor"]
22 }));
23 const first = area(state, "/swapfile-chj"), second = area(state, "/swapfile-chj2");
24 assert.equal(first.effectivePriority, -2); assert.equal(first.persistentPriority, null); assert.equal(first.priorityMode, "auto"); assert.equal(first.priorityPending, false);
25 assert.equal(first.precedence, 1); assert.equal(second.precedence, 2); assert.equal(first.persistentByChj, true);
26});
27test("explicit 100/10 saved and active: higher priority first; saved-but-not-yet-active is flagged", () => {
28 let state = parseLinuxInspect(inspect({
29 swaps: [["/swapfile-chj2", "file", 2097152, 0, 10], ["/swapfile-chj", "file", 1048576, 0, 100]],
30 fstab: ["4|/swapfile-chj2|/swapfile-chj2 none swap sw,pri=10 0 0 # CH-J chj.system-monitor", "3|/swapfile-chj|/swapfile-chj none swap sw,pri=100 0 0 # CH-J chj.system-monitor"]
31 }));
32 assert.equal(area(state, "/swapfile-chj").precedence, 1); assert.equal(area(state, "/swapfile-chj2").precedence, 2);
33 assert.equal(area(state, "/swapfile-chj").priorityMode, "custom"); assert.equal(area(state, "/swapfile-chj").priorityPending, false);
34 state = parseLinuxInspect(inspect({ swaps: [["/swapfile-chj", "file", 1048576, 0, -2]], fstab: ["3|/swapfile-chj|/swapfile-chj none swap sw,pri=100 0 0"] }));
35 assert.equal(area(state, "/swapfile-chj").priorityPending, true); assert.equal(area(state, "/swapfile-chj").persistentPriority, 100);
36});
37test("equal explicit priorities share precedence; runtime-only and fstab-only areas are both listed", () => {
38 const state = parseLinuxInspect(inspect({
39 swaps: [["/swap/a", "file", 1048576, 0, 5], ["/swap/b", "file", 1048576, 0, 5]],
40 fstab: ["7|/dev/sda2|UUID=1234 none swap sw,pri=1 0 0"]
41 }));
42 assert.equal(area(state, "/swap/a").sharedPriority, true); assert.equal(area(state, "/swap/a").precedence, 1);
43 assert.equal(area(state, "/swap/a").persistent, false); assert.equal(area(state, "/swap/a").priorityMode, "custom");
44 const partition = area(state, "/dev/sda2");
45 assert.equal(partition.active, false); assert.equal(partition.persistentSpec, "UUID=1234"); assert.equal(partition.persistentPriority, 1); assert.equal(partition.management, "partition");
46});
47test("UUID entries match the active device through the canonical identity; old line|raw format still parses", () => {
48 let state = parseLinuxInspect(inspect({ swaps: [["/dev/sda2", "partition", 1048576, 0, -2]], fstab: ["7|/dev/sda2|UUID=1234 none swap sw,pri=40 0 0"] }));
49 assert.equal(area(state, "/dev/sda2").persistent, true); assert.equal(area(state, "/dev/sda2").persistentPriority, 40); assert.equal(state.swapAreas.length, 1);
50 state = parseLinuxInspect(inspect({ swaps: [["/swapfile", "file", 1048576, 0, -2]], fstab: ["3|/swapfile none swap sw 0 0"] }));
51 assert.equal(area(state, "/swapfile").persistent, true);
52});
53test("requests: automatic/explicit/keep priorities and apply mode are validated before the server is contacted", async () => {
54 const calls = [];
55 const service = new VirtualMemoryService({ sessionManager: { _requireConnected: () => ({}), _platform: async () => ({ os: "linux" }) },
56 privilegedExecutor: { run: async (_id, request) => { calls.push(request.args); return { stdout: "" }; }, probe: async () => ({ mode: "root" }) } });
57 for (const [payload, code] of [[{ priority: -3 }, "VM_SWAP_PRIORITY_INVALID"], [{ priority: 32768 }, "VM_SWAP_PRIORITY_INVALID"], [{ priority: 1.5 }, "VM_SWAP_PRIORITY_INVALID"],
58 [{ priority: "abc" }, "VM_SWAP_PRIORITY_INVALID"], [{ priority: "keep" }, "VM_SWAP_PRIORITY_INVALID"], [{ priority: 5, apply: "soon" }, "VM_ARGUMENTS_INVALID"]]) {
59 await assert.rejects(service.manage("s", { action: "priority", path: "/swapfile-chj", ...payload }), { code });
60 }
61 await service.manage("s", { action: "priority", path: "/swapfile-chj", priority: 100, apply: "later" });
62 await service.manage("s", { action: "priority", path: "/swapfile-chj", priority: "auto" });
63 await service.manage("s", { action: "activate", path: "/swapfile-chj", priority: "keep" });
64 assert.deepEqual(calls.filter((args) => args[0] === "manage").map((args) => args.slice(1)), [["priority", "/swapfile-chj", "0", "100", "keep", "later"], ["priority", "/swapfile-chj", "0", "-1", "keep", "now"], ["activate", "/swapfile-chj", "0", "keep", "keep", "now"]]);
65});
SHA-256960d60d015afea31c3a0ffbb9b70a6cb8f5ddf6d2ed748111ddbdc192961ab95

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-256a9605c0870a223b6a8542bb0705edd51d8b04f3069582653417a8397fabcc09a
Tiedostot