Skip to content

Commit 08de6cc

Browse files
committed
fix(cli): gate session-host installer capability
1 parent aadb476 commit 08de6cc

6 files changed

Lines changed: 102 additions & 20 deletions

File tree

‎docs/cli/connect.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ hosting and exact capacity from this durable consent when it starts.
106106
- an `oc-pair://<setup-code>` URL;
107107
- a bare base64url setup code.
108108

109+
`--target-file <path>` reads the target from a private file and removes that file
110+
after reading it. The dormant installer wrapper uses this handoff to keep the
111+
single-use target out of child-process arguments.
112+
109113
Join URLs must use HTTPS. Plain HTTP is accepted only for loopback Gateway URLs
110114
such as `http://127.0.0.1/j/<shortcode>`. Direct setup codes can carry the
111115
Gateway TLS certificate fingerprint, which lets the node host pin a self-signed

‎docs/plan/runners.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,13 @@ get here, Tailscale's key/device revocation split is the documented model):
302302
Repository preparation now includes a dormant `scripts/connect.sh` wrapper.
303303
It requires an exact OpenClaw version, installs that version into the dedicated
304304
CLI prefix, and hands the join target to `openclaw connect --service
305-
--session-host` through a private temporary file. The wrapper is not hosted,
306-
website-synced, or emitted by the UI or devices CLI in this slice. Public
307-
activation still requires an explicitly authorized stable release and publish,
308-
followed by a separate activation change that hosts and emits the released
309-
wrapper.
305+
--session-host` through a private temporary file. Before creating that file, it
306+
verifies the installed exact CLI's `connect --help` advertises `--target-file`,
307+
`--service`, and `--session-host`; unsupported versions fail before the
308+
single-use target is handed off. The wrapper is not hosted, website-synced, or
309+
emitted by the UI or devices CLI in this slice. Public activation still requires
310+
an explicitly authorized stable release and publish, followed by a separate
311+
activation change that hosts and emits the released wrapper.
310312

311313
### Bundle and updates (milestone 7)
312314

‎scripts/connect.sh‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@ bash "$INSTALLER_PATH" --version "$VERSION" --prefix "$PREFIX" --no-onboard
189189
OPENCLAW_BIN="${PREFIX}/bin/openclaw"
190190
[[ -x "$OPENCLAW_BIN" ]] || fail "Installed OpenClaw CLI is missing at ${OPENCLAW_BIN}. Check the installer output and retry."
191191

192+
CAPABILITY_ERROR="The selected exact version ${VERSION} does not support session-host onboarding. Choose a newer supporting exact version and retry."
193+
if ! CONNECT_HELP="$("$OPENCLAW_BIN" connect --help 2>&1)"; then
194+
fail "$CAPABILITY_ERROR"
195+
fi
196+
for required_flag in --target-file --service --session-host; do
197+
if ! grep -Eq -- "^[[:space:]]+${required_flag}([[:space:]=<]|$)" <<<"$CONNECT_HELP"; then
198+
fail "$CAPABILITY_ERROR"
199+
fi
200+
done
201+
unset CONNECT_HELP
202+
192203
: >"$TARGET_FILE"
193204
chmod 0600 "$TARGET_FILE"
194205
printf '%s\n' "$JOIN_TARGET" >"$TARGET_FILE"

‎src/cli/connect-cli.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ describe("connect cli", () => {
6363
mocks.runtime.exit.mockImplementation(() => {});
6464
});
6565

66+
it("advertises the wrapper-required connect options", () => {
67+
const program = new Command();
68+
registerConnectCli(program);
69+
const help = program.commands[0]?.helpInformation() ?? "";
70+
71+
expect(help).toMatch(/^[ \t]+--target-file <path>(?:[ \t]|$)/mu);
72+
expect(help).toMatch(/^[ \t]+--service(?:[ \t]|$)/mu);
73+
expect(help).toMatch(/^[ \t]+--session-host(?:[ \t]|$)/mu);
74+
});
75+
6676
it.each([
6777
{ name: "bare setup code", target: () => setupCode(), fetched: false },
6878
{ name: "oc-pair wrapper", target: () => `oc-pair://${setupCode()}`, fetched: false },

‎src/cli/connect-cli.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// One-paste node onboarding from setup codes or single-use Gateway join URLs.
22
import fs from "node:fs/promises";
3-
import { Option, type Command } from "commander";
3+
import type { Command } from "commander";
44
import {
55
buildCloudflareAccessHeaders,
66
CF_ACCESS_CLIENT_ID_HEADER,
@@ -262,7 +262,7 @@ export function registerConnectCli(program: Command): void {
262262
"Host worker sessions (process-scoped unless installed as a service)",
263263
false,
264264
)
265-
.addOption(new Option("--target-file <path>").hideHelp())
265+
.option("--target-file <path>", "Read the connect target from a private file and remove it")
266266
.option("--display-name <name>", "Override the node display name")
267267
.addHelpText(
268268
"after",

‎test/scripts/connect-installer.test.ts‎

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
import { spawnSync } from "node:child_process";
2-
import { chmodSync, existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3-
import { tmpdir } from "node:os";
2+
import { chmodSync, existsSync, readFileSync, writeFileSync } from "node:fs";
43
import { dirname, join } from "node:path";
54
import { afterEach, describe, expect, it } from "vitest";
5+
import { useAutoCleanupTempDirTracker } from "../helpers/temp-dir.js";
66

77
const SCRIPT_PATH = "scripts/connect.sh";
8-
const tempDirs: string[] = [];
9-
10-
afterEach(() => {
11-
for (const path of tempDirs.splice(0)) {
12-
rmSync(path, { force: true, recursive: true });
13-
}
14-
});
8+
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
159

1610
function createFixture() {
17-
const root = mkdtempSync(join(tmpdir(), "openclaw-connect-installer-"));
18-
tempDirs.push(root);
11+
const root = tempDirs.make("openclaw-connect-installer-");
1912
const installer = join(root, "install-cli.sh");
2013
const installArgs = join(root, "install-args");
14+
const helpArgs = join(root, "help-args");
2115
const connectArgs = join(root, "connect-args");
2216
const targetContent = join(root, "target-content");
17+
const targetCreatedBeforeHelp = join(root, "target-created-before-help");
2318
const targetMode = join(root, "target-mode");
2419
const targetPath = join(root, "target-path");
2520
writeFileSync(
@@ -39,6 +34,19 @@ mkdir -p "$prefix/bin"
3934
cat >"$prefix/bin/openclaw" <<'OPENCLAW'
4035
#!/usr/bin/env bash
4136
set -euo pipefail
37+
if [[ "$#" -eq 2 && "$1" == "connect" && "$2" == "--help" ]]; then
38+
printf '%s\n' "$@" >"$FAKE_HELP_ARGS"
39+
target_files=("\${TMPDIR:-/tmp}"/openclaw-connect.*/join-target)
40+
if [[ -e "\${target_files[0]}" ]]; then
41+
: >"$FAKE_TARGET_CREATED_BEFORE_HELP"
42+
fi
43+
if [[ -n "\${FAKE_CONNECT_HELP:-}" ]]; then
44+
printf '%s\n' "$FAKE_CONNECT_HELP"
45+
else
46+
printf '%s\n' ' --target-file <path>' ' --service' ' --session-host'
47+
fi
48+
exit "\${FAKE_HELP_EXIT:-0}"
49+
fi
4250
printf '%s\n' "$@" >"$FAKE_CONNECT_ARGS"
4351
target_file=""
4452
while [[ $# -gt 0 ]]; do
@@ -65,8 +73,10 @@ chmod 0755 "$prefix/bin/openclaw"
6573
root,
6674
installer,
6775
installArgs,
76+
helpArgs,
6877
connectArgs,
6978
targetContent,
79+
targetCreatedBeforeHelp,
7080
targetMode,
7181
targetPath,
7282
};
@@ -84,10 +94,13 @@ function runWrapper(
8494
...process.env,
8595
OPENCLAW_INSTALL_CLI_URL: fixture.installer,
8696
FAKE_INSTALL_ARGS: fixture.installArgs,
97+
FAKE_HELP_ARGS: fixture.helpArgs,
8798
FAKE_CONNECT_ARGS: fixture.connectArgs,
8899
FAKE_TARGET_CONTENT: fixture.targetContent,
100+
FAKE_TARGET_CREATED_BEFORE_HELP: fixture.targetCreatedBeforeHelp,
89101
FAKE_TARGET_MODE: fixture.targetMode,
90102
FAKE_TARGET_PATH: fixture.targetPath,
103+
TMPDIR: fixture.root,
91104
...env,
92105
},
93106
});
@@ -105,18 +118,20 @@ describe("scripts/connect.sh", () => {
105118

106119
const result = runWrapper(
107120
fixture,
108-
["--version", "2026.7.1-2", "--prefix", prefix, "--display-name", "Runner Node", target],
121+
["--version", "2026.8.1", "--prefix", prefix, "--display-name", "Runner Node", target],
109122
{ HOME: undefined },
110123
);
111124

112125
expect(result.status, result.stderr).toBe(0);
113126
expect(readArgs(fixture.installArgs)).toEqual([
114127
"--version",
115-
"2026.7.1-2",
128+
"2026.8.1",
116129
"--prefix",
117130
prefix,
118131
"--no-onboard",
119132
]);
133+
expect(readArgs(fixture.helpArgs)).toEqual(["connect", "--help"]);
134+
expect(existsSync(fixture.targetCreatedBeforeHelp)).toBe(false);
120135
const connectArgs = readArgs(fixture.connectArgs);
121136
const privateTargetPath = readFileSync(fixture.targetPath, "utf8").trim();
122137
expect(connectArgs).toEqual([
@@ -137,6 +152,46 @@ describe("scripts/connect.sh", () => {
137152
expect(existsSync(dirname(privateTargetPath))).toBe(false);
138153
});
139154

155+
it.each([
156+
{ name: "the help probe fails", env: { FAKE_HELP_EXIT: "2" } },
157+
{
158+
name: "help omits --target-file",
159+
env: { FAKE_CONNECT_HELP: " --service\n --session-host" },
160+
},
161+
{
162+
name: "help omits --service",
163+
env: { FAKE_CONNECT_HELP: " --target-file <path>\n --session-host" },
164+
},
165+
{
166+
name: "help omits --session-host",
167+
env: { FAKE_CONNECT_HELP: " --target-file <path>\n --service" },
168+
},
169+
])("rejects an installed CLI when $name", ({ env }) => {
170+
const fixture = createFixture();
171+
const prefix = join(fixture.root, "prefix");
172+
const target = "oc-pair://private-join-target";
173+
174+
const result = runWrapper(
175+
fixture,
176+
["--version", "2026.7.1-2", "--prefix", prefix, target],
177+
env,
178+
);
179+
180+
expect(result.status).toBe(1);
181+
expect(readArgs(fixture.installArgs)).toContain("2026.7.1-2");
182+
expect(readArgs(fixture.helpArgs)).toEqual(["connect", "--help"]);
183+
expect(result.stderr).toContain(
184+
"selected exact version 2026.7.1-2 does not support session-host onboarding",
185+
);
186+
expect(result.stderr).toContain("Choose a newer supporting exact version");
187+
expect(result.stderr.match(/ERROR:/gu)).toHaveLength(1);
188+
expect(existsSync(fixture.targetCreatedBeforeHelp)).toBe(false);
189+
expect(existsSync(fixture.connectArgs)).toBe(false);
190+
expect(existsSync(fixture.targetPath)).toBe(false);
191+
expect(existsSync(fixture.targetContent)).toBe(false);
192+
expect(`${result.stdout}\n${result.stderr}`).not.toContain(target);
193+
});
194+
140195
it("respects OPENCLAW_PREFIX when --prefix is omitted", () => {
141196
const fixture = createFixture();
142197
const prefix = join(fixture.root, "env-prefix");

0 commit comments

Comments
 (0)