Files
pj eed99e58aa refactor: code organization cleanup (#35)
* chore: fix gitignore + decisions doc after web->inspect-ui rename

Update web/ references to inspect-ui/ in .gitignore and Makefile. Add
decisions.md tracking architectural decisions from code-org discussion.

* refactor: rename pkg/spec-api to pkg/spec

Aligns the directory name with the npm package name @sanderling/spec.
Updates Makefile, package.json directory field, and resolveSpecAPIPath.

* refactor(verifier): split bindings.go into types.go + bindings.go

Move shared public types (Action, ActionKind, LogEntry, Exception) to
types.go. bindings.go retains internal JS runtime wiring only.

* refactor(inspect): split runs.go into runs.go, runs_cache.go, runs_decode.go

runs.go: types (RunSummary, StepSummary, RunDetail, Run) and Scan.
runs_cache.go: Cache type, Open/Step/Detail methods, parseRun, scanSteps.
runs_decode.go: readMeta, tallyTrace, decodeStepSummary, validRunID.

* refactor: move android_env.go to internal/android/

Extracts Android device/AVD/adb logic into internal/android package.
Exports EnsureDevice, AdbReverse, AdbReverseRemove, EnvWithAndroidPlatformTools, AdbBinary.
Moves tests to internal/android/android_test.go. cmd/sanderling becomes a thin caller.

* refactor: extract test pipeline to internal/testrun/

runTestPipeline logic moves to testrun.Execute. buildDriver, resolveSpecAPIPath,
pickFreePort, and the progress logger move to internal/testrun/. cmd/sanderling/test_run.go
becomes a thin adapter. Tests follow their code.

* ci: update workflow paths after pkg/spec-api -> pkg/spec rename
2026-04-22 20:35:34 +07:00

94 lines
2.0 KiB
Go

package android
import (
"reflect"
"testing"
)
func TestParseAdbDevices_OnlineOnly(t *testing.T) {
output := `List of devices attached
emulator-5554 device
emulator-5556 offline
physical-abc device
`
got := parseAdbDevices(output)
want := []string{"emulator-5554", "physical-abc"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("got %v, want %v", got, want)
}
}
func TestParseAdbDevices_Empty(t *testing.T) {
output := "List of devices attached\n\n"
got := parseAdbDevices(output)
if len(got) != 0 {
t.Fatalf("got %v, want empty", got)
}
}
func TestParseAVDList_DropsInfoLines(t *testing.T) {
output := `INFO | Storing crashdata in: /tmp/x
Medium_Phone_API_36.0
sanderling_test
`
got := parseAVDList(output)
want := []string{"Medium_Phone_API_36.0", "sanderling_test"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("got %v, want %v", got, want)
}
}
func TestPickAVD_ExplicitName(t *testing.T) {
got, err := pickAVD("Pixel_7", []string{"Pixel_7", "sanderling_test"})
if err != nil {
t.Fatal(err)
}
if got != "Pixel_7" {
t.Fatalf("got %q, want Pixel_7", got)
}
}
func TestPickAVD_ExplicitMissing(t *testing.T) {
_, err := pickAVD("Nope", []string{"Pixel_7"})
if err == nil {
t.Fatal("expected error")
}
}
func TestPickAVD_SingleAvailable(t *testing.T) {
got, err := pickAVD("", []string{"sanderling_test"})
if err != nil {
t.Fatal(err)
}
if got != "sanderling_test" {
t.Fatalf("got %q, want sanderling_test", got)
}
}
func TestPickAVD_AmbiguousWithoutHint(t *testing.T) {
_, err := pickAVD("", []string{"a", "b"})
if err == nil {
t.Fatal("expected error when multiple AVDs and no --avd")
}
}
func TestPickAVD_NoneAvailable(t *testing.T) {
_, err := pickAVD("", nil)
if err == nil {
t.Fatal("expected error when no AVDs exist")
}
}
func TestPathContains(t *testing.T) {
path := "/usr/bin:/opt/tools:/usr/local/bin"
if !pathContains(path, "/opt/tools") {
t.Error("expected /opt/tools in PATH")
}
if pathContains(path, "/nope") {
t.Error("did not expect /nope in PATH")
}
}