-
Notifications
You must be signed in to change notification settings - Fork 204
fix(config): strip inline # comments + route /config/flags through merged env (#200, #201) #206
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
+108
−7
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| 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 ORIGINAL_HOME = process.env["HOME"]; | ||
| const ORIGINAL_USERPROFILE = process.env["USERPROFILE"]; | ||
|
|
||
| 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("loadEnvFile", () => { | ||
| beforeEach(() => { | ||
| sandboxHome = mkdtempSync(join(tmpdir(), "agentmemory-env-")); | ||
| process.env["HOME"] = sandboxHome; | ||
| process.env["USERPROFILE"] = sandboxHome; | ||
| delete process.env["AGENTMEMORY_AUTO_COMPRESS"]; | ||
| delete process.env["CONSOLIDATION_ENABLED"]; | ||
| delete process.env["GRAPH_EXTRACTION_ENABLED"]; | ||
| delete process.env["TOKEN"]; | ||
| delete process.env["HASHVAL"]; | ||
| }); | ||
|
|
||
| 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; | ||
| rmSync(sandboxHome, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| it("strips trailing inline # comments on unquoted values", async () => { | ||
| writeEnv( | ||
| [ | ||
| "AGENTMEMORY_AUTO_COMPRESS=true # opt in to LLM compression", | ||
| "CONSOLIDATION_ENABLED=true # daily summarization", | ||
| "GRAPH_EXTRACTION_ENABLED=true # entity graph", | ||
| ].join("\n"), | ||
| ); | ||
| const cfg = await freshConfig(); | ||
| expect(cfg.isAutoCompressEnabled()).toBe(true); | ||
| expect(cfg.isConsolidationEnabled()).toBe(true); | ||
| expect(cfg.isGraphExtractionEnabled()).toBe(true); | ||
| }); | ||
|
|
||
| it("preserves # inside double-quoted values", async () => { | ||
| writeEnv('TOKEN="abc#def"'); | ||
| const cfg = await freshConfig(); | ||
| expect(cfg.getEnvVar("TOKEN")).toBe("abc#def"); | ||
| }); | ||
|
|
||
| it("preserves # inside single-quoted values", async () => { | ||
| writeEnv("TOKEN='abc#def'"); | ||
| const cfg = await freshConfig(); | ||
| expect(cfg.getEnvVar("TOKEN")).toBe("abc#def"); | ||
| }); | ||
|
|
||
| it("treats hash without leading space as part of value", async () => { | ||
| writeEnv("HASHVAL=abc#def"); | ||
| const cfg = await freshConfig(); | ||
| expect(cfg.getEnvVar("HASHVAL")).toBe("abc#def"); | ||
| }); | ||
|
|
||
| it("strips inline comment after a quoted value and unwraps quotes", async () => { | ||
| writeEnv('TOKEN="abc" # trailing comment'); | ||
| const cfg = await freshConfig(); | ||
| expect(cfg.getEnvVar("TOKEN")).toBe("abc"); | ||
| }); | ||
|
|
||
| it("strips inline comment after a single-quoted value and unwraps quotes", async () => { | ||
| writeEnv("TOKEN='abc' # trailing comment"); | ||
| const cfg = await freshConfig(); | ||
| expect(cfg.getEnvVar("TOKEN")).toBe("abc"); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.