app-root.spec.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // @vitest-environment jsdom
  2. /**
  3. * AppRoot boot-gate smoke: loading page until the settled signal flips (status
  4. * alone never opens the gate), fail-loud entry list + boot failure report,
  5. * one-pass switch to the real UI. The full browser chain (real module system
  6. * + vendored Loader + bundles) is the e2e's job; this pins the shell-owned
  7. * gate semantics. Stores are the kernel-own signals production boot uses
  8. * (shell self-sufficiency: the loading page depends on no plugin package).
  9. */
  10. import { afterEach, describe, expect, it } from 'vitest'
  11. import { act, cleanup, render } from '@testing-library/react'
  12. afterEach(cleanup)
  13. import { AppRoot } from '@deepseek-ai/dsh-client-web/src/AppRoot.tsx'
  14. import { createLoaderStatusStore, createSignal } from '@deepseek-ai/dsh-client-web/src/loader-status.ts'
  15. function mount() {
  16. const settled = createSignal(false)
  17. const error = createSignal<string | undefined>(undefined)
  18. const status = createLoaderStatusStore()
  19. let renders = 0
  20. const utils = render(
  21. <AppRoot
  22. settled={settled}
  23. status={status}
  24. error={error}
  25. renderApp={() => { renders += 1; return <div data-testid="real-ui" /> }}
  26. />,
  27. )
  28. return { settled, status, error, counts: () => renders, ...utils }
  29. }
  30. describe('AppRoot', () => {
  31. it('shows the loading page and never calls renderApp before settled', () => {
  32. const { queryByTestId, counts, getByText } = mount()
  33. expect(getByText('HARNESS')).toBeTruthy()
  34. expect(queryByTestId('real-ui')).toBeNull()
  35. expect(counts()).toBe(0)
  36. })
  37. it('all-active status alone does not open the gate (settled signal is the only key)', () => {
  38. const { status, queryByTestId } = mount()
  39. act(() => {
  40. status.set('a', 'active')
  41. status.set('b', 'active')
  42. })
  43. expect(queryByTestId('real-ui')).toBeNull()
  44. })
  45. it('lists failed entries and stays on the loading page', () => {
  46. const { status, getByText, queryByTestId } = mount()
  47. act(() => {
  48. status.set('@deepseek-ai/dsh-client-ui-layout', 'failed')
  49. status.set('ok', 'active')
  50. })
  51. expect(getByText('Failed to load plugins')).toBeTruthy()
  52. expect(getByText('@deepseek-ai/dsh-client-ui-layout')).toBeTruthy()
  53. expect(queryByTestId('real-ui')).toBeNull()
  54. })
  55. it('renders the boot failure report even when no entry projected failed', () => {
  56. const { error, getByText, queryByTestId } = mount()
  57. act(() => { error.set('web boot: 1 entry did not activate\nx: pending (waiting for service: y)') })
  58. expect(getByText('Failed to load plugins')).toBeTruthy()
  59. expect(getByText(/waiting for service/)).toBeTruthy()
  60. expect(queryByTestId('real-ui')).toBeNull()
  61. })
  62. it('flipping settled switches to the real UI in one pass', () => {
  63. const { settled, getByTestId, queryByText, counts } = mount()
  64. act(() => { settled.set(true) })
  65. expect(getByTestId('real-ui')).toBeTruthy()
  66. expect(queryByText('HARNESS')).toBeNull()
  67. expect(counts()).toBe(1)
  68. })
  69. })