mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-06 02:41:48 +00:00
Keep the latest prompt sticky while the viewport is in live assistant output beyond history, and clear stale sticky state at the real bottom using fresh scroll height.
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { getViewportSnapshot, viewportSnapshotKey } from '../lib/viewportStore.js'
|
|
|
|
describe('viewportStore', () => {
|
|
it('normalizes absent scroll handles', () => {
|
|
expect(getViewportSnapshot(null)).toEqual({
|
|
atBottom: true,
|
|
bottom: 0,
|
|
pending: 0,
|
|
scrollHeight: 0,
|
|
top: 0,
|
|
viewportHeight: 0
|
|
})
|
|
})
|
|
|
|
it('includes pending scroll delta in snapshot math and keying', () => {
|
|
const handle = {
|
|
getPendingDelta: () => 3,
|
|
getScrollHeight: () => 40,
|
|
getScrollTop: () => 10,
|
|
getViewportHeight: () => 5,
|
|
isSticky: () => false
|
|
}
|
|
|
|
const snap = getViewportSnapshot(handle as any)
|
|
|
|
expect(snap).toMatchObject({
|
|
atBottom: false,
|
|
bottom: 18,
|
|
pending: 3,
|
|
scrollHeight: 40,
|
|
top: 13,
|
|
viewportHeight: 5
|
|
})
|
|
expect(viewportSnapshotKey(snap)).toBe('0:16:5:40:3')
|
|
})
|
|
|
|
it('uses fresh scroll height to clear stale non-bottom state', () => {
|
|
const handle = {
|
|
getFreshScrollHeight: () => 20,
|
|
getPendingDelta: () => 0,
|
|
getScrollHeight: () => 40,
|
|
getScrollTop: () => 15,
|
|
getViewportHeight: () => 5,
|
|
isSticky: () => false
|
|
}
|
|
|
|
const snap = getViewportSnapshot(handle as any)
|
|
|
|
expect(snap.atBottom).toBe(true)
|
|
expect(snap.scrollHeight).toBe(20)
|
|
})
|
|
})
|