core: fix session compaction test to properly enable prune config option
This commit is contained in:
@@ -564,65 +564,13 @@ describe("session.compaction.create", () => {
|
|||||||
describe("session.compaction.prune", () => {
|
describe("session.compaction.prune", () => {
|
||||||
it.live(
|
it.live(
|
||||||
"compacts old completed tool output",
|
"compacts old completed tool output",
|
||||||
provideTmpdirInstance((dir) =>
|
provideTmpdirInstance(
|
||||||
Effect.gen(function* () {
|
(dir) =>
|
||||||
const compact = yield* SessionCompaction.Service
|
Effect.gen(function* () {
|
||||||
const ssn = yield* SessionNs.Service
|
const compact = yield* SessionCompaction.Service
|
||||||
const info = yield* ssn.create({})
|
const ssn = yield* SessionNs.Service
|
||||||
const a = yield* ssn.updateMessage({
|
const info = yield* ssn.create({})
|
||||||
id: MessageID.ascending(),
|
const a = yield* ssn.updateMessage({
|
||||||
role: "user",
|
|
||||||
sessionID: info.id,
|
|
||||||
agent: "build",
|
|
||||||
model: ref,
|
|
||||||
time: { created: Date.now() },
|
|
||||||
})
|
|
||||||
yield* ssn.updatePart({
|
|
||||||
id: PartID.ascending(),
|
|
||||||
messageID: a.id,
|
|
||||||
sessionID: info.id,
|
|
||||||
type: "text",
|
|
||||||
text: "first",
|
|
||||||
})
|
|
||||||
const b: MessageV2.Assistant = {
|
|
||||||
id: MessageID.ascending(),
|
|
||||||
role: "assistant",
|
|
||||||
sessionID: info.id,
|
|
||||||
mode: "build",
|
|
||||||
agent: "build",
|
|
||||||
path: { cwd: dir, root: dir },
|
|
||||||
cost: 0,
|
|
||||||
tokens: {
|
|
||||||
output: 0,
|
|
||||||
input: 0,
|
|
||||||
reasoning: 0,
|
|
||||||
cache: { read: 0, write: 0 },
|
|
||||||
},
|
|
||||||
modelID: ref.modelID,
|
|
||||||
providerID: ref.providerID,
|
|
||||||
parentID: a.id,
|
|
||||||
time: { created: Date.now() },
|
|
||||||
finish: "end_turn",
|
|
||||||
}
|
|
||||||
yield* ssn.updateMessage(b)
|
|
||||||
yield* ssn.updatePart({
|
|
||||||
id: PartID.ascending(),
|
|
||||||
messageID: b.id,
|
|
||||||
sessionID: info.id,
|
|
||||||
type: "tool",
|
|
||||||
callID: crypto.randomUUID(),
|
|
||||||
tool: "bash",
|
|
||||||
state: {
|
|
||||||
status: "completed",
|
|
||||||
input: {},
|
|
||||||
output: "x".repeat(200_000),
|
|
||||||
title: "done",
|
|
||||||
metadata: {},
|
|
||||||
time: { start: Date.now(), end: Date.now() },
|
|
||||||
},
|
|
||||||
})
|
|
||||||
for (const text of ["second", "third"]) {
|
|
||||||
const msg = yield* ssn.updateMessage({
|
|
||||||
id: MessageID.ascending(),
|
id: MessageID.ascending(),
|
||||||
role: "user",
|
role: "user",
|
||||||
sessionID: info.id,
|
sessionID: info.id,
|
||||||
@@ -632,23 +580,82 @@ describe("session.compaction.prune", () => {
|
|||||||
})
|
})
|
||||||
yield* ssn.updatePart({
|
yield* ssn.updatePart({
|
||||||
id: PartID.ascending(),
|
id: PartID.ascending(),
|
||||||
messageID: msg.id,
|
messageID: a.id,
|
||||||
sessionID: info.id,
|
sessionID: info.id,
|
||||||
type: "text",
|
type: "text",
|
||||||
text,
|
text: "first",
|
||||||
})
|
})
|
||||||
}
|
const b: MessageV2.Assistant = {
|
||||||
|
id: MessageID.ascending(),
|
||||||
|
role: "assistant",
|
||||||
|
sessionID: info.id,
|
||||||
|
mode: "build",
|
||||||
|
agent: "build",
|
||||||
|
path: { cwd: dir, root: dir },
|
||||||
|
cost: 0,
|
||||||
|
tokens: {
|
||||||
|
output: 0,
|
||||||
|
input: 0,
|
||||||
|
reasoning: 0,
|
||||||
|
cache: { read: 0, write: 0 },
|
||||||
|
},
|
||||||
|
modelID: ref.modelID,
|
||||||
|
providerID: ref.providerID,
|
||||||
|
parentID: a.id,
|
||||||
|
time: { created: Date.now() },
|
||||||
|
finish: "end_turn",
|
||||||
|
}
|
||||||
|
yield* ssn.updateMessage(b)
|
||||||
|
yield* ssn.updatePart({
|
||||||
|
id: PartID.ascending(),
|
||||||
|
messageID: b.id,
|
||||||
|
sessionID: info.id,
|
||||||
|
type: "tool",
|
||||||
|
callID: crypto.randomUUID(),
|
||||||
|
tool: "bash",
|
||||||
|
state: {
|
||||||
|
status: "completed",
|
||||||
|
input: {},
|
||||||
|
output: "x".repeat(200_000),
|
||||||
|
title: "done",
|
||||||
|
metadata: {},
|
||||||
|
time: { start: Date.now(), end: Date.now() },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
for (const text of ["second", "third"]) {
|
||||||
|
const msg = yield* ssn.updateMessage({
|
||||||
|
id: MessageID.ascending(),
|
||||||
|
role: "user",
|
||||||
|
sessionID: info.id,
|
||||||
|
agent: "build",
|
||||||
|
model: ref,
|
||||||
|
time: { created: Date.now() },
|
||||||
|
})
|
||||||
|
yield* ssn.updatePart({
|
||||||
|
id: PartID.ascending(),
|
||||||
|
messageID: msg.id,
|
||||||
|
sessionID: info.id,
|
||||||
|
type: "text",
|
||||||
|
text,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
yield* compact.prune({ sessionID: info.id })
|
yield* compact.prune({ sessionID: info.id })
|
||||||
|
|
||||||
const msgs = yield* ssn.messages({ sessionID: info.id })
|
const msgs = yield* ssn.messages({ sessionID: info.id })
|
||||||
const part = msgs.flatMap((msg) => msg.parts).find((part) => part.type === "tool")
|
const part = msgs.flatMap((msg) => msg.parts).find((part) => part.type === "tool")
|
||||||
expect(part?.type).toBe("tool")
|
expect(part?.type).toBe("tool")
|
||||||
expect(part?.state.status).toBe("completed")
|
expect(part?.state.status).toBe("completed")
|
||||||
if (part?.type === "tool" && part.state.status === "completed") {
|
if (part?.type === "tool" && part.state.status === "completed") {
|
||||||
expect(part.state.time.compacted).toBeNumber()
|
expect(part.state.time.compacted).toBeNumber()
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
{
|
||||||
|
config: {
|
||||||
|
compaction: { prune: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user