mirror of https://github.com/openclaw/openclaw.git
test: isolate OPENCLAW_HOME in withTempHome
This commit is contained in:
parent
a2b6a064f7
commit
d6641ed306
|
|
@ -9,6 +9,7 @@ type EnvSnapshot = {
|
|||
userProfile: string | undefined;
|
||||
homeDrive: string | undefined;
|
||||
homePath: string | undefined;
|
||||
openclawHome: string | undefined;
|
||||
stateDir: string | undefined;
|
||||
};
|
||||
|
||||
|
|
@ -18,6 +19,7 @@ function snapshotEnv(): EnvSnapshot {
|
|||
userProfile: process.env.USERPROFILE,
|
||||
homeDrive: process.env.HOMEDRIVE,
|
||||
homePath: process.env.HOMEPATH,
|
||||
openclawHome: process.env.OPENCLAW_HOME,
|
||||
stateDir: process.env.OPENCLAW_STATE_DIR,
|
||||
};
|
||||
}
|
||||
|
|
@ -34,6 +36,7 @@ function restoreEnv(snapshot: EnvSnapshot) {
|
|||
restoreKey("USERPROFILE", snapshot.userProfile);
|
||||
restoreKey("HOMEDRIVE", snapshot.homeDrive);
|
||||
restoreKey("HOMEPATH", snapshot.homePath);
|
||||
restoreKey("OPENCLAW_HOME", snapshot.openclawHome);
|
||||
restoreKey("OPENCLAW_STATE_DIR", snapshot.stateDir);
|
||||
}
|
||||
|
||||
|
|
@ -58,6 +61,8 @@ function restoreExtraEnv(snapshot: Record<string, string | undefined>) {
|
|||
function setTempHome(base: string) {
|
||||
process.env.HOME = base;
|
||||
process.env.USERPROFILE = base;
|
||||
// Ensure tests using HOME isolation aren't affected by leaked OPENCLAW_HOME.
|
||||
delete process.env.OPENCLAW_HOME;
|
||||
process.env.OPENCLAW_STATE_DIR = path.join(base, ".openclaw");
|
||||
|
||||
if (process.platform !== "win32") {
|
||||
|
|
|
|||
Loading…
Reference in New Issue