Skip to content

Commit

Permalink
Attempt to fix e2e test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettgu10 committed Oct 16, 2024
1 parent 1f0eb23 commit e45a49d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 4 additions & 0 deletions packages/wrangler/e2e/dev-with-resources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ describe.sequential.each(RUNTIMES)("Bindings: $flags", ({ runtime, flags }) => {
});

it("exposes Vectorize bindings", async () => {
if (isLocal) return; // local mode is not supported yet for vectorize
// TODO: remove this testing code
await helper.d1(isLocal);

const name = await helper.vectorize(32, "euclidean");

await helper.seed({
Expand Down
6 changes: 3 additions & 3 deletions packages/wrangler/src/dev/miniflare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ async function buildSourceOptions(
? {
entrypointSource: config.bundle.entrypointSource,
modules: config.bundle.modules,
}
}
: withSourceURLs(
scriptPath,
config.bundle.entrypointSource,
config.bundle.modules
);
);

const entrypointNames = isPython
? []
Expand Down Expand Up @@ -620,7 +620,7 @@ export function buildMiniflareBindingOptions(config: MiniflareBindingsConfig): {
},
],
serviceBindings: {
FETCHER: MakeVectorizeFetcher(indexName, indexVersion),
FETCHER: MakeVectorizeFetcher(indexName),
},
bindings: {
INDEX_ID: indexName,
Expand Down
12 changes: 7 additions & 5 deletions packages/wrangler/src/vectorize/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ const URL_SUBSTITUTIONS = new Map<string, string>([
["deleteByIds", "delete_by_ids"],
]);

function toNdJson(arr: object[]): string {
return arr.reduce((acc, o) => acc + JSON.stringify(o) + "\n", "").trim();
}
export function MakeVectorizeFetcher(indexId: string) {
if (indexId !== "v2") {
throw new Error(
"Only v2 indexes are supported in local dev mode at the moment."
);
}

export function MakeVectorizeFetcher(indexId: string, indexVersion: string) {
return async function (request: Request): Promise<Response> {
const accountId = await getAccountId();

Expand Down Expand Up @@ -68,7 +70,7 @@ export function MakeVectorizeFetcher(indexId: string, indexVersion: string) {
: {
error: apiResponse.errors[0].message,
code: apiResponse.errors[0].code,
};
};

return new Response(JSON.stringify(newResponse), {
status: res.status,
Expand Down

0 comments on commit e45a49d

Please sign in to comment.