Files
paseo/packages/app/src/utils/agent-grouping.test.ts
T
Mohamed Boudra efd6023b90 Restore live sessions immediately after app resume (#4160)
* perf(app): restore live sessions immediately after resume

Foregrounding now reconnects every host without waiting for scheduled backoff, while cached turns, timelines, agents, and workspaces remain internally consistent until authoritative catch-up arrives. Replica persistence is keyed and incremental so ordinary updates avoid whole-directory serialization.

* fix(app): preserve turn ownership through session updates

Stream turn closure now wakes queued-message delivery, while same-turn snapshots retain local cancellation state. Offline liveness remains visible until an authoritative close arrives.

* fix(app): preserve pending chat cache writes and trim resume refactor

Directory baseline replacement must preserve independently accepted timeline changes until the deferred flush. Keep the reconnect and persistence fixes while removing the session-data facade and broad read-hook migration.

* fix(app): initialize reconnect policy from current app state

Initialize visibility before host bootstrap so a background mount cannot leave reconnect enabled. Seed sidebar fixtures through the workspace owner so cache hydration preserves their rows.

* test(app): verify submission settlement across reconnect

Keep submission acknowledgement separate from turn liveness: disconnect preserves the running turn until authoritative catch-up. Wait for confirmed running chrome before exercising queued cancellation so the alternate-send shortcut cannot race turn startup.

* docs: remove cache implementation recap
2026-09-06 10:18:41 +02:00

123 lines
4.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { deriveProjectDisplayName, deriveRemoteProjectKey, groupAgents } from "./agent-grouping";
import type { AggregatedAgent } from "@/hooks/use-aggregated-agents";
function makeAgent(overrides: Partial<AggregatedAgent> = {}): AggregatedAgent {
const now = new Date();
return {
id: overrides.id ?? "a1",
serverId: overrides.serverId ?? "s1",
serverLabel: (overrides as { serverLabel?: string }).serverLabel ?? "server",
title: overrides.title ?? null,
status: overrides.status ?? ("running" as AggregatedAgent["status"]),
turn:
overrides.turn ??
({
phase: "open",
turnId: null,
startedAt: null,
cancellationRequestId: null,
} as const),
lastActivityAt: overrides.lastActivityAt ?? now,
cwd: overrides.cwd ?? "/tmp/repo",
provider: overrides.provider ?? ("openai" as AggregatedAgent["provider"]),
requiresAttention: overrides.requiresAttention ?? false,
attentionReason: overrides.attentionReason ?? null,
attentionTimestamp: overrides.attentionTimestamp ?? null,
} as AggregatedAgent;
}
describe("deriveRemoteProjectKey", () => {
it("normalizes GitHub SSH and HTTPS to the same key", () => {
const ssh = "git@github.com:owner/repo.git";
const https = "https://github.com/owner/repo";
expect(deriveRemoteProjectKey(ssh)).toBe("remote:github.com/owner/repo");
expect(deriveRemoteProjectKey(https)).toBe("remote:github.com/owner/repo");
});
it("includes host for non-GitHub remotes", () => {
const gitlab = "git@gitlab.example.com:group/repo.git";
expect(deriveRemoteProjectKey(gitlab)).toBe("remote:gitlab.example.com/group/repo");
});
});
describe("deriveProjectDisplayName", () => {
it("shows owner/repo for GitHub remote keys", () => {
expect(
deriveProjectDisplayName({
projectKey: "remote:github.com/getpaseo/paseo",
projectName: "paseo",
}),
).toBe("getpaseo/paseo");
});
it("shows remote path for non-GitHub remote keys", () => {
expect(
deriveProjectDisplayName({
projectKey: "remote:gitlab.example.com/group/repo",
projectName: "repo",
}),
).toBe("group/repo");
});
it("falls back to projectName for local keys", () => {
expect(
deriveProjectDisplayName({
projectKey: "/Users/me/dev/paseo",
projectName: "paseo",
}),
).toBe("paseo");
});
});
describe("groupAgents", () => {
it("uses turn liveness instead of protocol status for active grouping", () => {
const old = new Date("2020-01-01T00:00:00.000Z");
const open = makeAgent({ id: "open", status: "idle", lastActivityAt: old });
const idle = makeAgent({
id: "idle",
status: "running",
lastActivityAt: old,
turn: { phase: "idle", cancellationRequestId: null },
});
const grouped = groupAgents([open, idle]);
const activeIds = grouped.activeGroups
.flatMap((group) => group.agents)
.map((agent) => agent.id);
const inactiveIds = grouped.inactiveGroups
.flatMap((group) => group.agents)
.map((agent) => agent.id);
expect(activeIds).toEqual(["open"]);
expect(inactiveIds).toEqual(["idle"]);
});
it("groups active agents by remote URL when available", () => {
const agents = [
makeAgent({ id: "a1", cwd: "/Users/me/dev/paseo" }),
makeAgent({ id: "a2", cwd: "/Users/me/dev/paseo-fix/worktree" }),
];
const { activeGroups } = groupAgents(agents, {
getRemoteUrl: () => "git@github.com:getpaseo/paseo.git",
});
expect(activeGroups).toHaveLength(1);
expect(activeGroups[0]?.agents.map((a) => a.id).sort()).toEqual(["a1", "a2"]);
});
it("falls back to cwd grouping when remote URL is unavailable", () => {
const agents = [
makeAgent({ id: "a1", cwd: "/Users/me/dev/paseo" }),
makeAgent({ id: "a2", cwd: "/Users/me/dev/paseo-fix/worktree" }),
];
const { activeGroups } = groupAgents(agents, {
getRemoteUrl: () => null,
});
expect(activeGroups).toHaveLength(2);
});
});