Skip to content

Commit e2a0e91

Browse files
authored
SDK-shape conformance test for SearchableIndex (#222)
* test: SDK-shape conformance guard for SearchableIndex (#220) SearchableIndex is a hand-written interface and indexes.ts force-casts the SDK index to it with as unknown as, which erases type checking; existing tests only mock our own interface. So an SDK bump that renames or removes a method the code calls would slip past the compiler and fail at runtime. Assert the members the code relies on (describeIndexStats, namespace, searchRecords, query) exist on a real SDK index handle, constructed offline with no network. A compile-time assertion was tried but the SDK types the index too loosely to catch drift without passing vacuously, so this is a runtime check; verified a renamed member fails it. * test: assert query/searchRecords on the namespace handle, not top-level (#220 review) The code calls query and searchRecords through index.namespace(ns) (indexes.ts namespace(ns).query, search.ts namespace(ns).searchRecords), so probe them on the namespace handle rather than the top-level index. describeIndexStats/namespace and the searchRecords index-fallback stay on the top-level index. Confirmed a bogus namespace-handle member fails the test.
1 parent 9ce9e7b commit e2a0e91

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { Pinecone } from '@pinecone-database/pinecone';
3+
4+
/**
5+
* SDK-shape conformance guard for SearchableIndex (#220).
6+
*
7+
* `indexes.ts` force-casts `pc.index(...)` to `SearchableIndex` with `as unknown as`,
8+
* which erases type checking, and the other tests only mock our own interface. So
9+
* nothing verifies the real SDK index still provides the members the code calls. If a
10+
* Pinecone SDK bump renames or removes one, it slips past the compiler and fails at
11+
* runtime in production. This asserts those members exist on a real SDK index, so a
12+
* drift fails here loudly instead.
13+
*
14+
* A compile-time assertion was tried but the SDK types the index too loosely to catch
15+
* drift, so this is a runtime existence check. `pc.index()` returns a handle
16+
* synchronously with no network call, so it needs no live Pinecone.
17+
*/
18+
describe('SearchableIndex SDK conformance (#220)', () => {
19+
const index = new Pinecone({ apiKey: 'pc-conformance-test' }).index(
20+
'conformance-test'
21+
) as unknown as Record<string, unknown>;
22+
23+
// Called on the top-level index: indexes.ts uses describeIndexStats() and
24+
// namespace(), and search.ts uses searchRecords() on the index fallback branch.
25+
it.each(['describeIndexStats', 'namespace', 'searchRecords'] as const)(
26+
'the SDK index exposes %s()',
27+
(method) => {
28+
expect(typeof index[method]).toBe('function');
29+
}
30+
);
31+
32+
// Called on the namespace handle from index.namespace(ns): indexes.ts does
33+
// namespace(ns).query(...) and search.ts does namespace(ns).searchRecords(...).
34+
const namespaceHandle = (index.namespace as (name: string) => Record<string, unknown>)(
35+
'conformance-test'
36+
);
37+
it.each(['query', 'searchRecords'] as const)(
38+
'the SDK namespace handle exposes %s()',
39+
(method) => {
40+
expect(typeof namespaceHandle[method]).toBe('function');
41+
}
42+
);
43+
});

0 commit comments

Comments
 (0)