mirror of
https://github.com/saymrwulf/KnowledgeRefinery.git
synced 2026-05-14 20:47:51 +00:00
macOS app for corpus ingestion, semantic search, and concept universe visualization powered by local LLMs via LM Studio. Architecture: - Go daemon (17MB single binary, zero dependencies) - chi router, pure-Go SQLite, tiktoken tokenizer - 6-stage pipeline: scan → extract → chunk → embed → annotate → conceptualize - Brute-force cosine vector search in memory - 89 tests across 8 packages - SwiftUI app (macOS 15+) - Multi-workspace management with auto-start daemons - Live pipeline progress, search, concept browser - WebGPU 3D universe renderer with Canvas2D fallback - Custom crystal app icon
72 lines
1.7 KiB
Go
72 lines
1.7 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestCORSMiddleware(t *testing.T) {
|
|
handler := CORSMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusOK)
|
|
}))
|
|
|
|
// Test regular request
|
|
req := httptest.NewRequest("GET", "/test", nil)
|
|
w := httptest.NewRecorder()
|
|
handler.ServeHTTP(w, req)
|
|
|
|
if w.Header().Get("Access-Control-Allow-Origin") != "*" {
|
|
t.Error("CORS origin header missing")
|
|
}
|
|
if w.Header().Get("Access-Control-Allow-Methods") != "*" {
|
|
t.Error("CORS methods header missing")
|
|
}
|
|
if w.Header().Get("Access-Control-Allow-Headers") != "*" {
|
|
t.Error("CORS headers header missing")
|
|
}
|
|
if w.Code != http.StatusOK {
|
|
t.Errorf("expected 200, got %d", w.Code)
|
|
}
|
|
}
|
|
|
|
func TestCORSPreflightOptions(t *testing.T) {
|
|
called := false
|
|
handler := CORSMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
called = true
|
|
}))
|
|
|
|
req := httptest.NewRequest("OPTIONS", "/test", nil)
|
|
w := httptest.NewRecorder()
|
|
handler.ServeHTTP(w, req)
|
|
|
|
if called {
|
|
t.Error("OPTIONS request should not reach inner handler")
|
|
}
|
|
if w.Code != http.StatusOK {
|
|
t.Errorf("expected 200 for OPTIONS, got %d", w.Code)
|
|
}
|
|
}
|
|
|
|
func TestNewRouter(t *testing.T) {
|
|
r := NewRouter()
|
|
if r == nil {
|
|
t.Fatal("NewRouter returned nil")
|
|
}
|
|
|
|
// Add a test route and verify it works
|
|
r.Get("/test", func(w http.ResponseWriter, r *http.Request) {
|
|
w.Write([]byte("ok"))
|
|
})
|
|
|
|
req := httptest.NewRequest("GET", "/test", nil)
|
|
w := httptest.NewRecorder()
|
|
r.ServeHTTP(w, req)
|
|
|
|
if w.Code != http.StatusOK {
|
|
t.Errorf("expected 200, got %d", w.Code)
|
|
}
|
|
if w.Body.String() != "ok" {
|
|
t.Errorf("expected 'ok', got %q", w.Body.String())
|
|
}
|
|
}
|