Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add POC of a testing framework #22

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.16.1
14 changes: 14 additions & 0 deletions e2e_tests/agent_test_cases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const TEST_CASES: {
name:string,
expectedOutput: Record<string, unknown>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add model as well?

startUrl: string,
instructions: string,
}[] = [{
name: 'fetchActorName',
startUrl: 'https://apify.com',
instructions: `Go to the store page and perform a search for "AI Web Agent". Click the first result.
Extract the name of the Actor and save it in the output as 'actorName'.`,
expectedOutput: {
actorName: 'AI Web Agent',
},
}];
25 changes: 25 additions & 0 deletions e2e_tests/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'zx/globals';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good start, I would make this Actor, which can be push to Apify.
The tricky part will be to distinguish between local run and run in platform.
Localy it will be basically same as you have now and you need to add some ifs, in case you run it on platform

  1. Use Actor.call instead npm run start:dev
  2. Input from Actor.getInput not local file.
  3. Save results to dataset maybe.

import fs from 'fs/promises';
import { TEST_CASES } from './agent_test_cases.js';

for (const c of TEST_CASES) {
const input = {
startUrl: c.startUrl,
instructions: c.instructions,
openaiApiKey: process.env.OPENAI_API_KEY,
};
await fs.writeFile('./storage/key_value_stores/default/INPUT.json', JSON.stringify(input));
await $`npm run start:dev`;
const outputRaw = await fs.readFile('./storage/key_value_stores/default/OUTPUT.json', { encoding: 'utf8' });
const output = JSON.parse(outputRaw);
Object.keys(c.expectedOutput).forEach((expectedKey) => {
if (!output[expectedKey]) {
console.log(`ERROR: ${expectedKey} does not exist in the output`);
} else if (c.expectedOutput[expectedKey] !== output[expectedKey]) {
console.log(`ERROR: Expected value for key ${expectedKey} "${c.expectedOutput[expectedKey]}" `
+ `does not correspond to "${output[expectedKey]}" in the output.`);
} else {
console.log('OK');
}
});
}
246 changes: 245 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading