mirror of
https://github.com/anomalyco/opencode.git
synced 2026-09-07 05:15:01 +00:00
fix(core): commit undo before compaction (#46383)
Co-authored-by: vimtor <36263538+vimtor@users.noreply.github.com>
This commit is contained in:
parent
e56ceed32b
commit
33536da231
2 changed files with 39 additions and 1 deletions
|
|
@ -278,7 +278,8 @@ export const make = Effect.fn("Session.make")(function* (servicesFor: (ref: Loca
|
|||
sessionID: SessionSchema.ID,
|
||||
input: { id?: SessionMessage.ID; delivery?: SessionInbox.Delivery },
|
||||
) {
|
||||
yield* get(sessionID)
|
||||
const session = yield* get(sessionID)
|
||||
if (session.revert) yield* SessionRevert.commit(bus, session)
|
||||
const inputID = input.id ?? SessionMessage.ID.create()
|
||||
const admitted = yield* admission
|
||||
.admitCompaction({
|
||||
|
|
|
|||
|
|
@ -130,4 +130,41 @@ describe("Session.compact", () => {
|
|||
expect(yield* session.inbox(created.id)).toHaveLength(1)
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("commits a staged revert before admitting manual compaction", () =>
|
||||
Effect.gen(function* () {
|
||||
const session = yield* Session.Service
|
||||
const bus = yield* Bus.Service
|
||||
const created = yield* session.create({ location })
|
||||
const messageID = SessionMessage.ID.create()
|
||||
|
||||
yield* bus.publish(SessionEvent.InboxEnqueued, {
|
||||
sessionID: created.id,
|
||||
inboxID: messageID,
|
||||
item: {
|
||||
type: "user",
|
||||
payload: { text: "Undo this prompt before compacting." },
|
||||
delivery: "steer",
|
||||
},
|
||||
})
|
||||
yield* bus.publish(SessionEvent.InboxDelivered, {
|
||||
sessionID: created.id,
|
||||
inboxID: messageID,
|
||||
})
|
||||
yield* bus.publish(SessionEvent.RevertEvent.Staged, {
|
||||
sessionID: created.id,
|
||||
revert: { messageID, files: [] },
|
||||
})
|
||||
|
||||
expect((yield* session.get(created.id)).revert?.messageID).toBe(messageID)
|
||||
|
||||
const compacted = yield* session.compact({ sessionID: created.id })
|
||||
|
||||
expect((yield* session.get(created.id)).revert).toBeUndefined()
|
||||
expect(yield* session.context(created.id)).toEqual([])
|
||||
expect(yield* session.inbox(created.id)).toEqual([
|
||||
expect.objectContaining({ id: compacted.id, type: "compaction" }),
|
||||
])
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue