diff --git a/src/remote/connect.ts b/src/remote/connect.ts index a6bc3af..44406ce 100644 --- a/src/remote/connect.ts +++ b/src/remote/connect.ts @@ -9,7 +9,11 @@ import type { Trace } from "../telemetry" // extension does (coder/vscode-coder docs/ARCHITECTURE.md): `spin code --start` starts it, // attaches this VS Code's server, writes the ssh config, and connects once through it - which runs // `spin ssh-prepare` and its launch-claim check - so a refusal is the CLI's error, with its action, -// here. A failure closes the remote, so Remote-SSH does not go on to fail its own way. +// here, first. A failure then closes the remote. That does not stop Remote-SSH: VS Code calls its +// resolver once this activation returns, and holding the activation instead holds the window's +// unload on that resolution forever. So Remote-SSH still connects once, and says briefly that it +// could not: spin code keeps its refusal marked as told, and the ssh-proxy of Remote-SSH's ssh +// ends at once on the same refusal rather than ask again (spin's toldAlready). export type ConnectCli = Pick diff --git a/test/remote-ssh/run.mjs b/test/remote-ssh/run.mjs index ee48c9b..8dc5c76 100644 --- a/test/remote-ssh/run.mjs +++ b/test/remote-ssh/run.mjs @@ -10,8 +10,9 @@ // - stopped: the same, with the workspace started by that `spin code --start`, and no error of // Remote-SSH's; // - unenrolled: with a key the account does not have, Spinbox says key_not_enrolled (whose -// action is Add Key), Remote-SSH never resolves, and once the message is closed - READ_MS -// after it is said, as a person reads it - the window leaves the remote. +// action is Add Key) and Remote-SSH waits while it is up. Once it is closed - READ_MS after it +// is said, as a person reads it - Remote-SSH resolves once, spin ends its ssh at once (no +// askpass, no ConnectTimeout), its error follows within seconds, and the window is local. // // SPIN_STACK names the spin checkout whose stack is up: its bin/spin, and the fixture user's home // hack/e2estack keeps. Each case runs in bubblewrap with a home of its own bound over $HOME, since @@ -53,6 +54,11 @@ const only = process.env.CASES?.split(",") const WAIT_MS = 360_000 // How long the unenrolled case leaves Spinbox's message up before closing it. const READ_MS = Number(process.env.READ_MS ?? 30_000) +// What "at once" is for a refused Remote-SSH's ssh: well under its 15 s ConnectTimeout. +const QUICK_MS = 5_000 +// How long the window may take to start again, local: Remote-SSH's local server and its ssh, then +// the unload - 10 s on a host at load 22. Waiting out the ConnectTimeout alone took 17 s. +const LEAVE_MS = 15_000 const say = (line) => console.log(`==> ${line}`) @@ -154,13 +160,15 @@ async function openCase(name, workspace, { enrolled, until }) { // An empty system ssh config: in bubblewrap's namespace root's files are nobody's, which ssh // refuses to read. writeFileSync(join(dir, "ssh_config"), "") - // Each spin the extension runs, said with when it started and ended, around the real one. + // Each spin the extension runs, said with when it started and ended, around the real one. The + // time is bash's own clock read, in ms: uutils' `date +%s%3N` mixed one instant's seconds with + // another's milliseconds on a loaded host, and wrote an end before its start. const calls = join(dir, "spin-calls.log") const wrapper = join(dir, "spin") - const stamp = (what) => `echo "$(date +%s%3N) ${what} $*" >> ${calls}` + const stamp = (what) => `t=\${EPOCHREALTIME/./}; echo "\${t%???} ${what} $*" >> ${calls}` writeFileSync( wrapper, - `#!/bin/sh\n${stamp("start")}\n${spin} "$@"\nrc=$?\n${stamp("end $rc")}\nexit $rc\n`, + `#!/bin/bash\n${stamp("start")}\n${spin} "$@"\nrc=$?\n${stamp("end $rc")}\nexit $rc\n`, ) chmodSync(wrapper, 0o755) mkdirSync(join(userData, "User"), { recursive: true }) @@ -228,6 +236,7 @@ async function openCase(name, workspace, { enrolled, until }) { spinbox: logOf(userData, "Spinbox.log"), remoteSSH: logOf(userData, "Remote - SSH.log"), exthost: logOf(userData, "exthost.log"), + renderer: logOf(userData, "renderer.log"), }) let s = seen() const end = Date.now() + WAIT_MS @@ -348,14 +357,39 @@ const cases = { o.resolving === undefined || o.resolvingMs >= dismissed?.t, [o.end, `message closed at ${dismissed?.t}`, `Remote-SSH: ${o.resolving}`], ) - check("unenrolled: Remote-SSH never resolved", o.resolving === undefined, o.resolving) - const errors = errorsOf(s) - check("unenrolled: Remote-SSH said no error", errors.length === 0, errors.slice(0, 5)) + // Then Remote-SSH connects once anyway (src/remote/connect.ts), and is ended at once by spin's + // ssh-proxy: no askpass box, no wait for its ConnectTimeout. + // From Remote-SSH's ssh: what comes before it is Remote-SSH starting its local server. + const spawned = s.remoteSSH.find((l) => /Spawned ssh, pid=/.test(l)) + const spawnedMs = spawned === undefined ? undefined : timeOf(spawned, s.started) + const gaveUp = errorsOf(s)[0] + const gaveUpMs = gaveUp === undefined ? undefined : timeOf(gaveUp, s.started) + check( + `unenrolled: Remote-SSH's error came within ${QUICK_MS / 1000} s of its ssh`, + spawnedMs !== undefined && gaveUpMs !== undefined && gaveUpMs - spawnedMs <= QUICK_MS, + [o.resolving, spawned, gaveUp], + ) + const asked = s.remoteSSH.filter((l) => /askpass request|banner exchange/i.test(l)) + check("unenrolled: Remote-SSH's ssh asked nothing and waited for nothing", asked.length === 0, [ + ...asked.slice(0, 3), + s.remoteSSH.find((l) => l.includes("as the editor already said")), + ]) + // The window that replaces the remote one starts when the renderer starts up again; the + // probe's activation in it says it is local, and comes when its extension host does, later. + const reopened = s.renderer.filter((l) => l.includes("[lifecycle] starting up"))[1] + const reopenedMs = reopened === undefined ? undefined : Date.parse(reopened.slice(0, 23)) const left = s.probe.filter((e) => e.event === "activate").at(-1) check( - "unenrolled: the window left the remote within 5 s of the message closing", - left?.remoteName === null && dismissed !== undefined && left.t - dismissed.t <= 5_000, - `message closed at ${dismissed?.t}, window local at ${left?.t} (remoteName=${left?.remoteName})`, + `unenrolled: the window left the remote within ${LEAVE_MS / 1000} s of the message closing`, + left?.remoteName === null && + dismissed !== undefined && + reopenedMs !== undefined && + reopenedMs - dismissed.t <= LEAVE_MS, + [ + `message closed at ${new Date(dismissed?.t).toISOString()}`, + `window started again: ${reopened}`, + `probe in it: remoteName=${left?.remoteName}`, + ], ) }, }