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

test(examples): e2e test for examples #80

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

akihikokuroda
Copy link

@akihikokuroda akihikokuroda commented Oct 10, 2024

Which issue(s) does this pull-request address?

Closes: #62

Description

This PR changes add making examples run during e2e testing.

Checklist

  • I have read the contributor guide
  • Linting passes: yarn lint or yarn lint:fix
  • Formatting is applied: yarn format or yarn format:fix
  • Unit tests pass: yarn test:unit
  • E2E tests pass: yarn test:e2e
  • Tests are included
  • Documentation is changed or added
  • Commit messages and PR title follow conventional commits

@akihikokuroda
Copy link
Author

For now, there is only one test for "memory/agentMemory.ts" added. I want to know if this is in the right direction or not.
Thanks!

@Tomas2D Tomas2D self-requested a review October 10, 2024 15:27
Copy link
Member

@Tomas2D Tomas2D left a comment

Choose a reason for hiding this comment

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

  • We don't want to modify the existing examples directory.
  • Testing output is not important.

Please see the Python example that I mentioned in the related Github issue.

@akihikokuroda
Copy link
Author

@Tomas2D There are not changes in the /examples directory. The tests of the examples are under /tests/examples directory that executes the examples as-is and check if the examples generate any output.

@Tomas2D
Copy link
Member

Tomas2D commented Oct 10, 2024

Oh. I wanted to say that I don't want 1:1 mapping between the tests/examples and the examples directories.

I would like to have one example test file, test/e2e/examples.ts, which executes (recursively) all files under the examples directory. This file will contain filters (so you can ignore some concrete examples or run them conditionally).

@akihikokuroda
Copy link
Author

@Tomas2D Thanks for review and direction. I'll work on it.

@akihikokuroda akihikokuroda force-pushed the examples-e2e branch 2 times, most recently from 3c87777 to d32d11c Compare October 11, 2024 01:16
@akihikokuroda
Copy link
Author

akihikokuroda commented Oct 11, 2024

yarn test:examples runs the all examples
EXAMPLE_NAME=<example name pattern> yarn test:examples runs the tests that matches the pattern (I couldn't find the way to pass the pattern as an argument of the yarn command)

The interactive examples and some other are failing. I'll look into the failures.

tests/e2e/examples.test.ts Outdated Show resolved Hide resolved
@akihikokuroda akihikokuroda force-pushed the examples-e2e branch 2 times, most recently from 85726e9 to 043c459 Compare October 11, 2024 19:46
.github/workflows/examples-tests.yml Outdated Show resolved Hide resolved
.github/workflows/examples-tests.yml Show resolved Hide resolved
tests/setup.examples.ts Outdated Show resolved Hide resolved
vitest.examples.config.ts Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@akihikokuroda
Copy link
Author

In the last commit:

  • move the examples.test.ts to /tests/examples
  • limit the number of concurrent executions to 5

@akihikokuroda akihikokuroda force-pushed the examples-e2e branch 2 times, most recently from ff6eed3 to 56ee5ee Compare October 14, 2024 00:33
@akihikokuroda
Copy link
Author

The last commit adds the configuration that can exclude examples from the tests in case some examples may not be expected work successfully.

@akihikokuroda akihikokuroda changed the title [WIP] test(examples): e2e test for examples test(examples): e2e test for examples Oct 14, 2024
dot: false,
realpath: true,
});
const config = JSON.parse(fs.readFileSync("./tests/examples/example_test.cfg", "utf8"));
Copy link
Member

Choose a reason for hiding this comment

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

I don't see the point of adding a next file. Declare ignored paths in this file directly.
Note: don't use a sync operation in an async environment

Comment on lines 37 to 38
it.concurrent(`Run ${example}`, async () => {
await semaphore.acquire();
Copy link
Member

Choose a reason for hiding this comment

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

it.concurrent(`Run ${example}`, async () => {
await semaphore.acquire();
try {
execSync(`yarn start -- ${example}`).toString();
Copy link
Member

Choose a reason for hiding this comment

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

Why do you call toString() even though you don't print anything?

Copy link
Member

Choose a reason for hiding this comment

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

btw, I think you should print something.

Copy link
Member

Choose a reason for hiding this comment

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

Move this file under examples.

passWithNoTests: true,
testTimeout: 120 * 1000,
printConsoleTrace: true,
setupFiles: ["./tests/setup.examples.ts"],
Copy link
Member

Choose a reason for hiding this comment

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

Use the same setup as the E2E tests.

Copy link
Member

Choose a reason for hiding this comment

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

or ideally just import e2e test config and spread it here

export define defineConfig({
   ...e2eConfig,
   // changes
})

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure how to do it. What necessary is undefine afterEach function defined in the "setup.ts".

vitest.examples.config.ts Outdated Show resolved Hide resolved
@akihikokuroda akihikokuroda force-pushed the examples-e2e branch 3 times, most recently from d95f4e7 to 11b92b8 Compare October 14, 2024 19:55
package.json Outdated Show resolved Hide resolved
Copy link
Member

@Tomas2D Tomas2D left a comment

Choose a reason for hiding this comment

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

So far so good!

tests/examples/examples.test.ts Outdated Show resolved Hide resolved
@akihikokuroda
Copy link
Author

There are still 3 example errors. I added them in the exclude list for now. They are:

Run examples/cache/fileCache.ts 964ms
Run examples/llms/providers/bam_verbose.ts 1718ms
Run examples/llms/providers/bam.ts 1919ms

Here is the errors.

 FAIL  tests/examples/examples.test.ts > E2E Examples > Run examples/cache/fileCache.ts
Error: Command failed: yarn start -- examples/cache/fileCache.ts <<< "Hello world"
node:internal/modules/run_main:129
    triggerUncaughtException(
    ^

[SerializerError: Class "UnconstrainedCache" was not found!] {
  isFatal: true,
  isRetryable: false,
  context: {},
  [errors]: []
}

Node.js v20.17.0

 FAIL  tests/examples/examples.test.ts > E2E Examples > Run examples/llms/providers/bam_verbose.ts
Error: Command failed: yarn start -- examples/llms/providers/bam_verbose.ts <<< "Hello world"
node:internal/modules/run_main:129
    triggerUncaughtException(
    ^

[LLMError: LLM has occurred an error!] {
  isFatal: false,
  isRetryable: false,
  context: {},
  [errors]: [
    HttpError: Model not found
        at clientErrorWrapper (file:///Users/akihikokuroda/development/repositories/agenticflow/bee-agent-framework/node_modules/@ibm-generative-ai/node-sdk/dist/chunk-D3OWGAYN.js:321:13)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async file:///Users/akihikokuroda/development/repositories/agenticflow/bee-agent-framework/node_modules/p-queue-compat/dist/esm/index.js:118:26 {
      error: 'Not Found',
      status_code: 404,
      extensions: {
        code: 'NOT_FOUND',
        state: { model_id: 'meta-llama/llama-3-1-70b-instruct' }
      },
      [cause]: {
        status_code: 404,
        error: 'Not Found',
        message: 'Model not found',
        extensions: {
          code: 'NOT_FOUND',
          state: { model_id: 'meta-llama/llama-3-1-70b-instruct' }
        }
      }
    }
  ]
}

Node.js v20.17.0

 ❯ clientErrorWrapper node_modules/@ibm-generative-ai/node-sdk/dist/chunk-D3OWGAYN.js:321:13

 FAIL  tests/examples/examples.test.ts > E2E Examples > Run examples/llms/providers/bam.ts
Error: Command failed: yarn start -- examples/llms/providers/bam.ts <<< "Hello world"
node:internal/modules/run_main:129
    triggerUncaughtException(
    ^

[LLMError: LLM has occurred an error!] {
  isFatal: false,
  isRetryable: false,
  context: {},
  [errors]: [
    HttpError: Model not found
        at clientErrorWrapper (file:///Users/akihikokuroda/development/repositories/agenticflow/bee-agent-framework/node_modules/@ibm-generative-ai/node-sdk/dist/chunk-D3OWGAYN.js:321:13)
        at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
        at async file:///Users/akihikokuroda/development/repositories/agenticflow/bee-agent-framework/node_modules/p-queue-compat/dist/esm/index.js:118:26 {
      error: 'Not Found',
      status_code: 404,
      extensions: {
        code: 'NOT_FOUND',
        state: { model_id: 'meta-llama/llama-3-1-70b-instruct' }
      },
      [cause]: {
        status_code: 404,
        error: 'Not Found',
        message: 'Model not found',
        extensions: {
          code: 'NOT_FOUND',
          state: { model_id: 'meta-llama/llama-3-1-70b-instruct' }
        }
      }
    }
  ]
}

Node.js v20.17.0

 ❯ clientErrorWrapper node_modules/@ibm-generative-ai/node-sdk/dist/chunk-D3OWGAYN.js:321:13

@Tomas2D
Copy link
Member

Tomas2D commented Oct 15, 2024

  • Regarding BAM (llama 3.1 is accessible only to some users). Let's ignore it for now. I will resolve this internally.
  • Change EXAMPLE_NAME to INCLUDE or INCLUDE_PATTERN
  • Add EXCLUDE or EXCLUDE_PATTERN optional env and use ignore property in the glob function
  • What wraps my head around is this not working test examples/cache/fileCache.ts. It works on my machine.
    • Try to 1. run the example without vitest (yarn start examples/cache/fileCache.ts or 2. replace os.tmpdir with some different static path.

@akihikokuroda akihikokuroda force-pushed the examples-e2e branch 2 times, most recently from 8b13f9b to d4b7b92 Compare October 16, 2024 14:55
@akihikokuroda
Copy link
Author

The environment variable names are now "INCLUDE_PATTERN" and "EXCLUDE_PATTERN".
The fileCache.ts works by replacing the os.tmpdir for me. Thanks!

Comment on lines +52 to +55
if (exclude.includes(example.slice(prefixLength))) {
continue;
}
Copy link
Member

Choose a reason for hiding this comment

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

This can be simplified.

   if (!exclude.startsWith('examples') {
      continue;
    }

Copy link
Author

Choose a reason for hiding this comment

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

The condition is to exclude such as when
examples is examples/templates/objects.ts
and exclude contains templates/objects.ts.

So the items in exclude list don't need to have examples/.

continue;
}
it.concurrent(`Run ${example}`, async () => {
const { stdout } = await execAsync(`yarn start -- ${example} <<< "Hello world"`);
Copy link
Member

Choose a reason for hiding this comment

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

we should also check for stderr being empty and return code being equal to 0

@Tomas2D
Copy link
Member

Tomas2D commented Oct 17, 2024

The os.tmpdir() should be cross-platform. Which operating system are you using? This should work

@akihikokuroda
Copy link
Author

It's M1 Mac. Sonoma 14.5

Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Run all examples as part of E2E tests
2 participants