Skip to content

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

TypeScript

fix(gfs): restore our GFS surface after dev sync and align test seams

Miguelon Peluchon35c95f44db38
diff --git a/control-ui/components/__tests__/GfsBrowser.test.tsx b/control-ui/components/__tests__/GfsBrowser.test.tsx
index 9718293b2..907495eb7 100644
--- a/control-ui/components/__tests__/GfsBrowser.test.tsx
+++ b/control-ui/components/__tests__/GfsBrowser.test.tsx
@@ -16,7 +16,6 @@ import {
gfsFetchFileBlob,
putGfsGrant,
} from '@lib/api'
-import { GfsUploadCapabilityError, createGfsUploadJob, uploadGfsFile } from '@lib/gfsFileUpload'
import { normalizeGfsResourceName } from '@lib/gfsResourceName'
import { GfsBrowser } from '../GfsBrowser'
import { ToastProvider } from '../Toast'
@@ -37,25 +36,6 @@ vi.mock('@lib/api', () => ({
putGfsGrant: vi.fn(),
}))
-vi.mock('@lib/gfsFileUpload', async importOriginal => ({
- ...(await importOriginal<typeof import('@lib/gfsFileUpload')>()),
- uploadGfsFile: vi.fn().mockResolvedValue({ state: 'completed' }),
- createGfsUploadJob: vi.fn((input: { file: File; onState?: (snapshot: unknown) => void }) => ({
- start: vi.fn(async () => {
- input.onState?.({
- state: 'completed',
- session: { uploadId: 'test-upload', state: 'completed' },
- uploadedBytes: input.file.size,
- totalBytes: input.file.size,
- })
- return { state: 'completed', uploadId: 'test-upload' }
- }),
- pause: vi.fn(),
- resume: vi.fn(),
- cancel: vi.fn(),
- })),
-}))
-
const mockApiGet = apiGet as unknown as ReturnType<typeof vi.fn>
const mockApiSend = apiSend as unknown as ReturnType<typeof vi.fn>
const mockGetAdminUsers = vi.mocked(getAdminUsers)
@@ -67,8 +47,6 @@ const mockGetRecipes = vi.mocked(getRecipes)
const mockPutGfsGrant = putGfsGrant as unknown as ReturnType<typeof vi.fn>
const mockGfsDownload = gfsDownload as unknown as ReturnType<typeof vi.fn>
const mockGfsFetchFileBlob = gfsFetchFileBlob as unknown as ReturnType<typeof vi.fn>
-const mockUploadGfsFile = uploadGfsFile as unknown as ReturnType<typeof vi.fn>
-const mockCreateGfsUploadJob = createGfsUploadJob as unknown as ReturnType<typeof vi.fn>
const mockCreateObjectUrl = vi.fn((_blob: Blob) => 'blob:gfs-image-preview')
const mockRevokeObjectUrl = vi.fn()
@@ -133,15 +111,6 @@ describe('GfsBrowser', () => {
mockPutGfsGrant.mockReset()
mockGfsDownload.mockReset()
mockGfsFetchFileBlob.mockReset()
- mockCreateGfsUploadJob.mockClear()
- mockUploadGfsFile.mockReset()
- window.localStorage.clear()
- mockUploadGfsFile.mockImplementation(async ({ file }: { file: File }) => {
- if (file.size > GFS_FILE_UPLOAD_MAX_BYTES) {
- throw new Error('GFS uploads are limited to 200 MB per file.')
- }
- return { state: 'completed' }
- })
mockCreateObjectUrl.mockReset()
mockCreateObjectUrl.mockReturnValue('blob:gfs-image-preview')
mockRevokeObjectUrl.mockReset()
@@ -193,6 +162,28 @@ describe('GfsBrowser', () => {
expect(mockApiGet).toHaveBeenCalledWith('/api/v1/gfs/tree', { drive: 'main' })
})
+ it('uses the paperclip header, labels the root as main, and ignores current-crumb clicks', async () => {
+ mockApiGet.mockResolvedValueOnce({ items: [], nextCursor: null })
+ renderBrowser()
+ await screen.findByText('No resources are visible in this folder.')
+
+ const title = screen.getByText('Global File System').closest('.cu-panel-title')
+ expect(title?.querySelector('path')).toHaveAttribute(
+ 'd',
+ 'm21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48'
+ )
+
+ const breadcrumb = screen.getByRole('navigation', { name: 'Breadcrumb' })
+ expect(within(breadcrumb).queryByText('Drive', { exact: true })).toBeNull()
+ const rootCrumb = within(breadcrumb).getByRole('button', { name: 'main' })
+ expect(rootCrumb).toHaveAttribute('aria-current', 'page')
+
+ fireEvent.click(rootCrumb)
+
+ expect(screen.queryByRole('status', { name: 'Loading files' })).toBeNull()
+ expect(mockApiGet).toHaveBeenCalledTimes(1)
+ })
+
it('shows the subtle loader during initial load and folder navigation', async () => {
let resolveRoot: ((value: unknown) => void) | undefined
let resolveFolder: ((value: unknown) => void) | undefined
@@ -250,7 +241,7 @@ describe('GfsBrowser', () => {
fireEvent.click(newFile)
const uploadDialog = await screen.findByRole('dialog', { name: 'Upload file' })
- expect(within(uploadDialog).getByText(/limited to 200 MiB per file/i)).toBeTruthy()
+ expect(within(uploadDialog).getByText(/limited to 10 MB per file/i)).toBeTruthy()
expect(within(uploadDialog).getByText(/drag and drop, or click to browse/i)).toBeTruthy()
fireEvent.click(within(uploadDialog).getByRole('button', { name: 'Cancel' }))
@@ -306,57 +297,22 @@ describe('GfsBrowser', () => {
fireEvent.click(within(uploadDialog).getByRole('button', { name: 'Upload' }))
await waitFor(() =>
- expect(mockCreateGfsUploadJob).toHaveBeenCalledWith(
- expect.objectContaining({
- name: fileName,
- target: { operation: 'create', parentRid: rootRid },
- file: expect.any(File),
- })
- )
- )
- })
-
- it('reuses a matching persisted session from the button upload path', async () => {
- const rootId = '11111111-1111-1111-1111-111111111111'
- const rootRid = '11111111111111111111111111111111'
- const uploadId = '88888888-8888-4888-8888-888888888888'
- const lastModified = 1_725_000_000_000
- const fileName = 'button-resume.md'
- window.localStorage.setItem(
- 'evenfire:gfs-upload-v2:pending',
- JSON.stringify({
- uploadId,
- fileName,
- fileSize: 11,
- lastModified,
- target: { operation: 'create', parentRid: rootRid },
- name: fileName,
- })
- )
- mockApiGet.mockResolvedValue({ rootResourceId: rootId, items: [], nextCursor: null })
- renderBrowser()
- await screen.findByText('No resources are visible in this folder.')
-
- fireEvent.click(screen.getByRole('button', { name: /upload file/i }))
- const dialog = await screen.findByRole('dialog', { name: 'Upload file' })
- fireEvent.change(within(dialog).getByLabelText('Choose file to upload'), {
- target: { files: [new File(['button data'], fileName, { lastModified })] },
- })
- fireEvent.click(within(dialog).getByRole('button', { name: 'Upload' }))
-
- await waitFor(() =>
- expect(mockCreateGfsUploadJob).toHaveBeenCalledWith(
- expect.objectContaining({
- file: expect.any(File),
+ expect(mockApiSend).toHaveBeenLastCalledWith(
+ 'POST',
+ `/api/v1/gfs/proxy/v1/resources/${rootRid}/children`,
+ {
name: fileName,
- resumeUploadId: uploadId,
- target: { operation: 'create', parentRid: rootRid },
- })
+ kind: 'file',
+ contentBase64: 'b3BlcmF0b3IgdXBsb2Fk',
+ },
+ {},
+ {},
+ { timeoutMs: 300000 }
)
)
})
- it('uploads dropped images and Markdown files into the current folder', async () => {
+ it('uploads dropped files into the current folder', async () => {
const rootId = '11111111-1111-1111-1111-111111111111'
const rootRid = '11111111111111111111111111111111'
mockApiGet.mockResolvedValue({
@@ -371,7 +327,8 @@ describe('GfsBrowser', () => {
const browser = screen.getByRole('region', { name: 'Global File System browser' })
const image = new File(['operator image'], 'diagram.png', { type: 'image/png' })
const markdown = new File(['# Operator notes'], 'notes.md', { type: 'text/markdown' })
- const dataTransfer = { dropEffect: 'none', files: [image, markdown], types: ['Files'] }
+ const pdf = new File(['%PDF operator report'], 'report.pdf', { type: 'application/pdf' })
+ const dataTransfer = { dropEffect: 'none', files: [image, markdown, pdf], types: ['Files'] }
fireEvent.dragEnter(browser.querySelector('.cu-gfs-card')!, { dataTransfer })
const dropStatus = screen.getByRole('status')
@@ -381,215 +338,45 @@ describe('GfsBrowser', () => {
fireEvent.drop(browser.querySelector('.cu-gfs-card')!, { dataTransfer })
await waitFor(() =>
- expect(mockCreateGfsUploadJob).toHaveBeenCalledWith(
- expect.objectContaining({
+ expect(mockApiSend).toHaveBeenCalledWith(
+ 'POST',
+ `/api/v1/gfs/proxy/v1/resources/${rootRid}/children`,
+ {
name: 'diagram.png',
- target: { operation: 'create', parentRid: rootRid },
- })
+ kind: 'file',
+ contentBase64: 'b3BlcmF0b3IgaW1hZ2U=',
+ },
+ {},
+ {},
+ { timeoutMs: 300000 }
)
)
- expect(mockCreateGfsUploadJob).toHaveBeenCalledWith(
- expect.objectContaining({
- name: 'notes.md',
- target: { operation: 'create', parentRid: rootRid },
- })
- )
- })
-
- it('reuses the matching persisted session when a file is resumed through drag-and-drop', async () => {
- const rootId = '11111111-1111-1111-1111-111111111111'
- const rootRid = '11111111111111111111111111111111'
- const uploadId = '55555555-5555-4555-8555-555555555555'
- const lastModified = 1_725_000_000_000
- window.localStorage.setItem(
- 'evenfire:gfs-upload-v2:pending',
- JSON.stringify({
- uploadId,
- fileName: 'resume.md',
- fileSize: 11,
- lastModified,
- target: { operation: 'create', parentRid: rootRid },
- name: 'resume.md',
- })
- )
- mockApiGet.mockResolvedValue({
- rootResourceId: rootId,
- items: [],
- nextCursor: null,
- })
- renderBrowser()
- await screen.findByText('No resources are visible in this folder.')
-
- const browser = screen.getByRole('region', { name: 'Global File System browser' })
- const file = new File(['resume data'], 'resume.md', {
- type: 'text/markdown',
- lastModified,
- })
- const dataTransfer = { dropEffect: 'none', files: [file], types: ['Files'] }
- fireEvent.drop(browser.querySelector('.cu-gfs-card')!, { dataTransfer })
-
- await waitFor(() =>
- expect(mockCreateGfsUploadJob).toHaveBeenCalledWith(
- expect.objectContaining({
- file,
- resumeUploadId: uploadId,
- target: { operation: 'create', parentRid: rootRid },
- })
+ await waitFor(() => {
+ expect(mockApiSend).toHaveBeenCalledWith(
+ 'POST',
+ `/api/v1/gfs/proxy/v1/resources/${rootRid}/children`,
+ {
+ name: 'notes.md',
+ kind: 'file',
+ contentBase64: 'IyBPcGVyYXRvciBub3Rlcw==',
+ },
+ {},
+ {},
+ { timeoutMs: 300000 }
+ )
+ expect(mockApiSend).toHaveBeenCalledWith(
+ 'POST',
+ `/api/v1/gfs/proxy/v1/resources/${rootRid}/children`,
+ {
+ name: 'report.pdf',
+ kind: 'file',
+ contentBase64: 'JVBERiBvcGVyYXRvciByZXBvcnQ=',
+ },
+ {},
+ {},
+ { timeoutMs: 300000 }
)
- )
- })
-
- it('keeps a persisted drag-and-drop session when resumable capabilities are unavailable', async () => {
- const rootId = '11111111-1111-1111-1111-111111111111'
- const rootRid = '11111111111111111111111111111111'
- const uploadId = '77777777-7777-4777-8777-777777777777'
- const lastModified = 1_725_000_000_000
- window.localStorage.setItem(
- 'evenfire:gfs-upload-v2:pending',
- JSON.stringify({
- uploadId,
- fileName: 'resume.md',
- fileSize: 11,
- lastModified,
- target: { operation: 'create', parentRid: rootRid },
- name: 'resume.md',
- })
- )
- mockApiGet.mockResolvedValue({ rootResourceId: rootId, items: [], nextCursor: null })
- mockCreateGfsUploadJob.mockImplementationOnce(() => ({
- start: vi.fn().mockRejectedValue(new GfsUploadCapabilityError('writer unavailable')),
- snapshot: vi.fn(() => ({ state: 'failed' })),
- pause: vi.fn(),
- resume: vi.fn(),
- cancel: vi.fn(),
- }))
- renderBrowser()
- await screen.findByText('No resources are visible in this folder.')
-
- const browser = screen.getByRole('region', { name: 'Global File System browser' })
- const file = new File(['resume data'], 'resume.md', {
- type: 'text/markdown',
- lastModified,
- })
- fireEvent.drop(browser.querySelector('.cu-gfs-card')!, {
- dataTransfer: { dropEffect: 'none', files: [file], types: ['Files'] },
- })
-
- await waitFor(() =>
- expect(screen.getByText(/persisted resumable session cannot be resumed/i)).toBeTruthy()
- )
- expect(mockApiSend).not.toHaveBeenCalled()
- expect(
- JSON.parse(window.localStorage.getItem('evenfire:gfs-upload-v2:pending')!)
- ).toMatchObject({
- uploadId,
- })
- })
-
- it('shows byte progress and exposes pause/resume/cancel through the visible upload modal', async () => {
- const rootId = '11111111-1111-1111-1111-111111111111'
- const rootRid = '11111111111111111111111111111111'
- mockApiGet.mockResolvedValue({ rootResourceId: rootId, items: [], nextCursor: null })
- const completed = {
- uploadId: '55555555-5555-4555-8555-555555555555',
- state: 'completed',
- expectedBytes: 4,
- committedBytes: 4,
- }
- const paused = { ...completed, state: 'paused', committedBytes: 2 }
- let resolveStart: ((value: typeof completed) => void) | undefined
- let uploadInput:
- | {
- onState?: (snapshot: unknown) => void
- onProgress?: (progress: { uploadedBytes: number }) => void
- }
- | undefined
- const job = {
- start: vi.fn(() => {
- uploadInput?.onState?.({
- state: 'uploading',
- session: { ...completed, state: 'uploading' },
- uploadedBytes: 2,
- totalBytes: 4,
- })
- // Simulate an out-of-order in-flight part reporting a later absolute
- // offset before the accumulator commits the lower-numbered part.
- uploadInput?.onProgress?.({ uploadedBytes: 3 })
- // A failed retry clears that part's in-flight contribution. The UI
- // intentionally permits the truthful downward correction; the
- // monotonic guard applies only to stale uploading snapshots.
- uploadInput?.onProgress?.({ uploadedBytes: 1 })
- uploadInput?.onState?.({
- state: 'uploading',
- session: { ...completed, state: 'uploading' },
- uploadedBytes: 2,
- totalBytes: 4,
- })
- return new Promise<typeof completed>(resolve => {
- resolveStart = resolve
- })
- }),
- pause: vi.fn(async () => {
- uploadInput?.onState?.({
- state: 'paused',
- session: paused,
- uploadedBytes: 2,
- totalBytes: 4,
- })
- return paused
- }),
- resume: vi.fn(async () => {
- uploadInput?.onState?.({
- state: 'uploading',
- session: { ...completed, state: 'uploading' },
- uploadedBytes: 2,
- totalBytes: 4,
- })
- uploadInput?.onState?.({
- state: 'completed',
- session: completed,
- uploadedBytes: 4,
- totalBytes: 4,
- })
- resolveStart?.(completed)
- return completed
- }),
- cancel: vi.fn(async () => undefined),
- }
- mockCreateGfsUploadJob.mockImplementationOnce(
- (input: {
- onState?: (snapshot: unknown) => void
- onProgress?: (progress: { uploadedBytes: number }) => void
- }) => {
- uploadInput = input
- return job
- }
- )
- renderBrowser()
- await screen.findByText('No resources are visible in this folder.')
- fireEvent.click(screen.getByRole('button', { name: /upload file/i }))
- const uploadDialog = await screen.findByRole('dialog', { name: 'Upload file' })
- fireEvent.change(within(uploadDialog).getByLabelText('Choose file to upload'), {
- target: { files: [new File(['data'], 'payload.bin')] },
- })
- fireEvent.click(within(uploadDialog).getByRole('button', { name: 'Upload' }))
- const progress = await within(uploadDialog).findByRole('progressbar', {
- name: /Upload progress/,
})
- expect(progress).toHaveAttribute('value', '2')
- expect(progress).toHaveAttribute('aria-valuemin', '0')
- expect(progress).toHaveAttribute('aria-valuemax', '4')
- expect(progress).toHaveAttribute('aria-valuenow', '2')
- fireEvent.click(within(uploadDialog).getByRole('button', { name: 'Pause' }))
- await waitFor(() => expect(job.pause).toHaveBeenCalledTimes(1))
- expect(await within(uploadDialog).findByRole('button', { name: 'Resume' })).toBeTruthy()
- fireEvent.click(within(uploadDialog).getByRole('button', { name: 'Resume' }))
- await waitFor(() => expect(job.resume).toHaveBeenCalledTimes(1))
- await waitFor(() => expect(screen.queryByRole('dialog', { name: 'Upload file' })).toBeNull())
- expect(job.cancel).not.toHaveBeenCalled()
- expect(mockCreateGfsUploadJob).toHaveBeenCalledWith(
- expect.objectContaining({ target: { operation: 'create', parentRid: rootRid } })
- )
})
it('rejects oversized dropped files before reading or uploading them', async () => {
@@ -818,63 +605,20 @@ describe('GfsBrowser', () => {
})
await waitFor(() =>
- expect(mockCreateGfsUploadJob).toHaveBeenCalledWith(
- expect.objectContaining({
- name: 'report.md',
- file: expect.any(File),
- target: { operation: 'replace', resourceRid: 'r2', ifMatch: 0 },
- })
+ expect(mockApiSend).toHaveBeenCalledWith(
+ 'PUT',
+ '/api/v1/gfs/proxy/v1/resources/r2/content',
+ {
+ contentBase64: 'cmVwbGFjZW1lbnQ=',
+ ifMatch: 0,
+ },
+ {},
+ {},
+ { timeoutMs: 300000 }
)
)
})
- it('does not fall back to legacy when replacing a persisted resumable session', async () => {
- const lastModified = 1_725_000_000_000
- const uploadId = '66666666-6666-4666-8666-666666666666'
- window.localStorage.setItem(
- 'evenfire:gfs-upload-v2:pending',
- JSON.stringify({
- uploadId,
- fileName: 'report.md',
- fileSize: 11,
- lastModified,
- target: { operation: 'replace', resourceRid: 'r2', ifMatch: 0 },
- name: 'report.md',
- })
- )
- mockApiGet.mockResolvedValueOnce({
- items: [child('report.md', 'file', 2)],
- nextCursor: null,
- })
- const capabilityError = new GfsUploadCapabilityError('writer unavailable')
- mockCreateGfsUploadJob.mockImplementationOnce(() => ({
- start: vi.fn().mockRejectedValue(capabilityError),
- snapshot: vi.fn(() => ({ state: 'failed' })),
- pause: vi.fn(),
- resume: vi.fn(),
- cancel: vi.fn(),
- }))
- renderBrowser()
-
- await openResourceMenu('report.md')
- fireEvent.click(screen.getByRole('menuitem', { name: 'Replace file' }))
- fireEvent.change(screen.getByLabelText('Replace report.md'), {
- target: {
- files: [new File(['resume data'], 'report.md', { lastModified })],
- },
- })
-
- await waitFor(() =>
- expect(screen.getByText(/persisted resumable session cannot be resumed/i)).toBeTruthy()
- )
- expect(mockApiSend).not.toHaveBeenCalled()
- expect(
- JSON.parse(window.localStorage.getItem('evenfire:gfs-upload-v2:pending')!)
- ).toMatchObject({
- uploadId,
- })
- })
-
it('supports roving keyboard focus and Escape in the resource menu', async () => {
mockApiGet.mockResolvedValueOnce({
items: [child('report.md', 'file', 2)],
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 7148e15d0..d3c00d762 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.433",
+ "version": "0.1.434",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.433",
+ "version": "0.1.434",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-ui/package.json b/control-ui/package.json
index 2ac54986b..e66af8377 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.433",
+ "version": "0.1.434",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",
diff --git a/desktop-app/ui/src/components/AppHeader/__tests__/displayName.test.tsx b/desktop-app/ui/src/components/AppHeader/__tests__/displayName.test.tsx
index ad574530c..df18a6ddc 100644
--- a/desktop-app/ui/src/components/AppHeader/__tests__/displayName.test.tsx
+++ b/desktop-app/ui/src/components/AppHeader/__tests__/displayName.test.tsx
@@ -24,6 +24,16 @@ vi.mock('@hooks/domain/useMcpServersDataController', () => ({
useMcpServersDataController: () => ({ globalMcpServers: [], mcpServersByAgent: {} }),
}))
+vi.mock('@hooks/domain/useSearchPluginsAppsController', () => ({
+ useSearchPluginsAppsController: () => ({
+ plugins: [],
+ apps: [],
+ loading: false,
+ error: null,
+ ensureLoaded: vi.fn(async () => undefined),
+ }),
+}))
+
vi.mock('@hooks/domain/useTeamsDataController', () => ({
useTeamsDataController: () => ({
teams: [],
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
index d922bac18..f1bee87e7 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
@@ -4,11 +4,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
import { AuthContext, type AuthContextValue } from '@contexts/AuthContext'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { act, cleanup, render, screen, waitFor } from '@testing-library/react'
-import {
- describeGfsBrowserFailure,
- isGfsSessionAuthorityFailure,
- useGfsBrowserController,
-} from '../useGfsBrowserController'
+import { useGfsBrowserController } from '../useGfsBrowserController'
const userA = {
id: 'user-a',
@@ -26,14 +22,7 @@ const userB = {
teamName: 'Team B',
}
-const userC = {
- ...userA,
- id: 'user-c',
- email: '[email protected]',
- name: 'User C',
-}
-
-function authValue(me: AuthContextValue['me'], envKey = 'env-a'): AuthContextValue {
+function authValue(me: AuthContextValue['me']): AuthContextValue {
return {
booting: false,
busy: false,
@@ -49,15 +38,7 @@ function authValue(me: AuthContextValue['me'], envKey = 'env-a'): AuthContextVal
runtimeConfigSetupExternalRestApiBaseUrl: '',
runtimeConfigSetupRpcProxyBaseUrl: '',
authTransitioning: false,
- runtimeConfigState: {
- configured: true,
- isLocalhost: false,
- selectorVisible: false,
- activeOptionId: envKey,
- envKey,
- storagePath: `/tmp/${envKey}`,
- options: [],
- },
+ runtimeConfigState: null,
runtimeConfigMissing: false,
showRuntimeConfigSelector: false,
dependencyHealth: null,
@@ -81,21 +62,17 @@ function authValue(me: AuthContextValue['me'], envKey = 'env-a'): AuthContextVal
}
}
-function Probe({ grantsListEnabled = false }: { grantsListEnabled?: boolean }) {
- const ctrl = useGfsBrowserController({ grantsListEnabled })
+function Probe() {
+ const ctrl = useGfsBrowserController()
return (
<>
<div data-testid="current">{ctrl.current?.resourceId ?? 'none'}</div>
<div data-testid="current-name">{ctrl.current?.name ?? 'none'}</div>
<div data-testid="current-version">{ctrl.current?.version ?? 'none'}</div>
<div data-testid="crumbs">{ctrl.crumbs.map(crumb => crumb.name).join(' / ')}</div>
- <div data-testid="view">{ctrl.view}</div>
- <div data-testid="access-state">{ctrl.accessState}</div>
- <div data-testid="operator-root">{ctrl.isOperatorRoot ? 'yes' : 'no'}</div>
<div data-testid="accessible-count">{ctrl.accessibleResources.length}</div>
<div data-testid="accessible-error">{ctrl.accessibleError ?? 'none'}</div>
<div data-testid="accessible-notice">{ctrl.accessibleNotice ?? 'none'}</div>
- <div data-testid="open-error">{ctrl.openError ?? 'none'}</div>
<div data-testid="held-permissions">{ctrl.affordances?.held.join(',') ?? 'none'}</div>
{ctrl.accessibleResources.map(resource => (
<button key={resource.resourceId} type="button" onClick={() => ctrl.openResource(resource)}>
@@ -113,20 +90,11 @@ function Probe({ grantsListEnabled = false }: { grantsListEnabled?: boolean }) {
<button type="button" onClick={() => void ctrl.refreshAffordances()}>
refresh permissions
</button>
- <button type="button" onClick={() => ctrl.reset()}>
- reset browser
- </button>
- <button type="button" onClick={() => ctrl.retryAccess()}>
- retry access
- </button>
- <button type="button" onClick={() => void ctrl.createFolder('Root docs')}>
- create folder current
- </button>
<button
type="button"
onClick={() =>
ctrl.current
- ? void ctrl.createFile(ctrl.current.resourceId, 'notes.md', 'notes.md')
+ ? void ctrl.createFile(ctrl.current.resourceId, 'notes.md', 'IyBOb3Rlcw==')
: undefined
}
>
@@ -150,7 +118,7 @@ function Probe({ grantsListEnabled = false }: { grantsListEnabled?: boolean }) {
type="button"
onClick={() =>
ctrl.current
- ? void ctrl.replaceFile(ctrl.current.resourceId, 'replacement.md', ctrl.current.version)
+ ? void ctrl.replaceFile(ctrl.current.resourceId, 'aGVsbG8=', ctrl.current.version)
: undefined
}
>
@@ -160,304 +128,30 @@ function Probe({ grantsListEnabled = false }: { grantsListEnabled?: boolean }) {
)
}
-function UploadProbe() {
- const ctrl = useGfsBrowserController()
- return (
- <>
- <div data-testid="upload-state">{ctrl.uploadSnapshot?.state ?? 'none'}</div>
- <button
- type="button"
- onClick={() =>
- void ctrl.startFileUpload({
- parentResourceId: 'parent-rid',
- name: 'legacy.bin',
- filePath: '/tmp/legacy.bin',
- })
- }
- >
- start upload
- </button>
- </>
- )
-}
-
-function Harness({ children, queryClient }: { children: ReactNode; queryClient?: QueryClient }) {
+function Harness({ children }: { children: ReactNode }) {
const [me, setMe] = useState<AuthContextValue['me']>(userA)
- const [envKey, setEnvKey] = useState('env-a')
const [client] = useState(
- () => queryClient ?? new QueryClient({ defaultOptions: { queries: { retry: false } } })
+ () => new QueryClient({ defaultOptions: { queries: { retry: false } } })
)
return (
- <AuthContext.Provider value={authValue(me, envKey)}>
+ <AuthContext.Provider value={authValue(me)}>
<QueryClientProvider client={client}>
{children}
<button type="button" onClick={() => setMe(userB)}>
switch team
</button>
- <button type="button" onClick={() => setMe(userC)}>
- switch user
- </button>
- <button type="button" onClick={() => setEnvKey('env-b')}>
- switch environment
- </button>
- <button type="button" onClick={() => setMe(null)}>
- sign out
- </button>
</QueryClientProvider>
</AuthContext.Provider>
)
}
-function MountingProbe() {
- const [mounted, setMounted] = useState(true)
- return (
- <>
- {mounted ? <Probe /> : null}
- <button type="button" onClick={() => setMounted(value => !value)}>
- toggle files
- </button>
- </>
- )
-}
-
describe('useGfsBrowserController', () => {
afterEach(() => {
cleanup()
vi.restoreAllMocks()
})
- it.each([
- ['403 Forbidden: manage_acl_required', false],
- ['403 Forbidden: escalation_rejected', false],
- ['403 Forbidden: foreign_agent_forbidden', false],
- ['403 Forbidden: operator_link_inactive', true],
- ['401 Unauthorized', true],
- ] as const)(
- 'distinguishes resource policy verdicts from session authority (%s)',
- (message, expected) => {
- expect(isGfsSessionAuthorityFailure(message, 'operation')).toBe(expected)
- }
- )
-
- it('prioritizes an authorization verdict over generic initialization wording', () => {
- expect(describeGfsBrowserFailure('403 Forbidden: drive not initialized').kind).toBe(
- 'unauthorized'
- )
- })
-
- it.each(['switch team', 'switch user', 'sign out'])(
- 'resets visible GFS state after %s changes the authenticated scope',
- async action => {
- Object.defineProperty(window, 'clerum', {
- configurable: true,
- value: {
- gfs: {
- listAccessible: vi.fn(async () => ({
- items: [],
- nextCursor: null,
- })),
- resolve: vi.fn(async () => ({
- resourceId: 'root',
- gfsUri: 'gfs://main/root',
- name: 'Root',
- kind: 'directory',
- })),
- listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
- affordances: vi.fn(async () => ({
- held: [],
- canDelegate: false,
- grantableBits: [],
- canCreateShare: false,
- })),
- },
- },
- })
-
- render(<Probe />, { wrapper: Harness })
-
- await act(async () => {
- screen.getByRole('button', { name: 'open' }).click()
- })
- await waitFor(() => expect(screen.getByTestId('current').textContent).toBe('root'))
-
- await act(async () => {
- screen.getByRole('button', { name: action }).click()
- })
-
- await waitFor(() => expect(screen.getByTestId('current').textContent).toBe('none'))
- }
- )
-
- it('initializes the linked operator at the real root and uses it for root mutations', async () => {
- const rootResourceId = '11111111-1111-1111-1111-111111111111'
- const child = {
- resourceId: '22222222-2222-2222-2222-222222222222',
- rid: '22222222222222222222222222222222',
- gfsUri: 'gfs://main/22222222222222222222222222222222',
- drive: 'main',
- parentResourceId: rootResourceId,
- name: 'Projects',
- kind: 'directory' as const,
- path: '/Projects',
- version: 1,
- bytes: 0,
- sources: [],
- permissions: ['read', 'write'],
- coversDescendants: false,
- }
- const listChildren = vi.fn(async () => ({ items: [], nextCursor: null }))
- const createFolder = vi.fn(async () => child)
- Object.defineProperty(window, 'clerum', {
- configurable: true,
- value: {
- gfs: {
- listAccessible: vi.fn(async () => ({
- items: [child],
- nextCursor: null,
- rootResourceId,
- view: 'operator' as const,
- })),
- resolve: vi.fn(),
- listChildren,
- affordances: vi.fn(async () => ({
- held: ['read', 'write', 'delete', 'manage_acl', 'share'],
- canDelegate: true,
- grantableBits: ['read', 'write', 'delete', 'manage_acl', 'share'],
- canCreateShare: true,
- })),
- createFolder,
- },
- },
- })
-
- render(<Probe />, { wrapper: Harness })
-
- await waitFor(() => expect(screen.getByTestId('current').textContent).toBe(rootResourceId))
- expect(screen.getByTestId('view').textContent).toBe('operator')
- expect(screen.getByTestId('operator-root').textContent).toBe('yes')
- expect(screen.getByTestId('crumbs').textContent).toBe('Global File System')
- expect(screen.getByTestId('accessible-count').textContent).toBe('1')
- expect(listChildren).not.toHaveBeenCalled()
-
- await act(async () => {
- screen.getByRole('button', { name: 'create folder current' }).click()
- })
- await waitFor(() =>
- expect(createFolder).toHaveBeenCalledWith(rootResourceId, 'Root docs', 'main')
- )
-
- await act(async () => {
- screen.getByRole('button', { name: 'open Projects' }).click()
- })
- await waitFor(() => expect(screen.getByTestId('current').textContent).toBe(child.resourceId))
- expect(screen.getByTestId('crumbs').textContent).toBe('Global File System / Projects')
- await waitFor(() =>
- expect(listChildren).toHaveBeenCalledWith(child.resourceId, 'main', undefined)
- )
-
- await act(async () => {
- screen.getByRole('button', { name: 'create folder current' }).click()
- })
- await waitFor(() =>
- expect(createFolder).toHaveBeenLastCalledWith(child.resourceId, 'Root docs', 'main')
- )
-
- await act(async () => {
- screen.getByRole('button', { name: 'reset browser' }).click()
- })
- await waitFor(() => expect(screen.getByTestId('current').textContent).toBe(rootResourceId))
- })
-
- it('replaces cached operator-root state when the environment changes', async () => {
- const roots = ['11111111-1111-1111-1111-111111111111', '22222222-2222-2222-2222-222222222222']
- let call = 0
- Object.defineProperty(window, 'clerum', {
- configurable: true,
- value: {
- gfs: {
- listAccessible: vi.fn(async () => ({
- items: [],
- nextCursor: null,
- rootResourceId: roots[Math.min(call++, roots.length - 1)],
- view: 'operator' as const,
- })),
- resolve: vi.fn(),
- listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
- affordances: vi.fn(async () => ({
- held: ['read'],
- canDelegate: false,
- grantableBits: [],
- canCreateShare: false,
- })),
- },
- },
- })
-
- render(<Probe />, { wrapper: Harness })
- await waitFor(() => expect(screen.getByTestId('current').textContent).toBe(roots[0]))
-
- await act(async () => {
- screen.getByRole('button', { name: 'switch environment' }).click()
- })
-
- await waitFor(() => expect(screen.getByTestId('current').textContent).toBe(roots[1]))
- expect(screen.getByTestId('crumbs').textContent).toBe('Global File System')
- })
-
- it('clears operator-root state when the next authenticated scope is an ordinary user', async () => {
- const rootResourceId = '11111111-1111-1111-1111-111111111111'
- const ordinaryResource = {
- resourceId: '33333333-3333-4333-8333-333333333333',
- rid: '33333333333343338333333333333333',
- gfsUri: 'gfs://main/33333333333343338333333333333333',
- drive: 'main',
- parentResourceId: null,
- name: 'Shared report.md',
- kind: 'file' as const,
- path: '/Shared report.md',
- version: 1,
- bytes: 12,
- sources: ['share'],
- permissions: ['read'],
- coversDescendants: false,
- }
- let call = 0
- Object.defineProperty(window, 'clerum', {
- configurable: true,
- value: {
- gfs: {
- listAccessible: vi.fn(async () =>
- call++ === 0
- ? { items: [], nextCursor: null, rootResourceId, view: 'operator' as const }
- : { items: [ordinaryResource], nextCursor: null }
- ),
- resolve: vi.fn(),
- listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
- affordances: vi.fn(async () => ({
- held: ['read'],
- canDelegate: false,
- grantableBits: [],
- canCreateShare: false,
- })),
- },
- },
- })
-
- render(<Probe />, { wrapper: Harness })
- await waitFor(() => expect(screen.getByTestId('operator-root').textContent).toBe('yes'))
-
- await act(async () => {
- screen.getByRole('button', { name: 'switch team' }).click()
- })
-
- await waitFor(() => expect(screen.getByTestId('view').textContent).toBe('shared'))
- expect(screen.getByTestId('operator-root').textContent).toBe('no')
- expect(screen.getByTestId('current').textContent).toBe('none')
- expect(screen.getByTestId('crumbs').textContent).toBe('')
- expect(screen.getByTestId('accessible-count').textContent).toBe('1')
- })
-
- it('fails closed when operator mode omits a valid rootResourceId', async () => {
+ it('resets visible GFS state when the authenticated session scope changes', async () => {
Object.defineProperty(window, 'clerum', {
configurable: true,
value: {
@@ -465,186 +159,16 @@ describe('useGfsBrowserController', () => {
listAccessible: vi.fn(async () => ({
items: [],
nextCursor: null,
- view: 'operator' as const,
- })),
- resolve: vi.fn(),
- listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
- affordances: vi.fn(),
- },
- },
- })
-
- render(<Probe />, { wrapper: Harness })
-
- await waitFor(() =>
- expect(screen.getByTestId('accessible-error').textContent).toContain('operator_root_missing')
- )
- expect(screen.getByTestId('current').textContent).toBe('none')
- })
-
- it('downgrades a revoked operator link to ordinary user scope through fresh discovery', async () => {
- const rootResourceId = '11111111-1111-1111-1111-111111111111'
- const ordinaryResource = {
- resourceId: '33333333-3333-4333-8333-333333333333',
- rid: '33333333333343338333333333333333',
- gfsUri: 'gfs://main/33333333333343338333333333333333',
- name: 'Shared report.md',
- kind: 'file' as const,
- path: '/Shared report.md',
- version: 1,
- bytes: 12,
- permissions: ['read'],
- }
- let state: 'operator' | 'revoking' | 'ordinary' = 'operator'
- const listAccessible = vi.fn(async () => {
- if (state === 'revoking') {
- state = 'ordinary'
- throw new Error('403 operator_link_inactive')
- }
- if (state === 'ordinary') return { items: [ordinaryResource], nextCursor: null }
- return { items: [], nextCursor: null, rootResourceId, view: 'operator' as const }
- })
- Object.defineProperty(window, 'clerum', {
- configurable: true,
- value: {
- gfs: {
- listAccessible,
- resolve: vi.fn(),
- listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
- affordances: vi.fn(async () => ({
- held: ['read', 'write'],
- canDelegate: true,
- grantableBits: ['read', 'write'],
- canCreateShare: true,
})),
- },
- },
- })
-
- render(<Probe />, { wrapper: Harness })
- await waitFor(() => expect(screen.getByTestId('operator-root').textContent).toBe('yes'))
-
- state = 'revoking'
- await act(async () => {
- screen.getByRole('button', { name: 'reset browser' }).click()
- })
- await waitFor(() => expect(screen.getByTestId('access-state').textContent).toBe('active'))
- await waitFor(() => expect(screen.getByTestId('view').textContent).toBe('shared'))
- expect(screen.getByTestId('current').textContent).toBe('none')
- await waitFor(() => expect(screen.getByTestId('accessible-count').textContent).toBe('1'))
- expect(screen.getByTestId('operator-root').textContent).toBe('no')
- expect(listAccessible).toHaveBeenCalledTimes(3)
- })
-
- it('fails closed after a second lifecycle denial instead of retrying forever', async () => {
- const rootResourceId = '11111111-1111-1111-1111-111111111111'
- let deny = false
- const listAccessible = vi.fn(async () => {
- if (deny) throw new Error('403 operator_link_inactive')
- return { items: [], nextCursor: null, rootResourceId, view: 'operator' as const }
- })
- Object.defineProperty(window, 'clerum', {
- configurable: true,
- value: {
- gfs: {
- listAccessible,
- resolve: vi.fn(),
- listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
- affordances: vi.fn(async () => ({
- held: ['read'],
- canDelegate: false,
- grantableBits: [],
- canCreateShare: false,
- })),
- },
- },
- })
-
- render(<Probe />, { wrapper: Harness })
- await waitFor(() => expect(screen.getByTestId('operator-root').textContent).toBe('yes'))
-
- deny = true
- await act(async () => {
- screen.getByRole('button', { name: 'reset browser' }).click()
- })
-
- await waitFor(() => expect(screen.getByTestId('access-state').textContent).toBe('revoked'))
- expect(listAccessible).toHaveBeenCalledTimes(3)
- })
-
- it('keeps the browser session active when ACL listing is denied by resource policy', async () => {
- const rootResourceId = '11111111-1111-1111-1111-111111111111'
- const listGrants = vi.fn(async () => {
- throw new Error('403 Forbidden: manage_acl_required')
- })
- Object.defineProperty(window, 'clerum', {
- configurable: true,
- value: {
- gfs: {
- listAccessible: vi.fn(async () => ({
- items: [],
- nextCursor: null,
- rootResourceId,
- view: 'operator' as const,
+ resolve: vi.fn(async () => ({
+ resourceId: 'root',
+ gfsUri: 'gfs://main/root',
+ name: 'Root',
+ kind: 'directory',
})),
- resolve: vi.fn(),
listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
affordances: vi.fn(async () => ({
- held: ['read'],
- canDelegate: false,
- grantableBits: [],
- canCreateShare: false,
- })),
- listGrants,
- listShares: vi.fn(async () => []),
- },
- },
- })
-
- const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
- const removeQueries = vi.spyOn(queryClient, 'removeQueries')
- render(<Probe grantsListEnabled />, {
- wrapper: ({ children }) => <Harness queryClient={queryClient}>{children}</Harness>,
- })
- await waitFor(() => expect(screen.getByTestId('operator-root').textContent).toBe('yes'))
- await waitFor(() => expect(listGrants).toHaveBeenCalled())
- await act(async () => {
- await Promise.resolve()
- await Promise.resolve()
- })
- expect(removeQueries).not.toHaveBeenCalled()
- expect(screen.getByTestId('access-state').textContent).toBe('active')
- expect(screen.getByTestId('current').textContent).toBe(rootResourceId)
- })
-
- it('keeps the browser session active when a resource children listing returns a generic 403', async () => {
- const resource = {
- resourceId: 'shared-folder',
- rid: 'sharedfolder',
- gfsUri: 'gfs://main/sharedfolder',
- drive: 'main',
- parentResourceId: null,
- name: 'Shared folder',
- kind: 'directory' as const,
- path: '/Shared folder',
- version: 1,
- bytes: 0,
- sources: ['grant'],
- permissions: ['read'],
- coversDescendants: true,
- }
- const listChildren = vi.fn(async () => {
- throw new Error('403 Forbidden')
- })
- Object.defineProperty(window, 'clerum', {
- configurable: true,
- value: {
- gfs: {
- listAccessible: vi.fn(async () => ({ items: [resource], nextCursor: null })),
- resolve: vi.fn(),
- listChildren,
- affordances: vi.fn(async () => ({
- held: ['read'],
+ held: [],
canDelegate: false,
grantableBits: [],
canCreateShare: false,
@@ -654,161 +178,17 @@ describe('useGfsBrowserController', () => {
})
render(<Probe />, { wrapper: Harness })
- await waitFor(() =>
- expect(screen.getByRole('button', { name: 'open Shared folder' })).toBeTruthy()
- )
-
- await act(async () => {
- screen.getByRole('button', { name: 'open Shared folder' }).click()
- })
-
- await waitFor(() =>
- expect(listChildren).toHaveBeenCalledWith('shared-folder', 'main', undefined)
- )
- expect(screen.getByTestId('access-state').textContent).toBe('active')
- expect(screen.getByTestId('current').textContent).toBe('shared-folder')
- })
-
- it.each([
- ['403 Forbidden: resource policy denied', '403 Forbidden: resource policy denied'],
- ['401 Unauthorized', '401 Unauthorized'],
- ] as const)('keeps the URI operation scoped for %s', async (_label, message) => {
- const resolve = vi.fn(async () => {
- throw new Error(message)
- })
- Object.defineProperty(window, 'clerum', {
- configurable: true,
- value: {
- gfs: {
- listAccessible: vi.fn(async () => ({ items: [], nextCursor: null })),
- resolve,
- listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
- affordances: vi.fn(async () => ({
- held: ['read'],
- canDelegate: false,
- grantableBits: [],
- canCreateShare: false,
- })),
- },
- },
- })
- render(<Probe />, { wrapper: Harness })
await act(async () => {
screen.getByRole('button', { name: 'open' }).click()
})
- await waitFor(() => expect(resolve).toHaveBeenCalledWith('gfs://main/root'))
-
- expect(screen.getByTestId('access-state').textContent).toBe(
- message.startsWith('401') ? 'revoked' : 'active'
- )
- expect(screen.getByTestId('open-error').textContent).toBe(
- message.startsWith('401') ? 'none' : message
- )
- })
-
- it('finishes a completed legacy receipt without polling it as a v2 session', async () => {
- const startFileUpload = vi.fn(async () => ({
- uploadId: 'legacy-resource-id',
- drive: 'main',
- operation: 'create' as const,
- expectedBytes: 12,
- partBytes: 12,
- partCount: 1,
- state: 'completed',
- contiguousBytes: 12,
- committedBytes: 12,
- committedPartCount: 1,
- activePartCount: 0,
- expiresAt: new Date().toISOString(),
- resultResourceId: 'legacy-resource-id',
- resultVersion: 1,
- }))
- const getUploadSnapshot = vi.fn()
- Object.defineProperty(window, 'clerum', {
- configurable: true,
- value: {
- gfs: {
- listAccessible: vi.fn(async () => ({ items: [], nextCursor: null })),
- startFileUpload,
- getUploadSnapshot,
- },
- },
- })
+ await waitFor(() => expect(screen.getByTestId('current').textContent).toBe('root'))
- render(<UploadProbe />, { wrapper: Harness })
await act(async () => {
- screen.getByRole('button', { name: 'start upload' }).click()
- })
-
- await waitFor(() => expect(screen.getByTestId('upload-state').textContent).toBe('completed'))
- expect(startFileUpload).toHaveBeenCalledWith(
- 'parent-rid',
- 'legacy.bin',
- '/tmp/legacy.bin',
- 'main',
- undefined
- )
- expect(getUploadSnapshot).not.toHaveBeenCalled()
- })
-
- it('rehydrates a scoped persisted upload after the renderer mounts', async () => {
- const listUploadSessions = vi.fn(async () => [
- {
- uploadId: 'terminal-upload',
- fileName: 'done.bin',
- fileSize: 12,
- name: 'done.bin',
- drive: 'main',
- status: 'failed' as const,
- target: { operation: 'create' as const, parentRid: 'parent-rid' },
- },
- {
- uploadId: 'persisted-upload',
- fileName: 'resume.bin',
- fileSize: 12,
- name: 'resume.bin',
- drive: 'main',
- status: 'suspended_auth' as const,
- target: { operation: 'create' as const, parentRid: 'parent-rid' },
- },
- ])
- const getUploadSnapshot = vi.fn(async () => ({
- state: 'suspended_auth' as const,
- session: {
- uploadId: 'persisted-upload',
- state: 'paused',
- expectedBytes: 12,
- committedBytes: 8,
- },
- uploadedBytes: 8,
- totalBytes: 12,
- }))
- Object.defineProperty(window, 'clerum', {
- configurable: true,
- value: {
- gfs: {
- listUploadSessions,
- getUploadSnapshot,
- listAccessible: vi.fn(async () => ({ items: [], nextCursor: null })),
- listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
- affordances: vi.fn(async () => ({
- held: [],
- canDelegate: false,
- grantableBits: [],
- canCreateShare: false,
- })),
- },
- },
+ screen.getByRole('button', { name: 'switch team' }).click()
})
- render(<UploadProbe />, { wrapper: Harness })
-
- await waitFor(() =>
- expect(screen.getByTestId('upload-state').textContent).toBe('suspended_auth')
- )
- expect(listUploadSessions).toHaveBeenCalledWith('main')
- expect(getUploadSnapshot).toHaveBeenCalledWith('persisted-upload', 'main')
+ await waitFor(() => expect(screen.getByTestId('current').textContent).toBe('none'))
})
it('refreshes cached affordances after permissions change outside Desktop', async () => {
@@ -863,7 +243,7 @@ describe('useGfsBrowserController', () => {
grantableBits: [],
canCreateShare: false,
}))
- const createFileFromPath = vi.fn(async () => undefined)
+ const createFile = vi.fn(async () => undefined)
Object.defineProperty(window, 'clerum', {
configurable: true,
value: {
@@ -877,7 +257,7 @@ describe('useGfsBrowserController', () => {
})),
listChildren,
affordances,
- createFileFromPath,
+ createFile,
},
},
})
@@ -894,7 +274,7 @@ describe('useGfsBrowserController', () => {
})
await waitFor(() =>
- expect(createFileFromPath).toHaveBeenCalledWith('root', 'notes.md', 'notes.md', 'main')
+ expect(createFile).toHaveBeenCalledWith('root', 'notes.md', 'IyBOb3Rlcw==', 'main')
)
await waitFor(() => expect(listChildren).toHaveBeenCalledTimes(2))
expect(affordances).toHaveBeenCalledTimes(1)
@@ -963,62 +343,6 @@ describe('useGfsBrowserController', () => {
await waitFor(() => expect(screen.getByTestId('current').textContent).toBe('team-folder'))
})
- it('refetches permission-derived resources when Files remounts', async () => {
- const resource = {
- resourceId: 'revoked-folder',
- rid: 'revokedfolder',
- gfsUri: 'gfs://main/revokedfolder',
- drive: 'main',
- parentResourceId: null,
- name: 'Revoked folder',
- kind: 'directory' as const,
- path: '/revoked-folder',
- version: 1,
- bytes: 0,
- sources: ['grant'],
- permissions: ['read'],
- coversDescendants: false,
- }
- let resources = [resource]
- const listAccessible = vi.fn(async () => ({ items: resources, nextCursor: null }))
- Object.defineProperty(window, 'clerum', {
- configurable: true,
- value: {
- gfs: {
- listAccessible,
- resolve: vi.fn(),
- listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
- affordances: vi.fn(async () => ({
- held: [],
- canDelegate: false,
- grantableBits: [],
- canCreateShare: false,
- })),
- },
- },
- })
-
- const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
- render(<MountingProbe />, {
- wrapper: ({ children }) => <Harness queryClient={queryClient}>{children}</Harness>,
- })
-
- await waitFor(() => expect(screen.getByTestId('accessible-count').textContent).toBe('1'))
- resources = []
-
- await act(async () => {
- screen.getByRole('button', { name: 'toggle files' }).click()
- })
- expect(screen.queryByTestId('accessible-count')).toBeNull()
-
- await act(async () => {
- screen.getByRole('button', { name: 'toggle files' }).click()
- })
-
- await waitFor(() => expect(screen.getByTestId('accessible-count').textContent).toBe('0'))
- expect(listAccessible).toHaveBeenCalledTimes(2)
- })
-
it('hydrates readable parent folders for a directly opened file', async () => {
const rootId = '00000000-0000-0000-0000-000000000001'
const projectsId = '00000000-0000-0000-0000-000000000002'
@@ -1143,7 +467,7 @@ describe('useGfsBrowserController', () => {
canCreateShare: false,
})),
renameResource: vi.fn(async () => ({ resourceId: 'file-1', version: 2 })),
- replaceFileFromPath: vi.fn(async () => ({
+ replaceFile: vi.fn(async () => ({
...fileResource,
name: 'Renamed report.md',
version: 3,
@@ -1248,29 +572,6 @@ describe('useGfsBrowserController', () => {
expect(screen.getByTestId('accessible-error').textContent).toBe('none')
expect(screen.getByTestId('accessible-count').textContent).toBe('0')
})
-
- it('keeps an unseeded drive distinct from the older-server 404 notice', async () => {
- Object.defineProperty(window, 'clerum', {
- configurable: true,
- value: {
- gfs: {
- listAccessible: vi.fn(async () => {
- throw new Error('404 Not Found: drive_not_seeded')
- }),
- resolve: vi.fn(),
- listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
- affordances: vi.fn(),
- },
- },
- })
-
- render(<Probe />, { wrapper: Harness })
-
- await waitFor(() =>
- expect(screen.getByTestId('accessible-error').textContent).toContain('drive_not_seeded')
- )
- expect(screen.getByTestId('accessible-notice').textContent).toBe('none')
- })
})
// The grants listing is gated by the `grantsListEnabled` hook option (the Manage
@@ -1286,7 +587,6 @@ function ManageProbe() {
<>
<div data-testid="current">{ctrl.current?.resourceId ?? 'none'}</div>
<div data-testid="grants-count">{ctrl.grants.length}</div>
- <div data-testid="shares-count">{ctrl.shares.length}</div>
<button type="button" onClick={() => void ctrl.openUri('gfs://main/root')}>
open root
</button>
@@ -1302,9 +602,6 @@ function ManageProbe() {
<button type="button" onClick={() => void ctrl.revokeGrant('grant-42')}>
revoke grant
</button>
- <button type="button" onClick={() => void ctrl.revokeShare('share-42')}>
- revoke share
- </button>
<button type="button" onClick={() => void ctrl.grant(['user:bob'], ['read'], true)}>
grant inherit true
</button>
@@ -1338,7 +635,6 @@ describe('useGfsBrowserController — grants list / revoke / inherit (#826)', ()
inherit: false,
},
])
- const listShares = vi.fn(async () => [])
Object.defineProperty(window, 'clerum', {
configurable: true,
value: {
@@ -1353,7 +649,6 @@ describe('useGfsBrowserController — grants list / revoke / inherit (#826)', ()
listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
affordances,
listGrants,
- listShares,
},
},
})
@@ -1368,20 +663,17 @@ describe('useGfsBrowserController — grants list / revoke / inherit (#826)', ()
// fired by now — but Manage is closed, so the grants list must stay dormant.
await waitFor(() => expect(affordances).toHaveBeenCalled())
expect(listGrants).not.toHaveBeenCalled()
- expect(listShares).not.toHaveBeenCalled()
await act(async () => {
screen.getByRole('button', { name: 'open manage' }).click()
})
await waitFor(() => expect(listGrants).toHaveBeenCalledTimes(1))
- await waitFor(() => expect(listShares).toHaveBeenCalledTimes(1))
expect(listGrants).toHaveBeenCalledWith('root', 'main')
await waitFor(() => expect(screen.getByTestId('grants-count').textContent).toBe('1'))
})
it('refetches the grants list when refreshGrants runs', async () => {
const listGrants = vi.fn(async () => [])
- const listShares = vi.fn(async () => [])
Object.defineProperty(window, 'clerum', {
configurable: true,
value: {
@@ -1401,7 +693,6 @@ describe('useGfsBrowserController — grants list / revoke / inherit (#826)', ()
canCreateShare: false,
})),
listGrants,
- listShares,
},
},
})
@@ -1436,7 +727,6 @@ describe('useGfsBrowserController — grants list / revoke / inherit (#826)', ()
inherit: false,
},
])
- const listShares = vi.fn(async () => [])
Object.defineProperty(window, 'clerum', {
configurable: true,
value: {
@@ -1456,7 +746,6 @@ describe('useGfsBrowserController — grants list / revoke / inherit (#826)', ()
canCreateShare: false,
})),
listGrants,
- listShares,
revokeGrant,
},
},
@@ -1482,63 +771,6 @@ describe('useGfsBrowserController — grants list / revoke / inherit (#826)', ()
await waitFor(() => expect(listGrants).toHaveBeenCalledTimes(2))
})
- it('lists and revokes a share by id, then refetches only the share list', async () => {
- const listGrants = vi.fn(async () => [])
- const listShares = vi.fn(async () => [
- {
- id: 'share-42',
- drive: 'main',
- resourceId: 'root',
- subject: { type: 'team', id: 'qa' },
- permissions: ['read'],
- includeDescendants: true,
- },
- ])
- const revokeShare = vi.fn(async () => undefined)
- Object.defineProperty(window, 'clerum', {
- configurable: true,
- value: {
- gfs: {
- listAccessible: vi.fn(async () => ({ items: [], nextCursor: null })),
- resolve: vi.fn(async () => ({
- resourceId: 'root',
- gfsUri: 'gfs://main/root',
- name: 'Root',
- kind: 'directory',
- })),
- listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
- affordances: vi.fn(async () => ({
- held: ['read', 'manage_acl', 'share'],
- canDelegate: true,
- grantableBits: ['read'],
- canCreateShare: true,
- })),
- listGrants,
- listShares,
- revokeShare,
- },
- },
- })
-
- render(<ManageProbe />, { wrapper: Harness })
- await act(async () => {
- screen.getByRole('button', { name: 'open root' }).click()
- })
- await waitFor(() => expect(screen.getByTestId('current').textContent).toBe('root'))
- await act(async () => {
- screen.getByRole('button', { name: 'open manage' }).click()
- })
- await waitFor(() => expect(screen.getByTestId('shares-count').textContent).toBe('1'))
-
- await act(async () => {
- screen.getByRole('button', { name: 'revoke share' }).click()
- })
-
- await waitFor(() => expect(revokeShare).toHaveBeenCalledWith('share-42'))
- await waitFor(() => expect(listShares).toHaveBeenCalledTimes(2))
- expect(listGrants).toHaveBeenCalledTimes(1)
- })
-
it('forwards the inherit flag (true and false) to window.clerum.gfs.grant', async () => {
const grant = vi.fn(async () => undefined)
Object.defineProperty(window, 'clerum', {
diff --git a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
index 610ee2ea3..cee86594e 100644
--- a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
+++ b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
@@ -42,6 +42,21 @@ interface GfsAccessibleResource extends GfsBrowserChild {
coversDescendants: boolean
}
+type GfsAccessibleWirePage = Awaited<ReturnType<typeof window.clerum.gfs.listAccessible>>
+
+function normalizeAccessibleResource(
+ item: GfsAccessibleWirePage['items'][number]
+): GfsAccessibleResource {
+ return {
+ ...item,
+ drive: item.drive ?? 'main',
+ parentResourceId: item.parentResourceId ?? null,
+ sources: item.sources ?? [],
+ permissions: item.permissions ?? [],
+ coversDescendants: item.coversDescendants ?? false,
+ }
+}
+
export interface GfsCrumb {
resourceId: string
gfsUri: string
@@ -112,10 +127,10 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
const accessibleQuery = useInfiniteQuery({
queryKey: desktopQueryKeys.gfsAccessible(sessionScope ?? 'anonymous', DRIVE),
- queryFn: ({ pageParam }) => {
+ queryFn: async ({ pageParam }): Promise<GfsAccessibleWirePage> => {
const listAccessible = window.clerum?.gfs?.listAccessible
if (typeof listAccessible !== 'function') {
- return Promise.resolve({ items: [], nextCursor: null })
+ return { items: [], nextCursor: null }
}
return listAccessible(DRIVE, pageParam)
},
@@ -254,7 +269,10 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
[childrenQuery.data]
)
const accessibleResources = useMemo<GfsAccessibleResource[]>(
- () => (accessibleQuery.data?.pages ?? []).flatMap(page => page.items),
+ () =>
+ (accessibleQuery.data?.pages ?? []).flatMap(page =>
+ page.items.map(normalizeAccessibleResource)
+ ),
[accessibleQuery.data]
)
const grants = useMemo<GfsGrantListItem[]>(() => grantsQuery.data ?? [], [grantsQuery.data])
diff --git a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
index c0b0b2189..1f987c5ea 100644
--- a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
+++ b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
@@ -494,7 +494,7 @@ describe('FilesPage', () => {
})
await waitFor(() =>
- expect(pushToast).toHaveBeenCalledWith('GFS uploads are limited to 16 MB per file.', 'error')
+ expect(pushToast).toHaveBeenCalledWith('GFS uploads are limited to 200 MB per file.', 'error')
)
expect(arrayBuffer).not.toHaveBeenCalled()
expect(createFile).not.toHaveBeenCalled()