forked from NousResearch/hermes-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(desktop): paint cached transcripts on session click (switch-paint) #296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| // Switch-paint from the render cache (Ace 2026-07-11: "clicking a session for | ||
| // the first time doesn't feel snappy"). Contract under test: | ||
| // 1. readCachedTranscript returns rows for a cached session, null otherwise; | ||
| // it NEVER throws (fail-open) — a broken preload API is a miss. | ||
| // 2. normalizeCachedTranscriptRows handles BOTH writer shapes: raw | ||
| // SessionMessage rows (transcript preloader) convert via toChatMessages; | ||
| // already-converted ChatMessage rows (write-through) pass through. | ||
| // 3. Empty/garbage normalizes to [] — the switch falls through to the | ||
| // network, never paints a blank. | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import { normalizeCachedTranscriptRows, readCachedTranscript } from './render-cache-hydration' | ||
|
|
||
| function installApi(readTranscript: unknown) { | ||
| ;(window as any).hermesDesktop = { renderCache: { readTranscript } } | ||
| } | ||
|
|
||
| describe('readCachedTranscript (switch-paint)', () => { | ||
| beforeEach(() => { | ||
| delete (window as any).hermesDesktop | ||
| }) | ||
|
|
||
| it('returns cached rows for a hit', async () => { | ||
| installApi(vi.fn().mockResolvedValue({ rows: [{ role: 'user', content: 'hi' }] })) | ||
| const rows = await readCachedTranscript('s1') | ||
| expect(rows).toEqual([{ role: 'user', content: 'hi' }]) | ||
| }) | ||
|
|
||
| it('passes a null gatewayUrl (main resolves it) and the session id', async () => { | ||
| const read = vi.fn().mockResolvedValue({ rows: [1] }) | ||
| installApi(read) | ||
| await readCachedTranscript('s42') | ||
| expect(read).toHaveBeenCalledWith(null, 's42') | ||
| }) | ||
|
|
||
| it('misses on null payload, empty rows, and missing id', async () => { | ||
| installApi(vi.fn().mockResolvedValue(null)) | ||
| expect(await readCachedTranscript('s1')).toBeNull() | ||
|
|
||
| installApi(vi.fn().mockResolvedValue({ rows: [] })) | ||
| expect(await readCachedTranscript('s1')).toBeNull() | ||
|
|
||
| installApi(vi.fn().mockResolvedValue({ rows: [1] })) | ||
| expect(await readCachedTranscript(null)).toBeNull() | ||
| expect(await readCachedTranscript('')).toBeNull() | ||
| }) | ||
|
|
||
| it('fail-open: missing bridge, missing method, rejecting IPC are all misses', async () => { | ||
| expect(await readCachedTranscript('s1')).toBeNull() // no hermesDesktop at all | ||
|
|
||
| ;(window as any).hermesDesktop = { renderCache: {} } // no readTranscript method | ||
| expect(await readCachedTranscript('s1')).toBeNull() | ||
|
|
||
| installApi(vi.fn().mockRejectedValue(new Error('ipc down'))) | ||
| expect(await readCachedTranscript('s1')).toBeNull() | ||
| }) | ||
|
|
||
| it('tolerates a malformed payload (rows not an array)', async () => { | ||
| installApi(vi.fn().mockResolvedValue({ rows: 'garbage' })) | ||
| expect(await readCachedTranscript('s1')).toBeNull() | ||
| }) | ||
| }) | ||
|
|
||
| describe('normalizeCachedTranscriptRows (dual writer shapes)', () => { | ||
| it('passes ChatMessage-shaped rows (write-through) straight through', () => { | ||
| const rows = [{ id: 'm1', role: 'user', parts: [{ type: 'text', text: 'hi' }] }] | ||
| expect(normalizeCachedTranscriptRows(rows)).toBe(rows) | ||
| }) | ||
|
|
||
| it('converts raw SessionMessage rows (preloader) via toChatMessages', () => { | ||
| const raw = [ | ||
| { role: 'user', content: 'hello' }, | ||
| { role: 'assistant', content: 'hey there' } | ||
| ] | ||
| const out = normalizeCachedTranscriptRows(raw) | ||
| expect(out.length).toBeGreaterThan(0) | ||
| expect(out[0]).toHaveProperty('parts') | ||
| expect(out[0].role).toBe('user') | ||
| }) | ||
|
|
||
| it('empty/garbage input normalizes to [] (a miss, never a blank paint)', () => { | ||
| expect(normalizeCachedTranscriptRows([])).toEqual([]) | ||
| expect(normalizeCachedTranscriptRows(null as never)).toEqual([]) | ||
| expect(normalizeCachedTranscriptRows('nope' as never)).toEqual([]) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
partsfieldIf the cache ever contains a heterogeneous array — e.g., a first
ChatMessagewhosepartsfield isnullorundefined(possible if a write-through stored a malformed row) — the entire array falls through totoChatMessages, which treats it asSessionMessage[]. Conversely, a first row that happens to carry apartskey for an unrelated reason would bypasstoChatMessagesentirely. Sincerowsis typed asunknown[], nothing enforces homogeneity at the call site. After this PR both writers produceChatMessage-shaped rows, so this is a backward-compat path for old cache files — but the sniff-by-first-element assumption is worth a clarifying comment.