Skip to content

Commit

Permalink
workflow(ci): optimize ai unit test (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw authored Aug 19, 2024
1 parent 4ac1ad1 commit b07f83d
Show file tree
Hide file tree
Showing 90 changed files with 2,688 additions and 2,221 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/ai.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
main:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.19.0]

env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_BASE_URL: ${{ secrets.OPENAI_BASE_URL }}
MIDSCENE_MODEL_NAME: ${{ secrets.MIDSCENE_MODEL_NAME }}

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 9.3.0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build project
run: pnpm run build:pkg

- name: Run tests
run: pnpm run test
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: AI test

on:
push:
Expand All @@ -16,8 +16,9 @@ jobs:
node-version: [18.19.0]

env:
MIDSCENE_OPENAI_INIT_CONFIG_JSON: ${{ secrets.MIDSCENE_OPENAI_INIT_CONFIG_JSON }}
MIDSCENE_OPENAI_MODEL: ${{ secrets.MIDSCENE_OPENAI_MODEL }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_BASE_URL: ${{ secrets.OPENAI_BASE_URL }}
MIDSCENE_MODEL_NAME: ${{ secrets.MIDSCENE_MODEL_NAME }}

steps:
- uses: actions/checkout@v4
Expand Down
14 changes: 13 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,15 @@ pnpm run build:pkg

---

## Testing
### Testing

To change the AI-related code of this repository, you need to create a '.env 'file in the root directory, which reads as follows:

```
OPENAI_API_KEY="you_token"
MIDSCENE_MODEL_NAME="gpt-4o-2024-08-06"
```


### Add New Tests

Expand All @@ -120,12 +128,16 @@ Before submitting a pull request, it's important to make sure that the changes h

```sh
pnpm run test
# Test with AI-related features, it will need to create a .env file
pnpm run test:all
```

You can also run the unit tests of single package:

```sh
npx nx test @midscene/web
# Test with AI-related features, it will need to create a .env file
npx nx test:all @midscene/web
```

### Run E2E Tests
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"build:pkg": "nx run-many --target=build --projects=@midscene/core,@midscene/visualizer,@midscene/web --verbose",
"test": "nx run-many --target=test --projects=@midscene/core,@midscene/visualizer,@midscene/web --verbose",
"test:ai": "nx run-many --target=test:ai --projects=@midscene/core,@midscene/visualizer,@midscene/web --verbose",
"e2e": "nx run-many --target=e2e --projects=@midscene/core,@midscene/visualizer,@midscene/web --verbose",
"prepare": "pnpm run build:pkg && simple-git-hooks",
"check-dependency-version": "check-dependency-version-consistency .",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"@midscene/web": "workspace:*",
"ora-classic": "5.4.2",
"puppeteer": "^22.8.0",
"puppeteer": "23.0.2",
"yargs": "17.7.2"
},
"devDependencies": {
Expand Down
13 changes: 7 additions & 6 deletions packages/midscene/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,23 @@
"new": "modern new",
"upgrade": "modern upgrade",
"test": "vitest --run",
"test:all": "AITEST=true vitest --run",
"test:ai": "AITEST=true npm run test",
"prepublishOnly": "npm run build"
},
"dependencies": {
"node-fetch": "2.6.7",
"openai": "4.47.1",
"sharp": "0.33.3",
"node-fetch": "2.6.7"
"optional": "0.1.4",
"sharp": "0.33.3"
},
"devDependencies": {
"@types/node-fetch": "2.6.11",
"@modern-js/module-tools": "^2.56.1",
"@types/node": "^18.0.0",
"@types/node-fetch": "2.6.11",
"dotenv": "16.4.5",
"langsmith": "0.1.36",
"typescript": "~5.0.4",
"vitest": "^1.6.0",
"dotenv": "16.4.5"
"vitest": "^1.6.0"
},
"engines": {
"node": ">=16.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/midscene/src/ai-model/coze/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export async function callCozeAi<T>(options: {

const aiResponse = await completion.json();
if (aiResponse.code !== 0) {
console.error('CozeAI error response', aiResponse);
throw new Error('CozeAI error response', aiResponse);
console.error('CozeAI error response', aiResponse.msg);
throw new Error(`CozeAI error response ${aiResponse.msg}`);
}

if (!aiResponse?.messages || !aiResponse?.messages[0]?.content) {
Expand Down
1 change: 1 addition & 0 deletions packages/midscene/src/ai-model/openai/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export async function call(
model,
messages,
response_format: { type: responseFormat },
temperature: 0.2,
});

const { content } = completion.choices[0].message;
Expand Down
16 changes: 0 additions & 16 deletions packages/midscene/tests/__snapshots__/showcase.test.ts.snap

This file was deleted.

34 changes: 0 additions & 34 deletions packages/midscene/tests/ai-model/assert/assert-coze.test.ts

This file was deleted.

34 changes: 0 additions & 34 deletions packages/midscene/tests/ai-model/assert/assert-openai.test.ts

This file was deleted.

81 changes: 0 additions & 81 deletions packages/midscene/tests/ai-model/automation/planning-coze.test.ts

This file was deleted.

Loading

0 comments on commit b07f83d

Please sign in to comment.