workbuddy and workbuddy-ai join retiredBuiltins, as Zed did in c0605abc2 and Qoder in 43cc3171d. @magpie-community/opencode-workbuddy-auth serves both, moved or not. Removed (built-in only): - provider: workbuddy_models.go (the model list); in workbuddy.go the sign-in, token renewal, usage/credits reading, request signing and the site's model fetch; the WorkBuddy cases in account.go (Accounts), logins_on.go, logins.go (list/switch/forget), login_usage.go, subscription_usage.go and signin.go; WorkBuddyBaseForTest, now unused. - The built-in tests: workbuddy_test, workbuddy_signin_test, workbuddy_accounts_test, workbuddy_ai_test, workbuddy_body_test, workbuddy_enterprise_test, workbuddy_free_test, workbuddy_names_test, workbuddy_spare_free_test, workbuddy_refused_test (provider), and gateway/workbuddy_refused_test. Kept, and why: - migrate_workbuddy.go (the mover) with what it reads: wbSite, wbCreds, wbOwn/wbAuthPath (the desktop's file, sent as a marker), wbLogins, wbTokens (back drops a renewed pair). - workbuddy_checkin.go: the daily check-in now walks the plugin's accounts only and sends through the plugin's fetch (a.via); wbCallVia, wbNum and the site's api() serve it, and plugin_usage's host. - WBRestricted/WBRestrictedHint: the gateway reads the plugin's 11140 by them. textOnly: applied to the plugin's lists. - draw_workbuddy and search_workbuddy in the gateway: they serve the plugin's provider. The PLUGIN-SERVED notice in workbuddy.go. - The WorkBuddy agent target (internal/agent) is untouched. Tests changed in meaning: - TestFetchNewAccount, TestFetchNewRetriedSoon and TestFetchingNewOnceStarted used WorkBuddy as the built-in signed in; they use Codex now (codexSignedIn, codexListedAt), same assertions. - TestFetchPlanWithoutList uses local models; TestWorkBuddyFetchModels, TestWorkBuddyAIGLMIsTextOnly and TestOwnStoreSignInAgainDropsTheReading (WorkBuddy case) are gone with the code. - Check-in: TestWorkBuddyCheckinSignedIn is gone; the fixture's account is a plugin account signing through via; PluginUnderItsOwnID became TestWorkBuddyCheckinPluginAccounts (plugin accounts listed, a built-in login left out). TestCheckinAccountsListed reads a moved plugin. - TestWorkBuddyMover seeds the desktop's logins.json row: retired, the built-in no longer writes it, and an existing user's row is what moves (red without the row). - Gateway: the WorkBuddy draw and search tests run through the fake plugin (besideFake), without the built-in's header checks; TestWorkBuddySearchesForItsModels folded into TestWorkBuddyPluginSearches (refusal and search-off checks kept); TestLoopEndsWorkBuddysReply is the plugin route only; TestWorkBuddyRestrictedRestsHours lost its built-in translation case. Run: - gofmt -l internal: empty - go vet -tags nogui ./...; GOOS=linux and GOOS=windows the same: clean - go test -tags nogui -count=1 -timeout 45m -run 'WorkBuddy|workbuddy|Checkin|CheckIn|FetchNew|FetchingNew|FetchPlan|Migrat|migrat|Mover|Moved|Retired|Retire|SignIn|Plugin|Draw|Search|Loop|Redact|Restricted|Images|TextOnly|Qoder|BuiltinsSay|AsksOwn|Loopback' ./internal/provider ./internal/gateway ./internal/cli ./internal/gui ./internal/qoder first run: gateway, cli, gui ok; provider red on TestWorkBuddyMover (above); after the fix provider ok (99s). - Not run: whole packages, the full suite, the GUI node suite.
96 lines
3.3 KiB
Go
96 lines
3.3 KiB
Go
package gateway
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// A search query that leaves magpie for a search service that isn't a
|
|
// model's endpoint is masked as the settings say: an agent's search MCP
|
|
// call carries it as the agent's model wrote it, the values put back, and
|
|
// it went to the search API, a Kimi Code plan's or WorkBuddy's search as
|
|
// it was (lc on Discord: "mcp 搜索出去的脱敏了吗?"). The agent gets its own
|
|
// values back in what the search found.
|
|
func TestSearchQueryMasked(t *testing.T) {
|
|
const phone = "13812345678"
|
|
query := "who called from " + phone
|
|
|
|
fresh(t)
|
|
if err := settings.Save(settings.Settings{RedactPersonal: true}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var mu sync.Mutex
|
|
var asked []string
|
|
api := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
q := r.URL.Query().Get("q")
|
|
mu.Lock()
|
|
asked = append(asked, q)
|
|
mu.Unlock()
|
|
w.Header().Set("Content-Type", "application/json")
|
|
b, _ := json.Marshal(map[string]any{"results": []map[string]any{{"title": "Directory", "url": "https://example.com/", "content": "Results for " + q}}})
|
|
w.Write(b)
|
|
}))
|
|
defer api.Close()
|
|
if err := provider.SetSearchAPI(provider.SearchAPI{Vendor: "searxng", URL: api.URL}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
call := `{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"web_search","arguments":{"query":"` + query + `"}}}`
|
|
m := readMCP(t, mcpPost(lanGuard(New().Handler()), "127.0.0.1:50000", call))
|
|
mu.Lock()
|
|
if len(asked) != 1 || strings.Contains(asked[0], phone) || !strings.Contains(asked[0], "{{PHONE_") {
|
|
t.Fatalf("the search API was asked %q", asked)
|
|
}
|
|
mu.Unlock()
|
|
if m.Result.IsError || len(m.Result.Content) != 1 || !strings.Contains(m.Result.Content[0].Text, "Results for "+query) {
|
|
t.Fatalf("the agent got %+v", m)
|
|
}
|
|
|
|
// a Kimi Code plan's search service
|
|
k := newKimiPlan(t)
|
|
kimi := provider.Provider{ID: "kimi", Name: "Kimi Code", Preset: "kimi-code-cn", Key: "sk-kimi", Chat: k.URL + "/coding/v1"}
|
|
if _, _, err := New().kimiSearch(context.Background(), kimi, query); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
k.mu.Lock()
|
|
if len(k.searched) != 1 || strings.Contains(k.searched[0], phone) || !strings.Contains(k.searched[0], "{{PHONE_") {
|
|
t.Fatalf("Kimi was asked %q", k.searched)
|
|
}
|
|
k.mu.Unlock()
|
|
// unless the user set the plan to go unmasked
|
|
kimi.Unredacted = true
|
|
if _, _, err := New().kimiSearch(context.Background(), kimi, query); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
k.mu.Lock()
|
|
if len(k.searched) != 2 || !strings.HasPrefix(k.searched[1], query+" |") {
|
|
t.Fatalf("an unmasked Kimi was asked %q", k.searched)
|
|
}
|
|
k.mu.Unlock()
|
|
|
|
// WorkBuddy's search
|
|
site := &wbSearchSite{}
|
|
p := wbSignedIn(t, "workbuddy", site)
|
|
if err := settings.Save(settings.Settings{RedactPersonal: true}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, _, err := New().ownSearch(searchingOn(context.Background(), p), p, query); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
site.mu.Lock()
|
|
defer site.mu.Unlock()
|
|
if len(site.searched) != 1 {
|
|
t.Fatalf("WorkBuddy searched %v", site.searched)
|
|
}
|
|
if q, _ := site.searched[0]["query"].(string); strings.Contains(q, phone) || !strings.Contains(q, "{{PHONE_") {
|
|
t.Fatalf("WorkBuddy was asked %q", q)
|
|
}
|
|
}
|