Add Android APK fleet nodes with Crucible UI integration and tests.
APK wrapper registers platform=android via AETHERFORGE_PLATFORM; fleet UI shows robot icons, Android Access Depth probes, and a shortened mining onion timeline.
This commit is contained in:
121
server/internal/builder/build_apk_test.go
Normal file
121
server/internal/builder/build_apk_test.go
Normal file
@@ -0,0 +1,121 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestApplyApkBuildPreset(t *testing.T) {
|
||||
req := &BuildRequest{
|
||||
WorkerName: "phone-1",
|
||||
ServerURL: "http://192.168.1.5:8989",
|
||||
FusionEnabled: true,
|
||||
Threads: 8,
|
||||
}
|
||||
ApplyApkBuildPreset(req)
|
||||
if !req.ApkMode || req.TargetOS != "android" || req.TargetArch != "arm64" {
|
||||
t.Fatalf("apk preset target: mode=%v os=%q arch=%q", req.ApkMode, req.TargetOS, req.TargetArch)
|
||||
}
|
||||
if req.FusionEnabled || req.SpreadKit || !req.MiningDisabled {
|
||||
t.Fatalf("fusion/spread/mining: fusion=%v spread=%v mining_disabled=%v", req.FusionEnabled, req.SpreadKit, req.MiningDisabled)
|
||||
}
|
||||
if req.Threads != 1 {
|
||||
t.Fatalf("threads=%d want 1", req.Threads)
|
||||
}
|
||||
if req.ApkAgentName != "phone-1" {
|
||||
t.Fatalf("apk_agent_name=%q", req.ApkAgentName)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlatformsForRequestApkMode(t *testing.T) {
|
||||
ps := platformsForRequest(&BuildRequest{ApkMode: true})
|
||||
if len(ps) != 1 || ps[0].GOOS != "linux" || ps[0].GOARCH != "arm64" {
|
||||
t.Fatalf("apk platform: %+v", ps)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildAPKAgentMockGradle(t *testing.T) {
|
||||
h, _ := testHandlerDB(t)
|
||||
setFakeGoSuccess(t, h)
|
||||
|
||||
androidDir := filepath.Join(h.projectRoot, "android")
|
||||
if err := os.MkdirAll(filepath.Join(androidDir, "agent-app", "src", "main", "assets"), 0755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
h.apkBuildFn = func(h *Handler, ctx context.Context, androidDir, buildDir string) (string, error) {
|
||||
apk := filepath.Join(buildDir, "agent-app-release.apk")
|
||||
if err := os.WriteFile(apk, []byte("PK fake apk"), 0644); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return apk, nil
|
||||
}
|
||||
|
||||
req := &BuildRequest{
|
||||
WorkerName: "tablet-1",
|
||||
ServerURL: "http://192.168.1.10:8989",
|
||||
CancelToken: "apk-test-token",
|
||||
ApkMode: true,
|
||||
}
|
||||
resp, code, _ := h.buildAPKAgent(context.Background(), req)
|
||||
if code != 200 || !resp.Success {
|
||||
t.Fatalf("build failed code=%d resp=%+v", code, resp)
|
||||
}
|
||||
if resp.ArtifactPath == "" || resp.DownloadURL == "" {
|
||||
t.Fatalf("missing artifact paths: %+v", resp)
|
||||
}
|
||||
if !strings.HasSuffix(resp.FileName, ".apk") {
|
||||
t.Fatalf("file_name=%q", resp.FileName)
|
||||
}
|
||||
|
||||
cfgPath := filepath.Join(h.apkAssetsDir(), "config.json")
|
||||
raw, err := os.ReadFile(cfgPath)
|
||||
if err != nil {
|
||||
t.Fatalf("config.json: %v", err)
|
||||
}
|
||||
var cfg apkAssetConfig
|
||||
if err := json.Unmarshal(raw, &cfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cfg.ServerURL != req.ServerURL || cfg.WorkerName != "tablet-1" {
|
||||
t.Fatalf("config.json: %+v", cfg)
|
||||
}
|
||||
|
||||
agentAsset := filepath.Join(h.apkAssetsDir(), "agent")
|
||||
if _, err := os.Stat(agentAsset); err != nil {
|
||||
t.Fatalf("agent asset missing: %v", err)
|
||||
}
|
||||
|
||||
// Verify compile step wrote linux/arm64 builtin config with APK flags.
|
||||
buildDirs, _ := os.ReadDir(filepath.Join(h.dataDir, "builds"))
|
||||
if len(buildDirs) == 0 {
|
||||
t.Fatal("no build dir")
|
||||
}
|
||||
builtinPath := filepath.Join(h.dataDir, "builds", buildDirs[0].Name(), "agent", "config", "builtin.go")
|
||||
builtin, err := os.ReadFile(builtinPath)
|
||||
if err != nil {
|
||||
t.Fatalf("builtin.go: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(builtin), "ApkMode") || !strings.Contains(string(builtin), "MiningDisabled: true") {
|
||||
t.Fatalf("apk flags missing from builtin.go:\n%s", builtin)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeRequestApkSkipsWallet(t *testing.T) {
|
||||
h := &Handler{}
|
||||
req := &BuildRequest{
|
||||
WorkerName: "apk-node",
|
||||
ServerURL: "http://192.168.1.5:8989",
|
||||
ApkMode: true,
|
||||
}
|
||||
if err := h.normalizeRequest(req); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if req.TargetOS != "android" || !req.MiningDisabled {
|
||||
t.Fatalf("normalized apk: os=%q mining_disabled=%v", req.TargetOS, req.MiningDisabled)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user