* fix(projects): restore cross-host grouping Random host-local project IDs replaced the remote-derived value that had also served as grouping identity. Persist a separate opaque group key and let normal boot reconciliation backfill older records without a migration. * fix(projects): keep ambiguous clones separate A shared remote can identify a project across hosts, but it cannot distinguish two independent clones on one host. Treat those keys as ambiguous so host-local project IDs remain separate. * fix(projects): preserve host-local project identity * fix(projects): strengthen grouping identity * test(app): update project host shape contract * fix(projects): preserve selected host identity * fix(projects): close grouped routing gaps * fix(projects): stabilize legacy subproject grouping * fix(projects): preserve selected project identity * fix(projects): isolate legacy host identity * fix(projects): preserve symlinked bootstrap roots * fix(projects): reconcile grouped custom names * fix(projects): stabilize settings and path identity * fix(projects): normalize default remote ports * fix(projects): harden host and remote identity * fix(projects): preserve host-scoped actions * fix(projects): preserve remote path semantics * fix(projects): model SCP remote semantics * fix(projects): keep settings on routed host * fix(projects): preserve SSH URL path semantics * fix(projects): separate identity from presentation * test(projects): use grouped identity in UI specs * fix(projects): harden grouped project routing * test(projects): expect framed settings route * fix(projects): preserve exact placement identity * fix(projects): harden grouping identity and routing * fix(projects): restore project key as grouping identity Random host-local project IDs had replaced the persisted cross-host value carried by projectKey. Keep projectId for routing while reconciliation owns and persists projectKey for grouping. * fix(projects): prevent project key collisions Preserve platform path semantics and generic remote transports in cross-host keys, and compare legacy checkout roots using filesystem equivalence before materializing ownership. * test(projects): assert host-scoped project keys * fix(projects): preserve project key compatibility Resolve legacy workspace project references at the daemon boundary while keeping projectKey as the cross-host identity. Complete generic SSH normalization without collapsing distinct repositories. * fix(projects): harden project reference identity * fix(projects): retain archived reference errors * fix(projects): scope legacy paths to hosts * test(app): model persisted project keys * fix(projects): retain absolute scp users * fix(projects): resolve legacy mutation aliases * fix(projects): preserve conservative identity boundaries * fix(projects): preserve legacy placement identity * test(projects): assert legacy placement identity * test(projects): expect canonical Windows keys * fix(projects): separate bootstrap identity fields * fix(projects): scope legacy paths by host * fix(projects): stabilize opaque project identity * fix(projects): preserve remaining opaque identities * fix(projects): classify forward-slash UNC roots * fix(projects): preserve opaque selection keys * fix(projects): frame host-local project keys * fix(projects): canonicalize framed identities * test(projects): isolate repeated remote fixtures * fix(projects): keep project key as UI identity * fix(projects): reconcile hydrated project references * fix(projects): preserve archived project identity * refactor(projects): group projects from project records, not workspaces Cross-host grouping had been built by hanging a projectKey off every workspace descriptor. That scoped the key to the wrong entity: the app then had to reconstruct project identity per workspace in six modules, which forced projectKey fallbacks into RPC arguments and a server-side resolver that turned grouping keys back into project ids. A workspace has a projectId. The key belongs to the project, and grouping is a display concern, so the daemon now publishes projects over project.list plus the existing project.update channel and the app groups them in one place. Projects are addressed by host-local projectId everywhere, including the settings route. Projects persisted without a key are backfilled by ordinary boot reconciliation, with no migration. Old daemons advertise no projectList capability and simply do not group. * test(projects): seed projects alongside workspaces in fixtures Sidebar fixtures seeded workspaces without their projects, which the daemon cannot produce now that projects arrive on their own channel, so nothing rendered. Adds a seeding helper that supplies both. Also drops the provisioning test for accepting a project key where a project id belongs; that resolver was removed deliberately. * fix(projects): keep derived project identity stable Four gaps left by shrinking the key derivation: Local keys used a bare path resolve, so one directory reached by a different spelling produced a different key and reset grouped identity. Windows CI caught this with the 8.3 and long-name forms of one temp path. Canonicalize through the shared realpath-aware normalization. Subproject display names lost their selected-path input, so every subproject of a monorepo rendered under the same remote-derived name. Reconciliation only ever backfilled a missing key, so a project whose remote changed stayed grouped with hosts on the old remote. Project settings kept a disconnected host selected and rendered a dead end with no way back to an editable host. * fix(projects): read scheme remotes as URLs, not scp form An `ssh://user@host:22/org/repo` remote matched the scp-form pattern first, because `[^@]+` happily eats `ssh://git`, so the port landed in the path and the project keyed as `remote:host/22/org/repo`. Two spellings of one remote therefore never grouped. Try scp form only when there is no scheme, and drop protocol-default ports so an explicitly written `:22` matches the same remote without it.
305 lines
8.9 KiB
TypeScript
305 lines
8.9 KiB
TypeScript
import { type Page } from "@playwright/test";
|
|
import { buildSeededHost } from "./daemon-registry";
|
|
import { wsRoutePatternForPort } from "./daemon-port";
|
|
import { type SeededWorkspace } from "./seed-client";
|
|
|
|
const REGISTRY_KEY = "@paseo:daemon-registry";
|
|
const SEED_NONCE_KEY = "@paseo:e2e-seed-nonce";
|
|
const EXTRA_HOSTS_KEY = "@paseo:e2e-extra-hosts";
|
|
export const FAKE_HOST_MODEL_ID = "fake-host-model";
|
|
export const FAKE_HOST_MODEL_LABEL = "Fake host model";
|
|
export const FAKE_HOST_PROJECT_DISPLAY_NAME = "Fake host project";
|
|
|
|
type WebSocketMessage = string | Buffer;
|
|
type SessionRequest = Record<string, unknown> & { type?: string; requestId?: string };
|
|
|
|
export interface FakeScheduleHostWorkspace {
|
|
serverId: string;
|
|
projectId: string;
|
|
projectKey: string;
|
|
projectDisplayName: string;
|
|
workspace: Record<string, unknown>;
|
|
}
|
|
|
|
interface FakeScheduleSummary {
|
|
id: string;
|
|
name: string | null;
|
|
prompt: string;
|
|
cadence: { type: "cron"; expression: string };
|
|
target: {
|
|
type: "new-agent";
|
|
config: {
|
|
provider: "mock";
|
|
cwd: string;
|
|
model: string;
|
|
modeId: string;
|
|
title?: string;
|
|
};
|
|
};
|
|
status: "active";
|
|
createdAt: string;
|
|
updatedAt: string;
|
|
nextRunAt: string | null;
|
|
lastRunAt: string | null;
|
|
pausedAt: string | null;
|
|
expiresAt: string | null;
|
|
maxRuns: number | null;
|
|
}
|
|
|
|
function parseJson(message: WebSocketMessage): unknown {
|
|
const raw = typeof message === "string" ? message : message.toString("utf8");
|
|
try {
|
|
return JSON.parse(raw);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function buildSessionMessage(type: string, payload: Record<string, unknown>) {
|
|
return JSON.stringify({
|
|
type: "session",
|
|
message: {
|
|
type,
|
|
payload,
|
|
},
|
|
});
|
|
}
|
|
|
|
function buildFakeProviderEntries(nowIso: string) {
|
|
return [
|
|
{
|
|
provider: "mock",
|
|
label: "Mock",
|
|
status: "ready",
|
|
enabled: true,
|
|
fetchedAt: nowIso,
|
|
models: [
|
|
{
|
|
provider: "mock",
|
|
id: FAKE_HOST_MODEL_ID,
|
|
label: FAKE_HOST_MODEL_LABEL,
|
|
isDefault: true,
|
|
},
|
|
],
|
|
modes: [{ id: "load-test", label: "Load test" }],
|
|
defaultModeId: "load-test",
|
|
},
|
|
];
|
|
}
|
|
|
|
function readSessionRequest(message: WebSocketMessage): SessionRequest | null {
|
|
const parsed = parseJson(message);
|
|
if (!parsed || typeof parsed !== "object") {
|
|
return null;
|
|
}
|
|
|
|
const envelope = parsed as { type?: string; message?: SessionRequest };
|
|
if (envelope.type !== "session" || !envelope.message) {
|
|
return null;
|
|
}
|
|
|
|
return envelope.message;
|
|
}
|
|
|
|
function getRequestId(request: SessionRequest): string {
|
|
return typeof request.requestId === "string" ? request.requestId : "fake-request";
|
|
}
|
|
|
|
export async function buildFakeScheduleHostWorkspace(
|
|
workspace: SeededWorkspace,
|
|
): Promise<FakeScheduleHostWorkspace> {
|
|
const workspaceList = await workspace.client.fetchWorkspaces({
|
|
filter: { projectId: workspace.projectId },
|
|
});
|
|
const baseWorkspace = workspaceList.entries.find((entry) => entry.id === workspace.workspaceId);
|
|
if (!baseWorkspace) {
|
|
throw new Error(`Failed to load seeded workspace descriptor ${workspace.workspaceId}`);
|
|
}
|
|
|
|
const projectId = `${workspace.projectId}-fake-host`;
|
|
const cwd = `${workspace.repoPath}-fake-host`;
|
|
return {
|
|
serverId: "schedule-fake-host",
|
|
projectId,
|
|
projectKey: workspace.projectKey,
|
|
projectDisplayName: FAKE_HOST_PROJECT_DISPLAY_NAME,
|
|
workspace: {
|
|
...baseWorkspace,
|
|
id: `${baseWorkspace.id}-fake-host`,
|
|
projectId,
|
|
projectDisplayName: FAKE_HOST_PROJECT_DISPLAY_NAME,
|
|
projectRootPath: cwd,
|
|
workspaceDirectory: cwd,
|
|
name: FAKE_HOST_PROJECT_DISPLAY_NAME,
|
|
project: undefined,
|
|
},
|
|
};
|
|
}
|
|
|
|
export async function installFakeScheduleHost(input: {
|
|
page: Page;
|
|
port: string;
|
|
serverId: string;
|
|
workspace: Record<string, unknown>;
|
|
project: Pick<FakeScheduleHostWorkspace, "projectId" | "projectKey" | "projectDisplayName">;
|
|
schedules?: FakeScheduleSummary[];
|
|
}): Promise<void> {
|
|
await input.page.routeWebSocket(wsRoutePatternForPort(input.port), (ws) => {
|
|
ws.onMessage((message) => {
|
|
const parsed = parseJson(message);
|
|
if (parsed && typeof parsed === "object" && (parsed as { type?: string }).type === "hello") {
|
|
ws.send(
|
|
buildSessionMessage("status", {
|
|
status: "server_info",
|
|
serverId: input.serverId,
|
|
hostname: "fake-schedule-host",
|
|
version: "0.0.0-e2e",
|
|
features: {
|
|
providersSnapshot: true,
|
|
workspaceMultiplicity: true,
|
|
projectList: true,
|
|
projectAdd: true,
|
|
projectRemove: true,
|
|
workspaceRecovery: true,
|
|
},
|
|
}),
|
|
);
|
|
return;
|
|
}
|
|
|
|
if (parsed && typeof parsed === "object" && (parsed as { type?: string }).type === "ping") {
|
|
ws.send(JSON.stringify({ type: "pong" }));
|
|
return;
|
|
}
|
|
|
|
const request = readSessionRequest(message);
|
|
if (!request) {
|
|
return;
|
|
}
|
|
|
|
const requestId = getRequestId(request);
|
|
const now = Date.now();
|
|
const nowIso = new Date(now).toISOString();
|
|
switch (request.type) {
|
|
case "ping":
|
|
ws.send(
|
|
buildSessionMessage("pong", {
|
|
requestId,
|
|
clientSentAt: typeof request.clientSentAt === "number" ? request.clientSentAt : now,
|
|
serverReceivedAt: now,
|
|
serverSentAt: now,
|
|
}),
|
|
);
|
|
return;
|
|
case "fetch_workspaces_request":
|
|
ws.send(
|
|
buildSessionMessage("fetch_workspaces_response", {
|
|
requestId,
|
|
entries: [input.workspace],
|
|
emptyProjects: [],
|
|
pageInfo: { nextCursor: null, prevCursor: null, hasMore: false },
|
|
}),
|
|
);
|
|
return;
|
|
case "project.list.request":
|
|
ws.send(
|
|
buildSessionMessage("project.list.response", {
|
|
requestId,
|
|
projects: [
|
|
{
|
|
projectId: input.project.projectId,
|
|
projectKey: input.project.projectKey,
|
|
projectDisplayName: input.project.projectDisplayName,
|
|
projectRootPath: String(input.workspace.projectRootPath),
|
|
projectKind: "git",
|
|
},
|
|
],
|
|
}),
|
|
);
|
|
return;
|
|
case "fetch_agents_request":
|
|
ws.send(
|
|
buildSessionMessage("fetch_agents_response", {
|
|
requestId,
|
|
entries: [],
|
|
pageInfo: { nextCursor: null, prevCursor: null, hasMore: false },
|
|
}),
|
|
);
|
|
return;
|
|
case "get_providers_snapshot_request":
|
|
ws.send(
|
|
buildSessionMessage("get_providers_snapshot_response", {
|
|
requestId,
|
|
entries: buildFakeProviderEntries(nowIso),
|
|
generatedAt: nowIso,
|
|
}),
|
|
);
|
|
return;
|
|
case "refresh_providers_snapshot_request":
|
|
ws.send(
|
|
buildSessionMessage("refresh_providers_snapshot_response", {
|
|
requestId,
|
|
acknowledged: true,
|
|
}),
|
|
);
|
|
return;
|
|
case "schedule/list":
|
|
ws.send(
|
|
buildSessionMessage("schedule/list/response", {
|
|
requestId,
|
|
schedules: input.schedules ?? [],
|
|
error: null,
|
|
}),
|
|
);
|
|
return;
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
export async function addFakeScheduleHostAndReload(input: {
|
|
page: Page;
|
|
serverId: string;
|
|
label: string;
|
|
port: string;
|
|
}): Promise<void> {
|
|
const host = buildSeededHost({
|
|
serverId: input.serverId,
|
|
label: input.label,
|
|
endpoint: `127.0.0.1:${input.port}`,
|
|
nowIso: new Date().toISOString(),
|
|
});
|
|
|
|
await input.page.evaluate(
|
|
({ seededHost, keys }) => {
|
|
const nonce = localStorage.getItem(keys.nonce);
|
|
if (!nonce) {
|
|
throw new Error("Expected the e2e seed nonce before overriding the host registry.");
|
|
}
|
|
const raw = localStorage.getItem(keys.registry);
|
|
const registry: Array<{ serverId: string }> = raw ? JSON.parse(raw) : [];
|
|
const nextRegistry = registry.filter((entry) => entry.serverId !== seededHost.serverId);
|
|
nextRegistry.push(seededHost);
|
|
localStorage.setItem(keys.registry, JSON.stringify(nextRegistry));
|
|
|
|
const rawExtraHosts = localStorage.getItem(keys.extraHosts);
|
|
const extraHosts: Array<{ serverId: string }> = rawExtraHosts
|
|
? JSON.parse(rawExtraHosts)
|
|
: [];
|
|
const nextExtraHosts = extraHosts.filter((entry) => entry.serverId !== seededHost.serverId);
|
|
nextExtraHosts.push(seededHost);
|
|
localStorage.setItem(keys.extraHosts, JSON.stringify(nextExtraHosts));
|
|
},
|
|
{
|
|
seededHost: host,
|
|
keys: {
|
|
registry: REGISTRY_KEY,
|
|
nonce: SEED_NONCE_KEY,
|
|
extraHosts: EXTRA_HOSTS_KEY,
|
|
},
|
|
},
|
|
);
|
|
|
|
await input.page.reload();
|
|
}
|