import { describe, expect, it } from "vite-plus/test";
import type { ResourceTelemetryProcess } from "@t3tools/contracts";
import * as DateTime from "effect/DateTime";
import { visibleResourceTelemetryProcesses } from "./ResourceTelemetryDiagnostics.logic";
const process = (pid: number, ppid: number, depth: number): ResourceTelemetryProcess => ({
identity: { pid, startTimeMs: pid * 1_000 },
ppid,
childPids: [],
depth,
name: `process-${pid}`,
command: `process-${pid}`,
status: "Running",
category: pid === 1 ? "server" : "server-child",
cpuPercent: 0,
cpuTimeMs: 0,
residentBytes: 0,
peakResidentBytes: 0,
virtualBytes: 0,
ioReadBytes: 0,
ioWriteBytes: 0,
ioReadBytesPerSecond: 0,
ioWriteBytesPerSecond: 0,
ioSemantics: "storage",
runTimeMs: 0,
firstSeenAt: DateTime.makeUnsafe(0),
lastSeenAt: DateTime.makeUnsafe(0),
});
describe("visibleResourceTelemetryProcesses", () => {
it("hides descendants by parentage even when rows are not depth-first", () => {
const processes = [
process(1, 0, 0),
process(10, 0, 0),
process(2, 1, 1),
process(11, 10, 1),
process(3, 2, 2),
];
expect(visibleResourceTelemetryProcesses(processes, new Set(["1:1000"]))).toEqual([
processes[0],
processes[1],
processes[3],
]);
});
});