source-launch.compat.spec.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { readFile } from 'node:fs/promises'
  2. import { fileURLToPath } from 'node:url'
  3. import { execa } from 'execa'
  4. import { describe, expect, it } from 'vitest'
  5. /**
  6. * Keyless smoke for SOURCE `dsh` execution: run `apps/cli/src/bin.ts`
  7. * with the exact production runtime vector (`node --import tsx/esm`, the
  8. * vector the root `dsh` script invokes directly) and assert the
  9. * required-config diagnostic. The Node compatibility matrix runs this
  10. * WHOLE file, so a Node release changing module hooks or TypeScript handling
  11. * breaks this gate instead of every developer's `pnpm dsh`; the built-bin
  12. * suite covers the published `lib/` entry, not this source chain.
  13. */
  14. const repoRoot = fileURLToPath(new URL('../../../', import.meta.url))
  15. const dshSourceBin = 'apps/cli/src/bin.ts'
  16. describe('dsh SOURCE launcher (node --import tsx/esm)', () => {
  17. it('launches the source CLI without building', async () => {
  18. const rootPackage = JSON.parse(await readFile(new URL('../../../package.json', import.meta.url), 'utf8')) as {
  19. readonly scripts?: Record<string, string>
  20. }
  21. expect(rootPackage.scripts?.dsh).toBe('node --import tsx/esm apps/cli/src/bin.ts')
  22. })
  23. it('boots the source entry and requires a profile', async () => {
  24. const result = await execa(process.execPath, ['--import', 'tsx/esm', dshSourceBin], {
  25. cwd: repoRoot,
  26. input: '',
  27. timeout: 25_000,
  28. killSignal: 'SIGKILL',
  29. reject: false,
  30. })
  31. if (result.timedOut) {
  32. throw new Error(`dsh source launch did not exit within 25s. stdout:\n${result.stdout}\nstderr:\n${result.stderr}`)
  33. }
  34. expect(result.exitCode).not.toBe(0)
  35. expect(result.stderr).toContain('--profile <name> is required')
  36. expect(result.stdout).toBe('')
  37. }, 30_000)
  38. })