fix(tui): scope diff viewer to session directory (#30426)

This commit is contained in:
James Long 2026-06-02 11:43:21 -04:00 committed by GitHub
parent f1af9c5ddf
commit c466d32bdb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 7 deletions

View File

@ -89,11 +89,15 @@ function DiffViewer(props: { api: TuiPluginApi }) {
}
| undefined
const mode = () => params()?.mode ?? "git"
const diffInput = createMemo(() => ({
mode: mode(),
sessionID: params()?.sessionID,
messageID: params()?.messageID,
}))
const diffInput = createMemo(() => {
const sessionID = params()?.sessionID
return {
mode: mode(),
sessionID,
messageID: params()?.messageID,
directory: sessionID ? props.api.state.session.get(sessionID)?.directory : undefined,
}
})
const [diff] = createResource(diffInput, async (input) => {
if (input.mode === "last-turn") {
const sessionID = input.sessionID
@ -106,7 +110,7 @@ function DiffViewer(props: { api: TuiPluginApi }) {
}
const result = await props.api.client.vcs.diff(
{ mode: "git", context: WORKING_TREE_DIFF_CONTEXT_LINES },
{ directory: input.directory, mode: "git", context: WORKING_TREE_DIFF_CONTEXT_LINES },
{ throwOnError: true },
)
return normalizeDiffs(result.data ?? [])

View File

@ -6,6 +6,7 @@ import { createDefaultOpenTuiKeymap } from "@opentui/keymap/opentui"
import { testRender, useRenderer } from "@opentui/solid"
import { Global } from "@opencode-ai/core/global"
import type { TuiPluginApi, TuiPluginMeta, TuiRouteCurrent, TuiRouteDefinition } from "@opencode-ai/plugin/tui"
import type { Session } from "@opencode-ai/sdk/v2"
import { KVProvider } from "../../../src/cli/cmd/tui/context/kv"
import { ThemeProvider } from "../../../src/cli/cmd/tui/context/theme"
import { TuiConfigProvider } from "../../../src/cli/cmd/tui/context/tui-config"
@ -22,6 +23,7 @@ test("closing the diff viewer returns to the route it opened from", async () =>
>()
let current = startRoute
let renderDiff: TuiRouteDefinition["render"] | undefined
let vcsDiffInput: unknown
await mkdir(Global.Path.state, { recursive: true })
await Bun.write(path.join(Global.Path.state, "kv.json"), "{}")
@ -36,9 +38,19 @@ test("closing the diff viewer returns to the route it opened from", async () =>
const base = createTuiPluginApi({
keymap,
client: {
vcs: { diff: async () => ({ data: [] }) },
vcs: {
diff: async (input: unknown) => {
vcsDiffInput = input
return { data: [] }
},
},
session: { diff: async () => ({ data: [] }) },
} as unknown as TuiPluginApi["client"],
state: {
session: {
get: () => session,
},
},
})
const api = {
...base,
@ -76,6 +88,7 @@ test("closing the diff viewer returns to the route it opened from", async () =>
try {
await waitForCommand(app, commands, "diff.close")
expect(current).toEqual({ name: "diff", params: { mode: "git", sessionID: "session-1", returnRoute: startRoute } })
expect(vcsDiffInput).toEqual({ directory: "/repo/session", mode: "git", context: 12 })
expect(commands.has("diff.close")).toBe(true)
commands.get("diff.close")!.run?.({} as never)
@ -85,6 +98,19 @@ test("closing the diff viewer returns to the route it opened from", async () =>
}
})
const session = {
id: "session-1",
slug: "session-1",
projectID: "project-1",
directory: "/repo/session",
title: "Session",
version: "1",
time: {
created: 0,
updated: 0,
},
} satisfies Session
async function waitForCommand(
app: Awaited<ReturnType<typeof testRender>>,
commands: Map<string, unknown>,