feat: 增加独立构建工作区、服务端ADB与私有文件清单
支持Git提交导入及未提交源码叠加,APK原名下载和完成通知。新增服务端设备安装与按工程维护的私有文件清单,修复Wrapper预检查、布局及IDE读锁和保存状态问题。更新协议、测试和部署记录;服务端0.7.0,插件0.7.1。
This commit is contained in:
1 parent
87652364bc
commit
6f9cc7e7ea
44 files changed
+2742
-87
No files matched your search
@@ -0,0 +1,87 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestServerADBTargetsStoredArtifactAndAuthorizedDevice(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
helper := filepath.Join(root, "adb-helper.go")
|
||||
exe := filepath.Join(root, "adb-helper")
|
||||
if runtime.GOOS == "windows" {
|
||||
exe += ".exe"
|
||||
}
|
||||
writeFixture(t, helper, `package main
|
||||
import("os";"fmt";"encoding/json")
|
||||
func main(){ f,_:=os.OpenFile(os.Getenv("ADB_TEST_LOG"),os.O_CREATE|os.O_APPEND|os.O_WRONLY,0600);json.NewEncoder(f).Encode(os.Args[1:]);f.Close();if os.Args[1]=="devices"{fmt.Println("List of devices attached\nremote-123 device model:Remote_Tablet\nlocked unauthorized")}else{fmt.Println("Success")} }
|
||||
`)
|
||||
cmd := exec.Command("go", "build", "-o", exe, helper)
|
||||
if out, e := cmd.CombinedOutput(); e != nil {
|
||||
t.Fatalf("helper: %v %s", e, out)
|
||||
}
|
||||
log := filepath.Join(root, "calls.jsonl")
|
||||
t.Setenv("ADB_TEST_LOG", log)
|
||||
cfg := filepath.Join(root, "env.json")
|
||||
data, _ := json.Marshal(BuildEnvironment{Adb: exe})
|
||||
writeFixture(t, cfg, string(data))
|
||||
bid := strings.Repeat("a", 32)
|
||||
content := []byte("apk-fixture")
|
||||
a := Artifact{Name: "0-app.apk", Size: int64(len(content)), Hash: digest(content)}
|
||||
s := &Server{root: root, token: "secret", environmentFile: cfg, builds: map[string]*Build{bid: {ID: bid, Status: "success", Artifacts: []Artifact{a}}}}
|
||||
apk := filepath.Join(root, "artifacts", bid, a.Name)
|
||||
writeFixture(t, apk, string(content))
|
||||
call := func(route, method, token string, body any) *httptest.ResponseRecorder {
|
||||
b, _ := json.Marshal(body)
|
||||
req := httptest.NewRequest(method, "/api/v1/adb/"+route, bytes.NewReader(b))
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
w := httptest.NewRecorder()
|
||||
s.ServeHTTP(w, req)
|
||||
return w
|
||||
}
|
||||
if w := call("devices", "GET", "wrong", nil); w.Code != 401 {
|
||||
t.Fatal(w.Code)
|
||||
}
|
||||
if w := call("devices", "GET", "secret", nil); w.Code != 200 || !strings.Contains(w.Body.String(), "Remote Tablet") {
|
||||
t.Fatal(w.Code, w.Body.String())
|
||||
}
|
||||
request := map[string]string{"buildId": bid, "artifact": a.Name, "serial": "remote-123"}
|
||||
if w := call("install", "POST", "secret", request); w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body.String())
|
||||
}
|
||||
raw, _ := os.ReadFile(log)
|
||||
if !strings.Contains(string(raw), `["-s","remote-123","install","-r",`) {
|
||||
t.Fatal(string(raw))
|
||||
}
|
||||
for _, serial := range []string{"locked", "missing", "-d"} {
|
||||
request["serial"] = serial
|
||||
if w := call("install", "POST", "secret", request); w.Code == 200 {
|
||||
t.Fatal("accepted unauthorized/missing serial", serial)
|
||||
}
|
||||
}
|
||||
request["serial"] = "remote-123"
|
||||
writeFixture(t, apk, "tampered")
|
||||
if w := call("install", "POST", "secret", request); w.Code != 409 {
|
||||
t.Fatal(w.Code, w.Body.String())
|
||||
}
|
||||
request["artifact"] = "../foreign.apk"
|
||||
if w := call("install", "POST", "secret", request); w.Code != 400 {
|
||||
t.Fatal(w.Code)
|
||||
}
|
||||
raw, _ = os.ReadFile(log)
|
||||
if strings.Count(string(raw), `"install"`) != 1 {
|
||||
t.Fatal("unexpected additional install", string(raw))
|
||||
}
|
||||
s.builds[bid].Status = "failed"
|
||||
request["artifact"] = a.Name
|
||||
if w := call("install", "POST", "secret", request); w.Code != 400 {
|
||||
t.Fatal(w.Code)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user