86 lines
3.0 KiB
TypeScript
86 lines
3.0 KiB
TypeScript
import { closeElectronApp, expect, getStableWindow, installIpcMocks, test } from './fixtures/electron';
|
|
|
|
const MAIN_SESSION_KEY = 'agent:main:main';
|
|
|
|
function stableStringify(value: unknown): string {
|
|
if (value == null || typeof value !== 'object') return JSON.stringify(value);
|
|
if (Array.isArray(value)) return `[${value.map((item) => stableStringify(item)).join(',')}]`;
|
|
const entries = Object.entries(value as Record<string, unknown>)
|
|
.sort(([left], [right]) => left.localeCompare(right))
|
|
.map(([key, entryValue]) => `${JSON.stringify(key)}:${stableStringify(entryValue)}`);
|
|
return `{${entries.join(',')}}`;
|
|
}
|
|
|
|
test.describe('ClawX chat session date grouping', () => {
|
|
test('new chat appears in the Today session bucket', async ({ launchElectronApp }) => {
|
|
const app = await launchElectronApp({ skipSetup: true });
|
|
const oldTimestampMs = Date.now() - 35 * 24 * 60 * 60 * 1000;
|
|
const seededHistory = [
|
|
{ role: 'user', content: 'Existing conversation', timestamp: oldTimestampMs },
|
|
{ role: 'assistant', content: 'Existing reply', timestamp: oldTimestampMs + 1000 },
|
|
];
|
|
|
|
try {
|
|
await installIpcMocks(app, {
|
|
gatewayStatus: { state: 'running', port: 18789, pid: 12345 },
|
|
gatewayRpc: {
|
|
[stableStringify(['sessions.list', {}])]: {
|
|
success: true,
|
|
result: {
|
|
sessions: [{
|
|
key: MAIN_SESSION_KEY,
|
|
displayName: 'main',
|
|
updatedAt: oldTimestampMs,
|
|
}],
|
|
},
|
|
},
|
|
[stableStringify(['chat.history', { sessionKey: MAIN_SESSION_KEY, limit: 200 }])]: {
|
|
success: true,
|
|
result: { messages: seededHistory },
|
|
},
|
|
[stableStringify(['chat.history', { sessionKey: MAIN_SESSION_KEY, limit: 1000 }])]: {
|
|
success: true,
|
|
result: { messages: seededHistory },
|
|
},
|
|
},
|
|
hostApi: {
|
|
[stableStringify(['/api/gateway/status', 'GET'])]: {
|
|
ok: true,
|
|
data: {
|
|
status: 200,
|
|
ok: true,
|
|
json: { state: 'running', port: 18789, pid: 12345 },
|
|
},
|
|
},
|
|
[stableStringify(['/api/agents', 'GET'])]: {
|
|
ok: true,
|
|
data: {
|
|
status: 200,
|
|
ok: true,
|
|
json: { success: true, agents: [{ id: 'main', name: 'Main' }] },
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
const page = await getStableWindow(app);
|
|
try {
|
|
await page.reload();
|
|
} catch (error) {
|
|
if (!String(error).includes('ERR_FILE_NOT_FOUND')) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
await expect(page.getByText('Existing conversation')).toBeVisible({ timeout: 30_000 });
|
|
|
|
await page.getByTestId('sidebar-new-chat').click();
|
|
|
|
await expect(page.getByTestId('session-bucket-today').getByText(/agent:main:session-/)).toBeVisible();
|
|
await expect(page.getByTestId('session-bucket-older')).toBeVisible();
|
|
} finally {
|
|
await closeElectronApp(app);
|
|
}
|
|
});
|
|
});
|