windows-shell.spec.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { afterEach, describe, expect, it } from 'vitest'
  2. import { mkdtempSync, writeFileSync, rmSync, mkdirSync } from 'node:fs'
  3. import { tmpdir } from 'node:os'
  4. import { join } from 'node:path'
  5. import type { ProfileLayer } from '@deepseek-ai/dsh-app-boot'
  6. import {
  7. BASE_BUNDLE,
  8. resolveWindowsShellLayer,
  9. WINDOWS_SHELL_PATCH_FILENAME,
  10. } from '../src/windows-shell.ts'
  11. const WINDOWS_PATCH = `- id: bash-sandbox
  12. disabled: true
  13. - insert:
  14. - id: pwsh-local
  15. name: '@deepseek-ai/dsh-pwsh-local'
  16. `
  17. /** One fake bundle layer rooted in a temp directory. */
  18. function fakeLayer(packageName: string, dir: string): ProfileLayer {
  19. return { packageName, packageDir: dir, patchPath: join(dir, 'cordis.patch.yml'), patches: [] }
  20. }
  21. /** A base bundle layer whose package carries the Windows shell patch. */
  22. function baseLayerWithPatch(dir: string): ProfileLayer {
  23. writeFileSync(join(dir, WINDOWS_SHELL_PATCH_FILENAME), WINDOWS_PATCH)
  24. return fakeLayer(BASE_BUNDLE, dir)
  25. }
  26. describe('resolveWindowsShellLayer', () => {
  27. let base: string
  28. afterEach(() => { if (base !== undefined) rmSync(base, { recursive: true, force: true }) })
  29. const tempBase = (): string => {
  30. base = mkdtempSync(join(tmpdir(), 'dsh-windows-shell-'))
  31. return base
  32. }
  33. it('never applies on POSIX hosts', () => {
  34. expect(resolveWindowsShellLayer('linux', [baseLayerWithPatch(tempBase())], 'dsh')).toBeUndefined()
  35. expect(resolveWindowsShellLayer('darwin', [baseLayerWithPatch(tempBase())], 'dsh')).toBeUndefined()
  36. })
  37. it('defaults Windows hosts to the pwsh platform layer', () => {
  38. const layer = resolveWindowsShellLayer('win32', [baseLayerWithPatch(tempBase())], 'dsh')
  39. expect(layer).toBeDefined()
  40. expect(layer?.label.endsWith(WINDOWS_SHELL_PATCH_FILENAME)).toBe(true)
  41. expect(layer?.patches).toEqual([
  42. { id: 'bash-sandbox', disabled: true },
  43. { insert: [{ id: 'pwsh-local', name: '@deepseek-ai/dsh-pwsh-local' }] },
  44. ])
  45. })
  46. it('skips custom profiles without a base bundle', () => {
  47. const other = fakeLayer('@deepseek-ai/dsh-custom', tempBase())
  48. expect(resolveWindowsShellLayer('win32', [other], 'dsh')).toBeUndefined()
  49. })
  50. it('fails loud when the base bundle ships no Windows shell patch', () => {
  51. const base = tempBase()
  52. mkdirSync(base, { recursive: true })
  53. expect(() => resolveWindowsShellLayer('win32', [fakeLayer(BASE_BUNDLE, base)], 'dsh'))
  54. .toThrow(/@deepseek-ai\/dsh-base ships no windows\.cordis\.patch\.yml/)
  55. })
  56. })