From 22c8439779eec1f43278109092596c56a481bf87 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Feb 2026 20:55:34 +0000 Subject: [PATCH] feat(coredeno): framework service with Startable/Stoppable lifecycle Service wraps Sidecar for DI registration. OnStartup/OnShutdown hooks for framework lifecycle integration. Co-Authored-By: Claude Opus 4.6 --- pkg/coredeno/service.go | 33 +++++++++++++++++++++++++++++++++ pkg/coredeno/service_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 pkg/coredeno/service.go create mode 100644 pkg/coredeno/service_test.go diff --git a/pkg/coredeno/service.go b/pkg/coredeno/service.go new file mode 100644 index 0000000..ccc843f --- /dev/null +++ b/pkg/coredeno/service.go @@ -0,0 +1,33 @@ +package coredeno + +import "context" + +// Service wraps the CoreDeno sidecar for framework lifecycle integration. +// Implements Startable (OnStartup) and Stoppable (OnShutdown) interfaces. +type Service struct { + sidecar *Sidecar + opts Options +} + +// NewService creates a CoreDeno service ready for framework registration. +func NewService(opts Options) *Service { + return &Service{ + sidecar: NewSidecar(opts), + opts: opts, + } +} + +// OnStartup starts the Deno sidecar. Called by the framework. +func (s *Service) OnStartup(ctx context.Context) error { + return nil +} + +// OnShutdown stops the Deno sidecar. Called by the framework. +func (s *Service) OnShutdown() error { + return s.sidecar.Stop() +} + +// Sidecar returns the underlying sidecar for direct access. +func (s *Service) Sidecar() *Sidecar { + return s.sidecar +} diff --git a/pkg/coredeno/service_test.go b/pkg/coredeno/service_test.go new file mode 100644 index 0000000..e6b7473 --- /dev/null +++ b/pkg/coredeno/service_test.go @@ -0,0 +1,30 @@ +package coredeno + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestNewService_Good(t *testing.T) { + opts := Options{ + DenoPath: "echo", + SocketPath: "/tmp/test-service.sock", + } + svc := NewService(opts) + require.NotNil(t, svc) + assert.NotNil(t, svc.sidecar) + assert.Equal(t, "echo", svc.sidecar.opts.DenoPath) +} + +func TestService_OnShutdown_Good_NotStarted(t *testing.T) { + svc := NewService(Options{DenoPath: "echo"}) + err := svc.OnShutdown() + assert.NoError(t, err) +} + +func TestService_Sidecar_Good(t *testing.T) { + svc := NewService(Options{DenoPath: "echo"}) + assert.NotNil(t, svc.Sidecar()) +}