mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 00:58:28 +00:00
refactor(test): snapshot deprecated auth profile env in e2e
This commit is contained in:
@@ -3,11 +3,11 @@ import os from "node:os";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import type { OpenClawConfig } from "../config/config.js";
|
import type { OpenClawConfig } from "../config/config.js";
|
||||||
|
import { captureEnv } from "../test-utils/env.js";
|
||||||
import { maybeRemoveDeprecatedCliAuthProfiles } from "./doctor-auth.js";
|
import { maybeRemoveDeprecatedCliAuthProfiles } from "./doctor-auth.js";
|
||||||
import type { DoctorPrompter } from "./doctor-prompter.js";
|
import type { DoctorPrompter } from "./doctor-prompter.js";
|
||||||
|
|
||||||
let originalAgentDir: string | undefined;
|
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||||
let originalPiAgentDir: string | undefined;
|
|
||||||
let tempAgentDir: string | undefined;
|
let tempAgentDir: string | undefined;
|
||||||
|
|
||||||
function makePrompter(confirmValue: boolean): DoctorPrompter {
|
function makePrompter(confirmValue: boolean): DoctorPrompter {
|
||||||
@@ -23,24 +23,14 @@ function makePrompter(confirmValue: boolean): DoctorPrompter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
originalAgentDir = process.env.OPENCLAW_AGENT_DIR;
|
envSnapshot = captureEnv(["OPENCLAW_AGENT_DIR", "PI_CODING_AGENT_DIR"]);
|
||||||
originalPiAgentDir = process.env.PI_CODING_AGENT_DIR;
|
|
||||||
tempAgentDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-auth-"));
|
tempAgentDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-auth-"));
|
||||||
process.env.OPENCLAW_AGENT_DIR = tempAgentDir;
|
process.env.OPENCLAW_AGENT_DIR = tempAgentDir;
|
||||||
process.env.PI_CODING_AGENT_DIR = tempAgentDir;
|
process.env.PI_CODING_AGENT_DIR = tempAgentDir;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
if (originalAgentDir === undefined) {
|
envSnapshot.restore();
|
||||||
delete process.env.OPENCLAW_AGENT_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.OPENCLAW_AGENT_DIR = originalAgentDir;
|
|
||||||
}
|
|
||||||
if (originalPiAgentDir === undefined) {
|
|
||||||
delete process.env.PI_CODING_AGENT_DIR;
|
|
||||||
} else {
|
|
||||||
process.env.PI_CODING_AGENT_DIR = originalPiAgentDir;
|
|
||||||
}
|
|
||||||
if (tempAgentDir) {
|
if (tempAgentDir) {
|
||||||
fs.rmSync(tempAgentDir, { recursive: true, force: true });
|
fs.rmSync(tempAgentDir, { recursive: true, force: true });
|
||||||
tempAgentDir = undefined;
|
tempAgentDir = undefined;
|
||||||
|
|||||||
Reference in New Issue
Block a user