mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 11:11:23 +00:00
refactor(test): dedupe onboard auth env cleanup
This commit is contained in:
@@ -4,6 +4,7 @@ import path from "node:path";
|
|||||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||||
import type { RuntimeEnv } from "../runtime.js";
|
import type { RuntimeEnv } from "../runtime.js";
|
||||||
import type { WizardPrompter } from "../wizard/prompts.js";
|
import type { WizardPrompter } from "../wizard/prompts.js";
|
||||||
|
import { captureEnv } from "../test-utils/env.js";
|
||||||
import { applyAuthChoice } from "./auth-choice.js";
|
import { applyAuthChoice } from "./auth-choice.js";
|
||||||
|
|
||||||
const noopAsync = async () => {};
|
const noopAsync = async () => {};
|
||||||
@@ -42,10 +43,12 @@ function createPrompter(overrides: Partial<WizardPrompter>): WizardPrompter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("applyAuthChoice (moonshot)", () => {
|
describe("applyAuthChoice (moonshot)", () => {
|
||||||
const previousStateDir = process.env.OPENCLAW_STATE_DIR;
|
const envSnapshot = captureEnv([
|
||||||
const previousAgentDir = process.env.OPENCLAW_AGENT_DIR;
|
"OPENCLAW_STATE_DIR",
|
||||||
const previousPiAgentDir = process.env.PI_CODING_AGENT_DIR;
|
"OPENCLAW_AGENT_DIR",
|
||||||
const previousMoonshotKey = process.env.MOONSHOT_API_KEY;
|
"PI_CODING_AGENT_DIR",
|
||||||
|
"MOONSHOT_API_KEY",
|
||||||
|
]);
|
||||||
let tempStateDir: string | null = null;
|
let tempStateDir: string | null = null;
|
||||||
|
|
||||||
async function setupTempState() {
|
async function setupTempState() {
|
||||||
@@ -61,26 +64,7 @@ describe("applyAuthChoice (moonshot)", () => {
|
|||||||
await fs.rm(tempStateDir, { recursive: true, force: true });
|
await fs.rm(tempStateDir, { recursive: true, force: true });
|
||||||
tempStateDir = null;
|
tempStateDir = null;
|
||||||
}
|
}
|
||||||
if (previousStateDir === undefined) {
|
envSnapshot.restore();
|
||||||
delete process.env.OPENCLAW_STATE_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.OPENCLAW_STATE_DIR = previousStateDir;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
if (previousMoonshotKey === undefined) {
|
|
||||||
delete process.env.MOONSHOT_API_KEY;
|
|
||||||
} else {
|
|
||||||
process.env.MOONSHOT_API_KEY = previousMoonshotKey;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps the .cn baseUrl when setDefaultModel is false", async () => {
|
it("keeps the .cn baseUrl when setDefaultModel is false", async () => {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
|
|||||||
import os from "node:os";
|
import os from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { afterEach, describe, expect, it } from "vitest";
|
import { afterEach, describe, expect, it } from "vitest";
|
||||||
|
import { captureEnv } from "../test-utils/env.js";
|
||||||
import {
|
import {
|
||||||
applyAuthProfileConfig,
|
applyAuthProfileConfig,
|
||||||
applyLitellmProviderConfig,
|
applyLitellmProviderConfig,
|
||||||
@@ -40,9 +41,12 @@ const requireAgentDir = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe("writeOAuthCredentials", () => {
|
describe("writeOAuthCredentials", () => {
|
||||||
const previousStateDir = process.env.OPENCLAW_STATE_DIR;
|
const envSnapshot = captureEnv([
|
||||||
const previousAgentDir = process.env.OPENCLAW_AGENT_DIR;
|
"OPENCLAW_STATE_DIR",
|
||||||
const previousPiAgentDir = process.env.PI_CODING_AGENT_DIR;
|
"OPENCLAW_AGENT_DIR",
|
||||||
|
"PI_CODING_AGENT_DIR",
|
||||||
|
"OPENCLAW_OAUTH_DIR",
|
||||||
|
]);
|
||||||
let tempStateDir: string | null = null;
|
let tempStateDir: string | null = null;
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
@@ -50,22 +54,7 @@ describe("writeOAuthCredentials", () => {
|
|||||||
await fs.rm(tempStateDir, { recursive: true, force: true });
|
await fs.rm(tempStateDir, { recursive: true, force: true });
|
||||||
tempStateDir = null;
|
tempStateDir = null;
|
||||||
}
|
}
|
||||||
if (previousStateDir === undefined) {
|
envSnapshot.restore();
|
||||||
delete process.env.OPENCLAW_STATE_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.OPENCLAW_STATE_DIR = previousStateDir;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
delete process.env.OPENCLAW_OAUTH_DIR;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("writes auth-profiles.json under OPENCLAW_AGENT_DIR when set", async () => {
|
it("writes auth-profiles.json under OPENCLAW_AGENT_DIR when set", async () => {
|
||||||
@@ -100,9 +89,11 @@ describe("writeOAuthCredentials", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("setMinimaxApiKey", () => {
|
describe("setMinimaxApiKey", () => {
|
||||||
const previousStateDir = process.env.OPENCLAW_STATE_DIR;
|
const envSnapshot = captureEnv([
|
||||||
const previousAgentDir = process.env.OPENCLAW_AGENT_DIR;
|
"OPENCLAW_STATE_DIR",
|
||||||
const previousPiAgentDir = process.env.PI_CODING_AGENT_DIR;
|
"OPENCLAW_AGENT_DIR",
|
||||||
|
"PI_CODING_AGENT_DIR",
|
||||||
|
]);
|
||||||
let tempStateDir: string | null = null;
|
let tempStateDir: string | null = null;
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
@@ -110,21 +101,7 @@ describe("setMinimaxApiKey", () => {
|
|||||||
await fs.rm(tempStateDir, { recursive: true, force: true });
|
await fs.rm(tempStateDir, { recursive: true, force: true });
|
||||||
tempStateDir = null;
|
tempStateDir = null;
|
||||||
}
|
}
|
||||||
if (previousStateDir === undefined) {
|
envSnapshot.restore();
|
||||||
delete process.env.OPENCLAW_STATE_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.OPENCLAW_STATE_DIR = previousStateDir;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("writes to OPENCLAW_AGENT_DIR when set", async () => {
|
it("writes to OPENCLAW_AGENT_DIR when set", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user