Migrate compaction process tests (#26723)

This commit is contained in:
Kit Langton 2026-05-10 12:25:44 -04:00 committed by GitHub
commit fa15dbc5ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -285,7 +285,7 @@ function runtime(
} }
const deps = Layer.mergeAll( const deps = Layer.mergeAll(
ProviderTest.fake().layer, wide().layer,
layer("continue"), layer("continue"),
Agent.defaultLayer, Agent.defaultLayer,
Plugin.defaultLayer, Plugin.defaultLayer,
@ -882,55 +882,42 @@ describe("session.compaction.process", () => {
}), }),
) )
test("publishes compacted event on continue", async () => { it.instance(
await using tmp = await tmpdir() "publishes compacted event on continue",
await WithInstance.provide({ Effect.gen(function* () {
directory: tmp.path, const bus = yield* Bus.Service
fn: async () => { const ssn = yield* SessionNs.Service
const session = await svc.create({}) const session = yield* ssn.create({})
const msg = await user(session.id, "hello") const msg = yield* createUserMessage(session.id, "hello")
const msgs = await svc.messages({ sessionID: session.id }) const msgs = yield* ssn.messages({ sessionID: session.id })
const done = defer() const done = defer()
let seen = false let seen = false
const rt = runtime("continue", Plugin.defaultLayer, wide()) const unsub = yield* bus.subscribeCallback(SessionCompaction.Event.Compacted, (evt) => {
let unsub: (() => void) | undefined if (evt.properties.sessionID !== session.id) return
try { seen = true
unsub = await rt.runPromise( done.resolve()
Bus.Service.use((svc) => })
svc.subscribeCallback(SessionCompaction.Event.Compacted, (evt) => { yield* Effect.addFinalizer(() => Effect.sync(unsub))
if (evt.properties.sessionID !== session.id) return
seen = true
done.resolve()
}),
),
)
const result = await rt.runPromise( const result = yield* SessionCompaction.use.process({
SessionCompaction.Service.use((svc) => parentID: msg.id,
svc.process({ messages: msgs,
parentID: msg.id, sessionID: session.id,
messages: msgs, auto: false,
sessionID: session.id, })
auto: false,
}),
),
)
await Promise.race([ yield* Effect.promise(() =>
done.promise, Promise.race([
wait(500).then(() => { done.promise,
throw new Error("timed out waiting for compacted event") wait(500).then(() => {
}), throw new Error("timed out waiting for compacted event")
]) }),
expect(result).toBe("continue") ]),
expect(seen).toBe(true) )
} finally { expect(result).toBe("continue")
unsub?.() expect(seen).toBe(true)
await rt.dispose() }),
} )
},
})
})
test("marks summary message as errored on compact result", async () => { test("marks summary message as errored on compact result", async () => {
await using tmp = await tmpdir() await using tmp = await tmpdir()
@ -970,46 +957,36 @@ describe("session.compaction.process", () => {
}) })
}) })
test("adds synthetic continue prompt when auto is enabled", async () => { it.instance(
await using tmp = await tmpdir() "adds synthetic continue prompt when auto is enabled",
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({}) const msg = yield* createUserMessage(session.id, "hello")
const msg = await user(session.id, "hello") 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,
}),
),
)
const all = await svc.messages({ sessionID: session.id }) const result = yield* SessionCompaction.use.process({
const last = all.at(-1) parentID: msg.id,
messages: msgs,
sessionID: session.id,
auto: true,
})
expect(result).toBe("continue") const all = yield* ssn.messages({ sessionID: session.id })
expect(last?.info.role).toBe("user") const last = all.at(-1)
expect(last?.parts[0]).toMatchObject({
type: "text", expect(result).toBe("continue")
synthetic: true, expect(last?.info.role).toBe("user")
metadata: { compaction_continue: true }, expect(last?.parts[0]).toMatchObject({
}) type: "text",
if (last?.parts[0]?.type === "text") { synthetic: true,
expect(last.parts[0].text).toContain("Continue if you have next steps") metadata: { compaction_continue: true },
} })
} finally { if (last?.parts[0]?.type === "text") {
await rt.dispose() expect(last.parts[0].text).toContain("Continue if you have next steps")
} }
}, }),
}) )
})
test("persists tail_start_id for retained recent turns", async () => { test("persists tail_start_id for retained recent turns", async () => {
await using tmp = await tmpdir() await using tmp = await tmpdir()