Skip to content

Commit 265b7b4

Browse files
committed
chore(audit-logs): scope the refresh refetch, drop a test that could not fail
`refetch` ignores `enabled`, so refreshing the unscoped feed fired a workspace lookup it has no use for and could fail a refresh that otherwise succeeded. It now runs only when a scope asked for it. The hook test claiming to cover an unresolved workspace scope passed `enabled: false` with no workspace at all, so it asserted TanStack's disabled handling and would have passed with the scope protection removed. The rule it named is derived in the component and is covered there by `presentableAuditEntries`; a test that cannot fail for its stated reason is worse than none.
1 parent d08d14c commit 265b7b4

2 files changed

Lines changed: 8 additions & 24 deletions

File tree

apps/sim/ee/audit-logs/components/audit-logs.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,14 @@ export function AuditLogs({ organizationId }: AuditLogsProps) {
407407
}, REFRESH_SPINNER_DURATION_MS)
408408
refreshTimers.add(timerId)
409409
/*
410-
Both, because a failed workspace lookup closes the feed — refreshing only the
411-
feed would leave the one control on screen unable to clear the state it is
412-
showing.
410+
The workspace lookup too, but only when a scope asked for it: a failed lookup
411+
closes the feed, so refreshing only the feed would leave the one control on
412+
screen unable to clear the state it is showing. `refetch` ignores `enabled`, so
413+
an unconditional call would fire a request the unscoped feed has no use for and
414+
could fail a refresh that otherwise succeeded.
413415
*/
414-
Promise.all([refetch(), orgWorkspaces.refetch()]).catch((error: unknown) => {
416+
const pending = workspaceScope ? [refetch(), orgWorkspaces.refetch()] : [refetch()]
417+
Promise.all(pending).catch((error: unknown) => {
415418
logger.error('Failed to refresh audit logs', { error })
416419
})
417420
}

apps/sim/ee/audit-logs/hooks/audit-logs.test.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,12 @@ function AuditProbe({
5454
organizationId,
5555
workspaceId,
5656
search,
57-
enabled = true,
5857
}: {
5958
organizationId: string
6059
workspaceId?: string
6160
search?: string
62-
enabled?: boolean
6361
}) {
64-
const auditLogs = useAuditLogs(organizationId, { workspaceId, search }, enabled)
62+
const auditLogs = useAuditLogs(organizationId, { workspaceId, search })
6563
const entries = auditLogs.data?.pages.flatMap((page) => page.data) ?? []
6664

6765
return (
@@ -75,7 +73,6 @@ function AuditProbe({
7573
interface RenderOptions {
7674
workspaceId?: string
7775
search?: string
78-
enabled?: boolean
7976
}
8077

8178
function renderAuditLogs(organizationId: string, options: RenderOptions = {}) {
@@ -86,7 +83,6 @@ function renderAuditLogs(organizationId: string, options: RenderOptions = {}) {
8683
organizationId={organizationId}
8784
workspaceId={options.workspaceId}
8885
search={options.search}
89-
enabled={options.enabled ?? true}
9086
/>
9187
</QueryClientProvider>
9288
)
@@ -197,19 +193,4 @@ describe('useAuditLogs identity transitions', () => {
197193
expect(container).not.toHaveTextContent('Updated Organization A')
198194
expect(container.querySelector('button')).toBeNull()
199195
})
200-
201-
/**
202-
* The scope a link asks for is a ceiling, not a hint. A workspace id that no longer
203-
* resolves must leave the feed closed rather than answering with the whole
204-
* organization's history under a URL that still claims to be scoped.
205-
*/
206-
it('never queries unscoped while a workspace scope is unresolved', async () => {
207-
mockRequestJson.mockResolvedValue(AUDIT_PAGE_A)
208-
209-
renderAuditLogs('org-a', { enabled: false })
210-
await flushQueries()
211-
212-
expect(mockRequestJson).not.toHaveBeenCalled()
213-
expect(container).not.toHaveTextContent('Updated Organization A')
214-
})
215196
})

0 commit comments

Comments
 (0)