Skip to content

Commit

Permalink
fixed session tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robgruen committed Feb 3, 2025
1 parent 1f0aa03 commit 471f803
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
34 changes: 17 additions & 17 deletions ts/packages/shell/test/sessionCommands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
getAppPath,
getLastAgentMessage,
sendUserRequest,
sendUserRequestAndWaitForResponse,
sendUserRequestAndWaitForCompletion,
startShell,
waitForAgentMessage,
} from "./testHelper";
Expand All @@ -29,20 +29,20 @@ test.describe("@session Commands", () => {
const mainWindow: Page = await startShell();

// get the session count
let msg = await sendUserRequestAndWaitForResponse(
let msg = await sendUserRequestAndWaitForCompletion(
`@session list`,
mainWindow,
);

const sessions: string[] = msg.split("\n");

msg = await sendUserRequestAndWaitForResponse(
msg = await sendUserRequestAndWaitForCompletion(
`@session new`,
mainWindow,
);
expect(msg.toLowerCase()).toContain("new session created: ");

msg = await sendUserRequestAndWaitForResponse(
msg = await sendUserRequestAndWaitForCompletion(
`@session list`,
mainWindow,
);
Expand All @@ -52,7 +52,7 @@ test.describe("@session Commands", () => {
sessions.length + 1,
);

msg = await sendUserRequestAndWaitForResponse(`@history`, mainWindow);
msg = await sendUserRequestAndWaitForCompletion(`@history`, mainWindow);
expect(msg.length, "History NOT cleared!").toBe(0);

// close the application
Expand All @@ -66,14 +66,14 @@ test.describe("@session Commands", () => {
const mainWindow: Page = await startShell();

// create a new session so we have at least two
let msg = await sendUserRequestAndWaitForResponse(
let msg = await sendUserRequestAndWaitForCompletion(
`@session new`,
mainWindow,
);
expect(msg.toLowerCase()).toContain("new session created: ");

// get the session count
msg = await sendUserRequestAndWaitForResponse(
msg = await sendUserRequestAndWaitForCompletion(
`@session list`,
mainWindow,
);
Expand All @@ -82,7 +82,7 @@ test.describe("@session Commands", () => {
const sessionName: string = sessions[sessions.length - 1];

// issue delete session command
msg = await sendUserRequestAndWaitForResponse(
msg = await sendUserRequestAndWaitForCompletion(
`@session delete ${sessions[0]}`,
mainWindow,
);
Expand All @@ -92,7 +92,7 @@ test.describe("@session Commands", () => {
await mainWindow.locator(".choice-button", { hasText: "No" }).click();

// verify session not deleted
msg = await sendUserRequestAndWaitForResponse(
msg = await sendUserRequestAndWaitForCompletion(
`@session list`,
mainWindow,
);
Expand All @@ -102,7 +102,7 @@ test.describe("@session Commands", () => {
);

// reissue delete session command
msg = await sendUserRequestAndWaitForResponse(
msg = await sendUserRequestAndWaitForCompletion(
`@session delete ${sessions[0]}`,
mainWindow,
);
Expand All @@ -112,7 +112,7 @@ test.describe("@session Commands", () => {
await mainWindow.locator(".choice-button", { hasText: "Yes" }).click();

// get new session count
msg = await sendUserRequestAndWaitForResponse(
msg = await sendUserRequestAndWaitForCompletion(
`@session list`,
mainWindow,
);
Expand All @@ -122,7 +122,7 @@ test.describe("@session Commands", () => {
);

// get session info
msg = await sendUserRequestAndWaitForResponse(
msg = await sendUserRequestAndWaitForCompletion(
`@session info`,
mainWindow,
);
Expand All @@ -140,14 +140,14 @@ test.describe("@session Commands", () => {
const mainWindow: Page = await startShell();

// reset
let msg = await sendUserRequestAndWaitForResponse(
let msg = await sendUserRequestAndWaitForCompletion(
`@session reset`,
mainWindow,
);
expect(msg).toContain("Session settings revert to default.");

// issue clear session command
msg = await sendUserRequestAndWaitForResponse(
msg = await sendUserRequestAndWaitForCompletion(
`@session clear`,
mainWindow,
);
Expand All @@ -167,21 +167,21 @@ test.describe("@session Commands", () => {
const mainWindow: Page = await startShell();

// create a new session
let msg = await sendUserRequestAndWaitForResponse(
let msg = await sendUserRequestAndWaitForCompletion(
`@session new`,
mainWindow,
);
expect(msg.toLowerCase()).toContain("new session created: ");

// get the session list
msg = await sendUserRequestAndWaitForResponse(
msg = await sendUserRequestAndWaitForCompletion(
`@session list`,
mainWindow,
);
const sessions: string[] = msg.split("\n");

// open the earlier session
msg = await sendUserRequestAndWaitForResponse(
msg = await sendUserRequestAndWaitForCompletion(
`@session open ${sessions[0]}`,
mainWindow,
);
Expand Down
1 change: 0 additions & 1 deletion ts/packages/shell/test/simple.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ test("why is the sky blue?", { tag: "@smoke" }, async ({}, testInfo) => {
const msg = await sendUserRequestAndWaitForCompletion(
`why is the sky blue?`,
mainWindow,
1,
);

expect(
Expand Down
20 changes: 9 additions & 11 deletions ts/packages/shell/test/testHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,10 @@ export async function sendUserRequestAndWaitForResponse(
*
* @param prompt The user request/prompt.
* @param page The page hosting the user shell
* @param expectedNumberOfAgentMessages The number of expected agent messages to wait for/receive
*/
export async function sendUserRequestAndWaitForCompletion(
prompt: string,
page: Page,
expectedNumberOfAgentMessages: number = 1,
): Promise<string> {
// TODO: implement
const locators: Locator[] = await page
Expand All @@ -248,7 +246,7 @@ export async function getLastAgentMessageText(page: Page): Promise<string> {
.locator(".chat-message-agent .chat-message-content")
.all();

return locators[0].innerText();
return await locators[0].innerText();
}

/**
Expand Down Expand Up @@ -311,15 +309,15 @@ export async function waitForAgentMessage(
let originalAgentMessageCount = locators.length;
let messageCount = originalAgentMessageCount;

if (
expectedMessageCount == messageCount &&
(!waitForMessageCompletion ||
(await isMessageCompleted(await getLastAgentMessage(page))))
) {
return;
}

do {
if (
expectedMessageCount == messageCount &&
(!waitForMessageCompletion ||
(await isMessageCompleted(await getLastAgentMessage(page))))
) {
return;
}

await page.waitForTimeout(1000);
timeWaited += 1000;

Expand Down

0 comments on commit 471f803

Please sign in to comment.