-
Notifications
You must be signed in to change notification settings - Fork 462
fix(ui): revalidate test runs before advancing from the Test step #9046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iagodahlem
wants to merge
5
commits into
main
Choose a base branch
from
iago/orgs-1701-test-runs-on-continue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bb00a08
fix(ui): revalidate test runs before advancing from the Test step
iagodahlem da3f2fc
chore(repo): add changeset
iagodahlem 8cd0916
style(shared): wrap long revalidate type signatures per prettier
iagodahlem 7450977
fix(ui): apply useSpinDelay to the Continue loading state and tidy co…
iagodahlem 584c4df
fix(shared): scope test-run probe revalidation to its exact query key
iagodahlem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@clerk/shared': patch | ||
| '@clerk/ui': patch | ||
| --- | ||
|
|
||
| On the Test step of the self-serve SSO configuration flow, clicking Continue now re-checks for a successful test run before blocking, so a successful run completed in a separate browser tab is recognized without first clicking Refresh logs. |
101 changes: 101 additions & 0 deletions
101
...ges/shared/src/react/hooks/__tests__/useOrganizationEnterpriseConnectionTestRuns.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import { act, renderHook, waitFor } from '@testing-library/react'; | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import type { GetEnterpriseConnectionTestRunsParams } from '@/types/enterpriseConnectionTestRun'; | ||
|
|
||
| import { INTERNAL_STABLE_KEYS } from '../../stable-keys'; | ||
| import { createCacheKeys } from '../createCacheKeys'; | ||
| import { __internal_useOrganizationEnterpriseConnectionTestRuns } from '../useOrganizationEnterpriseConnectionTestRuns'; | ||
| import { createMockClerk, createMockQueryClient } from './mocks/clerk'; | ||
| import { wrapper } from './wrapper'; | ||
|
|
||
| // The success-filtered, single-row probe the Test step uses to answer | ||
| // `hasSuccessfulTestRun`. It is a sibling of the visible list page: both live | ||
| // under the same broad org+connection invalidation key, differing only in their | ||
| // fetch params (`untracked`). | ||
| const PROBE_PARAMS: GetEnterpriseConnectionTestRunsParams = { initialPage: 1, pageSize: 1, status: ['success'] }; | ||
|
|
||
| const getTestRunsSpy = vi.fn(() => Promise.resolve({ data: [{ id: 'run_success' }], total_count: 1 })); | ||
|
|
||
| const defaultQueryClient = createMockQueryClient(); | ||
|
|
||
| // Only `mock`-prefixed names may be referenced inside the hoisted `vi.mock` | ||
| // factory below, hence `mockClerk`. | ||
| const mockClerk = createMockClerk({ | ||
| queryClient: defaultQueryClient, | ||
| __internal_lastEmittedResources: { | ||
| user: null, | ||
| session: null, | ||
| organization: { id: 'org_1', getEnterpriseConnectionTestRuns: getTestRunsSpy }, | ||
| client: null, | ||
| }, | ||
| }); | ||
|
|
||
| vi.mock('../../contexts', () => ({ | ||
| useAssertWrappedByClerkProvider: () => {}, | ||
| useClerkInstanceContext: () => mockClerk, | ||
| useInitialStateContext: () => undefined, | ||
| })); | ||
|
|
||
| // The exact per-query key (includes the fetch params under `untracked`) vs the | ||
| // broad org+connection prefix shared by every test-runs query for the | ||
| // connection. `invalidateQueries` prefix-matches, so invalidating the broad key | ||
| // refetches the probe AND the visible list; the exact key hits only this query. | ||
| const { queryKey: exactKey, invalidationKey: broadKey } = createCacheKeys({ | ||
| stablePrefix: INTERNAL_STABLE_KEYS.ORGANIZATION_ENTERPRISE_CONNECTION_TEST_RUNS_KEY, | ||
| authenticated: true, | ||
| tracked: { organizationId: 'org_1', enterpriseConnectionId: 'ent_1' }, | ||
| untracked: { args: PROBE_PARAMS }, | ||
| }); | ||
|
|
||
| const renderProbe = () => | ||
| renderHook( | ||
| () => | ||
| __internal_useOrganizationEnterpriseConnectionTestRuns({ | ||
| enterpriseConnectionId: 'ent_1', | ||
| params: PROBE_PARAMS, | ||
| enabled: true, | ||
| }), | ||
| { wrapper }, | ||
| ); | ||
|
|
||
| describe('useOrganizationEnterpriseConnectionTestRuns — revalidate invalidation scope', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| defaultQueryClient.client.clear(); | ||
| mockClerk.loaded = true; | ||
| }); | ||
|
|
||
| it('revalidate({ exact: true }) invalidates ONLY the exact queryKey, never the broad org+connection key — so a sibling list query is left untouched', async () => { | ||
| const { result } = renderProbe(); | ||
| await waitFor(() => expect(result.current.isLoading).toBe(false)); | ||
|
|
||
| const invalidateSpy = vi.spyOn(defaultQueryClient.client, 'invalidateQueries'); | ||
| await act(async () => { | ||
| await result.current.revalidate({ armPolling: false, exact: true }); | ||
| }); | ||
|
|
||
| expect(invalidateSpy).toHaveBeenCalledWith({ queryKey: exactKey, exact: true }); | ||
| // Never the broad prefix — invalidating it is exactly what would also | ||
| // refetch the visible list and spin its `isFetching`-bound "Refresh logs" | ||
| // button when the Test step revalidates the probe on Continue. | ||
| expect(invalidateSpy).not.toHaveBeenCalledWith({ queryKey: broadKey }); | ||
|
|
||
| invalidateSpy.mockRestore(); | ||
| }); | ||
|
|
||
| it('revalidate() (default) keeps the broad org+connection invalidation so refresh()/"Refresh logs" still refetches the whole connection', async () => { | ||
| const { result } = renderProbe(); | ||
| await waitFor(() => expect(result.current.isLoading).toBe(false)); | ||
|
|
||
| const invalidateSpy = vi.spyOn(defaultQueryClient.client, 'invalidateQueries'); | ||
| await act(async () => { | ||
| await result.current.revalidate({ armPolling: false }); | ||
| }); | ||
|
|
||
| expect(invalidateSpy).toHaveBeenCalledWith({ queryKey: broadKey }); | ||
| expect(invalidateSpy).not.toHaveBeenCalledWith({ queryKey: exactKey, exact: true }); | ||
|
|
||
| invalidateSpy.mockRestore(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...s/ui/src/components/ConfigureSSO/hooks/__tests__/useEnterpriseConnectionTestRuns.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import type { EnterpriseConnectionResource } from '@clerk/shared/types'; | ||
| import { act, renderHook } from '@testing-library/react'; | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| // The umbrella test-run hook composes the shared internal hook TWICE — once for | ||
| // the success probe (success-filtered, pageSize 1) and once for the visible list | ||
| // (pageSize 5). We mock the shared module so each gets its own `revalidate` spy, | ||
| // letting us assert exactly which query Continue's probe revalidation drives and | ||
| // with which options. | ||
| const probeRevalidate = vi.fn(() => Promise.resolve({ data: [], totalCount: 0 })); | ||
| const listRevalidate = vi.fn(() => Promise.resolve({ data: [], totalCount: 0 })); | ||
|
|
||
| vi.mock('@clerk/shared/react', () => ({ | ||
| __internal_useOrganizationEnterpriseConnectionTestRuns: (params: { params?: { status?: string[] } }) => { | ||
| // The probe is the only call that passes a `status` filter; the list omits | ||
| // it. Route each render's `revalidate` to the matching spy. | ||
| const isProbe = Array.isArray(params.params?.status); | ||
| return { | ||
| data: [], | ||
| totalCount: 0, | ||
| error: null, | ||
| isLoading: false, | ||
| isFetching: false, | ||
| isPolling: false, | ||
| revalidate: isProbe ? probeRevalidate : listRevalidate, | ||
| }; | ||
| }, | ||
| })); | ||
|
|
||
| import { useEnterpriseConnectionTestRuns } from '../useEnterpriseConnectionTestRuns'; | ||
|
|
||
| const connection = { id: 'ent_1' } as EnterpriseConnectionResource; | ||
|
|
||
| beforeEach(() => { | ||
| probeRevalidate.mockClear(); | ||
| listRevalidate.mockClear(); | ||
| }); | ||
|
|
||
| describe('useEnterpriseConnectionTestRuns', () => { | ||
| it('revalidateHasSuccessfulTestRun revalidates ONLY the probe, with exact invalidation — so Continue never refetches (or spins) the visible list', async () => { | ||
| const { result } = renderHook(() => useEnterpriseConnectionTestRuns(connection, true)); | ||
|
|
||
| await act(async () => { | ||
| await result.current.revalidateHasSuccessfulTestRun(); | ||
| }); | ||
|
|
||
| // Continue's probe revalidation scopes invalidation to the probe's own query | ||
| // (`exact: true`) and never arms polling — so the list query, and its | ||
| // `isFetching`-bound "Refresh logs" spinner, stays idle. | ||
| expect(probeRevalidate).toHaveBeenCalledTimes(1); | ||
| expect(probeRevalidate).toHaveBeenCalledWith({ armPolling: false, exact: true }); | ||
| expect(listRevalidate).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Test never asserts the actual boolean result of
revalidateHasSuccessfulTestRun().The test only verifies that
probeRevalidatewas invoked with the right options — it never checks whatrevalidateHasSuccessfulTestRun()resolves to. Since the mock always returns{ data: [], totalCount: 0 }, the boolean-derivation logic (the part that actually decides whether Continue can advance) is untested in both the "no successful run" and "successful run found" branches. Per the downstream snippet,TestConfigurationStepdirectly gatesadvance()on this resolved value, so an incorrect derivation here would silently break the revalidation feature.As per coding guidelines, test files must "Verify proper error handling and edge cases" and tests should "Test component behavior, not implementation details" — this test currently only verifies implementation (spy calls), not the resulting behavior.
✅ Suggested additional coverage
const probeRevalidate = vi.fn(() => Promise.resolve({ data: [], totalCount: 0 })); const listRevalidate = vi.fn(() => Promise.resolve({ data: [], totalCount: 0 })); ... describe('useEnterpriseConnectionTestRuns', () => { it('revalidateHasSuccessfulTestRun revalidates ONLY the probe, with exact invalidation', async () => { ... }); + + it('resolves true when the revalidated probe contains a successful run', async () => { + probeRevalidate.mockResolvedValueOnce({ data: [{ id: 'run_1', status: 'success' }], totalCount: 1 }); + const { result } = renderHook(() => useEnterpriseConnectionTestRuns(connection, true)); + + let resolved: boolean | undefined; + await act(async () => { + resolved = await result.current.revalidateHasSuccessfulTestRun(); + }); + + expect(resolved).toBe(true); + }); + + it('resolves false when the revalidated probe has no successful run', async () => { + const { result } = renderHook(() => useEnterpriseConnectionTestRuns(connection, true)); + + let resolved: boolean | undefined; + await act(async () => { + resolved = await result.current.revalidateHasSuccessfulTestRun(); + }); + + expect(resolved).toBe(false); + }); });Also applies to: 40-54
🤖 Prompt for AI Agents
Source: Coding guidelines