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,146 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPrivateListPaths(t *testing.T) {
|
||||
for _, path := range []string{"config.gradle", "app/keystore/test.jks", "key.properties", ".env", "signing.properties", "sign/HONOR.CER"} {
|
||||
if !privatePath(path) {
|
||||
t.Errorf("rejected %q", path)
|
||||
}
|
||||
}
|
||||
for _, path := range []string{"../secret", "/tmp/key", "C:/key.jks", "x\\key.jks", "a/../key.jks", ".git/config", "build/key.jks", "app/.gradle/x", ".gitignore", ".gitattributes", "foo.", "foo ", "file?bad.jks", "NUL.jks"} {
|
||||
if privatePath(path) {
|
||||
t.Errorf("accepted %q", path)
|
||||
}
|
||||
}
|
||||
names, e := parsePrivateList("\ufeff# comment\r\nconfig.gradle\r\n\napp/key.jks\n")
|
||||
if e != nil || len(names) != 2 {
|
||||
t.Fatal(names, e)
|
||||
}
|
||||
if _, e = parsePrivateList("config.gradle\nconfig.gradle"); e == nil {
|
||||
t.Fatal("duplicate accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrivateListAPIAndWorkspaceLifecycle(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
sources := t.TempDir()
|
||||
source := filepath.Join(sources, "source 工程")
|
||||
if e := os.MkdirAll(source, 0700); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
p := strings.Repeat("a", 32)
|
||||
s := &Server{root: root, token: "private-test", workspaceRoot: sources, projects: map[string]*Project{p: {Dedicated: true, WorkspacePath: source, Files: map[string]File{}}}}
|
||||
work := s.work(p)
|
||||
if e := os.MkdirAll(work, 0700); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e := gitCommand(work, nil, "init", "-q"); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
call := func(method, token string, body any) *httptest.ResponseRecorder {
|
||||
b, _ := json.Marshal(body)
|
||||
req := httptest.NewRequest(method, "/api/v1/private-files?workspacePath="+strings.ReplaceAll(source, " ", "%20"), bytes.NewReader(b))
|
||||
req.Header.Set("Authorization", "Bearer "+token)
|
||||
w := httptest.NewRecorder()
|
||||
s.ServeHTTP(w, req)
|
||||
return w
|
||||
}
|
||||
if w := call("GET", "bad", nil); w.Code != 401 {
|
||||
t.Fatal(w.Code)
|
||||
}
|
||||
get := func() map[string]any {
|
||||
w := call("GET", s.token, nil)
|
||||
if w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body.String())
|
||||
}
|
||||
var v map[string]any
|
||||
if e := json.Unmarshal(w.Body.Bytes(), &v); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
return v
|
||||
}
|
||||
first := get()
|
||||
if first["exists"].(bool) {
|
||||
t.Fatal("unexpected existing list")
|
||||
}
|
||||
put := func(content, hash string) *httptest.ResponseRecorder {
|
||||
return call("PUT", s.token, map[string]string{"workspacePath": source, "content": content, "baseHash": hash})
|
||||
}
|
||||
w := put("config.gradle\nkeys/platform.jks\n", first["hash"].(string))
|
||||
if w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body.String())
|
||||
}
|
||||
if get()["ready"].(bool) {
|
||||
t.Fatal("missing source files must be reported")
|
||||
}
|
||||
if e := s.preparePrivateFiles(p); e == nil {
|
||||
t.Fatal("missing private file accepted")
|
||||
}
|
||||
writeFixture(t, filepath.Join(source, "config.gradle"), "// private script\n")
|
||||
writeFixture(t, filepath.Join(source, "keys", "platform.jks"), "private-key-fixture")
|
||||
if !get()["ready"].(bool) {
|
||||
t.Fatal("existing sources not ready")
|
||||
}
|
||||
if e := s.preparePrivateFiles(p); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
raw, e := os.ReadFile(filepath.Join(work, "config.gradle"))
|
||||
if e != nil || string(raw) != "// private script\n" {
|
||||
t.Fatal(string(raw), e)
|
||||
}
|
||||
files, e := s.projectInventory(p)
|
||||
if e != nil || len(files) != 0 {
|
||||
t.Fatal(files, e)
|
||||
}
|
||||
syncBody, _ := json.Marshal(SyncRequest{Revision: "next", Files: map[string]File{"config.gradle": {Hash: digest([]byte("x"))}}})
|
||||
syncRequest := httptest.NewRequest("POST", "/api/v1/projects/"+p+"/sync", bytes.NewReader(syncBody))
|
||||
syncRequest.Header.Set("Authorization", "Bearer "+s.token)
|
||||
syncResponse := httptest.NewRecorder()
|
||||
s.ServeHTTP(syncResponse, syncRequest)
|
||||
if syncResponse.Code != 400 || !strings.Contains(syncResponse.Body.String(), "私有文件与普通源码同步冲突") {
|
||||
t.Fatal(syncResponse.Code, syncResponse.Body.String())
|
||||
}
|
||||
if w = put("", first["hash"].(string)); w.Code != 409 {
|
||||
t.Fatal("stale edit accepted", w.Code)
|
||||
}
|
||||
current := get()
|
||||
if w = put("", current["hash"].(string)); w.Code != 200 {
|
||||
t.Fatal(w.Code, w.Body.String())
|
||||
}
|
||||
writeFixture(t, filepath.Join(work, "config.gradle"), "manual-change")
|
||||
if e = s.preparePrivateFiles(p); e == nil {
|
||||
t.Fatal("modified private file removed")
|
||||
}
|
||||
raw, _ = os.ReadFile(filepath.Join(work, "config.gradle"))
|
||||
if string(raw) != "manual-change" {
|
||||
t.Fatal("modified copy not preserved")
|
||||
}
|
||||
writeFixture(t, filepath.Join(work, "config.gradle"), "// private script\n")
|
||||
if e = s.preparePrivateFiles(p); e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
if _, e = os.Stat(filepath.Join(work, "config.gradle")); !os.IsNotExist(e) {
|
||||
t.Fatal("removed private file retained")
|
||||
}
|
||||
if _, e = os.Stat(filepath.Join(source, "config.gradle")); e != nil {
|
||||
t.Fatal("source changed", e)
|
||||
}
|
||||
s.projects[p].Files["config.gradle"] = File{Hash: "source"}
|
||||
if w = put("config.gradle", get()["hash"].(string)); w.Code != 409 {
|
||||
t.Fatal("source collision accepted", w.Code)
|
||||
}
|
||||
delete(s.projects[p].Files, "config.gradle")
|
||||
s.projects[p].Busy = true
|
||||
if w = put("config.gradle", get()["hash"].(string)); w.Code != 409 {
|
||||
t.Fatal("busy write accepted", w.Code)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user