Skip to content

test: add unit tests for WatchManifest in internal/pkg/platform - #831

Merged
mwbrooks merged 6 commits into
mainfrom
mwbrooks-test-watch-manifest
Nov 23, 2026
Merged

mwbrooks merged 6 commits into
mainfrom
mwbrooks-test-watch-manifest

Conversation

@mwbrooks

Copy link
Copy Markdown
Member

Changelog

N/A - adds tests only, with no user-facing changes.

Summary

This pull request adds unit tests for WatchManifest in internal/pkg/platform/localserver.go, which had no test coverage. It is one in a series of small coverage PRs.

  • Adds Test_LocalServer_WatchManifest to internal/pkg/platform/localserver_test.go with cases for a manifest source read error, manifest watching turned off, and a remote manifest source
  • Raises internal/pkg/platform coverage from 56.7% to 58.5%

Testing

  1. Run go test ./internal/pkg/platform/... -run Test_LocalServer_WatchManifest -v and confirm the cases pass

Requirements

@mwbrooks
mwbrooks requested a review from a team as a code owner November 23, 2026 17:21
@mwbrooks mwbrooks added this to the Next Release milestone Nov 23, 2026
@mwbrooks mwbrooks added code health M-T: Test improvements and anything that improves code health semver:patch Use on pull requests to describe the release version increment labels Nov 23, 2026
@mwbrooks mwbrooks self-assigned this Nov 23, 2026
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.60%. Comparing base (d3904d1) to head (731c506).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #831      +/-   ##
==========================================
+ Coverage   80.54%   80.60%   +0.06%     
==========================================
  Files         246      246              
  Lines       18899    18899              
==========================================
+ Hits        15222    15234      +12     
+ Misses       3677     3665      -12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 Thanks @mwbrooks! Pinning the manifest source error and the remote note covers the two branches most likely to regress.
One blocking comment on the "waits for the context" case, the other is optional 🙏

} {
t.Run(name, func(t *testing.T) {
ctx, cancel := context.WithCancel(slackcontext.MockContext(t.Context()))
cancel()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 issue (blocking): Since the context is canceled before the call, this case still passes with the <-ctx.Done() wait removed (I tried it). That wait matters: slack run exits on the first value from errChan. Could we start WatchManifest in a goroutine on a live context, check it hasn't returned after a short wait, then cancel and expect nil?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit c7a650c, thanks for trying it without the wait! 🙇 The test now starts WatchManifest on a live context, checks it hasn't returned after 50ms, then cancels and expects nil. Removing the <-ctx.Done() wait now fails both cases.

}
}

func Test_LocalServer_WatchManifest(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 suggestion (non-blocking): The enabled path (paths, filter regex, w.Start) is still untested, leaving WatchManifest at 46% coverage. A test there would hang today since nothing closes the watcher when the context ends, so closing w on ctx.Done() could be a nice follow-up that makes it testable.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, thanks! I'll close the watcher on ctx.Done() in a follow-up PR, with a test for the enabled path, so this one stays test-only.

@WilliamBergamin WilliamBergamin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 @mwbrooks thanks! Running WatchManifest on a live context and checking it stays blocked until cancel now pins the wait that keeps slack run going. Nothing else from me 🚀

}
select {
case err := <-errChan:
require.FailNow(t, "WatchManifest returned before the context ended", "err: %v", err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 praise: Asserting no return before cancel() makes this fail if the <-ctx.Done() wait is dropped (I tried it), which is exactly the regression that would end slack run early.

@mwbrooks

Copy link
Copy Markdown
Member Author

Heads up @WilliamBergamin: #838 made a missing watch config show the hint and stop, so this PR's cases now set Watch themselves. Commit 731c506 does that and adds a case for the hint. No other changes.

@mwbrooks

Copy link
Copy Markdown
Member Author

Thanks @WilliamBergamin for the thorough review and for trying it without the wait! 🙇

@mwbrooks
mwbrooks merged commit 6dd6c5f into main Nov 23, 2026
14 checks passed
@mwbrooks
mwbrooks deleted the mwbrooks-test-watch-manifest branch November 23, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code health M-T: Test improvements and anything that improves code health semver:patch Use on pull requests to describe the release version increment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants