d02b544e08
No hardcoded tool lists. Scans all $PATH directories for executables (5541 on this system), then probes known runtime patterns for version info (23 detected: Go, Python, Node, Rust, Ruby, Perl, Java, Dart, Deno, Bun, Lua, LuaJIT, Guile, GCC, Clang, NASM + package managers). System prompt includes: OS, shell, runtime versions, and notable tools (git, docker, kubectl, fzf, rg, etc.) from the full PATH scan. Total executable count reported so the LLM knows the full scope. Milestones updated: M6 fixed context prefix, M12 multimodality.
94 lines
1.9 KiB
Go
94 lines
1.9 KiB
Go
package bash
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestScanPATH(t *testing.T) {
|
|
binaries := scanPATH()
|
|
if len(binaries) == 0 {
|
|
t.Fatal("should find at least some executables in PATH")
|
|
}
|
|
t.Logf("Found %d executables in PATH", len(binaries))
|
|
|
|
// Basic sanity — ls should be in PATH
|
|
hasLS := false
|
|
for _, b := range binaries {
|
|
if b == "ls" {
|
|
hasLS = true
|
|
break
|
|
}
|
|
}
|
|
if !hasLS {
|
|
t.Error("ls should be in PATH")
|
|
}
|
|
}
|
|
|
|
func TestHarvestInventory(t *testing.T) {
|
|
inv := HarvestInventory(context.Background())
|
|
|
|
if inv.OS == "" {
|
|
t.Error("OS should be detected")
|
|
}
|
|
t.Logf("OS: %s", inv.OS)
|
|
|
|
if inv.Shell == "" {
|
|
t.Error("Shell should be detected")
|
|
}
|
|
t.Logf("Shell: %s", inv.Shell)
|
|
|
|
t.Logf("Tools: %d executables in PATH", len(inv.Tools))
|
|
|
|
t.Logf("Runtimes (%d):", len(inv.Runtimes))
|
|
for _, rt := range inv.Runtimes {
|
|
t.Logf(" %s: %s", rt.Name, rt.Version)
|
|
}
|
|
|
|
// Should find at least Go (we're running Go tests)
|
|
hasGo := false
|
|
for _, rt := range inv.Runtimes {
|
|
if rt.Name == "go" {
|
|
hasGo = true
|
|
break
|
|
}
|
|
}
|
|
if !hasGo {
|
|
t.Error("should detect Go runtime (we're running Go tests)")
|
|
}
|
|
}
|
|
|
|
func TestInventory_String(t *testing.T) {
|
|
inv := &SystemInventory{
|
|
OS: "Linux 6.18 x86_64",
|
|
Shell: "/usr/bin/zsh",
|
|
Tools: []string{"git", "make", "docker"},
|
|
Runtimes: []Runtime{
|
|
{"go", "go version go1.26.1"},
|
|
{"python3", "Python 3.14.3"},
|
|
},
|
|
}
|
|
|
|
s := inv.String()
|
|
if !strings.Contains(s, "Linux") {
|
|
t.Error("should contain OS")
|
|
}
|
|
if !strings.Contains(s, "git") {
|
|
t.Error("should contain tools")
|
|
}
|
|
if !strings.Contains(s, "go:") {
|
|
t.Error("should contain runtimes")
|
|
}
|
|
if !strings.Contains(s, "3 executables in PATH") {
|
|
t.Errorf("should show tool count, got: %s", s)
|
|
}
|
|
}
|
|
|
|
func TestInventory_NilString(t *testing.T) {
|
|
var inv *SystemInventory
|
|
if inv.String() != "" {
|
|
t.Error("nil inventory should return empty string")
|
|
}
|
|
}
|