refactor(test): dedupe setup wizard test helpers

This commit is contained in:
Peter Steinberger
2026-03-21 23:29:02 +00:00
parent 6266b842d4
commit 57fa59ab92
13 changed files with 222 additions and 271 deletions

View File

@@ -62,6 +62,12 @@ function createDeferred() {
describe("FileBackedMatrixSyncStore", () => {
const tempDirs: string[] = [];
function createStoragePath(): string {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-matrix-sync-store-"));
tempDirs.push(tempDir);
return path.join(tempDir, "bot-storage.json");
}
afterEach(() => {
vi.restoreAllMocks();
vi.useRealTimers();
@@ -71,9 +77,7 @@ describe("FileBackedMatrixSyncStore", () => {
});
it("persists sync data so restart resumes from the saved cursor", async () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-matrix-sync-store-"));
tempDirs.push(tempDir);
const storagePath = path.join(tempDir, "bot-storage.json");
const storagePath = createStoragePath();
const firstStore = new FileBackedMatrixSyncStore(storagePath);
expect(firstStore.hasSavedSync()).toBe(false);
@@ -97,9 +101,7 @@ describe("FileBackedMatrixSyncStore", () => {
});
it("only treats sync state as restart-safe after a clean shutdown persist", async () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-matrix-sync-store-"));
tempDirs.push(tempDir);
const storagePath = path.join(tempDir, "bot-storage.json");
const storagePath = createStoragePath();
const firstStore = new FileBackedMatrixSyncStore(storagePath);
await firstStore.setSyncData(createSyncResponse("s123"));
@@ -118,9 +120,7 @@ describe("FileBackedMatrixSyncStore", () => {
});
it("clears the clean-shutdown marker once fresh sync data arrives", async () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-matrix-sync-store-"));
tempDirs.push(tempDir);
const storagePath = path.join(tempDir, "bot-storage.json");
const storagePath = createStoragePath();
const firstStore = new FileBackedMatrixSyncStore(storagePath);
await firstStore.setSyncData(createSyncResponse("s123"));
@@ -141,9 +141,7 @@ describe("FileBackedMatrixSyncStore", () => {
it("coalesces background persistence until the debounce window elapses", async () => {
vi.useFakeTimers();
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-matrix-sync-store-"));
tempDirs.push(tempDir);
const storagePath = path.join(tempDir, "bot-storage.json");
const storagePath = createStoragePath();
const writeSpy = vi.spyOn(jsonFiles, "writeJsonAtomic").mockResolvedValue();
const store = new FileBackedMatrixSyncStore(storagePath);
@@ -174,9 +172,7 @@ describe("FileBackedMatrixSyncStore", () => {
it("waits for an in-flight persist when shutdown flush runs", async () => {
vi.useFakeTimers();
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-matrix-sync-store-"));
tempDirs.push(tempDir);
const storagePath = path.join(tempDir, "bot-storage.json");
const storagePath = createStoragePath();
const writeDeferred = createDeferred();
const writeSpy = vi
.spyOn(jsonFiles, "writeJsonAtomic")
@@ -201,9 +197,7 @@ describe("FileBackedMatrixSyncStore", () => {
});
it("persists client options alongside sync state", async () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-matrix-sync-store-"));
tempDirs.push(tempDir);
const storagePath = path.join(tempDir, "bot-storage.json");
const storagePath = createStoragePath();
const firstStore = new FileBackedMatrixSyncStore(storagePath);
await firstStore.storeClientOptions({ lazyLoadMembers: true });
@@ -214,9 +208,7 @@ describe("FileBackedMatrixSyncStore", () => {
});
it("loads legacy raw sync payloads from bot-storage.json", async () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-matrix-sync-store-"));
tempDirs.push(tempDir);
const storagePath = path.join(tempDir, "bot-storage.json");
const storagePath = createStoragePath();
fs.writeFileSync(
storagePath,