mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix(schedules): accept absolute Windows directories for remote schedules
Remote schedule targets were validated with the host's path.isAbsolute, which rejects Windows paths like C:\Projects\App when the Manager runs on Linux. Share the POSIX/Windows absolute-path check already used by the server terminal routes and use it for remote schedule create and update.
This commit is contained in:
1 parent
eba86dc3fc
commit
742660ecfa
4 files changed
+46
-7
No files matched your search
@@ -9,6 +9,7 @@ import {
|
||||
} from '@opencode-manager/shared/schemas'
|
||||
import { OpenCodeServerError } from '../services/opencode-server-registry'
|
||||
import { TerminalNotFoundError, type TerminalService } from '../services/terminal'
|
||||
import { isAbsoluteRemoteDirectory } from '../utils/remote-path'
|
||||
import { parseTerminalCursor } from '../utils/terminal-cursor'
|
||||
import { createBridgedSocketEvents, isAllowedUpgradeOrigin } from '../utils/websocket-bridge'
|
||||
import { handleOpenCodeError, handleServiceError, parseJsonBody } from '../utils/route-helpers'
|
||||
@@ -23,14 +24,10 @@ interface ServerTerminalSocketVariables {
|
||||
session?: Session['session']
|
||||
}
|
||||
|
||||
function isAbsoluteDirectory(directory: string): boolean {
|
||||
return directory.startsWith('/') || /^[A-Za-z]:[\\/]/.test(directory)
|
||||
}
|
||||
|
||||
function readAbsoluteDirectory(raw: string | undefined): string | null {
|
||||
if (raw === undefined) return null
|
||||
const directory = raw.trim()
|
||||
return directory.length > 0 && isAbsoluteDirectory(directory) ? directory : null
|
||||
return directory.length > 0 && isAbsoluteRemoteDirectory(directory) ? directory : null
|
||||
}
|
||||
|
||||
function rejectLocalServer(c: Context, serverId: string): Response | null {
|
||||
|
||||
@@ -64,6 +64,7 @@ import { sseAggregator, type ScheduledSessionRef } from './sse-aggregator'
|
||||
import { getErrorMessage } from '../utils/error-utils'
|
||||
import { logger } from '../utils/logger'
|
||||
import { canonicalPathSync } from '../utils/fs-safe'
|
||||
import { isAbsoluteRemoteDirectory } from '../utils/remote-path'
|
||||
import { buildAssistantRepo } from './assistant-mode'
|
||||
import { createScheduleWorktreeDescriber } from './schedule-worktree-paths'
|
||||
import { SessionSandboxError, type SessionSandboxService } from './session-sandbox'
|
||||
@@ -717,7 +718,7 @@ export class ScheduleService {
|
||||
}
|
||||
|
||||
async createServerJob(serverId: string, directory: string, input: CreateScheduleJobRequest): Promise<ScheduleJob> {
|
||||
if (!path.isAbsolute(directory)) {
|
||||
if (!isAbsoluteRemoteDirectory(directory)) {
|
||||
throw new ScheduleServiceError('A remote schedule requires an absolute target directory', 400)
|
||||
}
|
||||
return this.createJobForTarget({ kind: 'server', serverId, directory }, input)
|
||||
@@ -751,7 +752,7 @@ export class ScheduleService {
|
||||
}
|
||||
|
||||
async updateServerJob(serverId: string, jobId: number, input: UpdateScheduleJobRequest): Promise<ScheduleJob> {
|
||||
if (input.directory !== undefined && input.directory !== null && !path.isAbsolute(input.directory)) {
|
||||
if (input.directory !== undefined && input.directory !== null && !isAbsoluteRemoteDirectory(input.directory)) {
|
||||
throw new ScheduleServiceError('A remote schedule requires an absolute target directory', 400)
|
||||
}
|
||||
return this.updateJobForTarget({ kind: 'server', serverId, directory: '' }, jobId, input)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export function isAbsoluteRemoteDirectory(directory: string): boolean {
|
||||
return directory.startsWith('/') || /^[A-Za-z]:[\\/]/.test(directory)
|
||||
}
|
||||
@@ -102,6 +102,44 @@ describe('remote schedule targets', () => {
|
||||
expect(localClient.api.session.create).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('accepts a Windows target directory for a remote job', async () => {
|
||||
const localClient = createClient().client
|
||||
const { client } = createClient()
|
||||
const { service } = createService(localClient, client)
|
||||
|
||||
const job = await service.createServerJob(server.id, 'C:\\Projects\\ExampleApp', baseRequest)
|
||||
|
||||
expect(job.directory).toBe('C:\\Projects\\ExampleApp')
|
||||
expect(getScheduleJobById(db, null, job.id)).toMatchObject({
|
||||
serverId: server.id,
|
||||
directory: 'C:\\Projects\\ExampleApp',
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects a relative target directory for a remote job', async () => {
|
||||
const localClient = createClient().client
|
||||
const { client } = createClient()
|
||||
const { service } = createService(localClient, client)
|
||||
|
||||
await expect(service.createServerJob(server.id, 'projects/app', baseRequest)).rejects.toMatchObject({
|
||||
status: 400,
|
||||
message: 'A remote schedule requires an absolute target directory',
|
||||
})
|
||||
expect(getScheduleJobById(db, null, 1)).toBeNull()
|
||||
})
|
||||
|
||||
it('updates a remote job to a Windows target directory', async () => {
|
||||
const localClient = createClient().client
|
||||
const { client } = createClient()
|
||||
const { service } = createService(localClient, client)
|
||||
const job = await service.createServerJob(server.id, '/srv/projects/audit', baseRequest)
|
||||
|
||||
const updated = await service.updateServerJob(server.id, job.id, { directory: 'D:/work/app' })
|
||||
|
||||
expect(updated.directory).toBe('D:/work/app')
|
||||
expect(getScheduleJobById(db, null, job.id)?.directory).toBe('D:/work/app')
|
||||
})
|
||||
|
||||
it('rejects worktree workspace modes for a remote job', async () => {
|
||||
const localClient = createClient().client
|
||||
const { client } = createClient()
|
||||
|
||||
Reference in new issue
Block a user