mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-08 05:23:41 +08:00
80fbb4f6db
Register vehicle controls, planner modes, UI actions and Galaxy services after their providers exist. Wire the shared runtime entrypoints and cover their combined behavior. Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Daniel Koepping <elkoled@gmail.com> Co-authored-by: Danny <dannyirwin31@yahoo.com> Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com> Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com> Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com> Co-authored-by: Kacper Rączy <gfw.kra@gmail.com> Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu> Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com> Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com> Co-authored-by: stef <19478336+stefpi@users.noreply.github.com> Co-authored-by: whoisdomi <dcantu83@gmail.com> Co-authored-by: Intelli <contact@intelli.software> Co-authored-by: haraschax <6804392+haraschax@users.noreply.github.com> Co-authored-by: prabhaavp <prabhaav@msu.edu>
46 lines
2.9 KiB
JavaScript
46 lines
2.9 KiB
JavaScript
import assert from "node:assert/strict"
|
|
import { readFileSync } from "node:fs"
|
|
import { normalizeSnapshot, processFeature, processRows, processState, displayNumber, vital } from "../web/js/system-monitor-data.js"
|
|
|
|
const fixture = JSON.parse(readFileSync(new URL("../web/data/system-monitor.sample.json", import.meta.url), "utf8"))
|
|
const sample = normalizeSnapshot(fixture)
|
|
assert.equal(sample.mode, undefined)
|
|
assert.equal(sample.processCount, 6)
|
|
assert.equal(sample.cpuPercent, 27.4)
|
|
assert.equal(processRows(sample).length, 4)
|
|
assert.deepEqual(processRows(sample).map(p => p.pid), [102, 101, 104, 103])
|
|
assert.deepEqual(processRows(sample, { scope: "users" }).map(p => p.pid), [102, 101, 105, 104, 103])
|
|
assert.equal(processRows(sample, { scope: "all" }).length, 6)
|
|
assert.deepEqual(processRows(sample, { query: "driving model" }).map(p => p.pid), [102])
|
|
assert.deepEqual(processRows(sample, { query: "sleeping", scope: "all" }).map(p => p.pid), [102, 104, 2, 103])
|
|
assert.deepEqual(processRows(sample, { sort: "cpu", descending: false, scope: "all" }).map(p => p.pid), [104, 105, 101, 102, 2, 103])
|
|
assert.equal(processFeature(sample.processes.at(-1)), "")
|
|
assert.equal(processState("R"), "Running")
|
|
assert.equal(processState("?"), "?")
|
|
assert.equal(processState("constructor"), "constructor")
|
|
assert.equal(processState("toString"), "toString")
|
|
assert.equal(displayNumber(null, "%"), "—")
|
|
assert.equal(displayNumber(0, "%"), "0.0%")
|
|
assert.equal(vital(sample, "cpuTempC", "onboardMaxAgeMs", 2499), 51.2)
|
|
assert.equal(vital(sample, "cpuTempC", "onboardMaxAgeMs", 2500), null)
|
|
assert.equal(vital(sample, "hotspotTempC", "maxAgeMs"), null)
|
|
assert.throws(() => normalizeSnapshot({ ...fixture, cores: null }), /Invalid/)
|
|
assert.throws(() => normalizeSnapshot({ ...fixture, processes: [{ pid: 1 }] }), /Invalid/)
|
|
assert.throws(() => normalizeSnapshot({ ...fixture, cores: [fixture.cores[0], fixture.cores[0]] }), /Duplicate/)
|
|
assert.throws(() => normalizeSnapshot({ ...fixture, processes: [fixture.processes[0], fixture.processes[0]] }), /Duplicate/)
|
|
const withUnknowns = normalizeSnapshot({ ...fixture, cpuPercent: -1,
|
|
processes: [{ ...fixture.processes[0], cpu: Infinity, memoryMiB: "0" }] })
|
|
assert.equal(withUnknowns.cpuPercent, null)
|
|
assert.equal(withUnknowns.processes[0].cpu, null)
|
|
assert.equal(withUnknowns.processes[0].memoryMiB, null)
|
|
const impossible = normalizeSnapshot({ ...fixture,
|
|
memory: { ...fixture.memory, usedMiB: fixture.memory.totalMiB + 1 },
|
|
storage: { usedGiB: 200, totalGiB: 100 },
|
|
vitals: { ...fixture.vitals, memoryUsedBytes: 200, memoryTotalBytes: 100, memoryMaxAgeMs: 2500 } })
|
|
assert.equal(impossible.memory.usedMiB, null)
|
|
assert.equal(impossible.memory.percent, null)
|
|
assert.equal(impossible.storage.usedGiB, null)
|
|
assert.equal(vital(impossible, "memoryUsedBytes", "memoryMaxAgeMs"), null)
|
|
assert.equal(vital(impossible, "memoryTotalBytes", "memoryMaxAgeMs"), null)
|
|
console.log("System Monitor data contract: pass")
|