Files
paseo/packages/app/src/hooks/sidebar-status-view-model.test.ts
T
Mohamed BoudraandGitHub a49c658d1f Merge sidebar workspaces across all connected hosts (#1538)
* Merge workspaces across all hosts in the sidebar

Replace per-host sidebar sections with a single merged project list.
Projects that exist on multiple hosts (matched by projectKey) are
collapsed into one row. Host identity is surfaced via:

- A status-only footer pill showing online/offline host counts
- Hover cards with a mandatory host row on every workspace entry
- Subtitles showing the host name when a project spans >1 host
- A host filter in the grouping dropdown (not a sidebar switcher)

Order and group-mode stores migrated from per-server to global keys
with zustand persist migrations. New-workspace screen now shows a
merged project list with a host selector combobox.

Key files:
- workspace-structure.ts: merge algorithm by projectKey
- sidebar-view-store.ts / sidebar-order-store.ts: global state
- sidebar-workspace-list.tsx: context-based subtitle injection
- new-workspace-screen.tsx: host selector in footer row

* Add host filtering to the merged sidebar

The sidebar now merges workspaces from every connected host, so a single
global "active host" no longer fits. Host selection becomes explicit per
action via a host chooser, and agent history pages across all hosts at
once. Removes the active-host / active-server-id model and the
all-agents-list hook that fed it.

* Fix rebase fallout: translate archive host error, update stale workspace-key test

archiveWorkspacesOptimistically used a raw "Host is not connected" string
that the i18n completeness test forbids; route it through i18n.t with the
existing hostDisconnected key. The selectors memoization test asserted
un-prefixed workspace keys, but merged-sidebar keys are serverId-prefixed.

* Fix sidebar review fallout

* Address sidebar review followups

* Fix sidebar workspace identity migration

* Address sidebar review followups

* Handle partial host history failures

* Fix merged sidebar project removal and E2E drift

* Restore history routes and project removal shape

* Remove sidebar host context plumbing

* Tighten sidebar status and host filter state

* Keep new workspace project selection host-compatible

* Migrate sidebar view storage

* Streamline host selection flows

* Update all-host history on archive

* Fix empty project sidebar action

Code regression: the main merge dropped the empty-project New workspace child row while keeping the empty project persistence contract. Restore the row using the project host target so the sidebar stays aligned with the no-host-selection model.

* Fix Japanese shortcut translation key

Stale-base integration: main added the Japanese locale after this branch added cycleAgentMode to the English shortcut help map. Merging main exposed the missing ja key in CI typecheck and resources.test.

* Fix Playwright speech teardown race
2026-06-26 12:16:49 +08:00

217 lines
6.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { SidebarWorkspaceEntry } from "./sidebar-workspaces-view-model";
import {
buildStatusGroups,
buildStatusShortcutIndex,
STATUS_BUCKET_LABELS,
STATUS_BUCKET_ORDER,
type StatusGroup,
} from "./sidebar-status-view-model";
function ws(
input: Partial<SidebarWorkspaceEntry> & { workspaceKey: string },
): SidebarWorkspaceEntry {
return {
serverId: input.serverId ?? "srv",
workspaceId: input.workspaceId ?? input.workspaceKey.split(":")[1] ?? "ws",
projectKey: input.projectKey ?? "proj",
projectName: input.projectName ?? "Project",
projectRootPath: input.projectRootPath,
workspaceDirectory: input.workspaceDirectory,
projectKind: input.projectKind ?? "git",
workspaceKind: input.workspaceKind ?? "worktree",
name: input.name ?? "main",
title: input.title ?? null,
currentBranch: input.currentBranch ?? null,
statusBucket: input.statusBucket ?? "done",
statusEnteredAt: input.statusEnteredAt ?? null,
archivingAt: null,
diffStat: null,
prHint: null,
archiveHasUncommittedChanges: null,
archiveUnpushedCommitCount: null,
scripts: [],
hasRunningScripts: false,
workspaceKey: input.workspaceKey,
};
}
function d(iso: string): Date {
return new Date(iso);
}
const emptyProjectNames = new Map<string, string>();
describe("buildStatusGroups", () => {
it("groups workspaces by status bucket in fixed order", () => {
const workspaces = [
ws({ workspaceKey: "srv:done-ws", statusBucket: "done", name: "done-ws" }),
ws({
workspaceKey: "srv:needs-input-ws",
statusBucket: "needs_input",
name: "needs-input-ws",
}),
ws({ workspaceKey: "srv:running-ws", statusBucket: "running", name: "running-ws" }),
];
const groups = buildStatusGroups(workspaces, emptyProjectNames);
expect(groups.map((g) => g.bucket)).toEqual(["needs_input", "running", "done"]);
expect(groups[0]?.label).toBe("Needs input");
expect(groups[1]?.label).toBe("Working");
expect(groups[2]?.label).toBe("Done");
});
it("omits empty buckets", () => {
const workspaces = [
ws({ workspaceKey: "srv:a", statusBucket: "done" }),
ws({ workspaceKey: "srv:b", statusBucket: "running" }),
];
const groups = buildStatusGroups(workspaces, emptyProjectNames);
expect(groups.map((g) => g.bucket)).toEqual(["running", "done"]);
});
it("sorts by statusEnteredAt desc within a bucket", () => {
const workspaces = [
ws({
workspaceKey: "srv:old",
statusBucket: "done",
statusEnteredAt: d("2026-01-01T00:00:00Z"),
}),
ws({
workspaceKey: "srv:new",
statusBucket: "done",
statusEnteredAt: d("2026-06-01T00:00:00Z"),
}),
ws({
workspaceKey: "srv:mid",
statusBucket: "done",
statusEnteredAt: d("2026-03-01T00:00:00Z"),
}),
];
const groups = buildStatusGroups(workspaces, emptyProjectNames);
expect(groups[0]?.rows.map((r) => r.workspaceKey)).toEqual(["srv:new", "srv:mid", "srv:old"]);
});
it("sorts null timestamps last within a bucket", () => {
const workspaces = [
ws({ workspaceKey: "srv:null-a", statusBucket: "done", statusEnteredAt: null }),
ws({
workspaceKey: "srv:ts",
statusBucket: "done",
statusEnteredAt: d("2026-01-01T00:00:00Z"),
}),
ws({ workspaceKey: "srv:null-b", statusBucket: "done", statusEnteredAt: null }),
];
const groups = buildStatusGroups(workspaces, emptyProjectNames);
expect(groups[0]?.rows.map((r) => r.workspaceKey)).toEqual([
"srv:ts",
"srv:null-a",
"srv:null-b",
]);
});
it("tie-breaks by project name, then workspace name, then workspaceKey", () => {
const projectNames = new Map<string, string>([
["proj-b", "Beta"],
["proj-a", "Alpha"],
]);
const workspaces = [
ws({ workspaceKey: "srv:1", statusBucket: "done", projectKey: "proj-b", name: "zebra" }),
ws({ workspaceKey: "srv:2", statusBucket: "done", projectKey: "proj-a", name: "alpha" }),
ws({ workspaceKey: "srv:3", statusBucket: "done", projectKey: "proj-a", name: "alpha" }),
];
const groups = buildStatusGroups(workspaces, projectNames);
expect(groups[0]?.rows.map((r) => r.workspaceKey)).toEqual(["srv:2", "srv:3", "srv:1"]);
});
it("returns empty array for no workspaces", () => {
const groups = buildStatusGroups([], emptyProjectNames);
expect(groups).toEqual([]);
});
it("uses hydrated workspace entries with real status, not structural placeholders", () => {
const workspaces = [
ws({
workspaceKey: "srv:ni",
statusBucket: "needs_input",
statusEnteredAt: d("2026-01-01T00:00:00Z"),
}),
ws({
workspaceKey: "srv:fail",
statusBucket: "failed",
statusEnteredAt: d("2026-01-01T00:00:00Z"),
}),
ws({
workspaceKey: "srv:att",
statusBucket: "attention",
statusEnteredAt: d("2026-01-01T00:00:00Z"),
}),
ws({
workspaceKey: "srv:run",
statusBucket: "running",
statusEnteredAt: d("2026-01-01T00:00:00Z"),
}),
ws({ workspaceKey: "srv:dn", statusBucket: "done", statusEnteredAt: null }),
];
const groups = buildStatusGroups(workspaces, emptyProjectNames);
expect(groups.map((g) => g.bucket)).toEqual(STATUS_BUCKET_ORDER);
expect(groups.map((g) => g.label)).toEqual(
STATUS_BUCKET_ORDER.map((b) => STATUS_BUCKET_LABELS[b]),
);
// Each group has exactly one row with the matching bucket
for (const group of groups) {
expect(group.rows).toHaveLength(1);
expect(group.rows[0]?.statusBucket).toBe(group.bucket);
}
});
});
describe("buildStatusShortcutIndex", () => {
it("assigns sequential numbers in status visual order", () => {
const groups: StatusGroup[] = [
{ bucket: "needs_input", label: "Needs input", rows: [ws({ workspaceKey: "srv:ni" })] },
{
bucket: "running",
label: "Working",
rows: [ws({ workspaceKey: "srv:run" }), ws({ workspaceKey: "srv:run2" })],
},
{ bucket: "done", label: "Done", rows: [ws({ workspaceKey: "srv:dn" })] },
];
const index = buildStatusShortcutIndex(groups);
expect(index.get("srv:ni")).toBe(1);
expect(index.get("srv:run")).toBe(2);
expect(index.get("srv:run2")).toBe(3);
expect(index.get("srv:dn")).toBe(4);
});
it("stops at 9 shortcuts", () => {
const rows = Array.from({ length: 12 }, (_, i) => ws({ workspaceKey: `srv:ws${i}` }));
const groups: StatusGroup[] = [{ bucket: "done", label: "Done", rows }];
const index = buildStatusShortcutIndex(groups);
expect(index.size).toBe(9);
expect(index.has("srv:ws8")).toBe(true);
expect(index.has("srv:ws9")).toBe(false);
});
it("returns empty map for empty groups", () => {
const index = buildStatusShortcutIndex([]);
expect(index.size).toBe(0);
});
});