Files
kandev/apps/backend/internal/plugins/runtime/testdata/fixtureplugin/main.go
T
Kandev Agent c53f699714 feat: add plugin system with grpc runtime and native ui plugins
- go plugin backends ship as release tarballs (per-platform binaries, checksums) that
  kandev installs from url/upload or filesystem sideload+sync, then spawns and
  supervises via hashicorp/go-plugin (unix socket / loopback tcp+automtls)
- strict typed grpc contract (kandev.plugin.v1): DeliverEvent/InvokeTool/HandleWebhook
  plus a capability-gated host service (state, secrets, emit); author sdk in
  pkg/pluginsdk; packaging cli in cmd/plugin-pack
- native frontend bundles: window.registerKandevPlugin + registry/host loader with
  dynamic routes, nav items, slots and ws handlers; plugins settings page with
  install dialog, sync button and enable/disable/uninstall
- gated behind the plugins feature flag (prod off, dev/e2e on); covered by unit and
  integration tests plus playwright e2e against a real packaged fixture plugin

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-16 17:55:45 +01:00

54 lines
1.8 KiB
Go

// Command fixtureplugin is a minimal kandev plugin backend built from
// pkg/pluginsdk, used only by internal/plugins/runtime's tests to exercise
// a real go-plugin subprocess spawn/handshake/DeliverEvent/InvokeTool/
// crash-restart cycle end to end. It is built at test time (see
// internal/plugins/runtime/manager_test.go's TestMain) into a temp binary;
// it is never shipped.
package main
import (
"context"
"os"
"github.com/kandev/kandev/pkg/pluginsdk"
)
// fixturePlugin embeds UnimplementedPlugin (for Host injection via
// SetHost/Host) and overrides every RPC with test-observable behavior:
// - OnEvent records the last delivered event into Host state, so an
// out-of-process test can observe delivery by reading that state back
// through its own fake Host implementation.
// - InvokeTool echoes its input back as output, except tool name "crash"
// which exits the process immediately (to exercise crash detection +
// restart), and "ping-host" which round-trips a GetState call.
// - HandleWebhook echoes the request back as a response body.
type fixturePlugin struct {
pluginsdk.UnimplementedPlugin
}
func (p *fixturePlugin) OnEvent(ctx context.Context, e *pluginsdk.Event) error {
host := p.Host()
if host == nil {
return nil
}
return host.SetState(ctx, "instance", "", "last_event", map[string]any{
"event_type": e.EventType,
"event_id": e.EventID,
})
}
func (p *fixturePlugin) InvokeTool(_ context.Context, req *pluginsdk.ToolRequest) (*pluginsdk.ToolResponse, error) {
if req.ToolName == "crash" {
os.Exit(1)
}
return &pluginsdk.ToolResponse{Output: req.Input}, nil
}
func (p *fixturePlugin) HandleWebhook(_ context.Context, req *pluginsdk.WebhookRequest) (*pluginsdk.WebhookResponse, error) {
return &pluginsdk.WebhookResponse{Status: 200, Body: req.Body}, nil
}
func main() {
pluginsdk.Serve(&fixturePlugin{})
}