From 6b3879fb9aaa093aee719153e11c3a9ebea26006 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 20:47:33 +0000 Subject: [PATCH] refactor(ax): make webview registration declarative --- pkg/display/display_test.go | 2 +- pkg/mcp/mcp_test.go | 2 +- pkg/webview/service.go | 20 +++++++++++++------- pkg/webview/service_test.go | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/pkg/display/display_test.go b/pkg/display/display_test.go index 9a34e97..84c8b69 100644 --- a/pkg/display/display_test.go +++ b/pkg/display/display_test.go @@ -246,7 +246,7 @@ func newExtendedTestConclaveWithMocks(t *testing.T) *extendedTestConclave { core.WithService(notification.Register(notificationPlatform)), core.WithService(dialog.Register(dialogPlatform)), core.WithService(environment.Register(environmentPlatform)), - core.WithService(webview.Register()), + core.WithService(webview.Register(webview.Options{})), core.WithServiceLock(), ) require.NoError(t, err) diff --git a/pkg/mcp/mcp_test.go b/pkg/mcp/mcp_test.go index 939d1ad..0bf0432 100644 --- a/pkg/mcp/mcp_test.go +++ b/pkg/mcp/mcp_test.go @@ -250,7 +250,7 @@ func TestMCP_Good_ScreenForWindow(t *testing.T) { func TestMCP_Good_WebviewErrors(t *testing.T) { c, err := core.New( - core.WithService(webview.Register()), + core.WithService(webview.Register(webview.Options{})), core.WithServiceLock(), ) require.NoError(t, err) diff --git a/pkg/webview/service.go b/pkg/webview/service.go index 9bfccde..2ddc593 100644 --- a/pkg/webview/service.go +++ b/pkg/webview/service.go @@ -49,7 +49,7 @@ type connector interface { } // Options holds configuration for the webview service. -// Use: svc, err := webview.Register()(core.New()) +// Use: svc, err := webview.Register(webview.Options{})(core.New()) type Options struct { DebugURL string // Chrome debug endpoint (default: "http://localhost:9222") Timeout time.Duration // Operation timeout (default: 30s) @@ -57,7 +57,7 @@ type Options struct { } // Service is a core.Service managing webview interactions via IPC. -// Use: svc, err := webview.Register()(core.New()) +// Use: svc, err := webview.Register(webview.Options{})(core.New()) type Service struct { *core.ServiceRuntime[Options] opts Options @@ -68,16 +68,22 @@ type Service struct { watcherSetup func(conn connector, windowName string) // called after connection creation } -// Register creates a factory closure with the given options. -// Use: core.WithService(webview.Register()) -func Register(opts ...func(*Options)) func(*core.Core) (any, error) { +// Register creates a factory closure with declarative options. +// Use: core.WithService(webview.Register(webview.Options{ConsoleLimit: 500})) +func Register(options Options) func(*core.Core) (any, error) { o := Options{ DebugURL: "http://localhost:9222", Timeout: 30 * time.Second, ConsoleLimit: 1000, } - for _, fn := range opts { - fn(&o) + if options.DebugURL != "" { + o.DebugURL = options.DebugURL + } + if options.Timeout != 0 { + o.Timeout = options.Timeout + } + if options.ConsoleLimit != 0 { + o.ConsoleLimit = options.ConsoleLimit } return func(c *core.Core) (any, error) { svc := &Service{ diff --git a/pkg/webview/service_test.go b/pkg/webview/service_test.go index 1da1d4c..f333833 100644 --- a/pkg/webview/service_test.go +++ b/pkg/webview/service_test.go @@ -111,7 +111,7 @@ func (m *mockConnector) GetConsole() []ConsoleMessage { return m.console } func newTestService(t *testing.T, mock *mockConnector) (*Service, *core.Core) { t.Helper() - factory := Register() + factory := Register(Options{}) c, err := core.New( core.WithService(window.Register(window.NewMockPlatform())), core.WithService(factory),