built-worker.e2e.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { existsSync } from 'node:fs'
  2. import { rm, writeFile } from 'node:fs/promises'
  3. import { join } from 'node:path'
  4. import { execFile } from 'node:child_process'
  5. import { promisify } from 'node:util'
  6. import { fileURLToPath } from 'node:url'
  7. import { describe, expect, it } from 'vitest'
  8. const packageRoot = fileURLToPath(new URL('..', import.meta.url))
  9. const builtIndex = join(packageRoot, 'lib', 'index.js')
  10. const builtWorker = join(packageRoot, 'lib', 'worker.cjs')
  11. const run = promisify(execFile)
  12. /**
  13. * Keyless built-artifact guard: plain Node loads `lib/index.js` and its sibling
  14. * `lib/worker.cjs` without tsx. Skips until the build produces both bundles.
  15. */
  16. describe.skipIf(!existsSync(builtIndex) || !existsSync(builtWorker))('built worker entry (lib/worker.cjs)', () => {
  17. it('the built engine spawns its built worker under plain node and completes a run', async () => {
  18. // Keep the driver in-package so bare imports resolve its node_modules.
  19. const driver = join(packageRoot, `.built-worker-driver-${process.pid}.mjs`)
  20. try {
  21. await writeFile(driver, `
  22. import { Context } from 'cordis'
  23. import SubagentService from '@deepseek-ai/dsh-subagent'
  24. import WorkerWorkflowEngine from '@deepseek-ai/dsh-workflow-workerthread'
  25. const ctx = new Context()
  26. await ctx.plugin(SubagentService)
  27. await ctx.plugin(WorkerWorkflowEngine, {})
  28. const run = ctx.workflows.start({
  29. script: 'return 6 * 7',
  30. meta: { name: 'built-smoke', description: 'built worker smoke' },
  31. // A zero-agent script never touches the provider.
  32. parent: { id: 'built-smoke-parent', options: {} },
  33. })
  34. const result = await run.result
  35. await run.dispose()
  36. if (result.stopReason !== 'completed' || result.value !== 42) {
  37. console.error('unexpected result: ' + JSON.stringify(result))
  38. process.exit(1)
  39. }
  40. console.log('built-worker-smoke-ok')
  41. `, 'utf8')
  42. const { stdout } = await run(process.execPath, [driver], { cwd: packageRoot, timeout: 60_000 })
  43. expect(stdout).toContain('built-worker-smoke-ok')
  44. } finally {
  45. await rm(driver, { force: true })
  46. }
  47. }, 120_000)
  48. })