@flamingo-stack/openframe-frontend-core 0.0.598-2039.5713.1 → 0.0.598
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.
- package/dist/chat-protocol/index.cjs +1 -8
- package/dist/chat-protocol/index.cjs.map +1 -1
- package/dist/chat-protocol/index.d.ts +0 -1
- package/dist/chat-protocol/index.d.ts.map +1 -1
- package/dist/chat-protocol/index.js +2 -7
- package/dist/chat-protocol/index.js.map +1 -1
- package/dist/chat-protocol/nats-decoder.d.ts.map +1 -1
- package/dist/{chunk-TSCIVH7T.js → chunk-2JNCZDJR.js} +2 -2
- package/dist/{chunk-6NSGAH5H.cjs → chunk-2SYX2Z7R.cjs} +34 -34
- package/dist/{chunk-6NSGAH5H.cjs.map → chunk-2SYX2Z7R.cjs.map} +1 -1
- package/dist/{chunk-6ZHH37RS.cjs → chunk-3WSS7C2V.cjs} +15 -15
- package/dist/{chunk-6ZHH37RS.cjs.map → chunk-3WSS7C2V.cjs.map} +1 -1
- package/dist/{chunk-5L4ERWSW.js → chunk-75YW6ET4.js} +4 -4
- package/dist/{chunk-VKCETV3C.js → chunk-BK6CCQG6.js} +12 -12
- package/dist/{chunk-HM25MFZX.cjs → chunk-BPVHDDNY.cjs} +8 -8
- package/dist/{chunk-HM25MFZX.cjs.map → chunk-BPVHDDNY.cjs.map} +1 -1
- package/dist/{chunk-VIBREYUK.cjs → chunk-BZEWPW5A.cjs} +3 -3
- package/dist/{chunk-VIBREYUK.cjs.map → chunk-BZEWPW5A.cjs.map} +1 -1
- package/dist/{chunk-KYWU6F3O.cjs → chunk-DAPOBLAK.cjs} +39 -39
- package/dist/{chunk-KYWU6F3O.cjs.map → chunk-DAPOBLAK.cjs.map} +1 -1
- package/dist/{chunk-DHCA5BZP.cjs → chunk-DI3SVVY5.cjs} +85 -85
- package/dist/{chunk-DHCA5BZP.cjs.map → chunk-DI3SVVY5.cjs.map} +1 -1
- package/dist/{chunk-BLUL2TE3.js → chunk-EVMHJB6X.js} +4 -4
- package/dist/{chunk-S6WBBSII.js → chunk-EZM5DNII.js} +3 -3
- package/dist/{chunk-BVQEU5JB.js → chunk-GGQZBSFN.js} +2 -2
- package/dist/{chunk-KTX5B2FW.js → chunk-GHYFVT52.js} +439 -414
- package/dist/chunk-GHYFVT52.js.map +1 -0
- package/dist/{chunk-CCWI3622.cjs → chunk-H64ZHSYR.cjs} +4 -4
- package/dist/{chunk-CCWI3622.cjs.map → chunk-H64ZHSYR.cjs.map} +1 -1
- package/dist/{chunk-4T42D6YG.js → chunk-HLPAVYK7.js} +4 -4
- package/dist/{chunk-HFHBA3VV.cjs → chunk-HWAYIK4U.cjs} +22 -22
- package/dist/{chunk-HFHBA3VV.cjs.map → chunk-HWAYIK4U.cjs.map} +1 -1
- package/dist/{chunk-CF4QJPTN.cjs → chunk-JVZVVZOZ.cjs} +9 -9
- package/dist/{chunk-CF4QJPTN.cjs.map → chunk-JVZVVZOZ.cjs.map} +1 -1
- package/dist/{chunk-XV7RFACE.js → chunk-KHOZ52NR.js} +6 -6
- package/dist/{chunk-IW746HJ7.js → chunk-LRQCKSZC.js} +2 -2
- package/dist/{chunk-JJUV7Z4L.cjs → chunk-M4YQUHOR.cjs} +15 -15
- package/dist/{chunk-JJUV7Z4L.cjs.map → chunk-M4YQUHOR.cjs.map} +1 -1
- package/dist/{chunk-FKBM6U43.js → chunk-MYBXCWEI.js} +2 -2
- package/dist/{chunk-QTPHBCPI.js → chunk-NIAMPMKV.js} +4 -4
- package/dist/{chunk-UXOOVP77.cjs → chunk-O4VZOA2Q.cjs} +3 -3
- package/dist/{chunk-UXOOVP77.cjs.map → chunk-O4VZOA2Q.cjs.map} +1 -1
- package/dist/{chunk-ABNBTPI2.cjs → chunk-P24VPJTT.cjs} +15 -15
- package/dist/{chunk-ABNBTPI2.cjs.map → chunk-P24VPJTT.cjs.map} +1 -1
- package/dist/{chunk-4XPPQDEM.js → chunk-PTK3CINU.js} +5 -5
- package/dist/{chunk-7FUIRGMU.js → chunk-PX4IPM7Q.js} +3 -3
- package/dist/{chunk-NLT5R43J.cjs → chunk-QD64Q4I2.cjs} +9 -9
- package/dist/{chunk-NLT5R43J.cjs.map → chunk-QD64Q4I2.cjs.map} +1 -1
- package/dist/{chunk-TEVP4KNG.cjs → chunk-QIKBISZM.cjs} +522 -497
- package/dist/chunk-QIKBISZM.cjs.map +1 -0
- package/dist/{chunk-FGNUI4CC.js → chunk-R4UV366K.js} +6 -6
- package/dist/{chunk-UPKZU6QU.cjs → chunk-RDTOMWDN.cjs} +1 -1
- package/dist/chunk-RDTOMWDN.cjs.map +1 -0
- package/dist/{chunk-YB6FI2G3.js → chunk-RYXIRVDC.js} +1 -1
- package/dist/chunk-RYXIRVDC.js.map +1 -0
- package/dist/{chunk-QPAPUIF3.cjs → chunk-SAEJGTCI.cjs} +35 -35
- package/dist/{chunk-QPAPUIF3.cjs.map → chunk-SAEJGTCI.cjs.map} +1 -1
- package/dist/{chunk-66HTVTZZ.js → chunk-SE3PVN64.js} +2 -2
- package/dist/{chunk-3IXDZI3R.cjs → chunk-STYNZ4QM.cjs} +3 -3
- package/dist/{chunk-3IXDZI3R.cjs.map → chunk-STYNZ4QM.cjs.map} +1 -1
- package/dist/{chunk-CQRYXSHL.js → chunk-TZPVRWPU.js} +5 -5
- package/dist/{chunk-RU3IKVY2.js → chunk-UAAXUFK6.js} +3 -3
- package/dist/{chunk-F5NEZLTG.cjs → chunk-UE7OFLLS.cjs} +14 -14
- package/dist/{chunk-F5NEZLTG.cjs.map → chunk-UE7OFLLS.cjs.map} +1 -1
- package/dist/{chunk-VUR24QYH.cjs → chunk-UG7JNQZY.cjs} +37 -37
- package/dist/{chunk-VUR24QYH.cjs.map → chunk-UG7JNQZY.cjs.map} +1 -1
- package/dist/{chunk-UQSOFWXP.cjs → chunk-V2QK5W3O.cjs} +3 -3
- package/dist/{chunk-UQSOFWXP.cjs.map → chunk-V2QK5W3O.cjs.map} +1 -1
- package/dist/{chunk-ZABAXD4U.js → chunk-VIRTMRS4.js} +7 -7
- package/dist/{chunk-D565OOXC.cjs → chunk-VLJTJAHJ.cjs} +25 -25
- package/dist/{chunk-D565OOXC.cjs.map → chunk-VLJTJAHJ.cjs.map} +1 -1
- package/dist/{chunk-K5QV7ZAY.js → chunk-VNSRNVPD.js} +437 -756
- package/dist/chunk-VNSRNVPD.js.map +1 -0
- package/dist/{chunk-UQEOAPAI.cjs → chunk-WCBRZCU4.cjs} +9 -9
- package/dist/{chunk-UQEOAPAI.cjs.map → chunk-WCBRZCU4.cjs.map} +1 -1
- package/dist/{chunk-3XFDRL32.js → chunk-WDWCQD75.js} +9 -9
- package/dist/{chunk-QT35C6CW.js → chunk-WPN545FW.js} +12 -12
- package/dist/{chunk-F2KBCLUG.js → chunk-WZJOILPU.js} +2 -2
- package/dist/{chunk-KAADFO74.js → chunk-XNPAVMPB.js} +5 -5
- package/dist/{chunk-5PPYXXUO.cjs → chunk-YBPFIXV4.cjs} +522 -841
- package/dist/chunk-YBPFIXV4.cjs.map +1 -0
- package/dist/{chunk-EHAYNUOL.cjs → chunk-YH6IQTPI.cjs} +3 -3
- package/dist/{chunk-EHAYNUOL.cjs.map → chunk-YH6IQTPI.cjs.map} +1 -1
- package/dist/{chunk-AVAENPVE.cjs → chunk-YWBAIFI2.cjs} +105 -105
- package/dist/{chunk-AVAENPVE.cjs.map → chunk-YWBAIFI2.cjs.map} +1 -1
- package/dist/components/case-studies/index.cjs +14 -14
- package/dist/components/case-studies/index.js +8 -8
- package/dist/components/chat/embeddable-chat.d.ts +19 -10
- package/dist/components/chat/embeddable-chat.d.ts.map +1 -1
- package/dist/components/chat/hooks/index.d.ts +0 -1
- package/dist/components/chat/hooks/index.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-chat-dialog-manager.d.ts +2 -2
- package/dist/components/chat/hooks/use-chat-dialog-manager.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-chat-history-hydration.d.ts +3 -13
- package/dist/components/chat/hooks/use-chat-history-hydration.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts +16 -2
- package/dist/components/chat/hooks/use-nats-chat-adapter.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-sse-chat-adapter.d.ts.map +1 -1
- package/dist/components/chat/hooks/use-unified-chat.d.ts.map +1 -1
- package/dist/components/chat/index.cjs +5 -9
- package/dist/components/chat/index.cjs.map +1 -1
- package/dist/components/chat/index.js +4 -8
- package/dist/components/chat/types/unified-chat-state.types.d.ts +6 -67
- package/dist/components/chat/types/unified-chat-state.types.d.ts.map +1 -1
- package/dist/components/chat/utils/index.d.ts +0 -1
- package/dist/components/chat/utils/index.d.ts.map +1 -1
- package/dist/components/contact/index.cjs +9 -9
- package/dist/components/contact/index.js +8 -8
- package/dist/components/docs/index.cjs +12 -12
- package/dist/components/docs/index.js +11 -11
- package/dist/components/embeds/index.cjs +9 -9
- package/dist/components/embeds/index.js +8 -8
- package/dist/components/faq/index.cjs +10 -10
- package/dist/components/faq/index.js +9 -9
- package/dist/components/features/index.cjs +8 -8
- package/dist/components/features/index.js +7 -7
- package/dist/components/help-center-pages/index.cjs +31 -31
- package/dist/components/help-center-pages/index.js +22 -22
- package/dist/components/index.cjs +66 -70
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +22 -26
- package/dist/components/index.js.map +1 -1
- package/dist/components/meeting-scheduler/index.cjs +49 -49
- package/dist/components/meeting-scheduler/index.js +9 -9
- package/dist/components/navigation/index.cjs +11 -11
- package/dist/components/navigation/index.js +10 -10
- package/dist/components/onboarding-guides/index.cjs +12 -12
- package/dist/components/onboarding-guides/index.js +11 -11
- package/dist/components/related-content/index.cjs +7 -7
- package/dist/components/related-content/index.js +6 -6
- package/dist/components/tickets/index.cjs +13 -13
- package/dist/components/tickets/index.js +12 -12
- package/dist/components/ui/data-table/data-table-body.d.ts.map +1 -1
- package/dist/components/ui/data-table/data-table-skeleton.d.ts +31 -0
- package/dist/components/ui/data-table/data-table-skeleton.d.ts.map +1 -1
- package/dist/components/ui/index.cjs +8 -12
- package/dist/components/ui/index.cjs.map +1 -1
- package/dist/components/ui/index.js +7 -11
- package/dist/components/ui/table/table-empty-state.d.ts +1 -1
- package/dist/components/ui/table/table-empty-state.d.ts.map +1 -1
- package/dist/components/ui/table/table-skeleton.d.ts +1 -14
- package/dist/components/ui/table/table-skeleton.d.ts.map +1 -1
- package/dist/components/ui/table/table.d.ts +1 -1
- package/dist/components/ui/table/table.d.ts.map +1 -1
- package/dist/components/ui/table/types.d.ts +33 -6
- package/dist/components/ui/table/types.d.ts.map +1 -1
- package/dist/contexts/chat-runtime-context.d.ts +0 -12
- package/dist/contexts/chat-runtime-context.d.ts.map +1 -1
- package/dist/contexts/index.cjs +2 -2
- package/dist/contexts/index.js +1 -1
- package/dist/hooks/index.cjs +5 -5
- package/dist/hooks/index.js +4 -4
- package/dist/index.cjs +12 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/chat-protocol/index.ts +0 -1
- package/src/chat-protocol/nats-decoder.ts +5 -1
- package/src/components/chat/.embeddable-chat.md +2 -4
- package/src/components/chat/embeddable-chat.tsx +84 -131
- package/src/components/chat/hooks/.use-chat-dialog-manager.md +1 -3
- package/src/components/chat/hooks/.use-nats-chat-adapter.md +1 -3
- package/src/components/chat/hooks/.use-sse-chat-adapter.md +1 -8
- package/src/components/chat/hooks/.use-unified-chat.md +2 -2
- package/src/components/chat/hooks/index.ts +0 -2
- package/src/components/chat/hooks/use-chat-dialog-manager.ts +65 -38
- package/src/components/chat/hooks/use-chat-history-hydration.ts +24 -67
- package/src/components/chat/hooks/use-nats-chat-adapter.ts +150 -65
- package/src/components/chat/hooks/use-sse-chat-adapter.ts +59 -233
- package/src/components/chat/hooks/use-unified-chat.ts +0 -5
- package/src/components/chat/types/.unified-chat-state.types.md +1 -13
- package/src/components/chat/types/unified-chat-state.types.ts +6 -74
- package/src/components/chat/utils/index.ts +0 -7
- package/src/components/ui/data-table/data-table-body.tsx +8 -49
- package/src/components/ui/data-table/data-table-skeleton.tsx +100 -0
- package/src/components/ui/table/table-empty-state.tsx +5 -1
- package/src/components/ui/table/table-skeleton.tsx +14 -40
- package/src/components/ui/table/table.tsx +34 -15
- package/src/components/ui/table/types.ts +33 -6
- package/src/contexts/.chat-runtime-context.md +1 -3
- package/src/contexts/chat-runtime-context.tsx +0 -12
- package/dist/chat-protocol/wire-narrow.d.ts +0 -17
- package/dist/chat-protocol/wire-narrow.d.ts.map +0 -1
- package/dist/chunk-5PPYXXUO.cjs.map +0 -1
- package/dist/chunk-K5QV7ZAY.js.map +0 -1
- package/dist/chunk-KTX5B2FW.js.map +0 -1
- package/dist/chunk-TEVP4KNG.cjs.map +0 -1
- package/dist/chunk-UPKZU6QU.cjs.map +0 -1
- package/dist/chunk-YB6FI2G3.js.map +0 -1
- package/dist/components/chat/hooks/use-managed-dialog-list.d.ts +0 -68
- package/dist/components/chat/hooks/use-managed-dialog-list.d.ts.map +0 -1
- package/dist/components/chat/utils/chat-conversations-api.d.ts +0 -29
- package/dist/components/chat/utils/chat-conversations-api.d.ts.map +0 -1
- package/src/chat-protocol/wire-narrow.ts +0 -22
- package/src/components/chat/hooks/.use-managed-dialog-list.md +0 -31
- package/src/components/chat/hooks/__tests__/managed-dialog-list.test.ts +0 -280
- package/src/components/chat/hooks/__tests__/nats-adapter-managed-dialogs.test.ts +0 -172
- package/src/components/chat/hooks/__tests__/sse-managed-dialogs.test.ts +0 -310
- package/src/components/chat/hooks/use-managed-dialog-list.ts +0 -371
- package/src/components/chat/utils/.chat-conversations-api.md +0 -16
- package/src/components/chat/utils/__tests__/chat-conversations-api-golden.test.ts +0 -105
- package/src/components/chat/utils/chat-conversations-api.ts +0 -83
- /package/dist/{chunk-TSCIVH7T.js.map → chunk-2JNCZDJR.js.map} +0 -0
- /package/dist/{chunk-5L4ERWSW.js.map → chunk-75YW6ET4.js.map} +0 -0
- /package/dist/{chunk-VKCETV3C.js.map → chunk-BK6CCQG6.js.map} +0 -0
- /package/dist/{chunk-BLUL2TE3.js.map → chunk-EVMHJB6X.js.map} +0 -0
- /package/dist/{chunk-S6WBBSII.js.map → chunk-EZM5DNII.js.map} +0 -0
- /package/dist/{chunk-BVQEU5JB.js.map → chunk-GGQZBSFN.js.map} +0 -0
- /package/dist/{chunk-4T42D6YG.js.map → chunk-HLPAVYK7.js.map} +0 -0
- /package/dist/{chunk-XV7RFACE.js.map → chunk-KHOZ52NR.js.map} +0 -0
- /package/dist/{chunk-IW746HJ7.js.map → chunk-LRQCKSZC.js.map} +0 -0
- /package/dist/{chunk-FKBM6U43.js.map → chunk-MYBXCWEI.js.map} +0 -0
- /package/dist/{chunk-QTPHBCPI.js.map → chunk-NIAMPMKV.js.map} +0 -0
- /package/dist/{chunk-4XPPQDEM.js.map → chunk-PTK3CINU.js.map} +0 -0
- /package/dist/{chunk-7FUIRGMU.js.map → chunk-PX4IPM7Q.js.map} +0 -0
- /package/dist/{chunk-FGNUI4CC.js.map → chunk-R4UV366K.js.map} +0 -0
- /package/dist/{chunk-66HTVTZZ.js.map → chunk-SE3PVN64.js.map} +0 -0
- /package/dist/{chunk-CQRYXSHL.js.map → chunk-TZPVRWPU.js.map} +0 -0
- /package/dist/{chunk-RU3IKVY2.js.map → chunk-UAAXUFK6.js.map} +0 -0
- /package/dist/{chunk-ZABAXD4U.js.map → chunk-VIRTMRS4.js.map} +0 -0
- /package/dist/{chunk-3XFDRL32.js.map → chunk-WDWCQD75.js.map} +0 -0
- /package/dist/{chunk-QT35C6CW.js.map → chunk-WPN545FW.js.map} +0 -0
- /package/dist/{chunk-F2KBCLUG.js.map → chunk-WZJOILPU.js.map} +0 -0
- /package/dist/{chunk-KAADFO74.js.map → chunk-XNPAVMPB.js.map} +0 -0
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CHARACTERIZATION TESTS — `useNatsChatAdapter` managed-dialog mode.
|
|
3
|
-
*
|
|
4
|
-
* Pins the dialog-list state machine (initial load, retry, pagination,
|
|
5
|
-
* optimistic rename/archive/delete) BEFORE that block moves into the shared
|
|
6
|
-
* `useManagedDialogList` hook consumed by both transport adapters. Every
|
|
7
|
-
* assertion here is observable host behaviour that must survive the
|
|
8
|
-
* extraction byte-for-byte: the wire params sent to `fetchDialogs`, the
|
|
9
|
-
* list contents after each mutation, and the active-id side effects.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { renderHook, act, waitFor } from '@testing-library/react';
|
|
13
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
14
|
-
import type { DialogItem } from '../../types/component.types';
|
|
15
|
-
import { useNatsChatAdapter, type FetchDialogsParams, type UseNatsChatAdapterConfig } from '../use-nats-chat-adapter';
|
|
16
|
-
|
|
17
|
-
const page = (ids: string[], nextCursor: string | null = null) => ({
|
|
18
|
-
dialogs: ids.map<DialogItem>(id => ({ id, title: `Chat ${id}`, timestamp: new Date('2026-01-01T00:00:00Z') })),
|
|
19
|
-
nextCursor,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
function makeConfig(overrides: Partial<UseNatsChatAdapterConfig> = {}): UseNatsChatAdapterConfig {
|
|
23
|
-
return {
|
|
24
|
-
getNatsWsUrl: () => null,
|
|
25
|
-
publishUserMessage: vi.fn(),
|
|
26
|
-
fetchChunks: vi.fn(() => Promise.resolve([])),
|
|
27
|
-
fetchDialogs: vi.fn((_p: FetchDialogsParams) => Promise.resolve(page(['a', 'b']))),
|
|
28
|
-
fetchDialogMessages: vi.fn(() => Promise.resolve({ messages: [], nextCursor: null })),
|
|
29
|
-
renameDialog: vi.fn(() => Promise.resolve()),
|
|
30
|
-
archiveDialog: vi.fn(() => Promise.resolve()),
|
|
31
|
-
deleteDialog: vi.fn(() => Promise.resolve()),
|
|
32
|
-
dialogsPageSize: 2,
|
|
33
|
-
...overrides,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
describe('useNatsChatAdapter — managed-dialog mode (characterization)', () => {
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
40
|
-
});
|
|
41
|
-
afterEach(() => {
|
|
42
|
-
vi.restoreAllMocks();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('loads the first page only when active, with exactly {cursor, limit} (no search key)', async () => {
|
|
46
|
-
const config = makeConfig();
|
|
47
|
-
const { result, rerender } = renderHook(({ active }) => useNatsChatAdapter(config, { active }), {
|
|
48
|
-
initialProps: { active: false },
|
|
49
|
-
});
|
|
50
|
-
expect(config.fetchDialogs).not.toHaveBeenCalled();
|
|
51
|
-
expect(result.current.dialogs).toEqual([]);
|
|
52
|
-
|
|
53
|
-
rerender({ active: true });
|
|
54
|
-
await waitFor(() => expect(result.current.dialogs.map(d => d.id)).toEqual(['a', 'b']));
|
|
55
|
-
expect(config.fetchDialogs).toHaveBeenCalledTimes(1);
|
|
56
|
-
const params = (config.fetchDialogs as ReturnType<typeof vi.fn>).mock.calls[0][0] as FetchDialogsParams;
|
|
57
|
-
expect(params).toEqual({ cursor: undefined, limit: 2 });
|
|
58
|
-
expect(Object.keys(params)).toEqual(['cursor', 'limit']);
|
|
59
|
-
expect(result.current.dialogsError).toBe(false);
|
|
60
|
-
expect(result.current.isDialogsLoading).toBe(false);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('first-page failure flags dialogsError and reloadDialogs retries', async () => {
|
|
64
|
-
const fetchDialogs = vi
|
|
65
|
-
.fn<(p: FetchDialogsParams) => Promise<ReturnType<typeof page>>>()
|
|
66
|
-
.mockRejectedValueOnce(new Error('boom'))
|
|
67
|
-
.mockResolvedValue(page(['a']));
|
|
68
|
-
const config = makeConfig({ fetchDialogs });
|
|
69
|
-
const { result } = renderHook(() => useNatsChatAdapter(config));
|
|
70
|
-
await waitFor(() => expect(result.current.dialogsError).toBe(true));
|
|
71
|
-
expect(result.current.dialogs).toEqual([]);
|
|
72
|
-
|
|
73
|
-
act(() => result.current.reloadDialogs());
|
|
74
|
-
await waitFor(() => expect(result.current.dialogs.map(d => d.id)).toEqual(['a']));
|
|
75
|
-
expect(result.current.dialogsError).toBe(false);
|
|
76
|
-
expect(fetchDialogs).toHaveBeenCalledTimes(2);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('paginates with the server cursor; a pagination failure keeps the loaded rows', async () => {
|
|
80
|
-
const fetchDialogs = vi
|
|
81
|
-
.fn<(p: FetchDialogsParams) => Promise<ReturnType<typeof page>>>()
|
|
82
|
-
.mockResolvedValueOnce(page(['a', 'b'], 'c2'))
|
|
83
|
-
.mockRejectedValueOnce(new Error('page 2 down'))
|
|
84
|
-
.mockResolvedValueOnce(page(['c'], null));
|
|
85
|
-
const config = makeConfig({ fetchDialogs });
|
|
86
|
-
const { result } = renderHook(() => useNatsChatAdapter(config));
|
|
87
|
-
await waitFor(() => expect(result.current.hasMoreDialogs).toBe(true));
|
|
88
|
-
|
|
89
|
-
await act(async () => {
|
|
90
|
-
await result.current.loadMoreDialogs();
|
|
91
|
-
});
|
|
92
|
-
expect(fetchDialogs.mock.calls[1][0]).toEqual({ cursor: 'c2', limit: 2 });
|
|
93
|
-
expect(result.current.dialogs.map(d => d.id)).toEqual(['a', 'b']);
|
|
94
|
-
expect(result.current.dialogsError).toBe(false);
|
|
95
|
-
expect(result.current.hasMoreDialogs).toBe(true);
|
|
96
|
-
|
|
97
|
-
await act(async () => {
|
|
98
|
-
await result.current.loadMoreDialogs();
|
|
99
|
-
});
|
|
100
|
-
expect(result.current.dialogs.map(d => d.id)).toEqual(['a', 'b', 'c']);
|
|
101
|
-
expect(result.current.hasMoreDialogs).toBe(false);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('rename is optimistic, rolls back AND surfaces the failure', async () => {
|
|
105
|
-
const renameDialog = vi
|
|
106
|
-
.fn<(id: string, title: string) => Promise<void>>()
|
|
107
|
-
.mockResolvedValueOnce(undefined)
|
|
108
|
-
.mockRejectedValueOnce(new Error('nope'));
|
|
109
|
-
const config = makeConfig({ renameDialog });
|
|
110
|
-
const { result } = renderHook(() => useNatsChatAdapter(config));
|
|
111
|
-
await waitFor(() => expect(result.current.dialogs.length).toBe(2));
|
|
112
|
-
|
|
113
|
-
await act(async () => {
|
|
114
|
-
await result.current.renameDialog('a', 'Renamed');
|
|
115
|
-
});
|
|
116
|
-
expect(result.current.dialogs.find(d => d.id === 'a')?.title).toBe('Renamed');
|
|
117
|
-
|
|
118
|
-
await act(async () => {
|
|
119
|
-
// Re-thrown (like archive/delete) so a rename modal can stay open — a
|
|
120
|
-
// silent rollback would just look like the title flickering back.
|
|
121
|
-
await expect(result.current.renameDialog('a', 'Will fail')).rejects.toThrow('nope');
|
|
122
|
-
});
|
|
123
|
-
expect(result.current.dialogs.find(d => d.id === 'a')?.title).toBe('Renamed');
|
|
124
|
-
expect(renameDialog).toHaveBeenCalledTimes(2);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('archiving the ACTIVE dialog removes it and clears activeDialogId; delete removes too', async () => {
|
|
128
|
-
const config = makeConfig();
|
|
129
|
-
const { result } = renderHook(() => useNatsChatAdapter(config));
|
|
130
|
-
await waitFor(() => expect(result.current.dialogs.length).toBe(2));
|
|
131
|
-
|
|
132
|
-
act(() => result.current.selectDialog('a'));
|
|
133
|
-
expect(result.current.activeDialogId).toBe('a');
|
|
134
|
-
|
|
135
|
-
await act(async () => {
|
|
136
|
-
await result.current.archiveDialog('a');
|
|
137
|
-
});
|
|
138
|
-
expect(config.archiveDialog).toHaveBeenCalledWith('a');
|
|
139
|
-
expect(result.current.dialogs.map(d => d.id)).toEqual(['b']);
|
|
140
|
-
expect(result.current.activeDialogId).toBeNull();
|
|
141
|
-
|
|
142
|
-
await act(async () => {
|
|
143
|
-
await result.current.deleteDialog('b');
|
|
144
|
-
});
|
|
145
|
-
expect(config.deleteDialog).toHaveBeenCalledWith('b');
|
|
146
|
-
expect(result.current.dialogs).toEqual([]);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('archive failure keeps the row and the active id, and surfaces the error', async () => {
|
|
150
|
-
const config = makeConfig({ archiveDialog: vi.fn(() => Promise.reject(new Error('down'))) });
|
|
151
|
-
const { result } = renderHook(() => useNatsChatAdapter(config));
|
|
152
|
-
await waitFor(() => expect(result.current.dialogs.length).toBe(2));
|
|
153
|
-
act(() => result.current.selectDialog('a'));
|
|
154
|
-
await act(async () => {
|
|
155
|
-
// Re-thrown (was swallowed before the shared-hook extraction) so a
|
|
156
|
-
// confirmation modal can stay open instead of closing on a write the
|
|
157
|
-
// server rejected.
|
|
158
|
-
await expect(result.current.archiveDialog('a')).rejects.toThrow('down');
|
|
159
|
-
});
|
|
160
|
-
expect(result.current.dialogs.map(d => d.id)).toEqual(['a', 'b']);
|
|
161
|
-
expect(result.current.activeDialogId).toBe('a');
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('bare-transport mode (no fetchDialogs) never lists and ignores selectDialog', () => {
|
|
165
|
-
const config = makeConfig({ fetchDialogs: undefined, dialogId: 'host-owned' });
|
|
166
|
-
const { result } = renderHook(() => useNatsChatAdapter(config));
|
|
167
|
-
act(() => result.current.selectDialog('other'));
|
|
168
|
-
expect(result.current.activeDialogId).toBe('host-owned');
|
|
169
|
-
expect(result.current.dialogs).toEqual([]);
|
|
170
|
-
expect(result.current.hasMoreDialogs).toBe(false);
|
|
171
|
-
});
|
|
172
|
-
});
|
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GOLDEN CONTRACT TESTS — Guide/SSE adapter with a managed conversation list
|
|
3
|
-
* (`ChatRuntime.endpoints.chatConversationsUrl`).
|
|
4
|
-
*
|
|
5
|
-
* Pins:
|
|
6
|
-
* - mount with a stored id → `activeDialogId` = stored, ONE list GET
|
|
7
|
-
* (`status=active&limit=20`), ONE history GET;
|
|
8
|
-
* - `selectDialog('b')` → thread reset, history GET for `b`, storage = `b`,
|
|
9
|
-
* `isMessagesLoading` true → false;
|
|
10
|
-
* - `clearMessages` → draft state (null id, storage cleared);
|
|
11
|
-
* - first send of a NEW conversation → id captured from the metadata frame,
|
|
12
|
-
* NO history GET for that id, list re-read at end of turn;
|
|
13
|
-
* - rename / archive / restore go to the PATCH wire; archiving the open
|
|
14
|
-
* conversation drops to draft;
|
|
15
|
-
* - ZERO-REGRESSION: without the endpoint `dialogs` is `[]`,
|
|
16
|
-
* `dialogsManaged` is false and no conversations request is issued.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
20
|
-
import { renderHook, act, waitFor } from '@testing-library/react';
|
|
21
|
-
import { createElement, type ReactNode } from 'react';
|
|
22
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
23
|
-
import { ChatRuntimeContext, type ChatRuntime } from '../../../../contexts/chat-runtime-context';
|
|
24
|
-
import { useSseChatAdapter } from '../use-sse-chat-adapter';
|
|
25
|
-
|
|
26
|
-
const SOURCE = 'managedsrc';
|
|
27
|
-
const CONVERSATION_KEY = `mingo-chat-${SOURCE}.conversation`;
|
|
28
|
-
const CONVERSATIONS_URL = '/api/docs/chat/conversations';
|
|
29
|
-
|
|
30
|
-
const baseEndpoints: ChatRuntime['endpoints'] = {
|
|
31
|
-
chatStreamUrl: '/api/docs/chat',
|
|
32
|
-
approvalToolUrl: '/api/chat/agent/confirm-tool',
|
|
33
|
-
commandsUrl: '/api/docs/commands',
|
|
34
|
-
buildListUrl: () => null,
|
|
35
|
-
attachmentUploadUrl: '/api/storage/generate-upload-url',
|
|
36
|
-
attachmentViewUrlPrefix: '/api/storage/view/chat-attachments/',
|
|
37
|
-
identityUrl: '/api/chat/identity',
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
function makeWrapper(runtime: ChatRuntime) {
|
|
41
|
-
return function wrapper({ children }: { children: ReactNode }) {
|
|
42
|
-
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
43
|
-
return createElement(
|
|
44
|
-
QueryClientProvider,
|
|
45
|
-
{ client: queryClient },
|
|
46
|
-
createElement(ChatRuntimeContext.Provider, { value: runtime }, children),
|
|
47
|
-
);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const managedRuntime: ChatRuntime = {
|
|
52
|
-
endpoints: { ...baseEndpoints, chatConversationsUrl: CONVERSATIONS_URL },
|
|
53
|
-
navigation: { mode: 'host' },
|
|
54
|
-
source: SOURCE,
|
|
55
|
-
};
|
|
56
|
-
const plainRuntime: ChatRuntime = { endpoints: baseEndpoints, navigation: { mode: 'host' }, source: SOURCE };
|
|
57
|
-
|
|
58
|
-
const enc = new TextEncoder();
|
|
59
|
-
function streamOf(chunks: string[]): ReadableStream<Uint8Array> {
|
|
60
|
-
return new ReadableStream<Uint8Array>({
|
|
61
|
-
start(controller) {
|
|
62
|
-
for (const c of chunks) controller.enqueue(enc.encode(c));
|
|
63
|
-
controller.close();
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
const USAGE_END_TRAILER = '{"kind":"usage","stage":"end","input_tokens":10,"output_tokens":5,"hit_rate_pct":50}';
|
|
68
|
-
function wireTurn(conversationId: string, answer: string): string[] {
|
|
69
|
-
return [
|
|
70
|
-
`{"modelLabel":"Claude Sonnet","provider":"anthropic","conversationId":"${conversationId}"}\0`,
|
|
71
|
-
'\x1E',
|
|
72
|
-
answer,
|
|
73
|
-
'\x1F' + USAGE_END_TRAILER,
|
|
74
|
-
];
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const historyFor = (id: string) => ({
|
|
78
|
-
data: {
|
|
79
|
-
messages: [
|
|
80
|
-
{ seq: 0, role: 'user', content: `q for ${id}`, created_at: '2026-09-01T09:00:00.000Z' },
|
|
81
|
-
{ seq: 1, role: 'assistant', content: `a for ${id}`, created_at: '2026-09-01T09:00:05.000Z' },
|
|
82
|
-
],
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
const listPayload = (ids: string[]) => ({
|
|
86
|
-
data: {
|
|
87
|
-
dialogs: ids.map(id => ({ id, title: `Chat ${id}`, timestamp: '2026-09-01T09:00:00.000Z' })),
|
|
88
|
-
nextCursor: null,
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
type Call = { url: string; init: RequestInit };
|
|
93
|
-
function mockFetch(options: { list?: () => unknown; streams?: string[][] }) {
|
|
94
|
-
const calls: Call[] = [];
|
|
95
|
-
let streamCall = 0;
|
|
96
|
-
const fetchMock = vi.fn((url: string, init?: RequestInit) => {
|
|
97
|
-
const u = String(url);
|
|
98
|
-
calls.push({ url: u, init: init ?? {} });
|
|
99
|
-
const json = (body: unknown, status = 200) =>
|
|
100
|
-
Promise.resolve({ ok: status < 300, status, json: () => Promise.resolve(body) } as unknown as Response);
|
|
101
|
-
if (u.startsWith(CONVERSATIONS_URL + '/')) return json({ data: { id: 'x' } });
|
|
102
|
-
if (u.startsWith(CONVERSATIONS_URL)) return json(options.list ? options.list() : listPayload([]));
|
|
103
|
-
if (u.includes('/history')) {
|
|
104
|
-
const id = new URL(u, 'http://x').searchParams.get('conversationId') ?? '';
|
|
105
|
-
return json(historyFor(id));
|
|
106
|
-
}
|
|
107
|
-
if (u.includes('/commands')) return json({ commands: [] });
|
|
108
|
-
const streams = options.streams ?? [];
|
|
109
|
-
const chunks = streams[Math.min(streamCall, streams.length - 1)] ?? [];
|
|
110
|
-
streamCall += 1;
|
|
111
|
-
return Promise.resolve({ ok: true, status: 200, body: streamOf(chunks) } as unknown as Response);
|
|
112
|
-
});
|
|
113
|
-
vi.stubGlobal('fetch', fetchMock);
|
|
114
|
-
return { fetchMock, calls };
|
|
115
|
-
}
|
|
116
|
-
const urlsOf = (calls: Call[], prefix: string) => calls.filter(c => c.url.startsWith(prefix)).map(c => c.url);
|
|
117
|
-
|
|
118
|
-
describe('useSseChatAdapter — managed conversation list', () => {
|
|
119
|
-
beforeEach(() => {
|
|
120
|
-
window.localStorage.clear();
|
|
121
|
-
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
122
|
-
});
|
|
123
|
-
afterEach(() => {
|
|
124
|
-
vi.restoreAllMocks();
|
|
125
|
-
vi.unstubAllGlobals();
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('mount with a stored id: lists once, hydrates once, highlights the stored conversation', async () => {
|
|
129
|
-
window.localStorage.setItem(CONVERSATION_KEY, JSON.stringify({ conversationId: 'a' }));
|
|
130
|
-
const { calls } = mockFetch({ list: () => listPayload(['a', 'b']) });
|
|
131
|
-
const { result } = renderHook(() => useSseChatAdapter(), { wrapper: makeWrapper(managedRuntime) });
|
|
132
|
-
|
|
133
|
-
await waitFor(() => expect(result.current.dialogs.map(d => d.id)).toEqual(['a', 'b']));
|
|
134
|
-
await waitFor(() => expect(result.current.messages.length).toBe(2));
|
|
135
|
-
expect(result.current.dialogsManaged).toBe(true);
|
|
136
|
-
expect(result.current.activeDialogId).toBe('a');
|
|
137
|
-
expect(urlsOf(calls, CONVERSATIONS_URL)).toEqual([`${CONVERSATIONS_URL}?status=active&limit=20`]);
|
|
138
|
-
expect(urlsOf(calls, '/api/docs/chat/history')).toEqual(['/api/docs/chat/history?conversationId=a']);
|
|
139
|
-
expect(result.current.dialogCapabilities).toMatchObject({ canRename: true, canArchive: true, searchQuery: '' });
|
|
140
|
-
expect(result.current.dialogCapabilities?.fetchArchivedDialogs).toBeTypeOf('function');
|
|
141
|
-
expect(result.current.dialogCapabilities?.unarchiveDialog).toBeTypeOf('function');
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('selectDialog switches the thread: reset, hydrate the new id, persist it', async () => {
|
|
145
|
-
window.localStorage.setItem(CONVERSATION_KEY, JSON.stringify({ conversationId: 'a' }));
|
|
146
|
-
const { calls } = mockFetch({ list: () => listPayload(['a', 'b']) });
|
|
147
|
-
const { result } = renderHook(() => useSseChatAdapter(), { wrapper: makeWrapper(managedRuntime) });
|
|
148
|
-
await waitFor(() => expect(result.current.messages.length).toBe(2));
|
|
149
|
-
|
|
150
|
-
act(() => result.current.selectDialog('b'));
|
|
151
|
-
expect(result.current.activeDialogId).toBe('b');
|
|
152
|
-
expect(JSON.parse(window.localStorage.getItem(CONVERSATION_KEY) ?? '{}')).toEqual({ conversationId: 'b' });
|
|
153
|
-
await waitFor(() => expect(result.current.messages.map(m => m.content)).toEqual(['q for b', 'a for b']));
|
|
154
|
-
expect(result.current.isMessagesLoading).toBe(false);
|
|
155
|
-
expect(urlsOf(calls, '/api/docs/chat/history')).toEqual([
|
|
156
|
-
'/api/docs/chat/history?conversationId=a',
|
|
157
|
-
'/api/docs/chat/history?conversationId=b',
|
|
158
|
-
]);
|
|
159
|
-
|
|
160
|
-
// Idempotent on the active id — no extra fetch.
|
|
161
|
-
act(() => result.current.selectDialog('b'));
|
|
162
|
-
expect(urlsOf(calls, '/api/docs/chat/history').length).toBe(2);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('clearMessages drops to draft state (null id, storage cleared)', async () => {
|
|
166
|
-
window.localStorage.setItem(CONVERSATION_KEY, JSON.stringify({ conversationId: 'a' }));
|
|
167
|
-
mockFetch({ list: () => listPayload(['a']) });
|
|
168
|
-
const { result } = renderHook(() => useSseChatAdapter(), { wrapper: makeWrapper(managedRuntime) });
|
|
169
|
-
await waitFor(() => expect(result.current.messages.length).toBe(2));
|
|
170
|
-
act(() => result.current.clearMessages());
|
|
171
|
-
expect(result.current.activeDialogId).toBeNull();
|
|
172
|
-
expect(result.current.messages).toEqual([]);
|
|
173
|
-
expect(window.localStorage.getItem(CONVERSATION_KEY)).toBeNull();
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('first send: captures the minted id WITHOUT hydrating it, and re-reads the list at end of turn', async () => {
|
|
177
|
-
let listed = 0;
|
|
178
|
-
const { calls } = mockFetch({
|
|
179
|
-
list: () => {
|
|
180
|
-
listed += 1;
|
|
181
|
-
return listed === 1 ? listPayload([]) : listPayload(['conv-new']);
|
|
182
|
-
},
|
|
183
|
-
streams: [wireTurn('conv-new', 'Hello there.')],
|
|
184
|
-
});
|
|
185
|
-
const { result } = renderHook(() => useSseChatAdapter(), { wrapper: makeWrapper(managedRuntime) });
|
|
186
|
-
await waitFor(() => expect(listed).toBe(1));
|
|
187
|
-
|
|
188
|
-
await act(async () => {
|
|
189
|
-
await result.current.sendMessage('first question');
|
|
190
|
-
});
|
|
191
|
-
expect(result.current.activeDialogId).toBe('conv-new');
|
|
192
|
-
expect(urlsOf(calls, '/api/docs/chat/history')).toEqual([]);
|
|
193
|
-
await waitFor(() => expect(listed).toBe(2));
|
|
194
|
-
expect(result.current.dialogs.map(d => d.id)).toEqual(['conv-new']);
|
|
195
|
-
// The streamed turn is the thread — nothing was prepended by hydration.
|
|
196
|
-
expect(result.current.messages.map(m => m.role)).toEqual(['user', 'assistant']);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('rename / archive / restore hit the PATCH wire; archiving the open chat drops to draft', async () => {
|
|
200
|
-
window.localStorage.setItem(CONVERSATION_KEY, JSON.stringify({ conversationId: 'a' }));
|
|
201
|
-
const { calls } = mockFetch({ list: () => listPayload(['a', 'b']) });
|
|
202
|
-
const { result } = renderHook(() => useSseChatAdapter(), { wrapper: makeWrapper(managedRuntime) });
|
|
203
|
-
await waitFor(() => expect(result.current.dialogs.length).toBe(2));
|
|
204
|
-
|
|
205
|
-
await act(async () => {
|
|
206
|
-
await result.current.renameDialog('b', 'Renamed B');
|
|
207
|
-
});
|
|
208
|
-
expect(result.current.dialogs.find(d => d.id === 'b')?.title).toBe('Renamed B');
|
|
209
|
-
|
|
210
|
-
await act(async () => {
|
|
211
|
-
await result.current.archiveDialog('a');
|
|
212
|
-
});
|
|
213
|
-
expect(result.current.dialogs.map(d => d.id)).toEqual(['b']);
|
|
214
|
-
expect(result.current.activeDialogId).toBeNull();
|
|
215
|
-
|
|
216
|
-
await act(async () => {
|
|
217
|
-
await result.current.dialogCapabilities?.unarchiveDialog?.('a');
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
const patches = calls.filter(c => c.url.startsWith(CONVERSATIONS_URL + '/'));
|
|
221
|
-
const parseBody = (c: Call): unknown => JSON.parse(String(c.init.body));
|
|
222
|
-
expect(patches.map(c => [c.url, c.init.method, parseBody(c)])).toEqual([
|
|
223
|
-
[`${CONVERSATIONS_URL}/b`, 'PATCH', { title: 'Renamed B' }],
|
|
224
|
-
[`${CONVERSATIONS_URL}/a`, 'PATCH', { archived: true }],
|
|
225
|
-
[`${CONVERSATIONS_URL}/a`, 'PATCH', { archived: false }],
|
|
226
|
-
]);
|
|
227
|
-
// Restore re-reads the active list.
|
|
228
|
-
expect(urlsOf(calls, `${CONVERSATIONS_URL}?`).length).toBeGreaterThanOrEqual(2);
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('search term change re-reads page 1 with `search`', async () => {
|
|
232
|
-
const { calls } = mockFetch({ list: () => listPayload(['a']) });
|
|
233
|
-
const { result } = renderHook(() => useSseChatAdapter(), { wrapper: makeWrapper(managedRuntime) });
|
|
234
|
-
await waitFor(() => expect(result.current.dialogs.length).toBe(1));
|
|
235
|
-
act(() => result.current.dialogCapabilities?.onSearchChange?.('print'));
|
|
236
|
-
await waitFor(() =>
|
|
237
|
-
expect(urlsOf(calls, `${CONVERSATIONS_URL}?`)).toEqual([
|
|
238
|
-
`${CONVERSATIONS_URL}?status=active&limit=20`,
|
|
239
|
-
`${CONVERSATIONS_URL}?status=active&limit=20&search=print`,
|
|
240
|
-
]),
|
|
241
|
-
);
|
|
242
|
-
expect(result.current.dialogCapabilities?.searchQuery).toBe('print');
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
it('never wedges on the message skeleton when a hydration is superseded', async () => {
|
|
246
|
-
window.localStorage.setItem(CONVERSATION_KEY, JSON.stringify({ conversationId: 'a' }));
|
|
247
|
-
mockFetch({ list: () => listPayload(['a', 'b']) });
|
|
248
|
-
const { result } = renderHook(() => useSseChatAdapter(), { wrapper: makeWrapper(managedRuntime) });
|
|
249
|
-
await waitFor(() => expect(result.current.messages.length).toBe(2));
|
|
250
|
-
|
|
251
|
-
// "New chat" while a hydration could still be in flight: the loading flag
|
|
252
|
-
// must clear, or `hasConversation` pins the panel on a skeleton forever.
|
|
253
|
-
act(() => result.current.clearMessages());
|
|
254
|
-
await waitFor(() => expect(result.current.isMessagesLoading).toBe(false));
|
|
255
|
-
expect(result.current.activeDialogId).toBeNull();
|
|
256
|
-
|
|
257
|
-
// Same for selecting away mid-flight.
|
|
258
|
-
act(() => result.current.selectDialog('b'));
|
|
259
|
-
act(() => result.current.selectDialog(null));
|
|
260
|
-
await waitFor(() => expect(result.current.isMessagesLoading).toBe(false));
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it('keeps a stored id whose thread is legitimately empty but owned', async () => {
|
|
264
|
-
window.localStorage.setItem(CONVERSATION_KEY, JSON.stringify({ conversationId: 'empty-but-mine' }));
|
|
265
|
-
const { fetchMock } = mockFetch({ list: () => listPayload([]) });
|
|
266
|
-
fetchMock.mockImplementation((url: string) => {
|
|
267
|
-
const u = String(url);
|
|
268
|
-
const json = (body: unknown) =>
|
|
269
|
-
Promise.resolve({ ok: true, status: 200, json: () => Promise.resolve(body) } as unknown as Response);
|
|
270
|
-
// Owned, just has no rows yet — the id must SURVIVE.
|
|
271
|
-
if (u.includes('/history')) return json({ conversationId: 'empty-but-mine', messages: [], found: true });
|
|
272
|
-
if (u.startsWith(CONVERSATIONS_URL)) return json(listPayload([]));
|
|
273
|
-
return json({ commands: [] });
|
|
274
|
-
});
|
|
275
|
-
const { result } = renderHook(() => useSseChatAdapter(), { wrapper: makeWrapper(managedRuntime) });
|
|
276
|
-
await waitFor(() => expect(result.current.dialogsManaged).toBe(true));
|
|
277
|
-
await new Promise(resolve => setTimeout(resolve, 20));
|
|
278
|
-
expect(window.localStorage.getItem(CONVERSATION_KEY)).not.toBeNull();
|
|
279
|
-
expect(result.current.activeDialogId).toBe('empty-but-mine');
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
it('drops a stored id the server reports as not ours (found: false)', async () => {
|
|
283
|
-
window.localStorage.setItem(CONVERSATION_KEY, JSON.stringify({ conversationId: 'gone' }));
|
|
284
|
-
const { fetchMock } = mockFetch({ list: () => listPayload([]) });
|
|
285
|
-
fetchMock.mockImplementation((url: string) => {
|
|
286
|
-
const u = String(url);
|
|
287
|
-
const json = (body: unknown) =>
|
|
288
|
-
Promise.resolve({ ok: true, status: 200, json: () => Promise.resolve(body) } as unknown as Response);
|
|
289
|
-
// `found: false` = the server does not recognize this id for us.
|
|
290
|
-
if (u.includes('/history')) return json({ conversationId: 'gone', messages: [], found: false });
|
|
291
|
-
if (u.startsWith(CONVERSATIONS_URL)) return json(listPayload([]));
|
|
292
|
-
return json({ commands: [] });
|
|
293
|
-
});
|
|
294
|
-
const { result } = renderHook(() => useSseChatAdapter(), { wrapper: makeWrapper(managedRuntime) });
|
|
295
|
-
await waitFor(() => expect(window.localStorage.getItem(CONVERSATION_KEY)).toBeNull());
|
|
296
|
-
expect(result.current.activeDialogId).toBeNull();
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
it('ZERO-REGRESSION: without chatConversationsUrl the single-thread stubs are returned', async () => {
|
|
300
|
-
window.localStorage.setItem(CONVERSATION_KEY, JSON.stringify({ conversationId: 'a' }));
|
|
301
|
-
const { calls } = mockFetch({});
|
|
302
|
-
const { result } = renderHook(() => useSseChatAdapter(), { wrapper: makeWrapper(plainRuntime) });
|
|
303
|
-
await waitFor(() => expect(result.current.messages.length).toBe(2));
|
|
304
|
-
expect(result.current.dialogs).toEqual([]);
|
|
305
|
-
expect(result.current.dialogsManaged).toBe(false);
|
|
306
|
-
expect(result.current.dialogCapabilities).toBeUndefined();
|
|
307
|
-
expect(result.current.activeDialogId).toBeNull();
|
|
308
|
-
expect(urlsOf(calls, CONVERSATIONS_URL)).toEqual([]);
|
|
309
|
-
});
|
|
310
|
-
});
|