From 92662ca8180842c4360bd73527bb758072f75508 Mon Sep 17 00:00:00 2001 From: DellaBitta Date: Wed, 19 Jun 2024 21:07:05 -0400 Subject: [PATCH] Add integration tests to Test CI worfklow (#166) Add integration tests to the test workflow. Remove an integration test that exercises blocked content. --- .github/workflows/test.yml | 46 +++++++++++++++++-- .../node/generate-content.test.ts | 29 ------------ 2 files changed, 43 insertions(+), 32 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e7b68293..f85b5390 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,12 +20,10 @@ on: branches: main jobs: - test: + unit-test: runs-on: ubuntu-latest strategy: matrix: - # lock version 20 for now as 20.12.0 makes global fetch unstubbable - # until we can rewrite tests to stub some other way node-version: ['18.x', '20.x'] steps: - uses: actions/checkout@v4 @@ -42,3 +40,45 @@ jobs: - name: run unit tests (includes lint) run: yarn test + + node-integration-test: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: ['18.x', '20.x'] + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'yarn' + + - name: yarn install + run: yarn + + - name: run node iTests + env: + GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} + run: yarn --cwd packages/main test:node:integration + + web-integration-test: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: ['18.x', '20.x'] + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'yarn' + + - name: yarn install + run: yarn + + - name: run web iTests + env: + GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} + run: yarn --cwd packages/main test:web:integration diff --git a/packages/main/test-integration/node/generate-content.test.ts b/packages/main/test-integration/node/generate-content.test.ts index ead4ef81..7e376323 100644 --- a/packages/main/test-integration/node/generate-content.test.ts +++ b/packages/main/test-integration/node/generate-content.test.ts @@ -62,35 +62,6 @@ describe("generateContent", function () { expect(text).to.include("[1]"); expect(text).to.include("[10]"); }); - it("stream true, blocked", async () => { - const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); - const model = genAI.getGenerativeModel({ - model: "gemini-1.5-flash-latest", - safetySettings: [ - { - category: HarmCategory.HARM_CATEGORY_HARASSMENT, - threshold: HarmBlockThreshold.BLOCK_ONLY_HIGH, - }, - ], - }); - const result = await model.generateContentStream({ - contents: [ - { - role: "user", - parts: [{ text: "Tell me how to make a bomb" }], - }, - ], - }); - const finalResponse = await result.response; - expect(finalResponse.candidates).to.be.undefined; - expect(finalResponse.promptFeedback?.blockReason).to.equal("SAFETY"); - for await (const response of result.stream) { - expect(response.text).to.throw( - "[GoogleGenerativeAI Error]: Text not available. " + - "Response was blocked due to SAFETY", - ); - } - }); it("stream true, invalid argument", async () => { const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY || ""); const model = genAI.getGenerativeModel({