Migrate compaction tool-call test (#26737)
This commit is contained in:
@@ -1448,88 +1448,74 @@ describe("session.compaction.process", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test("does not allow tool calls while generating the summary", async () => {
|
itProcess.instance(
|
||||||
const stub = llm()
|
"does not allow tool calls while generating the summary",
|
||||||
stub.push(
|
() => {
|
||||||
Stream.make(
|
const stub = llm()
|
||||||
{ type: "start" } satisfies LLM.Event,
|
stub.push(
|
||||||
{ type: "tool-input-start", id: "call-1", toolName: "_noop" } satisfies LLM.Event,
|
Stream.make(
|
||||||
{ type: "tool-call", toolCallId: "call-1", toolName: "_noop", input: {} } satisfies LLM.Event,
|
{ type: "start" } satisfies LLM.Event,
|
||||||
{
|
{ type: "tool-input-start", id: "call-1", toolName: "_noop" } satisfies LLM.Event,
|
||||||
type: "finish-step",
|
{ type: "tool-call", toolCallId: "call-1", toolName: "_noop", input: {} } satisfies LLM.Event,
|
||||||
finishReason: "tool-calls",
|
{
|
||||||
rawFinishReason: "tool_calls",
|
type: "finish-step",
|
||||||
response: { id: "res", modelId: "test-model", timestamp: new Date() },
|
finishReason: "tool-calls",
|
||||||
providerMetadata: undefined,
|
rawFinishReason: "tool_calls",
|
||||||
usage: {
|
response: { id: "res", modelId: "test-model", timestamp: new Date() },
|
||||||
inputTokens: 1,
|
providerMetadata: undefined,
|
||||||
outputTokens: 1,
|
usage: {
|
||||||
totalTokens: 2,
|
inputTokens: 1,
|
||||||
inputTokenDetails: {
|
outputTokens: 1,
|
||||||
noCacheTokens: undefined,
|
totalTokens: 2,
|
||||||
cacheReadTokens: undefined,
|
inputTokenDetails: {
|
||||||
cacheWriteTokens: undefined,
|
noCacheTokens: undefined,
|
||||||
|
cacheReadTokens: undefined,
|
||||||
|
cacheWriteTokens: undefined,
|
||||||
|
},
|
||||||
|
outputTokenDetails: {
|
||||||
|
textTokens: undefined,
|
||||||
|
reasoningTokens: undefined,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
outputTokenDetails: {
|
} satisfies LLM.Event,
|
||||||
textTokens: undefined,
|
{
|
||||||
reasoningTokens: undefined,
|
type: "finish",
|
||||||
|
finishReason: "tool-calls",
|
||||||
|
rawFinishReason: "tool_calls",
|
||||||
|
totalUsage: {
|
||||||
|
inputTokens: 1,
|
||||||
|
outputTokens: 1,
|
||||||
|
totalTokens: 2,
|
||||||
|
inputTokenDetails: {
|
||||||
|
noCacheTokens: undefined,
|
||||||
|
cacheReadTokens: undefined,
|
||||||
|
cacheWriteTokens: undefined,
|
||||||
|
},
|
||||||
|
outputTokenDetails: {
|
||||||
|
textTokens: undefined,
|
||||||
|
reasoningTokens: undefined,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
} satisfies LLM.Event,
|
||||||
} satisfies LLM.Event,
|
),
|
||||||
{
|
)
|
||||||
type: "finish",
|
return Effect.gen(function* () {
|
||||||
finishReason: "tool-calls",
|
const ssn = yield* SessionNs.Service
|
||||||
rawFinishReason: "tool_calls",
|
const session = yield* ssn.create({})
|
||||||
totalUsage: {
|
const msg = yield* createUserMessage(session.id, "hello")
|
||||||
inputTokens: 1,
|
const msgs = yield* ssn.messages({ sessionID: session.id })
|
||||||
outputTokens: 1,
|
yield* SessionCompaction.use.process({ parentID: msg.id, messages: msgs, sessionID: session.id, auto: false })
|
||||||
totalTokens: 2,
|
|
||||||
inputTokenDetails: {
|
|
||||||
noCacheTokens: undefined,
|
|
||||||
cacheReadTokens: undefined,
|
|
||||||
cacheWriteTokens: undefined,
|
|
||||||
},
|
|
||||||
outputTokenDetails: {
|
|
||||||
textTokens: undefined,
|
|
||||||
reasoningTokens: undefined,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
} satisfies LLM.Event,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
await using tmp = await tmpdir({ git: true })
|
const summary = (yield* ssn.messages({ sessionID: session.id })).find(
|
||||||
await WithInstance.provide({
|
(item) => item.info.role === "assistant" && item.info.summary,
|
||||||
directory: tmp.path,
|
)
|
||||||
fn: async () => {
|
|
||||||
const session = await svc.create({})
|
|
||||||
const msg = await user(session.id, "hello")
|
|
||||||
const rt = liveRuntime(stub.layer, wide())
|
|
||||||
try {
|
|
||||||
const msgs = await svc.messages({ sessionID: session.id })
|
|
||||||
await rt.runPromise(
|
|
||||||
SessionCompaction.Service.use((svc) =>
|
|
||||||
svc.process({
|
|
||||||
parentID: msg.id,
|
|
||||||
messages: msgs,
|
|
||||||
sessionID: session.id,
|
|
||||||
auto: false,
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
const summary = (await svc.messages({ sessionID: session.id })).find(
|
expect(summary?.info.role).toBe("assistant")
|
||||||
(item) => item.info.role === "assistant" && item.info.summary,
|
expect(summary?.parts.some((part) => part.type === "tool")).toBe(false)
|
||||||
)
|
}).pipe(Effect.provide(compactionProcessLayer({ llm: stub.layer })))
|
||||||
|
},
|
||||||
expect(summary?.info.role).toBe("assistant")
|
{ git: true },
|
||||||
expect(summary?.parts.some((part) => part.type === "tool")).toBe(false)
|
)
|
||||||
} finally {
|
|
||||||
await rt.dispose()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test("summarizes only the head while keeping recent tail out of summary input", async () => {
|
test("summarizes only the head while keeping recent tail out of summary input", async () => {
|
||||||
const stub = llm()
|
const stub = llm()
|
||||||
|
|||||||
Reference in New Issue
Block a user