diff --git a/extensions/zalouser/src/zalo-js.credentials.test.ts b/extensions/zalouser/src/zalo-js.credentials.test.ts index 3172b085161..a7036010124 100644 --- a/extensions/zalouser/src/zalo-js.credentials.test.ts +++ b/extensions/zalouser/src/zalo-js.credentials.test.ts @@ -1,4 +1,14 @@ -import { lstat, mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from "node:fs/promises"; +import { + lstat, + mkdir, + mkdtemp, + readFile, + rm, + stat, + symlink, + utimes, + writeFile, +} from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import { withEnvAsync } from "openclaw/plugin-sdk/test-env"; @@ -7,7 +17,6 @@ import type { API, Credentials, LoginQRCallbackEvent } from "./zca-client.js"; import { LoginQRCallbackEventType } from "./zca-constants.js"; const createZaloMock = vi.hoisted(() => vi.fn()); -const TEST_MTIME_TICK_MS = 20; const ISO_TIMESTAMP_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/u; vi.mock("./zca-client.js", () => ({ @@ -51,10 +60,6 @@ async function readStoredCredentials( ) as StoredCredentialFile; } -async function waitForMtimeTick(): Promise { - await new Promise((resolve) => setTimeout(resolve, TEST_MTIME_TICK_MS)); -} - function createMockApi(params: { imei: string; userAgent: string; @@ -308,10 +313,11 @@ describe("zalouser credential persistence", () => { await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => { await expect(listZaloFriends(profile)).resolves.toEqual([]); const firstRaw = await readFile(filePath, "utf8"); + const stableMtime = new Date("2026-04-01T00:00:10.000Z"); + await utimes(filePath, stableMtime, stableMtime); const firstMtimeMs = (await stat(filePath)).mtimeMs; currentCookie = cookieB; - await waitForMtimeTick(); await expect(listZaloFriends(profile)).resolves.toEqual([]); expect(await readFile(filePath, "utf8")).toBe(firstRaw);