Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/cli/src/browser/manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,15 +411,30 @@ describe("findBrowser — cache resolution", () => {
});

it("withInstallLock reports progress while waiting instead of staying silent", async () => {
// Fake timers freeze Date.now() so the lock mtime stays non-stale across
// the dynamic import that follows — without them, a slow import beat could
// push wall-clock past staleMs before `withInstallLock` even starts polling,
// firing the immediate-stale short-circuit and skipping the wait-notice
// branch this test exists to observe.
vi.useFakeTimers();
const paths = installFsMocks({
existing: new Set([CACHE_ROOT, HF_LOCK]),
initialMtimeMs: Date.now(),
});
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});

const { withInstallLock } = await import("./manager.js");
await withInstallLock(async () => "done", { ...TEST_LOCK_TIMINGS, waitNoticeMs: 20 });
const acquisition = withInstallLock(async () => "done", {
...TEST_LOCK_TIMINGS,
waitNoticeMs: 20,
});

// Advance past waitNoticeMs (fires the "Waiting for…" warn), then past
// staleMs (lets `reclaimStaleInstallLock` clear the held lock so the
// acquisition resolves).
await vi.advanceTimersByTimeAsync(TEST_LOCK_TIMINGS.staleMs + TEST_LOCK_TIMINGS.pollMs * 5);

await expect(acquisition).resolves.toBe("done");
expect(paths.has(HF_LOCK)).toBe(false);
expect(
warnSpy.mock.calls.some(([msg]) =>
Expand Down
Loading