1
0

profile-hmr.spec.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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('YAML-owned profile HMR', () => {
  19. it('enables configuration watching in the base and web compositions', () => {
  20. expect(hmr([bundle('base'), bundle('web-app')])).toMatchObject({ config: { root: [] } })
  21. expect(hmr([bundle('base')]).disabled).not.toBe(true)
  22. })
  23. it.each(['headless', 'sdk-app', 'acp-app'] as const)('%s disables HMR with a bundle override', (mode) => {
  24. expect(hmr([bundle('base'), bundle(mode)])).toMatchObject({ disabled: true })
  25. expect(hmr([bundle('base'), bundle(mode), [{ id: 'hmr', disabled: false }]])).toMatchObject({
  26. disabled: false, config: { root: [] },
  27. })
  28. })
  29. it('selects module roots through a later YAML layer', () => {
  30. expect(hmr([bundle('base'), [{ id: 'hmr', config: { root: ['.'] } }]])).toMatchObject({
  31. config: { root: ['.'] },
  32. })
  33. })
  34. it('keeps the standalone sdk-minimal tree free of HMR', () => {
  35. expect(composeEntries([bundle('sdk-minimal')]).find(entry => entry.id === 'hmr')).toBeUndefined()
  36. })
  37. })