Migrate compaction overflow tests (#26731)
This commit is contained in:
@@ -10,7 +10,6 @@ import { Agent } from "../../src/agent/agent"
|
|||||||
import { LLM } from "../../src/session/llm"
|
import { LLM } from "../../src/session/llm"
|
||||||
import { SessionCompaction } from "../../src/session/compaction"
|
import { SessionCompaction } from "../../src/session/compaction"
|
||||||
import { Token } from "@/util/token"
|
import { Token } from "@/util/token"
|
||||||
import { Instance } from "../../src/project/instance"
|
|
||||||
import { WithInstance } from "../../src/project/with-instance"
|
import { WithInstance } from "../../src/project/with-instance"
|
||||||
import * as Log from "@opencode-ai/core/util/log"
|
import * as Log from "@opencode-ai/core/util/log"
|
||||||
import { Permission } from "../../src/permission"
|
import { Permission } from "../../src/permission"
|
||||||
@@ -1293,91 +1292,70 @@ describe("session.compaction.process", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
test("replays the prior user turn on overflow when earlier context exists", async () => {
|
it.instance(
|
||||||
await using tmp = await tmpdir()
|
"replays the prior user turn on overflow when earlier context exists",
|
||||||
await WithInstance.provide({
|
Effect.gen(function* () {
|
||||||
directory: tmp.path,
|
const ssn = yield* SessionNs.Service
|
||||||
fn: async () => {
|
const session = yield* ssn.create({})
|
||||||
const session = await svc.create({})
|
yield* createUserMessage(session.id, "root")
|
||||||
await user(session.id, "root")
|
const replay = yield* createUserMessage(session.id, "image")
|
||||||
const replay = await user(session.id, "image")
|
yield* ssn.updatePart({
|
||||||
await svc.updatePart({
|
id: PartID.ascending(),
|
||||||
id: PartID.ascending(),
|
messageID: replay.id,
|
||||||
messageID: replay.id,
|
sessionID: session.id,
|
||||||
sessionID: session.id,
|
type: "file",
|
||||||
type: "file",
|
mime: "image/png",
|
||||||
mime: "image/png",
|
filename: "cat.png",
|
||||||
filename: "cat.png",
|
url: "https://example.com/cat.png",
|
||||||
url: "https://example.com/cat.png",
|
})
|
||||||
})
|
const msg = yield* createUserMessage(session.id, "current")
|
||||||
const msg = await user(session.id, "current")
|
const msgs = yield* ssn.messages({ sessionID: session.id })
|
||||||
const rt = runtime("continue", Plugin.defaultLayer, wide())
|
|
||||||
try {
|
|
||||||
const msgs = await svc.messages({ sessionID: session.id })
|
|
||||||
const result = await rt.runPromise(
|
|
||||||
SessionCompaction.Service.use((svc) =>
|
|
||||||
svc.process({
|
|
||||||
parentID: msg.id,
|
|
||||||
messages: msgs,
|
|
||||||
sessionID: session.id,
|
|
||||||
auto: true,
|
|
||||||
overflow: true,
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
const last = (await svc.messages({ sessionID: session.id })).at(-1)
|
const result = yield* SessionCompaction.use.process({
|
||||||
|
parentID: msg.id,
|
||||||
|
messages: msgs,
|
||||||
|
sessionID: session.id,
|
||||||
|
auto: true,
|
||||||
|
overflow: true,
|
||||||
|
})
|
||||||
|
|
||||||
expect(result).toBe("continue")
|
const last = (yield* ssn.messages({ sessionID: session.id })).at(-1)
|
||||||
expect(last?.info.role).toBe("user")
|
|
||||||
expect(last?.parts.some((part) => part.type === "file")).toBe(false)
|
|
||||||
expect(
|
|
||||||
last?.parts.some((part) => part.type === "text" && part.text.includes("Attached image/png: cat.png")),
|
|
||||||
).toBe(true)
|
|
||||||
} finally {
|
|
||||||
await rt.dispose()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test("falls back to overflow guidance when no replayable turn exists", async () => {
|
expect(result).toBe("continue")
|
||||||
await using tmp = await tmpdir()
|
expect(last?.info.role).toBe("user")
|
||||||
await WithInstance.provide({
|
expect(last?.parts.some((part) => part.type === "file")).toBe(false)
|
||||||
directory: tmp.path,
|
expect(
|
||||||
fn: async () => {
|
last?.parts.some((part) => part.type === "text" && part.text.includes("Attached image/png: cat.png")),
|
||||||
const session = await svc.create({})
|
).toBe(true)
|
||||||
await user(session.id, "earlier")
|
}),
|
||||||
const msg = await user(session.id, "current")
|
)
|
||||||
|
|
||||||
const rt = runtime("continue", Plugin.defaultLayer, wide())
|
it.instance(
|
||||||
try {
|
"falls back to overflow guidance when no replayable turn exists",
|
||||||
const msgs = await svc.messages({ sessionID: session.id })
|
Effect.gen(function* () {
|
||||||
const result = await rt.runPromise(
|
const ssn = yield* SessionNs.Service
|
||||||
SessionCompaction.Service.use((svc) =>
|
const session = yield* ssn.create({})
|
||||||
svc.process({
|
yield* createUserMessage(session.id, "earlier")
|
||||||
parentID: msg.id,
|
const msg = yield* createUserMessage(session.id, "current")
|
||||||
messages: msgs,
|
const msgs = yield* ssn.messages({ sessionID: session.id })
|
||||||
sessionID: session.id,
|
|
||||||
auto: true,
|
|
||||||
overflow: true,
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
const last = (await svc.messages({ sessionID: session.id })).at(-1)
|
const result = yield* SessionCompaction.use.process({
|
||||||
|
parentID: msg.id,
|
||||||
|
messages: msgs,
|
||||||
|
sessionID: session.id,
|
||||||
|
auto: true,
|
||||||
|
overflow: true,
|
||||||
|
})
|
||||||
|
|
||||||
expect(result).toBe("continue")
|
const last = (yield* ssn.messages({ sessionID: session.id })).at(-1)
|
||||||
expect(last?.info.role).toBe("user")
|
|
||||||
if (last?.parts[0]?.type === "text") {
|
expect(result).toBe("continue")
|
||||||
expect(last.parts[0].text).toContain("previous request exceeded the provider's size limit")
|
expect(last?.info.role).toBe("user")
|
||||||
}
|
if (last?.parts[0]?.type === "text") {
|
||||||
} finally {
|
expect(last.parts[0].text).toContain("previous request exceeded the provider's size limit")
|
||||||
await rt.dispose()
|
}
|
||||||
}
|
}),
|
||||||
},
|
)
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test("stops quickly when aborted during retry backoff", async () => {
|
test("stops quickly when aborted during retry backoff", async () => {
|
||||||
const stub = llm()
|
const stub = llm()
|
||||||
|
|||||||
Reference in New Issue
Block a user