fix: stabilize tests and logging
This commit is contained in:
@@ -183,7 +183,9 @@ async function fetchGeminiBatchStatus(params: {
|
||||
batchName: string;
|
||||
}): Promise<GeminiBatchStatus> {
|
||||
const baseUrl = getGeminiBaseUrl(params.gemini);
|
||||
const name = params.batchName.startsWith("batches/") ? params.batchName : `batches/${params.batchName}`;
|
||||
const name = params.batchName.startsWith("batches/")
|
||||
? params.batchName
|
||||
: `batches/${params.batchName}`;
|
||||
const statusUrl = `${baseUrl}/${name}`;
|
||||
debugLog("memory embeddings: gemini batch status", { statusUrl });
|
||||
const res = await fetch(statusUrl, {
|
||||
@@ -328,7 +330,11 @@ export async function runGeminiEmbeddingBatches(params: {
|
||||
requests: group.length,
|
||||
});
|
||||
|
||||
if (!params.wait && batchInfo.state && !["SUCCEEDED", "COMPLETED", "DONE"].includes(batchInfo.state)) {
|
||||
if (
|
||||
!params.wait &&
|
||||
batchInfo.state &&
|
||||
!["SUCCEEDED", "COMPLETED", "DONE"].includes(batchInfo.state)
|
||||
) {
|
||||
throw new Error(
|
||||
`gemini batch ${batchName} submitted; enable remote.batch.wait to await completion`,
|
||||
);
|
||||
@@ -376,8 +382,7 @@ export async function runGeminiEmbeddingBatches(params: {
|
||||
errors.push(`${customId}: ${line.response.error.message}`);
|
||||
continue;
|
||||
}
|
||||
const embedding =
|
||||
line.embedding?.values ?? line.response?.embedding?.values ?? [];
|
||||
const embedding = line.embedding?.values ?? line.response?.embedding?.values ?? [];
|
||||
if (embedding.length === 0) {
|
||||
errors.push(`${customId}: empty embedding`);
|
||||
continue;
|
||||
|
||||
@@ -3,14 +3,8 @@ import fsSync from "node:fs";
|
||||
import type { Llama, LlamaEmbeddingContext, LlamaModel } from "node-llama-cpp";
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
import { resolveUserPath } from "../utils.js";
|
||||
import {
|
||||
createGeminiEmbeddingProvider,
|
||||
type GeminiEmbeddingClient,
|
||||
} from "./embeddings-gemini.js";
|
||||
import {
|
||||
createOpenAiEmbeddingProvider,
|
||||
type OpenAiEmbeddingClient,
|
||||
} from "./embeddings-openai.js";
|
||||
import { createGeminiEmbeddingProvider, type GeminiEmbeddingClient } from "./embeddings-gemini.js";
|
||||
import { createOpenAiEmbeddingProvider, type OpenAiEmbeddingClient } from "./embeddings-openai.js";
|
||||
import { importNodeLlamaCpp } from "./node-llama.js";
|
||||
|
||||
export type { GeminiEmbeddingClient } from "./embeddings-gemini.js";
|
||||
@@ -68,7 +62,6 @@ function isMissingApiKeyError(err: unknown): boolean {
|
||||
return message.includes("No API key found for provider");
|
||||
}
|
||||
|
||||
|
||||
async function createLocalEmbeddingProvider(
|
||||
options: EmbeddingProviderOptions,
|
||||
): Promise<EmbeddingProvider> {
|
||||
@@ -188,9 +181,7 @@ export async function createEmbeddingProvider(
|
||||
fallbackReason: reason,
|
||||
};
|
||||
} catch (fallbackErr) {
|
||||
throw new Error(
|
||||
`${reason}\n\nFallback to ${fallback} failed: ${formatError(fallbackErr)}`,
|
||||
);
|
||||
throw new Error(`${reason}\n\nFallback to ${fallback} failed: ${formatError(fallbackErr)}`);
|
||||
}
|
||||
}
|
||||
throw new Error(reason);
|
||||
|
||||
@@ -697,9 +697,7 @@ export class MemoryIndexManager {
|
||||
|
||||
private async removeIndexFiles(basePath: string): Promise<void> {
|
||||
const suffixes = ["", "-wal", "-shm"];
|
||||
await Promise.all(
|
||||
suffixes.map((suffix) => fs.rm(`${basePath}${suffix}`, { force: true })),
|
||||
);
|
||||
await Promise.all(suffixes.map((suffix) => fs.rm(`${basePath}${suffix}`, { force: true })));
|
||||
}
|
||||
|
||||
private ensureSchema() {
|
||||
@@ -1064,8 +1062,8 @@ export class MemoryIndexManager {
|
||||
const batch = this.settings.remote?.batch;
|
||||
const enabled = Boolean(
|
||||
batch?.enabled &&
|
||||
((this.openAi && this.provider.id === "openai") ||
|
||||
(this.gemini && this.provider.id === "gemini")),
|
||||
((this.openAi && this.provider.id === "openai") ||
|
||||
(this.gemini && this.provider.id === "gemini")),
|
||||
);
|
||||
return {
|
||||
enabled,
|
||||
|
||||
@@ -63,7 +63,11 @@ describe("memory vector dedupe", () => {
|
||||
if (!result.manager) throw new Error("manager missing");
|
||||
manager = result.manager;
|
||||
|
||||
const db = (manager as unknown as { db: { exec: (sql: string) => void; prepare: (sql: string) => unknown } }).db;
|
||||
const db = (
|
||||
manager as unknown as {
|
||||
db: { exec: (sql: string) => void; prepare: (sql: string) => unknown };
|
||||
}
|
||||
).db;
|
||||
db.exec("CREATE TABLE IF NOT EXISTS chunks_vec (id TEXT PRIMARY KEY, embedding BLOB)");
|
||||
|
||||
const sqlSeen: string[] = [];
|
||||
@@ -75,16 +79,20 @@ describe("memory vector dedupe", () => {
|
||||
return originalPrepare(sql);
|
||||
};
|
||||
|
||||
(manager as unknown as { ensureVectorReady: (dims?: number) => Promise<boolean> }).ensureVectorReady =
|
||||
async () => true;
|
||||
(
|
||||
manager as unknown as { ensureVectorReady: (dims?: number) => Promise<boolean> }
|
||||
).ensureVectorReady = async () => true;
|
||||
|
||||
const entry = await buildFileEntry(path.join(workspaceDir, "MEMORY.md"), workspaceDir);
|
||||
await (manager as unknown as { indexFile: (entry: unknown, options: { source: "memory" }) => Promise<void> }).indexFile(
|
||||
entry,
|
||||
{ source: "memory" },
|
||||
);
|
||||
await (
|
||||
manager as unknown as {
|
||||
indexFile: (entry: unknown, options: { source: "memory" }) => Promise<void>;
|
||||
}
|
||||
).indexFile(entry, { source: "memory" });
|
||||
|
||||
const deleteIndex = sqlSeen.findIndex((sql) => sql.includes("DELETE FROM chunks_vec WHERE id = ?"));
|
||||
const deleteIndex = sqlSeen.findIndex((sql) =>
|
||||
sql.includes("DELETE FROM chunks_vec WHERE id = ?"),
|
||||
);
|
||||
const insertIndex = sqlSeen.findIndex((sql) => sql.includes("INSERT INTO chunks_vec"));
|
||||
expect(deleteIndex).toBeGreaterThan(-1);
|
||||
expect(insertIndex).toBeGreaterThan(-1);
|
||||
|
||||
Reference in New Issue
Block a user