fix(sync): keep session renames stable (#2043)
* fix(sync): keep session renames stable * fix(sync): clarify rename mirror flow * fix(sync): clarify archive comment --------- Co-authored-by: bashrusakh <bashrusakh@users.noreply.github.com> Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
bashrusakh
Bohdan Triapitsyn
parent
9bfc5bf0be
commit
d5745aaac9
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import type { Session } from "@opencode-ai/sdk/v2"
|
||||
import type { Event, Part, PermissionRequest, QuestionRequest, SessionStatus } from "@opencode-ai/sdk/v2/client"
|
||||
import { applyDirectoryEvent } from "../event-reducer"
|
||||
import { INITIAL_STATE, type State } from "../types"
|
||||
@@ -55,6 +56,14 @@ function topLevelSessionOnlyPartUpdatedEvent(): Event {
|
||||
} as Event
|
||||
}
|
||||
|
||||
function buildSession(title: string, time: Session["time"]): Session {
|
||||
return {
|
||||
id: "ses_1",
|
||||
title,
|
||||
time,
|
||||
} as Session
|
||||
}
|
||||
|
||||
describe("applyDirectoryEvent", () => {
|
||||
test("returns typed materialization when delta arrives before parts", () => {
|
||||
const result = applyDirectoryEvent(state(), deltaEvent())
|
||||
@@ -129,6 +138,20 @@ describe("applyDirectoryEvent", () => {
|
||||
})
|
||||
})
|
||||
|
||||
test("skips stale session.updated events so a newer title survives", () => {
|
||||
const draft = state({ session: [buildSession("New Title", { created: 1, updated: 20 })] })
|
||||
|
||||
const result = applyDirectoryEvent(draft, {
|
||||
type: "session.updated",
|
||||
properties: {
|
||||
info: buildSession("Old Title", { created: 1, updated: 10 }),
|
||||
},
|
||||
} as Event)
|
||||
|
||||
expect(result).toBe(false)
|
||||
expect(draft.session[0]?.title).toBe("New Title")
|
||||
})
|
||||
|
||||
test("applies part update without materialization when owning message exists", () => {
|
||||
const draft = state({
|
||||
message: { ses_1: [{ id: "msg_1", sessionID: "ses_1", role: "assistant", time: { created: 1 } } as never] },
|
||||
|
||||
Reference in New Issue
Block a user