feat: add docker deployment

This commit is contained in:
Yoilun
2026-05-25 22:41:12 +08:00
parent 8c1093a53c
commit 4262191462
9 changed files with 225 additions and 4 deletions

View File

@@ -202,6 +202,60 @@ func TestReadOnlyEndpointsRejectUnsupportedMethods(t *testing.T) {
}
}
func TestStaticFrontendServesIndexAndAssets(t *testing.T) {
root := t.TempDir()
staticDir := filepath.Join(root, "dist")
if err := os.MkdirAll(filepath.Join(staticDir, "assets"), 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(staticDir, "index.html"), []byte(`<html><title>管理台</title><script src="/assets/app.js"></script></html>`), 0o644); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(staticDir, "assets", "app.js"), []byte(`console.log("ok")`), 0o644); err != nil {
t.Fatal(err)
}
handler := New(app.Config{CodexHome: root, HTTPAddr: "127.0.0.1:0", StaticDir: staticDir})
for _, path := range []string{"/", "/workflow"} {
req := httptest.NewRequest(http.MethodGet, path, nil)
rec := httptest.NewRecorder()
handler.ServeHTTP(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("%s status = %d, body = %s", path, rec.Code, rec.Body.String())
}
if !strings.Contains(rec.Body.String(), "<title>管理台</title>") {
t.Fatalf("%s did not serve index.html: %s", path, rec.Body.String())
}
}
req := httptest.NewRequest(http.MethodGet, "/assets/app.js", nil)
rec := httptest.NewRecorder()
handler.ServeHTTP(rec, req)
if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), `console.log("ok")`) {
t.Fatalf("asset status = %d, body = %s", rec.Code, rec.Body.String())
}
}
func TestStaticFrontendDoesNotMaskMissingAPIRoutes(t *testing.T) {
root := t.TempDir()
staticDir := filepath.Join(root, "dist")
if err := os.MkdirAll(staticDir, 0o755); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(staticDir, "index.html"), []byte(`<html>index</html>`), 0o644); err != nil {
t.Fatal(err)
}
req := httptest.NewRequest(http.MethodGet, "/api/missing", nil)
rec := httptest.NewRecorder()
New(app.Config{CodexHome: root, HTTPAddr: "127.0.0.1:0", StaticDir: staticDir}).ServeHTTP(rec, req)
if rec.Code != http.StatusNotFound {
t.Fatalf("status = %d, want %d, body = %s", rec.Code, http.StatusNotFound, rec.Body.String())
}
}
func TestAgentValidateEndpointReturnsDiffAndRejectsUnsupportedMethods(t *testing.T) {
root := t.TempDir()
agentsDir := filepath.Join(root, "agents")