mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:20:44 +00:00
test: share auth profile env fixture
This commit is contained in:
@@ -28,14 +28,14 @@ async function loadFreshAuthProfilesModuleForTest() {
|
|||||||
await import("./auth-profiles.js"));
|
await import("./auth-profiles.js"));
|
||||||
}
|
}
|
||||||
|
|
||||||
function withAgentDirEnv(prefix: string, run: (agentDir: string) => void | Promise<void>) {
|
async function withAgentDirEnv(prefix: string, run: (agentDir: string) => void | Promise<void>) {
|
||||||
const agentDir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
const agentDir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
||||||
const previousAgentDir = process.env.OPENCLAW_AGENT_DIR;
|
const previousAgentDir = process.env.OPENCLAW_AGENT_DIR;
|
||||||
const previousPiAgentDir = process.env.PI_CODING_AGENT_DIR;
|
const previousPiAgentDir = process.env.PI_CODING_AGENT_DIR;
|
||||||
try {
|
try {
|
||||||
process.env.OPENCLAW_AGENT_DIR = agentDir;
|
process.env.OPENCLAW_AGENT_DIR = agentDir;
|
||||||
process.env.PI_CODING_AGENT_DIR = agentDir;
|
process.env.PI_CODING_AGENT_DIR = agentDir;
|
||||||
return run(agentDir);
|
await run(agentDir);
|
||||||
} finally {
|
} finally {
|
||||||
if (previousAgentDir === undefined) {
|
if (previousAgentDir === undefined) {
|
||||||
delete process.env.OPENCLAW_AGENT_DIR;
|
delete process.env.OPENCLAW_AGENT_DIR;
|
||||||
@@ -132,31 +132,14 @@ describe("auth profile store cache", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps runtime-only external auth out of persisted auth-profiles.json files", () => {
|
it("keeps runtime-only external auth out of persisted auth-profiles.json files", async () => {
|
||||||
const agentDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-auth-store-missing-"));
|
|
||||||
const previousAgentDir = process.env.OPENCLAW_AGENT_DIR;
|
|
||||||
const previousPiAgentDir = process.env.PI_CODING_AGENT_DIR;
|
|
||||||
mocks.resolveExternalCliAuthProfiles.mockReturnValue([createRuntimeOnlyOverlay("access-1")]);
|
mocks.resolveExternalCliAuthProfiles.mockReturnValue([createRuntimeOnlyOverlay("access-1")]);
|
||||||
try {
|
|
||||||
process.env.OPENCLAW_AGENT_DIR = agentDir;
|
|
||||||
process.env.PI_CODING_AGENT_DIR = agentDir;
|
|
||||||
|
|
||||||
|
await withAgentDirEnv("openclaw-auth-store-missing-", (agentDir) => {
|
||||||
const store = ensureAuthProfileStore(agentDir);
|
const store = ensureAuthProfileStore(agentDir);
|
||||||
|
|
||||||
expect(store.profiles["openai-codex:default"]).toMatchObject({ access: "access-1" });
|
expect(store.profiles["openai-codex:default"]).toMatchObject({ access: "access-1" });
|
||||||
expect(fs.existsSync(path.join(agentDir, "auth-profiles.json"))).toBe(false);
|
expect(fs.existsSync(path.join(agentDir, "auth-profiles.json"))).toBe(false);
|
||||||
} finally {
|
});
|
||||||
if (previousAgentDir === undefined) {
|
|
||||||
delete process.env.OPENCLAW_AGENT_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.OPENCLAW_AGENT_DIR = previousAgentDir;
|
|
||||||
}
|
|
||||||
if (previousPiAgentDir === undefined) {
|
|
||||||
delete process.env.PI_CODING_AGENT_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.PI_CODING_AGENT_DIR = previousPiAgentDir;
|
|
||||||
}
|
|
||||||
fs.rmSync(agentDir, { recursive: true, force: true });
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user