diff --git a/scripts/dev-portal/index.html b/scripts/dev-portal/index.html
index bad25cbfb1..8dc02c85eb 100644
--- a/scripts/dev-portal/index.html
+++ b/scripts/dev-portal/index.html
@@ -448,21 +448,49 @@
No stacks running
`;
}
- // Group stacks by worktree name so all envs for the same
- // worktree appear in a single card.
+ // All envs for the same worktree appear in a single card.
+ const groups = [...groupByWorktree(stacks).values()];
+ const dupNames = duplicateNames(
+ groups.map(group => cardHeader(group).worktree),
+ );
+
+ return `${groups.map(group => renderWorktreeCard(group, dupNames)).join('')}
`;
+ }
+
+ // Group by full path so checkouts that share a folder name (a/hyperdx,
+ // b/hyperdx) get separate cards. Items with no known path fall back to
+ // their folder name.
+ function groupByWorktree(items) {
const groups = new Map();
- for (const stack of stacks) {
- const key = stack.worktree || 'unknown';
+ for (const item of items) {
+ const key = item.worktreePath || item.worktree || 'unknown';
if (!groups.has(key)) groups.set(key, []);
- groups.get(key).push(stack);
+ groups.get(key).push(item);
}
+ return groups;
+ }
+
+ function duplicateNames(names) {
+ const seen = new Set();
+ const dups = new Set();
+ for (const name of names) (seen.has(name) ? dups : seen).add(name);
+ return dups;
+ }
- return `${[...groups.values()].map(renderWorktreeCard).join('')}
`;
+ // The folder name, or the full path when another card has the same name.
+ function worktreeLabel(name, worktreePath, dupNames) {
+ return dupNames.has(name) && worktreePath ? worktreePath : name;
}
- function renderWorktreeCard(stacks) {
- // Use the dev stack for the header since it has the richest metadata.
- const header = stacks.find(s => s.envType === 'dev') || stacks[0];
+ // Use the dev stack for the header since it has the richest metadata.
+ function cardHeader(stacks) {
+ return stacks.find(s => s.envType === 'dev') || stacks[0];
+ }
+
+ function renderWorktreeCard(stacks, dupNames) {
+ const header = cardHeader(stacks);
+ const worktreePath =
+ (stacks.find(s => s.worktreePath) || {}).worktreePath || '';
const devStack = stacks.find(s => s.envType === 'dev');
const appService =
devStack &&
@@ -506,7 +534,7 @@ No stacks running
${escapeHtml(header.branch)}
- ${escapeHtml(header.worktree)}
+ ${escapeHtml(worktreeLabel(header.worktree, worktreePath, dupNames))}
${chUrl ? `
Open ClickHouse ` : ''}
@@ -652,7 +680,11 @@
No stacks running
function filterHistoryEntries(entries, query) {
if (!query) return entries;
return entries.filter(entry =>
- fuzzyMatch(query, [entry.worktree || '', entry.branch || '']),
+ fuzzyMatch(query, [
+ entry.worktree || '',
+ entry.worktreePath || '',
+ entry.branch || '',
+ ]),
);
}
@@ -678,13 +710,10 @@
No past runs
const filtered = filterHistoryEntries(entries, historySearchQuery);
- // Group filtered entries by worktree
- const groups = new Map();
- for (const entry of filtered) {
- const key = entry.worktree || 'unknown';
- if (!groups.has(key)) groups.set(key, []);
- groups.get(key).push(entry);
- }
+ const groups = groupByWorktree(filtered);
+ const dupNames = duplicateNames(
+ [...groups.values()].map(group => group[0].worktree),
+ );
const noResults = filtered.length === 0;
@@ -698,29 +727,30 @@
Past Runs
noResults
? `
No runs matching "${escapeHtml(historySearchQuery)}"
`
: `
- ${[...groups.entries()].map(([worktree, group]) => renderHistoryWorktreeCard(worktree, group)).join('')}
+ ${[...groups.entries()].map(([key, group]) => renderHistoryWorktreeCard(key, group, dupNames)).join('')}
`
}
`;
}
- // Track which history cards are expanded (by worktree name).
+ // Track which history cards are expanded (by groupByWorktree key).
// All cards are collapsed by default.
const historyExpanded = new Set();
- function toggleHistoryCard(worktree) {
- if (historyExpanded.has(worktree)) {
- historyExpanded.delete(worktree);
+ function toggleHistoryCard(key) {
+ if (historyExpanded.has(key)) {
+ historyExpanded.delete(key);
} else {
- historyExpanded.add(worktree);
+ historyExpanded.add(key);
}
refreshHistory();
}
- function renderHistoryWorktreeCard(worktree, entries) {
- // Use the first entry for branch info
+ function renderHistoryWorktreeCard(key, entries, dupNames) {
+ // Use the first entry for branch and worktree info
+ const { worktree, worktreePath = '' } = entries[0];
const branch = entries[0].branch || 'unknown';
- const collapsed = !historyExpanded.has(worktree);
+ const collapsed = !historyExpanded.has(key);
const chevron = collapsed ? '\u25b6' : '\u25bc';
const count = entries.length;
@@ -732,10 +762,10 @@
Past Runs
${escapeHtml(branch)}
${count} run${count !== 1 ? 's' : ''}
- ${escapeHtml(worktree)}
+ ${escapeHtml(worktreeLabel(worktree, worktreePath, dupNames))}
- ${chevron}
+ ${chevron}
diff --git a/scripts/dev-portal/server.js b/scripts/dev-portal/server.js
index 37fc6a35d5..05524a4e0a 100755
--- a/scripts/dev-portal/server.js
+++ b/scripts/dev-portal/server.js
@@ -215,6 +215,19 @@ function resolveGitRoot(dir) {
return root;
}
+// The UI groups cards by this path, so it must come out the same for every
+// stack of one checkout: slot files record $PWD (which may go through a
+// symlink), and compose working_dir can be a subdirectory.
+function canonicalWorktreePath(dir) {
+ if (!dir) return '';
+ const root = resolveGitRoot(dir) || dir;
+ try {
+ return fs.realpathSync(root);
+ } catch {
+ return root;
+ }
+}
+
// Resolve git branch for a working directory. Cached per request cycle via
// the branchCache map passed in from the caller.
function resolveGitBranch(workingDir, branchCache) {
@@ -281,13 +294,12 @@ async function buildDashboardData() {
}
// For all envTypes: fall back to compose working_dir when missing.
- // The working_dir may be a subdirectory (e.g. packages/app/tests/e2e
- // for E2E containers), so resolve up to the git repo root.
const workingDir = labels['com.docker.compose.project.working_dir'] || '';
+ if (workingDir && !stack.worktreePath) {
+ stack.worktreePath = canonicalWorktreePath(workingDir);
+ }
if (workingDir && stack.worktree === 'unknown') {
- const repoRoot = resolveGitRoot(workingDir) || workingDir;
- stack.worktree = path.basename(repoRoot);
- stack.worktreePath = repoRoot;
+ stack.worktree = path.basename(stack.worktreePath);
}
if (workingDir && stack.branch === 'unknown') {
stack.branch = resolveGitBranch(workingDir, branchCache);
@@ -325,7 +337,9 @@ async function buildDashboardData() {
if (stack.worktree === 'unknown' && data.worktree) {
stack.worktree = data.worktree;
}
- stack.worktreePath = data.worktreePath || '';
+ if (data.worktreePath) {
+ stack.worktreePath = canonicalWorktreePath(data.worktreePath);
+ }
// Add API and App as services (probe their ports)
const apiUp = await probePort(data.apiPort);
@@ -723,12 +737,14 @@ function discoverHistory() {
// Resolve slot-level worktree/branch from the JSON file (if still alive)
let slotWorktree = null;
+ let slotWorktreePath = null;
let slotBranch = null;
const slotFile = path.join(SLOTS_DIR, `${slot}.json`);
try {
if (fs.existsSync(slotFile)) {
const data = JSON.parse(fs.readFileSync(slotFile, 'utf-8'));
slotWorktree = data.worktree || null;
+ slotWorktreePath = data.worktreePath || null;
slotBranch = data.branch || null;
if (!slotWorktree && data.worktreePath) {
slotWorktree = path.basename(data.worktreePath);
@@ -741,6 +757,7 @@ function discoverHistory() {
// Collect entries for this slot, reading meta.json where available
const slotEntries = [];
let metaWorktree = null;
+ let metaWorktreePath = null;
let metaBranch = null;
for (const runDir of fs.readdirSync(histDir)) {
@@ -764,16 +781,19 @@ function discoverHistory() {
// Read per-run meta.json
let runWorktree = null;
+ let runWorktreePath = null;
let runBranch = null;
const metaPath = path.join(runPath, 'meta.json');
try {
if (fs.existsSync(metaPath)) {
const meta = JSON.parse(fs.readFileSync(metaPath, 'utf-8'));
runWorktree = meta.worktree || null;
+ runWorktreePath = meta.worktreePath || null;
runBranch = meta.branch || null;
// Remember the first valid meta as a fallback for siblings
if (runWorktree && !metaWorktree) {
metaWorktree = runWorktree;
+ metaWorktreePath = runWorktreePath;
metaBranch = runBranch;
}
}
@@ -789,6 +809,7 @@ function discoverHistory() {
files,
totalSize,
worktree: runWorktree,
+ worktreePath: runWorktreePath,
branch: runBranch,
});
}
@@ -797,12 +818,16 @@ function discoverHistory() {
// priority: 1) sibling meta.json, 2) slot JSON file, 3) process.cwd()
// (only if this is the local slot).
let fallbackWorktree = metaWorktree || slotWorktree || null;
+ let fallbackWorktreePath = metaWorktree
+ ? metaWorktreePath
+ : slotWorktreePath;
let fallbackBranch = metaBranch || slotBranch || null;
if (!fallbackWorktree && slot === localSlot) {
const cwd = process.cwd();
const repoRoot = resolveGitRoot(cwd);
if (repoRoot) {
fallbackWorktree = path.basename(repoRoot);
+ fallbackWorktreePath = repoRoot;
fallbackBranch = resolveGitBranch(cwd, new Map());
}
}
@@ -810,7 +835,9 @@ function discoverHistory() {
for (const entry of slotEntries) {
if (!entry.worktree) {
entry.worktree = fallbackWorktree || `slot-${slot}`;
+ entry.worktreePath = fallbackWorktreePath;
}
+ entry.worktreePath = canonicalWorktreePath(entry.worktreePath);
if (!entry.branch) {
entry.branch = fallbackBranch || 'unknown';
}