c5d678a37a
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.
125 lines
4.5 KiB
TypeScript
125 lines
4.5 KiB
TypeScript
import { test, expect } from "../../fixtures/ssh-test-base";
|
||
import { killRemotePid, readRemoteFile } from "../../helpers/ssh";
|
||
import { waitForLatestSessionDone } from "../../helpers/session";
|
||
|
||
/**
|
||
* Backend-restart recovery. Persisted ExecutorRunning metadata
|
||
* (ssh_host, ssh_remote_agentctl_pid, ssh_remote_agentctl_port, etc.) drives
|
||
* ResumeRemoteInstance — re-dial the SSH connection, re-forward the recorded
|
||
* remote port, verify `kill -0 pid`, and reattach the stream manager.
|
||
*
|
||
* Covers e2e-plan.md group J (J1–J4).
|
||
*/
|
||
test.describe("ssh executor — recovery after restart", () => {
|
||
test("live session survives a backend restart", async ({ apiClient, seedData, backend }) => {
|
||
test.setTimeout(240_000);
|
||
const task = await apiClient.createTaskWithAgent(
|
||
seedData.workspaceId,
|
||
"J1 backend restart",
|
||
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 waitForLatestSessionDone(apiClient, task.id, 1, "Pre-restart launch");
|
||
|
||
const beforeSessions = await apiClient.listSSHSessions(seedData.sshExecutorId);
|
||
const beforeRow = beforeSessions.find((s) => s.task_id === task.id);
|
||
expect(beforeRow).toBeDefined();
|
||
const beforeRemotePort = beforeRow!.remote_agentctl_port;
|
||
|
||
await backend.restart();
|
||
|
||
await expect
|
||
.poll(
|
||
async () => {
|
||
const sessions = await apiClient.listSSHSessions(seedData.sshExecutorId);
|
||
const row = sessions.find((s) => s.task_id === task.id);
|
||
// Resume should land back on the same remote port (the agentctl
|
||
// process is unchanged) but a *new* local forward port.
|
||
return row && row.remote_agentctl_port === beforeRemotePort
|
||
? row.local_forward_port
|
||
: null;
|
||
},
|
||
{ timeout: 60_000 },
|
||
)
|
||
.toBeGreaterThan(0);
|
||
});
|
||
|
||
test("backend restart with a dead remote agentctl marks the execution stopped", async ({
|
||
apiClient,
|
||
seedData,
|
||
backend,
|
||
}) => {
|
||
test.setTimeout(240_000);
|
||
const task = await apiClient.createTaskWithAgent(
|
||
seedData.workspaceId,
|
||
"J2 dead agentctl",
|
||
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 waitForLatestSessionDone(apiClient, task.id, 1, "Launch before kill");
|
||
|
||
const sessions = await apiClient.listSSHSessions(seedData.sshExecutorId);
|
||
const row = sessions.find((s) => s.task_id === task.id);
|
||
expect(row).toBeDefined();
|
||
const sessionDir = `${row!.remote_task_dir}/.kandev/sessions/${row!.session_id}`;
|
||
const pidStr = readRemoteFile(seedData.sshTarget, `${sessionDir}/agentctl.pid`).trim();
|
||
const pid = parseInt(pidStr, 10);
|
||
expect(pid).toBeGreaterThan(0);
|
||
|
||
killRemotePid(seedData.sshTarget, pid);
|
||
|
||
await backend.restart();
|
||
|
||
await expect
|
||
.poll(
|
||
async () => {
|
||
const after = await apiClient.listSSHSessions(seedData.sshExecutorId);
|
||
const r = after.find((s) => s.task_id === task.id);
|
||
return r?.status ?? "absent";
|
||
},
|
||
{ timeout: 60_000 },
|
||
)
|
||
.not.toBe("running");
|
||
});
|
||
|
||
test("persisted metadata keys are present in ExecutorRunning after launch", async ({
|
||
apiClient,
|
||
seedData,
|
||
}) => {
|
||
test.setTimeout(180_000);
|
||
const task = await apiClient.createTaskWithAgent(
|
||
seedData.workspaceId,
|
||
"J4 persisted metadata",
|
||
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 waitForLatestSessionDone(apiClient, task.id, 1, "Launch for metadata");
|
||
|
||
const sessions = await apiClient.listSSHSessions(seedData.sshExecutorId);
|
||
const row = sessions.find((s) => s.task_id === task.id);
|
||
expect(row?.host).toBe(seedData.sshTarget.host);
|
||
expect(row?.user).toBe(seedData.sshTarget.user);
|
||
expect(row?.remote_agentctl_port).toBeGreaterThan(0);
|
||
expect(row?.local_forward_port).toBeGreaterThan(0);
|
||
expect(row?.remote_task_dir).toMatch(/\/tasks\//);
|
||
});
|
||
});
|