Merge remote-tracking branch 'origin/dev' into todo-dock-motion

# Conflicts:
#	packages/app/package.json
#	packages/app/src/pages/session.tsx
#	packages/app/src/pages/session/composer/session-composer-region.tsx
This commit is contained in:
Brendan Allan 2026-06-25 13:25:38 +08:00
commit 1084cd96ac
108 changed files with 6879 additions and 920 deletions

View file

@ -15,7 +15,6 @@ test("snaps spring progress when the session changes", async () => {
expect(state.progress()).toBe(0)
state.setSession("session-b")
await Bun.sleep(0)
expect(state.progress()).toBe(1)
state.dispose()
})

View file

@ -0,0 +1,90 @@
import { describe, expect, test } from "bun:test"
import { createRoot } from "solid-js"
import { createPromptAttachmentsCore } from "@/components/prompt-input/attachments"
import { createPromptState } from "@/context/prompt"
describe("prompt attachment session ownership", () => {
test("adds an asynchronously read image to the session where the read started", async () => {
await createRoot(async (dispose) => {
const sessions = { A: createPromptState(), B: createPromptState() }
let active: "A" | "B" = "A"
const attachments = createPromptAttachmentsCore({
capture: () => sessions[active].capture(),
editor: () => document.createElement("div"),
})
const pending = attachments.addAttachment(new File([new Uint8Array(1024 * 1024)], "a.png", { type: "image/png" }))
active = "B"
await pending
expect(images(sessions.A)).toHaveLength(1)
expect(images(sessions.B)).toHaveLength(0)
dispose()
})
})
test("finishes the captured attachment after the active editor is removed", async () => {
await createRoot(async (dispose) => {
const prompt = createPromptState()
let editor: HTMLDivElement | undefined = document.createElement("div")
const attachments = createPromptAttachmentsCore({
capture: prompt.capture,
editor: () => editor,
})
const pending = attachments.addAttachment(new File([new Uint8Array(1024 * 1024)], "a.png", { type: "image/png" }))
editor = undefined
await pending
expect(images(prompt)).toHaveLength(1)
dispose()
})
})
test("keeps every file in a batch on the session where the batch started", async () => {
await createRoot(async (dispose) => {
const sessions = { A: createPromptState(), B: createPromptState() }
let active: "A" | "B" = "A"
const attachments = createPromptAttachmentsCore({
capture: () => sessions[active].capture(),
editor: () => document.createElement("div"),
})
const pending = attachments.addAttachments([
new File([new Uint8Array(1024 * 1024)], "first.png", { type: "image/png" }),
new File([new Uint8Array(1024 * 1024)], "second.png", { type: "image/png" }),
])
active = "B"
await pending
expect(images(sessions.A)).toHaveLength(2)
expect(images(sessions.B)).toHaveLength(0)
dispose()
})
})
test("keeps a delayed native clipboard image on the session where paste started", async () => {
await createRoot(async (dispose) => {
const sessions = { A: createPromptState(), B: createPromptState() }
const read = Promise.withResolvers<File | null>()
let active: "A" | "B" = "A"
const attachments = createPromptAttachmentsCore({
capture: () => sessions[active].capture(),
editor: () => document.createElement("div"),
})
const pending = attachments.addClipboardAttachment(read.promise)
active = "B"
read.resolve(new File([new Uint8Array(1024 * 1024)], "clipboard.png", { type: "image/png" }))
await pending
expect(images(sessions.A)).toHaveLength(1)
expect(images(sessions.B)).toHaveLength(0)
dispose()
})
})
})
function images(prompt: ReturnType<typeof createPromptState>) {
return prompt.current().filter((part) => part.type === "image")
}

View file

@ -0,0 +1,14 @@
import { expect, test } from "bun:test"
import { ServerConnection } from "@/context/server"
import { selectPromptTab } from "@/context/prompt"
import type { Tab } from "@/context/tabs"
test("selects the explicitly scoped session tab instead of the active tab", () => {
const server = ServerConnection.Key.make("local")
const tabs: Tab[] = [
{ type: "session", server, sessionId: "A" },
{ type: "session", server, sessionId: "B" },
]
expect(selectPromptTab(tabs, { dir: "repo", id: "B" }, server)).toBe(tabs[1])
})

View file

@ -0,0 +1,56 @@
import { describe, expect, test } from "bun:test"
import { createPromptState } from "@/context/prompt"
import { createPromptSubmissionState } from "@/components/prompt-input/submission-state"
describe("prompt submission state", () => {
test("keeps failed submission restoration with the prompt where it started", () => {
const target = createPromptState()
const submission = createPromptSubmissionState({
target,
prompt: [{ type: "text", content: "prompt-A", start: 0, end: 8 }],
context: [{ key: "file:src/index.ts:undefined:undefined", type: "file", path: "src/index.ts" }],
})
expect(submission.restore()).toEqual({
target,
prompt: [{ type: "text", content: "prompt-A", start: 0, end: 8 }],
context: [{ key: "file:src/index.ts:undefined:undefined", type: "file", path: "src/index.ts" }],
})
})
test("moves first-submit restoration and context to the promoted session", () => {
const draft = createPromptState()
const session = createPromptState()
const submission = createPromptSubmissionState({
target: draft,
prompt: [{ type: "text", content: "first prompt", start: 0, end: 12 }],
context: [{ key: "file:src/index.ts:undefined:undefined", type: "file", path: "src/index.ts" }],
})
submission.retarget(session)
expect(submission.restore()).toEqual({
target: session,
prompt: [{ type: "text", content: "first prompt", start: 0, end: 12 }],
context: [{ key: "file:src/index.ts:undefined:undefined", type: "file", path: "src/index.ts" }],
})
expect(session.context.items()).toHaveLength(1)
expect(session.context.items()[0]).toMatchObject({ type: "file", path: "src/index.ts" })
})
test("does not restore over a prompt edited after submission", () => {
const target = createPromptState()
target.set([{ type: "text", content: "submitted", start: 0, end: 9 }])
const submission = createPromptSubmissionState({
target,
prompt: target.current(),
context: [],
})
submission.clear()
target.set([{ type: "text", content: "new draft", start: 0, end: 9 }])
expect(submission.restore()).toBeUndefined()
expect(target.current()[0]).toMatchObject({ type: "text", content: "new draft" })
})
})

View file

@ -0,0 +1,36 @@
import { expect, test } from "bun:test"
import { createRoot, createSignal } from "solid-js"
import { createPromptInputTransientState } from "@/components/prompt-input/transient-state"
test("resets transient prompt input state when the prompt session changes", () => {
createRoot((dispose) => {
const [identity, setIdentity] = createSignal("A")
const [state, setState] = createPromptInputTransientState(identity, 3)
setState({
popover: "slash",
historyIndex: 2,
savedPrompt: {
prompt: [{ type: "text", content: "draft-A", start: 0, end: 7 }],
comments: [],
},
draggingType: "image",
mode: "shell",
applyingHistory: true,
variantOpen: true,
})
setIdentity("B")
expect(state).toMatchObject({
popover: null,
historyIndex: -1,
savedPrompt: null,
placeholder: 3,
draggingType: null,
mode: "normal",
applyingHistory: false,
variantOpen: false,
})
dispose()
})
})

View file

@ -0,0 +1,45 @@
import { describe, expect, test } from "bun:test"
import { createRoot, createSignal } from "solid-js"
import { createSessionOwnership } from "@/pages/session/session-ownership"
describe("createSessionOwnership", () => {
test("invalidates captured work when its Solid owner is disposed", () => {
let current = true
createRoot((dispose) => {
const owner = createSessionOwnership(() => "A").capture()
dispose()
current = owner.current()
})
expect(current).toBe(false)
})
test("does not run a continuation after navigation", () => {
createRoot((dispose) => {
const [session, setSession] = createSignal("A")
const owner = createSessionOwnership(session).capture()
let ran = false
setSession("B")
owner.run(() => {
ran = true
})
expect(ran).toBe(false)
dispose()
})
})
test("does not revive a continuation after A to B to A navigation", () => {
createRoot((dispose) => {
const [session, setSession] = createSignal("A")
const owner = createSessionOwnership(session).capture()
setSession("B")
setSession("A")
expect(owner.current()).toBe(false)
dispose()
})
})
})