From bc8ec89ca411e02e06a7f9eb838c0afa6e585642 Mon Sep 17 00:00:00 2001 From: Michael Brooks Date: Mon, 23 Nov 2026 09:41:05 -0700 Subject: [PATCH 1/3] test: add unit tests for WatchManifest in internal/pkg/platform --- internal/pkg/platform/localserver_test.go | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/internal/pkg/platform/localserver_test.go b/internal/pkg/platform/localserver_test.go index a2e5304e..456f2266 100644 --- a/internal/pkg/platform/localserver_test.go +++ b/internal/pkg/platform/localserver_test.go @@ -28,6 +28,7 @@ import ( "github.com/gorilla/websocket" "github.com/radovskyb/watcher" "github.com/slackapi/slack-cli/internal/api" + "github.com/slackapi/slack-cli/internal/config" "github.com/slackapi/slack-cli/internal/hooks" "github.com/slackapi/slack-cli/internal/shared" "github.com/slackapi/slack-cli/internal/shared/types" @@ -508,6 +509,51 @@ func Test_LocalServer_watchAppEvents(t *testing.T) { } } +func Test_LocalServer_WatchManifest(t *testing.T) { + for name, tc := range map[string]struct { + manifestSource config.ManifestSource + manifestErr error + expectedErr error + expectedOutput []string + }{ + "returns the error when the manifest source cannot be read": { + manifestSource: config.ManifestSourceLocal, + manifestErr: slackerror.New(slackerror.ErrInvalidManifestSource), + expectedErr: slackerror.New(slackerror.ErrInvalidManifestSource), + }, + "waits for the context to end when manifest watching is not enabled": { + manifestSource: config.ManifestSourceLocal, + expectedOutput: []string{"Manifest watching is not enabled"}, + }, + "notes a remote manifest source before checking the watch config": { + manifestSource: config.ManifestSourceRemote, + expectedOutput: []string{"Manifest source is remote", "Manifest watching is not enabled"}, + }, + } { + t.Run(name, func(t *testing.T) { + ctx, cancel := context.WithCancel(slackcontext.MockContext(t.Context())) + cancel() + clientsMock := shared.NewClientsMock() + clientsMock.Config.DebugEnabled = true + projectConfigMock := config.NewProjectConfigMock() + projectConfigMock.On("GetManifestSource", mock.Anything).Return(tc.manifestSource, tc.manifestErr) + clientsMock.Config.ProjectConfig = projectConfigMock + clientsMock.AddDefaultMocks() + clients := shared.NewClientFactory(clientsMock.MockClientFactory()) + server := LocalServer{clients: clients} + err := server.WatchManifest(ctx, types.SlackAuth{}, types.App{}) + if tc.expectedErr != nil { + assert.Equal(t, tc.expectedErr, err) + return + } + require.NoError(t, err) + for _, expected := range tc.expectedOutput { + assert.Contains(t, clientsMock.GetStdoutOutput(), expected) + } + }) + } +} + func Test_LocalServer_watchManifestEvents(t *testing.T) { for name, tc := range map[string]struct { cancel bool From c7a650c0e501257a3563608180c6b86728ff67ed Mon Sep 17 00:00:00 2001 From: Michael Brooks Date: Mon, 23 Nov 2026 11:36:01 -0700 Subject: [PATCH 2/3] test: check WatchManifest blocks until the context ends --- internal/pkg/platform/localserver_test.go | 28 +++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/internal/pkg/platform/localserver_test.go b/internal/pkg/platform/localserver_test.go index 456f2266..ae5783de 100644 --- a/internal/pkg/platform/localserver_test.go +++ b/internal/pkg/platform/localserver_test.go @@ -24,6 +24,7 @@ import ( "strings" "sync" "testing" + "time" "github.com/gorilla/websocket" "github.com/radovskyb/watcher" @@ -532,7 +533,7 @@ func Test_LocalServer_WatchManifest(t *testing.T) { } { t.Run(name, func(t *testing.T) { ctx, cancel := context.WithCancel(slackcontext.MockContext(t.Context())) - cancel() + defer cancel() clientsMock := shared.NewClientsMock() clientsMock.Config.DebugEnabled = true projectConfigMock := config.NewProjectConfigMock() @@ -541,12 +542,31 @@ func Test_LocalServer_WatchManifest(t *testing.T) { clientsMock.AddDefaultMocks() clients := shared.NewClientFactory(clientsMock.MockClientFactory()) server := LocalServer{clients: clients} - err := server.WatchManifest(ctx, types.SlackAuth{}, types.App{}) + errChan := make(chan error, 1) + go func() { + errChan <- server.WatchManifest(ctx, types.SlackAuth{}, types.App{}) + }() if tc.expectedErr != nil { - assert.Equal(t, tc.expectedErr, err) + select { + case err := <-errChan: + assert.Equal(t, tc.expectedErr, err) + case <-time.After(time.Second): + require.FailNow(t, "WatchManifest did not return the error") + } return } - require.NoError(t, err) + select { + case err := <-errChan: + require.FailNow(t, "WatchManifest returned before the context ended", "err: %v", err) + case <-time.After(50 * time.Millisecond): + } + cancel() + select { + case err := <-errChan: + require.NoError(t, err) + case <-time.After(time.Second): + require.FailNow(t, "WatchManifest did not return after the context ended") + } for _, expected := range tc.expectedOutput { assert.Contains(t, clientsMock.GetStdoutOutput(), expected) } From 731c50650df3d4550dfd64a02b2000d1e6a332ee Mon Sep 17 00:00:00 2001 From: Michael Brooks Date: Mon, 23 Nov 2026 15:31:50 -0700 Subject: [PATCH 3/3] test: set watch options per case now that a missing watch config shows the hint --- internal/pkg/platform/localserver_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/pkg/platform/localserver_test.go b/internal/pkg/platform/localserver_test.go index ae5783de..8cb8536d 100644 --- a/internal/pkg/platform/localserver_test.go +++ b/internal/pkg/platform/localserver_test.go @@ -514,20 +514,28 @@ func Test_LocalServer_WatchManifest(t *testing.T) { for name, tc := range map[string]struct { manifestSource config.ManifestSource manifestErr error + watch *hooks.WatchOpts expectedErr error expectedOutput []string }{ + "asks for watch configuration when the hooks omit it": { + manifestSource: config.ManifestSourceLocal, + expectedOutput: []string{"provide watch configuration"}, + }, "returns the error when the manifest source cannot be read": { manifestSource: config.ManifestSourceLocal, + watch: &hooks.WatchOpts{}, manifestErr: slackerror.New(slackerror.ErrInvalidManifestSource), expectedErr: slackerror.New(slackerror.ErrInvalidManifestSource), }, "waits for the context to end when manifest watching is not enabled": { manifestSource: config.ManifestSourceLocal, + watch: &hooks.WatchOpts{}, expectedOutput: []string{"Manifest watching is not enabled"}, }, "notes a remote manifest source before checking the watch config": { manifestSource: config.ManifestSourceRemote, + watch: &hooks.WatchOpts{}, expectedOutput: []string{"Manifest source is remote", "Manifest watching is not enabled"}, }, } { @@ -542,6 +550,7 @@ func Test_LocalServer_WatchManifest(t *testing.T) { clientsMock.AddDefaultMocks() clients := shared.NewClientFactory(clientsMock.MockClientFactory()) server := LocalServer{clients: clients} + server.cliConfig.Config.Watch = tc.watch errChan := make(chan error, 1) go func() { errChan <- server.WatchManifest(ctx, types.SlackAuth{}, types.App{})