mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
dea06c391c
* Improve the web launcher and gateway integration across backend and frontend. - add runtime model availability checks for local and OAuth-backed models - support launcher-driven gateway host overrides and websocket URL resolution - add gateway log clearing and keep incremental log sync consistent after resets - migrate session history APIs to JSONL metadata-backed storage with legacy fallback - expose session titles and improve chat history loading and error handling - move shared backend runtime helpers into the web utils package - avoid blocking web startup when automatic onboard initialization fails - add backend tests covering gateway readiness, host resolution, models, logs, and sessions * feat(agent): add skills and tools management APIs and UI - add backend APIs to list, view, import, and delete skills - add tool status and toggle endpoints with dependency-aware config updates - add agent skills/tools pages, routes, sidebar entries, and i18n strings - add backend tests for the new skills and tools flows * chore(frontend): upgrade shadcn to 4.0.5 and refresh lockfile * chore(web): keep backend dist placeholder tracked
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/sipeed/picoclaw/pkg/config"
|
|
"github.com/sipeed/picoclaw/web/backend/launcherconfig"
|
|
)
|
|
|
|
func TestGatewayHostOverrideUsesExplicitRuntimePublic(t *testing.T) {
|
|
configPath := filepath.Join(t.TempDir(), "config.json")
|
|
launcherPath := launcherconfig.PathForAppConfig(configPath)
|
|
if err := launcherconfig.Save(launcherPath, launcherconfig.Config{
|
|
Port: 18800,
|
|
Public: false,
|
|
}); err != nil {
|
|
t.Fatalf("launcherconfig.Save() error = %v", err)
|
|
}
|
|
|
|
h := NewHandler(configPath)
|
|
h.SetServerOptions(18800, true, true, nil)
|
|
|
|
if got := h.gatewayHostOverride(); got != "0.0.0.0" {
|
|
t.Fatalf("gatewayHostOverride() = %q, want %q", got, "0.0.0.0")
|
|
}
|
|
}
|
|
|
|
func TestBuildWsURLUsesRequestHostWhenLauncherPublicSaved(t *testing.T) {
|
|
configPath := filepath.Join(t.TempDir(), "config.json")
|
|
launcherPath := launcherconfig.PathForAppConfig(configPath)
|
|
if err := launcherconfig.Save(launcherPath, launcherconfig.Config{
|
|
Port: 18800,
|
|
Public: true,
|
|
}); err != nil {
|
|
t.Fatalf("launcherconfig.Save() error = %v", err)
|
|
}
|
|
|
|
h := NewHandler(configPath)
|
|
h.SetServerOptions(18800, false, false, nil)
|
|
|
|
cfg := config.DefaultConfig()
|
|
cfg.Gateway.Host = "127.0.0.1"
|
|
cfg.Gateway.Port = 18790
|
|
|
|
req := httptest.NewRequest("GET", "http://launcher.local/api/pico/token", nil)
|
|
req.Host = "192.168.1.9:18800"
|
|
|
|
if got := h.buildWsURL(req, cfg); got != "ws://192.168.1.9:18790/pico/ws" {
|
|
t.Fatalf("buildWsURL() = %q, want %q", got, "ws://192.168.1.9:18790/pico/ws")
|
|
}
|
|
}
|
|
|
|
func TestGatewayProbeHostUsesLoopbackForWildcardBind(t *testing.T) {
|
|
if got := gatewayProbeHost("0.0.0.0"); got != "127.0.0.1" {
|
|
t.Fatalf("gatewayProbeHost() = %q, want %q", got, "127.0.0.1")
|
|
}
|
|
}
|