zelong77 asked for two things once Devin 0.1.30's cache keep-alive
worked: its pings were invisible in magpie, and the interval and ping
count could only be edited in plugins.json. The owner decided pings are
shown as counted usage and the two numbers are edited in the GUI.
- host.js gives plugins input.magpie.usage(provider, call) and
input.magpie.account(provider). usage validates the call (kind
[a-z0-9_-]{1,40}, a model id, whole-number tokens from 0, status at
most 999, error clipped to 500) and sends an unasked "usage" event;
host.go hands it to plugin.OnUsage in the background.
- internal/usage/plugin_calls.go writes each one as a row of agent
magpie on the plugin's provider (provider.PluginID) and account
(provider.PluginAccountUser), with its kind. It is counted, priced
and in every total, not a probe. Kind cache_keepalive is in the
purpose catalog as "Cache keep-alive" (five languages), so the
request log names and filters it. The ping itself still goes straight
to Devin, never through the gateway, which would break the cache.
- /api/plugins reads every plugin's package options example, not only a
middleware's or request hook's, and the Installed row offers the same
Options JSON editor for a provider or agent plugin that suggests or
has options (not while it is off). Clear's confirm no longer calls
them a middleware's options.
- The Devin mover's min is 0.1.31, which reports each ping and gives
its two settings' defaults (285 s, 6) to the editor. npm has 0.1.31
(published 10:03Z); the plugins publish run is red only for
think-tags' known E404 (plugins#180).
- docs: provider-plugins.md (the API, the options editor),
gateway-sessions.md (the counted row beside probes).
Run at this tree (rebased on origin/main 85e37162e):
- mote (mote-run): go test -count=1 -timeout 45m ./internal/plugin
./internal/usage ./internal/gui ./internal/provider: plugin, usage,
provider ok; gui red only in TestMainWindowCorners/macOS_26_SDK, the
macOS 27 red already filed as #3949 (not this change's code).
- mote: GOOS=linux and GOOS=windows go vet of plugin, usage, provider ok;
gofmt -l clean.
- mote: plugin-provider-options.test.cjs (new, 5 languages, 980/420px,
Chromium + WebKit), plugin-gateway.test.cjs and i18n-keys.test.cjs:
28 of 28 pass.
- The whole GUI suite (make test-ui) on WSL magpie-desktop (mote was at
load ~100 with other sessions' suites, #4125), at the 8f804396f base:
cut off after 498 test entries, when the session's background jobs
were killed; 495 ok, 3 red, none on a page this change touches. Run
again alone at origin/main 85e37162e, the same files are red there
too: account-eye webkit (#4244), agent-expand-steady webkit 980px
(#2935), add-button zh's 3000ms waitForFunction (filed #4792). The
rest of the suite was not run.
Broken by hand (each red, then put back):
- host.go dropping the "usage" event: TestPluginReportsOwnUsage fails.
- plugins.go reading optionsExample for middleware/hooks only:
TestProviderPluginOptionsExample fails.
- purpose.go without the Cache keep-alive kind:
TestPluginKeepaliveIsCounted fails (purpose {}).
- plugins.js without ownOpts: plugin-provider-options.test.cjs times
out waiting for the Options button in every language.
Not tried: a real Devin account's keep-alive ping reported into a real
magpie (needs a live Devin conversation idle for 285 s); a plugin can
report a row for any provider id, as magpie.load can.
74 lines
2.6 KiB
Go
74 lines
2.6 KiB
Go
package gui
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/plugin"
|
|
)
|
|
|
|
func TestGatewayPluginOptionsAndKind(t *testing.T) {
|
|
t.Setenv("HOME", t.TempDir())
|
|
t.Setenv("USERPROFILE", t.TempDir())
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
t.Setenv("MAGPIE_PLUGIN_MARKET", "off")
|
|
t.Cleanup(plugin.Settle)
|
|
dir := t.TempDir()
|
|
if err := os.WriteFile(filepath.Join(dir, "package.json"), []byte(`{"name":"gateway-fixture","magpie":{"hooks":"./hooks.js","options":{"serverUrl":"http://127.0.0.1:8000"}}}`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(dir, "hooks.js"), []byte(`export function onRequest() {}`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := plugin.Add(t.Context(), dir); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
state := pluginsState(t.Context(), nil)
|
|
if len(state.Plugins) != 1 {
|
|
t.Fatalf("plugins: %+v", state)
|
|
}
|
|
p := state.Plugins[0]
|
|
if !p.IsGateway || !p.GatewayOnly || p.OptionsExample["serverUrl"] != "http://127.0.0.1:8000" || p.Gateway == nil || p.Gateway.LastOutcome != "idle" {
|
|
t.Fatalf("gateway missing from Settings: %+v", p)
|
|
}
|
|
if err := plugin.SetOff(dir, true); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p = pluginsState(t.Context(), nil).Plugins[0]
|
|
if !p.IsGateway || p.Gateway != nil {
|
|
t.Fatalf("disabled gateway: %+v", p)
|
|
}
|
|
}
|
|
|
|
// A provider plugin's package options are its row's too (plugins#592:
|
|
// Devin's cacheKeepaliveInterval and cacheKeepaliveMaxPings), so the
|
|
// Installed tab can offer the options editor without plugins.json.
|
|
func TestProviderPluginOptionsExample(t *testing.T) {
|
|
t.Setenv("HOME", t.TempDir())
|
|
t.Setenv("USERPROFILE", t.TempDir())
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
t.Setenv("MAGPIE_PLUGIN_MARKET", "off")
|
|
t.Cleanup(plugin.Settle)
|
|
dir := t.TempDir()
|
|
if err := os.WriteFile(filepath.Join(dir, "package.json"), []byte(`{"name":"provider-fixture","main":"index.js","magpie":{"options":{"cacheKeepaliveInterval":285,"cacheKeepaliveMaxPings":6}}}`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(filepath.Join(dir, "index.js"), []byte(`export default async () => ({ auth: { provider: "fixture", methods: [] } })`), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := plugin.Add(t.Context(), dir); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
state := pluginsState(t.Context(), nil)
|
|
if len(state.Plugins) != 1 {
|
|
t.Fatalf("plugins: %+v", state)
|
|
}
|
|
p := state.Plugins[0]
|
|
if p.IsMiddleware || p.IsGateway || p.OptionsExample["cacheKeepaliveInterval"] != float64(285) || p.OptionsExample["cacheKeepaliveMaxPings"] != float64(6) {
|
|
t.Fatalf("provider plugin's options example: %+v", p)
|
|
}
|
|
}
|