Foinse foilsithe
Íosluchtaigh foinse ZIP
CH-J Server Manager
Brabhsáil comhadlanna agus comhaid chun feidhmchlár áirithe a scaoileadh.
CH-J / Server Manager
377 Comhaid
core-20261019T111616Z-160a00bfcddc
Suimigh: · Tógtha:
1
"use strict";3
// System Monitor on an ISOLATED Windows test machine: metrics, latency and pagefile configuration.4
// Pagefile changes only take effect after a restart; this test never restarts Windows and always restores the5
// original configuration. Environment: CHJ_USERS_WINDOWS_HOST, CHJ_USERS_WINDOWS_USER, CHJ_USERS_WINDOWS_FINGERPRINT6
// and CHJ_USERS_WINDOWS_PASSWORD or CHJ_USERS_WINDOWS_KEY (private key path).7
const test = require("node:test");8
const assert = require("node:assert/strict");9
const { SessionManager } = require("../src/main/sessions/sessionManager");10
const { PrivilegedExecutor } = require("../src/main/sessions/privilegedExec");11
const { VirtualMemoryService } = require("../src/main/system/virtualMemoryService");13
const env = process.env;14
const enabled = Boolean(env.CHJ_USERS_WINDOWS_HOST && env.CHJ_USERS_WINDOWS_FINGERPRINT && (env.CHJ_USERS_WINDOWS_PASSWORD || env.CHJ_USERS_WINDOWS_KEY));15
const skip = enabled ? false : "Set CHJ_USERS_WINDOWS_* to run on an isolated Windows test machine.";17
test("System Monitor on an isolated Windows machine", { skip, timeout: 600000 }, async (t) => {18
const fingerprint = Buffer.from(`${env.CHJ_USERS_WINDOWS_FINGERPRINT}=`, "base64").toString("hex");19
const profileService = {20
get: () => ({ id: "w", label: "win", host: env.CHJ_USERS_WINDOWS_HOST, port: 22, username: env.CHJ_USERS_WINDOWS_USER || "codex", authMethod: env.CHJ_USERS_WINDOWS_KEY ? "privateKey" : "password", privateKeyPath: env.CHJ_USERS_WINDOWS_KEY }),21
getHostKey: () => fingerprint, trustHostKey() {}, getStoredPassword: () => env.CHJ_USERS_WINDOWS_PASSWORD || "", markUsed() {}22
};23
const manager = new SessionManager({ profileService });24
const latency = new Promise((resolve) => manager.on("state", (state) => { if (state.latency?.measuredAt) resolve(state.latency); }));25
await manager.connect({ sessionId: "w", profileId: "w" });26
const service = new VirtualMemoryService({ sessionManager: manager, privilegedExecutor: new PrivilegedExecutor({ sessionManager: manager }) });27
const original = await service.read("w");28
t.after(async () => {29
// Restore the original pagefile configuration (pending changes are discarded, Windows is never restarted).30
try {31
const now = await service.read("w");32
if (original.automatic === true && now.automatic !== true) await service.manage("w", { action: "automatic" });33
else if (original.automatic === false) {34
for (const file of original.pagefiles.filter((entry) => entry.configured)) {35
await service.manage("w", { action: "set", drive: file.drive, initialMb: Math.round((file.initial || 0) / 1048576), maximumMb: Math.round((file.maximum || 0) / 1048576) });36
}37
}38
const restored = await service.read("w");39
assert.equal(restored.automatic, original.automatic, "original management mode restored");40
} finally { await manager.disconnectAll(); }41
});43
await t.test("metrics come from the Windows backend; unsupported values are null, not 0", async () => {44
await manager.readSystemMetrics("w");45
await new Promise((resolve) => setTimeout(resolve, 2000));46
const metrics = await manager.readSystemMetrics("w");47
t.diagnostic(`${metrics.osName} ${metrics.kernel} ${metrics.installationType}`);48
assert.equal(metrics.os, "windows");49
assert.equal(metrics.load1, null); assert.equal(metrics.loadAverageSupported, false);50
assert.ok(metrics.cpu.usagePercent >= 0 && metrics.cpu.usagePercent <= 100, "CPU usage from two raw counter samples");51
assert.ok(metrics.cpu.logicalCores >= 1);52
assert.ok(metrics.uptimeSeconds > 0);53
const slices = metrics.memoryDetail.slices;54
const sum = slices.inUse + slices.modified + slices.standby + slices.free;55
assert.ok(Math.abs(sum - metrics.memory.total) / metrics.memory.total < 0.05, "non-overlapping memory lists add up to physical memory");56
assert.ok(metrics.memoryDetail.commit.limit >= metrics.memory.total, "commit limit includes physical memory");57
assert.ok(metrics.disk.total > 0 && metrics.disks.length >= 1);58
assert.ok(metrics.network.interfaces.some((entry) => entry.state === "up"));59
assert.equal(metrics.swap.kind, "pagefile");60
});62
await t.test("ICMP ping and SSH RTT are measured independently", async () => {63
const value = await Promise.race([latency, new Promise((resolve) => setTimeout(() => resolve(null), 40000))]);64
t.diagnostic(JSON.stringify(value));65
assert.ok(value, "latency published");66
assert.ok(value.sshRttMs > 0, "SSH RTT works even if ICMP is blocked");67
assert.equal(value.sshRttMethod, "transport");68
assert.ok(value.pingMs > 0 || ["timeout", "unreachable", "denied"].includes(value.pingStatus), "ICMP reports a value or a concrete reason");69
});71
await t.test("pagefile configuration is read, validated and changed only as a pending restart", async () => {72
t.diagnostic(`original: automatic=${original.automatic} pagefiles=${JSON.stringify(original.pagefiles.map((file) => [file.name, file.configured, file.active]))}`);73
assert.equal(original.platform, "windows");74
assert.equal(original.canManage, true, "elevated administrator session");75
assert.ok(original.pagefiles.some((file) => file.active));76
for (const payload of [77
{ action: "set", drive: "C:", initialMb: 8, maximumMb: 16 },78
{ action: "set", drive: "C:", initialMb: 2048, maximumMb: 1024 },79
{ action: "set", drive: "C:", initialMb: 0, maximumMb: 1024 },80
{ action: "set", drive: "C:; Restart-Computer", initialMb: 1024, maximumMb: 2048 },81
{ action: "set", drive: "C:", initialMb: "1024", maximumMb: 2048.5 }82
]) await assert.rejects(() => service.manage("w", payload), { code: /VM_PAGEFILE_(SIZE|DRIVE)_INVALID/ }, JSON.stringify(payload));83
await assert.rejects(() => service.manage("w", { action: "set", drive: "Q:", initialMb: 1024, maximumMb: 2048 }), { code: "VM_PAGEFILE_DRIVE_INVALID" });84
const system = original.systemDrive || "C:";85
const changed = await service.manage("w", { action: "set", drive: system, initialMb: 1024, maximumMb: 2048 });86
assert.equal(changed.restartRequired, true);87
assert.equal(changed.state.automatic, false);88
const configured = changed.state.pagefiles.find((file) => file.drive === system.toUpperCase());89
assert.equal(configured.initial, 1024 * 1048576); assert.equal(configured.maximum, 2048 * 1048576);90
assert.equal(changed.state.restartPending, true);91
assert.ok(changed.state.pendingChanges.length >= 1);92
assert.match(changed.backup, /pagefile-backup-/);93
const others = changed.state.pagefiles.filter((file) => file.configured && file.drive !== system.toUpperCase());94
if (!others.length) {95
await assert.rejects(() => service.manage("w", { action: "remove", drive: system }), { code: "VM_PAGEFILE_LAST" });96
}97
const concurrent = service.manage("w", { action: "set", drive: system, initialMb: 1024, maximumMb: 4096 });98
await assert.rejects(() => service.manage("w", { action: "automatic" }), { code: "VM_BUSY" });99
await concurrent;100
});101
});SHA-256
d6e7b955bcc757171e07daca18c5b5511f5130494f0545ad92db6975225f5e1fCH-J Proprietary Software License 1.14 · Tá Foinse ar fáil faoin CH-J Proprietary Software License 1.14. Ní chuireann a infhaighteacht a athrú ar na téarmaí ceadúnais nó cearta breise a dheonú.
Cartlann SHA-256
a9605c0870a223b6a8542bb0705edd51d8b04f3069582653417a8397fabcc09a