test: batch 16 coverage — preflightCheck, useClusterContext, sampleData#11192
test: batch 16 coverage — preflightCheck, useClusterContext, sampleData#11192clubanderson merged 2 commits intomainfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
✅ Deploy Preview for kubestellarconsole ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
👋 Hey @clubanderson — thanks for opening this PR!
This is an automated message. |
There was a problem hiding this comment.
Pull request overview
Adds targeted Vitest coverage suites to exercise previously uncovered branches in preflight tooling, cluster context aggregation, and AI sample-data heuristics—helping keep the web app’s high coverage bar and improving regression detection around edge-case handling.
Changes:
- Adds additional branch/edge-case tests for
preflightCheck.ts(classification, remediation, tool checks, catch-branch normalization). - Adds additional tests for
useClusterContextaggregation behaviors (resources/issues/labels and null guards). - Adds additional tests for
sampleData.tsheuristics anddetectFieldFormatedge cases.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| web/src/lib/missions/tests/preflightCheck-coverage.test.ts | New coverage-focused tests for preflight error classification, tool checks, and remediation actions |
| web/src/hooks/tests/useClusterContext-coverage.test.ts | New coverage-focused tests for cluster context aggregation logic and null/edge handling |
| web/src/lib/ai/tests/sampleData-coverage.test.ts | New coverage-focused tests for sample data generation heuristics and field-format detection |
| it('handles non-Error thrown value (string)', async () => { | ||
| const exec = vi.fn().mockRejectedValue('raw string error') | ||
|
|
||
| const result = await runPreflightCheck(exec) | ||
| expect(result.ok).toBe(false) | ||
| }) |
There was a problem hiding this comment.
This test currently only asserts ok is false; it doesn't verify the catch-branch classification behavior for non-Error thrown values. Add an assertion on result.error.code and/or result.error.message to ensure the hook keeps returning a stable, useful PreflightError for string throws.
| it('handles null thrown value', async () => { | ||
| const exec = vi.fn().mockRejectedValue(null) | ||
|
|
||
| const result = await runPreflightCheck(exec) | ||
| expect(result.ok).toBe(false) | ||
| }) |
There was a problem hiding this comment.
Same issue here: asserting only ok is false doesn't validate the specific null-throw handling (the implementation normalizes null to "Unknown execution error"). Add an assertion that confirms the normalized message is used and that the returned PreflightError shape is consistent.
| describe('useClusterContext — additional coverage', () => { | ||
| it('extracts base name from operators with -operator suffix', () => { | ||
| vi.mocked(useClusters).mockReturnValue({ | ||
| deduplicatedClusters: [ | ||
| { name: 'cluster-1', healthy: true, isCurrent: true }, |
There was a problem hiding this comment.
The mocked hook return values are mutated in many tests but there's no beforeEach/afterEach resetting them, so tests can inadvertently depend on state from earlier cases (e.g., useHelmReleases/useOperators return values persisting). Add a beforeEach that restores default mock implementations/return values for all mocked hooks to keep each test independent and avoid order-dependent failures.
| it('returns explicit tools even if empty array', () => { | ||
| // Empty explicit array is falsy length, so falls through | ||
| const result = resolveRequiredTools('deploy', []) | ||
| // Empty array has length 0, so it falls through to type-based lookup | ||
| expect(result).toContain('helm') | ||
| }) |
There was a problem hiding this comment.
The test name is misleading: resolveRequiredTools() only returns explicitTools when the array is non-empty. With an empty array it intentionally falls back to missionType/default tool resolution, so the test should be renamed to reflect that behavior (e.g., "falls back when explicit tools is an empty array").
| it('includes context in MISSING_CREDENTIALS code snippet when provided', () => { | ||
| const error: PreflightError = { | ||
| code: 'MISSING_CREDENTIALS', | ||
| message: 'No kubeconfig', | ||
| } | ||
| const actions = getRemediationActions(error, 'prod-ctx') | ||
| const copyActions = actions.filter(a => a.actionType === 'copy') | ||
| // The second copy action should include cloud provider commands | ||
| expect(copyActions.some(a => a.codeSnippet?.includes('GKE'))).toBe(true) | ||
| }) |
There was a problem hiding this comment.
The test name suggests the context value is included in the MISSING_CREDENTIALS snippet, but getRemediationActions() only switches between a generic snippet and provider-login examples based on whether context is provided (it doesn't interpolate the context). Rename the test (and/or adjust the assertion) so the intent matches the actual behavior being verified.
| it('handles cross-realm error with undefined message', async () => { | ||
| const crossRealmError = { message: undefined } | ||
| const exec = vi.fn().mockRejectedValue(crossRealmError) | ||
|
|
||
| const result = await runPreflightCheck(exec) | ||
| expect(result.ok).toBe(false) | ||
| // Falls through to String(err) path | ||
| }) |
There was a problem hiding this comment.
This test only asserts ok is false, which makes it very hard to detect regressions (any failure path satisfies the assertion). Since the code is specifically handling the message: undefined cross-realm case, assert something about the resulting error (e.g., that an UNKNOWN_EXECUTION_FAILURE is returned and that the message is derived via String(err) rather than the literal "undefined").
…xt, sampleData Add 116 tests across 3 files to push line coverage past 90.50%: - preflightCheck-coverage (67 tests): classifyKubectlError, resolveRequiredTools, runToolPreflightCheck - useClusterContext-coverage (17 tests): operator name stripping, helm chart parsing, pod issues - sampleData-coverage (32 tests): field heuristics, detectFieldFormat edge cases Signed-off-by: Andrew Anderson <[email protected]>
0e36ebf to
ea4a27c
Compare
…setShareRegistries Signed-off-by: Andrew Anderson <[email protected]>
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
✅ Post-Merge Verification: passedCommit: |
|
Post-merge build verification passed ✅ Both Go and frontend builds compiled successfully against merge commit |
…ta (#11192) * test: add batch 16 coverage tests for preflightCheck, useClusterContext, sampleData Add 116 tests across 3 files to push line coverage past 90.50%: - preflightCheck-coverage (67 tests): classifyKubectlError, resolveRequiredTools, runToolPreflightCheck - useClusterContext-coverage (17 tests): operator name stripping, helm chart parsing, pod issues - sampleData-coverage (32 tests): field heuristics, detectFieldFormat edge cases Signed-off-by: Andrew Anderson <[email protected]> * fix: change savedCards/sharedDashboards to let for reassignment in resetShareRegistries Signed-off-by: Andrew Anderson <[email protected]> --------- Signed-off-by: Andrew Anderson <[email protected]>
* 🐛 Fix incorrect assertion in agentFetch 401 retry test Co-authored-by: Copilot <[email protected]> Signed-off-by: Copilot <[email protected]> * test: batch 16 coverage — preflightCheck, useClusterContext, sampleData (#11192) * test: add batch 16 coverage tests for preflightCheck, useClusterContext, sampleData Add 116 tests across 3 files to push line coverage past 90.50%: - preflightCheck-coverage (67 tests): classifyKubectlError, resolveRequiredTools, runToolPreflightCheck - useClusterContext-coverage (17 tests): operator name stripping, helm chart parsing, pod issues - sampleData-coverage (32 tests): field heuristics, detectFieldFormat edge cases Signed-off-by: Andrew Anderson <[email protected]> * fix: change savedCards/sharedDashboards to let for reassignment in resetShareRegistries Signed-off-by: Andrew Anderson <[email protected]> --------- Signed-off-by: Andrew Anderson <[email protected]> * 🐛 Fix medium Copilot comments: GHE commit URL, stale cluster selection, type signatures - feedback_config.go: add resolveGitHubUIBase() for GHE-aware web link construction - feedback_github.go: use resolveGitHubUIBase() for SHA commit link (#11177 follow-up) - ComplianceReports.tsx: clear selectedCluster when it's filtered out by reachability (was only auto-set when empty, leaving stale selection pointing to hidden cluster) - ComplianceReports.tsx + ControlPlaneHealth.tsx: fix misleading 'only reachable' comments — predicate c.reachable !== false also includes undefined (not-yet-checked) - dedup.ts: widen shareMetricsBetweenSameServerClusters signature to ClusterInfo[] | null | undefined to match the runtime guard already in the body (#11184 medium) - shared.ts: fix dedup priority comment — reachability is criterion #1, not #2 Co-authored-by: Copilot <[email protected]> Signed-off-by: Copilot <[email protected]> --------- Signed-off-by: Copilot <[email protected]> Signed-off-by: Andrew Anderson <[email protected]> Co-authored-by: Copilot <[email protected]>
|
🤖 Reviewer: Addressed HIGH + MEDIUM Copilot comments (commit
|
…ta (kubestellar#11192) * test: add batch 16 coverage tests for preflightCheck, useClusterContext, sampleData Add 116 tests across 3 files to push line coverage past 90.50%: - preflightCheck-coverage (67 tests): classifyKubectlError, resolveRequiredTools, runToolPreflightCheck - useClusterContext-coverage (17 tests): operator name stripping, helm chart parsing, pod issues - sampleData-coverage (32 tests): field heuristics, detectFieldFormat edge cases Signed-off-by: Andrew Anderson <[email protected]> * fix: change savedCards/sharedDashboards to let for reassignment in resetShareRegistries Signed-off-by: Andrew Anderson <[email protected]> --------- Signed-off-by: Andrew Anderson <[email protected]> Signed-off-by: lightyagami2109 <[email protected]>
…1202) * 🐛 Fix incorrect assertion in agentFetch 401 retry test Co-authored-by: Copilot <[email protected]> Signed-off-by: Copilot <[email protected]> * test: batch 16 coverage — preflightCheck, useClusterContext, sampleData (kubestellar#11192) * test: add batch 16 coverage tests for preflightCheck, useClusterContext, sampleData Add 116 tests across 3 files to push line coverage past 90.50%: - preflightCheck-coverage (67 tests): classifyKubectlError, resolveRequiredTools, runToolPreflightCheck - useClusterContext-coverage (17 tests): operator name stripping, helm chart parsing, pod issues - sampleData-coverage (32 tests): field heuristics, detectFieldFormat edge cases Signed-off-by: Andrew Anderson <[email protected]> * fix: change savedCards/sharedDashboards to let for reassignment in resetShareRegistries Signed-off-by: Andrew Anderson <[email protected]> --------- Signed-off-by: Andrew Anderson <[email protected]> * 🐛 Fix medium Copilot comments: GHE commit URL, stale cluster selection, type signatures - feedback_config.go: add resolveGitHubUIBase() for GHE-aware web link construction - feedback_github.go: use resolveGitHubUIBase() for SHA commit link (kubestellar#11177 follow-up) - ComplianceReports.tsx: clear selectedCluster when it's filtered out by reachability (was only auto-set when empty, leaving stale selection pointing to hidden cluster) - ComplianceReports.tsx + ControlPlaneHealth.tsx: fix misleading 'only reachable' comments — predicate c.reachable !== false also includes undefined (not-yet-checked) - dedup.ts: widen shareMetricsBetweenSameServerClusters signature to ClusterInfo[] | null | undefined to match the runtime guard already in the body (kubestellar#11184 medium) - shared.ts: fix dedup priority comment — reachability is criterion kubestellar#1, not kubestellar#2 Co-authored-by: Copilot <[email protected]> Signed-off-by: Copilot <[email protected]> --------- Signed-off-by: Copilot <[email protected]> Signed-off-by: Andrew Anderson <[email protected]> Co-authored-by: Copilot <[email protected]> Signed-off-by: lightyagami2109 <[email protected]>
Summary
classifyKubectlErrorpatterns,resolveRequiredTools,runToolPreflightCheck,runPreflightCheckcatch branch,getRemediationActionsdetectFieldFormatedge casesTest plan
npx vitest run)