Files
Netcatty/domain/systemManager/systemTarget.test.ts
T
61839acaca [Feature] System 面板增加 GPU / NPU 占用监控 (#2561) (#2768)
* feat(system): add GPU/NPU monitor tab when accelerators are detected

Probe nvidia-smi and npu-smi during System capabilities checks and show a
GPU sub-tab with utilization, memory/HBM, temperature, power, and compute
processes. Reuses the existing SSH exec + parse pattern (same approach as
open-source remote GPU monitors) without new dependencies.

Related to #2561

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* fix(system): address GPU monitor Bugbot findings

- Use PowerShell nvidia-smi collector for local Windows sessions
- Keep GPU tab in loading state while listAccelerators is pending
- Render compute processes even when device list is empty
- Stop treating Ascend HBM usage rate (%) as megabytes

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* fix(system): address Codex GPU collector review findings

- Wrap POSIX accelerator script with JSON.stringify so nested sed
  quotes cannot break outer sh -c
- Parse Ascend proc-mem whitespace-delimited table rows

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* fix(system): show unknown GPU util/memory as -- not 0%

ResourceBar now treats null/undefined as unavailable, and the GPU
device cards pass through null metrics instead of coalescing to 0.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>
2026-08-06 11:44:08 +08:00

122 lines
2.7 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { buildSystemManagerTabs, shouldCollectServerStats, shouldShowGpuTab } from "./systemTarget.ts";
test("system manager shows overview before detailed management tabs", () => {
assert.deepEqual(buildSystemManagerTabs(null, undefined, null), ["overview", "processes"]);
});
test("gpu tab appears only after nvidia-smi or npu-smi is detected", () => {
assert.equal(shouldShowGpuTab(undefined), false);
assert.equal(
shouldShowGpuTab({
targetOs: "linux",
hasTmux: false,
hasDocker: false,
hasNvidiaSmi: false,
hasNpuSmi: false,
probedAt: 1,
}),
false,
);
assert.equal(
shouldShowGpuTab({
targetOs: "linux",
hasTmux: false,
hasDocker: false,
hasNvidiaSmi: true,
hasNpuSmi: false,
probedAt: 1,
}),
true,
);
const host = {
id: "host-gpu",
label: "GPU",
hostname: "gpu.local",
username: "root",
tags: [],
os: "linux" as const,
};
assert.deepEqual(
buildSystemManagerTabs(host, {
targetOs: "linux",
hasTmux: true,
hasDocker: true,
hasNvidiaSmi: false,
hasNpuSmi: true,
probedAt: 1,
}, null),
["overview", "processes", "tmux", "docker", "gpu"],
);
});
test("system overview stats skip network devices even when a Linux icon was selected", () => {
assert.equal(
shouldCollectServerStats(
{
id: "host-1",
label: "Router",
hostname: "router.local",
username: "admin",
tags: [],
os: "linux",
deviceType: "network",
},
undefined,
null,
),
false,
);
});
test("system overview stats run for Linux and macOS targets", () => {
assert.equal(
shouldCollectServerStats(
{
id: "host-1",
label: "Linux",
hostname: "linux.local",
username: "root",
tags: [],
os: "linux",
},
undefined,
null,
),
true,
);
assert.equal(
shouldCollectServerStats(
{
id: "host-2",
label: "Mac",
hostname: "mac.local",
username: "root",
tags: [],
os: "macos",
},
undefined,
null,
),
true,
);
});
test("FreeBSD icon detection does not enable unsupported system features", () => {
const host = {
id: "host-3",
label: "FreeBSD",
hostname: "freebsd.local",
username: "root",
tags: [],
os: "linux" as const,
distro: "freebsd",
};
assert.equal(shouldCollectServerStats(host, undefined, null), false);
assert.deepEqual(buildSystemManagerTabs(host, undefined, null), ["overview", "processes"]);
});