feat: improve passthrough composer and session recovery (#1411)

This commit is contained in:
Carlos Florêncio
2026-06-17 19:01:42 +01:00
committed by GitHub
parent 1d61727df3
commit d8436dfd8f
36 changed files with 2139 additions and 449 deletions
@@ -0,0 +1,66 @@
import { describe, expect, it, vi } from "vitest";
import { applySummarizeSessionResult } from "./session-context-summary";
describe("applySummarizeSessionResult", () => {
it("sanitizes unsafe characters before writing the prompt", () => {
const promptRef = { current: { value: "" } as HTMLTextAreaElement };
const setContextValue = vi.fn();
const setHasPrompt = vi.fn();
const toast = vi.fn();
applySummarizeSessionResult({
result: { summary: "line1\r\n<unsafe>\nline2" },
promptRef,
setContextValue,
setHasPrompt,
toast,
});
expect(promptRef.current.value).toBe("line1\n unsafe \nline2");
expect(setHasPrompt).toHaveBeenCalledWith(true);
expect(toast).not.toHaveBeenCalled();
});
it("treats an empty summary string as a successful summary", () => {
const promptRef = { current: { value: "existing" } as HTMLTextAreaElement };
const setContextValue = vi.fn();
const setHasPrompt = vi.fn();
const toast = vi.fn();
applySummarizeSessionResult({
result: { summary: "" },
promptRef,
setContextValue,
setHasPrompt,
toast,
});
expect(promptRef.current.value).toBe("");
expect(setHasPrompt).toHaveBeenCalledWith(true);
expect(toast).not.toHaveBeenCalled();
});
it("resets context and prompt state when summary is null", () => {
const promptRef = { current: { value: "stale prompt" } as HTMLTextAreaElement };
const setContextValue = vi.fn();
const setHasPrompt = vi.fn();
const toast = vi.fn();
applySummarizeSessionResult({
result: { summary: null, error: "connection refused" },
promptRef,
setContextValue,
setHasPrompt,
toast,
});
expect(setContextValue).toHaveBeenCalledWith("blank");
expect(promptRef.current.value).toBe("");
expect(setHasPrompt).toHaveBeenCalledWith(false);
expect(toast).toHaveBeenCalledWith({
title: "Summarize failed",
description: "connection refused",
variant: "error",
});
});
});