- TokenCtx + Classify + formatTokenCount (R2.2, R3.1-3.5, R4.4) - ReadTokenCtx orchestrator: env > PID walk > transcript parse (R1.1-1.6, R2.1-2.6) - parseLastUsage: 10MB scanner, JSONL last-assistant-wins, zero-usage qualifies (R2.1-2.3) - parsePIDFile: strict two-line layout; rejects partial/corrupted writes (R6.2-6.3) - resolveViaPIDWalk: 8-hop ancestor walk, liveness + start-stamp check (R1.2, R6.1, R6.3) - proc_darwin.go (x/sys/unix kinfo_proc) + proc_linux.go (/proc/stat field 22) - parseStatStartTime: platform-agnostic, handles comm with parens/spaces Parent 1.0 from dev/plans/26174-planctl-context-tokens/tasks.md
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
// spec:26174-planctl-context-tokens/R1.2+D§3.3
|
|
func TestPpidOf_selfParent(t *testing.T) {
|
|
got := ppidOf(os.Getpid())
|
|
want := os.Getppid()
|
|
if got != want {
|
|
t.Errorf("ppidOf(getpid()) = %d, want getppid()=%d", got, want)
|
|
}
|
|
}
|
|
|
|
// spec:26174-planctl-context-tokens/R6.3+D§3.3
|
|
func TestProcessAlive_self(t *testing.T) {
|
|
if !processAlive(os.Getpid()) {
|
|
t.Error("processAlive(self) returned false")
|
|
}
|
|
}
|
|
|
|
// spec:26174-planctl-context-tokens/R6.3+D§3.3
|
|
func TestProcessAlive_zeroOrNegative(t *testing.T) {
|
|
if processAlive(0) {
|
|
t.Error("processAlive(0) should be false")
|
|
}
|
|
if processAlive(-1) {
|
|
t.Error("processAlive(-1) should be false")
|
|
}
|
|
}
|
|
|
|
// spec:26174-planctl-context-tokens/R6.3+D§3.3+D§4.1
|
|
func TestProcessStartTimeSec_selfNonZero(t *testing.T) {
|
|
stamp, err := processStartTimeSec(os.Getpid())
|
|
if err != nil {
|
|
t.Fatalf("processStartTimeSec(self): %v", err)
|
|
}
|
|
if stamp <= 0 {
|
|
t.Errorf("expected positive stamp, got %d", stamp)
|
|
}
|
|
}
|
|
|
|
// spec:26174-planctl-context-tokens/R6.3+D§3.3
|
|
// ppidOf of a very unlikely PID (huge number) should return 0 (not panic).
|
|
func TestPpidOf_nonexistent(t *testing.T) {
|
|
got := ppidOf(999_999_999)
|
|
if got != 0 {
|
|
t.Errorf("ppidOf(nonexistent) = %d, want 0", got)
|
|
}
|
|
}
|