-
Notifications
You must be signed in to change notification settings - Fork 321
Add Paseo schedule commands to Maestro CLI #1030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
IAKGnaHz
wants to merge
3
commits into
RunMaestro:main
Choose a base branch
from
IAKGnaHz:feat/paseo-schedule-cli
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import { describe, it, expect, vi, beforeEach, afterEach, type MockInstance } from 'vitest'; | ||
|
|
||
| vi.mock('../../../cli/services/paseo', () => ({ | ||
| createPaseoSchedule: vi.fn(), | ||
| listPaseoSchedules: vi.fn(), | ||
| getPaseoScheduleLogs: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock('../../../cli/output/formatter', () => ({ | ||
| formatError: vi.fn((message: string) => `Error: ${message}`), | ||
| })); | ||
|
|
||
| import { | ||
| paseoScheduleCreate, | ||
| paseoScheduleList, | ||
| paseoScheduleLogs, | ||
| } from '../../../cli/commands/paseo'; | ||
| import { | ||
| createPaseoSchedule, | ||
| getPaseoScheduleLogs, | ||
| listPaseoSchedules, | ||
| } from '../../../cli/services/paseo'; | ||
|
|
||
| describe('paseo command', () => { | ||
| let consoleSpy: MockInstance; | ||
| let consoleErrorSpy: MockInstance; | ||
| let processExitSpy: MockInstance; | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {}); | ||
| consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}); | ||
| processExitSpy = vi | ||
| .spyOn(process, 'exit') | ||
| .mockImplementation((code?: string | number | null | undefined) => { | ||
| throw new Error(`process.exit(${code})`); | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| consoleSpy.mockRestore(); | ||
| consoleErrorSpy.mockRestore(); | ||
| processExitSpy.mockRestore(); | ||
| }); | ||
|
|
||
| it('creates a Paseo schedule and prints stdout', async () => { | ||
| vi.mocked(createPaseoSchedule).mockResolvedValue({ | ||
| stdout: 'ID NAME\nabc demo\n', | ||
| stderr: '', | ||
| }); | ||
|
|
||
| await paseoScheduleCreate('do work', { | ||
| every: '2m', | ||
| name: 'demo', | ||
| provider: 'codex', | ||
| cwd: '/repo', | ||
| maxRuns: '2', | ||
| expiresIn: '10m', | ||
| }); | ||
|
|
||
| expect(createPaseoSchedule).toHaveBeenCalledWith('do work', { | ||
| every: '2m', | ||
| name: 'demo', | ||
| provider: 'codex', | ||
| cwd: '/repo', | ||
| maxRuns: '2', | ||
| expiresIn: '10m', | ||
| }); | ||
| expect(consoleSpy).toHaveBeenCalledWith('ID NAME\nabc demo'); | ||
| expect(processExitSpy).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('lists schedules', async () => { | ||
| vi.mocked(listPaseoSchedules).mockResolvedValue({ stdout: 'schedules\n', stderr: '' }); | ||
|
|
||
| await paseoScheduleList({ json: true, host: '127.0.0.1:6767' }); | ||
|
|
||
| expect(listPaseoSchedules).toHaveBeenCalledWith({ | ||
| json: true, | ||
| host: '127.0.0.1:6767', | ||
| }); | ||
| expect(consoleSpy).toHaveBeenCalledWith('schedules'); | ||
| }); | ||
|
|
||
| it('shows schedule logs', async () => { | ||
| vi.mocked(getPaseoScheduleLogs).mockResolvedValue({ stdout: 'logs\n', stderr: '' }); | ||
|
|
||
| await paseoScheduleLogs('abc123', { cliPath: '/bin/paseo' }); | ||
|
|
||
| expect(getPaseoScheduleLogs).toHaveBeenCalledWith('abc123', { cliPath: '/bin/paseo' }); | ||
| expect(consoleSpy).toHaveBeenCalledWith('logs'); | ||
| }); | ||
|
|
||
| it('prints JSON errors when json mode is enabled', async () => { | ||
| vi.mocked(listPaseoSchedules).mockRejectedValue(new Error('daemon unavailable')); | ||
|
|
||
| await expect(paseoScheduleList({ json: true })).rejects.toThrow('process.exit(1)'); | ||
|
|
||
| const output = JSON.parse(consoleErrorSpy.mock.calls[0][0]); | ||
| expect(output).toEqual({ success: false, error: 'daemon unavailable' }); | ||
| }); | ||
|
|
||
| it('prints human-readable errors otherwise', async () => { | ||
| vi.mocked(listPaseoSchedules).mockRejectedValue(new Error('daemon unavailable')); | ||
|
|
||
| await expect(paseoScheduleList({})).rejects.toThrow('process.exit(1)'); | ||
|
|
||
| expect(consoleErrorSpy).toHaveBeenCalledWith('Error: daemon unavailable'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; | ||
|
|
||
| vi.mock('fs', () => ({ | ||
| statSync: vi.fn(), | ||
| accessSync: vi.fn(), | ||
| constants: { X_OK: 1 }, | ||
| })); | ||
|
|
||
| vi.mock('os', () => ({ | ||
| platform: vi.fn(() => 'darwin'), | ||
| })); | ||
|
|
||
| vi.mock('child_process', () => ({ | ||
| spawn: vi.fn(), | ||
| })); | ||
|
|
||
| import { EventEmitter } from 'events'; | ||
| import { Readable } from 'stream'; | ||
| import * as fs from 'fs'; | ||
| import * as os from 'os'; | ||
| import { spawn } from 'child_process'; | ||
| import { | ||
| createPaseoSchedule, | ||
| getPaseoScheduleLogs, | ||
| listPaseoSchedules, | ||
| resolvePaseoCliPath, | ||
| runPaseoCommand, | ||
| } from '../../../cli/services/paseo'; | ||
|
|
||
| function mockSpawnResult(code: number, stdout = '', stderr = ''): void { | ||
| const child = new EventEmitter() as EventEmitter & { | ||
| stdout: Readable; | ||
| stderr: Readable; | ||
| }; | ||
| child.stdout = new Readable({ read() {} }); | ||
| child.stderr = new Readable({ read() {} }); | ||
|
|
||
| vi.mocked(spawn).mockReturnValue(child as any); | ||
|
|
||
| setImmediate(() => { | ||
| if (stdout) child.stdout.emit('data', Buffer.from(stdout)); | ||
| if (stderr) child.stderr.emit('data', Buffer.from(stderr)); | ||
| child.emit('close', code); | ||
| }); | ||
| } | ||
|
|
||
| describe('paseo service', () => { | ||
| const originalEnv = process.env.PASEO_CLI_PATH; | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| delete process.env.PASEO_CLI_PATH; | ||
| vi.mocked(os.platform).mockReturnValue('darwin'); | ||
| vi.mocked(fs.statSync).mockReturnValue({ isFile: () => true } as any); | ||
| vi.mocked(fs.accessSync).mockReturnValue(undefined); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| if (originalEnv === undefined) { | ||
| delete process.env.PASEO_CLI_PATH; | ||
| } else { | ||
| process.env.PASEO_CLI_PATH = originalEnv; | ||
| } | ||
| }); | ||
|
|
||
| it('prefers an explicit CLI path', () => { | ||
| expect(resolvePaseoCliPath('/tmp/paseo')).toBe('/tmp/paseo'); | ||
| }); | ||
|
|
||
| it('uses PASEO_CLI_PATH before bundled defaults', () => { | ||
| process.env.PASEO_CLI_PATH = '/env/paseo'; | ||
| expect(resolvePaseoCliPath()).toBe('/env/paseo'); | ||
| }); | ||
|
|
||
| it('uses the macOS bundled Paseo CLI when executable', () => { | ||
| expect(resolvePaseoCliPath()).toBe('/Applications/Paseo.app/Contents/Resources/bin/paseo'); | ||
| }); | ||
|
|
||
| it('falls back to PATH command when bundled CLI is unavailable', () => { | ||
| vi.mocked(fs.statSync).mockImplementation(() => { | ||
| throw new Error('missing'); | ||
| }); | ||
| expect(resolvePaseoCliPath()).toBe('paseo'); | ||
| }); | ||
|
|
||
| it('runs Paseo commands and returns output', async () => { | ||
| mockSpawnResult(0, 'ok\n', 'warn\n'); | ||
|
|
||
| const result = await runPaseoCommand(['schedule', 'ls'], { cliPath: '/bin/paseo' }); | ||
|
|
||
| expect(spawn).toHaveBeenCalledWith('/bin/paseo', ['schedule', 'ls'], { | ||
| env: process.env, | ||
| stdio: ['ignore', 'pipe', 'pipe'], | ||
| }); | ||
| expect(result).toEqual({ stdout: 'ok\n', stderr: 'warn\n' }); | ||
| }); | ||
|
|
||
| it('rejects failed Paseo commands with stderr and exit code', async () => { | ||
| mockSpawnResult(2, '', 'bad option\n'); | ||
|
|
||
| await expect(runPaseoCommand(['bad'], { cliPath: '/bin/paseo' })).rejects.toThrow('bad option'); | ||
| }); | ||
|
|
||
| it('builds schedule create arguments', async () => { | ||
| mockSpawnResult(0, 'created\n'); | ||
|
|
||
| await createPaseoSchedule('do work', { | ||
| cliPath: '/bin/paseo', | ||
| every: '2m', | ||
| name: 'demo', | ||
| provider: 'codex', | ||
| cwd: '/repo', | ||
| maxRuns: '2', | ||
| expiresIn: '10m', | ||
| json: true, | ||
| }); | ||
|
|
||
| expect(spawn).toHaveBeenCalledWith( | ||
| '/bin/paseo', | ||
| [ | ||
| 'schedule', | ||
| 'create', | ||
| '--every', | ||
| '2m', | ||
| '--name', | ||
| 'demo', | ||
| '--provider', | ||
| 'codex', | ||
| '--cwd', | ||
| '/repo', | ||
| '--max-runs', | ||
| '2', | ||
| '--expires-in', | ||
| '10m', | ||
| '--json', | ||
| 'do work', | ||
| ], | ||
| expect.any(Object) | ||
| ); | ||
| }); | ||
|
|
||
| it('builds schedule list and logs arguments', async () => { | ||
| mockSpawnResult(0, ''); | ||
| await listPaseoSchedules({ cliPath: '/bin/paseo', host: '127.0.0.1:6767' }); | ||
|
|
||
| expect(spawn).toHaveBeenLastCalledWith( | ||
| '/bin/paseo', | ||
| ['schedule', 'ls', '--host', '127.0.0.1:6767'], | ||
| expect.any(Object) | ||
| ); | ||
|
|
||
| mockSpawnResult(0, ''); | ||
| await getPaseoScheduleLogs('abc123', { cliPath: '/bin/paseo', json: true }); | ||
|
|
||
| expect(spawn).toHaveBeenLastCalledWith( | ||
| '/bin/paseo', | ||
| ['schedule', 'logs', '--json', 'abc123'], | ||
| expect.any(Object) | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // Paseo command group for Maestro CLI | ||
|
|
||
| import { | ||
| createPaseoSchedule, | ||
| getPaseoScheduleLogs, | ||
| listPaseoSchedules, | ||
| type PaseoCommandResult, | ||
| } from '../services/paseo'; | ||
| import { formatError } from '../output/formatter'; | ||
|
|
||
| interface PaseoBaseOptions { | ||
| cliPath?: string; | ||
| host?: string; | ||
| json?: boolean; | ||
| } | ||
|
|
||
| interface PaseoScheduleCreateCommandOptions extends PaseoBaseOptions { | ||
| every?: string; | ||
| cron?: string; | ||
| name?: string; | ||
| target?: string; | ||
| provider?: string; | ||
| mode?: string; | ||
| cwd?: string; | ||
| maxRuns?: string; | ||
| expiresIn?: string; | ||
| runNow?: boolean; | ||
| noRunNow?: boolean; | ||
| } | ||
|
|
||
| function printResult(result: PaseoCommandResult): void { | ||
| if (result.stdout.trim()) { | ||
| console.log(result.stdout.trimEnd()); | ||
| } | ||
| if (result.stderr.trim()) { | ||
| console.error(result.stderr.trimEnd()); | ||
| } | ||
| } | ||
|
|
||
| function printError(error: unknown, json?: boolean): void { | ||
| const message = error instanceof Error ? error.message : 'Unknown error'; | ||
| if (json) { | ||
| console.error(JSON.stringify({ success: false, error: message }, null, 2)); | ||
| } else { | ||
| console.error(formatError(message)); | ||
| } | ||
| process.exit(1); | ||
| } | ||
|
|
||
| export async function paseoScheduleCreate( | ||
| prompt: string, | ||
| options: PaseoScheduleCreateCommandOptions | ||
| ): Promise<void> { | ||
| try { | ||
| const result = await createPaseoSchedule(prompt, options); | ||
| printResult(result); | ||
| } catch (error) { | ||
| printError(error, options.json); | ||
| } | ||
| } | ||
|
|
||
| export async function paseoScheduleList(options: PaseoBaseOptions): Promise<void> { | ||
| try { | ||
| const result = await listPaseoSchedules(options); | ||
| printResult(result); | ||
| } catch (error) { | ||
| printError(error, options.json); | ||
| } | ||
| } | ||
|
|
||
| export async function paseoScheduleLogs( | ||
| scheduleId: string, | ||
| options: PaseoBaseOptions | ||
| ): Promise<void> { | ||
| try { | ||
| const result = await getPaseoScheduleLogs(scheduleId, options); | ||
| printResult(result); | ||
| } catch (error) { | ||
| printError(error, options.json); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Integrate Sentry for error tracking as required by coding guidelines.
All three command handlers catch errors without using Sentry utilities for production error tracking. As per coding guidelines, unexpected errors should be reported to Sentry for observability, even in CLI contexts.
Consider:
captureExceptionfromsrc/utils/sentry.tscaptureException(error)with appropriate context beforeprintErrorAlternatively, if all CLI errors should be tracked in production, add
captureException(error)at the start of each catch block.As per coding guidelines: "Use Sentry utilities (
captureException,captureMessage) fromsrc/utils/sentry.tsfor explicit error reporting with context."Also applies to: 63-68, 75-80
🤖 Prompt for AI Agents