1
0

built-worker.e2e.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 '@deepseek-ai/cordis'
  23. import SessionProjectionRegistry from '@deepseek-ai/dsh-session-projection'
  24. import SubagentRuntime from '@deepseek-ai/dsh-subagent'
  25. import WorkerThreadWorkflowEngine from '@deepseek-ai/dsh-workflow-worker-thread'
  26. const ctx = new Context()
  27. await ctx.plugin(SessionProjectionRegistry)
  28. await ctx.plugin(SubagentRuntime)
  29. let selectedStarts = 0
  30. ctx.subagents.registerProvider({
  31. name: 'built-selected',
  32. capabilities: { agentOptions: true, outputSchema: true, depthLimit: false, toolFilter: false, persona: false },
  33. inheritsParentContext: false,
  34. async start() {
  35. selectedStarts += 1
  36. return {
  37. id: 'built-child',
  38. result: Promise.resolve({ output: [], structured: { answer: 42 }, stopReason: 'completed' }),
  39. dispose: () => Promise.resolve(),
  40. }
  41. },
  42. })
  43. await ctx.plugin(WorkerThreadWorkflowEngine, { provider: 'must-not-be-used' })
  44. const run = ctx.workflowEngine.start({
  45. script: "const value = await agent('answer', { schema: { type: 'object', properties: { answer: { type: 'number' } }, required: ['answer'] } }); return value.answer",
  46. meta: { name: 'built-smoke', description: 'built worker smoke' },
  47. subagentProvider: 'built-selected',
  48. parent: { id: 'built-smoke-parent', options: {} },
  49. })
  50. const result = await run.result
  51. await run.dispose()
  52. if (result.stopReason !== 'completed' || result.value !== 42 || selectedStarts !== 1) {
  53. console.error('unexpected result: ' + JSON.stringify(result))
  54. process.exit(1)
  55. }
  56. console.log('built-worker-smoke-ok')
  57. `, 'utf8')
  58. const { stdout } = await run(process.execPath, [driver], { cwd: packageRoot, timeout: 60_000 })
  59. expect(stdout).toContain('built-worker-smoke-ok')
  60. } finally {
  61. await rm(driver, { force: true })
  62. }
  63. }, 120_000)
  64. })