-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(consolidation): default ON when LLM provider is configured (#612) #696
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
Merged
+139
−5
Merged
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
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,112 @@ | ||
| import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"; | ||
| import { mkdtempSync, writeFileSync, mkdirSync, rmSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
|
|
||
| const ENV_KEYS = [ | ||
| "CONSOLIDATION_ENABLED", | ||
| "AGENTMEMORY_PROVIDER", | ||
| "ANTHROPIC_API_KEY", | ||
| "OPENAI_API_KEY", | ||
| "OPENAI_API_KEY_FOR_LLM", | ||
| "OPENROUTER_API_KEY", | ||
| "GEMINI_API_KEY", | ||
| "GOOGLE_API_KEY", | ||
| "MINIMAX_API_KEY", | ||
| "OPENAI_BASE_URL", | ||
| ]; | ||
|
|
||
| const ORIGINAL_HOME = process.env["HOME"]; | ||
| const ORIGINAL_USERPROFILE = process.env["USERPROFILE"]; | ||
| const ORIGINAL: Record<string, string | undefined> = {}; | ||
|
|
||
| let sandboxHome: string; | ||
|
|
||
| async function freshConfig() { | ||
| vi.resetModules(); | ||
| return await import("../src/config.js"); | ||
| } | ||
|
|
||
| function writeEnv(contents: string) { | ||
| const dir = join(sandboxHome, ".agentmemory"); | ||
| mkdirSync(dir, { recursive: true }); | ||
| writeFileSync(join(dir, ".env"), contents); | ||
| } | ||
|
|
||
| describe("isConsolidationEnabled default behavior", () => { | ||
| beforeEach(() => { | ||
| sandboxHome = mkdtempSync(join(tmpdir(), "agentmemory-consolidation-")); | ||
| process.env["HOME"] = sandboxHome; | ||
| process.env["USERPROFILE"] = sandboxHome; | ||
| for (const k of ENV_KEYS) { | ||
| ORIGINAL[k] = process.env[k]; | ||
| delete process.env[k]; | ||
| } | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| if (ORIGINAL_HOME === undefined) delete process.env["HOME"]; | ||
| else process.env["HOME"] = ORIGINAL_HOME; | ||
| if (ORIGINAL_USERPROFILE === undefined) delete process.env["USERPROFILE"]; | ||
| else process.env["USERPROFILE"] = ORIGINAL_USERPROFILE; | ||
| for (const k of ENV_KEYS) { | ||
| if (ORIGINAL[k] === undefined) delete process.env[k]; | ||
| else process.env[k] = ORIGINAL[k]; | ||
| } | ||
| rmSync(sandboxHome, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| it("returns false when no LLM provider configured (default BM25-only mode)", async () => { | ||
| writeEnv(""); | ||
| const cfg = await freshConfig(); | ||
| expect(cfg.isConsolidationEnabled()).toBe(false); | ||
| }); | ||
|
|
||
| it("returns true by default when ANTHROPIC_API_KEY is set", async () => { | ||
| writeEnv("ANTHROPIC_API_KEY=sk-test-123"); | ||
| const cfg = await freshConfig(); | ||
| expect(cfg.isConsolidationEnabled()).toBe(true); | ||
| }); | ||
|
|
||
| it("returns true by default when OPENAI_API_KEY is set", async () => { | ||
| writeEnv("OPENAI_API_KEY=sk-test-123"); | ||
| const cfg = await freshConfig(); | ||
| expect(cfg.isConsolidationEnabled()).toBe(true); | ||
| }); | ||
|
|
||
| it("returns true by default when OPENAI_BASE_URL is set (local OpenAI-compatible)", async () => { | ||
| writeEnv("OPENAI_BASE_URL=http://localhost:1234/v1"); | ||
| const cfg = await freshConfig(); | ||
| expect(cfg.isConsolidationEnabled()).toBe(true); | ||
| }); | ||
|
|
||
| it("returns true by default when AGENTMEMORY_PROVIDER=agent-sdk", async () => { | ||
| writeEnv("AGENTMEMORY_PROVIDER=agent-sdk"); | ||
| const cfg = await freshConfig(); | ||
| expect(cfg.isConsolidationEnabled()).toBe(true); | ||
| }); | ||
|
|
||
| it("explicit CONSOLIDATION_ENABLED=false overrides provider-based default", async () => { | ||
| writeEnv("ANTHROPIC_API_KEY=sk-test-123\nCONSOLIDATION_ENABLED=false"); | ||
| const cfg = await freshConfig(); | ||
| expect(cfg.isConsolidationEnabled()).toBe(false); | ||
| }); | ||
|
|
||
| it("explicit CONSOLIDATION_ENABLED=true overrides absence of provider", async () => { | ||
| writeEnv("CONSOLIDATION_ENABLED=true"); | ||
| const cfg = await freshConfig(); | ||
| expect(cfg.isConsolidationEnabled()).toBe(true); | ||
| }); | ||
|
|
||
| it("AGENTMEMORY_PROVIDER=noop returns false even with API key set", async () => { | ||
| writeEnv("AGENTMEMORY_PROVIDER=noop\nANTHROPIC_API_KEY=sk-test-123"); | ||
| const cfg = await freshConfig(); | ||
| expect(cfg.isConsolidationEnabled()).toBe(false); | ||
| }); | ||
|
|
||
| it("OPENAI_API_KEY_FOR_LLM=false scopes the key to embeddings only", async () => { | ||
| writeEnv("OPENAI_API_KEY=sk-test-123\nOPENAI_API_KEY_FOR_LLM=false"); | ||
| const cfg = await freshConfig(); | ||
| expect(cfg.isConsolidationEnabled()).toBe(false); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.