-
Notifications
You must be signed in to change notification settings - Fork 348
feat(autorun): schedule an Auto Run to start at a specific date/time #1429
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
pedramamini
wants to merge
1
commit into
rc
Choose a base branch
from
feat/716-schedule-auto-run-cue
base: rc
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 all commits
Commits
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
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
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
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,151 @@ | ||
| /** | ||
| * Tests for cue-autorun-executor. | ||
| * | ||
| * The status this executor returns is load-bearing rather than cosmetic: a | ||
| * `time.once` subscription is consumed on any terminal status, so `completed` | ||
| * vs `failed` decides whether a scheduled run that did NOT start survives on | ||
| * disk for the user to find. These tests pin that behavior, plus the fact that | ||
| * the documents launched are the ones captured at schedule time. | ||
| */ | ||
|
|
||
| import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
| import type { BrowserWindow } from 'electron'; | ||
| import type { CueEvent, CueSubscription } from '../../../main/cue/cue-types'; | ||
| import type { SessionInfo } from '../../../shared/types'; | ||
|
|
||
| const launchCueAutoRunMock = vi.fn(); | ||
| vi.mock('../../../main/cue/cue-autorun-bridge', () => ({ | ||
| launchCueAutoRun: (...args: unknown[]) => launchCueAutoRunMock(...args), | ||
| })); | ||
|
|
||
| import { executeCueAutoRun } from '../../../main/cue/cue-autorun-executor'; | ||
|
|
||
| function createSession(): SessionInfo { | ||
| return { | ||
| id: 'session-1', | ||
| name: 'Nightly', | ||
| toolType: 'claude-code', | ||
| cwd: '/tmp/project', | ||
| projectRoot: '/tmp/project', | ||
| }; | ||
| } | ||
|
|
||
| function createSubscription(overrides: Partial<CueSubscription> = {}): CueSubscription { | ||
| return { | ||
| name: 'run-at-6am', | ||
| event: 'time.once', | ||
| enabled: true, | ||
| prompt: '', | ||
| action: 'autorun', | ||
| agent_id: 'session-1', | ||
| auto_run: { documents: ['/proj/Auto Run Docs/ship.md'] }, | ||
| ...overrides, | ||
| } as CueSubscription; | ||
| } | ||
|
|
||
| const event = { type: 'time.once', payload: {} } as unknown as CueEvent; | ||
| const mainWindow = {} as BrowserWindow; | ||
|
|
||
| describe('executeCueAutoRun', () => { | ||
| beforeEach(() => { | ||
| launchCueAutoRunMock.mockReset(); | ||
| }); | ||
|
|
||
| it('launches the documents captured on the subscription', async () => { | ||
| launchCueAutoRunMock.mockResolvedValue({ success: true }); | ||
|
|
||
| const result = await executeCueAutoRun({ | ||
| runId: 'run-1', | ||
| session: createSession(), | ||
| subscription: createSubscription(), | ||
| event, | ||
| autoRun: { | ||
| documents: ['/proj/Auto Run Docs/a.md', '/proj/Auto Run Docs/b.md'], | ||
| reset_on_completion: [false, true], | ||
| prompt: 'Work the tasks', | ||
| loop_enabled: true, | ||
| max_loops: 2, | ||
| }, | ||
| mainWindow, | ||
| onLog: vi.fn(), | ||
| }); | ||
|
|
||
| expect(launchCueAutoRunMock).toHaveBeenCalledWith( | ||
| mainWindow, | ||
| expect.objectContaining({ | ||
| sessionId: 'session-1', | ||
| documents: [ | ||
| { filename: '/proj/Auto Run Docs/a.md', resetOnCompletion: false }, | ||
| { filename: '/proj/Auto Run Docs/b.md', resetOnCompletion: true }, | ||
| ], | ||
| prompt: 'Work the tasks', | ||
| loopEnabled: true, | ||
| maxLoops: 2, | ||
| }) | ||
| ); | ||
| expect(result.status).toBe('completed'); | ||
| expect(result.exitCode).toBe(0); | ||
| }); | ||
|
|
||
| it('defaults resetOnCompletion to false when no flags were captured', async () => { | ||
| launchCueAutoRunMock.mockResolvedValue({ success: true }); | ||
|
|
||
| await executeCueAutoRun({ | ||
| runId: 'run-1', | ||
| session: createSession(), | ||
| subscription: createSubscription(), | ||
| event, | ||
| autoRun: { documents: ['/proj/a.md'] }, | ||
| mainWindow, | ||
| onLog: vi.fn(), | ||
| }); | ||
|
|
||
| expect(launchCueAutoRunMock.mock.calls[0][1].documents).toEqual([ | ||
| { filename: '/proj/a.md', resetOnCompletion: false }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('reports `failed` when the renderer does not accept the launch', async () => { | ||
| // This is the case the status semantics exist for: paired with | ||
| // `self_destruct_on_failure: false`, a `failed` status keeps the | ||
| // subscription on disk instead of silently consuming the user's | ||
| // scheduled run. | ||
| launchCueAutoRunMock.mockResolvedValue({ | ||
| success: false, | ||
| error: 'renderer webContents not available', | ||
| }); | ||
|
|
||
| const result = await executeCueAutoRun({ | ||
| runId: 'run-1', | ||
| session: createSession(), | ||
| subscription: createSubscription(), | ||
| event, | ||
| autoRun: { documents: ['/proj/a.md'] }, | ||
| mainWindow, | ||
| onLog: vi.fn(), | ||
| }); | ||
|
|
||
| expect(result.status).toBe('failed'); | ||
| expect(result.exitCode).toBe(1); | ||
| expect(result.stderr).toContain('renderer webContents not available'); | ||
| }); | ||
|
|
||
| it('logs an explanation when the launch fails so the failure is triageable', async () => { | ||
| launchCueAutoRunMock.mockResolvedValue({ success: false, error: 'boom' }); | ||
| const onLog = vi.fn(); | ||
|
|
||
| await executeCueAutoRun({ | ||
| runId: 'run-1', | ||
| session: createSession(), | ||
| subscription: createSubscription(), | ||
| event, | ||
| autoRun: { documents: ['/proj/a.md'] }, | ||
| mainWindow, | ||
| onLog, | ||
| }); | ||
|
|
||
| const errorLogs = onLog.mock.calls.filter(([level]) => level === 'error'); | ||
| expect(errorLogs).toHaveLength(1); | ||
| expect(errorLogs[0][1]).toContain('boom'); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Document failed-launch retention.
The table says that a schedule is gone after it fires. Scheduled Auto Runs use
keepOnFailure: true, so a failed launch remains in Scheduled Tasks for inspection. State that successful one-shot runs are removed, but failed launches are retained.🤖 Prompt for AI Agents