fix assistant prompt submission
This commit is contained in:
1 parent
c81a3b9432
commit
abc17e7c2a
7 files changed
+143
-48
No files matched your search
@@ -3,22 +3,44 @@ import { describe, expect, test, vi } from "vitest";
|
||||
import { sendAssistantPrompt } from "./assistant-send";
|
||||
|
||||
describe("sendAssistantPrompt", () => {
|
||||
test("uses the composer lifecycle so programmatic prompts start a run", () => {
|
||||
const calls: string[] = [];
|
||||
const composer = {
|
||||
setText: vi.fn((text: string) => calls.push(`set:${text}`)),
|
||||
send: vi.fn(() => calls.push("send")),
|
||||
test("appends a trimmed user prompt and explicitly starts a run", () => {
|
||||
const append = vi.fn();
|
||||
const runtime = {
|
||||
composer: () => ({ getState: () => ({ runConfig: { custom: { source: "spotlight" } } }) }),
|
||||
thread: () => ({ append }),
|
||||
};
|
||||
|
||||
expect(sendAssistantPrompt(composer, " Check my services ")).toBe(true);
|
||||
expect(calls).toEqual(["set:Check my services", "send"]);
|
||||
expect(sendAssistantPrompt(runtime, " Check my services ")).toBe(true);
|
||||
expect(append).toHaveBeenCalledWith({
|
||||
role: "user",
|
||||
content: [{ type: "text", text: "Check my services" }],
|
||||
runConfig: { custom: { source: "spotlight" } },
|
||||
startRun: true,
|
||||
});
|
||||
});
|
||||
|
||||
test("ignores empty prompts", () => {
|
||||
const composer = { setText: vi.fn(), send: vi.fn() };
|
||||
test("does not replace an existing composer draft", () => {
|
||||
const append = vi.fn();
|
||||
const getState = vi.fn(() => ({ text: "Keep this draft", runConfig: {} }));
|
||||
const runtime = {
|
||||
composer: () => ({ getState }),
|
||||
thread: () => ({ append }),
|
||||
};
|
||||
|
||||
expect(sendAssistantPrompt(composer, " ")).toBe(false);
|
||||
expect(composer.setText).not.toHaveBeenCalled();
|
||||
expect(composer.send).not.toHaveBeenCalled();
|
||||
sendAssistantPrompt(runtime, "Run a health check");
|
||||
|
||||
expect(getState().text).toBe("Keep this draft");
|
||||
expect(append).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
test("ignores empty prompts without touching the runtime", () => {
|
||||
const runtime = {
|
||||
composer: vi.fn(),
|
||||
thread: vi.fn(),
|
||||
};
|
||||
|
||||
expect(sendAssistantPrompt(runtime, " ")).toBe(false);
|
||||
expect(runtime.composer).not.toHaveBeenCalled();
|
||||
expect(runtime.thread).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user