-
Notifications
You must be signed in to change notification settings - Fork 648
fix(openclaw): stop injecting legacy auth-profiles.json beside SQLite stores #288
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
VickyXAI
merged 2 commits into
BlockRunAI:main
from
0xCheetah1:fix/auth-injection-sqlite-aware
Aug 31, 2026
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| // The legacy auth-profiles.json write is now sqlite-aware: beside an | ||
| // openclaw-agent.sqlite store the file is obsolete — and since OpenClaw | ||
| // 2026.8.1 a leftover legacy file beside an empty store fails auth migration | ||
| // closed, bricking dispatch for the whole agent fleet. These pin the new | ||
| // behavior. | ||
| describe("injectAuthProfile", () => { | ||
| let homeDir: string | undefined; | ||
|
|
||
| afterEach(() => { | ||
| vi.resetModules(); | ||
| vi.doUnmock("node:os"); | ||
| if (homeDir) { | ||
| rmSync(homeDir, { recursive: true, force: true }); | ||
| homeDir = undefined; | ||
| } | ||
| }); | ||
|
|
||
| async function withHome() { | ||
| homeDir = mkdtempSync(join(tmpdir(), "clawrouter-auth-profile-")); | ||
| vi.doMock("node:os", async () => ({ | ||
| ...(await vi.importActual<typeof import("node:os")>("node:os")), | ||
| homedir: () => homeDir, | ||
| })); | ||
| const mod = await import("./index.js"); | ||
| return { mod, homeDir }; | ||
| } | ||
|
|
||
| const agentDir = (home: string, agent: string) => | ||
| join(home, ".openclaw", "agents", agent, "agent"); | ||
| const authPath = (home: string, agent: string) => | ||
| join(agentDir(home, agent), "auth-profiles.json"); | ||
|
|
||
| it("still bootstraps the legacy JSON when no SQLite store exists", async () => { | ||
| const { mod, homeDir } = await withHome(); | ||
| mkdirSync(agentDir(homeDir, "main"), { recursive: true }); | ||
| mkdirSync(agentDir(homeDir, "mike"), { recursive: true }); | ||
|
|
||
| mod.injectAuthProfile({ info: vi.fn() }); | ||
|
|
||
| expect(existsSync(authPath(homeDir, "mike"))).toBe(true); | ||
| const store = JSON.parse(readFileSync(authPath(homeDir, "mike"), "utf8")); | ||
| expect(store.profiles["blockrun:default"]?.key).toBe("x402-proxy-handles-auth"); | ||
| }); | ||
|
|
||
| it("never writes into the shared auth-owner directory, even without a store", async () => { | ||
| const { mod, homeDir } = await withHome(); | ||
| mkdirSync(agentDir(homeDir, "main"), { recursive: true }); | ||
|
|
||
| mod.injectAuthProfile({ info: vi.fn() }); | ||
|
|
||
| expect(existsSync(authPath(homeDir, "main"))).toBe(false); | ||
| }); | ||
|
|
||
| it("does not write the legacy JSON beside an existing SQLite store", async () => { | ||
| const { mod, homeDir } = await withHome(); | ||
| const dir = agentDir(homeDir, "mike"); | ||
| mkdirSync(dir, { recursive: true }); | ||
| writeFileSync(join(dir, "openclaw-agent.sqlite"), "placeholder bytes"); | ||
|
|
||
| mod.injectAuthProfile({ info: vi.fn() }); | ||
|
|
||
| expect(existsSync(authPath(homeDir, "mike"))).toBe(false); | ||
| }); | ||
|
|
||
| it("removes our own placeholder beside a SQLite store", async () => { | ||
| const { mod, homeDir } = await withHome(); | ||
| const dir = agentDir(homeDir, "mike"); | ||
| mkdirSync(dir, { recursive: true }); | ||
| writeFileSync(join(dir, "openclaw-agent.sqlite"), "placeholder bytes"); | ||
| writeFileSync( | ||
| authPath(homeDir, "mike"), | ||
| JSON.stringify({ | ||
| version: 1, | ||
| profiles: { | ||
| "blockrun:default": { | ||
| type: "api_key", | ||
| provider: "blockrun", | ||
| key: "x402-proxy-handles-auth", | ||
| }, | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| mod.injectAuthProfile({ info: vi.fn() }); | ||
|
|
||
| expect(existsSync(authPath(homeDir, "mike"))).toBe(false); | ||
| }); | ||
|
|
||
| it("never removes a JSON file that carries real credentials", async () => { | ||
| const { mod, homeDir } = await withHome(); | ||
| const dir = agentDir(homeDir, "mike"); | ||
| mkdirSync(dir, { recursive: true }); | ||
| writeFileSync(join(dir, "openclaw-agent.sqlite"), "placeholder bytes"); | ||
| writeFileSync( | ||
| authPath(homeDir, "mike"), | ||
| JSON.stringify({ | ||
| version: 1, | ||
| profiles: { | ||
| "blockrun:default": { | ||
| type: "api_key", | ||
| provider: "blockrun", | ||
| key: "x402-proxy-handles-auth", | ||
| }, | ||
| "anthropic:default": { type: "api_key", provider: "anthropic", key: "sk-real-key" }, | ||
| }, | ||
| }), | ||
| ); | ||
|
|
||
| mod.injectAuthProfile({ info: vi.fn() }); | ||
|
|
||
| expect(existsSync(authPath(homeDir, "mike"))).toBe(true); | ||
| }); | ||
| }); |
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
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.
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: BlockRunAI/ClawRouter
Length of output: 14325
🏁 Script executed:
Repository: BlockRunAI/ClawRouter
Length of output: 11337
🌐 Web query:
Node.js 22 fs.existsSync returns true for directories official documentation💡 Result:
Yes, in Node.js 22, the fs.existsSync(path) method returns true if the specified path exists, regardless of whether that path points to a file or a directory [1]. Official Node.js documentation defines fs.existsSync as a synchronous method that returns true if the path exists, and false otherwise [1]. Because the method checks for the existence of the path in the file system, it does not distinguish between files and directories in its return value; if the path is found, it evaluates to true. Note that while fs.existsSync is not deprecated, it is often recommended to avoid checking for file existence before performing operations (like reading or writing) to prevent race conditions. Instead, you should perform the desired operation directly and handle any errors that occur if the file is inaccessible [2][3].
Citations:
Require a regular SQLite database file before skipping bootstrap.
When
openclaw-agent.sqliteis a directory,existsSync(sqlitePath)is true, soinjectAuthProfileremoves the placeholder and skips legacy JSON bootstrap. UsestatSync(sqlitePath).isFile()and add a Vitest regression test for this state.🤖 Prompt for AI Agents
Source: Coding guidelines