Skip to content

Commit 7b49f57

Browse files
authored
fix(test): zalouser credential and doctor suites fail Windows teardown with EBUSY (#119964)
Three zalouser fixtures remove their temporary state directory while SQLite handles opened under it are still live, so on Windows the removal fails with EBUSY and the whole suite is reported as failed. doctor-contract-api already resets the plugin state store, but that helper only releases plugin state plus shared state and leaves the cached per-agent databases open, which is the handle its migrations create. The credential and quote-metadata fixtures never released the shared state database at all.
1 parent f33a88b commit 7b49f57

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

‎extensions/zalouser/doctor-contract-api.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
normalizeSessionDeliveryState,
1818
upsertSessionEntry,
1919
} from "openclaw/plugin-sdk/session-store-runtime";
20+
import { closeOpenClawAgentDatabasesForTest } from "openclaw/plugin-sdk/sqlite-runtime-testing";
2021
import { afterEach, beforeEach, describe, expect, it } from "vitest";
2122
import { stateMigrations } from "./doctor-contract-api.js";
2223
import { setZalouserRuntime } from "./src/runtime.js";
@@ -61,6 +62,10 @@ describe("zalouser doctor state migration", () => {
6162
});
6263

6364
afterEach(async () => {
65+
// Session migrations open per-agent databases under the temporary state dir, and
66+
// resetPluginStateStoreForTests only releases plugin state plus shared state, so the
67+
// cached agent handles must be closed here or Windows fails the removal with EBUSY.
68+
closeOpenClawAgentDatabasesForTest();
6469
resetPluginStateStoreForTests();
6570
await fs.rm(stateDir, { recursive: true, force: true });
6671
});

‎extensions/zalouser/src/zalo-js.credentials.test.ts‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ function seedStoredCredentials(
5959
saveStoredZaloCredentials(profile, credentials, { OPENCLAW_STATE_DIR: stateDir });
6060
}
6161

62+
// Credential reads and writes leave the shared state database open under the temporary
63+
// state dir, so it must be released before removal or Windows keeps the files locked and
64+
// the removal fails with EBUSY.
65+
async function removeCredentialStateDir(stateDir: string): Promise<void> {
66+
resetPluginStateStoreForTests();
67+
await rm(stateDir, { recursive: true, force: true });
68+
}
69+
6270
function createMockApi(params: {
6371
imei: string;
6472
userAgent: string;
@@ -127,7 +135,7 @@ describe("zalouser credential persistence", () => {
127135
).toBe(false);
128136
expect(loadStoredZaloCredentials(profile, env)).toBeNull();
129137
} finally {
130-
await rm(stateDir, { recursive: true, force: true });
138+
await removeCredentialStateDir(stateDir);
131139
}
132140
});
133141

@@ -184,7 +192,7 @@ describe("zalouser credential persistence", () => {
184192
expect(stored.cookie).toEqual(refreshedCookie);
185193
});
186194
} finally {
187-
await rm(stateDir, { recursive: true, force: true });
195+
await removeCredentialStateDir(stateDir);
188196
}
189197
});
190198

@@ -233,7 +241,7 @@ describe("zalouser credential persistence", () => {
233241
expect(loadStoredZaloCredentials(profile)).toBeNull();
234242
});
235243
} finally {
236-
await rm(stateDir, { recursive: true, force: true });
244+
await removeCredentialStateDir(stateDir);
237245
}
238246
});
239247

@@ -304,7 +312,7 @@ describe("zalouser credential persistence", () => {
304312
expect(stored.lastUsedAt).toMatch(ISO_TIMESTAMP_RE);
305313
});
306314
} finally {
307-
await rm(stateDir, { recursive: true, force: true });
315+
await removeCredentialStateDir(stateDir);
308316
}
309317
});
310318

@@ -344,7 +352,7 @@ describe("zalouser credential persistence", () => {
344352
expect(await readStoredCredentials(stateDir, profile)).toEqual(storedBefore);
345353
});
346354
} finally {
347-
await rm(stateDir, { recursive: true, force: true });
355+
await removeCredentialStateDir(stateDir);
348356
}
349357
});
350358

@@ -400,7 +408,7 @@ describe("zalouser credential persistence", () => {
400408
expect(stored.lastUsedAt).toMatch(ISO_TIMESTAMP_RE);
401409
});
402410
} finally {
403-
await rm(stateDir, { recursive: true, force: true });
411+
await removeCredentialStateDir(stateDir);
404412
}
405413
});
406414

@@ -440,7 +448,7 @@ describe("zalouser credential persistence", () => {
440448
expect(await readStoredCredentials(stateDir, profile)).toEqual(firstStored);
441449
});
442450
} finally {
443-
await rm(stateDir, { recursive: true, force: true });
451+
await removeCredentialStateDir(stateDir);
444452
}
445453
});
446454

@@ -464,7 +472,7 @@ describe("zalouser credential persistence", () => {
464472
expectMissingSessionResult(result);
465473
});
466474
} finally {
467-
await rm(stateDir, { recursive: true, force: true });
475+
await removeCredentialStateDir(stateDir);
468476
}
469477
});
470478

@@ -479,7 +487,7 @@ describe("zalouser credential persistence", () => {
479487
expectMissingSessionResult(result);
480488
});
481489
} finally {
482-
await rm(stateDir, { recursive: true, force: true });
490+
await removeCredentialStateDir(stateDir);
483491
}
484492
});
485493

@@ -501,7 +509,7 @@ describe("zalouser credential persistence", () => {
501509
access(path.join(stateDir, "state", "openclaw.sqlite")),
502510
).resolves.toBeUndefined();
503511
} finally {
504-
await rm(stateDir, { recursive: true, force: true });
512+
await removeCredentialStateDir(stateDir);
505513
}
506514
});
507515
});

‎extensions/zalouser/src/zalo-quote-metadata.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ async function withStoredSession<T>(params: {
7272
try {
7373
return await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, params.run);
7474
} finally {
75+
// Listener and send paths leave the shared state database open under the temporary
76+
// state dir, so it must be released before removal or Windows keeps the files locked
77+
// and the removal fails with EBUSY.
78+
resetPluginStateStoreForTests();
7579
await rm(stateDir, { recursive: true, force: true });
7680
}
7781
}

0 commit comments

Comments
 (0)