@linxin666/dsh-pet 0.4.4 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.i18n.yaml +2 -2
  2. package/README.md +46 -6
  3. package/README.zh.md +46 -6
  4. package/lib/client.js +244 -47
  5. package/lib/client.js.map +1 -1
  6. package/lib/index.js +287 -28
  7. package/lib/types/announce.d.ts +16 -0
  8. package/lib/types/announce.d.ts.map +1 -1
  9. package/lib/types/announce.js +16 -0
  10. package/lib/types/client/PetDockEntry.d.ts +6 -0
  11. package/lib/types/client/PetDockEntry.d.ts.map +1 -1
  12. package/lib/types/client/PetDockEntry.js +1 -1
  13. package/lib/types/client/PetSettingsCard.d.ts +4 -0
  14. package/lib/types/client/PetSettingsCard.d.ts.map +1 -1
  15. package/lib/types/client/PetSettingsCard.js +16 -1
  16. package/lib/types/client/PetSprite.d.ts +7 -0
  17. package/lib/types/client/PetSprite.d.ts.map +1 -1
  18. package/lib/types/client/PetSprite.js +23 -13
  19. package/lib/types/client/index.d.ts +2 -0
  20. package/lib/types/client/index.d.ts.map +1 -1
  21. package/lib/types/client/index.js +224 -28
  22. package/lib/types/client/locales.d.ts +4 -0
  23. package/lib/types/client/locales.d.ts.map +1 -1
  24. package/lib/types/client/locales.js +4 -0
  25. package/lib/types/index.d.ts +14 -3
  26. package/lib/types/index.d.ts.map +1 -1
  27. package/lib/types/index.js +32 -3
  28. package/lib/types/panel-actions.d.ts +96 -0
  29. package/lib/types/panel-actions.d.ts.map +1 -0
  30. package/lib/types/panel-actions.js +134 -0
  31. package/lib/types/routes.d.ts.map +1 -1
  32. package/lib/types/routes.js +10 -0
  33. package/lib/types/service.d.ts +137 -9
  34. package/lib/types/service.d.ts.map +1 -1
  35. package/lib/types/service.js +163 -21
  36. package/package.json +1 -1
  37. package/src/announce.ts +17 -0
  38. package/src/client/PetDockEntry.test.tsx +1 -0
  39. package/src/client/PetDockEntry.tsx +7 -0
  40. package/src/client/PetSettingsCard.test.tsx +88 -0
  41. package/src/client/PetSettingsCard.tsx +31 -0
  42. package/src/client/PetSprite.test.tsx +197 -0
  43. package/src/client/PetSprite.tsx +56 -12
  44. package/src/client/index.test.tsx +152 -4
  45. package/src/client/index.ts +228 -29
  46. package/src/client/locales.ts +4 -0
  47. package/src/index.test.ts +22 -0
  48. package/src/index.ts +45 -3
  49. package/src/panel-actions.test.ts +130 -0
  50. package/src/panel-actions.ts +182 -0
  51. package/src/registry.test.ts +11 -1
  52. package/src/routes.ts +9 -0
  53. package/src/service.test.ts +128 -0
  54. package/src/service.ts +218 -24
@@ -9,6 +9,7 @@ import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
9
9
  import { PetSprite, type PetSpriteProps } from './PetSprite.tsx'
10
10
  import { t } from './locales.ts'
11
11
  import type { PetStateView } from '../service.ts'
12
+ import type { PetAnnouncement } from '../announce.ts'
12
13
  import type { PetDefinition, PetTrackDef } from '../registry.ts'
13
14
  import type { PetAnimation } from '../state.ts'
14
15
  import type { DecorationView } from '../contracts/status-decoration.ts'
@@ -104,6 +105,7 @@ function petProps(overrides: Partial<PetSpriteProps> = {}): PetSpriteProps {
104
105
  onHide: vi.fn(),
105
106
  onDragEnd: vi.fn(),
106
107
  onRename: vi.fn(),
108
+ onPanelAction: vi.fn(),
107
109
  onOpenSession: vi.fn(),
108
110
  onFeedbackDone: vi.fn(),
109
111
  t,
@@ -1202,3 +1204,198 @@ describe('PetSprite portal target', () => {
1202
1204
  })
1203
1205
  })
1204
1206
 
1207
+ describe('PetSprite plugin panel actions (issue #6)', () => {
1208
+ const withActions = (...ids: string[]): PetStateView => ({
1209
+ ...snapshot,
1210
+ panelActions: ids.map(id => ({ id, label: id === 'pet-quota-swap' ? '换装' : id, order: 0 })),
1211
+ })
1212
+
1213
+ it('renders no plugin action while nothing is registered', () => {
1214
+ renderPet()
1215
+ fireEvent.pointerOver(screen.getByRole('button', { name: '鲸鱼娘' }))
1216
+ // The row is exactly the built-in one: a pet with no sibling plugin
1217
+ // showing an action would mean the extension point leaked a default.
1218
+ expect(screen.getByText('喂食')).toBeDefined()
1219
+ expect(document.querySelectorAll('[data-dsh-pet-panel-action]')).toHaveLength(0)
1220
+ })
1221
+
1222
+ it('renders a registered action after the built-in row and reports its id on click', () => {
1223
+ const onPanelAction = vi.fn()
1224
+ renderPet({ snapshot: withActions('pet-quota-swap'), onPanelAction })
1225
+
1226
+ fireEvent.pointerOver(screen.getByRole('button', { name: '鲸鱼娘' }))
1227
+ const action = screen.getByText('换装')
1228
+ // The built-in row keeps its order; the extension follows it.
1229
+ const row = action.closest('[class*="actions"]')!
1230
+ expect(Array.from(row.children).map(child => child.textContent))
1231
+ .toEqual(['喂食', '改名', '隐藏', '换装'])
1232
+ expect(action.closest('button')?.getAttribute('data-dsh-pet-panel-action')).toBe('pet-quota-swap')
1233
+
1234
+ fireEvent.click(action)
1235
+ expect(onPanelAction).toHaveBeenCalledWith('pet-quota-swap')
1236
+ })
1237
+
1238
+ it('renders the plugin tooltip the registration declared', () => {
1239
+ renderPet({
1240
+ snapshot: {
1241
+ ...snapshot,
1242
+ panelActions: [{ id: 'pet-quota-swap', label: '换装', title: '切换到下一只宠物', order: 0 }],
1243
+ },
1244
+ })
1245
+ fireEvent.pointerOver(screen.getByRole('button', { name: '鲸鱼娘' }))
1246
+ expect(screen.getByText('换装').closest('button')?.getAttribute('title')).toBe('切换到下一只宠物')
1247
+ })
1248
+
1249
+ it('shows a plugin action even when a voice pack hides every built-in action', () => {
1250
+ renderPet({
1251
+ definition: { ...petDefinition(), panel: { actions: [] } },
1252
+ snapshot: withActions('pet-quota-swap'),
1253
+ })
1254
+ fireEvent.pointerOver(screen.getByRole('button', { name: '鲸鱼娘' }))
1255
+ expect(screen.queryByText('喂食')).toBeNull()
1256
+ expect(screen.getByText('换装')).toBeDefined()
1257
+ })
1258
+ })
1259
+
1260
+ describe('PetSprite status bubble switch (issue #6)', () => {
1261
+ const busy = (mode?: 'auto' | 'off'): PetStateView => ({
1262
+ ...snapshot,
1263
+ animation: 'running',
1264
+ phase: 'thinking',
1265
+ bubble: '正在思考',
1266
+ sessions: [
1267
+ { sessionId: 's-a', animation: 'running', phase: 'thinking', bubble: '正在思考' },
1268
+ { sessionId: 's-b', animation: 'running-right', phase: 'tool', bubble: '正在使用 grep' },
1269
+ ],
1270
+ ...(mode === undefined ? {} : { statusBubbles: mode }),
1271
+ })
1272
+
1273
+ it('keeps the shipped bubbles for a host that serves no mode', () => {
1274
+ renderPet({ snapshot: busy() })
1275
+ expect(screen.queryAllByText('正在思考').length).toBeGreaterThan(0)
1276
+ })
1277
+
1278
+ it('hides the built-in session and status bubbles when they are switched off', () => {
1279
+ renderPet({ snapshot: busy('off') })
1280
+ // Neither the multi-session stack nor the legacy single status bubble.
1281
+ expect(screen.queryAllByText('正在思考')).toHaveLength(0)
1282
+ expect(screen.queryByText('正在使用 grep')).toBeNull()
1283
+ })
1284
+
1285
+ it('keeps a sibling plugin announcement bubble while the built-in ones are off', () => {
1286
+ renderPet({
1287
+ snapshot: {
1288
+ ...busy('off'),
1289
+ announcement: {
1290
+ source: 'dsh-pet-quota',
1291
+ kind: 'cost',
1292
+ title: 'DeepSeek',
1293
+ amount: '今日 1.2M tokens',
1294
+ tone: 'ok',
1295
+ ttlMs: 60_000,
1296
+ at: Date.now(),
1297
+ },
1298
+ },
1299
+ })
1300
+ // The point of the switch: the pet stops speaking for itself, and a plugin
1301
+ // that drives its own bubble surface still gets the row.
1302
+ expect(screen.queryAllByText('正在思考')).toHaveLength(0)
1303
+ expect(screen.queryByText('今日 1.2M tokens')).not.toBeNull()
1304
+ })
1305
+
1306
+ it('keeps the interaction feedback bubble while the built-in ones are off', () => {
1307
+ renderPet({ snapshot: busy('off'), feedback: { text: '摸摸成功', kind: 'pet', at: 1 } })
1308
+ expect(screen.queryByText('摸摸成功')).not.toBeNull()
1309
+ })
1310
+ })
1311
+
1312
+ describe('PetSprite announcement bubbles from several publishers (issue #1812)', () => {
1313
+ /** One publisher's announcement as the host serves it, `ageMs` old. */
1314
+ const from = (source: string, amount: string, ageMs = 0): PetAnnouncement => ({
1315
+ source,
1316
+ kind: 'cost',
1317
+ title: 'DeepSeek',
1318
+ amount,
1319
+ tone: 'ok',
1320
+ ttlMs: 60_000,
1321
+ at: Date.now() - ageMs,
1322
+ })
1323
+
1324
+ it('renders one bubble per publishing plugin', () => {
1325
+ renderPet({
1326
+ snapshot: {
1327
+ ...snapshot,
1328
+ announcements: [
1329
+ from('dsh-pet-quota', '今日 1.2M tokens'),
1330
+ from('dsh-pet-notices', '余额 ¥110.00'),
1331
+ ],
1332
+ },
1333
+ })
1334
+
1335
+ // The reported defect: one publisher used to erase the other's bubble.
1336
+ expect(screen.queryByText('今日 1.2M tokens')).not.toBeNull()
1337
+ expect(screen.queryByText('余额 ¥110.00')).not.toBeNull()
1338
+ })
1339
+
1340
+ it('stacks the publishers above the session bubbles in the served order', () => {
1341
+ renderPet({
1342
+ snapshot: {
1343
+ ...snapshot,
1344
+ bubble: '正在思考',
1345
+ sessions: [{ sessionId: 's-a', animation: 'running', phase: 'thinking', bubble: '正在思考' }],
1346
+ announcements: [
1347
+ from('dsh-pet-quota', '今日 1.2M tokens'),
1348
+ from('dsh-pet-notices', '余额 ¥110.00'),
1349
+ ],
1350
+ },
1351
+ })
1352
+
1353
+ // Each announcement carries its publisher's tag, so the DOM order is what
1354
+ // the bubble stack renders: session bubble first, publishers above it.
1355
+ const stack = screen.getByText('正在思考').closest('div')!
1356
+ const tags = Array.from(stack.querySelectorAll('[data-dsh-pet-announcement]'))
1357
+ .map(node => node.getAttribute('data-dsh-pet-announcement'))
1358
+ expect(tags).toEqual(['dsh-pet-quota', 'dsh-pet-notices'])
1359
+ })
1360
+
1361
+ it('renders the singular field alone for a host predating the per-source array', () => {
1362
+ renderPet({ snapshot: { ...snapshot, announcement: from('dsh-pet-quota', '今日 1.2M tokens') } })
1363
+
1364
+ // A rolling upgrade must not blank a publisher: the pre-#1812 host field is
1365
+ // still read when the array is absent.
1366
+ expect(screen.queryByText('今日 1.2M tokens')).not.toBeNull()
1367
+ })
1368
+
1369
+ it('drops a publisher whose ttl lapsed between polls', () => {
1370
+ renderPet({
1371
+ snapshot: {
1372
+ ...snapshot,
1373
+ announcements: [
1374
+ from('dsh-pet-quota', '今日 1.2M tokens', 61_000),
1375
+ from('dsh-pet-notices', '余额 ¥110.00'),
1376
+ ],
1377
+ },
1378
+ })
1379
+
1380
+ expect(screen.queryByText('今日 1.2M tokens')).toBeNull()
1381
+ expect(screen.queryByText('余额 ¥110.00')).not.toBeNull()
1382
+ })
1383
+
1384
+ it('yields the whole stack to interaction feedback', () => {
1385
+ renderPet({
1386
+ snapshot: {
1387
+ ...snapshot,
1388
+ announcements: [
1389
+ from('dsh-pet-quota', '今日 1.2M tokens'),
1390
+ from('dsh-pet-notices', '余额 ¥110.00'),
1391
+ ],
1392
+ },
1393
+ feedback: { text: '摸摸成功', kind: 'pet', at: 3 },
1394
+ })
1395
+
1396
+ expect(screen.queryByText('摸摸成功')).not.toBeNull()
1397
+ expect(screen.queryByText('今日 1.2M tokens')).toBeNull()
1398
+ expect(screen.queryByText('余额 ¥110.00')).toBeNull()
1399
+ })
1400
+ })
1401
+
@@ -50,6 +50,13 @@ export interface PetSpriteProps {
50
50
  onDraggingChange?: (dragging: boolean) => void
51
51
  /** Rename the selected pet (persisted by the host). */
52
52
  onRename: (name: string) => void
53
+ /**
54
+ * Report a click on one plugin-registered action (issue #6). The buttons
55
+ * themselves come from the state snapshot's `panelActions` slice, so the
56
+ * panel renders exactly the registrations the host serves and adds nothing
57
+ * of its own.
58
+ */
59
+ onPanelAction: (id: string) => void
53
60
  /** Navigate to the session one status bubble reports on. */
54
61
  onOpenSession: (sessionId: string) => void
55
62
  /** Clear the reaction bubble (after its CSS animation). */
@@ -616,20 +623,30 @@ export function PetSprite(props: PetSpriteProps): ReactPortal {
616
623
  // is hovered/pinned open. The legacy single 'bubble' is the fallback when
617
624
  // the host serves no per-session list. The hover panel normally sits below
618
625
  // the sprite, so the bubbles stay visible and clickable — no region swap.
619
- const sessionBubbles = snapshot?.sessions ?? []
626
+ // Whether the pet renders its OWN session/status bubbles (issue #6). Only
627
+ // these are gated: the interaction feedback bubble and a sibling plugin's
628
+ // announcement bubble are separate surfaces and keep rendering, so a plugin
629
+ // that drives its own bubble can switch the built-in ones off. A host that
630
+ // predates the field serves no mode at all, which reads as 'auto' — the
631
+ // behavior that shipped before the switch existed.
632
+ const statusBubblesOn = (snapshot?.statusBubbles ?? 'auto') !== 'off'
633
+ const sessionBubbles = statusBubblesOn ? (snapshot?.sessions ?? []) : []
620
634
  const stackOpen = stackPeek || stackPinned
621
635
  const collapsed = !stackOpen && sessionBubbles.length > 1
622
636
  const visibleSessions = collapsed ? sessionBubbles.slice(0, 1) : sessionBubbles
623
- const statusBubble = feedback === null && sessionBubbles.length === 0
637
+ const statusBubble = statusBubblesOn && feedback === null && sessionBubbles.length === 0
624
638
  ? snapshot?.bubble
625
639
  : undefined
626
- // The freshest plugin-authored announcement (dsh-usage linkage): a
627
- // dedicated, specially styled bubble above the session stack. The host
628
- // already TTL-filters; this client-side check covers the last poll tick.
629
- const announcement = snapshot?.announcement
630
- const usageAnnouncement = feedback === null && announcement !== undefined && announcementFresh(announcement, Date.now())
631
- ? announcement
632
- : undefined
640
+ // The plugin-authored announcements: one dedicated, specially styled bubble
641
+ // per publishing plugin above the session stack (issue #1812 — the contract
642
+ // used to hold a single slot, so a second publisher displaced the first).
643
+ // The host already TTL-filters; this client-side check covers the last poll
644
+ // tick. A host predating the array serves the singular field only, and a
645
+ // browser half predating it (this file, before the upgrade) renders the same
646
+ // one bubble, so neither side of a rolling upgrade loses a publisher.
647
+ const announced = snapshot?.announcements ?? (snapshot?.announcement !== undefined ? [snapshot.announcement] : [])
648
+ const now = Date.now()
649
+ const usageAnnouncements = feedback === null ? announced.filter(entry => announcementFresh(entry, now)) : []
633
650
  // Each session's inner whisper (碎碎念) rides its own bubble — short
634
651
  // inner-voice copy woken by that session's activity, never the model's or
635
652
  // another session's. Instead of a second bubble of its own, a fresh
@@ -637,7 +654,7 @@ export function PetSprite(props: PetSpriteProps): ReactPortal {
637
654
  // never wears two voices at once. Interaction feedback takes over the
638
655
  // whole bubble area while it plays, so whispers yield to it like status
639
656
  // copy.
640
- const bubblePresent = feedback !== null || sessionBubbles.length > 0 || statusBubble !== undefined || usageAnnouncement !== undefined
657
+ const bubblePresent = feedback !== null || sessionBubbles.length > 0 || statusBubble !== undefined || usageAnnouncements.length > 0
641
658
  const displayName = snapshot?.name ?? definition.displayName
642
659
  // The host-served status decoration (M5, #567); absent = text-only bubbles.
643
660
  const decoration = snapshot?.decoration
@@ -754,7 +771,7 @@ export function PetSprite(props: PetSpriteProps): ReactPortal {
754
771
  {feedback.text}
755
772
  </div>
756
773
  )}
757
- {feedback === null && (sessionBubbles.length > 0 || statusBubble !== undefined || usageAnnouncement !== undefined) && (
774
+ {feedback === null && (sessionBubbles.length > 0 || statusBubble !== undefined || usageAnnouncements.length > 0) && (
758
775
  <div
759
776
  ref={bubbleRef}
760
777
  className={styles.bubbleStack}
@@ -825,7 +842,16 @@ export function PetSprite(props: PetSpriteProps): ReactPortal {
825
842
  {statusBubble}
826
843
  </div>
827
844
  )}
828
- {usageAnnouncement !== undefined && <UsageAnnouncementBubble announcement={usageAnnouncement} />}
845
+ {/*
846
+ One bubble per publishing plugin, in the order the host serves
847
+ them. Keyed by `source`, not by arrival: a repeating publisher
848
+ updates its own bubble in place instead of remounting (which would
849
+ replay the entrance animation on every poll), and two publishers on
850
+ different cadences keep their positions.
851
+ */}
852
+ {usageAnnouncements.map(entry => (
853
+ <UsageAnnouncementBubble key={entry.source} announcement={entry} />
854
+ ))}
829
855
  </div>
830
856
  )}
831
857
  {hovered && dragRef.current === null && (
@@ -936,6 +962,24 @@ export function PetSprite(props: PetSpriteProps): ReactPortal {
936
962
  {props.t('pet.gameplay.menu')}
937
963
  </button>
938
964
  )}
965
+ {/*
966
+ Plugin-registered actions (issue #6). They follow the built-in
967
+ ones so the pet's own row keeps its fixed order, and they
968
+ carry their registration id as a data attribute so a test (or
969
+ a skin) can address one action without depending on its label.
970
+ */}
971
+ {(snapshot?.panelActions ?? []).map(action => (
972
+ <button
973
+ key={action.id}
974
+ type="button"
975
+ className={styles.action}
976
+ data-dsh-pet-panel-action={action.id}
977
+ {...(action.title === undefined ? {} : { title: action.title })}
978
+ onClick={() => { props.onPanelAction(action.id) }}
979
+ >
980
+ {action.label}
981
+ </button>
982
+ ))}
939
983
  </div>
940
984
  </>
941
985
  )}
@@ -49,7 +49,7 @@ vi.mock('@deepseek-ai/dsh-client-store', () => ({
49
49
  },
50
50
  }))
51
51
  import type { Context as ClientContext } from '@deepseek-ai/cordis'
52
- import { apply } from './index.ts'
52
+ import { apply, BINDER_RETRY_MS } from './index.ts'
53
53
 
54
54
  beforeAll(() => {
55
55
  document.documentElement.lang = 'zh'
@@ -65,8 +65,17 @@ interface FakeClientLifecycle {
65
65
  setEnabled(enabled: boolean): void
66
66
  /** Namespaces the family settings binder was asked for (empty without one). */
67
67
  boundNamespaces(): string[]
68
+ /** Namespaces the framework translate seat was bound for. */
69
+ localeSeats(): string[]
70
+ /** Publish the family settings binder, as the aggregate's async mount does. */
71
+ publishFamilyBinder(enabled: boolean): void
72
+ /** Move the shared mirror to another state and notify its subscribers. */
73
+ settleFallback(status: FallbackStatus): void
68
74
  }
69
75
 
76
+ /** The states the shared per-entry mirror can report for the pet namespace. */
77
+ type FallbackStatus = 'ready' | 'loading' | 'unavailable'
78
+
70
79
  const activeLifecycles: FakeClientLifecycle[] = []
71
80
 
72
81
  afterEach(() => {
@@ -79,6 +88,14 @@ interface FakeContextOptions {
79
88
  familyBinder?: boolean
80
89
  /** Initial value of the settings section the bound form answers with. */
81
90
  enabled?: boolean
91
+ /**
92
+ * What the shared per-entry form answers before any family binder exists.
93
+ * The aggregate renames the pet row to 'web-ui-pet', so the family alias
94
+ * 'pet' is never a served key there and the fallback reports unavailable.
95
+ * 'loading' is the state a host-persisted mirror starts in: it has published
96
+ * no view yet, so it answers nothing either way (#1813).
97
+ */
98
+ fallbackStatus?: FallbackStatus
82
99
  }
83
100
 
84
101
  function fakeContext(options: FakeContextOptions = {}): FakeClientLifecycle {
@@ -86,7 +103,44 @@ function fakeContext(options: FakeContextOptions = {}): FakeClientLifecycle {
86
103
  const settingsListeners = new Set<() => void>()
87
104
  const sessionListeners = new Set<() => void>()
88
105
  const boundNamespaces: string[] = []
106
+ const localeSeats: string[] = []
89
107
  let settingsValue: { enabled?: boolean } | undefined = options.enabled === undefined ? undefined : { enabled: options.enabled }
108
+ // The family binder is published later in the aggregate race; the shared form
109
+ // answers 'unavailable' until then, exactly as the wrongly-keyed fallback does.
110
+ let binderPublished = options.familyBinder === true
111
+ let fallbackStatus: FallbackStatus = options.fallbackStatus ?? 'ready'
112
+ // The shared per-entry form a standalone install answers with: the plugin's
113
+ // own row id IS served, so it carries the same values as the bound scope. A
114
+ // test that sets fallbackStatus to 'unavailable' models the aggregate, where
115
+ // the family alias is never a served key and the form can only report that.
116
+ const fallbackScope = {
117
+ getSnapshot: () => (fallbackStatus === 'ready'
118
+ ? {
119
+ status: 'ready',
120
+ writable: true,
121
+ value: settingsValue,
122
+ base: undefined,
123
+ user: {},
124
+ revision: 1,
125
+ mode: 'host',
126
+ }
127
+ : {
128
+ // 'loading' and 'unavailable' carry no view: the first is the mirror
129
+ // before its first view, the second its answer for a key it never
130
+ // serves. Neither can answer, so neither is writable.
131
+ status: fallbackStatus,
132
+ writable: false,
133
+ value: undefined,
134
+ base: undefined,
135
+ user: {},
136
+ revision: undefined,
137
+ mode: 'host',
138
+ }),
139
+ subscribe: (listener: () => void) => {
140
+ settingsListeners.add(listener)
141
+ return () => { settingsListeners.delete(listener) }
142
+ },
143
+ }
90
144
  const scope = {
91
145
  getSnapshot: () => ({
92
146
  status: 'ready',
@@ -116,11 +170,28 @@ function fakeContext(options: FakeContextOptions = {}): FakeClientLifecycle {
116
170
  disposers.push(cleanup)
117
171
  return cleanup
118
172
  },
119
- locale: { register: () => () => {} },
173
+ locale: {
174
+ register: () => () => {},
175
+ // The framework translate seat for one namespace. The floating surface
176
+ // must be handed this function rather than the plugin's own zh/en
177
+ // dictionary, which resolves by <html lang> and sends every language
178
+ // except English to Chinese.
179
+ bind: (namespace: string) => {
180
+ localeSeats.push(namespace)
181
+ return (key: string) => 'seat:' + key
182
+ },
183
+ },
120
184
  // The family binder is optional (dsh-web-settings may be absent); both
121
185
  // answers are the shared per-entry form of this plugin's own profile entry.
122
- get: (name: string) => name === 'webUiSettings' && options.familyBinder === true ? familyBinder : undefined,
123
- configForms: { get: () => scope },
186
+ get: (name: string) => name === 'webUiSettings' && binderPublished ? familyBinder : undefined,
187
+ configForms: {
188
+ get: () => fallbackScope,
189
+ // The aggregate's mirror names the renamed row; the family alias never
190
+ // appears there, so the fallback lookup cannot resolve it.
191
+ describe: () => ({
192
+ getSnapshot: () => ({ view: { namespaces: [{ ns: 'web-ui-pet' }] } }),
193
+ }),
194
+ },
124
195
  slots: {
125
196
  // Cordis runs the factory when the slot mounts and its returned
126
197
  // disposer when the fiber disposes; mirror that so slot content
@@ -158,6 +229,15 @@ function fakeContext(options: FakeContextOptions = {}): FakeClientLifecycle {
158
229
  sessionsListenerCount: () => sessionListeners.size,
159
230
  setEnabled: (enabled: boolean) => { settingsValue = { enabled } },
160
231
  boundNamespaces: () => boundNamespaces,
232
+ localeSeats: () => localeSeats,
233
+ publishFamilyBinder: (enabled: boolean) => {
234
+ binderPublished = true
235
+ settingsValue = { enabled }
236
+ },
237
+ settleFallback: (status: FallbackStatus) => {
238
+ fallbackStatus = status
239
+ for (const listener of settingsListeners) listener()
240
+ },
161
241
  }
162
242
  activeLifecycles.push(lifecycle)
163
243
  return lifecycle
@@ -171,6 +251,15 @@ describe('pet client apply', () => {
171
251
  expect(root!.getAttribute('data-dsh-plugin')).toBe('pet')
172
252
  })
173
253
 
254
+ it('hands the floating entry the framework locale seat', () => {
255
+ const lifecycle = fakeContext()
256
+ apply(lifecycle.ctx)
257
+ // The floating surface has no session-scoped locale seat, so the mount has
258
+ // to bind the 'pet' namespace explicitly. Resolving copy from the plugin's
259
+ // own zh/en dictionary instead sent every language but English to Chinese.
260
+ expect(lifecycle.localeSeats()).toContain('pet')
261
+ })
262
+
174
263
  it('keeps one global pet root when two client factories overlap (#785)', () => {
175
264
  const first = fakeContext()
176
265
  apply(first.ctx)
@@ -256,6 +345,65 @@ describe('pet client apply', () => {
256
345
  expect(document.body.querySelectorAll('[data-dsh-pet-root]')).toHaveLength(1)
257
346
  })
258
347
 
348
+ it('binds the family binder published AFTER apply, instead of keeping the dead fallback', () => {
349
+ // Given a page where the aggregate mounts its inlined children behind an
350
+ // async fetch: at apply() time the family settings binder does not exist
351
+ // yet, and the shared mirror cannot resolve the 'pet' alias (the aggregate
352
+ // serves the renamed 'web-ui-pet' row), so a single early probe falls back
353
+ // to a permanently unavailable form.
354
+ vi.useFakeTimers()
355
+ const lifecycle = fakeContext({ fallbackStatus: 'unavailable' })
356
+
357
+ // When the pet client plugin applies inside that window
358
+ apply(lifecycle.ctx)
359
+
360
+ // Then no binder was bound yet and the pet surface is not yet up
361
+ expect(lifecycle.boundNamespaces()).toEqual([])
362
+ expect(document.body.querySelectorAll('[data-dsh-pet-root]')).toHaveLength(0)
363
+
364
+ // And when the aggregate finally publishes the binder, the settings form
365
+ // rebinds to the real namespace and the pet surface comes up.
366
+ lifecycle.publishFamilyBinder(true)
367
+ vi.advanceTimersByTime(BINDER_RETRY_MS)
368
+
369
+ expect(lifecycle.boundNamespaces()).toEqual(['pet'])
370
+ expect(document.body.querySelectorAll('[data-dsh-pet-root]')).toHaveLength(1)
371
+ vi.useRealTimers()
372
+ })
373
+
374
+ it('keeps the retry window open while the shared form is still loading, then binds the late binder (#1813)', () => {
375
+ // Given a shared per-entry form that has published no view yet: on the
376
+ // loopback page the official per-row form starts out 'loading' for a
377
+ // host-persisted row, and 'loading' is no more an answer than 'unavailable'
378
+ // is — reading it as settled adopted the fallback on sight, armed no retry,
379
+ // and left the aggregate's binder unpicked forever.
380
+ vi.useFakeTimers()
381
+ const lifecycle = fakeContext({ fallbackStatus: 'loading' })
382
+
383
+ // When the pet client plugin applies inside that window
384
+ apply(lifecycle.ctx)
385
+
386
+ // Then no namespace was bound and the pet surface is not up yet
387
+ expect(lifecycle.boundNamespaces()).toEqual([])
388
+ expect(document.body.querySelectorAll('[data-dsh-pet-root]')).toHaveLength(0)
389
+
390
+ // And when the mirror answers with the aggregate's view — which serves the
391
+ // renamed 'web-ui-pet' row only, so the 'pet' alias can never answer it —
392
+ // the window stays open instead of settling on a form that cannot answer.
393
+ lifecycle.settleFallback('unavailable')
394
+ vi.advanceTimersByTime(BINDER_RETRY_MS)
395
+ expect(lifecycle.boundNamespaces()).toEqual([])
396
+
397
+ // And when the aggregate finally publishes the binder, the form binds the
398
+ // real namespace and the pet surface comes up.
399
+ lifecycle.publishFamilyBinder(true)
400
+ vi.advanceTimersByTime(BINDER_RETRY_MS)
401
+
402
+ expect(lifecycle.boundNamespaces()).toEqual(['pet'])
403
+ expect(document.body.querySelectorAll('[data-dsh-pet-root]')).toHaveLength(1)
404
+ vi.useRealTimers()
405
+ })
406
+
259
407
  it('user gets the pet settings form through the family binder when the group plugin is mounted', () => {
260
408
  // Given a client context that provides the dsh-web-settings family binder
261
409
  // and answers 'disabled' through the form that binder returns