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 · 69 lines
TypeScript
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970import { mkdtempSync, rmSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";import { afterAll, describe, expect, it, vi } from "vitest";import { InteractiveMode } from "../src/modes/interactive/interactive-mode.js";
type InteractiveModePrototype = { handleResumeCommand(this: ResumeCommandContext, args: string): Promise<void>;};
type ResumeCommandContext = { requestAgentsView: () => Promise<void>; handleResumeSession: (sessionPath: string) => Promise<{ cancelled: boolean }>; showError: (message: string) => void; getCurrentCwd: () => string; connectionState: { sessionDir?: string } | undefined;};
const interactiveModePrototype = InteractiveMode.prototype as unknown as InteractiveModePrototype;
const emptySessionDir = mkdtempSync(join(tmpdir(), "resume-command-test-"));
afterAll(() => { rmSync(emptySessionDir, { recursive: true, force: true });});
function makeContext() { return { requestAgentsView: vi.fn<() => Promise<void>>(async () => undefined), handleResumeSession: vi.fn<(sessionPath: string) => Promise<{ cancelled: boolean }>>(async () => ({ cancelled: false, })), showError: vi.fn<(message: string) => void>(), getCurrentCwd: () => emptySessionDir, connectionState: { sessionDir: emptySessionDir }, } satisfies ResumeCommandContext;}
describe("InteractiveMode /resume command", () => { it("opens the agents view for bare /resume", async () => { const context = makeContext();
await interactiveModePrototype.handleResumeCommand.call(context, " ");
expect(context.requestAgentsView).toHaveBeenCalledTimes(1); expect(context.handleResumeSession).not.toHaveBeenCalled(); expect(context.showError).not.toHaveBeenCalled(); });
it("resumes a session path argument in place", async () => { const context = makeContext();
await interactiveModePrototype.handleResumeCommand.call(context, "/tmp/session.jsonl");
expect(context.handleResumeSession).toHaveBeenCalledWith("/tmp/session.jsonl"); expect(context.requestAgentsView).not.toHaveBeenCalled(); expect(context.showError).not.toHaveBeenCalled(); });
it("shows a non-fatal error for an unknown session selector", async () => { const context = makeContext();
await interactiveModePrototype.handleResumeCommand.call(context, "no-such-session");
expect(context.showError).toHaveBeenCalledWith(expect.stringContaining("No session found matching")); expect(context.handleResumeSession).not.toHaveBeenCalled(); expect(context.requestAgentsView).not.toHaveBeenCalled(); });});