Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(control-ui): prove forced publish-scope refresh

Josuécead4af564e3
diff --git a/control-ui/lib/hooks/__tests__/usePublishScope.test.tsx b/control-ui/lib/hooks/__tests__/usePublishScope.test.tsx
index 08e7816d1..b54f81eed 100644
--- a/control-ui/lib/hooks/__tests__/usePublishScope.test.tsx
+++ b/control-ui/lib/hooks/__tests__/usePublishScope.test.tsx
@@ -23,10 +23,12 @@ function Probe() {
}
function RefreshProbe() {
- const { scope, loading, refresh } = usePublishScope()
+ const { scope, loading, error, refresh } = usePublishScope()
return (
<div>
- <div data-testid="scope">{loading ? 'loading' : (scope?.scope ?? 'none')}</div>
+ <div data-testid="scope">
+ {loading ? 'loading' : error ? 'error' : (scope?.scope ?? 'none')}
+ </div>
<button type="button" onClick={() => void refresh({ force: true })}>
Refresh
</button>
@@ -147,6 +149,73 @@ describe('usePublishScope / isPublisherEnabled', () => {
expect(api.getPublishScope).toHaveBeenCalledTimes(1)
})
+ it('bypasses the resolved provider cache on forced refresh', async () => {
+ vi.mocked(api.getPublishScope)
+ .mockResolvedValueOnce(scope('@acme'))
+ .mockResolvedValueOnce(scope('@beta'))
+
+ const view = renderWithProvider(<RefreshProbe />)
+ expect(await screen.findByText('@acme')).toBeInTheDocument()
+ expect(api.getPublishScope).toHaveBeenCalledTimes(1)
+
+ fireEvent.click(screen.getByRole('button', { name: 'Refresh' }))
+ expect(await screen.findByText('@beta')).toBeInTheDocument()
+ expect(api.getPublishScope).toHaveBeenCalledTimes(2)
+
+ view.unmount()
+ renderWithProvider(<RefreshProbe />)
+ expect(await screen.findByText('@beta')).toBeInTheDocument()
+ expect(api.getPublishScope).toHaveBeenCalledTimes(2)
+ })
+
+ it('keeps overlapping forced refreshes ordered after an existing cache hit', async () => {
+ const beta = deferred<api.PublishScope>()
+ const gamma = deferred<api.PublishScope>()
+ vi.mocked(api.getPublishScope)
+ .mockResolvedValueOnce(scope('@acme'))
+ .mockReturnValueOnce(beta.promise)
+ .mockReturnValueOnce(gamma.promise)
+
+ const view = renderWithProvider(<RefreshProbe />)
+ expect(await screen.findByText('@acme')).toBeInTheDocument()
+
+ fireEvent.click(screen.getByRole('button', { name: 'Refresh' }))
+ fireEvent.click(screen.getByRole('button', { name: 'Refresh' }))
+ expect(api.getPublishScope).toHaveBeenCalledTimes(3)
+
+ await act(async () => {
+ gamma.resolve(scope('@gamma'))
+ await gamma.promise
+ })
+ expect(await screen.findByText('@gamma')).toBeInTheDocument()
+
+ await act(async () => {
+ beta.resolve(scope('@beta'))
+ await beta.promise
+ })
+ expect(screen.getByText('@gamma')).toBeInTheDocument()
+ expect(screen.queryByText('@beta')).toBeNull()
+
+ view.unmount()
+ renderWithProvider(<RefreshProbe />)
+ expect(await screen.findByText('@gamma')).toBeInTheDocument()
+ expect(api.getPublishScope).toHaveBeenCalledTimes(3)
+ })
+
+ it('does not expose a stale resolved scope after a forced refresh failure', async () => {
+ vi.mocked(api.getPublishScope)
+ .mockResolvedValueOnce(scope('@acme'))
+ .mockRejectedValueOnce(Object.assign(new Error('boom'), { status: 500 }))
+
+ renderWithProvider(<RefreshProbe />)
+ expect(await screen.findByText('@acme')).toBeInTheDocument()
+
+ fireEvent.click(screen.getByRole('button', { name: 'Refresh' }))
+ expect(await screen.findByText('error')).toBeInTheDocument()
+ expect(screen.queryByText('@acme')).toBeNull()
+ expect(api.getPublishScope).toHaveBeenCalledTimes(2)
+ })
+
it('does not expose a stale keyed request that resolves after reset', async () => {
const stale = deferred<api.PublishScope>()
const fresh = deferred<api.PublishScope>()
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 7bdf2794d..cc90c2d02 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.378",
+ "version": "0.1.379",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.378",
+ "version": "0.1.379",
"dependencies": {
"@clerum/llm-providers": "file:../packages/llm-providers",
"@clerum/workflow-recipe-capability-policy": "file:../packages/workflow-recipe-capability-policy",
diff --git a/control-ui/package.json b/control-ui/package.json
index f261022b8..beca2d0af 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.378",
+ "version": "0.1.379",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",