diff --git a/apps/server/package.json b/apps/server/package.json index 3c1bc59a62d06..9e1153de864df 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -25,6 +25,7 @@ "@anthropic-ai/claude-agent-sdk": "^0.3.260", "@effect/platform-bun": "catalog:", "@effect/platform-node": "catalog:", + "@effect/platform-node-shared": "catalog:", "@effect/sql-sqlite-bun": "catalog:", "@ff-labs/fff-node": "0.9.4", "@opencode-ai/sdk": "^1.3.15", diff --git a/docs/user/rtvision-wsl-ssh.md b/docs/user/rtvision-wsl-ssh.md index 2c9cdb36636e5..236904ef4df6f 100644 --- a/docs/user/rtvision-wsl-ssh.md +++ b/docs/user/rtvision-wsl-ssh.md @@ -183,14 +183,14 @@ enter a hostname that is not in the list. ## Troubleshooting -| Symptom | What to check | -| ------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| SSH credentials selector is missing | It is hidden in WSL-only mode, where WSL is already selected automatically. Otherwise enable a WSL backend to expose it. | -| Error says `via Windows OpenSSH` | The attempt is using Windows credentials. Select WSL, confirm the restart, and recreate a saved environment if it retained the old credentials source. | -| `Permission denied (publickey)` followed by a password prompt | The offered key was not accepted. Check the remote username, selected credentials source, key, and agent. A remote login password cannot fix a connection where the server permits only public-key authentication. | -| `No matching version found for @rtvision/t3@0.0.41` | Check the exact version in the RTVision mirror. If unavailable, use the matching release attachment and complete both fallback installation commands. | -| `t3 --version` works but adding still tries to download a missing version | A global executable is insufficient for the packaged 0.0.41 launcher. Run the exact `npx --package` verification from the remote home directory. | -| Adding stays busy for about a minute | Remote startup can wait about 60 seconds before reporting an installation or readiness failure. Read the resulting error; retries alone will not resolve it. Close and reopen the dialog after the attempt finishes. | +| Symptom | What to check | +| ------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| SSH credentials selector is missing | It is hidden in WSL-only mode, where WSL is already selected automatically. Otherwise enable a WSL backend to expose it. | +| Error says `via Windows OpenSSH` | The attempt is using Windows credentials. Select WSL, confirm the restart, and recreate a saved environment if it retained the old credentials source. | +| `Permission denied (publickey)` followed by a password prompt | The offered key was not accepted. Check the remote username, selected credentials source, key, and agent. A remote login password cannot fix a connection where the server permits only public-key authentication. | +| `No matching version found for @rtvision/t3@0.0.41` | Check the exact version in the RTVision mirror. If unavailable, use the matching release attachment and complete both fallback installation commands. | +| `t3 --version` works but adding still tries to download a missing version | A global executable is insufficient. Current desktops can reuse a complete service installation at the same version. The older 0.0.41 launcher requires the exact `npx --package` verification from the remote home directory. | +| Adding stays busy for about a minute | Remote startup can wait about 60 seconds before reporting an installation or readiness failure. Read the resulting error; retries alone will not resolve it. Close and reopen the dialog after the attempt finishes. | For more detail, inspect the remote account's `~/.t3/ssh-launch//server.log`. Logs may contain older attempts; diff --git a/knip.jsonc b/knip.jsonc index 1ac43b105269e..8db2776797ed5 100644 --- a/knip.jsonc +++ b/knip.jsonc @@ -25,7 +25,12 @@ "src/provider/testFixtures/*.mjs", ], // Native msgpack acceleration and the Vite+ web build prerequisite. - "ignoreDependencies": ["msgpackr-extract", "@t3tools/web"], + "ignoreDependencies": [ + "msgpackr-extract", + "@t3tools/web", + // Pins npm resolution; npm ignores overrides inside installed dependencies. + "@effect/platform-node-shared", + ], }, "apps/desktop": { // Electron loads these bundles by filename rather than importing them. diff --git a/packages/ssh/src/installedRuntime.test.ts b/packages/ssh/src/installedRuntime.test.ts new file mode 100644 index 0000000000000..148a595b56a7e --- /dev/null +++ b/packages/ssh/src/installedRuntime.test.ts @@ -0,0 +1,127 @@ +// @effect-diagnostics nodeBuiltinImport:off - Executes generated shell scripts against real runtime installations on disk. +import * as NodeChildProcess from "node:child_process"; +import * as NodeFSP from "node:fs/promises"; +import * as NodeOS from "node:os"; +import * as NodePath from "node:path"; +import * as NodeUtil from "node:util"; + +import { describe, expect, it } from "vite-plus/test"; + +import { HostProcessPlatform } from "@t3tools/shared/hostProcess"; + +import { buildRemoteT3RunnerScript } from "./tunnel.ts"; + +const execFile = NodeUtil.promisify(NodeChildProcess.execFile); +const version = "1.2.3"; +const packageName = "@rtvision/t3"; + +/** Runs the generated runner against isolated installed-runtime and npm-fallback fixtures. */ +async function fixture( + run: (input: { + root: string; + runtime: string; + packageDir: string; + execute: (options?: Parameters[0]) => Promise; + }) => Promise, +) { + const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3 installed runtime ")); + const runtime = NodePath.join(root, ".t3", "runtime", "versions", version); + const packageDir = NodePath.join(runtime, "node_modules", "t3"); + const bin = NodePath.join(root, "bin"); + try { + await NodeFSP.mkdir(NodePath.join(packageDir, "dist"), { recursive: true }); + await NodeFSP.mkdir(bin); + await NodeFSP.symlink(process.execPath, NodePath.join(bin, "node")); + await NodeFSP.writeFile( + NodePath.join(packageDir, "package.json"), + JSON.stringify({ name: packageName, version }), + ); + await NodeFSP.writeFile(NodePath.join(runtime, ".install-complete"), `${version}\n`); + await NodeFSP.writeFile( + NodePath.join(packageDir, "dist", "bin.mjs"), + 'process.stdout.write(JSON.stringify({ source: "installed", args: process.argv.slice(2) }));', + ); + const fallback = NodePath.join(root, "fallback"); + await NodeFSP.writeFile(fallback, '#!/bin/sh\nprintf "npm fallback"\n', { mode: 0o700 }); + await NodeFSP.writeFile( + NodePath.join(bin, "npx"), + "#!/usr/bin/env node\nprocess.stdout.write(process.env.T3_TEST_FALLBACK);\n", + { mode: 0o700 }, + ); + await run({ + root, + runtime, + packageDir, + execute: async (options) => { + const script = NodePath.join(root, "runner.sh"); + await NodeFSP.writeFile( + script, + buildRemoteT3RunnerScript({ packageSpec: `${packageName}@${version}`, ...options }), + ); + const result = await execFile( + "/bin/sh", + [script, "auth", "pairing", "create", "--base-dir", root, "--json"], + { env: { ...process.env, HOME: root, PATH: bin, T3_TEST_FALLBACK: fallback } }, + ); + return result.stdout; + }, + }); + } finally { + await NodeFSP.rm(root, { recursive: true, force: true }); + } +} + +describe.skipIf(HostProcessPlatform.defaultValue() === "win32")("installed remote CLI", () => { + it("pairs using the complete matching runtime without npm, preserving arguments and spaces", () => + fixture(async ({ root, execute }) => { + expect(JSON.parse(await execute())).toEqual({ + source: "installed", + args: ["auth", "pairing", "create", "--base-dir", root, "--json"], + }); + })); + + it.each([ + "incomplete", + "wrong-sentinel", + "invalid-manifest", + "wrong-package", + "wrong-version", + "missing-entry", + ] as const)("falls back to npm for a %s installation", (state) => + fixture(async ({ runtime, packageDir, execute }) => { + if (state === "incomplete") await NodeFSP.rm(NodePath.join(runtime, ".install-complete")); + if (state === "wrong-sentinel") + await NodeFSP.writeFile(NodePath.join(runtime, ".install-complete"), "1.2.2\n"); + if (state === "invalid-manifest") + await NodeFSP.writeFile(NodePath.join(packageDir, "package.json"), "{"); + if (state === "wrong-package" || state === "wrong-version") { + await NodeFSP.writeFile( + NodePath.join(packageDir, "package.json"), + JSON.stringify({ + name: state === "wrong-package" ? "t3" : packageName, + version: state === "wrong-version" ? "1.2.2" : version, + }), + ); + } + if (state === "missing-entry") await NodeFSP.rm(NodePath.join(packageDir, "dist", "bin.mjs")); + expect(await execute()).toBe("npm fallback"); + }), + ); + + it("does not reuse an older installation after a desktop update", () => + fixture(async ({ execute }) => { + expect(await execute({ packageSpec: `${packageName}@1.2.4` })).toBe("npm fallback"); + })); + + it("keeps explicit script overrides ahead of installed runtimes", () => + fixture(async ({ root, execute }) => { + const override = NodePath.join(root, "override.mjs"); + await NodeFSP.writeFile(override, 'process.stdout.write("explicit override");'); + expect(await execute({ nodeScriptPath: override })).toBe("explicit override"); + })); + + it("resolves dist-tags through npm", () => + fixture(async ({ execute }) => { + expect(await execute({ packageSpec: `${packageName}@latest` })).toBe("npm fallback"); + })); +}); diff --git a/packages/ssh/src/tunnel.ts b/packages/ssh/src/tunnel.ts index 61085b57ff4c9..b5b63627f32d8 100644 --- a/packages/ssh/src/tunnel.ts +++ b/packages/ssh/src/tunnel.ts @@ -430,6 +430,40 @@ if [ -n "$T3_NODE_SCRIPT_PATH" ]; then fi exec node "$T3_NODE_SCRIPT_PATH" "$@" fi +# Service updates install a complete, versioned runtime without adding it to +# PATH or npm's cache. Reuse that exact package for pairing as well as startup. +resolve_installed_cli() { + node - @@T3_PACKAGE_SPEC@@ <<'NODE' +const fs = require("node:fs"); +const path = require("node:path"); +try { + const spec = process.argv[2]; + const separator = spec.lastIndexOf("@"); + const name = spec.slice(0, separator); + const version = spec.slice(separator + 1); + if (separator <= 0 || !/^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$/.test(version)) { + process.exit(1); + } + const runtimeDir = path.join(process.env.HOME, ".t3", "runtime", "versions", version); + if (fs.readFileSync(path.join(runtimeDir, ".install-complete"), "utf8").trim() !== version) { + process.exit(1); + } + const packageDir = path.join(runtimeDir, "node_modules", "t3"); + const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, "package.json"), "utf8")); + const entry = path.join(packageDir, "dist", "bin.mjs"); + if (manifest.name !== name || manifest.version !== version || !fs.statSync(entry).isFile()) { + process.exit(1); + } + process.stdout.write(entry); +} catch { + process.exit(1); +} +NODE +} +T3_INSTALLED_CLI="$(resolve_installed_cli)" || true +if [ -n "$T3_INSTALLED_CLI" ]; then + exec node "$T3_INSTALLED_CLI" "$@" +fi # npm extracts a package before it runs the native builds of its dependencies, # so a failed build (t3 depends on node-pty, which needs a C toolchain) leaves # the npx cache without a t3 executable. \`npx --yes\` then exits 0 without diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2cba4e1a87718..d3e4fdaf2c7e6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -501,6 +501,9 @@ importers: '@effect/platform-node': specifier: 4.0.0-rc.112 version: 4.0.0-rc.112(bufferutil@4.1.0)(effect@4.0.0-rc.112(patch_hash=8bef799f35729cf3465eb428196f617b434a7c9f658d56acb2874d74b21b98b2))(redis@6.2.1)(utf-8-validate@6.0.6) + '@effect/platform-node-shared': + specifier: 4.0.0-rc.112 + version: 4.0.0-rc.112(bufferutil@4.1.0)(effect@4.0.0-rc.112(patch_hash=8bef799f35729cf3465eb428196f617b434a7c9f658d56acb2874d74b21b98b2))(utf-8-validate@6.0.6) '@effect/sql-sqlite-bun': specifier: 4.0.0-rc.112 version: 4.0.0-rc.112(effect@4.0.0-rc.112(patch_hash=8bef799f35729cf3465eb428196f617b434a7c9f658d56acb2874d74b21b98b2))