feat(tui): add main branch source to diff mode (#30942)

This commit is contained in:
Victor Navarro 2026-06-24 12:35:37 +02:00 committed by GitHub
commit 6eec98371a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 82 additions and 22 deletions

View file

@ -98,14 +98,15 @@ test("brackets navigate diff hunks", async () => {
}
})
async function renderDiffViewer(vcsDiff: unknown[], height = 20) {
async function renderDiffViewer(vcsDiff: unknown[], height = 20, initialRoute?: TuiRouteCurrent) {
const commands = new Map<
string,
NonNullable<Parameters<TuiPluginApi["keymap"]["registerLayer"]>[0]["commands"]>[number]
>()
let current = startRoute
let current = initialRoute ?? startRoute
let renderDiff: TuiRouteDefinition["render"] | undefined
let vcsDiffInput: unknown
let sessionDiffInput: unknown
const config = createTuiResolvedConfig()
function Harness() {
const renderer = useRenderer()
@ -124,7 +125,12 @@ async function renderDiffViewer(vcsDiff: unknown[], height = 20) {
return { data: vcsDiff }
},
},
session: { diff: async () => ({ data: [] }) },
session: {
diff: async (input: unknown) => {
sessionDiffInput = input
return { data: [] }
},
},
} as unknown as TuiPluginApi["client"],
state: {
session: {
@ -149,7 +155,7 @@ async function renderDiffViewer(vcsDiff: unknown[], height = 20) {
} satisfies TuiPluginApi
void diffViewerPlugin.tui(api, undefined, pluginMeta)
commands.get("diff.open")?.run?.({} as never)
if (!initialRoute) commands.get("diff.open")?.run?.({} as never)
return (
<TestTuiContexts>
@ -173,6 +179,7 @@ async function renderDiffViewer(vcsDiff: unknown[], height = 20) {
commands,
current: () => current,
vcsDiffInput: () => vcsDiffInput,
sessionDiffInput: () => sessionDiffInput,
}
}
@ -201,6 +208,40 @@ const session = {
},
} satisfies Session
test("branch diff source requests branch VCS diff", async () => {
const viewer = await renderDiffViewer([], 20, {
name: "diff",
params: { mode: "branch", sessionID: "session-1", returnRoute: startRoute },
})
try {
expect(viewer.current()).toEqual({
name: "diff",
params: { mode: "branch", sessionID: "session-1", returnRoute: startRoute },
})
expect(viewer.vcsDiffInput()).toEqual({ directory: "/repo/session", mode: "branch", context: 12 })
expect(viewer.sessionDiffInput()).toBeUndefined()
} finally {
viewer.app.renderer.destroy()
}
})
test("last-turn diff source requests session diff", async () => {
const viewer = await renderDiffViewer([], 20, {
name: "diff",
params: { mode: "last-turn", sessionID: "session-1", messageID: "message-1", returnRoute: startRoute },
})
try {
expect(viewer.current()).toEqual({
name: "diff",
params: { mode: "last-turn", sessionID: "session-1", messageID: "message-1", returnRoute: startRoute },
})
expect(viewer.sessionDiffInput()).toEqual({ sessionID: "session-1", messageID: "message-1" })
expect(viewer.vcsDiffInput()).toBeUndefined()
} finally {
viewer.app.renderer.destroy()
}
})
async function waitForCommand(
app: Awaited<ReturnType<typeof testRender>>,
commands: Map<string, unknown>,