mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
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.
385 lines
11 KiB
TypeScript
385 lines
11 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { render, screen, waitFor } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
import { ScheduleJobDialog } from './ScheduleJobDialog'
|
|
import { DEFAULT_DESTRUCTIVE_BASH_PATTERNS } from '@opencode-manager/shared/schemas'
|
|
import type { ScheduleJob } from '@opencode-manager/shared/types'
|
|
|
|
// jsdom does not implement scrollIntoView
|
|
Element.prototype.scrollIntoView = vi.fn()
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
templates: [] as Array<{ id: number; title: string; description: string; category: string; cadenceHint: string; suggestedName: string; suggestedDescription: string; prompt: string }>,
|
|
useDeletePromptTemplateMutate: vi.fn(),
|
|
}))
|
|
|
|
vi.mock('@/hooks/usePromptTemplates', () => ({
|
|
usePromptTemplates: () => ({ data: mocks.templates, isLoading: false }),
|
|
useCreatePromptTemplate: () => ({ mutate: vi.fn(), isPending: false }),
|
|
useUpdatePromptTemplate: () => ({ mutate: vi.fn(), isPending: false }),
|
|
useDeletePromptTemplate: () => ({ mutate: mocks.useDeletePromptTemplateMutate, isPending: false }),
|
|
}))
|
|
|
|
vi.mock('@/api/providers', () => ({
|
|
getProviders: () => Promise.resolve({ providers: [], models: [] }),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useOpenCode', () => ({
|
|
useAgents: () => ({ data: [] }),
|
|
}))
|
|
|
|
vi.mock('@/api/settings', () => ({
|
|
settingsApi: {
|
|
listManagedSkills: () => Promise.resolve([]),
|
|
},
|
|
}))
|
|
|
|
vi.mock('@/api/repos', () => ({
|
|
listRepos: () => Promise.resolve([]),
|
|
listBranches: () => Promise.resolve({ branches: [], status: { ahead: 0, behind: 0 } }),
|
|
}))
|
|
|
|
function createWrapper() {
|
|
const queryClient = new QueryClient({
|
|
defaultOptions: {
|
|
queries: { retry: false },
|
|
mutations: { retry: false },
|
|
},
|
|
})
|
|
return ({ children }: { children: React.ReactNode }) => (
|
|
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
)
|
|
}
|
|
|
|
function getDefaultJob(overrides?: Partial<ScheduleJob>): ScheduleJob {
|
|
return {
|
|
id: 1,
|
|
repoId: 1,
|
|
name: 'Test Job',
|
|
description: null,
|
|
enabled: true,
|
|
scheduleMode: 'interval',
|
|
intervalMinutes: 60,
|
|
cronExpression: null,
|
|
timezone: null,
|
|
agentSlug: null,
|
|
prompt: 'Test prompt',
|
|
model: null,
|
|
skillMetadata: null,
|
|
permissionConfig: null,
|
|
branch: null,
|
|
createdAt: Date.now(),
|
|
updatedAt: Date.now(),
|
|
lastRunAt: null,
|
|
nextRunAt: null,
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
async function navigateToGeneralTab(user: ReturnType<typeof userEvent.setup>) {
|
|
const generalTab = screen.getByRole('tab', { name: 'General' })
|
|
await user.click(generalTab)
|
|
}
|
|
|
|
async function fillRequiredFields(user: ReturnType<typeof userEvent.setup>) {
|
|
const nameInput = screen.getByLabelText('Name')
|
|
await user.type(nameInput, 'Test Job')
|
|
const promptTab = screen.getByRole('tab', { name: 'Prompt' })
|
|
await user.click(promptTab)
|
|
const promptInput = screen.getByRole('textbox', { name: 'Prompt' })
|
|
await user.type(promptInput, 'Run a test')
|
|
}
|
|
|
|
/** The external-directory switch is the 2nd switch (index 1) after Enabled */
|
|
function getExternalDirSwitch() {
|
|
return screen.getAllByRole('switch')[1]
|
|
}
|
|
|
|
/** The allow-questions switch is the 3rd switch (index 2), after Enabled and external directory */
|
|
function getAllowQuestionsSwitch() {
|
|
return screen.getAllByRole('switch')[2]
|
|
}
|
|
|
|
describe('ScheduleJobDialog — permission config', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('shows default deny patterns and external-directory toggle off for a new job', async () => {
|
|
const onSubmit = vi.fn()
|
|
const onOpenChange = vi.fn()
|
|
const user = userEvent.setup()
|
|
|
|
render(
|
|
<ScheduleJobDialog
|
|
open
|
|
onOpenChange={onOpenChange}
|
|
onSubmit={onSubmit}
|
|
isSaving={false}
|
|
/>,
|
|
{ wrapper: createWrapper() },
|
|
)
|
|
|
|
await navigateToGeneralTab(user)
|
|
|
|
const textarea = await screen.findByLabelText('Blocked bash commands')
|
|
const defaultText = DEFAULT_DESTRUCTIVE_BASH_PATTERNS.join('\n')
|
|
expect(textarea).toHaveValue(defaultText)
|
|
|
|
const switchInput = getExternalDirSwitch()
|
|
expect(switchInput).not.toBeChecked()
|
|
expect(getAllowQuestionsSwitch()).not.toBeChecked()
|
|
})
|
|
|
|
it('names each form switch after its visible label', async () => {
|
|
const user = userEvent.setup()
|
|
|
|
render(
|
|
<ScheduleJobDialog
|
|
open
|
|
onOpenChange={vi.fn()}
|
|
onSubmit={vi.fn()}
|
|
isSaving={false}
|
|
/>,
|
|
{ wrapper: createWrapper() },
|
|
)
|
|
|
|
await navigateToGeneralTab(user)
|
|
|
|
expect(screen.getByRole('switch', { name: 'Enabled' })).toBeInTheDocument()
|
|
expect(
|
|
screen.getByRole('switch', { name: 'Allow access outside the working directory' }),
|
|
).toBeInTheDocument()
|
|
expect(screen.getByRole('switch', { name: 'Allow questions' })).toBeInTheDocument()
|
|
})
|
|
|
|
it('names the missing required fields while Create schedule is disabled', async () => {
|
|
const user = userEvent.setup()
|
|
|
|
render(
|
|
<ScheduleJobDialog
|
|
open
|
|
onOpenChange={vi.fn()}
|
|
onSubmit={vi.fn()}
|
|
isSaving={false}
|
|
/>,
|
|
{ wrapper: createWrapper() },
|
|
)
|
|
|
|
expect(screen.getByRole('button', { name: 'Create schedule' })).toBeDisabled()
|
|
expect(screen.getByText('Required: name, prompt')).toBeInTheDocument()
|
|
|
|
await user.type(screen.getByLabelText('Name'), 'Test Job')
|
|
|
|
expect(screen.getByText('Required: prompt')).toBeInTheDocument()
|
|
expect(screen.getByRole('button', { name: 'Create schedule' })).toBeDisabled()
|
|
})
|
|
|
|
it('initializes permission config from an existing job', async () => {
|
|
const onSubmit = vi.fn()
|
|
const onOpenChange = vi.fn()
|
|
const user = userEvent.setup()
|
|
|
|
const customPatterns = ['rm -rf *', 'sudo *']
|
|
const job = getDefaultJob({
|
|
permissionConfig: {
|
|
allowExternalDirectory: true,
|
|
allowQuestions: true,
|
|
bashDenyPatterns: [...customPatterns],
|
|
},
|
|
})
|
|
|
|
render(
|
|
<ScheduleJobDialog
|
|
open
|
|
onOpenChange={onOpenChange}
|
|
job={job}
|
|
onSubmit={onSubmit}
|
|
isSaving={false}
|
|
/>,
|
|
{ wrapper: createWrapper() },
|
|
)
|
|
|
|
await navigateToGeneralTab(user)
|
|
|
|
const textarea = await screen.findByLabelText('Blocked bash commands')
|
|
expect(textarea).toHaveValue(customPatterns.join('\n'))
|
|
|
|
const switchInput = getExternalDirSwitch()
|
|
expect(switchInput).toBeChecked()
|
|
expect(getAllowQuestionsSwitch()).toBeChecked()
|
|
})
|
|
|
|
it('submits permissionConfig in the create payload', async () => {
|
|
const onSubmit = vi.fn()
|
|
const onOpenChange = vi.fn()
|
|
const user = userEvent.setup()
|
|
|
|
render(
|
|
<ScheduleJobDialog
|
|
open
|
|
onOpenChange={onOpenChange}
|
|
onSubmit={onSubmit}
|
|
isSaving={false}
|
|
/>,
|
|
{ wrapper: createWrapper() },
|
|
)
|
|
|
|
await navigateToGeneralTab(user)
|
|
await fillRequiredFields(user)
|
|
|
|
// Navigate back to General tab
|
|
await navigateToGeneralTab(user)
|
|
|
|
// Enable external directory access
|
|
const switchInput = getExternalDirSwitch()
|
|
await user.click(switchInput)
|
|
|
|
// Submit
|
|
const submitButton = screen.getByRole('button', { name: /Create schedule/i })
|
|
await user.click(submitButton)
|
|
|
|
await waitFor(() => {
|
|
expect(onSubmit).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
const payload = onSubmit.mock.calls[0][0]
|
|
expect(payload.permissionConfig).toEqual({
|
|
allowExternalDirectory: true,
|
|
allowQuestions: false,
|
|
bashDenyPatterns: [...DEFAULT_DESTRUCTIVE_BASH_PATTERNS],
|
|
})
|
|
})
|
|
|
|
it('submits allowQuestions true when the questions toggle is enabled', async () => {
|
|
const onSubmit = vi.fn()
|
|
const onOpenChange = vi.fn()
|
|
const user = userEvent.setup()
|
|
|
|
render(
|
|
<ScheduleJobDialog
|
|
open
|
|
onOpenChange={onOpenChange}
|
|
onSubmit={onSubmit}
|
|
isSaving={false}
|
|
/>,
|
|
{ wrapper: createWrapper() },
|
|
)
|
|
|
|
await navigateToGeneralTab(user)
|
|
await fillRequiredFields(user)
|
|
|
|
await navigateToGeneralTab(user)
|
|
|
|
await user.click(getAllowQuestionsSwitch())
|
|
|
|
const submitButton = screen.getByRole('button', { name: /Create schedule/i })
|
|
await user.click(submitButton)
|
|
|
|
await waitFor(() => {
|
|
expect(onSubmit).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
const payload = onSubmit.mock.calls[0][0]
|
|
expect(payload.permissionConfig).toEqual({
|
|
allowExternalDirectory: false,
|
|
allowQuestions: true,
|
|
bashDenyPatterns: [...DEFAULT_DESTRUCTIVE_BASH_PATTERNS],
|
|
})
|
|
})
|
|
|
|
it('strips empty lines from bash deny patterns before submitting', async () => {
|
|
const onSubmit = vi.fn()
|
|
const onOpenChange = vi.fn()
|
|
const user = userEvent.setup()
|
|
|
|
render(
|
|
<ScheduleJobDialog
|
|
open
|
|
onOpenChange={onOpenChange}
|
|
onSubmit={onSubmit}
|
|
isSaving={false}
|
|
/>,
|
|
{ wrapper: createWrapper() },
|
|
)
|
|
|
|
await navigateToGeneralTab(user)
|
|
await fillRequiredFields(user)
|
|
|
|
// Navigate back to General tab
|
|
await navigateToGeneralTab(user)
|
|
|
|
// Clear and set patterns with empty lines via paste to preserve newlines
|
|
const textarea = await screen.findByLabelText('Blocked bash commands')
|
|
await user.clear(textarea)
|
|
await user.type(textarea, 'rm -rf *{Enter}{Enter}{Enter}sudo *{Enter}{Enter}')
|
|
|
|
// Submit
|
|
const submitButton = screen.getByRole('button', { name: /Create schedule/i })
|
|
await user.click(submitButton)
|
|
|
|
await waitFor(() => {
|
|
expect(onSubmit).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
const payload = onSubmit.mock.calls[0][0]
|
|
expect(payload.permissionConfig).toEqual({
|
|
allowExternalDirectory: false,
|
|
allowQuestions: false,
|
|
bashDenyPatterns: ['rm -rf *', 'sudo *'],
|
|
})
|
|
})
|
|
|
|
it('submits updated permissionConfig when editing an existing job', async () => {
|
|
const onSubmit = vi.fn()
|
|
const onOpenChange = vi.fn()
|
|
const user = userEvent.setup()
|
|
|
|
const job = getDefaultJob({
|
|
permissionConfig: {
|
|
allowExternalDirectory: false,
|
|
allowQuestions: true,
|
|
bashDenyPatterns: ['rm -rf *', 'git push --force*'],
|
|
},
|
|
})
|
|
|
|
render(
|
|
<ScheduleJobDialog
|
|
open
|
|
onOpenChange={onOpenChange}
|
|
job={job}
|
|
onSubmit={onSubmit}
|
|
isSaving={false}
|
|
/>,
|
|
{ wrapper: createWrapper() },
|
|
)
|
|
|
|
await navigateToGeneralTab(user)
|
|
|
|
// Toggle external directory on
|
|
const switchInput = getExternalDirSwitch()
|
|
await user.click(switchInput)
|
|
|
|
// Add a pattern via Enter key
|
|
const textarea = await screen.findByLabelText('Blocked bash commands')
|
|
const existingValue = textarea as HTMLTextAreaElement
|
|
await user.type(existingValue, '{Enter}sudo *')
|
|
|
|
// Submit
|
|
const submitButton = screen.getByRole('button', { name: /Save changes/i })
|
|
await user.click(submitButton)
|
|
|
|
await waitFor(() => {
|
|
expect(onSubmit).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
const payload = onSubmit.mock.calls[0][0]
|
|
expect(payload.permissionConfig).toEqual({
|
|
allowExternalDirectory: true,
|
|
allowQuestions: true,
|
|
bashDenyPatterns: ['rm -rf *', 'git push --force*', 'sudo *'],
|
|
})
|
|
})
|
|
})
|