loader-smoke.spec.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { existsSync } from 'node:fs'
  2. import { join } from 'node:path'
  3. import { fileURLToPath } from 'node:url'
  4. import { describe, expect, it } from 'vitest'
  5. import { LOADER_SMOKE_TEST_TIMEOUT_MS, runLoaderSmoke } from '@deepseek-ai/dsh-loader-smoke'
  6. const configPath = '/tmp/fixture.cordis.yml'
  7. const tsconfigPath = fileURLToPath(new URL('../../../../tsconfig.json', import.meta.url))
  8. const fixture = (name: string): string => fileURLToPath(new URL(`./fixtures/${name}.ts`, import.meta.url))
  9. const canonicalTempPath = (path: string): string => path.replace(/^\/private(?=\/var\/)/, '')
  10. describe('runLoaderSmoke', () => {
  11. it('isolates the process, writes stdin, captures output, and removes the cwd', async () => {
  12. const result = await runLoaderSmoke({
  13. label: 'success fixture',
  14. tempDirPrefix: 'loader-smoke-success-',
  15. binScript: fixture('success'),
  16. configPath,
  17. tsconfigPath,
  18. mode: 'src',
  19. env: { LOADER_SMOKE_MARKER: 'present' },
  20. stdinLines: ['one', 'two'],
  21. })
  22. const output = JSON.parse(result.stdout) as {
  23. configPath: string
  24. cwd: string
  25. dshHome: string
  26. agentsHome: string
  27. marker: string
  28. input: string
  29. }
  30. expect(output).toMatchObject({
  31. configPath,
  32. marker: 'present',
  33. input: 'one\ntwo\n',
  34. })
  35. expect(canonicalTempPath(output.dshHome)).toBe(canonicalTempPath(join(output.cwd, '.dsh')))
  36. expect(canonicalTempPath(output.agentsHome)).toBe(canonicalTempPath(join(output.cwd, '.agents')))
  37. expect(result.stderr).toContain('fixture stderr')
  38. expect(existsSync(output.cwd)).toBe(false)
  39. }, LOADER_SMOKE_TEST_TIMEOUT_MS)
  40. it('rejects a non-zero exit with captured diagnostics', async () => {
  41. await expect(runLoaderSmoke({
  42. label: 'failure fixture',
  43. tempDirPrefix: 'loader-smoke-fail-',
  44. binScript: fixture('fail'),
  45. libBinScript: fixture('fail'),
  46. configPath,
  47. tsconfigPath,
  48. })).rejects.toThrow('failure fixture exited 7. stdout:\n\nstderr:\nfixture failed')
  49. })
  50. it('kills a process at its deadline and reports captured output', async () => {
  51. await expect(runLoaderSmoke({
  52. label: 'hanging fixture',
  53. tempDirPrefix: 'loader-smoke-hang-',
  54. binScript: fixture('hang'),
  55. libBinScript: fixture('hang'),
  56. configPath,
  57. tsconfigPath,
  58. processTimeoutMs: 100,
  59. })).rejects.toThrow('hanging fixture did not exit within 0.1s.')
  60. })
  61. })