test(runtime): strengthen sessionThread compaction-skip + undecodable coverage
This commit is contained in:
1 parent
67178e018a
commit
f35070594f
2 files changed
+24
-2
No files matched your search
@@ -161,6 +161,8 @@ func (r *Runtime) turnSlice(startLen int, done bool, reason string, usage *llm.U
|
||||
// (assistant), tool results as their output or "[error] <err>" (user).
|
||||
// Compaction/meta and non-user/assistant message entries are skipped — the
|
||||
// thread carries only conversation turns and tool exchanges.
|
||||
// On the runtime's per-turn serve path each call sees one turn's fresh session,
|
||||
// so a compaction summary's absence here is intentional, not a gap.
|
||||
func sessionThread(history []session.SessionEntry) []Message {
|
||||
var thread []Message
|
||||
for _, e := range history {
|
||||
|
||||
@@ -29,16 +29,36 @@ func TestSessionThread_RendersEntries(t *testing.T) {
|
||||
|
||||
func TestSessionThread_SkipsCompaction(t *testing.T) {
|
||||
sess := session.NewSession("a", "k")
|
||||
// Compaction is appended FIRST so the entries that follow remain on the
|
||||
// View() walk-back path. View() stops its back-walk at the most recent
|
||||
// compaction (inclusive), so appending user/assistant AFTER it yields
|
||||
// View() == [compaction, user, assistant] — the compaction is genuinely
|
||||
// present in the slice handed to sessionThread, exercising the skip path.
|
||||
// (Appending compaction last would make it the leaf, and View() would
|
||||
// return only [compaction], never reaching the messages.)
|
||||
sess.Append(session.CompactionEntry("summary", "", "", "m", 0, 0, 0))
|
||||
sess.Append(session.UserMessageEntry("hello"))
|
||||
sess.Append(session.AssistantMessageEntry("hi"))
|
||||
// Build the expected from whatever View() returns, minus any compaction/meta.
|
||||
got := sessionThread(sess.View())
|
||||
|
||||
view := sess.View()
|
||||
require.Equal(t, session.EntryTypeCompaction, view[0].Type, "View() must include the compaction entry to exercise the skip")
|
||||
|
||||
got := sessionThread(view)
|
||||
require.Equal(t, []Message{
|
||||
{Role: "user", Content: "hello"},
|
||||
{Role: "assistant", Content: "hi"},
|
||||
}, got)
|
||||
}
|
||||
|
||||
func TestSessionThread_SkipsUndecodableEntry(t *testing.T) {
|
||||
history := []session.SessionEntry{
|
||||
{Type: session.EntryTypeToolCall, Data: []byte("not json")},
|
||||
session.UserMessageEntry("after"),
|
||||
}
|
||||
got := sessionThread(history)
|
||||
require.Equal(t, []Message{{Role: "user", Content: "after"}}, got)
|
||||
}
|
||||
|
||||
func TestSessionThread_Empty(t *testing.T) {
|
||||
require.Nil(t, sessionThread(nil))
|
||||
}
|
||||
Reference in new issue
Block a user