



























@@ -11,16 +11,6 @@ let resetSessionWriteLockStateForTest: typeof import("./session-write-lock.js").
1111let resolveSessionLockMaxHoldFromTimeout: typeof import("./session-write-lock.js").resolveSessionLockMaxHoldFromTimeout;
1212let resolveSessionWriteLockAcquireTimeoutMs: typeof import("./session-write-lock.js").resolveSessionWriteLockAcquireTimeoutMs;
131314-vi.mock("../shared/pid-alive.js", async () => {
15-const original =
16-await vi.importActual<typeof import("../shared/pid-alive.js")>("../shared/pid-alive.js");
17-return {
18- ...original,
19-// Keep liveness checks real; only pin process start time for PID recycle coverage.
20-getProcessStartTime: (pid: number) => (pid === process.pid ? FAKE_STARTTIME : null),
21-};
22-});
23-2414async function expectLockRemovedOnlyAfterFinalRelease(params: {
2515lockPath: string;
2616firstLock: { release: () => Promise<void> };
@@ -142,6 +132,12 @@ describe("acquireSessionWriteLock", () => {
142132resetSessionWriteLockStateForTest();
143133vi.clearAllMocks();
144134});
135+136+function pinCurrentProcessStartTimeForTest(): void {
137+__testing.setProcessStartTimeResolverForTest((pid) =>
138+pid === process.pid ? FAKE_STARTTIME : null,
139+);
140+}
145141it("reuses locks across symlinked session paths", async () => {
146142await withSymlinkedSessionPaths(
147143async ({ sessionReal, sessionLink, realLockPath, linkLockPath }) => {
@@ -418,6 +414,7 @@ describe("acquireSessionWriteLock", () => {
418414});
419415420416it("cleans untracked current-process .jsonl lock files with matching starttime", async () => {
417+pinCurrentProcessStartTimeForTest();
421418const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-lock-"));
422419const sessionsDir = path.join(root, "sessions");
423420await fs.mkdir(sessionsDir, { recursive: true });
@@ -490,6 +487,7 @@ describe("acquireSessionWriteLock", () => {
490487return;
491488}
492489await withTempSessionLockFile(async ({ sessionFile, lockPath }) => {
490+pinCurrentProcessStartTimeForTest();
493491// Write a lock with a live PID (current process) but a wrong starttime,
494492// simulating PID recycling: the PID is alive but belongs to a different
495493// process than the one that created the lock.
@@ -511,6 +509,7 @@ describe("acquireSessionWriteLock", () => {
511509512510it("reclaims untracked current-process lock files with matching starttime", async () => {
513511await withTempSessionLockFile(async ({ sessionFile, lockPath }) => {
512+pinCurrentProcessStartTimeForTest();
514513await writeCurrentProcessLock(lockPath, { starttime: FAKE_STARTTIME });
515514516515await expectCurrentPidOwnsLock({ sessionFile, timeoutMs: 500 });
@@ -526,6 +525,7 @@ describe("acquireSessionWriteLock", () => {
526525});
527526528527it("does not reclaim active in-process lock files with matching starttime", async () => {
528+pinCurrentProcessStartTimeForTest();
529529await expectActiveInProcessLockIsNotReclaimed({ legacyStarttime: FAKE_STARTTIME });
530530});
531531此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。