fix(coding-agent): add entry renderers for session entries

This commit is contained in:
Mario Zechner
2026-07-01 11:00:14 +02:00
parent 8c9436407c
commit ba10b60b51
18 changed files with 507 additions and 158 deletions
@@ -1,8 +1,10 @@
import { describe, expect, it } from "vitest";
import {
type BranchSummaryEntry,
buildContextEntries,
buildSessionContext,
type CompactionEntry,
type CustomEntry,
type ModelChangeEntry,
type SessionEntry,
type SessionMessageEntry,
@@ -52,6 +54,10 @@ function branchSummary(id: string, parentId: string | null, summary: string, fro
return { type: "branch_summary", id, parentId, timestamp: "2025-01-01T00:00:00Z", summary, fromId };
}
function custom(id: string, parentId: string | null, customType: string, data?: unknown): CustomEntry {
return { type: "custom", id, parentId, timestamp: "2025-01-01T00:00:00Z", customType, data };
}
function thinkingLevel(id: string, parentId: string | null, level: string): ThinkingLevelChangeEntry {
return { type: "thinking_level_change", id, parentId, timestamp: "2025-01-01T00:00:00Z", thinkingLevel: level };
}
@@ -169,6 +175,37 @@ describe("buildSessionContext", () => {
expect(ctx.messages).toHaveLength(4);
expect((ctx.messages[0] as any).summary).toContain("Second summary");
});
it("buildContextEntries returns compaction-aware entries including custom entries", () => {
const entries: SessionEntry[] = [
msg("1", null, "user", "first"),
custom("2", "1", "old-state", { hidden: true }),
msg("3", "2", "assistant", "response1"),
custom("4", "3", "kept-card", { title: "Kept" }),
msg("5", "4", "user", "second"),
compaction("6", "5", "Summary", "4"),
custom("7", "6", "after-card", { title: "After" }),
msg("8", "7", "assistant", "response2"),
];
expect(buildContextEntries(entries).map((entry) => entry.id)).toEqual(["6", "4", "5", "7", "8"]);
const ctx = buildSessionContext(entries);
expect(ctx.messages.map((message) => message.role)).toEqual(["compactionSummary", "user", "assistant"]);
});
it("keeps settings from the full path after compaction", () => {
const entries: SessionEntry[] = [
msg("1", null, "user", "first"),
thinkingLevel("2", "1", "high"),
msg("3", "2", "assistant", "response1"),
msg("4", "3", "user", "second"),
compaction("5", "4", "Summary", "4"),
];
const ctx = buildSessionContext(entries);
expect(ctx.thinkingLevel).toBe("high");
expect(ctx.messages.map((message) => message.role)).toEqual(["compactionSummary", "user"]);
});
});
describe("with branches", () => {