mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
fix(schedules): submit scheduled runs via prompt_async with SSE monitoring (#335)
* fix(schedules): submit scheduled runs via prompt_async with SSE monitoring * fix(session): use session directory for SSE and queries when it differs from repo path
This commit is contained in:
1 parent
1666d0de8f
commit
cfe2031c04
15 files changed
+538
-199
No files matched your search
@@ -30,6 +30,8 @@ type GeneralTabProps = {
|
||||
repoOptions: ComboboxOption[]
|
||||
allowExternalDirectory: boolean
|
||||
onAllowExternalDirectoryChange: (value: boolean) => void
|
||||
allowQuestions: boolean
|
||||
onAllowQuestionsChange: (value: boolean) => void
|
||||
bashDenyPatterns: string[]
|
||||
onBashDenyPatternsChange: (value: string[]) => void
|
||||
}
|
||||
@@ -70,6 +72,8 @@ export function GeneralTab({
|
||||
repoOptions,
|
||||
allowExternalDirectory,
|
||||
onAllowExternalDirectoryChange,
|
||||
allowQuestions,
|
||||
onAllowQuestionsChange,
|
||||
bashDenyPatterns,
|
||||
onBashDenyPatternsChange,
|
||||
}: GeneralTabProps) {
|
||||
@@ -178,6 +182,15 @@ export function GeneralTab({
|
||||
<Switch checked={allowExternalDirectory} onCheckedChange={onAllowExternalDirectoryChange} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="rounded-lg border border-border bg-card p-4">
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<p className="text-sm font-medium">Allow questions</p>
|
||||
<InfoHint text="Scheduled runs are unattended. When disabled, the agent's question tool is denied so a run can never stall waiting for an answer that nobody is there to give." />
|
||||
</div>
|
||||
<Switch checked={allowQuestions} onCheckedChange={onAllowQuestionsChange} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="rounded-lg border border-border bg-card p-4">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
|
||||
@@ -99,6 +99,11 @@ 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()
|
||||
@@ -127,6 +132,7 @@ describe('ScheduleJobDialog — permission config', () => {
|
||||
|
||||
const switchInput = getExternalDirSwitch()
|
||||
expect(switchInput).not.toBeChecked()
|
||||
expect(getAllowQuestionsSwitch()).not.toBeChecked()
|
||||
})
|
||||
|
||||
it('initializes permission config from an existing job', async () => {
|
||||
@@ -138,6 +144,7 @@ describe('ScheduleJobDialog — permission config', () => {
|
||||
const job = getDefaultJob({
|
||||
permissionConfig: {
|
||||
allowExternalDirectory: true,
|
||||
allowQuestions: true,
|
||||
bashDenyPatterns: [...customPatterns],
|
||||
},
|
||||
})
|
||||
@@ -160,6 +167,7 @@ describe('ScheduleJobDialog — permission config', () => {
|
||||
|
||||
const switchInput = getExternalDirSwitch()
|
||||
expect(switchInput).toBeChecked()
|
||||
expect(getAllowQuestionsSwitch()).toBeChecked()
|
||||
})
|
||||
|
||||
it('submits permissionConfig in the create payload', async () => {
|
||||
@@ -198,6 +206,44 @@ describe('ScheduleJobDialog — permission config', () => {
|
||||
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],
|
||||
})
|
||||
})
|
||||
@@ -239,6 +285,7 @@ describe('ScheduleJobDialog — permission config', () => {
|
||||
const payload = onSubmit.mock.calls[0][0]
|
||||
expect(payload.permissionConfig).toEqual({
|
||||
allowExternalDirectory: false,
|
||||
allowQuestions: false,
|
||||
bashDenyPatterns: ['rm -rf *', 'sudo *'],
|
||||
})
|
||||
})
|
||||
@@ -251,6 +298,7 @@ describe('ScheduleJobDialog — permission config', () => {
|
||||
const job = getDefaultJob({
|
||||
permissionConfig: {
|
||||
allowExternalDirectory: false,
|
||||
allowQuestions: true,
|
||||
bashDenyPatterns: ['rm -rf *', 'git push --force*'],
|
||||
},
|
||||
})
|
||||
@@ -288,6 +336,7 @@ describe('ScheduleJobDialog — permission config', () => {
|
||||
const payload = onSubmit.mock.calls[0][0]
|
||||
expect(payload.permissionConfig).toEqual({
|
||||
allowExternalDirectory: true,
|
||||
allowQuestions: true,
|
||||
bashDenyPatterns: ['rm -rf *', 'git push --force*', 'sudo *'],
|
||||
})
|
||||
})
|
||||
|
||||
@@ -65,6 +65,7 @@ export function ScheduleJobDialog({ open, onOpenChange, job, isSaving, onSubmit,
|
||||
const initialSkillNotesRef = useRef<string | undefined>(undefined)
|
||||
const [branch, setBranch] = useState('')
|
||||
const [allowExternalDirectory, setAllowExternalDirectory] = useState(false)
|
||||
const [allowQuestions, setAllowQuestions] = useState(false)
|
||||
const [bashDenyPatterns, setBashDenyPatterns] = useState<string[]>([...DEFAULT_DESTRUCTIVE_BASH_PATTERNS])
|
||||
const [templateDialogOpen, setTemplateDialogOpen] = useState(false)
|
||||
const [editingTemplate, setEditingTemplate] = useState<PromptTemplate | undefined>(undefined)
|
||||
@@ -222,6 +223,7 @@ export function ScheduleJobDialog({ open, onOpenChange, job, isSaving, onSubmit,
|
||||
initialSkillNotesRef.current = initialSkillNotes
|
||||
setBranch(job?.branch ?? '')
|
||||
setAllowExternalDirectory(job?.permissionConfig?.allowExternalDirectory ?? false)
|
||||
setAllowQuestions(job?.permissionConfig?.allowQuestions ?? false)
|
||||
setBashDenyPatterns(job?.permissionConfig?.bashDenyPatterns ?? [...DEFAULT_DESTRUCTIVE_BASH_PATTERNS])
|
||||
}, [job, open])
|
||||
|
||||
@@ -265,6 +267,7 @@ export function ScheduleJobDialog({ open, onOpenChange, job, isSaving, onSubmit,
|
||||
branch: branch.trim() || null,
|
||||
permissionConfig: {
|
||||
allowExternalDirectory,
|
||||
allowQuestions,
|
||||
bashDenyPatterns: bashDenyPatterns.map((p) => p.trim()).filter(Boolean),
|
||||
},
|
||||
...(shouldIncludeSkillMetadata ? {
|
||||
@@ -347,6 +350,8 @@ export function ScheduleJobDialog({ open, onOpenChange, job, isSaving, onSubmit,
|
||||
repoOptions={repoOptions}
|
||||
allowExternalDirectory={allowExternalDirectory}
|
||||
onAllowExternalDirectoryChange={setAllowExternalDirectory}
|
||||
allowQuestions={allowQuestions}
|
||||
onAllowQuestionsChange={setAllowQuestions}
|
||||
bashDenyPatterns={bashDenyPatterns}
|
||||
onBashDenyPatternsChange={setBashDenyPatterns}
|
||||
/>
|
||||
|
||||
Reference in new issue
Block a user