fix: test failures - was doing a chat test in agent mode

This commit is contained in:
Dallin Romney 2025-07-20 12:19:42 +02:00
parent 049f34b79d
commit 9511eb5fa9
5 changed files with 52 additions and 51 deletions

View file

@ -70,7 +70,7 @@ function toolToSystemToolDefinition(tool: Tool): string {
}
let argDescription = "";
if ("description" in value) {
argDescription = value.argDescription;
argDescription = value.description;
}
toolDefinition += `TOOL_ARG: ${key} (${argType}, ${requiredText})\n`;
@ -85,9 +85,9 @@ function toolToSystemToolDefinition(tool: Tool): string {
return toolDefinition.trim();
}
export const generateToolsSystemMessage = (tools: Tool[]) => {
export const generateToolsSystemMessage = (tools: Tool[]): string => {
if (tools.length === 0) {
return undefined;
return "";
}
const withPredefinedMessage = tools.filter(
(tool) => !!tool.systemMessageDescription,
@ -97,26 +97,31 @@ export const generateToolsSystemMessage = (tools: Tool[]) => {
(tool) => !tool.systemMessageDescription,
);
let prompt = `${TOOL_INSTRUCTIONS_TAG}\n`;
prompt += `You have access to several "tools" that you can use at any time to retrieve information and/or perform tasks for the User.`;
prompt += `\nTo use a tool, respond with a tool code block (\`\`\`tool) using the syntax shown in the examples below:`;
const instructions: string[] = [];
instructions.push(TOOL_INSTRUCTIONS_TAG);
instructions.push(
`You have access to several "tools" that you can use at any time to retrieve information and/or perform tasks for the User.`,
);
instructions.push(
`To use a tool, respond with a tool code block (\`\`\`tool) using the syntax shown in the examples below:`,
);
if (withPredefinedMessage.length > 0) {
prompt += `\n\nThe following tools are available to you:`;
instructions.push(`\nThe following tools are available to you:`);
for (const tool of withPredefinedMessage) {
prompt += "\n\n";
prompt += tool.systemMessageDescription;
instructions.push(`\n${tool.systemMessageDescription}`);
}
}
if (withDynamicMessage.length > 0) {
prompt += `\n\nAlso, these additional tool definitions show other tools you can call with the same syntax:`;
instructions.push(
`\nAlso, these additional tool definitions show other tools you can call with the same syntax:`,
);
for (const tool of tools) {
try {
const definition = toolToSystemToolDefinition(tool);
prompt += "\n\n";
prompt += definition;
instructions.push(`\n${definition}`);
} catch (e) {
console.error(
"Failed to convert tool to system message tool:\n" +
@ -125,22 +130,27 @@ export const generateToolsSystemMessage = (tools: Tool[]) => {
}
}
prompt += `\n\nFor example, this tool definition:\n\n`;
prompt += EXAMPLE_DYNAMIC_TOOL;
prompt += "\n\nCan be called like this:\n";
prompt += EXAMPLE_DYNAMIC_TOOL_CALL;
instructions.push(`\nFor example, this tool definition:\n`);
instructions.push(EXAMPLE_DYNAMIC_TOOL);
instructions.push("\nCan be called like this:\n");
instructions.push(EXAMPLE_DYNAMIC_TOOL_CALL);
}
prompt += `\n\nIf it seems like the User's request could be solved with one of the tools, choose the BEST one for the job based on the user's request and the tool descriptions`;
prompt += `\nThen send the \`\`\`tool codeblock (YOU call the tool, not the user). Always start the codeblock on a new line.`;
prompt += `\nDo not perform actions with/for hypothetical files. Ask the user or use tools to deduce which files are relevant.`;
prompt += `\nYou can only call ONE tool at at time. The tool codeblock should be the last thing you say; stop your response after the tool codeblock.`;
instructions.push(
`\nIf it seems like the User's request could be solved with one of the tools, choose the BEST one for the job based on the user's request and the tool descriptions`,
);
instructions.push(
`Then send the \`\`\`tool codeblock (YOU call the tool, not the user). Always start the codeblock on a new line.`,
);
instructions.push(
`Do not perform actions with/for hypothetical files. Ask the user or use tools to deduce which files are relevant.`,
);
instructions.push(
`You can only call ONE tool at at time. The tool codeblock should be the last thing you say; stop your response after the tool codeblock.`,
);
prompt += `\n${closeTag(TOOL_INSTRUCTIONS_TAG)}`;
return prompt;
instructions.push(`${closeTag(TOOL_INSTRUCTIONS_TAG)}`);
return instructions.join("\n");
};
export function addSystemMessageToolsToSystemMessage(

View file

@ -75,7 +75,7 @@ describe("Edit Test", () => {
return codeLens;
}
it.only("Accepts an Edit in the GUI", async () => {
it("Accepts an Edit in the GUI", async () => {
({ view } = await GUIActions.switchToReactIframe());
await EditActions.acceptEditInGUI(view);

View file

@ -3,11 +3,10 @@ import {
By,
EditorView,
Key,
VSBrowser,
WebDriver,
WebElement,
WebView,
until,
until
} from "vscode-extension-tester";
import { GlobalActions } from "../actions/Global.actions";
@ -16,14 +15,14 @@ import { DEFAULT_TIMEOUT } from "../constants";
import { GUISelectors } from "../selectors/GUI.selectors";
import { TestUtils } from "../TestUtils";
describe("GUI Test", () => {
describe.only("GUI Test", () => {
let view: WebView;
let driver: WebDriver;
before(async function () {
this.timeout(DEFAULT_TIMEOUT.XL);
// Uncomment this line for faster testing
await GUIActions.moveContinueToSidebar(VSBrowser.instance.driver);
// await GUIActions.moveContinueToSidebar(VSBrowser.instance.driver);
await GlobalActions.openTestWorkspace();
await GlobalActions.clearAllNotifications();
});
@ -299,8 +298,6 @@ describe("GUI Test", () => {
expect(await statusMessage.getText()).contain(
"Continue viewed the git diff",
);
// wait for 30 seconds, promise
await new Promise((resolve) => setTimeout(resolve, 30000));
}).timeout(DEFAULT_TIMEOUT.MD * 100);
it("should call tool after approval", async () => {
@ -367,8 +364,9 @@ describe("GUI Test", () => {
}).timeout(DEFAULT_TIMEOUT.MD);
});
describe("Repeat back the system message", () => {
describe("should repeat back the system message", () => {
it("should repeat back the system message", async () => {
await GUIActions.selectModeFromDropdown(view, "Chat");
await GUIActions.selectModelFromDropdown(view, "SYSTEM MESSAGE MOCK LLM");
const [messageInput] = await GUISelectors.getMessageInputFields(view);
await messageInput.sendKeys("Hello");
@ -376,8 +374,8 @@ describe("GUI Test", () => {
await TestUtils.waitForSuccess(() =>
GUISelectors.getThreadMessageByText(view, "TEST_SYS_MSG"),
);
});
});
}).timeout(DEFAULT_TIMEOUT.XL * 1000);
})
describe("Chat Paths", () => {
it("Send many messages → chat auto scrolls → go to history → open previous chat → it is scrolled to the bottom", async () => {

View file

@ -8,13 +8,13 @@ import {
ToolResultChatMessage,
UserChatMessage,
} from "core";
import { renderChatMessage } from "core/util/messageContent";
import { beforeEach, describe, expect, test, vi } from "vitest";
import {
CANCELLED_TOOL_CALL_MESSAGE,
constructMessages,
NO_TOOL_CALL_OUTPUT_MESSAGE,
} from "./constructMessages";
} from "core/tools/constants";
import { renderChatMessage } from "core/util/messageContent";
import { beforeEach, describe, expect, test, vi } from "vitest";
import { constructMessages } from "./constructMessages";
// For these tests we will mock the rules to simulate different scenarios
const CONTEXT_RULE: RuleWithSource = {

View file

@ -1,27 +1,26 @@
import {
AssistantChatMessage,
ChatHistoryItem,
ChatMessage,
ContextItemWithId,
RuleWithSource,
TextMessagePart,
ToolCallState,
ToolResultChatMessage,
UserChatMessage,
} from "core";
import { chatMessageIsEmpty } from "core/llm/messages";
import { getSystemMessageWithRules } from "core/llm/rules/getSystemMessageWithRules";
import { RulePolicies } from "core/llm/rules/types";
import {
CANCELLED_TOOL_CALL_MESSAGE,
NO_TOOL_CALL_OUTPUT_MESSAGE,
} from "core/tools/constants";
import { convertToolCallStatesToSystemCallsAndOutput } from "core/tools/systemMessageTools/textifySystemTools";
import { findLast, findLastIndex } from "core/util/findLast";
import {
normalizeToMessageParts,
renderContextItems,
} from "core/util/messageContent";
import { toolCallStateToContextItems } from "../../pages/gui/ToolCallDiv/utils";
export const NO_TOOL_CALL_OUTPUT_MESSAGE = "No tool output";
export const CANCELLED_TOOL_CALL_MESSAGE = "The user cancelled this tool call.";
interface MessageWithContextItems {
ctxItems: ContextItemWithId[];
message: ChatMessage;
@ -214,9 +213,3 @@ export function constructMessages(
appliedRuleIndex,
};
}
function convertToolCallStatesToSystemCallsAndOutput(
message: AssistantChatMessage,
arg1: ToolCallState[],
): { userMessage: any; assistantMessage: any } {
throw new Error("Function not implemented.");
}