Skip to content

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

TypeScript

test(desktop-app): consolidate app-controller clerum harness into shared fixture

Diego Zacarias5972c5df25f2
diff --git a/desktop-app/package-lock.json b/desktop-app/package-lock.json
index a86de9fcb..f344dc192 100644
--- a/desktop-app/package-lock.json
+++ b/desktop-app/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "evenfire",
- "version": "0.1.321",
+ "version": "0.1.322",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "evenfire",
- "version": "0.1.321",
+ "version": "0.1.322",
"license": "MPL-2.0",
"dependencies": {
"@tanstack/react-query": "5.100.10",
diff --git a/desktop-app/package.json b/desktop-app/package.json
index ce2450ae7..19b999f75 100644
--- a/desktop-app/package.json
+++ b/desktop-app/package.json
@@ -1,7 +1,7 @@
{
"name": "evenfire",
"productName": "Evenfire",
- "version": "0.1.321",
+ "version": "0.1.322",
"private": true,
"license": "MPL-2.0",
"description": "Evenfire desktop client for secure agent and workflow access",
diff --git a/desktop-app/ui/src/hooks/__tests__/useWorkspaceController.test.tsx b/desktop-app/ui/src/hooks/__tests__/useWorkspaceController.test.tsx
index 79629b57a..9df0a1a4b 100644
--- a/desktop-app/ui/src/hooks/__tests__/useWorkspaceController.test.tsx
+++ b/desktop-app/ui/src/hooks/__tests__/useWorkspaceController.test.tsx
@@ -5,221 +5,39 @@ import { AgentTaskTrackerProvider } from '@contexts/AgentTaskTrackerContext'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
import { DEFAULT_TOAST_DURATION_MS } from '@constants/toasts'
+import {
+ type AppControllerClerumOptions,
+ installAppControllerClerum,
+} from '../domain/__tests__/__fixtures__/appControllerHarness'
+import { uninstallMockClerum } from '../domain/__tests__/__fixtures__/mockClerum'
import { useWorkspaceController } from '../useWorkspaceController'
-type Deferred<T> = {
- promise: Promise<T>
- resolve: (value: T) => void
+/**
+ * `useWorkspaceController` is a deprecated re-export of `useAppController`, so
+ * the `window.clerum` bridge these tests need is the same one
+ * `hooks/domain/__tests__/chatSelectionAcrossRouteChange` needs. It lives in the
+ * shared fixture; only the deltas this suite depends on are spelled out here.
+ */
+const OUTDATED_DESKTOP_RELEASE = {
+ checked: true,
+ currentVersion: '0.1.249',
+ latestVersion: '0.1.250',
+ minimumVersion: '0.1.250',
+ updateRequired: true,
+ releaseUrl: 'https://github.com/your-org/evenfire/releases/tag/desktop-app-0.1.250',
}
-type SessionState = {
- authenticated: boolean
- me: { id: string; email: string; name: string; teamId: string; teamName: string } | null
-}
-
-function createDeferred<T>(): Deferred<T> {
- let resolve!: (value: T) => void
- const promise = new Promise<T>(res => {
- resolve = res
- })
- return { promise, resolve }
-}
-
-function createCatalog() {
- return {
- userId: 'user-1',
- teamId: '',
+/**
+ * Boots at the login screen (these tests drive `handlePasswordLogin` themselves),
+ * with no agents in the access catalog and an update-required release status.
+ */
+function installClerumHarness(options: AppControllerClerumOptions = {}) {
+ return installAppControllerClerum({
+ startAuthenticated: false,
agentNames: [],
- userAgentNames: [],
- teamAgentNames: [],
- mcpServersByAgent: {},
- agentContextByName: {},
- contextIds: [],
- userContextIds: [],
- teamContextIds: [],
- }
-}
-
-function createHealth() {
- return {
- externalRestApi: { ok: true },
- rpcProxy: { ok: true },
- }
-}
-
-function createSessionState(authenticated: boolean): SessionState {
- return authenticated
- ? {
- authenticated: true,
- me: {
- id: 'user-1',
- email: '[email protected]',
- name: 'Test User',
- teamId: 'team-1',
- teamName: 'Test Team',
- },
- }
- : {
- authenticated: false,
- me: null,
- }
-}
-
-function installClerumHarness(
- options: { delayAuthenticatedLoad?: boolean; passwordLoginError?: unknown } = {}
-) {
- let authenticated = false
- const teamDirectoryDeferred = createDeferred<{ items: []; currentTeamId: string }>()
- const catalogDeferred = createDeferred<ReturnType<typeof createCatalog>>()
- const approvalsDeferred = createDeferred<[]>()
-
- const getSessionState = vi.fn(async () => createSessionState(authenticated))
- const passwordLogin = vi.fn(async () => {
- if (options.passwordLoginError) throw options.passwordLoginError
- authenticated = true
- return createSessionState(true)
- })
-
- const teamDirectory = vi.fn(async () =>
- options.delayAuthenticatedLoad && authenticated
- ? teamDirectoryDeferred.promise
- : { items: [], currentTeamId: '' }
- )
- const refreshCatalog = vi.fn(async () =>
- options.delayAuthenticatedLoad && authenticated ? catalogDeferred.promise : createCatalog()
- )
- const listPending = vi.fn(async () =>
- options.delayAuthenticatedLoad && authenticated ? approvalsDeferred.promise : []
- )
- const getDesktopReleaseStatus = vi.fn(async () => ({
- checked: true,
- currentVersion: '0.1.249',
- latestVersion: '0.1.250',
- minimumVersion: '0.1.250',
- updateRequired: true,
- releaseUrl: 'https://github.com/your-org/evenfire/releases/tag/desktop-app-0.1.250',
- }))
-
- Object.defineProperty(window, 'clerum', {
- configurable: true,
- writable: true,
- value: {
- auth: {
- getRuntimeConfigState: vi.fn(async () => ({
- activeProfileId: null,
- configured: false,
- isPackaged: false,
- options: [],
- })),
- getDependenciesHealth: vi.fn(async () => createHealth()),
- getSessionState,
- passwordLogin,
- onDesktopSetupToken: vi.fn(() => () => undefined),
- onDesktopEnvironmentSetup: vi.fn(() => () => undefined),
- onExternalLogout: vi.fn(() => () => undefined),
- getDesktopReleaseStatus,
- openDesktopRelease: vi.fn(async () => undefined),
- logout: vi.fn(async () => undefined),
- },
- team: {
- list: vi.fn(async () => ({ items: [], currentTeamId: '' })),
- members: vi.fn(async () => []),
- directory: teamDirectory,
- initialDirectory: teamDirectory,
- switch: vi.fn(async () => undefined),
- },
- access: {
- refreshCatalog,
- },
- notificationPreferences: {
- get: vi.fn(async () => ({
- preferredMedium: null,
- channelFallbackEnabled: true,
- verifiedMedia: [],
- })),
- update: vi.fn(async (next: unknown) => ({
- ...(next && typeof next === 'object' ? next : {}),
- verifiedMedia: [],
- })),
- },
- approvals: {
- listPending,
- decide: vi.fn(async () => ({ ok: true })),
- },
- notifications: {
- ack: vi.fn(async () => undefined),
- subscribe: vi.fn(async (onEvent: (event: unknown) => void) => {
- onEvent({
- type: 'notification.snapshot',
- items: [],
- cursor: null,
- observedAt: new Date().toISOString(),
- })
- return async () => undefined
- }),
- status: vi.fn(async () => ({
- active: 1,
- open: 1,
- connecting: 0,
- error: 0,
- approvalRequested: 0,
- snapshot: 1,
- updated: 0,
- })),
- isSupported: vi.fn(async () => false),
- show: vi.fn(async (payload: { id: string }) => ({ supported: false, id: payload.id })),
- onClick: vi.fn(() => () => undefined),
- onAction: vi.fn(() => () => undefined),
- onFailed: vi.fn(() => () => undefined),
- },
- rpc: {
- listServers: vi.fn(async () => ({ servers: [] })),
- subscribeHostStatus: vi.fn(async () => async () => undefined),
- approveToolCall: vi.fn(async () => undefined),
- denyToolCall: vi.fn(async () => undefined),
- cancelTask: vi.fn(async () => undefined),
- listSessions: vi.fn(async () => ({ items: [] })),
- loadSessionMessages: vi.fn(async () => ({ agent: '', chatId: '', turns: [] })),
- },
- chat: {
- list: vi.fn(async () => []),
- create: vi.fn(async (_agentRef: string, chatId: string) => ({
- id: chatId,
- title: 'New Chat',
- createdAt: new Date().toISOString(),
- updatedAt: new Date().toISOString(),
- })),
- rename: vi.fn(async () => undefined),
- delete: vi.fn(async () => undefined),
- loadMessages: vi.fn(async () => []),
- appendMessages: vi.fn(async () => undefined),
- getLastActive: vi.fn(async () => null),
- setLastActive: vi.fn(async () => undefined),
- getIndex: vi.fn(async () => ({ chats: [] })),
- },
- desktop: {
- onWindowClosed: vi.fn(() => () => undefined),
- getStatus: vi.fn(async () => ({ status: 'inactive' })),
- },
- workflows: {
- list: vi.fn(async () => ({ items: [], count: 0 })),
- runs: vi.fn(async () => ({ items: [] })),
- listRunArtifacts: vi.fn(async () => ({ artifacts: [] })),
- trigger: vi.fn(async () => undefined),
- },
- },
- })
-
- return {
- passwordLogin,
- getSessionState,
- getDesktopReleaseStatus,
- resolveAuthenticatedLoad() {
- teamDirectoryDeferred.resolve({ items: [], currentTeamId: '' })
- catalogDeferred.resolve(createCatalog())
- approvalsDeferred.resolve([])
- },
- }
+ desktopReleaseStatus: OUTDATED_DESKTOP_RELEASE,
+ ...options,
+ }).handle
}
function renderControllerHarness() {
@@ -287,7 +105,7 @@ describe('useWorkspaceController', () => {
afterEach(() => {
cleanup()
vi.restoreAllMocks()
- delete (window as { clerum?: unknown }).clerum
+ uninstallMockClerum()
})
it('preserves a workflow nav selection while login session hydration finishes', async () => {
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/appControllerHarness.tsx b/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/appControllerHarness.tsx
index 0ca0d3f59..08568c095 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/appControllerHarness.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/__fixtures__/appControllerHarness.tsx
@@ -4,25 +4,28 @@ import { AgentTaskTrackerProvider } from '@contexts/AgentTaskTrackerContext'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { renderHook } from '@testing-library/react'
import { useAppController } from '../../../useAppController'
-import type { MockClerum } from './mockClerum'
+import { type MockClerum, installMockClerum } from './mockClerum'
/**
- * Mounts the REAL coordinator (`useAppController`) instead of a single domain
- * controller, so tests can drive its cross-domain entry points
- * (`handleSelectChatAgent`, `handleOpenNotification` → `openAgentConversationTarget`)
- * and observe the navigation + chat controllers reacting to each other.
+ * The single `window.clerum` bridge for tests that boot the REAL coordinator
+ * (`useAppController`), plus a `renderHook` mount for the ones that drive it
+ * through its return value rather than through rendered UI.
+ *
+ * Two suites share it — `hooks/domain/__tests__/chatSelectionAcrossRouteChange`
+ * and `hooks/__tests__/useWorkspaceController` (whose hook is a deprecated
+ * re-export of `useAppController`, so both boot the same thing). It lives in this
+ * folder because the repo keeps ONE `__fixtures__` directory for the hooks tests
+ * and because it is built on top of `mockClerum` — splitting it away from its own
+ * base would cost more than the cross-folder import it saves.
*
* `controllerHarness.renderController` stays the right tool when a test only
* needs `useAgentChatController` — it drives `navItem` as a prop. The guards in
* `useAppController` read `nav.navItem` from the navigation controller it owns,
* which no prop can stand in for, hence this second harness.
*
- * The `window.clerum` surface here EXTENDS `installMockClerum()` (chat + rpc)
- * with the namespaces the coordinator touches on mount. It mirrors
- * `hooks/__tests__/useWorkspaceController.test.tsx`'s `installClerumHarness` —
- * the established way to boot the coordinator in a test — but keeps the chat/rpc
- * mocks from `mockClerum` so chat assertions read the same as in the rest of
- * this folder.
+ * The bridge EXTENDS `installMockClerum()` (chat + rpc) with the namespaces the
+ * coordinator touches on mount. Everything that differs between the two suites
+ * is an option — never a duplicated bridge.
*/
export const HARNESS_ME = {
@@ -33,6 +36,27 @@ export const HARNESS_ME = {
teamName: 'Team 1',
}
+type Fn = ReturnType<typeof vi.fn>
+
+interface Deferred<T> {
+ promise: Promise<T>
+ resolve: (value: T) => void
+}
+
+function createDeferred<T>(): Deferred<T> {
+ let resolve!: (value: T) => void
+ const promise = new Promise<T>(res => {
+ resolve = res
+ })
+ return { promise, resolve }
+}
+
+function createSessionState(authenticated: boolean) {
+ return authenticated
+ ? { authenticated: true, me: HARNESS_ME }
+ : { authenticated: false, me: null }
+}
+
function createCatalog(agentNames: string[]) {
return {
userId: HARNESS_ME.id,
@@ -49,18 +73,85 @@ function createCatalog(agentNames: string[]) {
}
}
+const DEFAULT_DESKTOP_RELEASE_STATUS = {
+ checked: true,
+ currentVersion: '0.1.250',
+ latestVersion: '0.1.250',
+ minimumVersion: '0.1.250',
+ updateRequired: false,
+ releaseUrl: '',
+}
+
+export interface AppControllerClerumOptions {
+ /** Access-catalog agents. Empty means "authenticated user with no agents". */
+ agentNames?: string[]
+ /** Boot already signed in (default). `false` boots at the login screen. */
+ startAuthenticated?: boolean
+ /**
+ * Hold `team.directory`, `access.refreshCatalog` and `approvals.listPending`
+ * open once authenticated, until `resolveAuthenticatedLoad()` runs — lets a
+ * test observe the window between login and workspace hydration.
+ */
+ delayAuthenticatedLoad?: boolean
+ /** Make `auth.passwordLogin` reject with this instead of signing in. */
+ passwordLoginError?: unknown
+ /** Payload for `auth.getDesktopReleaseStatus`. */
+ desktopReleaseStatus?: typeof DEFAULT_DESKTOP_RELEASE_STATUS
+ /** Payload for `team.directory` / `team.initialDirectory` / `team.list`. */
+ teamDirectory?: { items: unknown[]; currentTeamId: string }
+}
+
+export interface AppControllerClerumHandle {
+ getSessionState: Fn
+ passwordLogin: Fn
+ getDesktopReleaseStatus: Fn
+ teamDirectory: Fn
+ refreshCatalog: Fn
+ listPending: Fn
+ /** Settles whatever `delayAuthenticatedLoad` is holding open. */
+ resolveAuthenticatedLoad: () => void
+}
+
/**
* Adds the auth/team/access/notifications/... namespaces the coordinator needs
* on top of an installed `MockClerum`. Call it AFTER `installMockClerum()` and
- * BEFORE `renderAppController()`.
+ * BEFORE mounting. Use `installAppControllerClerum` when the suite has no
+ * `installMockClerum()` of its own.
*/
export function extendMockClerumForAppController(
clerum: MockClerum,
- options: { agentNames?: string[] } = {}
-): void {
+ options: AppControllerClerumOptions = {}
+): AppControllerClerumHandle {
const agentNames = options.agentNames ?? ['agent-x']
const bridge = clerum as unknown as Record<string, unknown>
+ let authenticated = options.startAuthenticated ?? true
+ const teamDirectoryPayload = options.teamDirectory ?? {
+ items: [],
+ currentTeamId: HARNESS_ME.teamId,
+ }
+ const teamDirectoryDeferred = createDeferred<typeof teamDirectoryPayload>()
+ const catalogDeferred = createDeferred<ReturnType<typeof createCatalog>>()
+ const approvalsDeferred = createDeferred<unknown[]>()
+ const held = () => Boolean(options.delayAuthenticatedLoad) && authenticated
+
+ const getSessionState = vi.fn(async () => createSessionState(authenticated))
+ const passwordLogin = vi.fn(async () => {
+ if (options.passwordLoginError) throw options.passwordLoginError
+ authenticated = true
+ return createSessionState(true)
+ })
+ const getDesktopReleaseStatus = vi.fn(
+ async () => options.desktopReleaseStatus ?? DEFAULT_DESKTOP_RELEASE_STATUS
+ )
+ const teamDirectory = vi.fn(async () =>
+ held() ? teamDirectoryDeferred.promise : teamDirectoryPayload
+ )
+ const refreshCatalog = vi.fn(async () =>
+ held() ? catalogDeferred.promise : createCatalog(agentNames)
+ )
+ const listPending = vi.fn(async () => (held() ? approvalsDeferred.promise : []))
+
Object.assign(bridge.rpc as object, {
listServers: vi.fn(async () => ({ servers: [] })),
prewarmHost: vi.fn(async () => ({ status: 'ok' })),
@@ -68,46 +159,39 @@ export function extendMockClerumForAppController(
denyToolCall: vi.fn(async () => undefined),
})
- const teamDirectory = vi.fn(async () => ({ items: [], currentTeamId: HARNESS_ME.teamId }))
-
Object.assign(bridge, {
auth: {
getDependenciesHealth: vi.fn(async () => ({
externalRestApi: { ok: true },
rpcProxy: { ok: true },
})),
- getSessionState: vi.fn(async () => ({ authenticated: true, me: HARNESS_ME })),
+ getSessionState,
getRuntimeConfigState: vi.fn(async () => ({
activeProfileId: null,
configured: true,
isPackaged: false,
options: [],
})),
- getDesktopReleaseStatus: vi.fn(async () => ({
- checked: true,
- currentVersion: '0.1.250',
- latestVersion: '0.1.250',
- minimumVersion: '0.1.250',
- updateRequired: false,
- releaseUrl: '',
- })),
+ getDesktopReleaseStatus,
openDesktopRelease: vi.fn(async () => undefined),
- passwordLogin: vi.fn(async () => ({ authenticated: true, me: HARNESS_ME })),
+ passwordLogin,
logout: vi.fn(async () => undefined),
onDesktopSetupToken: vi.fn(() => () => undefined),
onDesktopEnvironmentSetup: vi.fn(() => () => undefined),
onExternalLogout: vi.fn(() => () => undefined),
},
team: {
+ list: vi.fn(async () => teamDirectoryPayload),
+ members: vi.fn(async () => []),
directory: teamDirectory,
initialDirectory: teamDirectory,
- switch: vi.fn(async () => ({ authenticated: true, me: HARNESS_ME })),
+ switch: vi.fn(async () => createSessionState(true)),
},
access: {
- refreshCatalog: vi.fn(async () => createCatalog(agentNames)),
+ refreshCatalog,
},
approvals: {
- listPending: vi.fn(async () => []),
+ listPending,
decide: vi.fn(async () => ({ ok: true })),
},
notifications: {
@@ -142,7 +226,10 @@ export function extendMockClerumForAppController(
channelFallbackEnabled: true,
verifiedMedia: [],
})),
- update: vi.fn(async () => ({ verifiedMedia: [] })),
+ update: vi.fn(async (next: unknown) => ({
+ ...(next && typeof next === 'object' ? next : {}),
+ verifiedMedia: [],
+ })),
},
desktop: {
getStatus: vi.fn(async () => ({ status: 'inactive' })),
@@ -157,6 +244,29 @@ export function extendMockClerumForAppController(
trigger: vi.fn(async () => undefined),
},
})
+
+ return {
+ getSessionState,
+ passwordLogin,
+ getDesktopReleaseStatus,
+ teamDirectory,
+ refreshCatalog,
+ listPending,
+ resolveAuthenticatedLoad() {
+ teamDirectoryDeferred.resolve(teamDirectoryPayload)
+ catalogDeferred.resolve(createCatalog(agentNames))
+ approvalsDeferred.resolve([])
+ },
+ }
+}
+
+/** `installMockClerum()` + `extendMockClerumForAppController()` in one call. */
+export function installAppControllerClerum(options: AppControllerClerumOptions = {}): {
+ clerum: MockClerum
+ handle: AppControllerClerumHandle
+} {
+ const clerum = installMockClerum()
+ return { clerum, handle: extendMockClerumForAppController(clerum, options) }
}
export interface RenderAppControllerResult {