From 6d45db1e08fdc996731813209133e5dec80883ce Mon Sep 17 00:00:00 2001 From: iamtoruk Date: Sat, 12 Sep 2026 05:50:41 -0700 Subject: [PATCH] fix(app): re-read the project filter when it changes outside the window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The main process re-reads app-filter.json whenever the file changes, which is what makes a hand edit land. The renderer only re-read it on its own config mutations, so a filter that appeared any other way left `projectFiltered` false: Settings kept offering Combined, the hero kept saying "Combined · …", and buildOverviewArgs had already dropped `--scope combined` because the filter was non-empty. The reading on screen was a local, project-filtered total labelled as the combined one. Re-read on a manual refresh and on every overview poll as well. It costs one statSync the main process already memoizes by stat stamp. --- app/renderer/App.test.tsx | 15 +++++++++++++++ app/renderer/App.tsx | 9 +++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/renderer/App.test.tsx b/app/renderer/App.test.tsx index a5365880..67dee182 100644 --- a/app/renderer/App.test.tsx +++ b/app/renderer/App.test.tsx @@ -493,6 +493,21 @@ describe('App shortcuts', () => { await waitFor(() => expect(localStorage.getItem('codeburn.scope')).toBe('local')) }) + // app-filter.json is read by the main process on every fetch, so a hand edit + // lands there at once. A renderer that only re-read on its own saves kept + // Combined on screen over argv that had already dropped `--scope combined`. + it('collapses combined scope when the filter appears outside the app', async () => { + localStorage.setItem('codeburn.scope', 'combined') + localStorage.setItem('codeburn.projectFiltered', '0') + mocks.getProjectFilter.mockResolvedValueOnce({ project: [], exclude: [] }) + mocks.getProjectFilter.mockResolvedValue({ project: [], exclude: ['my-company'] }) + mocks.getOverview.mockResolvedValue(overviewPayload()) + render() + await waitFor(() => expect(mocks.getOverview).toHaveBeenCalledWith('30days', 'all', undefined, undefined, undefined, 'combined')) + await waitFor(() => expect(localStorage.getItem('codeburn.scope')).toBe('local')) + await waitFor(() => expect(localStorage.getItem('codeburn.projectFiltered')).toBe('1')) + }) + it('records the filter for the next boot when the pane is empty', async () => { render() await waitFor(() => expect(localStorage.getItem('codeburn.projectFiltered')).toBe('0')) diff --git a/app/renderer/App.tsx b/app/renderer/App.tsx index 72a3938e..0ddd1fbf 100644 --- a/app/renderer/App.tsx +++ b/app/renderer/App.tsx @@ -686,7 +686,12 @@ function AppMain() { setProvider(value) } - // Re-read on config invalidation: another window can save the pane too. + // Re-read on config invalidation (another window can save the pane too), on a + // manual refresh, and on every overview poll. The main process honours a hand + // edit of app-filter.json the moment the file changes, so a renderer that only + // re-read on its own saves kept offering Combined while buildOverviewArgs had + // already dropped `--scope combined` — a local, filtered total under a + // "Combined · …" headline, which is the one reading the pane must never give. useEffect(() => { let cancelled = false void Promise.resolve().then(() => codeburn.getProjectFilter()) @@ -698,7 +703,7 @@ function AppMain() { }) .catch(() => { /* an older preload has no getProjectFilter to honour */ }) return () => { cancelled = true } - }, [snapshotRevision]) + }, [snapshotRevision, refreshToken, overview.data]) // Collapse the stored preference too, so clearing the filter later starts // from local instead of silently restoring a combined view.