mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
fix: address findings from the full Docker evaluation of main
Critical and high: - repos: unlinking a local repo removes only the Manager reference and alias, never the repository files; confirm button reads "Unlink" - auth: rate-limit by the socket address; trust proxy headers only when AUTH_TRUSTED_PROXY_HEADERS is set (documented and forwarded in compose) - composer: per-session in-memory drafts (text, bash mode, attachments); Escape no longer clears the prompt - url params: compose same-tick updates so schedule dialogs stay closed after create/delete; delete dialog names the job Medium: - tool rows show failures (non-zero shell exit, failed exploration members) - voice conversation shows the specific error and a starting state - settings: Escape in dropdowns and the shortcut recorder no longer closes the dialog; mobile deep links open the requested section; one content tree per platform - closing pushed sheets, settings, tool panels and schedule dialogs goes back in history - login returns to the requested page; signed-out pages make no authenticated requests - action terminals keep their output (Manager-side output capture and replay) - unpushed-commit detection, commit message kept on failure - binary files with unknown extensions are detected and not editable - tool panel resizes when docked and floats as a dismissible sheet when the page is too narrow - Docker image runs tini as PID 1 Low: not-found states, add-repo and branch validation errors (4xx), search-aware empty states, mobile repo sort/filter/select cues, sidebar resize affordance and collapse shortcut, mobile unread badge, preview port filtering, terminal close handling, walkthrough empty state and helper session filtering, placeholder contrast, permission labels and focus, TTS task-list sanitizing, git identity email validation, quieter git logging, hermetic worktree tests, and accessible names for icon-only controls.
This commit is contained in:
1 parent
1c22ef6ea1
commit
4ec62cd4e7
191 files changed
+6674
-696
No files matched your search
@@ -0,0 +1,126 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { render, waitFor } from '@testing-library/react'
|
||||
import { MemoryRouter, Route, Routes } from 'react-router-dom'
|
||||
import { LocationCatcher } from '@/test/test-utils'
|
||||
import { AuthProvider } from './AuthContext'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
useSession: vi.fn(),
|
||||
refetch: vi.fn(),
|
||||
signInEmail: vi.fn(),
|
||||
signInSocial: vi.fn(),
|
||||
signInPasskey: vi.fn(),
|
||||
signUpEmail: vi.fn(),
|
||||
signOut: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/auth-client', () => ({
|
||||
useSession: mocks.useSession,
|
||||
signIn: { email: mocks.signInEmail, social: mocks.signInSocial },
|
||||
signUp: { email: mocks.signUpEmail },
|
||||
signOut: mocks.signOut,
|
||||
authClient: { signIn: { passkey: mocks.signInPasskey } },
|
||||
}))
|
||||
|
||||
type AuthValue = ReturnType<typeof useAuth>
|
||||
|
||||
function AuthProbe({ captured }: { captured: { current: AuthValue | null } }) {
|
||||
captured.current = useAuth()
|
||||
return null
|
||||
}
|
||||
|
||||
function renderAuth(initialEntry: string) {
|
||||
const capturedPathname: { current: string } = { current: '' }
|
||||
const capturedSearch: { current: string } = { current: '' }
|
||||
const captured: { current: AuthValue | null } = { current: null }
|
||||
|
||||
render(
|
||||
<MemoryRouter initialEntries={[initialEntry]}>
|
||||
<LocationCatcher capturedSearch={capturedSearch} capturedPathname={capturedPathname} />
|
||||
<Routes>
|
||||
<Route
|
||||
path="/login"
|
||||
element={(
|
||||
<AuthProvider>
|
||||
<AuthProbe captured={captured} />
|
||||
</AuthProvider>
|
||||
)}
|
||||
/>
|
||||
<Route path="/" element={null} />
|
||||
<Route path="/repos/:id" element={null} />
|
||||
</Routes>
|
||||
</MemoryRouter>,
|
||||
)
|
||||
|
||||
return { capturedPathname, capturedSearch, captured }
|
||||
}
|
||||
|
||||
describe('AuthProvider post-login navigation', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mocks.useSession.mockReturnValue({ data: null, isPending: false, refetch: mocks.refetch })
|
||||
mocks.refetch.mockResolvedValue(undefined)
|
||||
mocks.signInEmail.mockResolvedValue({ data: { user: { id: 'user-1' } } })
|
||||
mocks.signInPasskey.mockResolvedValue({ data: { user: { id: 'user-1' } } })
|
||||
mocks.signInSocial.mockResolvedValue({ data: { url: 'https://github.example.com' } })
|
||||
mocks.signUpEmail.mockResolvedValue({ data: { user: { id: 'user-1' } } })
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ enabledProviders: ['credentials'], registrationEnabled: true, isFirstUser: false, adminConfigured: true }),
|
||||
}))
|
||||
})
|
||||
|
||||
it('returns to the requested page after signing in with a password', async () => {
|
||||
const { captured, capturedPathname, capturedSearch } = renderAuth('/login?redirect=%2Frepos%2F2%3Ftab%3Dworkspaces')
|
||||
|
||||
await captured.current?.signInWithEmail('user@example.com', 'password')
|
||||
|
||||
await waitFor(() => {
|
||||
expect(capturedPathname.current).toBe('/repos/2')
|
||||
})
|
||||
expect(capturedSearch.current).toBe('?tab=workspaces')
|
||||
})
|
||||
|
||||
it('falls back to the app root for an unsafe redirect target', async () => {
|
||||
const { captured, capturedPathname } = renderAuth('/login?redirect=%2F%2Fevil.example.com')
|
||||
|
||||
await captured.current?.signInWithEmail('user@example.com', 'password')
|
||||
|
||||
await waitFor(() => {
|
||||
expect(capturedPathname.current).toBe('/')
|
||||
})
|
||||
})
|
||||
|
||||
it('returns to the requested page after signing in with a passkey', async () => {
|
||||
const { captured, capturedPathname, capturedSearch } = renderAuth('/login?redirect=%2Frepos%2F7')
|
||||
|
||||
await captured.current?.signInWithPasskey()
|
||||
|
||||
await waitFor(() => {
|
||||
expect(capturedPathname.current).toBe('/repos/7')
|
||||
})
|
||||
expect(capturedSearch.current).toBe('')
|
||||
})
|
||||
|
||||
it('sends the redirect target as the OAuth callback URL', async () => {
|
||||
const { captured } = renderAuth('/login?redirect=%2Frepos%2F3%3Ftab%3Dworkspaces')
|
||||
|
||||
await captured.current?.signInWithProvider('github')
|
||||
|
||||
expect(mocks.signInSocial).toHaveBeenCalledWith({
|
||||
provider: 'github',
|
||||
callbackURL: '/repos/3?tab=workspaces',
|
||||
})
|
||||
})
|
||||
|
||||
it('lands on the app root without a redirect target', async () => {
|
||||
const { captured, capturedPathname } = renderAuth('/login')
|
||||
|
||||
await captured.current?.signInWithEmail('user@example.com', 'password')
|
||||
|
||||
await waitFor(() => {
|
||||
expect(capturedPathname.current).toBe('/')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -2,6 +2,7 @@
|
||||
import { createContext, useEffect, useMemo, useState, useCallback, type ReactNode } from 'react'
|
||||
import { useSession, signIn, signUp, signOut, authClient, type AuthUser } from '@/lib/auth-client'
|
||||
import { useNavigate, useLocation } from 'react-router-dom'
|
||||
import { getLoginRedirectTarget } from '@/lib/auth-loaders'
|
||||
|
||||
interface AuthConfig {
|
||||
enabledProviders: string[]
|
||||
@@ -37,6 +38,10 @@ export function AuthProvider({ children }: AuthProviderProps) {
|
||||
const [config, setConfig] = useState<AuthConfig | null>(null)
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const redirectTarget = useMemo(
|
||||
() => getLoginRedirectTarget(location.search),
|
||||
[location.search],
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
const fetchConfig = async () => {
|
||||
@@ -64,19 +69,18 @@ export function AuthProvider({ children }: AuthProviderProps) {
|
||||
return { error: result.error.message || 'Sign in failed' }
|
||||
}
|
||||
await refetch()
|
||||
const from = (location.state as { from?: string })?.from || '/'
|
||||
navigate(from, { replace: true })
|
||||
navigate(redirectTarget, { replace: true })
|
||||
return {}
|
||||
}, [refetch, navigate, location])
|
||||
}, [refetch, navigate, redirectTarget])
|
||||
|
||||
const signInWithProvider = useCallback(async (provider: 'github' | 'google' | 'discord') => {
|
||||
try {
|
||||
await signIn.social({ provider, callbackURL: '/' })
|
||||
await signIn.social({ provider, callbackURL: redirectTarget })
|
||||
return {}
|
||||
} catch (err) {
|
||||
return { error: err instanceof Error ? err.message : 'OAuth sign in failed' }
|
||||
}
|
||||
}, [])
|
||||
}, [redirectTarget])
|
||||
|
||||
const signInWithPasskey = useCallback(async () => {
|
||||
try {
|
||||
@@ -85,13 +89,12 @@ export function AuthProvider({ children }: AuthProviderProps) {
|
||||
return { error: result.error.message || 'Passkey sign in failed' }
|
||||
}
|
||||
await refetch()
|
||||
const from = (location.state as { from?: string })?.from || '/'
|
||||
navigate(from, { replace: true })
|
||||
navigate(redirectTarget, { replace: true })
|
||||
return {}
|
||||
} catch (err) {
|
||||
return { error: err instanceof Error ? err.message : 'Passkey sign in failed' }
|
||||
}
|
||||
}, [refetch, navigate, location])
|
||||
}, [refetch, navigate, redirectTarget])
|
||||
|
||||
const signUpWithEmail = useCallback(async (email: string, password: string, name: string) => {
|
||||
const result = await signUp.email({ email, password, name })
|
||||
@@ -99,9 +102,9 @@ export function AuthProvider({ children }: AuthProviderProps) {
|
||||
return { error: result.error.message || 'Sign up failed' }
|
||||
}
|
||||
await refetch()
|
||||
navigate('/', { replace: true })
|
||||
navigate(redirectTarget, { replace: true })
|
||||
return {}
|
||||
}, [refetch, navigate])
|
||||
}, [refetch, navigate, redirectTarget])
|
||||
|
||||
const addPasskey = useCallback(async (name?: string) => {
|
||||
const result = await authClient.passkey.addPasskey({ name })
|
||||
|
||||
@@ -26,6 +26,7 @@ const mocks = vi.hoisted(() => ({
|
||||
listProjects: vi.fn(),
|
||||
servers: [] as Array<{ id: string; enabled: boolean }>,
|
||||
serversLoaded: false,
|
||||
isAuthenticated: true,
|
||||
}))
|
||||
|
||||
vi.mock('@/api/repos', () => ({
|
||||
@@ -45,7 +46,7 @@ vi.mock('@/api/opencode', () => ({
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useAuth', () => ({
|
||||
useAuth: () => ({ isAuthenticated: true }),
|
||||
useAuth: () => ({ isAuthenticated: mocks.isAuthenticated }),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useOpenCodeServers', () => ({
|
||||
@@ -242,6 +243,7 @@ describe('EventProvider permissions and forms', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
window.history.pushState({}, '', '/')
|
||||
mocks.isAuthenticated = true
|
||||
mocks.listRepos.mockResolvedValue([])
|
||||
mocks.listProjects.mockResolvedValue([])
|
||||
mocks.servers = []
|
||||
@@ -264,6 +266,15 @@ describe('EventProvider permissions and forms', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('defers authenticated bootstrap reads and the event stream until a session exists', () => {
|
||||
mocks.isAuthenticated = false
|
||||
|
||||
render(<Harness />, { wrapper: createWrapper() })
|
||||
|
||||
expect(mocks.listRepos).not.toHaveBeenCalled()
|
||||
expect(mocks.subscribeGlobalMonitor).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('syncs missed pending forms for a session', async () => {
|
||||
mocks.listPendingForms.mockResolvedValue([pendingForm])
|
||||
|
||||
|
||||
@@ -375,12 +375,13 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
|
||||
const ancestryInFlightRef = useRef<Set<string>>(new Set())
|
||||
const forgottenSessionIDsRef = useRef(new Set<string>())
|
||||
|
||||
const { isAuthenticated } = useAuth()
|
||||
const { data: repos } = useQuery({
|
||||
queryKey: ['repos'],
|
||||
queryFn: listRepos,
|
||||
enabled: isAuthenticated,
|
||||
})
|
||||
|
||||
const { isAuthenticated } = useAuth()
|
||||
const { servers, isSuccess: serversLoaded } = useOpenCodeServers({ enabled: isAuthenticated })
|
||||
const enabledRemoteServers = useMemo(() => servers.filter((server) => server.enabled), [servers])
|
||||
const enabledRemoteServersRef = useRef(enabledRemoteServers)
|
||||
@@ -967,6 +968,8 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
|
||||
}, [rememberSessionDirectory, reconcileFormsForDirectory])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated) return
|
||||
|
||||
const handleSSEMessage = (data: unknown) => {
|
||||
if (!data || typeof data !== 'object' || !('type' in data)) return
|
||||
|
||||
@@ -1211,7 +1214,7 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
|
||||
subscription.dispose()
|
||||
subscriptionRef.current = null
|
||||
}
|
||||
}, [addPermission, removePermission, addForm, removeForm, forgetPendingActionsForSession, rememberSessionDirectory, fetchInitialSessionStatuses, startStatusPoll, stopStatusPoll, queryClient, handleHealthChange, reconcilePendingActionsForDirectories, reconcilePendingActionsForServer, collectTrackedDirectories, syncRunningShells, resolveSessionAncestry, reconcileRemoteSessionStatuses, reconcileRemoteServersOnce, invalidateRemoteStatusSyncs])
|
||||
}, [isAuthenticated, addPermission, removePermission, addForm, removeForm, forgetPendingActionsForSession, rememberSessionDirectory, fetchInitialSessionStatuses, startStatusPoll, stopStatusPoll, queryClient, handleHealthChange, reconcilePendingActionsForDirectories, reconcilePendingActionsForServer, collectTrackedDirectories, syncRunningShells, resolveSessionAncestry, reconcileRemoteSessionStatuses, reconcileRemoteServersOnce, invalidateRemoteStatusSyncs])
|
||||
|
||||
useEffect(() => {
|
||||
reposRef.current = repos
|
||||
|
||||
@@ -24,6 +24,10 @@ vi.mock('@/hooks/useSettings', () => ({
|
||||
useSettings: mocks.useSettings,
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useAuth', () => ({
|
||||
useAuth: () => ({ isAuthenticated: true }),
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/webSpeechSynthesizer', () => ({
|
||||
getWebSpeechSynthesizer: () => webSpeech as unknown as WebSpeechSynthesizer,
|
||||
isWebSpeechSupported: () => true,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useState, useRef, useCallback, useEffect, type ReactNode } from 'react'
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { API_BASE_URL } from '@/config'
|
||||
import { TTSContext, type TTSState, type TTSConfig, type TTSEndReason, type SpeakMessageOptions } from './tts-context'
|
||||
import { sanitizeForTTS } from '@/lib/utils'
|
||||
@@ -45,7 +46,8 @@ interface TTSProviderProps {
|
||||
}
|
||||
|
||||
export function TTSProvider({ children }: TTSProviderProps) {
|
||||
const { preferences } = useSettings()
|
||||
const { isAuthenticated } = useAuth()
|
||||
const { preferences } = useSettings('default', { enabled: isAuthenticated })
|
||||
const [state, setState] = useState<TTSState>('idle')
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [currentText, setCurrentText] = useState<string | null>(null)
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
/* eslint-disable react-refresh/only-export-components */
|
||||
import { createContext, useContext, useEffect, useState } from 'react'
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { applyColorTheme, getDocumentThemeMode, type ThemeMode } from '@/lib/theme/colorTheme'
|
||||
|
||||
const ThemeContext = createContext<ThemeMode | null>(null)
|
||||
|
||||
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
||||
const { preferences } = useSettings()
|
||||
const { isAuthenticated } = useAuth()
|
||||
const { preferences } = useSettings('default', { enabled: isAuthenticated })
|
||||
const [themeMode, setThemeMode] = useState<ThemeMode>(getDocumentThemeMode)
|
||||
const hasPreferences = preferences !== undefined
|
||||
const theme = preferences?.theme || 'dark'
|
||||
|
||||
Reference in new issue
Block a user