fix(tui): restore reverted prompt in v2

This commit is contained in:
Aiden Cline 2026-07-05 18:53:38 +00:00 committed by 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴
commit cdb8fc9960
3 changed files with 114 additions and 4 deletions

View file

@ -0,0 +1,61 @@
import { describe, expect, test } from "bun:test"
import type { SessionMessageUser } from "@opencode-ai/sdk/v2"
import { revertedPrompt } from "../../src/util/revert-prompt"
const message: SessionMessageUser = {
id: "message-1",
type: "user",
text: "Fix the tests",
time: { created: 1 },
files: [
{
uri: "file:///repo/test.ts",
mime: "text/typescript",
name: "test.ts",
source: { start: 0, end: 8, text: "@test.ts" },
},
],
agents: [{ name: "review", source: { start: 9, end: 16, text: "@review" } }],
}
describe("reverted prompt", () => {
test("restores the reverted user message into an empty prompt", () => {
expect(revertedPrompt({ input: "", parts: [] }, message)).toEqual({
input: "Fix the tests",
parts: [
{
type: "file",
mime: "text/typescript",
filename: "test.ts",
url: "file:///repo/test.ts",
source: {
type: "file",
path: "test.ts",
text: { start: 0, end: 8, value: "@test.ts" },
},
},
{
type: "agent",
name: "review",
source: { start: 9, end: 16, value: "@review" },
},
],
})
})
test("preserves an existing text draft", () => {
expect(revertedPrompt({ input: "Keep this", parts: [] }, message)).toBeUndefined()
})
test("preserves an existing attachment draft", () => {
expect(
revertedPrompt(
{
input: "",
parts: [{ type: "agent", name: "build" }],
},
message,
),
).toBeUndefined()
})
})