-
Notifications
You must be signed in to change notification settings - Fork 10
test: add credential-gated Pinecone integration test #74
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
Open
pinecone-groundskeeper
wants to merge
1
commit into
main
Choose a base branch
from
agent/maintenance/issue-25-123d8286f9bf9d98
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+148
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // Exercises a real upsert/query round-trip against a live Pinecone project — | ||
| // the gap that let a v2→v8 response-shape mismatch (see #5) ship undetected, | ||
| // since unit tests mock the SDK entirely. | ||
| // | ||
| // Skips outright when PINECONE_API_KEY is unset so `npm test` and PR runs | ||
| // stay green and credential-free; only `npm run test:integration` (wired into | ||
| // CI on main/workflow_dispatch, see ci.yml) actually exercises it. | ||
| import { randomUUID } from "crypto"; | ||
| import { afterAll, beforeAll, describe, expect, it } from "vitest"; | ||
| import { | ||
| Pinecone, | ||
| type Index, | ||
| type PineconeRecord, | ||
| } from "@pinecone-database/pinecone"; | ||
| import { getEnv } from "../../src/utils/env.ts"; | ||
| import { chunkedUpsert } from "../../src/utils/chunkedUpsert.ts"; | ||
|
|
||
| const DIMENSION = 384; | ||
| const NAMESPACE = "integration-test"; | ||
|
|
||
| const randomVector = (length: number): number[] => | ||
| Array.from({ length }, () => Math.random()); | ||
|
|
||
| // Serverless upserts are eventually consistent, so a query issued right after | ||
| // an upsert can legitimately return fewer than the expected matches. Poll | ||
| // instead of a fixed sleep. | ||
| async function waitForMatches( | ||
| index: Index, | ||
| vector: number[], | ||
| expected: number, | ||
| { attempts = 10, delayMs = 3000 } = {} | ||
| ) { | ||
| for (let attempt = 0; attempt < attempts; attempt += 1) { | ||
| const result = await index.namespace(NAMESPACE).query({ | ||
| vector, | ||
| topK: expected, | ||
| includeMetadata: true, | ||
| includeValues: true, | ||
| }); | ||
| if ((result.matches?.length ?? 0) >= expected) { | ||
| return result; | ||
| } | ||
| await new Promise((resolve) => setTimeout(resolve, delayMs)); | ||
| } | ||
| throw new Error(`Query never returned ${expected} match(es) in time`); | ||
| } | ||
|
|
||
| describe.skipIf(!process.env.PINECONE_API_KEY)("Pinecone integration", () => { | ||
| const indexName = `recommender-it-${randomUUID().slice(0, 8)}`; | ||
| let pinecone: Pinecone; | ||
| let index: Index; | ||
| let indexCreated = false; | ||
|
|
||
| beforeAll(async () => { | ||
| pinecone = new Pinecone({ apiKey: getEnv("PINECONE_API_KEY") }); | ||
| await pinecone.createIndex({ | ||
| name: indexName, | ||
| dimension: DIMENSION, | ||
| metric: "cosine", | ||
| spec: { | ||
| serverless: { | ||
| cloud: getEnv("PINECONE_CLOUD"), | ||
| region: getEnv("PINECONE_REGION"), | ||
| }, | ||
| }, | ||
| waitUntilReady: true, | ||
| }); | ||
| indexCreated = true; | ||
| index = pinecone.index(indexName); | ||
| }, 120_000); | ||
|
|
||
| afterAll(async () => { | ||
| if (indexCreated) { | ||
| await pinecone.deleteIndex(indexName); | ||
| } | ||
| }); | ||
|
|
||
| it("upserts and queries records through the real chunkedUpsert path", async () => { | ||
| const records: PineconeRecord[] = Array.from({ length: 5 }, (_, i) => ({ | ||
| id: `article-${i}`, | ||
| values: randomVector(DIMENSION), | ||
| metadata: { title: `Article ${i}` }, | ||
| })); | ||
|
|
||
| await chunkedUpsert(index, records, NAMESPACE, 2); | ||
|
|
||
| const result = await waitForMatches( | ||
| index, | ||
| records[0].values as number[], | ||
| records.length | ||
| ); | ||
|
|
||
| expect(result.matches?.length).toBeGreaterThan(0); | ||
| for (const match of result.matches ?? []) { | ||
| expect(match.id).toMatch(/^article-\d+$/); | ||
| expect(match.values).toHaveLength(DIMENSION); | ||
| expect(match.metadata?.title).toBeDefined(); | ||
| } | ||
| }, 60_000); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,12 @@ | ||
| import { defineConfig } from "vitest/config"; | ||
| import { configDefaults, defineConfig } from "vitest/config"; | ||
|
|
||
| // Integration tests live under tests/integration and run via the separate | ||
| // vitest.integration.config.ts / `npm run test:integration`, never here — they | ||
| // hit a real Pinecone project and must not run on untrusted PRs. | ||
| export default defineConfig({ | ||
| test: { | ||
| include: ["tests/**/*.test.ts"], | ||
| exclude: [...configDefaults.exclude, "tests/integration/**"], | ||
| environment: "node", | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { defineConfig } from "vitest/config"; | ||
|
|
||
| // Separate from vitest.config.ts so a plain `npm test` never touches the | ||
| // network: this config's tests hit a real Pinecone project and are run | ||
| // explicitly via `npm run test:integration` (see ci.yml's integration-test | ||
| // job). | ||
| export default defineConfig({ | ||
| test: { | ||
| include: ["tests/integration/**/*.test.ts"], | ||
| environment: "node", | ||
| testTimeout: 120_000, | ||
| hookTimeout: 120_000, | ||
| }, | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throwaway indexes can leak
Medium Severity
indexCreatedflips only aftercreateIndexwithwaitUntilReadyresolves, and teardown runs only inafterAll. A hook timeout or a cancelled CI job (this workflow usescancel-in-progress) leaves the liverecommender-it-*index behind, which can exhaust the project index quota and fail later creates.Additional Locations (1)
.github/workflows/ci.yml#L15-L18Reviewed by Cursor Bugbot for commit 5b57c29. Configure here.