profile-hmr.spec.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /** Module-HMR ownership across the real shipped profile bundle layers. */
  2. import { join } from 'node:path'
  3. import { fileURLToPath } from 'node:url'
  4. import { describe, expect, it } from 'vitest'
  5. import { composeEntries, loadOverlayPatches } from '@deepseek-ai/dsh-app-boot'
  6. import type { PatchOptions } from '@deepseek-ai/cordis-plugin-include'
  7. const REPOSITORY_ROOT = fileURLToPath(new URL('../../../', import.meta.url))
  8. /** Load one shipped bundle patch through the same parser as profile boot. */
  9. function bundle(name: 'acp-app' | 'base' | 'headless' | 'sdk-app' | 'sdk-minimal' | 'web-app'): PatchOptions[] {
  10. return loadOverlayPatches('profile-hmr test', join(REPOSITORY_ROOT, 'packages', 'bundle', name, 'cordis.patch.yml'))
  11. }
  12. /** Resolve the effective HMR row after the supplied layers. */
  13. function hmr(layers: PatchOptions[][]) {
  14. const row = composeEntries(layers).find(entry => entry.id === 'hmr')
  15. if (row === undefined) throw new Error('the base bundle must insert the hmr row')
  16. return row
  17. }
  18. describe('profile module-HMR policy', () => {
  19. it.each(['web-app', 'headless', 'sdk-app', 'acp-app'] as const)(
  20. '%s inherits the disabled base row without a mode override',
  21. (mode) => {
  22. const modePatches = bundle(mode)
  23. expect(modePatches.some(patch => patch.id === 'hmr')).toBe(false)
  24. expect(hmr([bundle('base'), modePatches])).toMatchObject({
  25. disabled: true,
  26. config: { root: ['.'] },
  27. })
  28. },
  29. )
  30. it('requires an explicit later layer to enable source-module reload', () => {
  31. expect(hmr([bundle('base'), [{ id: 'hmr', disabled: false }]])).toMatchObject({
  32. disabled: false,
  33. config: { root: ['.'] },
  34. })
  35. })
  36. it('keeps the standalone sdk-minimal tree free of module HMR', () => {
  37. expect(composeEntries([bundle('sdk-minimal')]).find(entry => entry.id === 'hmr')).toBeUndefined()
  38. })
  39. })