Repository navigation
[defer] fix embedded CLIProxyAPI config handling #6877
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
diegosouzapw
merged 3 commits into
cheaper-inference:release/v3.8.49
from
professional-ALFIE:agent/fix-cliproxy-config-flag
Jul 21, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
104 changes: 104 additions & 0 deletions
104
tests/unit/services/installers/cliproxy-resolve-spawn-args-6877.test.ts
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,104 @@ | ||
| /** | ||
| * Regression test for #6877 — cliproxy resolveSpawnArgs() must: | ||
| * (a) invoke the real CLIProxyAPI binary with the long-form `--config` flag | ||
| * (the short `-c` flag is not recognized by the upstream binary and | ||
| * silently falls back to its own default config, ignoring ours), and | ||
| * (b) never clobber an existing config.yaml — only write the default | ||
| * template the first time the file does not exist yet. | ||
| * | ||
| * Unlike the pre-existing tests/unit/services/installers/cliproxy.test.ts | ||
| * (which only re-asserts string literals and never calls the real function), | ||
| * this test imports and calls the real resolveSpawnArgs() against a real | ||
| * temp-directory filesystem. | ||
| */ | ||
|
|
||
| import { describe, it, beforeEach, after } from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
| import fs from "node:fs"; | ||
| import os from "node:os"; | ||
| import path from "node:path"; | ||
|
|
||
| const ORIGINAL_DATA_DIR = process.env.DATA_DIR; | ||
|
|
||
| function createTempDataDir(): string { | ||
| return fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-cliproxy-6877-")); | ||
| } | ||
|
|
||
| // DATA_DIR is captured into a module-level const the *first* time | ||
| // src/lib/db/core.ts (transitively imported by cliproxy.ts) is loaded, and | ||
| // dynamic import() results are cached per resolved URL for the lifetime of | ||
| // the process — so the env var must be pinned to one fixed temp dir BEFORE | ||
| // the module is imported for the first time. Each test then resets the | ||
| // *contents* of that same directory rather than re-pointing DATA_DIR. | ||
| const FIXED_DATA_DIR = createTempDataDir(); | ||
| process.env.DATA_DIR = FIXED_DATA_DIR; | ||
|
|
||
| after(() => { | ||
| if (ORIGINAL_DATA_DIR === undefined) { | ||
| delete process.env.DATA_DIR; | ||
| } else { | ||
| process.env.DATA_DIR = ORIGINAL_DATA_DIR; | ||
| } | ||
| fs.rmSync(FIXED_DATA_DIR, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| describe("resolveSpawnArgs (#6877 — real filesystem)", () => { | ||
| const dataDir = FIXED_DATA_DIR; | ||
|
|
||
| beforeEach(() => { | ||
| fs.rmSync(dataDir, { recursive: true, force: true }); | ||
| fs.mkdirSync(dataDir, { recursive: true }); | ||
| }); | ||
|
|
||
| it("uses the --config long flag and never the -c short flag", async () => { | ||
| const { resolveSpawnArgs } = await import( | ||
| "../../../../src/lib/services/installers/cliproxy.ts" | ||
| ); | ||
|
|
||
| const port = 8317; | ||
| const result = resolveSpawnArgs(port); | ||
|
|
||
| const configPath = path.join(dataDir, "services", "cliproxy", "config.yaml"); | ||
|
|
||
| assert.deepEqual(result.args, ["--config", configPath]); | ||
| assert.ok(!result.args.includes("-c"), "args must never contain the short -c flag"); | ||
| }); | ||
|
|
||
| it("writes the default config.yaml template when none exists yet", async () => { | ||
| const { resolveSpawnArgs } = await import( | ||
| "../../../../src/lib/services/installers/cliproxy.ts" | ||
| ); | ||
|
|
||
| const port = 9123; | ||
| const result = resolveSpawnArgs(port); | ||
|
|
||
| const configPath = path.join(dataDir, "services", "cliproxy", "config.yaml"); | ||
| assert.equal(result.args[1], configPath); | ||
| assert.ok(fs.existsSync(configPath), "config.yaml must be created on first run"); | ||
|
|
||
| const content = fs.readFileSync(configPath, "utf8"); | ||
| assert.equal(content, `port: ${port}\nhost: 127.0.0.1\nlog_level: warn\n`); | ||
| }); | ||
|
|
||
| it("preserves a pre-existing config.yaml byte-for-byte instead of overwriting it", async () => { | ||
| const { resolveSpawnArgs } = await import( | ||
| "../../../../src/lib/services/installers/cliproxy.ts" | ||
| ); | ||
|
|
||
| const configDir = path.join(dataDir, "services", "cliproxy"); | ||
| fs.mkdirSync(configDir, { recursive: true }); | ||
| const configPath = path.join(configDir, "config.yaml"); | ||
| const customContent = | ||
| "port: 8317\nhost: 0.0.0.0\nlog_level: debug\n# hand-edited by the operator\napi-keys:\n - custom-key\n"; | ||
| fs.writeFileSync(configPath, customContent, "utf8"); | ||
|
|
||
| resolveSpawnArgs(8317); | ||
|
|
||
| const contentAfter = fs.readFileSync(configPath, "utf8"); | ||
| assert.equal( | ||
| contentAfter, | ||
| customContent, | ||
| "resolveSpawnArgs must not clobber an existing, operator-customized config.yaml" | ||
| ); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the Repository Style Guide (Rule 9: 'Always include tests when changing production code'), any changes to production code under
src/must include corresponding test updates. Please update the unit tests intests/unit/services/installers/cliproxy.test.tsto verify that the--configflag is correctly passed instead of-cto prevent future regressions.References