Files
HomeAgent/internal/agent/api/quickchat_test.go
root dbbd73b930 refactor: migrate built-in plugins to SDK-only interface
- Six-phase plan complete: webui/cli/healthcheck/pluginmgr/clawhubadapter
  now interact with the kernel exclusively via internal/sdk interfaces;
  all Configure() calls and package-level global injection removed
- buildSDK in internal/plugin/registry.go is the single assembly point
- Add internal/sdk/events.go exporting event types/constants
- Fix ProviderManager cooldown sharing: LuaAdaptedProvider.Name() now
  returns the source name instead of lua_<adapter>, so multiple sources
  sharing an adapter (single script load via shared VM AdapterCache) no
  longer share failure-cooldown state
- Verified: build/vet/tests green, deployed to homeagent.service with
  full plugin capability testing via local OpenAI-compatible mock
2026-08-01 12:17:17 +08:00

55 lines
1.2 KiB
Go

package api
import (
"context"
"os"
"testing"
"time"
luaVM "gitcode.com/JianFeeeee/HomeAgent/internal/lua"
)
func TestQuickChatWithRealKey(t *testing.T) {
apiKey := os.Getenv("DEEPSEEK_API_KEY")
if apiKey == "" {
t.Skip("DEEPSEEK_API_KEY not set — skipping real LLM test")
}
tmpDir := t.TempDir()
vm := luaVM.NewVM(tmpDir + "/adapters")
if err := vm.Start(); err != nil {
t.Fatal(err)
}
defer vm.Stop()
pm := NewProviderManager()
pm.Register("deepseek", NewLuaAdaptedProvider(BaseConfig{
Model: "deepseek-v4-flash",
BaseURL: "https://api.deepseek.com",
APIKey: apiKey,
}, vm, "deepseek", "deepseek"))
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
start := time.Now()
resp, err := pm.QuickChat(ctx, "请回复'OK',不要输出其他内容")
elapsed := time.Since(start)
if err != nil {
t.Fatalf("QuickChat failed: %v", err)
}
if resp.Content == "" {
t.Fatal("empty response")
}
t.Logf("Response: %q", resp.Content)
t.Logf("Time: %v", elapsed.Round(time.Millisecond))
if resp.TokenUsage.Total > 0 {
t.Logf("Tokens: %d (prompt %d + completion %d)",
resp.TokenUsage.Total, resp.TokenUsage.Prompt, resp.TokenUsage.Completion)
}
}