Skip to content

Commit

Permalink
fix: not stubbing env vars in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamwhiteuk committed Sep 27, 2024
1 parent 10621d4 commit 3016ba6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ jobs:
- name: E2E Tests
env:
GENAI_API_KEY: ${{ secrets.GENAI_API_KEY }}
IMAGE_DESC_VLLM_API: ${{ secrets.IMAGE_DESC_VLLM_API }}
IMAGE_DESC_MODEL_ID: ${{ secrets.IMAGE_DESC_MODEL_ID }}
run: yarn test:e2e
3 changes: 0 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,4 @@ jobs:
- name: Build
run: yarn build
- name: Unit Tests
env:
IMAGE_DESC_VLLM_API: ${{ secrets.IMAGE_DESC_VLLM_API }}
IMAGE_DESC_MODEL_ID: ${{ secrets.IMAGE_DESC_MODEL_ID }}
run: yarn test:unit
11 changes: 6 additions & 5 deletions src/tools/imageDescription.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,16 @@
* limitations under the License.
*/

import { getEnv } from "bee-agent-framework/internals/env";

import { ImageDescriptionTool } from "@/tools/imageDescription.js";

import { describe, test, expect } from "vitest";
import { afterAll, afterEach, beforeAll, expect, describe, test, vi } from "vitest";
import { setupServer } from "msw/node";
import { http, HttpResponse } from "msw";

const exampleDescription = "This is the image description text.";
const vllmApiEndpoint = getEnv("IMAGE_DESC_VLLM_API");

const handlers = [
http.post(`${vllmApiEndpoint}/v1/chat/completions`, () => {
http.post(`https://api.openai.com/v1/chat/completions`, () => {
return HttpResponse.json({
choices: [
{
Expand All @@ -43,6 +40,9 @@ const server = setupServer(...handlers);

describe("ImageDescriptionTool", () => {
beforeAll(() => {
vi.stubEnv("IMAGE_DESC_VLLM_API", "https://api.openai.com");
vi.stubEnv("IMAGE_DESC_MODEL_ID", "llava-hf/llama3-llava-next-8b-hf");
vi.stubEnv("OPENAI_API_KEY", "abc123");
server.listen();
});

Expand All @@ -52,6 +52,7 @@ describe("ImageDescriptionTool", () => {

afterAll(() => {
server.close();
vi.unstubAllEnvs();
});

test("make a request to the vllm backend to describe an image", async () => {
Expand Down

0 comments on commit 3016ba6

Please sign in to comment.