Skip to content
5 changes: 5 additions & 0 deletions .changeset/slow-bottles-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@workflow/next': patch
---

Stop eager input-graph directive discovery in deferred Next.js builds and rely on loader/socket-driven discovery with `onBeforeDeferredEntries`.
57 changes: 57 additions & 0 deletions packages/core/e2e/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,63 @@ ${apiFileContent}`
});
}
);

test.skipIf(!supportsDeferredStepCopies)(
'should copy package step sources discovered via manifest entries',
{ timeout: 30_000 },
async () => {
const workflowManifestPath = path.join(
appPath,
'app/.well-known/workflow/v1/manifest.json'
);
const copiedStepDir = path.join(
path.dirname(generatedStep),
'__workflow_step_files__'
);

await pollUntil({
description:
'copied deferred step files to include @workflow/ai package steps',
timeoutMs: 25_000,
check: async () => {
await fetchWithTimeout('/api/chat');
const manifestJson = await fs.readFile(
workflowManifestPath,
'utf8'
);
const manifest = JSON.parse(manifestJson) as {
steps?: Record<string, unknown>;
};
const manifestStepFiles = Object.keys(manifest.steps || {});
expect(
manifestStepFiles.some((filePath) =>
filePath.includes('ai/dist/agent/durable-agent.js')
)
).toBe(true);

const copiedStepFileNames = await fs.readdir(copiedStepDir);
const copiedStepContents = await Promise.all(
copiedStepFileNames.map(async (copiedStepFileName) => {
const copiedStepFilePath = path.join(
copiedStepDir,
copiedStepFileName
);
const copiedStepStats = await fs.stat(copiedStepFilePath);
if (!copiedStepStats.isFile()) {
return '';
}
return await fs.readFile(copiedStepFilePath, 'utf8');
})
);
expect(
copiedStepContents.some((content) =>
content.includes('async function closeStream')
)
).toBe(true);
},
});
}
);
});
}

Expand Down
17 changes: 17 additions & 0 deletions packages/core/e2e/local-build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ const ESM_STEP_BUNDLE_PROJECTS: Record<string, string> = {
'.vercel/output/functions/.well-known/workflow/v1/step.func/index.mjs',
};

const DEFERRED_BUILD_MODE_PROJECTS = new Set([
'nextjs-webpack',
'nextjs-turbopack',
]);
const DEFERRED_BUILD_UNSUPPORTED_WARNING =
'Enabled lazyDiscovery but Next.js version is not compatible';
const EAGER_DISCOVERY_LOG = 'Discovering workflow directives';

describe.each([
'example',
'nextjs-webpack',
Expand Down Expand Up @@ -111,6 +119,15 @@ describe.each([

expect(result.output).not.toContain('Error:');

if (DEFERRED_BUILD_MODE_PROJECTS.has(project)) {
const deferredBuildSupported = !result.output.includes(
DEFERRED_BUILD_UNSUPPORTED_WARNING
);
if (deferredBuildSupported) {
expect(result.output).not.toContain(EAGER_DISCOVERY_LOG);
}
}

if (usesVercelWorld()) {
const diagnosticsManifestPath = path.join(
getWorkbenchAppPath(project),
Expand Down
Loading
Loading