Update streamResponse.test.ts
This commit is contained in:
parent
66bf2227aa
commit
4eeaa6d60d
1 changed files with 355 additions and 65 deletions
|
|
@ -3221,80 +3221,346 @@ describe("streamResponseThunk", () => {
|
|||
|
||||
// Execute thunk
|
||||
const result = await mockStoreWithManualApproval.dispatch(
|
||||
streamNormalInput({}) as any,
|
||||
streamResponseThunk({
|
||||
editorState: mockEditorState,
|
||||
modifiers: mockModifiers
|
||||
}) as any,
|
||||
);
|
||||
|
||||
// Verify thunk completed successfully (tool waits for approval)
|
||||
expect(result.type).toBe("chat/streamNormalInput/fulfilled");
|
||||
expect(result.type).toBe("chat/streamResponse/fulfilled");
|
||||
|
||||
// Verify action sequence includes tool generation but NO execution
|
||||
// Verify exact action sequence includes tool generation but NO execution
|
||||
const dispatchedActions = (mockStoreWithManualApproval as any).getActions();
|
||||
|
||||
// Should contain the standard streaming setup actions
|
||||
expect(dispatchedActions).toContainEqual(
|
||||
expect.objectContaining({
|
||||
expect(dispatchedActions).toEqual([
|
||||
{
|
||||
type: "chat/streamResponse/pending",
|
||||
meta: {
|
||||
arg: {
|
||||
editorState: mockEditorState,
|
||||
modifiers: mockModifiers,
|
||||
},
|
||||
requestId: expect.any(String),
|
||||
requestStatus: "pending",
|
||||
},
|
||||
payload: undefined,
|
||||
},
|
||||
{
|
||||
type: "chat/streamWrapper/pending",
|
||||
meta: {
|
||||
arg: expect.any(Function),
|
||||
requestId: expect.any(String),
|
||||
requestStatus: "pending",
|
||||
},
|
||||
payload: undefined,
|
||||
},
|
||||
{
|
||||
type: "session/submitEditorAndInitAtIndex",
|
||||
payload: {
|
||||
editorState: mockEditorState,
|
||||
index: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "session/resetNextCodeBlockToApplyIndex",
|
||||
payload: undefined,
|
||||
},
|
||||
{
|
||||
type: "symbols/updateFromContextItems/pending",
|
||||
meta: {
|
||||
arg: [],
|
||||
requestId: expect.any(String),
|
||||
requestStatus: "pending",
|
||||
},
|
||||
payload: undefined,
|
||||
},
|
||||
{
|
||||
type: "session/updateHistoryItemAtIndex",
|
||||
payload: {
|
||||
index: 1,
|
||||
updates: {
|
||||
contextItems: [],
|
||||
message: {
|
||||
content: "Hello, please help me with this code",
|
||||
id: "mock-uuid-123",
|
||||
role: "user",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "chat/streamNormalInput/pending",
|
||||
meta: {
|
||||
arg: {
|
||||
legacySlashCommandData: undefined,
|
||||
},
|
||||
requestId: expect.any(String),
|
||||
requestStatus: "pending",
|
||||
},
|
||||
payload: undefined,
|
||||
},
|
||||
{
|
||||
type: "session/setAppliedRulesAtIndex",
|
||||
payload: { index: 0, appliedRules: [] },
|
||||
}),
|
||||
);
|
||||
expect(dispatchedActions).toContainEqual(
|
||||
expect.objectContaining({ type: "session/setActive" }),
|
||||
);
|
||||
expect(dispatchedActions).toContainEqual(
|
||||
expect.objectContaining({
|
||||
payload: {
|
||||
appliedRules: [],
|
||||
index: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "session/setActive",
|
||||
payload: undefined,
|
||||
},
|
||||
{
|
||||
type: "session/setInlineErrorMessage",
|
||||
payload: undefined,
|
||||
},
|
||||
{
|
||||
type: "session/setIsPruned",
|
||||
payload: false,
|
||||
},
|
||||
{
|
||||
type: "session/setContextPercentage",
|
||||
payload: 0.9,
|
||||
}),
|
||||
);
|
||||
|
||||
// Should contain streaming updates including the tool call
|
||||
const streamUpdates = dispatchedActions.filter(
|
||||
(action: any) => action.type === "session/streamUpdate",
|
||||
);
|
||||
expect(streamUpdates.length).toBeGreaterThanOrEqual(2);
|
||||
|
||||
// Tool call should be marked as generated but NOT executed (waiting for approval)
|
||||
expect(dispatchedActions).toContainEqual(
|
||||
expect.objectContaining({
|
||||
},
|
||||
{
|
||||
type: "symbols/updateFromContextItems/fulfilled",
|
||||
meta: {
|
||||
arg: [],
|
||||
requestId: expect.any(String),
|
||||
requestStatus: "fulfilled",
|
||||
},
|
||||
payload: undefined,
|
||||
},
|
||||
{
|
||||
type: "session/streamUpdate",
|
||||
payload: [
|
||||
{
|
||||
role: "assistant",
|
||||
content: "I'll search the codebase for you.",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "session/streamUpdate",
|
||||
payload: [
|
||||
{
|
||||
role: "assistant",
|
||||
content: "",
|
||||
toolCalls: [
|
||||
{
|
||||
id: "tool-approval-1",
|
||||
type: "function",
|
||||
function: {
|
||||
name: "search_codebase",
|
||||
arguments: JSON.stringify({ query: "test function" }),
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "session/addPromptCompletionPair",
|
||||
payload: [
|
||||
{
|
||||
completion: "I'll search the codebase for you.",
|
||||
modelProvider: "anthropic",
|
||||
prompt: "Please search the codebase",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "session/setInactive",
|
||||
payload: undefined,
|
||||
},
|
||||
{
|
||||
type: "session/setToolGenerated",
|
||||
payload: expect.objectContaining({ toolCallId: "tool-approval-1" }),
|
||||
}),
|
||||
);
|
||||
|
||||
// Should NOT contain any tool execution actions
|
||||
expect(dispatchedActions).not.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: "session/setToolCallCalling",
|
||||
}),
|
||||
);
|
||||
expect(dispatchedActions).not.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: "session/updateToolCallOutput",
|
||||
}),
|
||||
);
|
||||
expect(dispatchedActions).not.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: "session/acceptToolCall",
|
||||
}),
|
||||
);
|
||||
|
||||
// Should complete successfully
|
||||
expect(dispatchedActions).toContainEqual(
|
||||
expect.objectContaining({
|
||||
payload: {
|
||||
toolCallId: "tool-approval-1",
|
||||
tools: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "chat/streamNormalInput/fulfilled",
|
||||
}),
|
||||
);
|
||||
meta: {
|
||||
arg: {
|
||||
legacySlashCommandData: undefined,
|
||||
},
|
||||
requestId: expect.any(String),
|
||||
requestStatus: "fulfilled",
|
||||
},
|
||||
payload: undefined,
|
||||
},
|
||||
{
|
||||
type: "session/saveCurrent/pending",
|
||||
meta: {
|
||||
arg: {
|
||||
generateTitle: true,
|
||||
openNewSession: false,
|
||||
},
|
||||
requestId: expect.any(String),
|
||||
requestStatus: "pending",
|
||||
},
|
||||
payload: undefined,
|
||||
},
|
||||
{
|
||||
type: "session/update/pending",
|
||||
meta: {
|
||||
arg: expect.objectContaining({
|
||||
history: expect.any(Array),
|
||||
sessionId: "session-123",
|
||||
title: "New Session",
|
||||
workspaceDirectory: "",
|
||||
}),
|
||||
requestId: expect.any(String),
|
||||
requestStatus: "pending",
|
||||
},
|
||||
payload: undefined,
|
||||
},
|
||||
{
|
||||
type: "session/updateSessionMetadata",
|
||||
payload: {
|
||||
sessionId: "session-123",
|
||||
title: "New Session",
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "session/refreshMetadata/pending",
|
||||
meta: {
|
||||
arg: {},
|
||||
requestId: expect.any(String),
|
||||
requestStatus: "pending",
|
||||
},
|
||||
payload: undefined,
|
||||
},
|
||||
{
|
||||
type: "session/setIsSessionMetadataLoading",
|
||||
payload: false,
|
||||
},
|
||||
{
|
||||
type: "session/setAllSessionMetadata",
|
||||
payload: {
|
||||
compiledChatMessages: [
|
||||
{
|
||||
content: "Please search the codebase",
|
||||
role: "user",
|
||||
},
|
||||
],
|
||||
contextPercentage: 0.9,
|
||||
didPrune: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "session/refreshMetadata/fulfilled",
|
||||
meta: {
|
||||
arg: {},
|
||||
requestId: expect.any(String),
|
||||
requestStatus: "fulfilled",
|
||||
},
|
||||
payload: {
|
||||
compiledChatMessages: [
|
||||
{
|
||||
content: "Please search the codebase",
|
||||
role: "user",
|
||||
},
|
||||
],
|
||||
contextPercentage: 0.9,
|
||||
didPrune: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "session/update/fulfilled",
|
||||
meta: {
|
||||
arg: expect.objectContaining({
|
||||
history: expect.any(Array),
|
||||
sessionId: "session-123",
|
||||
title: "New Session",
|
||||
workspaceDirectory: "",
|
||||
}),
|
||||
requestId: expect.any(String),
|
||||
requestStatus: "fulfilled",
|
||||
},
|
||||
payload: undefined,
|
||||
},
|
||||
{
|
||||
type: "session/saveCurrent/fulfilled",
|
||||
meta: {
|
||||
arg: {
|
||||
generateTitle: true,
|
||||
openNewSession: false,
|
||||
},
|
||||
requestId: expect.any(String),
|
||||
requestStatus: "fulfilled",
|
||||
},
|
||||
payload: undefined,
|
||||
},
|
||||
{
|
||||
type: "chat/streamWrapper/fulfilled",
|
||||
meta: {
|
||||
arg: expect.any(Function),
|
||||
requestId: expect.any(String),
|
||||
requestStatus: "fulfilled",
|
||||
},
|
||||
payload: undefined,
|
||||
},
|
||||
{
|
||||
type: "chat/streamResponse/fulfilled",
|
||||
meta: {
|
||||
arg: {
|
||||
editorState: mockEditorState,
|
||||
modifiers: mockModifiers,
|
||||
},
|
||||
requestId: expect.any(String),
|
||||
requestStatus: "fulfilled",
|
||||
},
|
||||
payload: undefined,
|
||||
},
|
||||
]);
|
||||
|
||||
// Verify IDE messenger calls - compilation should happen, streaming should happen
|
||||
expect(mockIdeMessengerManual.request).toHaveBeenCalledWith(
|
||||
"llm/compileChat",
|
||||
{
|
||||
messages: [{ role: "user", content: "Hello" }], // constructMessages mock
|
||||
options: {},
|
||||
},
|
||||
);
|
||||
expect(mockIdeMessengerManual.request).toHaveBeenCalledWith("llm/compileChat", {
|
||||
messages: [
|
||||
{
|
||||
role: "system",
|
||||
content: "You are a helpful assistant.",
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "Please search the codebase",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: "Hello, please help me with this code",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
options: {},
|
||||
});
|
||||
|
||||
expect(mockIdeMessengerManual.llmStreamChat).toHaveBeenCalled();
|
||||
expect(mockIdeMessengerManual.llmStreamChat).toHaveBeenCalledWith(
|
||||
{
|
||||
completionOptions: {},
|
||||
legacySlashCommandData: undefined,
|
||||
messageOptions: { precompiled: true },
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: "Please search the codebase",
|
||||
},
|
||||
],
|
||||
title: "Claude 3.5 Sonnet",
|
||||
},
|
||||
expect.any(AbortSignal),
|
||||
);
|
||||
|
||||
// Should NOT call tools/call since tool requires approval
|
||||
expect(mockIdeMessengerManual.request).not.toHaveBeenCalledWith(
|
||||
|
|
@ -3302,13 +3568,18 @@ describe("streamResponseThunk", () => {
|
|||
expect.anything(),
|
||||
);
|
||||
|
||||
// Verify session save was called
|
||||
expect(mockIdeMessengerManual.request).toHaveBeenCalledWith(
|
||||
"history/save",
|
||||
expect.anything(),
|
||||
);
|
||||
|
||||
// Verify final state contains the tool call in "generated" state (waiting for approval)
|
||||
const finalState = mockStoreWithManualApproval.getState();
|
||||
expect(finalState).toEqual({
|
||||
session: {
|
||||
history: [
|
||||
{
|
||||
appliedRules: [],
|
||||
contextItems: [],
|
||||
message: {
|
||||
id: "1",
|
||||
|
|
@ -3316,12 +3587,22 @@ describe("streamResponseThunk", () => {
|
|||
content: "Please search the codebase",
|
||||
},
|
||||
},
|
||||
{
|
||||
appliedRules: [],
|
||||
contextItems: [],
|
||||
editorState: mockEditorState,
|
||||
message: {
|
||||
content: "Hello, please help me with this code",
|
||||
id: expect.any(String),
|
||||
role: "user",
|
||||
},
|
||||
},
|
||||
{
|
||||
contextItems: [],
|
||||
isGatheringContext: false,
|
||||
message: {
|
||||
content: "I'll search the codebase for you.",
|
||||
id: expect.any(String),
|
||||
id: "mock-uuid-123",
|
||||
role: "assistant",
|
||||
toolCalls: [
|
||||
{
|
||||
|
|
@ -3366,10 +3647,19 @@ describe("streamResponseThunk", () => {
|
|||
contextPercentage: 0.9,
|
||||
isPruned: false,
|
||||
isInEdit: false,
|
||||
title: "",
|
||||
title: "New Session",
|
||||
lastSessionId: undefined,
|
||||
isSessionMetadataLoading: false,
|
||||
allSessionMetadata: [],
|
||||
allSessionMetadata: {
|
||||
compiledChatMessages: [
|
||||
{
|
||||
content: "Please search the codebase",
|
||||
role: "user",
|
||||
},
|
||||
],
|
||||
contextPercentage: 0.9,
|
||||
didPrune: false,
|
||||
},
|
||||
symbols: {},
|
||||
codeBlockApplyStates: {
|
||||
states: [],
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue