feat: establish Orbit models, migrations and development baseline

This commit is contained in:
2026-09-17 07:04:21 +08:00
commit 4f2935e36f
84 changed files with 4915 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
// Package httpserver exposes bootstrap health endpoints only. Task, workflow,
// authentication and WebSocket APIs will be implemented in subsequent slices.
package httpserver
import (
"context"
"encoding/json"
"net/http"
"time"
)
type Checker func(context.Context) error
func New(addr string, ready Checker) *http.Server {
mux := http.NewServeMux()
write := func(w http.ResponseWriter, status int, body map[string]string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_ = json.NewEncoder(w).Encode(body)
}
mux.HandleFunc("GET /health/live", func(w http.ResponseWriter, r *http.Request) {
write(w, http.StatusOK, map[string]string{"status": "alive"})
})
mux.HandleFunc("GET /health/ready", func(w http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), 2*time.Second)
defer cancel()
if ready == nil || ready(ctx) != nil {
write(w, http.StatusServiceUnavailable, map[string]string{"status": "not_ready"})
return
}
write(w, http.StatusOK, map[string]string{"status": "ready", "scope": "database_and_schema"})
})
return &http.Server{Addr: addr, Handler: mux, ReadHeaderTimeout: 5 * time.Second, ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second, IdleTimeout: 60 * time.Second, MaxHeaderBytes: 16 << 10}
}

View File

@@ -0,0 +1,21 @@
package httpserver
import (
"context"
"errors"
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestHealthSeparatesLivenessAndReadiness(t *testing.T) {
server := New("127.0.0.1:0", func(context.Context) error { return errors.New("internal-database-details") })
for path, want := range map[string]int{"/health/live": 200, "/health/ready": 503, "/v1/tasks": 404} {
rr := httptest.NewRecorder()
server.Handler.ServeHTTP(rr, httptest.NewRequest(http.MethodGet, path, nil))
if rr.Code != want || strings.Contains(rr.Body.String(), "internal-database-details") {
t.Fatalf("%s: %d %s", path, rr.Code, rr.Body.String())
}
}
}