Verify system monitoring against an explicit hosted OpenCode server
This commit is contained in:
+17
-7
@@ -1,31 +1,41 @@
|
||||
import assert from "node:assert/strict"
|
||||
import { execFileSync } from "node:child_process"
|
||||
import { parseArgs } from "node:util"
|
||||
|
||||
const cli = process.argv[2]
|
||||
const { positionals: [cli], values } = parseArgs({
|
||||
allowPositionals: true,
|
||||
options: { server: { type: "string" }, directory: { type: "string" }, "require-gpu": { type: "boolean" } },
|
||||
})
|
||||
if (!cli) throw new Error("Pass the OpenCode CLI executable path")
|
||||
const location = values.directory ? { directory: values.directory } : undefined
|
||||
const query = location ? `?${new URLSearchParams({ "location[directory]": location.directory })}` : ""
|
||||
function api(method, route, body) {
|
||||
const args = ["api", method, route]
|
||||
if (values.server) args.unshift("--server", values.server)
|
||||
if (body !== undefined) args.push("--data", JSON.stringify(body))
|
||||
const result = execFileSync(cli, args, { encoding: "utf8", windowsHide: true, timeout: 20000 })
|
||||
return result.trim() ? JSON.parse(result) : undefined
|
||||
}
|
||||
|
||||
const plugins = api("get", "/api/plugin").data
|
||||
const plugins = api("get", "/api/plugin" + query).data
|
||||
const plugin = plugins.find(item => item.id === "local-system-monitor")
|
||||
assert.equal(plugin?.state.status, "active")
|
||||
assert.equal(plugin.features.gui, true)
|
||||
assert.equal(plugin.features.rpc, true)
|
||||
const snapshot = api("post", "/api/rpc/local-system-monitor/snapshot", { input: {} }).output
|
||||
if (process.argv.includes("--require-gpu")) {
|
||||
const snapshot = api("post", "/api/rpc/local-system-monitor/snapshot" + query, { input: {} }).output
|
||||
assert.ok(Number.isFinite(snapshot.cpu.percent) && snapshot.cpu.percent >= 0 && snapshot.cpu.percent <= 100)
|
||||
assert.ok(snapshot.ram.total > 0 && snapshot.ram.used + snapshot.ram.free === snapshot.ram.total)
|
||||
if (values["require-gpu"]) {
|
||||
assert.equal(snapshot.gpu.error, null)
|
||||
assert.ok(snapshot.gpu.adapter?.percent != null)
|
||||
const percent = snapshot.gpu.adapter?.percent
|
||||
assert.ok(Number.isFinite(percent) && percent >= 0 && percent <= 100)
|
||||
}
|
||||
assert.ok(snapshot.disks.items.length > 0)
|
||||
console.log("Installed plugin, GUI feature, RPC, and disk readings: passed")
|
||||
console.log("Installed plugin, GUI feature, RPC, and CPU/RAM/disk readings: passed")
|
||||
|
||||
let sessionID
|
||||
try {
|
||||
const result = api("post", "/api/session", { title: "System Monitor self-test" })
|
||||
const result = api("post", "/api/session", { title: "System Monitor self-test", location })
|
||||
sessionID = (result.data ?? result).id
|
||||
assert.ok(sessionID)
|
||||
api("post", `/api/session/${sessionID}/command`, { name: "system_status", text: "" })
|
||||
|
||||
Reference in New Issue
Block a user