Something went wrong. Try again.
fork of prime agent with changes i want but are not upstreamable probqbly (and some fixes)
Something went wrong. Try again.
2.6 kB · 74 lines
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475import { describe, expect, it, vi } from "vitest";import { InteractiveMode } from "../src/modes/interactive/interactive-mode.js";
type CloneCommandContext = { agentConnection: { getSessionTree: () => Promise<{ tree: unknown[]; leafId: string | null }>; fork: (entryId: string, options?: { position?: "before" | "at" }) => Promise<{ cancelled: boolean }>; }; renderCurrentSessionState: () => void; editor: { setText: (text: string) => void }; showStatus: (message: string) => void; showError: (message: string) => void; ui: { requestRender: () => void };};
type InteractiveModePrototype = { handleCloneCommand(this: CloneCommandContext): Promise<void>;};
const interactiveModePrototype = InteractiveMode.prototype as unknown as InteractiveModePrototype;
describe("InteractiveMode /clone", () => { it("clones the current leaf into a new session", async () => { const getSessionTree = vi.fn(async () => ({ tree: [], leafId: "leaf-123" })); const fork = vi.fn(async () => ({ cancelled: false })); const renderCurrentSessionState = vi.fn(); const setText = vi.fn(); const showStatus = vi.fn(); const showError = vi.fn(); const requestRender = vi.fn();
const context: CloneCommandContext = { agentConnection: { getSessionTree, fork }, renderCurrentSessionState, editor: { setText }, showStatus, showError, ui: { requestRender }, };
await interactiveModePrototype.handleCloneCommand.call(context);
expect(getSessionTree).toHaveBeenCalledWith(); expect(fork).toHaveBeenCalledWith("leaf-123", { position: "at" }); expect(renderCurrentSessionState).toHaveBeenCalled(); expect(setText).toHaveBeenCalledWith(""); expect(showStatus).toHaveBeenCalledWith("Cloned to new session"); expect(showError).not.toHaveBeenCalled(); expect(requestRender).not.toHaveBeenCalled(); });
it("shows a status message when there is nothing to clone", async () => { const getSessionTree = vi.fn(async () => ({ tree: [], leafId: null })); const fork = vi.fn(async () => ({ cancelled: false })); const showStatus = vi.fn(); const showError = vi.fn();
const context: CloneCommandContext = { agentConnection: { getSessionTree, fork }, renderCurrentSessionState: vi.fn(), editor: { setText: vi.fn() }, showStatus, showError, ui: { requestRender: vi.fn() }, };
await interactiveModePrototype.handleCloneCommand.call(context);
expect(getSessionTree).toHaveBeenCalledWith(); expect(fork).not.toHaveBeenCalled(); expect(showStatus).toHaveBeenCalledWith("Nothing to clone yet"); expect(showError).not.toHaveBeenCalled(); });});