refactor(gui): rebuild the client loading kernel as dsh-client-modules with a two-phase boot

The module system moves out of dsh-client-runtime (./loader retired) into
its own package: a lazy CJS table where executing a bundle only registers
its factory and materialization happens at first require, memoized, with
recursive requires self-ordering. ClientModuleSystem is a class; index.ts
keeps the types and a thin factory. Boot is two-phase: phase one prefetches
the immediately tier in parallel (registration only, failures deferred to
phase two's loud import); phase two mounts the vendored Loader with the
module system as internal, creates one entry per graph row plus the
app-shell pseudo-row the kernel appends itself, and settles on an
all-ACTIVE sweep. The shell kernel is self-sufficient: hand-rolled
loader-status stores, no plugin value imports, platform seed list single-
sourced in platform.ts.
This commit is contained in:
imccyu
2026-07-23 21:55:39 +08:00
parent 15fde82f80
commit b58f0989f9
30 changed files with 1064 additions and 1015 deletions
+26 -25
View File
@@ -1,42 +1,33 @@
// @vitest-environment jsdom
/**
* AppRoot boot-gate smoke: loading page until the settled signal flips (status
* alone never opens the gate), fail-loud plugin list, one-pass switch to the
* real UI. The full browser chain (real loader + bundles) is the e2e's job;
* this pins the shell-owned gate semantics.
* alone never opens the gate), fail-loud entry list + boot failure report,
* one-pass switch to the real UI. The full browser chain (real module system
* + vendored Loader + bundles) is the e2e's job; this pins the shell-owned
* gate semantics. Stores are the kernel-own signals production boot uses
* (shell self-sufficiency: the loading page depends on no plugin package).
*/
import { afterEach, describe, expect, it } from 'vitest'
import { act, cleanup, render } from '@testing-library/react'
afterEach(cleanup)
// The snapshot-store engine lives with runtime now; the status-store stub
// uses the same channel production code does.
import { createSnapshotStore, type ObservableSnapshot } from '@deepseek-ai/dsh-client-runtime/client'
import type { LoaderStatus } from '@deepseek-ai/dsh-client-runtime/client'
import { AppRoot } from '@deepseek-ai/dsh-client-web/src/AppRoot.tsx'
function signal(): ObservableSnapshot<boolean> & { flip: () => void } {
let value = false
const listeners = new Set<() => void>()
return {
getSnapshot: () => value,
subscribe: (fn) => { listeners.add(fn); return () => { listeners.delete(fn) } },
flip: () => { value = true; for (const fn of [...listeners]) fn() },
}
}
import { createLoaderStatusStore, createSignal } from '@deepseek-ai/dsh-client-web/src/loader-status.ts'
function mount() {
const settled = signal()
const status = createSnapshotStore<LoaderStatus>({})
const settled = createSignal(false)
const error = createSignal<string | undefined>(undefined)
const status = createLoaderStatusStore()
let renders = 0
const utils = render(
<AppRoot
settled={settled}
status={status}
error={error}
renderApp={() => { renders += 1; return <div data-testid="real-ui" /> }}
/>,
)
return { settled, status, counts: () => renders, ...utils }
return { settled, status, error, counts: () => renders, ...utils }
}
describe('AppRoot', () => {
@@ -50,24 +41,34 @@ describe('AppRoot', () => {
it('all-active status alone does not open the gate (settled signal is the only key)', () => {
const { status, queryByTestId } = mount()
act(() => {
status.update((d) => { d['a'] = 'active'; d['b'] = 'active' })
status.set('a', 'active')
status.set('b', 'active')
})
expect(queryByTestId('real-ui')).toBeNull()
})
it('lists failed plugins and stays on the loading page', () => {
it('lists failed entries and stays on the loading page', () => {
const { status, getByText, queryByTestId } = mount()
act(() => {
status.update((d) => { d['@deepseek-ai/dsh-client-ui-theme'] = 'failed'; d['ok'] = 'active' })
status.set('@deepseek-ai/dsh-client-ui-layout', 'failed')
status.set('ok', 'active')
})
expect(getByText('Failed to load plugins')).toBeTruthy()
expect(getByText('@deepseek-ai/dsh-client-ui-theme')).toBeTruthy()
expect(getByText('@deepseek-ai/dsh-client-ui-layout')).toBeTruthy()
expect(queryByTestId('real-ui')).toBeNull()
})
it('renders the boot failure report even when no entry projected failed', () => {
const { error, getByText, queryByTestId } = mount()
act(() => { error.set('web boot: 1 entry did not activate\nx: pending (waiting for service: y)') })
expect(getByText('Failed to load plugins')).toBeTruthy()
expect(getByText(/waiting for service/)).toBeTruthy()
expect(queryByTestId('real-ui')).toBeNull()
})
it('flipping settled switches to the real UI in one pass', () => {
const { settled, getByTestId, queryByText, counts } = mount()
act(() => { settled.flip() })
act(() => { settled.set(true) })
expect(getByTestId('real-ui')).toBeTruthy()
expect(queryByText('HARNESS')).toBeNull()
expect(counts()).toBe(1)