Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ A piece that another open change is still building is marked as pending with the
Every web spec runs on the core's own engine, the one engine a daemon builds: `startEngine()` is a daemon over the `hide-holder` built beside `hided`.
`startFixture()` is the default: one checkout, the folder `fixture` under the run's root, whose one tab holds two panes, each running the `claude` stand-in on a session whose transcript names it `Agent one` and `Agent two`; `agents: false` leaves two shells, and `family: true` makes the second agent the first one's delegated child, spawned beside it with `hide agent spawn --parent here` from inside the first agent's pane, so the core records the relationship as it records a real delegation.
`startCaller()` is that parent alone, for a spec whose subject is a command an agent runs rather than the family.
A spec or fixture starts an agent as the start panel does through `startAgentInCheckout` in `web/e2e/daemon-actions.ts`, which waits for the core's answer to that start, the receipt the start panel reads too (`web/src/startAnswer.ts`), until the agent has started, and fails with the core's answer on a refusal.
The core holds one task slot and refuses another start (`task_operation.busy`) while an agent is still starting, and it publishes the agent's row before that, so a second start sent once the first row appears was refused on a loaded runner and nothing retried it (with-hide/hide-private#561).
The two-shell setup waits for both terminals to be controlling before returning: a published split can precede its holder, and a spec that immediately restarts the daemon needs running shells to restore.
`startEngine()` is the empty engine for a spec that builds its own projects, and `startLayoutStack` a stack for pane and layout specs.
The fixture makes everything with the events the web shell sends, over its own connection to the daemon (`web/e2e/hided-control.mjs`, which the web shell measurement shares), and reads it back from the snapshot frames, never from an engine's CLI, so the fixture's checkout and panes exist only once the first `startHided` has returned.
Expand Down
28 changes: 28 additions & 0 deletions web/e2e/daemon-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,34 @@ export async function openProject(control: HidedControl, dir: string, label: str
}, `the project ${folder} with its first tab`, 30_000);
}

type TaskOperation = { kind: string; phase: string; pane_id: string | null; agent_phase: string | null; failure: string | null; request_id: string | null };

/**
* Starts the `claude` stand-in in the checkout at `folder` as the start
* panel's start does, with the start's other `fields` (a resumed session, a
* target beside another pane), and returns the pane the core started it in.
* It waits for the core's answer to this start, the receipt carrying its
* request id that the start panel reads too (`web/src/startAnswer.ts`), until
* the agent has started: the core holds one task slot and refuses another
* start, as `task_operation.busy`, while this one's agent is still starting,
* and the agent's row is published before that.
* A refused or failed start throws with the core's answer.
*/
export async function startAgentInCheckout(control: HidedControl, folder: string, fields: Record<string, unknown>, what: string): Promise<string> {
const requestId = `e2e-${crypto.randomUUID()}`;
control.send("agent_start_in_checkout", { checkout_path: folder, provider: "claude", request_id: requestId, ...fields });
const answer = await control.until((rest) => {
const refused = (rest.status as { last_error?: { kind: string; request_id?: string | null } | null } | undefined)?.last_error;
if (refused?.request_id === requestId) return { refused: refused.kind };
const operation = rest.task_operation as TaskOperation | null | undefined;
if (operation?.request_id !== requestId || operation.kind !== "agent_start") return undefined;
return operation.phase === "working" || operation.agent_phase === "starting" ? undefined : { operation };
}, `the core's answer to the start of ${what}`, 30_000);
const operation = "operation" in answer ? answer.operation : undefined;
if (operation?.phase !== "ready" || operation.agent_phase !== "started" || !operation.pane_id) throw new Error(`the core did not start ${what}: ${JSON.stringify(answer)}`);
return operation.pane_id;
}

/** A new tab in `checkout`, as New tab makes it, and its shell. */
export async function newTab(control: HidedControl, at: { workspace: string; checkout: string }, label: string): Promise<{ tab: string; pane: string }> {
const before = await control.until((rest) => tabsOf(rest, at.workspace), `the tabs of ${at.workspace}`);
Expand Down
29 changes: 14 additions & 15 deletions web/e2e/engine-fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
// web shell sends (`hided-control.mjs`) and reads them back from the
// snapshot.

import crypto from "node:crypto";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { expect, type Page } from "@playwright/test";
import { connectControl, type HidedControl } from "./hided-control.mjs";
import { agentIn, areaShowing, checkoutAt, closePane, focusPane, openProject, splitPane, startedAgentIn, tabPanes, viewPane, waitForPaneInput } from "./daemon-actions";
import { agentIn, areaShowing, closePane, focusPane, openProject, splitPane, startAgentInCheckout, startedAgentIn, tabOfPane, tabPanes, viewPane, waitForPaneInput } from "./daemon-actions";
import { claudeProjects, panePrompt, paneShellOf, writeFixtureTranscript, type PaneShell } from "./pane-fixture";
import { startHided, type Daemon, type DaemonEngine, type OpenedDaemon } from "./hided-fixture";
import { fixtureExecutable, fixturePrograms } from "./platform-fixture";
Expand Down Expand Up @@ -310,13 +309,13 @@ async function openFixture(control: HidedControl, server: EngineServer, daemon:
// A family's agents run `hide` as a real agent does, from inside their panes.
const runAs = kind === "family" ? installAgentRunner(server as AgentPaneFixture, daemon.stateDir) : undefined;
for (const agent of FIXTURE_AGENTS) writeFixtureTranscript(claudeProjects(server), agent.session, { task: agent.task });
const { start, one } = await startFirstAgent(control, folder, first.tab);
const one = await startFirstAgent(control, folder);
if (runAs) {
await parentOnItsSession(control, one.pane);
const spawned = await runAs(one.pane)(["agent", "spawn", "--parent", "here", "--beside", "--name", "agent-two", "--intent", "fixture-two", "--kind", "claude", "--repo", fs.realpathSync.native(dir), "--branch", "main", "--", "--resume", FIXTURE_AGENTS[1].session]);
if (spawned.status !== 0) throw new Error(`the fixture's parent could not spawn its child: ${spawned.out}`);
} else {
start(FIXTURE_AGENTS[1].session, { ...one.area, tab_id: one.tab, add_pane: true });
await startAgentInCheckout(control, folder, { resume_session_id: FIXTURE_AGENTS[1].session, target: { ...one.area, tab_id: one.tab, add_pane: true } }, "the second fixture agent");
}
const panes = await control.until((rest) => {
const listed = tabPanes(rest, one.tab);
Expand All @@ -339,28 +338,28 @@ async function openCaller(control: HidedControl, server: EngineServer, daemon: O
const first = await openProject(control, dir, "fixture");
const runAs = installAgentRunner(server as AgentPaneFixture, daemon.stateDir);
writeFixtureTranscript(claudeProjects(server), FIXTURE_AGENTS[0].session, { task: FIXTURE_AGENTS[0].task });
const { one } = await startFirstAgent(control, first.folder, first.tab);
const one = await startFirstAgent(control, first.folder);
await parentOnItsSession(control, one.pane);
// The shell Add project opened is not the fixture's: its tab goes.
await closePane(control, first.pane);
await agentsResting(control, server, [one.pane], true);
return { workspace: first.workspace, checkout: first.checkout, tab: one.tab, pane: one.pane, runAs };
}

/** Starts the fixture's first agent in a tab of its own in `folder`, as the start panel does, and sizes its pane. */
async function startFirstAgent(control: HidedControl, folder: string, projectTab: string) {
const start = (session: string, target?: Record<string, unknown>) => control.send("agent_start_in_checkout", {
checkout_path: folder, provider: "claude", resume_session_id: session, request_id: `e2e-${crypto.randomUUID()}`, ...(target ? { target } : {}),
});
start(FIXTURE_AGENTS[0].session);
/**
* Starts the fixture's first agent in a tab of its own in `folder`, as the
* start panel does, and sizes its pane. It returns once the core has
* started it, so the start that follows meets a free task slot.
*/
async function startFirstAgent(control: HidedControl, folder: string) {
const pane = await startAgentInCheckout(control, folder, { resume_session_id: FIXTURE_AGENTS[0].session }, "the first fixture agent");
const one = await control.until((rest) => {
const tab = checkoutAt(rest, folder)?.tabs.find((id) => id !== projectTab);
const pane = tab ? tabPanes(rest, tab)[0] : undefined;
const tab = tabOfPane(rest, pane);
const area = tab ? areaShowing(rest, tab) : undefined;
return tab && pane && area && agentIn(rest, pane) ? { tab, pane, area } : undefined;
return tab && area && agentIn(rest, pane) ? { tab, pane, area } : undefined;
}, "the first fixture agent in a tab of its own", 30_000);
viewPane(control, one.pane);
return { start, one };
return one;
}

/** The parent reports its session before it can name itself as one. */
Expand Down
11 changes: 4 additions & 7 deletions web/e2e/fixture-agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import path from "node:path";
import { prepareAgentInput, waitForAgentInput } from "./agent-pane";
import { claudeProjects, writeFixtureTranscript, type FixtureLabel } from "./pane-fixture";
import { agentIn, checkoutAt, closePane, focusTab, newTab, preparePaneInput, sendKeys, startedAgentIn, tabPanes, withControl, type AgentRow, type OpenedProject } from "./daemon-actions";
import { agentIn, closePane, focusTab, newTab, preparePaneInput, sendKeys, startAgentInCheckout, startedAgentIn, tabOfPane, withControl, type AgentRow, type OpenedProject } from "./daemon-actions";
import type { Daemon } from "./hided-fixture";
import type { AgentFixture, EngineServer } from "./engine-fixture";

Expand Down Expand Up @@ -126,13 +126,10 @@ export async function startAgentInProject(fixture: EngineServer, daemon: Pick<Da
const session = `project-agent-${process.pid}-${(projectAgents += 1)}`;
writeFixtureTranscript(claudeProjects(fixture), session, label);
return withControl(daemon, async (control) => {
control.send("agent_start_in_checkout", {
checkout_path: project.folder, provider: "claude", resume_session_id: session, request_id: `e2e-${session}`,
});
const pane = await startAgentInCheckout(control, project.folder, { resume_session_id: session }, `an agent in ${project.folder}`);
const made = await control.until((rest) => {
const tab = checkoutAt(rest, project.folder)?.tabs.find((id) => id !== project.tab);
const pane = tab ? tabPanes(rest, tab)[0] : undefined;
return tab && pane && agentIn(rest, pane) ? { tab, pane } : undefined;
const tab = tabOfPane(rest, pane);
return tab && agentIn(rest, pane) ? { tab, pane } : undefined;
}, `an agent in a tab of ${project.folder}`, 30_000);
// The engine learns the pane's session from the start's resume.
await closePane(control, project.pane);
Expand Down
11 changes: 4 additions & 7 deletions web/e2e/sidebar-menus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@

import { expect, test, type Locator, type Page } from "@playwright/test";
import { execFileSync } from "node:child_process";
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
import { agentIn, checkoutAt, closePane, openProject, tabPanes, tabsOf, withControl } from "./daemon-actions";
import { agentIn, checkoutAt, closePane, openProject, startAgentInCheckout, tabOfPane, tabsOf, withControl } from "./daemon-actions";
import { startEngine, type EngineServer } from "./engine-fixture";
import { setAgentSession } from "./fixture-agents";
import type { HidedControl } from "./hided-control.mjs";
Expand All @@ -41,12 +40,10 @@ function git(cwd: string, args: string[]): void {
*/
async function startAgentAt(server: EngineServer, daemon: Daemon, control: HidedControl, folder: string, session: string, task: string): Promise<{ tab: string; pane: string }> {
writeFixtureTranscript(claudeProjects(server), session, { task });
const known = await control.until((rest) => checkoutAt(rest, folder)?.tabs ?? [], "the snapshot");
control.send("agent_start_in_checkout", { checkout_path: folder, provider: "claude", resume_session_id: session, request_id: `e2e-${crypto.randomUUID()}` });
const pane = await startAgentInCheckout(control, folder, { resume_session_id: session }, `an agent in ${folder}`);
const started = await control.until((rest) => {
const tab = checkoutAt(rest, folder)?.tabs.find((id) => !known.includes(id));
const pane = tab ? tabPanes(rest, tab)[0] : undefined;
return tab && pane && agentIn(rest, pane) ? { tab, pane } : undefined;
const tab = tabOfPane(rest, pane);
return tab && agentIn(rest, pane) ? { tab, pane } : undefined;
}, `an agent in a new tab of ${folder}`, 30_000);
await setAgentSession(server, daemon, started.pane, session);
return started;
Expand Down
18 changes: 6 additions & 12 deletions web/e2e/sidebar-tab-groups.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { test, expect, type Page } from "@playwright/test";
import fs from "node:fs";
import path from "node:path";
import { toPage } from "../../desktop/src/main/wirePath";
import crypto from "node:crypto";
import { agentIn, areaShowing, checkoutAt, closePane, tabPanes, withControl } from "./daemon-actions";
import { agentIn, areaShowing, closePane, startAgentInCheckout, tabOfPane, withControl } from "./daemon-actions";
import { startFixture, type AgentFixture } from "./engine-fixture";
import { setAgentSession } from "./fixture-agents";
import { startHided } from "./hided-fixture";
Expand Down Expand Up @@ -33,18 +32,13 @@ const folderOf = (herdr: AgentFixture) => toPage(fs.realpathSync(path.join(herdr
async function startAgent(herdr: AgentFixture, daemon: Awaited<ReturnType<typeof startHided>>, beside?: string): Promise<{ tab: string; pane: string }> {
const folder = folderOf(herdr);
const started = await withControl(daemon, async (control) => {
const before = await control.until((rest) => checkoutAt(rest, folder)?.tabs, "the checkout's tabs");
const panesBefore = beside ? await control.until((rest) => tabPanes(rest, beside), `the panes of ${beside}`) : [];
const area = beside ? await control.until((rest) => areaShowing(rest, beside), `the area showing ${beside}`) : undefined;
control.send("agent_start_in_checkout", {
checkout_path: folder, provider: "claude", request_id: `e2e-${crypto.randomUUID()}`,
...(beside ? { target: { ...area, tab_id: beside, add_pane: true } } : {}),
});
const what = beside ? `a new agent beside ${beside}` : "a new agent in a tab of its own";
const pane = await startAgentInCheckout(control, folder, beside ? { target: { ...area, tab_id: beside, add_pane: true } } : {}, what);
return control.until((rest) => {
const tab = beside ?? checkoutAt(rest, folder)?.tabs.find((id) => !before.includes(id));
const pane = tab ? tabPanes(rest, tab).find((id) => !panesBefore.includes(id)) : undefined;
return tab && pane && agentIn(rest, pane) ? { tab, pane } : undefined;
}, beside ? `a new agent beside ${beside}` : "a new agent in a tab of its own", 30_000);
const tab = tabOfPane(rest, pane);
return tab && agentIn(rest, pane) ? { tab, pane } : undefined;
}, what, 30_000);
});
// The stand-in reports its session, as Claude Code does, and its start settles, so its row leaves Starting.
await setAgentSession(herdr, daemon, started.pane, `sidebar-${started.pane.replaceAll(":", "-")}`);
Expand Down
Loading