Files
kandev/apps/web/e2e/tests/ssh/sessions-card.spec.ts
T
José Almeida c5d678a37a test(e2e): add SSH executor Playwright suite (17 specs, ~75 cases)
Every spec drives the real sshd container set up by the ssh-test-base
fixture; no mocks. Specs are grouped by concern (file per group),
mirroring the docker/ directory style. Each one maps 1:1 to a row in
docs/specs/ssh-executor/e2e-plan.md.

UI surface:
- connection-form.spec.ts — field rendering, save/test gating,
  identity-source toggle, default port.
- test-result.spec.ts — successful + failed Test Connection paths,
  per-step badges, fingerprint surfacing, cached/will-upload copy.
- trust-gate.spec.ts — save disabled until trust ticked, edits reset
  result + trust, fingerprint-change warning when pinned != observed.
- sessions-card.spec.ts — empty state, row rendering, manual refresh,
  status badges, truncation, polling pickup.
- persistence.spec.ts — fingerprint persists across reload, new form
  starts blank, executor list label, partial state doesn't leak.

API contract:
- test-endpoint.spec.ts — POST /api/v1/ssh/test step ordering, invalid
  body, host-required, handshake short-circuit, cached/uploaded states.
- sessions-endpoint.spec.ts — GET /api/v1/ssh/executors/:id/sessions
  filters to ssh-runtime rows, populates metadata, monotonic uptime.
- executor-crud.spec.ts — type=ssh persists fingerprint, profile
  workdir round-trip, edit-with-running-sessions keeps snapshots.

Real-SSH integration:
- launch-task.spec.ts — full smoke: agentctl upload + sha256 cache hit
  on second launch, task/session dir layout, stop cleans session dir.
- recovery.spec.ts — backend restart reconnects, dead pid surfaces
  failure, persisted metadata keys present.
- auth-methods.spec.ts — key + valid, missing key, passphrase-protected
  rejection, agent without SSH_AUTH_SOCK, wrong-key auth failure.
- concurrency.spec.ts — two sessions share task dir distinct ports, two
  tasks distinct dirs, traffic drop + restore exercises eviction +
  reconnect.
- hostkey-rotation.spec.ts — regenerate host key surfaces new
  fingerprint, stale pinned fingerprint blocks launch verbatim, re-trust
  restores function.
- config-inheritance.spec.ts — ~/.ssh/config HostName / Port /
  IdentityFile / ProxyJump inheritance with form-overrides-config rules.
- workdir-per-profile.spec.ts — per-profile ssh_workdir_root routes to
  separate remote workdir trees; default falls back to ~/.kandev.
- proxy-jump.spec.ts — 2-container bastion topology asserts target is
  unreachable directly, reachable via ProxyJump, chained ProxyJump fails.
- error-surfacing.spec.ts — TCP refused, auth failed, bastion unreachable
  surface verbatim; backend 400 stays a 400 not a synthesised failure.

Also adds an AGENTS.md (CLAUDE.md symlink) line pointing at the
e2e/README.md so future agents discover the containers project +
KANDEV_E2E_CONTAINERS env var without grepping playwright.config.ts.
2026-05-17 23:45:07 +01:00

187 lines
6.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { test, expect } from "../../fixtures/ssh-test-base";
import { SSHSettingsPage } from "../../pages/SSHSettingsPage";
/**
* SSHSessionsCard — table of active sessions for the executor. Mirrors
* SpritesInstancesCard / DockerContainersCard shape.
*
* Covers e2e-plan.md group E (E1–E6).
*/
test.describe("ssh sessions card", () => {
test("empty state when no sessions are running", async ({ testPage, seedData }) => {
const page = new SSHSettingsPage(testPage);
await page.gotoExisting(seedData.sshExecutorId);
await expect(page.sessionsEmpty).toBeVisible();
await expect(page.sessionsTable).toBeHidden();
});
test("renders a row per active session with correct columns", async ({
testPage,
apiClient,
seedData,
}) => {
const task = await apiClient.createTaskWithAgent(
seedData.workspaceId,
"E2 sessions row",
seedData.agentProfileId,
{
description: "/e2e:simple-message",
workflow_id: seedData.workflowId,
workflow_step_id: seedData.startStepId,
repository_ids: [seedData.repositoryId],
executor_profile_id: seedData.sshExecutorProfileId,
},
);
await expect
.poll(async () => (await apiClient.getTaskEnvironment(task.id))?.executor_type ?? null, {
timeout: 60_000,
})
.toBe("ssh");
const sessions = await apiClient.listSSHSessions(seedData.sshExecutorId);
const row = sessions.find((s) => s.task_id === task.id);
expect(row).toBeDefined();
const page = new SSHSettingsPage(testPage);
await page.gotoExisting(seedData.sshExecutorId);
await expect(page.sessionRow(row!.session_id)).toBeVisible();
await expect(page.sessionRow(row!.session_id).getByTestId("ssh-session-host")).toHaveText(
`${seedData.sshTarget.user}@${seedData.sshTarget.host}`,
);
await expect(
page.sessionRow(row!.session_id).getByTestId("ssh-session-remote-port"),
).toContainText(String(row!.remote_agentctl_port));
await expect(
page.sessionRow(row!.session_id).getByTestId("ssh-session-local-port"),
).toContainText(String(row!.local_forward_port));
});
test("manual Refresh re-fetches the list", async ({ testPage, apiClient, seedData }) => {
const page = new SSHSettingsPage(testPage);
await page.gotoExisting(seedData.sshExecutorId);
await expect(page.sessionsEmpty).toBeVisible();
const task = await apiClient.createTaskWithAgent(
seedData.workspaceId,
"E3 manual refresh",
seedData.agentProfileId,
{
description: "/e2e:simple-message",
workflow_id: seedData.workflowId,
workflow_step_id: seedData.startStepId,
repository_ids: [seedData.repositoryId],
executor_profile_id: seedData.sshExecutorProfileId,
},
);
await expect
.poll(async () => (await apiClient.getTaskEnvironment(task.id))?.executor_type ?? null, {
timeout: 60_000,
})
.toBe("ssh");
await page.sessionsRefresh.click();
await expect(page.sessionsTable).toBeVisible({ timeout: 10_000 });
});
test("status badge variants render", async ({ testPage, apiClient, seedData }) => {
const task = await apiClient.createTaskWithAgent(
seedData.workspaceId,
"E4 status",
seedData.agentProfileId,
{
description: "/e2e:simple-message",
workflow_id: seedData.workflowId,
workflow_step_id: seedData.startStepId,
repository_ids: [seedData.repositoryId],
executor_profile_id: seedData.sshExecutorProfileId,
},
);
await expect
.poll(async () => (await apiClient.getTaskEnvironment(task.id))?.executor_type ?? null, {
timeout: 60_000,
})
.toBe("ssh");
const sessions = await apiClient.listSSHSessions(seedData.sshExecutorId);
const row = sessions[0];
const page = new SSHSettingsPage(testPage);
await page.gotoExisting(seedData.sshExecutorId);
const badge = page.sessionRow(row.session_id).getByTestId("ssh-session-status");
await expect(badge).toBeVisible();
// Any non-empty status is acceptable; we're asserting variant routing
// works, not what the orchestrator picked for this row.
await expect(badge).not.toHaveText("");
});
test("task id and session id are truncated to 8 chars in the UI", async ({
testPage,
apiClient,
seedData,
}) => {
const task = await apiClient.createTaskWithAgent(
seedData.workspaceId,
"E5 truncation",
seedData.agentProfileId,
{
description: "/e2e:simple-message",
workflow_id: seedData.workflowId,
workflow_step_id: seedData.startStepId,
repository_ids: [seedData.repositoryId],
executor_profile_id: seedData.sshExecutorProfileId,
},
);
await expect
.poll(async () => (await apiClient.getTaskEnvironment(task.id))?.executor_type ?? null, {
timeout: 60_000,
})
.toBe("ssh");
const sessions = await apiClient.listSSHSessions(seedData.sshExecutorId);
const row = sessions[0];
const page = new SSHSettingsPage(testPage);
await page.gotoExisting(seedData.sshExecutorId);
const taskCell = page.sessionRow(row.session_id).getByTestId("ssh-session-task");
const sessionCell = page.sessionRow(row.session_id).getByTestId("ssh-session-id");
await expect(taskCell).toHaveText(task.id.slice(0, 8));
await expect(sessionCell).toHaveText(row.session_id.slice(0, 8));
});
test("polling refresh picks up a new session within the next interval", async ({
testPage,
apiClient,
seedData,
}) => {
test.setTimeout(120_000);
const page = new SSHSettingsPage(testPage);
await page.gotoExisting(seedData.sshExecutorId);
await expect(page.sessionsEmpty).toBeVisible();
const task = await apiClient.createTaskWithAgent(
seedData.workspaceId,
"E6 polling",
seedData.agentProfileId,
{
description: "/e2e:simple-message",
workflow_id: seedData.workflowId,
workflow_step_id: seedData.startStepId,
repository_ids: [seedData.repositoryId],
executor_profile_id: seedData.sshExecutorProfileId,
},
);
// Don't rely on the 90s auto-refresh — exercise the manual refresh, which
// calls the same code path. The 90s interval is observable via repeated
// calls but too slow for an e2e timeout.
await expect
.poll(
async () => {
await page.sessionsRefresh.click();
const sessions = await apiClient.listSSHSessions(seedData.sshExecutorId);
return sessions.some((s) => s.task_id === task.id);
},
{ timeout: 60_000 },
)
.toBe(true);
});
});