Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions test/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,41 @@ describe("pi-context-kit inside Pi", () => {
);
});

it("does not shake when replacing old reads alone brings the context under the threshold", async () => {
const { session } = await start(
[
fauxAssistantMessage([
{
type: "text",
text: ["```ts", "x = 1;".repeat(2_800), "```"].join("\n"),
},
fauxToolCall("read", { path: "b.ts" }),
]),
fauxAssistantMessage(fauxToolCall("read", { path: "b.ts" })),
fauxAssistantMessage("done"),
],
200_000,
true,
{
thresholdTokens: 11_000,
asyncEnabled: false,
prune: { enabled: false },
shake: { protectTokens: 0, minSavings: 1, blockMinTokens: 10 },
},
);
await session.prompt("Read b.ts twice");
const branch = session.sessionManager.getBranch();
const replacements = branch.flatMap((entry) =>
entry.type === "context_edit" ? [JSON.stringify(entry.replacement)] : [],
);
expect(replacements).toHaveLength(1);
expect(replacements[0]).toContain("Superseded by a newer read");
expect(branch.filter((entry) => entry.type === "compaction")).toHaveLength(
0,
);
expect(JSON.stringify(session.messages.at(-1))).toContain("done");
});

it("does not shake before soft when methodOrder puts soft first", async () => {
const { session } = await start(
[
Expand Down
Loading