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
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import type { Session } from "@opencode-ai/sdk/v2"
|
||||
|
||||
import { shouldSkipStaleSessionEvent } from "../session-event-freshness"
|
||||
|
||||
const buildSession = (title: string, time: Partial<NonNullable<Session["time"]>>): Session => ({
|
||||
id: "ses_1",
|
||||
title,
|
||||
time: time as Session["time"],
|
||||
} as Session)
|
||||
|
||||
describe("shouldSkipStaleSessionEvent", () => {
|
||||
test("skips a stale SSE session update after a newer local rename", () => {
|
||||
const current = buildSession("New Title", { created: 1, updated: 20 })
|
||||
const incoming = buildSession("Old Title", { created: 1, updated: 10 })
|
||||
|
||||
expect(shouldSkipStaleSessionEvent(current, incoming)).toBe(true)
|
||||
})
|
||||
|
||||
test("allows a fresher SSE update to apply", () => {
|
||||
const current = buildSession("Old Title", { created: 1, updated: 10 })
|
||||
const incoming = buildSession("New Title", { created: 1, updated: 20 })
|
||||
|
||||
expect(shouldSkipStaleSessionEvent(current, incoming)).toBe(false)
|
||||
})
|
||||
|
||||
test("falls back to created timestamp when updated is missing", () => {
|
||||
const current = buildSession("Current", { created: 20 })
|
||||
const incoming = buildSession("Incoming", { created: 10 })
|
||||
|
||||
expect(shouldSkipStaleSessionEvent(current, incoming)).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user