* ui: let a menu action open a submenu Group and project pickers open as flyouts from a chat's menus. Master's menu list has no submenus, so bring them back next to its tooltips, with a close callback for picks made inside them. Assisted-by: Claude (Opus 5.5 Medium) * ui : store groups and let conversations join them Groups live in their own IndexedDB table (schema version 2) with a name. groupsStore creates, renames and deletes them; deleting a group keeps its chats, out of any group. A conversation records the group it is sorted into, and a group picked before the first message is kept pending and applied when the conversation is created. Assisted-by: Claude (Opus 5.5 Medium) * ui : show each group as a sidebar section Every group is a sidebar section next to Pinned and Recent, folding, showing its first six chats and dragged into place like them. A chat dropped on a group joins it and leaves Pinned; dropped on Recent, it leaves its group. Recent is called Ungrouped once a group exists, and its menus create a group in a small naming dialog; so does a right-click anywhere in the list that no row or heading takes, down to the empty space under the last section. A group's heading starts a new chat in it, and its menus rename or delete it; deleting keeps its chats, back in Ungrouped. Assisted-by: Claude (Opus 5.5 Medium) * ui : move chats into groups from their menus A chat's menus, in the sidebar and on right-click, move it into a group or take it out of its group. Desktop menus show a searchable group flyout whose New group entry names a group in the group dialog and moves the chat into it; a phone gets a picker dialog instead, which creates a group from what is typed. Assisted-by: Claude (Opus 5.5 Medium) * ui: open the group picker from a phone's hold menu The hold menu is anchored to the row, so it showed the desktop flyout, which ran off the left edge of the screen and whose New group closed without naming one. On a phone, Move to group now opens the picker dialog, as intended. Assisted-by: Claude (Opus 5.5 Medium) * ui: open a new chat in a tab of its own With conversation tabs on, New chat from the sidebar, a group's heading or the shortcut replaced the open chat's tab. It now adds a tab, as the tab bar's "+" does, and the open chat keeps its own. Assisted-by: Claude (Opus 5.5 Medium) * ui: list a phone's groups under the picker's search On a phone the picker fills the screen, and its grid spread the rows over the height, so the list sat in the middle. It is now a column: the list starts under the search and scrolls in the rest of the screen. Assisted-by: Claude (Opus 5.5 Medium) * ui: fix gaps in chat groups found in review - A phone shows a group heading's New chat and menu, and the Ungrouped heading's menu, which were reachable only by hover or right-click. - A pinned chat moved into a group from its menu leaves Pinned, as a drag onto the group already did, so the move shows. - Only the sidebar's New chat, a group's New chat and the new-chat shortcut open a new tab; stepping past the last chat, search and the models drawer show the new-chat screen in the current tab again. - An export carries each chat's group, and an import sorts the chat into the group of that id or name, or creates it; a group the file does not carry is dropped. - The group picked with a group's New chat survives leaving the new-chat tab and coming back. - A phone's menus skip any submenu in the shared menu list, not only the group one. - Deleting a group forgets its section's place and fold. - Groups load newest first by creation, so a rename no longer moves one after a reload. - groupsStore looks groups up in a map and answers which live group a chat is in, for the three places that checked it by hand. Assisted-by: Claude (Opus 5.5 Medium) * ui: keep a forked chat in its source chat's group A fork copied the working directory but not the group, so it landed in Ungrouped. Assisted-by: Claude (Opus 5.5 Medium) * ui: move a chat with its whole fork family between groups Moving a chat into a group, or out of one, takes its parents and its children along, so a fork tree never splits across sidebar sections. A pinned member that joins a group leaves Pinned with the rest. Group sections render the tree with its depth, as Ungrouped does. * ui: show the group name prompt as a small centered card on phones The new and rename group prompt opened full screen on a phone, like a large dialog. It is now built on the alert dialog, as the chat rename prompt is, so a phone shows it as a card in the middle of the screen. Its Cancel is a plain button, so Enter in the name field saves. Assisted-by: Claude (Opus 5.5 Medium) * ui: space a phone's group sections like Ungrouped On a phone a group or Pinned section put its first chat right under the heading, where Ungrouped leaves a row gap. They now leave the same gap, and the sections sit a little further apart than the rows inside them. Assisted-by: Claude (Opus 5.5 Medium) --------- Co-authored-by: Pascal <admin@serveurperso.com>
176 lines
5.7 KiB
TypeScript
176 lines
5.7 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
vi.mock('$lib/services/database.service', () => ({
|
|
DatabaseService: { getAllGroups: vi.fn(async () => []), getConversationsWithMessages: vi.fn() }
|
|
}));
|
|
|
|
import { MessageRole, MessageType } from '$lib/enums';
|
|
import { ConversationTransferService } from '$lib/services/conversation-transfer.service';
|
|
import { DatabaseService } from '$lib/services/database.service';
|
|
import { conversationsStore } from '$lib/stores/conversations/index.svelte';
|
|
import type { DatabaseConversation, DatabaseMessage } from '$lib/types/database';
|
|
import { filterByLeafNodeId } from '$lib/utils/branching';
|
|
|
|
/**
|
|
* Reproduces the exported-conversation bug:
|
|
*
|
|
* A conversation created in the current page session keeps `currNode: ''` in the
|
|
* sidebar list, because that list is only loaded at init while IndexedDB is stamped
|
|
* on every message insert.
|
|
*
|
|
* Exporting from the cached record resulted in no branch pointer, and importing
|
|
* the file showed every branch at once.
|
|
*/
|
|
|
|
const fetchMock = vi.mocked(DatabaseService.getConversationsWithMessages);
|
|
|
|
beforeEach(() => {
|
|
fetchMock.mockReset();
|
|
});
|
|
|
|
const CONV_ID = 'c1';
|
|
|
|
function message(
|
|
id: string,
|
|
parent: string | null,
|
|
timestamp: number,
|
|
role: MessageRole,
|
|
type: MessageType = MessageType.TEXT
|
|
): DatabaseMessage {
|
|
return {
|
|
children: [],
|
|
content: id,
|
|
convId: CONV_ID,
|
|
id,
|
|
parent,
|
|
role,
|
|
timestamp,
|
|
toolCalls: '',
|
|
type
|
|
} as DatabaseMessage;
|
|
}
|
|
|
|
/** root -> u1 -> a1 -> { u2a -> a2a (older) | u2b -> a2b (newer) } */
|
|
function branchedMessages(): DatabaseMessage[] {
|
|
const messages = [
|
|
message('root', null, 10, MessageRole.USER, MessageType.ROOT),
|
|
message('u1', 'root', 20, MessageRole.USER),
|
|
message('a1', 'u1', 30, MessageRole.ASSISTANT),
|
|
message('u2a', 'a1', 40, MessageRole.USER),
|
|
message('a2a', 'u2a', 50, MessageRole.ASSISTANT),
|
|
message('u2b', 'a1', 60, MessageRole.USER),
|
|
message('a2b', 'u2b', 70, MessageRole.ASSISTANT)
|
|
];
|
|
|
|
for (const m of messages) {
|
|
m.children = messages.filter((c) => c.parent === m.id).map((c) => c.id);
|
|
}
|
|
|
|
return messages;
|
|
}
|
|
|
|
/** A second conversation with a single linear path: root -> u1 -> a1. */
|
|
function linearMessages(convId: string): DatabaseMessage[] {
|
|
return [
|
|
{ ...message('root', null, 10, MessageRole.USER, MessageType.ROOT), children: ['u1'], convId },
|
|
{ ...message('u1', 'root', 20, MessageRole.USER), children: ['a1'], convId },
|
|
{ ...message('a1', 'u1', 30, MessageRole.ASSISTANT), convId }
|
|
];
|
|
}
|
|
|
|
function conversation(currNode: string, id: string = CONV_ID): DatabaseConversation {
|
|
return { currNode, id, lastModified: 100, name: `Chat ${id}` };
|
|
}
|
|
|
|
/** Mirrors `conversationsStore.loadConversation` */
|
|
function displayedIds(imported: { conv: DatabaseConversation; messages: DatabaseMessage[] }) {
|
|
if (imported.conv.currNode) {
|
|
return filterByLeafNodeId(imported.messages, imported.conv.currNode, false).map((m) => m.id);
|
|
}
|
|
|
|
return imported.messages.map((m) => m.id);
|
|
}
|
|
|
|
/** Export then re-import */
|
|
function roundTrip(conv: DatabaseConversation) {
|
|
const jsonl = ConversationTransferService.serializeSessionToJsonl({
|
|
conv,
|
|
messages: branchedMessages()
|
|
});
|
|
const [imported] = ConversationTransferService.parseSessionsJsonl(jsonl);
|
|
|
|
return { imported, sessionLine: JSON.parse(jsonl.split('\n')[0]) };
|
|
}
|
|
|
|
describe('conversation export source', () => {
|
|
it('reads the database record rather than the stale sidebar list', async () => {
|
|
conversationsStore.conversations = [conversation('')];
|
|
|
|
fetchMock.mockResolvedValue(
|
|
new Map([[CONV_ID, { conv: conversation('a2a'), messages: branchedMessages() }]])
|
|
);
|
|
|
|
const [exported] = await conversationsStore.getConversationsForExport([CONV_ID]);
|
|
|
|
expect(exported.conv.currNode).toBe('a2a');
|
|
expect(conversationsStore.conversations[0].currNode).toBe('');
|
|
});
|
|
|
|
it('reads every selected conversation from the database on bulk export', async () => {
|
|
conversationsStore.conversations = [conversation(''), conversation('', 'c2')];
|
|
conversationsStore.activeConversation = conversation('');
|
|
|
|
fetchMock.mockResolvedValue(
|
|
new Map([
|
|
['c2', { conv: conversation('a1', 'c2'), messages: linearMessages('c2') }],
|
|
[CONV_ID, { conv: conversation('a2a'), messages: branchedMessages() }]
|
|
])
|
|
);
|
|
|
|
const archive = vi
|
|
.spyOn(ConversationTransferService, 'downloadConversationsArchive')
|
|
.mockImplementation(() => {});
|
|
|
|
await conversationsStore.bulkExportConversations([CONV_ID, 'c2']);
|
|
|
|
expect(fetchMock).toHaveBeenCalledWith([CONV_ID, 'c2']);
|
|
expect(archive).toHaveBeenCalledTimes(1);
|
|
|
|
const payload = archive.mock.calls[0][0];
|
|
|
|
expect(payload.map((entry) => entry.conv.id)).toEqual([CONV_ID, 'c2']);
|
|
// Each entry carries its own database currNode.
|
|
expect(payload.map((entry) => entry.conv.currNode)).toEqual(['a2a', 'a1']);
|
|
expect(payload[1].messages.map((m: DatabaseMessage) => m.id)).toEqual(['root', 'u1', 'a1']);
|
|
|
|
archive.mockRestore();
|
|
});
|
|
});
|
|
|
|
describe('exported conversation branch pointer', () => {
|
|
it('carries the database currNode, so the import restores the current branch', () => {
|
|
// The user regenerated to create a2b, then switched back to the a2a branch,
|
|
// so the stored leaf is NOT the newest message.
|
|
const { imported, sessionLine } = roundTrip(conversation('a2a'));
|
|
|
|
expect(sessionLine.currNode).toBe('a2a');
|
|
expect(displayedIds(imported)).toEqual(['u1', 'a1', 'u2a', 'a2a']);
|
|
expect(imported.messages.map((m: DatabaseMessage) => m.id).sort()).toEqual([
|
|
'a1',
|
|
'a2a',
|
|
'a2b',
|
|
'root',
|
|
'u1',
|
|
'u2a',
|
|
'u2b'
|
|
]);
|
|
});
|
|
|
|
it('shows every branch on import when the cache entry exported an empty currNode', () => {
|
|
const { imported, sessionLine } = roundTrip(conversation(''));
|
|
|
|
expect(sessionLine.currNode).toBe('');
|
|
expect(displayedIds(imported)).toEqual(['root', 'u1', 'a1', 'u2a', 'a2a', 'u2b', 'a2b']);
|
|
});
|
|
});
|