Normalize Workbenches#283
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: eb0931e The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
a11298d to
e75af80
Compare
There was a problem hiding this comment.
🔧 Build Fix:
The import path ../../../_workflows is incorrect and points one directory level too shallow, causing the build to fail when trying to resolve the _workflows module.
View Details
📝 Patch Details
diff --git a/workbench/sveltekit/src/routes/api/trigger/+server.ts b/workbench/sveltekit/src/routes/api/trigger/+server.ts
index e0940ab..d0860ba 100644
--- a/workbench/sveltekit/src/routes/api/trigger/+server.ts
+++ b/workbench/sveltekit/src/routes/api/trigger/+server.ts
@@ -1,7 +1,7 @@
import { json, type RequestHandler } from '@sveltejs/kit';
import { getRun, start } from 'workflow/api';
import { hydrateWorkflowArguments } from 'workflow/internal/serialization';
-import { allWorkflows } from '../../../_workflows';
+import { allWorkflows } from '../../../../_workflows';
export const POST: RequestHandler = async ({ request }) => {
const url = new URL(request.url);
Analysis
Incorrect relative import path causes module resolution failure
What fails: TypeScript/Rollup build fails on src/routes/api/trigger/+server.ts due to incorrect relative import path for _workflows module
How to reproduce:
cd workbench/sveltekit && pnpm run buildResult:
error during build:
Could not resolve "../../../_workflows" from "src/routes/api/trigger/+server.ts"
Expected behavior: The import should resolve to the _workflows.ts file in the project root directory.
e75af80 to
c44f1f3
Compare
There was a problem hiding this comment.
🔧 Build Fix:
The import path ../../../../workflows/user-signup is incorrect and cannot be resolved during build. The correct relative path should be ../../../workflows/user-signup to properly import from the src/workflows/user-signup.ts file.
View Details
📝 Patch Details
diff --git a/workbench/sveltekit/src/routes/api/signup/+server.ts b/workbench/sveltekit/src/routes/api/signup/+server.ts
index 8e76aaf..c15d48d 100644
--- a/workbench/sveltekit/src/routes/api/signup/+server.ts
+++ b/workbench/sveltekit/src/routes/api/signup/+server.ts
@@ -1,6 +1,6 @@
import { json, type RequestHandler } from '@sveltejs/kit';
import { start } from 'workflow/api';
-import { handleUserSignup } from '../../../../workflows/user-signup';
+import { handleUserSignup } from '../../../workflows/user-signup';
export const GET: RequestHandler = async ({
request,
Analysis
Import resolution failure in SvelteKit API route
What fails: SvelteKit build fails with module resolution error in src/routes/api/signup/+server.ts due to incorrect relative import path
How to reproduce:
pnpm run build --filter @workflow/example-sveltekitResult:
Could not resolve "../../../../workflows/user-signup" from "src/routes/api/signup/+server.ts"
Root cause: The import path ../../../../workflows/user-signup attempts to resolve to workbench/sveltekit/workflows/user-signup.ts (which doesn't exist) instead of the actual file location at workbench/sveltekit/src/workflows/user-signup.ts. The correct relative path should be ../../../workflows/user-signup.
There was a problem hiding this comment.
🔧 Build Fix:
The import path ../../../../workflows/3_streams is incorrect and points to a non-existent directory, causing module resolution to fail during build.
View Details
📝 Patch Details
diff --git a/workbench/sveltekit/src/routes/api/chat/+server.ts b/workbench/sveltekit/src/routes/api/chat/+server.ts
index 3e2b41d..73efee8 100644
--- a/workbench/sveltekit/src/routes/api/chat/+server.ts
+++ b/workbench/sveltekit/src/routes/api/chat/+server.ts
@@ -2,7 +2,7 @@
// TO IMPORT THE WORKFLOWS TO DISCOVER THEM AND WATCH
import { json, type RequestHandler } from '@sveltejs/kit';
-import * as workflows from '../../../../workflows/3_streams';
+import * as workflows from '../../../workflows/3_streams';
export const POST: RequestHandler = async ({
request,
Analysis
Incorrect import path causes build failure
What fails: SvelteKit build fails due to incorrect import path in src/routes/api/chat/+server.ts trying to import from non-existent ../../../../workflows/3_streams
How to reproduce:
cd workbench/sveltekit
npx tsc --noEmit --skipLibCheck src/routes/api/chat/+server.tsResult:
error TS2307: Cannot find module '../../../../workflows/3_streams' or its corresponding type declarations.Fix: Changed import path from ../../../../workflows/3_streams to ../../../workflows/3_streams to correctly reference the symlinked workflow file in src/workflows/3_streams.ts.
| @@ -0,0 +1,7 @@ | |||
| --- | |||
| }); | ||
|
|
||
| // Test route for calling step functions directly outside workflow context | ||
| app.post('/api/test-direct-step-call', async ({ req }) => { |
There was a problem hiding this comment.
This is checked in the e2e tests
| @@ -0,0 +1,8 @@ | |||
| // THIS FILE IS JUST FOR TESTING HMR AS AN ENTRY NEEDS | |||
There was a problem hiding this comment.
I dropped the symlink for the entire api directory and jsut copied the files from nextjs-turbopack to prevent symlink based errors for webpack
| @@ -0,0 +1,9 @@ | |||
| // THIS FILE IS JUST FOR TESTING HMR AS AN ENTRY NEEDS | |||
There was a problem hiding this comment.
like webpack, I dropped the symlink and just implemented the routes directly.
otherwise, it doens't work properly with the now generated _workflow.ts file
There was a problem hiding this comment.
🔧 Build Fix:
TypeScript compilation fails because the code tries to assign errorCode properties to WorkflowRun and Step objects, but these properties don't exist in their type definitions.
View Details
📝 Patch Details
diff --git a/packages/world-local/src/storage.ts b/packages/world-local/src/storage.ts
index 2292832..7c99382 100644
--- a/packages/world-local/src/storage.ts
+++ b/packages/world-local/src/storage.ts
@@ -112,7 +112,6 @@ export function createStorage(basedir: string): Storage {
input: (data.input as any[]) || [],
output: undefined,
error: undefined,
- errorCode: undefined,
startedAt: undefined,
completedAt: undefined,
createdAt: now,
@@ -234,7 +233,6 @@ export function createStorage(basedir: string): Storage {
input: data.input as any[],
output: undefined,
error: undefined,
- errorCode: undefined,
attempt: 0,
startedAt: undefined,
completedAt: undefined,
Analysis
TypeScript compilation failure due to undefined errorCode properties
What fails: TypeScript compiler fails on packages/world-local/src/storage.ts lines 115 and 237 due to errorCode property assignments that don't exist in WorkflowRun and Step type definitions
How to reproduce:
cd packages/world-local && pnpm run buildResult:
src/storage.ts(115,11): error TS2353: Object literal may only specify known properties, and 'errorCode' does not exist in type '{ runId: string; deploymentId: string; status: "pending" | "running" | "completed" | "failed" | "paused" | "cancelled"; workflowName: string; input: any[]; createdAt: Date; updatedAt: Date; ... 4 more ...; completedAt?: Date | undefined; }'.
src/storage.ts(237,11): error TS2353: Object literal may only specify known properties, and 'errorCode' does not exist in type '{ runId: string; stepId: string; stepName: string; status: "pending" | "running" | "completed" | "failed" | "cancelled"; input: any[]; attempt: number; createdAt: Date; updatedAt: Date; ... 4 more ...; retryAfter?: Date | undefined; }'.There was a problem hiding this comment.
Additional Suggestions:
- The workflow imports in this file use incorrect relative paths that point to the old workflow locations before they were moved to
src/workflows/in this PR.
View Details
📝 Patch Details
diff --git a/workbench/sveltekit/src/routes/api/test-direct-step-call/+server.ts b/workbench/sveltekit/src/routes/api/test-direct-step-call/+server.ts
index 1aef582..d249bb8 100644
--- a/workbench/sveltekit/src/routes/api/test-direct-step-call/+server.ts
+++ b/workbench/sveltekit/src/routes/api/test-direct-step-call/+server.ts
@@ -3,7 +3,7 @@
// and keep their original implementation, allowing them to be called as regular async functions
import { json, type RequestHandler } from '@sveltejs/kit';
-import { add } from '../../../../workflows/99_e2e.js';
+import { add } from '../../../workflows/99_e2e.js';
export const POST: RequestHandler = async ({ request }) => {
const body = await request.json();
diff --git a/workbench/sveltekit/src/routes/api/trigger/+server.ts b/workbench/sveltekit/src/routes/api/trigger/+server.ts
index 4b38f05..1f4d1b2 100644
--- a/workbench/sveltekit/src/routes/api/trigger/+server.ts
+++ b/workbench/sveltekit/src/routes/api/trigger/+server.ts
@@ -1,10 +1,10 @@
import { json, type RequestHandler } from '@sveltejs/kit';
import { getRun, start } from 'workflow/api';
import { hydrateWorkflowArguments } from 'workflow/internal/serialization';
-import * as calcWorkflow from '../../../../workflows/0_calc';
-import * as batchingWorkflow from '../../../../workflows/6_batching';
-import * as duplicateE2e from '../../../../workflows/98_duplicate_case';
-import * as e2eWorkflows from '../../../../workflows/99_e2e';
+import * as calcWorkflow from '../../../workflows/0_calc';
+import * as batchingWorkflow from '../../../workflows/6_batching';
+import * as duplicateE2e from '../../../workflows/98_duplicate_case';
+import * as e2eWorkflows from '../../../workflows/99_e2e';
import {
WorkflowRunFailedError,
WorkflowRunNotCompletedError,
Analysis
Incorrect workflow import paths in API route handlers
What fails: Module imports fail at runtime because import paths in src/routes/api/trigger/+server.ts and src/routes/api/test-direct-step-call/+server.ts point to a non-existent workbench/sveltekit/workflows/ directory instead of the actual workbench/sveltekit/src/workflows/ directory where workflows were moved.
How to reproduce: The imports on lines 4-7 of src/routes/api/trigger/+server.ts use:
import * as calcWorkflow from '../../../../workflows/0_calc';From file location src/routes/api/trigger/+server.ts, the path ../../../../workflows/ resolves to workbench/sveltekit/workflows/ (which doesn't exist). Running the development server and making a request to /api/trigger will fail with module not found errors.
Result: Module resolution fails; cannot load workflow modules
Expected: Imports should use ../../../workflows/ to correctly resolve to workbench/sveltekit/src/workflows/ where the workflows actually exist. This matches the pattern correctly used in src/routes/api/chat/+server.ts and src/routes/api/signup/+server.ts.
Files fixed:
workbench/sveltekit/src/routes/api/trigger/+server.ts(lines 4-7: changed../../../../workflows/to../../../workflows/)workbench/sveltekit/src/routes/api/test-direct-step-call/+server.ts(line 5: changed../../../../workflows/to../../../workflows/)
View Details
📝 Patch Details
diff --git a/workbench/sveltekit/src/routes/api/test-direct-step-call/+server.ts b/workbench/sveltekit/src/routes/api/test-direct-step-call/+server.ts
index 1aef582..d249bb8 100644
--- a/workbench/sveltekit/src/routes/api/test-direct-step-call/+server.ts
+++ b/workbench/sveltekit/src/routes/api/test-direct-step-call/+server.ts
@@ -3,7 +3,7 @@
// and keep their original implementation, allowing them to be called as regular async functions
import { json, type RequestHandler } from '@sveltejs/kit';
-import { add } from '../../../../workflows/99_e2e.js';
+import { add } from '../../../workflows/99_e2e.js';
export const POST: RequestHandler = async ({ request }) => {
const body = await request.json();
diff --git a/workbench/sveltekit/src/routes/api/trigger/+server.ts b/workbench/sveltekit/src/routes/api/trigger/+server.ts
index 4b38f05..1f4d1b2 100644
--- a/workbench/sveltekit/src/routes/api/trigger/+server.ts
+++ b/workbench/sveltekit/src/routes/api/trigger/+server.ts
@@ -1,10 +1,10 @@
import { json, type RequestHandler } from '@sveltejs/kit';
import { getRun, start } from 'workflow/api';
import { hydrateWorkflowArguments } from 'workflow/internal/serialization';
-import * as calcWorkflow from '../../../../workflows/0_calc';
-import * as batchingWorkflow from '../../../../workflows/6_batching';
-import * as duplicateE2e from '../../../../workflows/98_duplicate_case';
-import * as e2eWorkflows from '../../../../workflows/99_e2e';
+import * as calcWorkflow from '../../../workflows/0_calc';
+import * as batchingWorkflow from '../../../workflows/6_batching';
+import * as duplicateE2e from '../../../workflows/98_duplicate_case';
+import * as e2eWorkflows from '../../../workflows/99_e2e';
import {
WorkflowRunFailedError,
WorkflowRunNotCompletedError,
Analysis
Incorrect workflow import paths in API route files
What fails: Two API route files use incorrect relative import paths that point to non-existent workflow locations, causing module resolution failures at type-check time.
How to reproduce:
cd workbench/sveltekit
pnpm checkResult: Type checker reports "Cannot find module" errors:
/src/routes/api/test-direct-step-call/+server.ts:6- Cannot find module../../../../workflows/99_e2e.js/src/routes/api/trigger/+server.ts:4-7- Cannot find modules../../../../workflows/0_calc,../../../../workflows/6_batching,../../../../workflows/98_duplicate_case,../../../../workflows/99_e2e
Expected: Imports should resolve to the workflows located in src/workflows/ directory, which require the path ../../../workflows/ from the route files (all at src/routes/api/*/+server.ts).
Fixed: Changed import paths in both files from ../../../../workflows/ to ../../../workflows/ to match the correct directory structure and align with the working imports in chat/+server.ts and signup/+server.ts.
There was a problem hiding this comment.
🔧 Build Fix:
The completedAt getter has a type mismatch where the discriminated union returns void for non-final workflow states, but the getter expects Date | undefined.
View Details
📝 Patch Details
diff --git a/packages/core/src/runtime.ts b/packages/core/src/runtime.ts
index 069accb..b428ee2 100644
--- a/packages/core/src/runtime.ts
+++ b/packages/core/src/runtime.ts
@@ -158,7 +158,7 @@ export class Run<TResult> {
* Returns undefined if the workflow has not completed yet.
*/
get completedAt(): Promise<Date | undefined> {
- return this.world.runs.get(this.runId).then((run) => run.completedAt);
+ return this.world.runs.get(this.runId).then((run) => run.completedAt || undefined);
}
/**
Analysis
TypeScript compilation failure in @workflow/core
What fails: TypeScript compiler fails on packages/core/src/runtime.ts line 161 due to type mismatch
How to reproduce:
npx turbo run build --filter="@workflow/core"Result:
@workflow/core:build: src/runtime.ts(161,5): error TS2322: Type 'Promise<void | Date | undefined>' is not assignable to type 'Promise<Date | undefined>'.
@workflow/core:build: Type 'void | Date | undefined' is not assignable to type 'Date | undefined'.
@workflow/core:build: Type 'void' is not assignable to type 'Date | undefined'.|
|
| if (builder) { | ||
| await builder.build(); | ||
| } |
There was a problem hiding this comment.
The hotUpdate hook in the Nitro Vite plugin calls builder.build() without error handling when a workflow file changes. This can cause unhandled promise rejections that crash the dev server.
View Details
📝 Patch Details
diff --git a/packages/nitro/src/vite.ts b/packages/nitro/src/vite.ts
index f210250..971b40e 100644
--- a/packages/nitro/src/vite.ts
+++ b/packages/nitro/src/vite.ts
@@ -77,7 +77,13 @@ export function workflow(options?: ModuleOptions): Plugin[] {
// File might have been deleted - trigger rebuild to update generated routes
console.log('Workflow file deleted, rebuilding...');
if (builder) {
- await builder.build();
+ try {
+ await builder.build();
+ } catch (buildError) {
+ // Build might fail if files are being deleted during test cleanup
+ // Log but don't crash - the next successful change will trigger a rebuild
+ console.error('Build failed during file deletion:', buildError);
+ }
}
// NOTE: Might be too aggressive
server.ws.send({
@@ -101,7 +107,14 @@ export function workflow(options?: ModuleOptions): Plugin[] {
// which will rebuild workflows and update routes
console.log('Workflow file changed, rebuilding...');
if (builder) {
- await builder.build();
+ try {
+ await builder.build();
+ } catch (buildError) {
+ // Build might fail if files are being modified/deleted during test cleanup
+ // Log but don't crash - the next successful change will trigger a rebuild
+ console.error('Build failed during HMR:', buildError);
+ return;
+ }
}
server.ws.send({
type: 'full-reload',
Analysis
Unhandled builder.build() errors in Nitro Vite plugin hotUpdate hook
What fails: The Nitro Vite plugin's hotUpdate handler at lines 80 and 104 calls await builder.build() without error handling. When builder.build() throws an error (e.g., from esbuild compilation failures during file modifications), this causes an unhandled promise rejection that can crash or destabilize the Vite dev server.
How to reproduce:
- Start Nitro dev server with the workflow plugin enabled
- Create a syntax error in a workflow file (e.g., a file containing
'use workflow') - The
hotUpdatehook triggers builder.build() - Builder fails due to syntax error in esbuild compilation
- The unhandled promise rejection crashes the dev server or logs an unhandled rejection warning
Result: Dev server crashes or becomes unstable with unhandled promise rejection. Server logs show rejection from builder.build() without proper error handling.
Expected: Errors from builder.build() should be caught, logged, and gracefully handled without crashing the dev server. A page reload should still be triggered to allow developers to fix the error and recover.
Evidence: The SvelteKit plugin in the same codebase (packages/sveltekit/src/plugin.ts, lines 141-148 and 149-159) implements identical logic with proper try-catch error handling around both builder.build() calls. These were added in commit b2c6e3b ("fix: normalize workbench tests #292") along with comments noting "Build might fail if files are being deleted during test cleanup". The Nitro plugin was not updated in that commit despite having the same vulnerability pattern. Per Vite issue #20835 and PR #18713, unhandled errors in plugin hooks can cause issues - Vite itself fixed similar unhandled rejection bugs in its full reload handler.
Normalize trigger scripts across workbenches fix: include hono in local build test test: include src dir for test test: add workflow dir config in test to fix sveltekit dev tests add temp 7_full in example wokrflow format fix(sveltekit): detecting workflow folders and customizable dir Remove 7_full and 1_simple error replace API symlink in webpack workbench Fix sveltekit and vite tests Fix sveltekit symlinks Test fixes Fix sveltekit workflows path Dont symlink routes in vite Include e2e tests for hono and vite fix error tests post normalization wip - attempted fixes
* Proper stacktrace propogation in world Proper stacktrace propogation in world * Standardize the error type in the world spec * Normalize Workbenches Normalize trigger scripts across workbenches fix: include hono in local build test test: include src dir for test test: add workflow dir config in test to fix sveltekit dev tests add temp 7_full in example wokrflow format fix(sveltekit): detecting workflow folders and customizable dir Remove 7_full and 1_simple error replace API symlink in webpack workbench Fix sveltekit and vite tests Fix sveltekit symlinks Test fixes Fix sveltekit workflows path Dont symlink routes in vite Include e2e tests for hono and vite * fix error tests post normalization * fix(sveltekit): reading file on hmr delete * changeset * fix(vite): add resolve symlink script * fix(vite): missing building on hmr * test local builder in vite * test: increase timeout on hookWorkflow * test: ignore vite based apps in crossFileWorkflow * test: fix nitro based apps status codes * fix: intercept default vite spa handler on 404 workflow routes * fix: vite hook route returning 422 * test: use 422 for hookWorkflow expected * test: fix hono returning 404 * chore: add comment to middleware to clarify * make api route for duplicate case * revert * revert: nitro builder * add back nitro unhandled rejection logic * test: add hono * changeset * fix: unused method * fix: remove duplicate import * remove * chore: add comments to clarify * test remove vite symlink script --------- Co-authored-by: Pranay Prakash <pranay.gp@gmail.com>
* fix: add sveltekit server routes to builder * fix: remove root workflow dir check * fix missing root level workflow route * Fix: The constructor now hardcodes `dirs: ['src/routes', 'src/lib']` which silently ignores any user\-provided `dirs` option passed to the plugin\, breaking the documented API and removing support for custom workflow directories\. * Fix: The test expectations don\'t match the new implementation of `getWorkflowDirs()`\. The mock provides `scanDirs` which the new code no longer uses\, and the new implementation adds scanning of `routesDir` and `apiDir` instead\. * fix(nitro): use src dir --------- Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com> Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>


The various workbenches have gone out of sync. Just trying to normalize and clean them up for better testing and internal DX
This is part 3 of 3 in a stack made with GitButler: