//go:build linux || darwin

package runtimeproc

import "testing"

func TestDescendantPIDsReturnsChildrenBeforeParents(t *testing.T) {
	children := childPIDMap([]ProcessInfo{
		{PID: 1},
		{PID: 2, PPID: 1},
		{PID: 3, PPID: 1},
		{PID: 4, PPID: 2},
	})

	got := descendantPIDs(1, children)
	seen := map[int]int{}
	for idx, pid := range got {
		seen[pid] = idx
	}
	for _, pid := range []int{2, 3, 4} {
		if _, ok := seen[pid]; !ok {
			t.Fatalf("descendantPIDs=%v, missing pid %d", got, pid)
		}
	}
	if seen[4] > seen[2] {
		t.Fatalf("descendantPIDs=%v, want child 4 before parent 2", got)
	}
}
