From eca60a38eee9ece9e226ce94fa4d9e2b015b7d8f Mon Sep 17 00:00:00 2001 From: iamtoruk Date: Mon, 11 May 2026 22:02:15 -0700 Subject: [PATCH] shortProject: cache homedir, normalize Windows backslashes, fix stale test helper --- src/dashboard.tsx | 12 +++++++----- tests/dashboard.test.ts | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/dashboard.tsx b/src/dashboard.tsx index fdd7992..6a95da4 100644 --- a/src/dashboard.tsx +++ b/src/dashboard.tsx @@ -247,13 +247,15 @@ function DailyActivity({ projects, days = 14, pw, bw }: { projects: ProjectSumma ) } +const _home = homedir() +const _homePrefix = _home.endsWith('/') ? _home : _home + '/' + export function shortProject(absPath: string): string { - const home = homedir() - const homePrefix = home.endsWith('/') ? home : home + '/' + const normalized = absPath.replace(/\\/g, '/') let path: string - if (absPath === home) path = '' - else if (absPath.startsWith(homePrefix)) path = absPath.slice(homePrefix.length) - else path = absPath + if (normalized === _home) path = '' + else if (normalized.startsWith(_homePrefix)) path = normalized.slice(_homePrefix.length) + else path = normalized path = path.replace(/^\/+/, '') path = path.replace(/^private\/tmp\/[^/]+\/[^/]+\//, '').replace(/^private\/tmp\//, '').replace(/^tmp\//, '') if (!path) return 'home' diff --git a/tests/dashboard.test.ts b/tests/dashboard.test.ts index de45a5c..da802f1 100644 --- a/tests/dashboard.test.ts +++ b/tests/dashboard.test.ts @@ -56,7 +56,7 @@ function makeProject(name: string, sessions: SessionSummary[]): ProjectSummary { // Logic replicated from TopSessions component function getTopSessions(projects: ProjectSummary[], n = 5) { - const all = projects.flatMap(p => p.sessions.map(s => ({ ...s, projectName: p.project }))) + const all = projects.flatMap(p => p.sessions.map(s => ({ ...s, projectPath: p.projectPath }))) return [...all].sort((a, b) => b.totalCostUSD - a.totalCostUSD).slice(0, n) }