fix(tui): scope diff viewer to session directory (#30426)
This commit is contained in:
@@ -89,11 +89,15 @@ function DiffViewer(props: { api: TuiPluginApi }) {
|
|||||||
}
|
}
|
||||||
| undefined
|
| undefined
|
||||||
const mode = () => params()?.mode ?? "git"
|
const mode = () => params()?.mode ?? "git"
|
||||||
const diffInput = createMemo(() => ({
|
const diffInput = createMemo(() => {
|
||||||
mode: mode(),
|
const sessionID = params()?.sessionID
|
||||||
sessionID: params()?.sessionID,
|
return {
|
||||||
messageID: params()?.messageID,
|
mode: mode(),
|
||||||
}))
|
sessionID,
|
||||||
|
messageID: params()?.messageID,
|
||||||
|
directory: sessionID ? props.api.state.session.get(sessionID)?.directory : undefined,
|
||||||
|
}
|
||||||
|
})
|
||||||
const [diff] = createResource(diffInput, async (input) => {
|
const [diff] = createResource(diffInput, async (input) => {
|
||||||
if (input.mode === "last-turn") {
|
if (input.mode === "last-turn") {
|
||||||
const sessionID = input.sessionID
|
const sessionID = input.sessionID
|
||||||
@@ -106,7 +110,7 @@ function DiffViewer(props: { api: TuiPluginApi }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const result = await props.api.client.vcs.diff(
|
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 },
|
{ throwOnError: true },
|
||||||
)
|
)
|
||||||
return normalizeDiffs(result.data ?? [])
|
return normalizeDiffs(result.data ?? [])
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { createDefaultOpenTuiKeymap } from "@opentui/keymap/opentui"
|
|||||||
import { testRender, useRenderer } from "@opentui/solid"
|
import { testRender, useRenderer } from "@opentui/solid"
|
||||||
import { Global } from "@opencode-ai/core/global"
|
import { Global } from "@opencode-ai/core/global"
|
||||||
import type { TuiPluginApi, TuiPluginMeta, TuiRouteCurrent, TuiRouteDefinition } from "@opencode-ai/plugin/tui"
|
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 { KVProvider } from "../../../src/cli/cmd/tui/context/kv"
|
||||||
import { ThemeProvider } from "../../../src/cli/cmd/tui/context/theme"
|
import { ThemeProvider } from "../../../src/cli/cmd/tui/context/theme"
|
||||||
import { TuiConfigProvider } from "../../../src/cli/cmd/tui/context/tui-config"
|
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 current = startRoute
|
||||||
let renderDiff: TuiRouteDefinition["render"] | undefined
|
let renderDiff: TuiRouteDefinition["render"] | undefined
|
||||||
|
let vcsDiffInput: unknown
|
||||||
await mkdir(Global.Path.state, { recursive: true })
|
await mkdir(Global.Path.state, { recursive: true })
|
||||||
await Bun.write(path.join(Global.Path.state, "kv.json"), "{}")
|
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({
|
const base = createTuiPluginApi({
|
||||||
keymap,
|
keymap,
|
||||||
client: {
|
client: {
|
||||||
vcs: { diff: async () => ({ data: [] }) },
|
vcs: {
|
||||||
|
diff: async (input: unknown) => {
|
||||||
|
vcsDiffInput = input
|
||||||
|
return { data: [] }
|
||||||
|
},
|
||||||
|
},
|
||||||
session: { diff: async () => ({ data: [] }) },
|
session: { diff: async () => ({ data: [] }) },
|
||||||
} as unknown as TuiPluginApi["client"],
|
} as unknown as TuiPluginApi["client"],
|
||||||
|
state: {
|
||||||
|
session: {
|
||||||
|
get: () => session,
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
const api = {
|
const api = {
|
||||||
...base,
|
...base,
|
||||||
@@ -76,6 +88,7 @@ test("closing the diff viewer returns to the route it opened from", async () =>
|
|||||||
try {
|
try {
|
||||||
await waitForCommand(app, commands, "diff.close")
|
await waitForCommand(app, commands, "diff.close")
|
||||||
expect(current).toEqual({ name: "diff", params: { mode: "git", sessionID: "session-1", returnRoute: startRoute } })
|
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)
|
expect(commands.has("diff.close")).toBe(true)
|
||||||
commands.get("diff.close")!.run?.({} as never)
|
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(
|
async function waitForCommand(
|
||||||
app: Awaited<ReturnType<typeof testRender>>,
|
app: Awaited<ReturnType<typeof testRender>>,
|
||||||
commands: Map<string, unknown>,
|
commands: Map<string, unknown>,
|
||||||
|
|||||||
Reference in New Issue
Block a user