Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(control-ui): r7-m9 cover resync read convergence
Codexd202dd1986f2
diff --git a/control-ui/components/__tests__/GfsBrowser.revalidation.integration.test.tsx b/control-ui/components/__tests__/GfsBrowser.revalidation.integration.test.tsxindex 35221f442..aa1c1ca28 100644--- a/control-ui/components/__tests__/GfsBrowser.revalidation.integration.test.tsx+++ b/control-ui/components/__tests__/GfsBrowser.revalidation.integration.test.tsx@@ -31,116 +31,119 @@ describe('GfsBrowser authoritative revalidation integration', () => {vi.restoreAllMocks()})- it('does not publish a stale background page after the newer stream read', async () => {- const work = child('folder-1', 'rid-folder-1', 'work', 'directory')- const staleRow = child('stale-file', 'rid-stale', 'stale.txt', 'file')- const currentRow = child('current-file', 'rid-current', 'current.txt', 'file')- const folderPath = '/control-api/api/v1/gfs/resources/folder-1/children'- const stalePage = { items: [staleRow], nextCursor: null }- const currentPage = { items: [currentRow], nextCursor: null }- let finishStaleRead!: (response: Response) => void- const staleRead = new Promise<Response>(resolve => {- finishStaleRead = resolve- })- let childReads = 0- let folderOpened = false- let staleBackgroundStarted = false- const streamControllers: ReadableStreamDefaultController<Uint8Array>[] = []- vi.stubGlobal(- 'fetch',- vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {- const url = new URL(String(input), 'http://control-ui.test')- if (url.pathname.endsWith('/api/v1/gfs/entity-changes/stream')) {- const body = new ReadableStream<Uint8Array>({- start(controller) {- streamControllers.push(controller)- init?.signal?.addEventListener('abort', () => controller.close(), { once: true })- },- })- return new Response(body, {- status: 200,- headers: { 'content-type': 'application/x-ndjson' },- })- }- if (url.pathname.endsWith('/api/v1/gfs/tree')) {- return jsonResponse({- rootResourceId: 'root-1',- items: [work],- nextCursor: null,- })- }- if (url.pathname === '/control-api/api/v1/gfs/resources/root-1/children') {- return jsonResponse({ items: [work], nextCursor: null })- }- if (url.pathname === folderPath) {- childReads += 1- if (!folderOpened) return jsonResponse(stalePage)- if (!staleBackgroundStarted) {- staleBackgroundStarted = true- return staleRead- }- return jsonResponse(currentPage)- }- if (url.pathname.endsWith('/api/v1/gfs/resolve')) {- return jsonResponse({- resourceId: 'folder-1',- rid: 'rid-folder-1',- gfsUri: 'gfs://main/rid-folder-1',- name: 'work',- kind: 'directory',- path: '/work',- version: 1,- })- }- if (url.pathname.endsWith('/api/v1/gfs/by-path')) {- return jsonResponse({- resourceId: 'folder-1',- rid: 'rid-folder-1',- gfsUri: 'gfs://main/rid-folder-1',- name: 'work',- kind: 'directory',- path: '/work',- version: 1,- })- }- return jsonResponse({ items: [], nextCursor: null })+ it.each(['scope.invalidated', 'resync_required'] as const)(+ 'does not publish a stale background page after %s',+ async frameType => {+ const work = child('folder-1', 'rid-folder-1', 'work', 'directory')+ const staleRow = child('stale-file', 'rid-stale', 'stale.txt', 'file')+ const currentRow = child('current-file', 'rid-current', 'current.txt', 'file')+ const folderPath = '/control-api/api/v1/gfs/resources/folder-1/children'+ const stalePage = { items: [staleRow], nextCursor: null }+ const currentPage = { items: [currentRow], nextCursor: null }+ let finishStaleRead!: (response: Response) => void+ const staleRead = new Promise<Response>(resolve => {+ finishStaleRead = resolve})- )+ let childReads = 0+ let folderOpened = false+ let staleBackgroundStarted = false+ const streamControllers: ReadableStreamDefaultController<Uint8Array>[] = []+ vi.stubGlobal(+ 'fetch',+ vi.fn(async (input: RequestInfo | URL, init?: RequestInit) => {+ const url = new URL(String(input), 'http://control-ui.test')+ if (url.pathname.endsWith('/api/v1/gfs/entity-changes/stream')) {+ const body = new ReadableStream<Uint8Array>({+ start(controller) {+ streamControllers.push(controller)+ init?.signal?.addEventListener('abort', () => controller.close(), { once: true })+ },+ })+ return new Response(body, {+ status: 200,+ headers: { 'content-type': 'application/x-ndjson' },+ })+ }+ if (url.pathname.endsWith('/api/v1/gfs/tree')) {+ return jsonResponse({+ rootResourceId: 'root-1',+ items: [work],+ nextCursor: null,+ })+ }+ if (url.pathname === '/control-api/api/v1/gfs/resources/root-1/children') {+ return jsonResponse({ items: [work], nextCursor: null })+ }+ if (url.pathname === folderPath) {+ childReads += 1+ if (!folderOpened) return jsonResponse(stalePage)+ if (!staleBackgroundStarted) {+ staleBackgroundStarted = true+ return staleRead+ }+ return jsonResponse(currentPage)+ }+ if (url.pathname.endsWith('/api/v1/gfs/resolve')) {+ return jsonResponse({+ resourceId: 'folder-1',+ rid: 'rid-folder-1',+ gfsUri: 'gfs://main/rid-folder-1',+ name: 'work',+ kind: 'directory',+ path: '/work',+ version: 1,+ })+ }+ if (url.pathname.endsWith('/api/v1/gfs/by-path')) {+ return jsonResponse({+ resourceId: 'folder-1',+ rid: 'rid-folder-1',+ gfsUri: 'gfs://main/rid-folder-1',+ name: 'work',+ kind: 'directory',+ path: '/work',+ version: 1,+ })+ }+ return jsonResponse({ items: [], nextCursor: null })+ })+ )- render(- <ToastProvider>- <GfsBrowser />- </ToastProvider>- )- await waitFor(() => expect(streamControllers).toHaveLength(1))- await screen.findByRole('button', { name: 'work' })- fireEvent.click(screen.getByRole('button', { name: 'work' }))- await screen.findByRole('button', { name: 'stale.txt' })- const breadcrumb = screen.getByRole('navigation', { name: 'Breadcrumb' })- fireEvent.click(breadcrumb.querySelector('button')!)- await screen.findByRole('button', { name: 'work' })- folderOpened = true- fireEvent.click(screen.getByRole('button', { name: 'work' }))- await screen.findByRole('button', { name: 'stale.txt' })- await waitFor(() => expect(staleBackgroundStarted).toBe(true))+ render(+ <ToastProvider>+ <GfsBrowser />+ </ToastProvider>+ )+ await waitFor(() => expect(streamControllers).toHaveLength(1))+ await screen.findByRole('button', { name: 'work' })+ fireEvent.click(screen.getByRole('button', { name: 'work' }))+ await screen.findByRole('button', { name: 'stale.txt' })+ const breadcrumb = screen.getByRole('navigation', { name: 'Breadcrumb' })+ fireEvent.click(breadcrumb.querySelector('button')!)+ await screen.findByRole('button', { name: 'work' })+ folderOpened = true+ fireEvent.click(screen.getByRole('button', { name: 'work' }))+ await screen.findByRole('button', { name: 'stale.txt' })+ await waitFor(() => expect(staleBackgroundStarted).toBe(true))- await act(async () => {- streamControllers[0]!.enqueue(- new TextEncoder().encode(- `${JSON.stringify({- schemaVersion: 1,- type: 'scope.invalidated',- cursor: 'd119f895-1ef8-4e73-8f08-f9754919682a',- scopes: ['gfs'],- })}\n`+ await act(async () => {+ streamControllers[0]!.enqueue(+ new TextEncoder().encode(+ `${JSON.stringify({+ schemaVersion: 1,+ type: frameType,+ cursor: 'd119f895-1ef8-4e73-8f08-f9754919682a',+ scopes: ['gfs'],+ })}\n`+ ))- )- })- await screen.findByRole('button', { name: 'current.txt' })- await waitFor(() => expect(childReads).toBeGreaterThan(2))+ })+ await screen.findByRole('button', { name: 'current.txt' })+ await waitFor(() => expect(childReads).toBeGreaterThan(2))- await act(async () => finishStaleRead(jsonResponse(stalePage)))- await waitFor(() => expect(screen.getByRole('button', { name: 'current.txt' })).toBeVisible())- expect(screen.queryByRole('button', { name: 'stale.txt' })).toBeNull()- })+ await act(async () => finishStaleRead(jsonResponse(stalePage)))+ await waitFor(() => expect(screen.getByRole('button', { name: 'current.txt' })).toBeVisible())+ expect(screen.queryByRole('button', { name: 'stale.txt' })).toBeNull()+ }+ )})diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex a4cf48932..d2f07540f 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.672",+ "version": "0.1.673","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.672",+ "version": "0.1.673","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/frontend-components": "file:../packages/frontend-components",diff --git a/control-ui/package.json b/control-ui/package.jsonindex 5f95c6e06..d55750d71 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.672",+ "version": "0.1.673","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",