Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 349
Add lazy workflow and step discovery in Next.js#640
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
0498a48
Add lazy workflow and step discovery in Next.js
ijjk 9147a93
fix nitro builder name
ijjk 01e6ddc
updates from review
ijjk 2386ca9
update dev tests
ijjk 48ce295
fix source map issue and stdlib discovery
ijjk 6c44ef1
update tests and deduping
ijjk 1707672
update logs and fixture
ijjk 41aba42
remove arbitrary timeout
ijjk 625037c
update socket path for windows
ijjk 4480408
update sock
ijjk ff0a669
use a port instead of socket path
ijjk 43e7546
skip cache
ijjk 4848acc
update stdlib discovering
ijjk a24d063
updates
ijjk 5cebfeb
update resolving
ijjk ef2a5ed
temp fixes
ijjk bb68808
set config to avoid scope hoisting issue
ijjk b11d7e8
bump
ijjk ea47de8
add log
ijjk 3eded37
adjust debounce
ijjk 730e71a
always give heartbeat from loader
ijjk 1da5189
update
ijjk 3f1ac4f
remove condition
ijjk 3c3bba0
add warning
ijjk df01356
only recompile if workflow related event
ijjk 88dcb1b
add socket validation and comments from review
ijjk 60eaeb3
cleanup and fix warning
ijjk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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,6 @@ | ||
| --- | ||
| "@workflow/builders": patch | ||
| "@workflow/next": patch | ||
| --- | ||
| Add lazy workflow and step discovery in Next.js |
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
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import fs from 'fs/promises'; | ||
| import path from 'path'; | ||
| import fs from 'node:fs/promises'; | ||
| import path from 'node:path'; | ||
| import { afterEach, describe, expect, test } from 'vitest'; | ||
| import { getWorkbenchAppPath } from './utils'; | ||
| @@ -44,6 +44,14 @@ export function createDevTests(config?: DevTestConfig) { | ||
| const workflowsDir = finalConfig.workflowsDir ?? 'workflows'; | ||
| const restoreFiles: Array<{ path: string; content: string }> = []; | ||
| const warmEndpoint = async () => { | ||
ijjk marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // Warm up the Next.js routes to trigger lazy workflow/step discovery and compilation. | ||
| // This is only required for tests that respond to file updates (HMR tests). | ||
| // Without this, the routes won't be built yet and file change detection won't work. | ||
| await fetch(new URL('/api/trigger', process.env.DEPLOYMENT_URL)); | ||
| await fetch(new URL('/api/chat', process.env.DEPLOYMENT_URL)); | ||
| }; | ||
| afterEach(async () => { | ||
| await Promise.all( | ||
| restoreFiles.map(async (item) => { | ||
| @@ -54,58 +62,61 @@ export function createDevTests(config?: DevTestConfig) { | ||
| } | ||
| }) | ||
| ); | ||
| await warmEndpoint(); | ||
| restoreFiles.length = 0; | ||
| }); | ||
| test('should rebuild on workflow change', { timeout: 30_000 }, async () => { | ||
| const workflowFile = path.join(appPath, workflowsDir, testWorkflowFile); | ||
| test('should rebuild on step change', { timeout: 15_000 }, async () => { | ||
| const stepFile = path.join(appPath, workflowsDir, testWorkflowFile); | ||
| const content = await fs.readFile(workflowFile, 'utf8'); | ||
| const content = await fs.readFile(stepFile, 'utf8'); | ||
| await fs.writeFile( | ||
| workflowFile, | ||
| stepFile, | ||
| `${content} | ||
| export async function myNewWorkflow() { | ||
| 'use workflow' | ||
| export async function myNewStep() { | ||
| 'use step' | ||
| return 'hello world' | ||
| } | ||
| ` | ||
| ); | ||
| restoreFiles.push({ path: workflowFile, content }); | ||
| restoreFiles.push({ path: stepFile, content }); | ||
| while (true) { | ||
| try { | ||
| const workflowContent = await fs.readFile(generatedWorkflow, 'utf8'); | ||
| expect(workflowContent).toContain('myNewWorkflow'); | ||
| await warmEndpoint(); | ||
| const workflowContent = await fs.readFile(generatedStep, 'utf8'); | ||
| expect(workflowContent).toContain('myNewStep'); | ||
| break; | ||
| } catch (_) { | ||
| await new Promise((res) => setTimeout(res, 1_000)); | ||
| } | ||
| } | ||
| }); | ||
| test('should rebuild on step change', { timeout: 30_000 }, async () => { | ||
| const stepFile = path.join(appPath, workflowsDir, testWorkflowFile); | ||
| test('should rebuild on workflow change', { timeout: 15_000 }, async () => { | ||
| const workflowFile = path.join(appPath, workflowsDir, testWorkflowFile); | ||
| const content = await fs.readFile(stepFile, 'utf8'); | ||
| const content = await fs.readFile(workflowFile, 'utf8'); | ||
| await fs.writeFile( | ||
| stepFile, | ||
| workflowFile, | ||
| `${content} | ||
| export async function myNewStep() { | ||
| 'use step' | ||
| export async function myNewWorkflow() { | ||
| 'use workflow' | ||
| return 'hello world' | ||
| } | ||
| ` | ||
| ); | ||
| restoreFiles.push({ path: stepFile, content }); | ||
| restoreFiles.push({ path: workflowFile, content }); | ||
| while (true) { | ||
| try { | ||
| const workflowContent = await fs.readFile(generatedStep, 'utf8'); | ||
| expect(workflowContent).toContain('myNewStep'); | ||
| await warmEndpoint(); | ||
| const workflowContent = await fs.readFile(generatedWorkflow, 'utf8'); | ||
| expect(workflowContent).toContain('myNewWorkflow'); | ||
| break; | ||
| } catch (_) { | ||
| await new Promise((res) => setTimeout(res, 1_000)); | ||
| @@ -115,7 +126,7 @@ export async function myNewStep() { | ||
| test( | ||
| 'should rebuild on adding workflow file', | ||
| { timeout: 30_000 }, | ||
| { timeout: 15_000 }, | ||
| async () => { | ||
| const workflowFile = path.join( | ||
| appPath, | ||
| @@ -131,11 +142,11 @@ export async function myNewStep() { | ||
| } | ||
| ` | ||
| ); | ||
| restoreFiles.push({ path: workflowFile, content: '' }); | ||
| const apiFile = path.join(appPath, finalConfig.apiFilePath); | ||
| const apiFileContent = await fs.readFile(apiFile, 'utf8'); | ||
| restoreFiles.push({ path: apiFile, content: apiFileContent }); | ||
| restoreFiles.push({ path: workflowFile, content: '' }); | ||
| await fs.writeFile( | ||
| apiFile, | ||
| @@ -145,6 +156,7 @@ ${apiFileContent}` | ||
| while (true) { | ||
| try { | ||
| await warmEndpoint(); | ||
| const workflowContent = await fs.readFile( | ||
| generatedWorkflow, | ||
| 'utf8' | ||
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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.