fix(opencode): use chronological message boundaries (#40991)
Co-authored-by: Dax <mail@thdxr.com>
This commit is contained in:
committed by
GitHub
parent
d468201952
commit
a54a693af2
@@ -35,6 +35,18 @@ const user = Effect.fn("test.user")(function* (sessionID: SessionID, agent = "de
|
||||
})
|
||||
})
|
||||
|
||||
const userAt = Effect.fn("test.userAt")(function* (sessionID: SessionID, id: string, created: number) {
|
||||
const session = yield* Session.Service
|
||||
return yield* session.updateMessage({
|
||||
id: MessageID.make(id),
|
||||
role: "user" as const,
|
||||
sessionID,
|
||||
agent: "default",
|
||||
model: { providerID: ProviderV2.ID.make("openai"), modelID: ModelV2.ID.make("gpt-4") },
|
||||
time: { created },
|
||||
})
|
||||
})
|
||||
|
||||
const assistant = Effect.fn("test.assistant")(function* (sessionID: SessionID, parentID: MessageID, dir: string) {
|
||||
const session = yield* Session.Service
|
||||
return yield* session.updateMessage({
|
||||
@@ -426,6 +438,39 @@ describe("revert + compact workflow", () => {
|
||||
),
|
||||
)
|
||||
|
||||
it.live(
|
||||
"reverts chronological suffixes on both sides of mixed message ID ordering",
|
||||
provideTmpdirInstance(
|
||||
() =>
|
||||
Effect.gen(function* () {
|
||||
const session = yield* Session.Service
|
||||
const revert = yield* SessionRevert.Service
|
||||
const ids = ["msg_z9-before", "msg_z1-before-wrap", "msg_a0-after-wrap", "msg_a1-after"]
|
||||
|
||||
const run = Effect.fn("test.mixedIDRevert")(function* (target: number) {
|
||||
const info = yield* session.create({})
|
||||
for (const [index, id] of ids.entries()) {
|
||||
const message = yield* userAt(info.id, id, index + 1)
|
||||
yield* text(info.id, message.id, id)
|
||||
}
|
||||
|
||||
const reverted = yield* revert.revert({
|
||||
sessionID: info.id,
|
||||
messageID: MessageID.make(ids[target]!),
|
||||
})
|
||||
yield* revert.cleanup(reverted)
|
||||
const remaining = yield* session.messages({ sessionID: info.id })
|
||||
yield* session.remove(info.id)
|
||||
return remaining.map((msg) => msg.info.time.created)
|
||||
})
|
||||
|
||||
expect(yield* run(1)).toEqual([1])
|
||||
expect(yield* run(2)).toEqual([1, 2])
|
||||
}),
|
||||
{ git: true },
|
||||
),
|
||||
)
|
||||
|
||||
it.live(
|
||||
"cleanup is a no-op when session has no revert state",
|
||||
provideTmpdirInstance(
|
||||
|
||||
@@ -238,6 +238,38 @@ describe("Session", () => {
|
||||
}),
|
||||
)
|
||||
|
||||
it.instance("forks the chronological prefix across mixed message ID ordering", () =>
|
||||
Effect.gen(function* () {
|
||||
const session = yield* SessionNs.Service
|
||||
const created = yield* Effect.acquireRelease(session.create({}), (info) =>
|
||||
session.remove(info.id).pipe(Effect.ignore),
|
||||
)
|
||||
const ids = ["msg_z9-before", "msg_z1-before-wrap", "msg_a0-after-wrap", "msg_a1-after"]
|
||||
for (const [index, id] of ids.entries()) {
|
||||
yield* session.updateMessage({
|
||||
id: MessageID.make(id),
|
||||
sessionID: created.id,
|
||||
role: "user",
|
||||
time: { created: index + 1 },
|
||||
agent: "user",
|
||||
model: { providerID: "test", modelID: "test" },
|
||||
} as SessionV1.User)
|
||||
}
|
||||
|
||||
const beforeWrap = yield* Effect.acquireRelease(
|
||||
session.fork({ sessionID: created.id, messageID: MessageID.make(ids[1]!) }),
|
||||
(info) => session.remove(info.id).pipe(Effect.ignore),
|
||||
)
|
||||
const afterWrap = yield* Effect.acquireRelease(
|
||||
session.fork({ sessionID: created.id, messageID: MessageID.make(ids[2]!) }),
|
||||
(info) => session.remove(info.id).pipe(Effect.ignore),
|
||||
)
|
||||
|
||||
expect((yield* session.messages({ sessionID: beforeWrap.id })).map((msg) => msg.info.time.created)).toEqual([1])
|
||||
expect((yield* session.messages({ sessionID: afterWrap.id })).map((msg) => msg.info.time.created)).toEqual([1, 2])
|
||||
}),
|
||||
)
|
||||
|
||||
it.instance("omits metadata when not provided", () =>
|
||||
Effect.gen(function* () {
|
||||
const session = yield* SessionNs.Service
|
||||
|
||||
Reference in New Issue
Block a user