test: ignore stale isolated state dir in live env staging

This commit is contained in:
Gustavo Madeira Santana 2026-03-28 20:34:41 -04:00
parent 0e0945c5ed
commit 225d58b74a
No known key found for this signature in database
2 changed files with 16 additions and 2 deletions

View File

@ -50,6 +50,7 @@ afterEach(() => {
describe("installTestEnv", () => {
it("keeps live tests on a temp HOME while copying config and auth state", () => {
const realHome = createTempHome();
const priorIsolatedHome = createTempHome();
writeFile(path.join(realHome, ".profile"), "export TEST_PROFILE_ONLY=from-profile\n");
writeFile(
path.join(realHome, "custom-openclaw.json5"),
@ -87,6 +88,8 @@ describe("installTestEnv", () => {
process.env.OPENCLAW_LIVE_TEST = "1";
process.env.OPENCLAW_LIVE_TEST_QUIET = "1";
process.env.OPENCLAW_CONFIG_PATH = "~/custom-openclaw.json5";
process.env.OPENCLAW_TEST_HOME = priorIsolatedHome;
process.env.OPENCLAW_STATE_DIR = path.join(priorIsolatedHome, ".openclaw");
const testEnv = installTestEnv();
cleanupFns.push(testEnv.cleanup);

View File

@ -277,9 +277,20 @@ function stageLiveTestState(params: {
realHome: string;
tempHome: string;
}): void {
const realStateDir = params.env.OPENCLAW_STATE_DIR?.trim()
? resolveHomeRelativePath(params.env.OPENCLAW_STATE_DIR, params.realHome)
const rawStateDir = params.env.OPENCLAW_STATE_DIR?.trim();
let realStateDir = rawStateDir
? resolveHomeRelativePath(rawStateDir, params.realHome)
: path.join(params.realHome, ".openclaw");
const priorIsolatedHome = params.env.OPENCLAW_TEST_HOME?.trim();
const snapshotHome = params.env.HOME?.trim();
if (
priorIsolatedHome &&
snapshotHome &&
snapshotHome !== priorIsolatedHome &&
realStateDir === path.join(priorIsolatedHome, ".openclaw")
) {
realStateDir = path.join(params.realHome, ".openclaw");
}
const tempStateDir = path.join(params.tempHome, ".openclaw");
fs.mkdirSync(tempStateDir, { recursive: true });