fix(app): stabilize virtual session timeline interactions (#28422)

This commit is contained in:
Luke Parker 2026-05-25 12:05:27 +10:00 committed by GitHub
commit f023c63a60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 1062 additions and 177 deletions

View file

@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test"
import { normalize, text } from "./session-diff"
import { normalize, resolveFileDiff, text } from "./session-diff"
describe("session diff", () => {
test("keeps unified patch content", () => {
@ -13,8 +13,8 @@ describe("session diff", () => {
}
const view = normalize(diff)
expect(view.patch).toBe(diff.patch)
expect(view.fileDiff.name).toBe("a.ts")
expect(view.fileDiff.isPartial).toBe(true)
expect(text(view, "deletions")).toBe("one\ntwo\n")
expect(text(view, "additions")).toBe("one\nthree\n")
})
@ -34,7 +34,52 @@ describe("session diff", () => {
expect(text(view, "additions")).toBe("one\nthree")
})
test("converts legacy content into a patch", () => {
test("keeps separated patch hunks partial without complete file contents", () => {
const fileDiff = resolveFileDiff({
file: "project.ts",
patch:
'Index: project.ts\n===================================================================\n--- project.ts\t\n+++ project.ts\t\n@@ -1,3 +1,2 @@\n import { and } from "drizzle-orm"\n-import { sql } from "drizzle-orm"\n import { ProjectTable } from "./project.sql"\n@@ -346,3 +345,3 @@\n import { Database } from "@/storage/db"\n-import { ProjectTable } from "./project.sql"\n+import { ProjectTable } from "../project/project.sql"\n import { SessionTable } from "../session/session.sql"\n',
})
expect(fileDiff.isPartial).toBe(true)
expect(fileDiff.hunks).toHaveLength(2)
expect(fileDiff.hunks[1]?.collapsedBefore).toBeGreaterThan(0)
})
test("renders headerless persisted patches", () => {
const view = normalize({
file: "a.ts",
patch: "@@ -1 +1 @@\n-old\n+new\n",
additions: 1,
deletions: 1,
status: "modified" as const,
})
expect(view.fileDiff.name).toBe("a.ts")
expect(view.fileDiff.isPartial).toBe(true)
expect(text(view, "deletions")).toBe("old\n")
expect(text(view, "additions")).toBe("new\n")
})
test("does not share headerless patch metadata between files", () => {
const patch = "@@ -1 +1 @@\n-old\n+new\n"
expect(resolveFileDiff({ file: "a.ts", patch }).name).toBe("a.ts")
expect(resolveFileDiff({ file: "b.ts", patch }).name).toBe("b.ts")
})
test("keeps capped header-only patches partial", () => {
const fileDiff = resolveFileDiff({
file: "a.ts",
patch: "Index: a.ts\n===================================================================\n--- a.ts\t\n+++ a.ts\t\n",
})
expect(fileDiff.name).toBe("a.ts")
expect(fileDiff.isPartial).toBe(true)
expect(fileDiff.hunks).toEqual([])
})
test("keeps full legacy content as a complete diff", () => {
const diff = {
file: "a.ts",
before: "one\n",
@ -45,7 +90,7 @@ describe("session diff", () => {
}
const view = normalize(diff)
expect(view.patch).toContain("@@ -1,1 +1,1 @@")
expect(view.fileDiff.isPartial).toBe(false)
expect(text(view, "deletions")).toBe("one\n")
expect(text(view, "additions")).toBe("two\n")
})
@ -61,7 +106,6 @@ describe("session diff", () => {
}
const view = normalize(diff)
expect(view.patch).toBe(diff.patch)
expect(text(view, "deletions")).toBe("")
expect(text(view, "additions")).toBe("")
})