refactor(ax): make webview registration declarative
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

This commit is contained in:
Virgil 2026-04-02 20:47:33 +00:00
parent d9491380f8
commit 6b3879fb9a
4 changed files with 16 additions and 10 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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{

View file

@ -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),