mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-11-29 10:43:47 +00:00
fix(app): list projects for the whole history, not the visible period
getUnfilteredProjects passed the period on screen, and the CLI builds that list from the days the period covers. A project filter has no period: it scopes every screen and every horizon at once. So an exclude pattern for a project with no activity in the current period rendered as "matches nothing detected" next to a Remove button, while the footer read "Nothing is hidden." Clicking Remove there unhid the project on every screen, from a control that had just called the pattern dead. The list is lifetime now, and the period argument is gone from the channel rather than left for a caller to get wrong. `all` is capped at six months, so lifetime is the only horizon that can answer for the whole filter. The pane's memo key goes through reportMemoKey like every other pane, and the fetch is off the poll interval: it is the heaviest read in the app, a toggle cannot change an unfiltered list, and the only thing that can is a project appearing, which the next open picks up.
This commit is contained in:
parent
1e34d36144
commit
f76ee91526
6 changed files with 64 additions and 13 deletions
|
|
@ -128,7 +128,7 @@ const ARGV_CASES: Array<{ channel: string; args: unknown[]; argv: string[] }> =
|
|||
{ channel: 'codeburn:getAudit', args: ['month', 'claude'], argv: ['audit', '--format', 'json', '--period', 'month', '--provider', 'claude'] },
|
||||
{ channel: 'codeburn:getAudit', args: ['30days', 'all', { from: '2026-07-01', to: '2026-07-11' }], argv: ['audit', '--format', 'json', '--period', '30days', '--from', '2026-07-01', '--to', '2026-07-11'] },
|
||||
{ channel: 'codeburn:getPriceOverrides', args: [], argv: ['price-override', '--list', '--format', 'json'] },
|
||||
{ channel: 'codeburn:getUnfilteredProjects', args: ['month'], argv: ['report', '--format', 'json', '--period', 'month'] },
|
||||
{ channel: 'codeburn:getUnfilteredProjects', args: [], argv: ['report', '--format', 'json', '--period', 'lifetime'] },
|
||||
{ channel: 'codeburn:setPriceOverride', args: ['unpriced/test-model', { input: 0.27, output: 1.1 }], argv: ['price-override', 'unpriced/test-model', '--input', '0.27', '--output', '1.1'] },
|
||||
{ channel: 'codeburn:setPriceOverride', args: ['unpriced/test-model', { input: 0.27, output: 1.1, cacheRead: 0.03, cacheCreation: 0.42 }], argv: ['price-override', 'unpriced/test-model', '--input', '0.27', '--output', '1.1', '--cache-read', '0.03', '--cache-creation', '0.42'] },
|
||||
{ channel: 'codeburn:removePriceOverride', args: ['unpriced/test-model'], argv: ['price-override', '--remove', 'unpriced/test-model'] },
|
||||
|
|
@ -832,8 +832,21 @@ describe('project filter', () => {
|
|||
writeProjectFilter({ project: [], exclude: ['my-company'] })
|
||||
const { spawnCli, spawnCliAction, calls } = fakeSpawn()
|
||||
const handlers = createBridgeHandlers(deps({ spawnCli, spawnCliAction, resolveCodeburnPath: () => '/bin/codeburn' }))
|
||||
await handlers['codeburn:getUnfilteredProjects']!('30days')
|
||||
expect(calls[0]).toEqual(['report', '--format', 'json', '--period', '30days'])
|
||||
await handlers['codeburn:getUnfilteredProjects']!()
|
||||
expect(calls[0]).toEqual(['report', '--format', 'json', '--period', 'lifetime'])
|
||||
})
|
||||
})
|
||||
|
||||
// A filter has no period: a pattern excluding a project that was last touched
|
||||
// months ago is live on every screen. Asking for anything narrower than
|
||||
// lifetime returns a list that pattern is missing from, and the pane reads
|
||||
// that absence as "this exclude matches nothing".
|
||||
it('asks for the whole history, never the period on screen', async () => {
|
||||
await withFilterFile(async () => {
|
||||
const { spawnCli, spawnCliAction, calls } = fakeSpawn()
|
||||
const handlers = createBridgeHandlers(deps({ spawnCli, spawnCliAction, resolveCodeburnPath: () => '/bin/codeburn' }))
|
||||
await handlers['codeburn:getUnfilteredProjects']!('today')
|
||||
expect(calls[0]).toEqual(['report', '--format', 'json', '--period', 'lifetime'])
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -584,7 +584,14 @@ export function createBridgeHandlers(deps: Deps = { spawnCli, spawnCliAction, re
|
|||
},
|
||||
// Deliberately NOT scoped by projectArgs(): the Projects pane builds its
|
||||
// checklist from this, so it has to see the projects the filter is hiding.
|
||||
'codeburn:getUnfilteredProjects': run((period: string) => ['report', '--format', 'json', '--period', vPeriod(period)]),
|
||||
//
|
||||
// Lifetime, and NOT the period on screen. A filter scopes every screen and
|
||||
// every horizon at once, so a list bounded to the visible period hides the
|
||||
// projects a pattern is actually excluding: the pane would print "matches
|
||||
// nothing detected" beside a live exclude, offer to remove it, and count it
|
||||
// out of "N projects hidden". `all` is capped at six months, so `lifetime`
|
||||
// is the only horizon that can answer for the whole filter.
|
||||
'codeburn:getUnfilteredProjects': run(() => ['report', '--format', 'json', '--period', 'lifetime']),
|
||||
'codeburn:setCurrency': runAction((code: string) => ['currency', vCurrency(code)]),
|
||||
'codeburn:resetCurrency': runAction(() => ['currency', '--reset']),
|
||||
'codeburn:addAlias': runAction((from: string, to: string) => ['model-alias', vToken(from), vToken(to)]),
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ const bridge = {
|
|||
getPriceOverrides: () => invoke('codeburn:getPriceOverrides'),
|
||||
getProjectFilter: () => invoke('codeburn:getProjectFilter'),
|
||||
setProjectFilter: (filter: { project: string[]; exclude: string[] }) => invoke('codeburn:setProjectFilter', filter),
|
||||
getUnfilteredProjects: (period: string) => invoke('codeburn:getUnfilteredProjects', period),
|
||||
getUnfilteredProjects: () => invoke('codeburn:getUnfilteredProjects'),
|
||||
setPriceOverride: (model: string, rates: PriceRates) => invoke('codeburn:setPriceOverride', model, rates),
|
||||
removePriceOverride: (model: string) => invoke('codeburn:removePriceOverride', model),
|
||||
setCurrency: (code: string) => invoke('codeburn:setCurrency', code),
|
||||
|
|
|
|||
|
|
@ -777,7 +777,7 @@ export interface CodeburnBridge {
|
|||
getProjectFilter(): Promise<ProjectFilter>
|
||||
setProjectFilter(filter: ProjectFilter): Promise<ProjectFilter>
|
||||
/** Every project that exists, filter NOT applied: the Projects pane's checklist. */
|
||||
getUnfilteredProjects(period: Period): Promise<ProjectsReport>
|
||||
getUnfilteredProjects(): Promise<ProjectsReport>
|
||||
setPriceOverride(model: string, rates: PriceRates): Promise<ActionResult>
|
||||
removePriceOverride(model: string): Promise<ActionResult>
|
||||
setCurrency(code: string): Promise<ActionResult>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const mocks = vi.hoisted(() => ({
|
|||
getPriceOverrides: vi.fn<() => Promise<PriceOverrideList>>(),
|
||||
getProjectFilter: vi.fn<() => Promise<ProjectFilter>>(),
|
||||
setProjectFilter: vi.fn<(filter: ProjectFilter) => Promise<ProjectFilter>>(),
|
||||
getUnfilteredProjects: vi.fn<(period: string) => Promise<ProjectsReport>>(),
|
||||
getUnfilteredProjects: vi.fn<() => Promise<ProjectsReport>>(),
|
||||
setPriceOverride: vi.fn<(model: string, rates: PriceRates) => Promise<ActionResult>>(),
|
||||
removePriceOverride: vi.fn<(model: string) => Promise<ActionResult>>(),
|
||||
setCurrency: vi.fn<(code: string) => Promise<ActionResult>>(),
|
||||
|
|
@ -173,6 +173,28 @@ describe('Settings', () => {
|
|||
expect(mocks.setProjectFilter).toHaveBeenCalledWith({ project: [], exclude: [] })
|
||||
})
|
||||
|
||||
// A filter has no period, so neither can the list it is checked against. The
|
||||
// period on screen used to key this fetch, which made a pattern excluding a
|
||||
// dormant project read as an orphan next to a Remove button.
|
||||
it('asks for one project list for the whole history, not one per period on screen', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<Settings period="today" />)
|
||||
await user.click(screen.getByRole('button', { name: 'Projects' }))
|
||||
await screen.findByRole('switch', { name: 'Show /Users/x/Web/work/my-company' })
|
||||
expect(mocks.getUnfilteredProjects).toHaveBeenCalledWith()
|
||||
})
|
||||
|
||||
it('keeps the project list across a period change instead of refetching it', async () => {
|
||||
const user = userEvent.setup()
|
||||
const { rerender } = render(<Settings period="today" />)
|
||||
await user.click(screen.getByRole('button', { name: 'Projects' }))
|
||||
await screen.findByRole('switch', { name: 'Show /Users/x/Web/work/my-company' })
|
||||
expect(mocks.getUnfilteredProjects).toHaveBeenCalledTimes(1)
|
||||
rerender(<Settings period="month" />)
|
||||
expect(await screen.findByRole('switch', { name: 'Show /Users/x/Web/work/my-company' })).toBeInTheDocument()
|
||||
expect(mocks.getUnfilteredProjects).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('switches panes from the rail and renders the completed Plans pane', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(<Settings period="month" />)
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ export function Settings({ period, refreshToken = 0, onNavigate, initialPane, cl
|
|||
<main className="set-pane">
|
||||
{pane === 'general' && <GeneralPane period={period} refreshToken={refreshToken} claudeConfigs={claudeConfigs} claudeConfigSource={claudeConfigSource} onConfigMutated={onConfigMutated} scope={scope} onScopeChange={onScopeChange} projectFiltered={projectFiltered} />}
|
||||
{pane === 'providers' && <ProvidersPane period={period} refreshToken={refreshToken} />}
|
||||
{pane === 'projects' && <ProjectsPane period={period} refreshToken={refreshToken} onConfigMutated={onConfigMutated} />}
|
||||
{pane === 'projects' && <ProjectsPane refreshToken={refreshToken} onConfigMutated={onConfigMutated} />}
|
||||
{pane === 'aliases' && <AliasesPane refreshToken={refreshToken} onConfigMutated={onConfigMutated} />}
|
||||
{pane === 'pricing' && <PricingPane refreshToken={refreshToken} onConfigMutated={onConfigMutated} />}
|
||||
{pane === 'plans' && <PlansPane period={period} refreshToken={refreshToken} onNavigate={onNavigate} onConfigMutated={onConfigMutated} />}
|
||||
|
|
@ -290,14 +290,23 @@ function projectVisible(project: ProjectRow, filter: ProjectFilter): boolean {
|
|||
return filter.project.length === 0 || filter.project.some(pattern => projectMatches(project, pattern))
|
||||
}
|
||||
|
||||
function ProjectsPane({ period, refreshToken, onConfigMutated }: { period: Period; refreshToken: number; onConfigMutated?: () => void }) {
|
||||
function ProjectsPane({ refreshToken, onConfigMutated }: { refreshToken: number; onConfigMutated?: () => void }) {
|
||||
const [actionNonce, setActionNonce] = useState(0)
|
||||
const [pattern, setPattern] = useState('')
|
||||
const [error, setError] = useState('')
|
||||
const [busy, setBusy] = useState(false)
|
||||
// Not keyed on refreshToken: `report` is the heaviest fetch in the app, and a
|
||||
// toggle cannot change an unfiltered list.
|
||||
const report = usePolled<ProjectsReport>(() => codeburn.getUnfilteredProjects(period), [period], { memoKey: `projects|${period}` })
|
||||
// Lifetime, and not the period on screen: the filter applies to every screen
|
||||
// and every horizon, so a list bounded to the visible period would call a live
|
||||
// exclude an orphan and leave "Nothing is hidden." under hidden projects.
|
||||
//
|
||||
// Not keyed on refreshToken, and never on an interval: `report` is the
|
||||
// heaviest fetch in the app, a toggle cannot change an unfiltered list, and
|
||||
// the only thing that can is a project appearing, which the next open picks
|
||||
// up. The memo key goes through reportMemoKey like every other pane's.
|
||||
const report = usePolled<ProjectsReport>(() => codeburn.getUnfilteredProjects(), [], {
|
||||
memoKey: reportMemoKey('projects', 'lifetime'),
|
||||
intervalMs: null,
|
||||
})
|
||||
const saved = usePolled<ProjectFilter>(() => codeburn.getProjectFilter(), [refreshToken, actionNonce])
|
||||
const filter = saved.data ?? NO_PROJECT_FILTER
|
||||
const projects = report.data?.projects ?? []
|
||||
|
|
@ -343,7 +352,7 @@ function ProjectsPane({ period, refreshToken, onConfigMutated }: { period: Perio
|
|||
{report.error ? <SettingsErrorText error={report.error} />
|
||||
: saved.error ? <SettingsErrorText error={saved.error} />
|
||||
: !report.data || !saved.data ? <p className="set-cap">Loading projects…</p>
|
||||
: projects.length === 0 ? <p className="set-cap">No projects detected in this period.</p>
|
||||
: projects.length === 0 ? <p className="set-cap">No projects detected yet.</p>
|
||||
: projects.map(project => {
|
||||
const visible = projectVisible(project, filter)
|
||||
const pattern_ = projectPattern(project)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue