mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-22 11:04:42 -07:00
refactor(cli,core): foundational layout, identity management, and type safety (#23286)
This commit is contained in:
@@ -39,6 +39,56 @@ describe('useHistoryManager', () => {
|
||||
expect(result.current.history[0].id).toBeGreaterThanOrEqual(timestamp);
|
||||
});
|
||||
|
||||
it('should generate strictly increasing IDs even if baseTimestamp goes backwards', async () => {
|
||||
const { result } = await renderHook(() => useHistory());
|
||||
const timestamp = 1000000;
|
||||
const itemData: Omit<HistoryItem, 'id'> = { type: 'info', text: 'First' };
|
||||
|
||||
let id1!: number;
|
||||
let id2!: number;
|
||||
|
||||
act(() => {
|
||||
id1 = result.current.addItem(itemData, timestamp);
|
||||
// Try to add with a smaller timestamp
|
||||
id2 = result.current.addItem(itemData, timestamp - 500);
|
||||
});
|
||||
|
||||
expect(id1).toBe(timestamp);
|
||||
expect(id2).toBe(id1 + 1);
|
||||
expect(result.current.history[1].id).toBe(id2);
|
||||
});
|
||||
|
||||
it('should ensure new IDs start after existing IDs when resuming a session', async () => {
|
||||
const initialItems: HistoryItem[] = [
|
||||
{ id: 5000, type: 'info', text: 'Existing' },
|
||||
];
|
||||
const { result } = await renderHook(() => useHistory({ initialItems }));
|
||||
|
||||
let newId!: number;
|
||||
act(() => {
|
||||
// Try to add with a timestamp smaller than the highest existing ID
|
||||
newId = result.current.addItem({ type: 'info', text: 'New' }, 2000);
|
||||
});
|
||||
|
||||
expect(newId).toBe(5001);
|
||||
expect(result.current.history[1].id).toBe(5001);
|
||||
});
|
||||
|
||||
it('should update lastIdRef when loading new history', async () => {
|
||||
const { result } = await renderHook(() => useHistory());
|
||||
|
||||
act(() => {
|
||||
result.current.loadHistory([{ id: 8000, type: 'info', text: 'Loaded' }]);
|
||||
});
|
||||
|
||||
let newId!: number;
|
||||
act(() => {
|
||||
newId = result.current.addItem({ type: 'info', text: 'New' }, 1000);
|
||||
});
|
||||
|
||||
expect(newId).toBe(8001);
|
||||
});
|
||||
|
||||
it('should generate unique IDs for items added with the same base timestamp', async () => {
|
||||
const { result } = await renderHook(() => useHistory());
|
||||
const timestamp = Date.now();
|
||||
@@ -215,8 +265,8 @@ describe('useHistoryManager', () => {
|
||||
const after = Date.now();
|
||||
|
||||
expect(result.current.history).toHaveLength(1);
|
||||
// ID should be >= before + 1 (since counter starts at 0 and increments to 1)
|
||||
expect(result.current.history[0].id).toBeGreaterThanOrEqual(before + 1);
|
||||
// ID should be >= before (since baseTimestamp defaults to Date.now())
|
||||
expect(result.current.history[0].id).toBeGreaterThanOrEqual(before);
|
||||
expect(result.current.history[0].id).toBeLessThanOrEqual(after + 1);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user