diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9d4d7cda..229553f7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -42,3 +42,10 @@ jobs: - name: Test run: bun run test + + - name: Test Local Release + run: | + bun run release:local --skip-check --out /tmp/shumai-local-release --force + cd /tmp/shumai-local-release/node + npx shumai-agent + npx shumai-transcode diff --git a/packages/workflow-core/src/bun-temporal-plugin.test.ts b/packages/workflow-core/src/bun-temporal-plugin.test.ts new file mode 100644 index 00000000..8083d7a8 --- /dev/null +++ b/packages/workflow-core/src/bun-temporal-plugin.test.ts @@ -0,0 +1,52 @@ +import { describe, it, expect, vi, beforeEach } from 'vitest' +import { temporalWorkflow } from './bun-temporal-plugin' +import * as worker from '@temporalio/worker' + +vi.mock('@temporalio/worker', () => ({ + bundleWorkflowCode: vi.fn().mockResolvedValue({ code: 'mock-code', sourceMap: '' }) +})) + +describe('temporalWorkflow plugin', () => { + beforeEach(() => { + vi.clearAllMocks() + }) + + it('should register onLoad and configure webpackConfigHook with @temporalio/workflow alias', async () => { + const plugin = temporalWorkflow() + + let onLoadCallback: ((...args: unknown[]) => unknown) | null = null + + const mockBuild = { + onResolve: vi.fn(), + onLoad: vi.fn((opts, callback) => { + onLoadCallback = callback + }) + } + + // Run setup + // @ts-ignore + plugin.setup(mockBuild) + + expect(onLoadCallback).toBeDefined() + + // Trigger onLoad callback + await onLoadCallback!({ path: 'dummy-path' }) + + // Verify bundleWorkflowCode was called + expect(worker.bundleWorkflowCode).toHaveBeenCalled() + + // Webpack's configuration type is complex and varies across versions. + // We cast it to any here to allow indexing the config aliases dynamically. + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const callArgs = vi.mocked(worker.bundleWorkflowCode).mock.calls[0][0] as any + expect(callArgs.webpackConfigHook).toBeDefined() + + // Invoke the hook with a dummy config + const config = { resolve: { alias: {} } } + const updatedConfig = callArgs.webpackConfigHook(config) + + // Check that aliases are set + expect(updatedConfig.resolve.alias['@shumai/workflow-core']).toBeDefined() + expect(updatedConfig.resolve.alias['@temporalio/workflow']).toBeDefined() + }) +}) diff --git a/packages/workflow-core/src/bun-temporal-plugin.ts b/packages/workflow-core/src/bun-temporal-plugin.ts index 2cec9cc2..92d1537f 100644 --- a/packages/workflow-core/src/bun-temporal-plugin.ts +++ b/packages/workflow-core/src/bun-temporal-plugin.ts @@ -1,6 +1,6 @@ import { bundleWorkflowCode } from '@temporalio/worker' import type { BunPlugin } from 'bun' -import { resolve } from 'node:path' +import { resolve, dirname } from 'node:path' export interface TemporalWorkflowPluginOptions { /** Query param identifier. Default: 'workflow' */ @@ -47,6 +47,9 @@ export function temporalWorkflow(options: TemporalWorkflowPluginOptions = {}): B ...config.resolve.alias, '@shumai/workflow-core': require.resolve('@shumai/workflow-core/src/workflow-utils.ts'), + '@temporalio/workflow': dirname( + require.resolve('@temporalio/workflow/package.json'), + ), } console.log('Webpack config aliases:', config.resolve.alias) if (originalHook) {