* feat(schedules): per-run workspaces, isolation and archive controls Scheduled agents never appeared in the sidebar: each schedule reused one stamped workspace and archived the run's agent on completion. Now every run mints its own workspace — the entity the sidebar shows — with per-schedule controls for isolation (local or worktree) and whether to archive that workspace when the run finishes. The schedule form is rebuilt on a non-React form model (open/commands/close) to end the flicker, edit-into-create contamination, and multi-host hydration bugs that came from effect-choreographed shared state. That lands the reusable foundations it needed: a form kit over a single control-geometry owner, a data-access taxonomy (replica/snapshot/fetch) with real load-state semantics, and lint/boundary guardrails so new screens inherit the paved road. Also fixes desktop combobox popovers truncating options when the trigger is narrower than the content. New schedule protocol fields are optional on both create and update, so old and new clients/daemons stay compatible. * test(app): complete mock themes for control-geometry tokens switch and terminal-profile-edit-modal now style through createControlGeometry, which reads theme.borderWidth[1], theme.opacity[50], and theme.colors.borderAccent. The hand-rolled mock themes in these two suites lacked those tokens, so the eager StyleSheet.create mock threw at import (collection error), not on any assertion. Add the missing tokens. * fix(schedules): address review findings on run cleanup, edit isolation, load error, sheet dismiss, and preference hydration - Server: archive the run's workspace even when agent creation fails, so a misconfigured provider no longer orphans a sidebar workspace/worktree. - Edit form: keep a stored worktree isolation while worktree eligibility is still resolving, instead of silently downgrading a saved schedule to local. - Schedules screen: show the load error/retry UI when every host fails, rather than spinning forever behind the loading branch. - Form sheet: fire the parent onClose on native gesture/backdrop dismiss so the sheet closes instead of re-opening. - Form model: apply late-loading saved preferences to untouched create-mode fields (never to edited schedules or user-modified fields). * fix(schedules): review batch — reconnect resubscribe, worktree prune, Android dismiss, cadence and provider edit safety - Push-router: re-send terminal and checkout-diff subscriptions after a reconnect; the old per-hook effect resubscribed on isConnected and the extracted router did not, so daemon restarts silently stopped terminals_changed pushes (root cause of the terminal-activity e2e failures). - Server: pass the run's source repo root when archiving worktree runs so the worktree is unregistered (git worktree remove/prune), not just deleted; also archive the workspace when agent creation fails even with archive-off (an agentless workspace has nothing to inspect). - Sheet: RN Modal onDismiss is iOS-only — notify dismiss once-per-close on the Android native path too; replace the JSDOM component test with a real Playwright dismiss spec and inline the trivial dismiss decision. - Form model: editing an interval schedule no longer rewrites its cadence to cron unless the cadence UI is touched (90-minute intervals have no cron equivalent); switching projects clears stale provider/model state and gates submit until the new host's snapshot resolves. * chore(lint): drop custom lint wrapper and boundary script, plain oxlint The import bans stay in .oxlintrc.json (oxlint-native no-restricted-imports). The receiver-sensitive checks the custom script enforced are not worth a parallel lint pipeline; if they come back it will be as oxlint rules. * fix(schedules): crash-safe run cleanup, capability-gated run options, resilient mutations - Persist the run's workspace/agent ids on the running-run record so a daemon crash mid-run can be recovered: restart archives the interrupted run's workspace under the same policy as normal cleanup (agentless always archives, otherwise archiveOnFinish is respected). - Hide Archive on finish (and omit archiveOnFinish/isolation from payloads) on hosts without workspaceMultiplicity — an old daemon ignores the fields, so offering the switch there would lie. - Optimistic pause/resume/delete no longer throw when the schedules cache holds a still-connecting entry alongside loaded data. - Mode field is gated on provider mode options, not a selected model, so model-less providers can pick their advertised modes.
285 lines
8.2 KiB
TypeScript
285 lines
8.2 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;
|
|
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,
|
|
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>;
|
|
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,
|
|
projectAdd: true,
|
|
projectRemove: true,
|
|
worktreeRestore: 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 "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();
|
|
}
|