Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(ci): stabilize teardown and rotation tests

Genercf0ffc777dcc
diff --git a/src/daemon/src/util/rotatingFileSink.test.ts b/src/daemon/src/util/rotatingFileSink.test.ts
index d0db30682..8f17ea452 100644
--- a/src/daemon/src/util/rotatingFileSink.test.ts
+++ b/src/daemon/src/util/rotatingFileSink.test.ts
@@ -36,15 +36,14 @@ describe("createRotatingFileSink (batch E1 — bounded default trace backing)",
const path = join(dir, "trace.jsonl");
const maxBytes = 1000;
const sink = createRotatingFileSink(path, maxBytes);
- // Write far more than the cap: 500 lines × ~100 bytes = ~50KB, cap is 1KB.
- const line = "x".repeat(99); // ~100 bytes with newline
- for (let i = 0; i < 500; i++) sink.write(line);
+ const line = "x".repeat(499);
+ for (let i = 0; i < 20; i++) sink.write(line);
const active = existsSync(path) ? statSync(path).size : 0;
const rotated = existsSync(`${path}.1`) ? statSync(`${path}.1`).size : 0;
// Total bounded by ~2×maxBytes + one line's slack (a write can push the
// active file slightly past maxBytes before the NEXT write rotates it).
- expect(active + rotated).toBeLessThanOrEqual(2 * maxBytes + 200);
+ expect(active + rotated).toBeLessThanOrEqual(2 * maxBytes + line.length + 1);
// And it kept SOMETHING (didn't just delete everything).
expect(active + rotated).toBeGreaterThan(0);
});
diff --git a/src/web/src/stores/community/index.test.ts b/src/web/src/stores/community/index.test.ts
index 2902e639f..3a06e5c08 100644
--- a/src/web/src/stores/community/index.test.ts
+++ b/src/web/src/stores/community/index.test.ts
@@ -12,14 +12,9 @@ vi.mock("@/lib/community/pending-reads", () => ({
flushPendingReads: flushPendingReadsSpy,
}))
-// Each test starts from a clean slate — otherwise Zustand's module-scoped
-// store would leak state (and lingering timers) between cases. `reset()`
-// schedules a dynamic-imported flush via a microtask; wait until the spy
-// fires before clearing it — otherwise the pending callback would bleed
-// into the next test's count.
-beforeEach(async () => {
+beforeEach(() => {
useCommunityStore.getState().reset()
- await vi.waitFor(() => expect(flushPendingReadsSpy).toHaveBeenCalled())
+ expect(flushPendingReadsSpy).toHaveBeenCalled()
flushPendingReadsSpy.mockClear()
})
@@ -123,12 +118,9 @@ describe("useCommunityStore", () => {
expect(useCommunityStore.getState().uiHandlers.openProfile).toBe(openProfile)
})
- it("reset flushes pending mark-reads before wiping state", async () => {
- // `reset()` uses a dynamic import so store initialization does not load
- // the queue implementation eagerly. Poll instead of assuming a fixed
- // microtask count.
+ it("reset flushes pending mark-reads before returning", () => {
useCommunityStore.getState().reset()
- await vi.waitFor(() => expect(flushPendingReadsSpy).toHaveBeenCalledTimes(1))
+ expect(flushPendingReadsSpy).toHaveBeenCalledTimes(1)
})
it("reset clears every field including timer maps", () => {
diff --git a/src/web/src/stores/community/index.ts b/src/web/src/stores/community/index.ts
index 9d4366a3a..07b7cb5ce 100644
--- a/src/web/src/stores/community/index.ts
+++ b/src/web/src/stores/community/index.ts
@@ -4,6 +4,7 @@ import { create } from "zustand"
import { useShallow } from "zustand/react/shallow"
import type React from "react"
import type { FileAttachment, ImagePreview } from "@/lib/community/models/message"
+import { flushPendingReads } from "@/lib/community/pending-reads"
/**
* Zustand store for community client-only state.
@@ -242,14 +243,7 @@ export const useCommunityStore = create<CommunityStoreState>((set, get) => ({
set({ uiHandlers: { ...get().uiHandlers, ...handlers } }),
reset: () => {
- // Flush any pending mark-channel-read PUTs before we wipe local state so
- // the last-read pointer isn't stranded in the 500ms debounce window
- // (sign-out, hard-reset, tab close). Dynamic import avoids coupling the
- // store to the mutation hooks that consume this queue. Fire-and-forget is
- // fine — the PUTs go out under the still-live auth cookie.
- void import("@/lib/community/pending-reads").then((module) =>
- module.flushPendingReads(),
- )
+ flushPendingReads()
// Fire-and-forget: clear every outstanding timer so nothing lingers past
// sign-out or a hard-reset.
const { typingTimers, reactionTimers } = get()