Skip to content

Commit 7097813

Browse files
only21milclaude
andcommitted
test(web): cover the prompt stash cross-tab storage listener
A matching key or a null key (another tab's clear()) refreshes the list; an unrelated key leaves it alone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3bee846 commit 7097813

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

‎apps/web/src/promptStashStore.test.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,34 @@ describe("promptStashStore", () => {
199199
]);
200200
});
201201

202+
it("refreshes on another tab's stash write or clear, ignoring other keys", async () => {
203+
const shared = stubSharedStorage();
204+
const tabWindow = new EventTarget();
205+
vi.stubGlobal("window", tabWindow);
206+
try {
207+
const tab = (await importTab()).usePromptStashStore;
208+
const dispatchStorage = (key: string | null) =>
209+
tabWindow.dispatchEvent(Object.assign(new Event("storage"), { key }));
210+
shared.stored.set(
211+
PROMPT_STASH_STORAGE_KEY,
212+
JSON.stringify({ version: 2, state: { entries: [makeEntry({ id: "other-tab" })] } }),
213+
);
214+
215+
dispatchStorage("t3code:unrelated");
216+
expect(tab.getState().entries).toEqual([]);
217+
218+
dispatchStorage(PROMPT_STASH_STORAGE_KEY);
219+
expect(tab.getState().entries.map((entry) => entry.id)).toEqual(["other-tab"]);
220+
221+
// localStorage.clear() in another tab reports a null key.
222+
shared.stored.clear();
223+
dispatchStorage(null);
224+
expect(tab.getState().entries).toEqual([]);
225+
} finally {
226+
vi.unstubAllGlobals();
227+
}
228+
});
229+
202230
// regression: #4787 stashed prompts were lost when switching providers
203231
it("distinguishes a memory-only write (written, not durable) from a failed one", () => {
204232
const store = usePromptStashStore.getState();

0 commit comments

Comments
 (0)