Публикуемый источник
Загрузка источника ZIP
CH-J Server Manager
Просмотр каталогов и файлов для конкретного выпуска приложения.
CH-J / Server Manager
377 файлы
core-20261019T111616Z-160a00bfcddc
Добавлено: · Построено:
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.5
const test = require("node:test");6
const assert = require("node:assert/strict");7
const { parseLinuxInspect, VirtualMemoryService } = require("../src/main/system/virtualMemoryService");9
const 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("");16
const area = (state, name) => state.swapAreas.find((entry) => entry.path === name);18
test("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
});27
test("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
});37
test("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
});47
test("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
});53
test("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-256
960d60d015afea31c3a0ffbb9b70a6cb8f5ddf6d2ed748111ddbdc192961ab95CH-J Proprietary Software License 1.14 · Источник представлен в CH-J Proprietary Software License 1.14. Его наличие не изменяет лицензионных условий и не предоставляет дополнительных прав.
Архив SHA-256
a9605c0870a223b6a8542bb0705edd51d8b04f3069582653417a8397fabcc09a