built-lib.e2e.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /** Plain-Node smoke for the built Agent Teams service and Remote contribution. */
  2. import { execFile } from 'node:child_process'
  3. import { existsSync } from 'node:fs'
  4. import { join, resolve } from 'node:path'
  5. import { fileURLToPath, pathToFileURL } from 'node:url'
  6. import { describe, expect, it } from 'vitest'
  7. const packageDir = fileURLToPath(new URL('..', import.meta.url))
  8. const root = resolve(packageDir, '../../..')
  9. const artifact = (path: string): string => join(root, path)
  10. const artifactUrl = (path: string): string => pathToFileURL(artifact(path)).href
  11. const requiredArtifacts = [
  12. 'packages/experimental/agent-team/lib/index.js',
  13. 'packages/experimental/agent-team/lib/typert.remote-client.js',
  14. ].every(path => existsSync(artifact(path)))
  15. describe.skipIf(!requiredArtifacts)('Agent Teams built LIB service', () => {
  16. it('loads the Host service and its generated browser contribution under plain Node', async () => {
  17. const urls = {
  18. host: artifactUrl('packages/experimental/agent-team/lib/index.js'),
  19. remote: artifactUrl('packages/experimental/agent-team/lib/typert.remote-client.js'),
  20. }
  21. const script = `
  22. const host = await import(${JSON.stringify(urls.host)})
  23. const remote = await import(${JSON.stringify(urls.remote)})
  24. console.log(JSON.stringify({
  25. className: host.default.name,
  26. methods: remote.default.descriptors.map(descriptor => descriptor.id),
  27. }))
  28. `
  29. const result = await runPlainNode(script)
  30. expect(result.exitCode, `stderr:\n${result.stderr}`).toBe(0)
  31. const output = JSON.parse(result.stdout.trim().split('\n').at(-1) ?? '{}') as {
  32. className: string
  33. methods: string[]
  34. }
  35. expect(output).toEqual({
  36. className: 'TeamService',
  37. methods: [
  38. '@deepseek-ai/dsh-experimental-agent-team#agentTeams/createTask',
  39. '@deepseek-ai/dsh-experimental-agent-team#agentTeams/updateTask',
  40. '@deepseek-ai/dsh-experimental-agent-team#agentTeams/view',
  41. ],
  42. })
  43. })
  44. })
  45. function runPlainNode(script: string): Promise<{
  46. readonly exitCode: number | null
  47. readonly stdout: string
  48. readonly stderr: string
  49. }> {
  50. return new Promise((resolveRun) => {
  51. execFile(process.execPath, ['--input-type=module', '-e', script], {
  52. cwd: packageDir,
  53. encoding: 'utf8',
  54. timeout: 30_000,
  55. }, (error, stdout, stderr) => {
  56. resolveRun({
  57. exitCode: error === null ? 0 : typeof error.code === 'number' ? error.code : null,
  58. stdout,
  59. stderr,
  60. })
  61. })
  62. })
  63. }