Skip to content

Commit 1029c13

Browse files
authored
SearchQnA UT (opea-project#421)
Signed-off-by: Yue, Wenjiao <wenjiao.yue@intel.com>
1 parent 1cfcbfc commit 1029c13

10 files changed

Lines changed: 183 additions & 59 deletions

File tree

SearchQnA/docker/gaudi/compose.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,22 @@ services:
157157
- LLM_SERVICE_PORT=${LLM_SERVICE_PORT}
158158
ipc: host
159159
restart: always
160+
searchqna-gaudi-ui-server:
161+
image: opea/searchqna-ui:latest
162+
container_name: searchqna-gaudi-ui-server
163+
depends_on:
164+
- searchqna-gaudi-backend-server
165+
ports:
166+
- "5173:5173"
167+
environment:
168+
- no_proxy=${no_proxy}
169+
- https_proxy=${https_proxy}
170+
- http_proxy=${http_proxy}
171+
- BACKEND_BASE_URL=${BACKEND_SERVICE_ENDPOINT}
172+
ipc: host
173+
restart: always
174+
175+
160176

161177
networks:
162178
default:

SearchQnA/docker/ui/svelte/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
BACKEND_BASE_URL = 'http://x.x.x.x:yyyy/v1/searchqna'
1+
BACKEND_BASE_URL = 'http://backend_address:3008/v1/searchqna'

SearchQnA/docker/ui/svelte/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"devDependencies": {
1515
"@fortawesome/free-solid-svg-icons": "6.2.0",
16+
"@playwright/test": "^1.45.2",
1617
"@sveltejs/adapter-auto": "1.0.0-next.75",
1718
"@sveltejs/kit": "^1.30.4",
1819
"@tailwindcss/typography": "0.5.7",
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (C) 2024 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { defineConfig, devices } from "@playwright/test";
5+
6+
/**
7+
* Read environment variables from file.
8+
* https://github.com/motdotla/dotenv
9+
*/
10+
// require('dotenv').config();
11+
12+
/**
13+
* See https://playwright.dev/docs/test-configuration.
14+
*/
15+
export default defineConfig({
16+
testDir: "./tests",
17+
/* Maximum time one test can run for. */
18+
timeout: 30 * 1000,
19+
expect: {
20+
/**
21+
* Maximum time expect() should wait for the condition to be met.
22+
* For example in `await expect(locator).toHaveText();`
23+
*/
24+
timeout: 5000,
25+
},
26+
/* Run tests in files in parallel */
27+
fullyParallel: true,
28+
/* Fail the build on CI if you accidentally left test.only in the source code. */
29+
forbidOnly: !!process.env.CI,
30+
/* Retry on CI only */
31+
retries: process.env.CI ? 2 : 0,
32+
/* Opt out of parallel tests on CI. */
33+
workers: process.env.CI ? 1 : undefined,
34+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
35+
reporter: [["html", { open: "never" }]],
36+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
37+
use: {
38+
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
39+
actionTimeout: 0,
40+
/* Base URL to use in actions like `await page.goto('/')`. */
41+
baseURL: "http://localhost:5173",
42+
43+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
44+
trace: "on-first-retry",
45+
},
46+
47+
/* Configure projects for major browsers */
48+
projects: [
49+
{
50+
name: "webkit",
51+
use: { ...devices["Desktop Safari"] },
52+
},
53+
],
54+
});

SearchQnA/docker/ui/svelte/src/lib/modules/chat/ChatMessage.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
class={msg.role === 0
3232
? "flex w-full gap-3"
3333
: "flex w-full items-center gap-3"}
34+
data-testid={msg.role === 0
35+
? "display-answer"
36+
: "display-question"}
3437
>
3538
<div
3639
class={msg.role === 0

SearchQnA/docker/ui/svelte/src/routes/+page.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
class="text-md block w-full border-0 border-b-2 border-gray-300 px-1 py-4
189189
text-gray-900 focus:border-gray-300 focus:ring-0 dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-blue-500 dark:focus:ring-blue-500"
190190
type="text"
191+
data-testid="chat-input"
191192
placeholder="Enter prompt here"
192193
disabled={loading}
193194
maxlength="1200"
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (C) 2024 Intel Corporation
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { test, expect, type Page } from "@playwright/test";
5+
6+
// Initialization before each test
7+
test.beforeEach(async ({ page }) => {
8+
await page.goto("/");
9+
});
10+
11+
// Constants definition
12+
const CHAT_ITEMS = ["What is the total revenue of Nike in 2023?"];
13+
14+
// Helper function: Enter message to chat
15+
async function enterMessageToChat(page: Page, message: string) {
16+
await page.getByTestId("chat-input").click();
17+
await page.getByTestId("chat-input").fill(message);
18+
await page.getByTestId("chat-input").press("Enter");
19+
await page.waitForTimeout(10000);
20+
await expect(page.getByTestId("display-answer")).toBeVisible();
21+
}
22+
23+
// Test description: New Chat
24+
test.describe("New Chat", () => {
25+
// Test: Enter message to chat
26+
test("should enter message to chat", async ({ page }) => {
27+
await enterMessageToChat(page, CHAT_ITEMS[0]);
28+
});
29+
});

SearchQnA/docker/xeon/compose.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,21 @@ services:
141141
- LLM_SERVICE_PORT=${LLM_SERVICE_PORT}
142142
ipc: host
143143
restart: always
144+
searchqna-gaudi-ui-server:
145+
image: opea/searchqna-ui:latest
146+
container_name: searchqna-xeon-ui-server
147+
depends_on:
148+
- searchqna-xeon-backend-server
149+
ports:
150+
- "5173:5173"
151+
environment:
152+
- no_proxy=${no_proxy}
153+
- https_proxy=${https_proxy}
154+
- http_proxy=${http_proxy}
155+
- BACKEND_BASE_URL=${BACKEND_SERVICE_ENDPOINT}
156+
ipc: host
157+
restart: always
158+
144159

145160
networks:
146161
default:

SearchQnA/tests/test_searchqna_on_gaudi.sh

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# for test
66

7-
set -e
7+
set -xe
88

99
WORKPATH=$(dirname "$PWD")
1010
LOG_PATH="$WORKPATH/tests"
@@ -30,8 +30,8 @@ function build_docker_images() {
3030
cd $WORKPATH/docker
3131
docker build --no-cache -t opea/searchqna:latest -f Dockerfile .
3232

33-
# cd $WORKPATH/docker/ui
34-
# docker build --no-cache -t opea/searchqna-ui:latest -f docker/Dockerfile .
33+
cd $WORKPATH/docker/ui
34+
docker build --no-cache -t opea/searchqna-ui:latest -f docker/Dockerfile .
3535

3636
docker images
3737
}
@@ -66,8 +66,10 @@ function start_services() {
6666
export WEB_RETRIEVER_SERVICE_PORT=3003
6767
export RERANK_SERVICE_PORT=3005
6868
export LLM_SERVICE_PORT=3007
69+
export BACKEND_SERVICE_ENDPOINT="http://${ip_address}:3008/v1/searchqna"
6970

70-
# sed -i "s/backend_address/$ip_address/g" $WORKPATH/docker/ui/svelte/.env
71+
72+
sed -i "s/backend_address/$ip_address/g" $WORKPATH/docker/ui/svelte/.env
7173

7274
if [[ "$IMAGE_REPO" != "" ]]; then
7375
# Replace the container name with a test-specific name
@@ -111,30 +113,31 @@ function validate_megaservice() {
111113

112114
}
113115

114-
#function validate_frontend() {
115-
# cd $WORKPATH/docker/ui/svelte
116-
# local conda_env_name="OPEA_e2e"
117-
# export PATH=${HOME}/miniforge3/bin/:$PATH
118-
## conda remove -n ${conda_env_name} --all -y
119-
## conda create -n ${conda_env_name} python=3.12 -y
120-
# source activate ${conda_env_name}
121-
#
122-
# sed -i "s/localhost/$ip_address/g" playwright.config.ts
123-
#
124-
## conda install -c conda-forge nodejs -y
125-
# npm install && npm ci && npx playwright install --with-deps
126-
# node -v && npm -v && pip list
127-
#
128-
# exit_status=0
129-
# npx playwright test || exit_status=$?
130-
#
131-
# if [ $exit_status -ne 0 ]; then
132-
# echo "[TEST INFO]: ---------frontend test failed---------"
133-
# exit $exit_status
134-
# else
135-
# echo "[TEST INFO]: ---------frontend test passed---------"
136-
# fi
137-
#}
116+
function validate_frontend() {
117+
cd $WORKPATH/docker/ui/svelte
118+
local conda_env_name="OPEA_e2e"
119+
120+
export PATH=${HOME}/miniforge3/bin/:$PATH
121+
# conda remove -n ${conda_env_name} --all -y
122+
# conda create -n ${conda_env_name} python=3.12 -y
123+
source activate ${conda_env_name}
124+
125+
sed -i "s/localhost/$ip_address/g" playwright.config.ts
126+
127+
# conda install -c conda-forge nodejs -y
128+
npm install && npm ci && npx playwright install --with-deps
129+
node -v && npm -v && pip list
130+
131+
exit_status=0
132+
npx playwright test || exit_status=$?
133+
134+
if [ $exit_status -ne 0 ]; then
135+
echo "[TEST INFO]: ---------frontend test failed---------"
136+
exit $exit_status
137+
else
138+
echo "[TEST INFO]: ---------frontend test passed---------"
139+
fi
140+
}
138141

139142
function stop_docker() {
140143
cd $WORKPATH/docker/gaudi
@@ -148,7 +151,7 @@ function main() {
148151
start_services
149152

150153
validate_megaservice
151-
# validate_frontend
154+
validate_frontend
152155

153156
stop_docker
154157
echo y | docker system prune

SearchQnA/tests/test_searchqna_on_xeon.sh

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright (C) 2024 Intel Corporation
33
# SPDX-License-Identifier: Apache-2.0
44

5-
set -e
5+
set -xe
66

77
WORKPATH=$(dirname "$PWD")
88
LOG_PATH="$WORKPATH/tests"
@@ -22,8 +22,8 @@ function build_docker_images() {
2222
cd $WORKPATH/docker
2323
docker build -t opea/searchqna:latest -f Dockerfile .
2424

25-
# cd $WORKPATH/docker/ui
26-
# docker build --no-cache -t opea/searchqna-ui:latest -f docker/Dockerfile .
25+
cd $WORKPATH/docker/ui
26+
docker build --no-cache -t opea/searchqna-ui:latest -f docker/Dockerfile .
2727

2828
docker images
2929
}
@@ -52,8 +52,10 @@ function start_services() {
5252
export WEB_RETRIEVER_SERVICE_PORT=3003
5353
export RERANK_SERVICE_PORT=3005
5454
export LLM_SERVICE_PORT=3007
55+
export BACKEND_SERVICE_ENDPOINT="http://${ip_address}:3008/v1/searchqna"
5556

56-
# sed -i "s/backend_address/$ip_address/g" $WORKPATH/docker/ui/svelte/.env
57+
58+
sed -i "s/backend_address/$ip_address/g" $WORKPATH/docker/ui/svelte/.env
5759

5860
if [[ "$IMAGE_REPO" != "" ]]; then
5961
# Replace the container name with a test-specific name
@@ -94,30 +96,30 @@ function validate_megaservice() {
9496

9597
}
9698

97-
#function validate_frontend() {
98-
# cd $WORKPATH/docker/ui/svelte
99-
# local conda_env_name="OPEA_e2e"
100-
# export PATH=${HOME}/miniforge3/bin/:$PATH
101-
## conda remove -n ${conda_env_name} --all -y
102-
## conda create -n ${conda_env_name} python=3.12 -y
103-
# source activate ${conda_env_name}
104-
#
105-
# sed -i "s/localhost/$ip_address/g" playwright.config.ts
106-
#
107-
## conda install -c conda-forge nodejs -y
108-
# npm install && npm ci && npx playwright install --with-deps
109-
# node -v && npm -v && pip list
110-
#
111-
# exit_status=0
112-
# npx playwright test || exit_status=$?
113-
#
114-
# if [ $exit_status -ne 0 ]; then
115-
# echo "[TEST INFO]: ---------frontend test failed---------"
116-
# exit $exit_status
117-
# else
118-
# echo "[TEST INFO]: ---------frontend test passed---------"
119-
# fi
120-
#}
99+
function validate_frontend() {
100+
cd $WORKPATH/docker/ui/svelte
101+
local conda_env_name="OPEA_e2e"
102+
export PATH=${HOME}/miniforge3/bin/:$PATH
103+
# conda remove -n ${conda_env_name} --all -y
104+
# conda create -n ${conda_env_name} python=3.12 -y
105+
source activate ${conda_env_name}
106+
107+
sed -i "s/localhost/$ip_address/g" playwright.config.ts
108+
109+
# conda install -c conda-forge nodejs -y
110+
npm install && npm ci && npx playwright install --with-deps
111+
node -v && npm -v && pip list
112+
113+
exit_status=0
114+
npx playwright test || exit_status=$?
115+
116+
if [ $exit_status -ne 0 ]; then
117+
echo "[TEST INFO]: ---------frontend test failed---------"
118+
exit $exit_status
119+
else
120+
echo "[TEST INFO]: ---------frontend test passed---------"
121+
fi
122+
}
121123

122124
function stop_docker() {
123125
cd $WORKPATH/docker/xeon
@@ -131,7 +133,7 @@ function main() {
131133
start_services
132134

133135
validate_megaservice
134-
# validate_frontend
136+
validate_frontend
135137

136138
stop_docker
137139
echo y | docker system prune

0 commit comments

Comments
 (0)