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
3 changes: 2 additions & 1 deletion packages/shared/src/cliRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export const CLI_RELEASES_PAGE_URL = `https://github.com/${CLI_RELEASE_REPOSITOR
export const CLI_RELEASE_CHECKSUMS_FILE = "SHA256SUMS";
export const CLI_RELEASE_BASE_URL_ENV = "T3CODE_RELEASE_BASE_URL";

// Keep archive keys aligned with the Linux matrix, Windows ARM64 build, and cli_archive rows in release.yml.
// Keep archive keys aligned with the Linux matrix, Windows ARM64 build, and cli_archive rows in release.yml,
// and with the SSH runner's host check in packages/ssh/src/tunnel.ts.
// Node single-executables do not support darwin-x64 and segfault at startup.
const CLI_ARCHIVE_PLATFORM_KEYS = [
"darwin-arm64",
Expand Down
46 changes: 46 additions & 0 deletions packages/ssh/src/tunnel.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// @effect-diagnostics nodeBuiltinImport:off - Runs the generated runner in a real shell.
import * as NodeChildProcess from "node:child_process";
import * as NodeFS from "node:fs";
import * as NodeOS from "node:os";
import * as NodePath from "node:path";

import { assert, describe, it } from "@effect/vitest";
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
import * as NodeServices from "@effect/platform-node/NodeServices";
Expand Down Expand Up @@ -108,6 +114,46 @@ describe("ssh tunnel scripts", () => {
);
});

it.each([
{ host: "Darwin x86_64", system: "Darwin", machine: "x86_64", downloads: false },
{ host: "Darwin arm64", system: "Darwin", machine: "arm64", downloads: true },
])(
"only downloads a release archive the host can run: $host",
({ system, machine, downloads }) => {
const root = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-ssh-runner-"));
try {
const bin = NodePath.join(root, "bin");
NodeFS.mkdirSync(bin);
NodeFS.mkdirSync(NodePath.join(root, "home"));
NodeFS.writeFileSync(
NodePath.join(bin, "uname"),
`#!/bin/sh\ncase "$1" in -s) echo ${system} ;; -m) echo ${machine} ;; esac\n`,
{ mode: 0o755 },
);
NodeFS.writeFileSync(
NodePath.join(bin, "curl"),
"#!/bin/sh\necho 'download attempt' >&2\nexit 22\n",
{ mode: 0o755 },
);
const runner = NodePath.join(root, "run-t3.sh");
NodeFS.writeFileSync(runner, SshTunnel.buildRemoteT3RunnerScript(ARCHIVE));
const result = NodeChildProcess.spawnSync("sh", [runner, "--version"], {
encoding: "utf8",
env: { HOME: NodePath.join(root, "home"), PATH: `${bin}:${process.env.PATH ?? ""}` },
});
assert.notEqual(result.status, 0);
if (downloads) {
assert.include(result.stderr, "download attempt");
} else {
assert.notInclude(result.stderr, "download attempt");
assert.include(result.stderr, "has no t3 release archive.");
}
} finally {
NodeFS.rmSync(root, { recursive: true, force: true });
}
},
);

it.effect("accepts launch JSON after remote shell startup noise", () => {
const target = {
alias: "devbox",
Expand Down
17 changes: 7 additions & 10 deletions packages/ssh/src/tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,17 +475,14 @@ if ! t3_runtime_ready; then
trap 'rm -rf "$T3_LOCK"' EXIT
fi
if ! t3_runtime_ready; then
case "$(uname -s)" in
Darwin) T3_PLATFORM="darwin" ;;
Linux) T3_PLATFORM="linux" ;;
*) printf 'Remote host %s has no t3 release archive.\\n' "$(uname -s)" >&2; exit 1 ;;
# Keep aligned with CLI_ARCHIVE_PLATFORM_KEYS in packages/shared/src/cliRelease.ts.
case "$(uname -s) $(uname -m)" in
"Darwin arm64") T3_PLATFORM_KEY="darwin-arm64" ;;
"Linux arm64" | "Linux aarch64") T3_PLATFORM_KEY="linux-arm64" ;;
"Linux x86_64" | "Linux amd64") T3_PLATFORM_KEY="linux-x64" ;;
*) printf 'Remote host %s has no t3 release archive.\\n' "$(uname -s) $(uname -m)" >&2; exit 1 ;;
esac
case "$(uname -m)" in
arm64 | aarch64) T3_ARCH="arm64" ;;
x86_64 | amd64) T3_ARCH="x64" ;;
*) printf 'Remote host %s has no t3 release archive.\\n' "$(uname -m)" >&2; exit 1 ;;
esac
T3_ARCHIVE="t3-$T3_ARCHIVE_VERSION-$T3_PLATFORM-$T3_ARCH.tar.gz"
T3_ARCHIVE="t3-$T3_ARCHIVE_VERSION-$T3_PLATFORM_KEY.tar.gz"
T3_STAGING="$(mktemp -d "$HOME/.t3/runtime/versions/.staging-XXXXXX")"
trap 'rm -rf "$T3_STAGING" "$T3_LOCK"' EXIT
t3_fetch() {
Expand Down
Loading