Skip to content

test(missions): unit tests for missions pure functions [Part 1 of #17600]#18373

Open
AdeshDeshmukh wants to merge 1 commit into
kubestellar:mainfrom
AdeshDeshmukh:test/missions-pure-functions
Open

test(missions): unit tests for missions pure functions [Part 1 of #17600]#18373
AdeshDeshmukh wants to merge 1 commit into
kubestellar:mainfrom
AdeshDeshmukh:test/missions-pure-functions

Conversation

@AdeshDeshmukh

Copy link
Copy Markdown
Contributor

Picking up issue #17600 — the pkg/api/handlers/ directory has had zero test coverage since the codebase was first built. The child issues (#17605#17609) were auto-closed by a bot without any actual tests written, so the gap is completely untouched.

This is the first of several focused PRs to fix that. I am starting with the pure functions in the missions package because they have no external dependencies (no HTTP, no DB, no Kubernetes) — which means no mocking infrastructure needed, and tests that run in under a millisecond.

What is in this PR

Three new test files following the existing pattern in types_test.go:

  • helpers_test.go — covers isDemoMode() and isSafeImageKey()
  • share_test.go — covers validateSlackWebhookURL(), resolveAllowedShareRepos(), isRepoAllowedForShare(), isRepoAllowedForShareWithList()
  • embedded_test.go — covers embeddedHiddenMissionEntry()

All tests are table-driven with t.Run() subtests, matching the project's existing convention.

Coverage delta

Function File Before After
isDemoMode helpers.go 0% 100%
isSafeImageKey helpers.go 100% 100% (was already tested)
embeddedHiddenMissionEntry embedded.go 0% 100%
resolveAllowedShareRepos share.go 0% 100%
isRepoAllowedForShare share.go 0% 100%
isRepoAllowedForShareWithList share.go 0% 100%
validateSlackWebhookURL share.go 0% 93.8%

Why these test cases specifically

The allowlist logic (isRepoAllowedForShare) and webhook validation (validateSlackWebhookURL) are security-sensitive. The tests deliberately include adversarial inputs — SSRF vectors, subdomain confusion attacks, path traversal attempts, and protocol injection — not just the happy path. If this logic regresses, the test suite will catch it before it ships.

Test output

58 passed in 1 packages

What comes next

PR 2 will cover feedback/github_helpers.go and feedback/github_prs.go using a mocked GitHub client interface.

Addresses part of #17600

Copilot AI review requested due to automatic review settings June 13, 2026 16:53
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign mikespreitzer for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubestellar-prow kubestellar-prow Bot added the dco-signoff: no Indicates the PR's author has not signed the DCO. label Jun 13, 2026
@netlify

netlify Bot commented Jun 13, 2026

Copy link
Copy Markdown

Deploy Preview for kubestellarconsole canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 53eee87
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/6a2d8c954e4ec400087b3be2

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 13, 2026

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds new unit tests for the missions handlers package, focusing on input validation and internal helper behavior.

Changes:

  • Add tests for Slack webhook URL validation, share repo allowlist resolution, and repo allow/deny checks.
  • Add tests for isDemoMode header parsing behavior.
  • Add tests for embedded mission entry “hidden file” filtering.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
pkg/api/handlers/missions/share_test.go Adds coverage for Slack webhook URL validation and share repo allowlist logic (env-driven + matching).
pkg/api/handlers/missions/helpers_test.go Adds tests for demo-mode detection via X-Demo-Mode header.
pkg/api/handlers/missions/embedded_test.go Adds tests for filtering hidden embedded mission entries.

Comment on lines +31 to +37
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := validateSlackWebhookURL(tt.url)
assert.Error(t, err)
assert.Contains(t, err.Error(), tt.msg)
})
}
Comment thread pkg/api/handlers/missions/share_test.go Outdated
Comment on lines +58 to +61
os.Setenv(envVar, "org1/repo1,org2/repo2")

repos := resolveAllowedShareRepos()
assert.Len(t, repos, 3)
Comment thread pkg/api/handlers/missions/share_test.go Outdated
t.Cleanup(func() {
os.Unsetenv(envVar)
})
os.Setenv(envVar, "org1/repo1,org2/repo2")
Comment thread pkg/api/handlers/missions/share_test.go Outdated
t.Cleanup(func() {
os.Unsetenv(envVar)
})
os.Setenv(envVar, " org1/repo1 , org2/repo2 ")
Comment thread pkg/api/handlers/missions/share_test.go Outdated
t.Cleanup(func() {
os.Unsetenv(envVar)
})
os.Setenv(envVar, "org1/repo1,,org2/repo2")
Comment on lines +42 to +45
resp, err := app.Test(req, 5000)
require.NoError(t, err)
body, _ := io.ReadAll(resp.Body)
assert.Equal(t, fmt.Sprintf("%t", tt.want), string(body))
Comment on lines +26 to +31
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := embeddedHiddenMissionEntry(tt.entry)
assert.Equal(t, tt.hidden, result)
})
}
@AdeshDeshmukh AdeshDeshmukh force-pushed the test/missions-pure-functions branch from 1f78b3d to f7cc6b4 Compare June 13, 2026 16:54
@kubestellar-prow kubestellar-prow Bot added dco-signoff: yes Indicates the PR's author has signed the DCO. and removed dco-signoff: no Indicates the PR's author has not signed the DCO. labels Jun 13, 2026
Signed-off-by: AdeshDeshmukh <adeshkd123@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants