diff --git a/src/session-cache.ts b/src/session-cache.ts index 10b583c6..fe9f02b9 100644 --- a/src/session-cache.ts +++ b/src/session-cache.ts @@ -642,7 +642,10 @@ export const PROVIDER_PARSE_VERSIONS: Record = { // to land. // billed-cost-v1: total_billed_cost_in_cents prices conversations that carry // no provider cost or charged usage. - warp: 'worktree-project-grouping-v1-est-cost-billing-cost-v1-billed-cost-v1', + // exchange-share-v1: cached exchanges keep their share of a conversation's + // cost and only new spend goes to new exchanges (parser.ts + // keepCachedWarpShares); unchanged databases re-parse once onto that rule. + warp: 'worktree-project-grouping-v1-est-cost-billing-cost-v1-billed-cost-v1-exchange-share-v1', // cache-read-v1-est-cost: gen_metadata and RPC usage now carry cache-read // tokens, fields 9/10 read as thinking/response (they were swapped), and // placeholder-only models are priced and flagged costIsEstimated. diff --git a/tests/warp-billing-cost-cache.test.ts b/tests/warp-billing-cost-cache.test.ts index ae6cb0dd..14dfffbf 100644 --- a/tests/warp-billing-cost-cache.test.ts +++ b/tests/warp-billing-cost-cache.test.ts @@ -288,3 +288,24 @@ itUnlessNoSqlite('allocates two conversations in one database independently', as expect(costs.get('warp:B:B1')).toBeCloseTo(7.5, 10) expect(costs.get('warp:B:B2')).toBeCloseTo(0, 10) }) + +it('bumps the warp parse version for the per-exchange share rule', async () => { + const { PROVIDER_PARSE_VERSIONS } = await import('../src/session-cache.js') + expect(PROVIDER_PARSE_VERSIONS['warp']).toContain('exchange-share-v1') +}) + +itUnlessNoSqlite('clears a conversation whose exchanges are no longer finished', async () => { + writeWarpDb('2026-08-16 10:00:00.000000') + const { clearSessionCache, parseAllSessions } = await import('../src/parser.js') + const calls = async () => { + clearSessionCache() + return (await parseAllSessions(undefined, 'warp')).reduce((sum, p) => sum + p.totalApiCalls, 0) + } + expect(await calls()).toBe(3) + + const { DatabaseSync } = requireForTest('node:sqlite') + const db = new DatabaseSync(DB_PATH) + db.prepare(`UPDATE ai_queries SET output_status = '"InProgress"' WHERE conversation_id = 'conv-credits'`).run() + db.close() + expect(await calls()).toBe(2) +})