feat(coding-agent): expose post-compaction token estimates
closes #5877
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
type Model,
|
||||
} from "@earendil-works/pi-ai";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { estimateTokens } from "../../src/core/compaction/index.ts";
|
||||
import { createHarness, type Harness } from "./harness.ts";
|
||||
|
||||
type SessionWithCompactionInternals = {
|
||||
@@ -118,8 +119,10 @@ describe("AgentSession compaction characterization", () => {
|
||||
|
||||
const result = await harness.session.compact();
|
||||
const compactionEntries = harness.sessionManager.getEntries().filter((entry) => entry.type === "compaction");
|
||||
const estimatedTokensAfter = harness.session.messages.reduce((sum, message) => sum + estimateTokens(message), 0);
|
||||
|
||||
expect(result.summary).toBe("summary from extension");
|
||||
expect(result.estimatedTokensAfter).toBe(estimatedTokensAfter);
|
||||
expect(compactionEntries).toHaveLength(1);
|
||||
expect(harness.session.messages[0]?.role).toBe("compactionSummary");
|
||||
});
|
||||
@@ -161,7 +164,9 @@ describe("AgentSession compaction characterization", () => {
|
||||
await sessionInternals._runAutoCompaction("threshold", false);
|
||||
|
||||
const compactionEntries = harness.sessionManager.getEntries().filter((entry) => entry.type === "compaction");
|
||||
const compactionEnd = harness.eventsOfType("compaction_end").at(-1);
|
||||
expect(compactionEntries).toHaveLength(1);
|
||||
expect(compactionEnd?.result?.estimatedTokensAfter).toBeGreaterThan(0);
|
||||
expect(getStreamCallCount()).toBe(1);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user