Skip to content

Open-source, local-first social media research agent for Instagram, TikTok, and LinkedIn. Jev routes read-only steps; socai CLI captures cited browser evidence.

fix: do not auto-install socai during non-interactive onboarding (#117)

Giridhar Patil54266caf8cf5
diff --git a/README.md b/README.md
index 56921bd..79b9bbc 100644
--- a/README.md
+++ b/README.md
@@ -33,7 +33,7 @@ npx github:socai-io/jev-social#v0.1.13 onboard
npx github:socai-io/jev-social#v0.1.13
```
-With the default OpenRouter provider, onboarding prompts for the OpenRouter key. On macOS and Windows, onboarding can also install the official `socai CLI` when it is missing. On Linux, install a current `socai CLI` from source first, then put it on `PATH` or set `SOCAI_BIN`. The second command opens the loopback-only demo.
+With the default OpenRouter provider, onboarding prompts for the OpenRouter key. On macOS and Windows, onboarding can also install the official `socai CLI` when it is missing. On Linux, install a current `socai CLI` from source first, then put it on `PATH` or set `SOCAI_BIN`. Unattended or non-interactive installation requires the explicit `--install` flag. The second command opens the loopback-only demo.
![Earlier routing-only demo](https://raw.githubusercontent.com/socai-io/jev-social/main/docs/jev-social.gif)
diff --git a/bin/jev-social.js b/bin/jev-social.js
index 8a07153..2aa23e7 100755
--- a/bin/jev-social.js
+++ b/bin/jev-social.js
@@ -7,7 +7,7 @@ import { runSearch } from "../src/app.js";
import { getConfigPath, readConfig, resolveApiKey } from "../src/config.js";
import { resolveDecisionProvider } from "../src/decision-provider.js";
import { loadLocalEnv } from "../src/env.js";
-import { saveOnboarding } from "../src/onboard.js";
+import { saveOnboarding, resolveSocaiInstallDecision } from "../src/onboard.js";
import { probeSocai } from "../src/socai.js";
import { startServer } from "../src/server.js";
@@ -29,7 +29,7 @@ Search options:
Configuration (normally auto-loaded from .env):
--api-key <key> OpenRouter API key (prompt is safer)
--socai-bin <path> socai executable override
- --install Install/reinstall official socai CLI
+ --install Install/reinstall official socai CLI (required for unattended install)
--skip-install Do not offer CLI installation
--no-verify Save API key without a network check
@@ -117,9 +117,20 @@ async function onboard(flags) {
const proposed = { ...current, ...(flags.socaiBin ? { socaiBin: flags.socaiBin } : {}) };
const before = await probeSocai(proposed);
- let installCli = Boolean(flags.install);
- if (!before.installed && !flags.skipInstall && !flags.install) {
- installCli = await promptYesNo("socai CLI was not found. Install the official release now?", true);
+ let installCli = resolveSocaiInstallDecision({
+ installed: before.installed,
+ install: flags.install,
+ skipInstall: flags.skipInstall,
+ isTTY: stdin.isTTY,
+ });
+ if (!before.installed && !flags.skipInstall && !flags.install && stdin.isTTY) {
+ const userChoice = await promptYesNo("socai CLI was not found. Install the official release now?", true);
+ installCli = resolveSocaiInstallDecision({
+ installed: before.installed,
+ install: userChoice,
+ skipInstall: !userChoice,
+ isTTY: stdin.isTTY,
+ });
}
console.log("Checking setup…");
@@ -178,7 +189,7 @@ function parseArgs(args) {
}
async function promptYesNo(question, defaultYes) {
- if (!stdin.isTTY) return defaultYes;
+ if (!stdin.isTTY) return false;
const rl = readline.createInterface({ input: stdin, output: stdout });
try {
const answer = (await rl.question(`${question} ${defaultYes ? "[Y/n]" : "[y/N]"} `)).trim().toLowerCase();
diff --git a/src/onboard.js b/src/onboard.js
index ca8bc98..47c2f84 100644
--- a/src/onboard.js
+++ b/src/onboard.js
@@ -111,4 +111,14 @@ export async function saveOnboarding({
};
}
+export function resolveSocaiInstallDecision({ installed, install, skipInstall, isTTY, answer = "" }) {
+ if (install) return true;
+ if (skipInstall) return false;
+ if (installed) return false;
+ if (!isTTY) return false;
+ const trimmed = String(answer).trim().toLowerCase();
+ if (!trimmed) return true;
+ return trimmed === "y" || trimmed === "yes";
+}
+
export const verifyTypesafeApiKey = verifyOpenRouterApiKey;
diff --git a/test-support/forbid-fetch.js b/test-support/forbid-fetch.js
new file mode 100644
index 0000000..f63afa0
--- /dev/null
+++ b/test-support/forbid-fetch.js
@@ -0,0 +1,3 @@
+globalThis.fetch = () => {
+ throw new Error("Network access forbidden in offline test context.");
+};
diff --git a/test/cli-onboard.test.js b/test/cli-onboard.test.js
new file mode 100644
index 0000000..fa3f741
--- /dev/null
+++ b/test/cli-onboard.test.js
@@ -0,0 +1,38 @@
+import assert from "node:assert/strict";
+import { spawnSync } from "node:child_process";
+import { mkdtempSync, rmSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import test from "node:test";
+
+const root = new URL("../", import.meta.url);
+const forbidFetchHook = new URL("../test-support/forbid-fetch.js", import.meta.url);
+
+test("non-interactive onboard subprocess does not attempt socai CLI installation without --install", () => {
+ const directory = mkdtempSync(join(tmpdir(), "jev-social-subprocess-"));
+ try {
+ const result = spawnSync(
+ process.execPath,
+ ["--import", forbidFetchHook.href, "bin/jev-social.js", "onboard", "--no-verify"],
+ {
+ cwd: root,
+ encoding: "utf8",
+ env: {
+ ...process.env,
+ JEV_SOCIAL_HOME: directory,
+ SOCAI_BIN: join(directory, "missing-socai"),
+ OPENROUTER_API_KEY: String(104),
+ },
+ input: "",
+ },
+ );
+
+ assert.equal(result.status, 0, `Expected exit status 0, stderr: ${result.stderr}`);
+ assert.match(result.stdout, /socai CLI: not ready/u);
+ assert.doesNotMatch(result.stdout, /Downloading official installer/u);
+ assert.doesNotMatch(result.stdout, /socai CLI was not found/u);
+ assert.equal(result.stderr, "");
+ } finally {
+ rmSync(directory, { recursive: true, force: true });
+ }
+});
diff --git a/test/onboard.test.js b/test/onboard.test.js
index 03af917..b88e1a7 100644
--- a/test/onboard.test.js
+++ b/test/onboard.test.js
@@ -4,7 +4,7 @@ import os from "node:os";
import path from "node:path";
import test from "node:test";
import { readConfig } from "../src/config.js";
-import { saveOnboarding } from "../src/onboard.js";
+import { saveOnboarding, resolveSocaiInstallDecision } from "../src/onboard.js";
test("environment-only OpenRouter keys are not persisted during onboarding", async () => {
const directory = await mkdtemp(path.join(os.tmpdir(), "jev-social-onboard-"));
@@ -62,3 +62,70 @@ test("saveOnboarding reports the resolved socai bin path for CLI output", async
await rm(directory, { recursive: true, force: true });
}
});
+
+test("onboarding in non-interactive environment does not install missing socai CLI unless installCli is explicitly true", async () => {
+ const directory = await mkdtemp(path.join(os.tmpdir(), "jev-social-onboard-noninteractive-"));
+ const env = {
+ ...process.env,
+ JEV_SOCIAL_HOME: directory,
+ OPENROUTER_API_KEY: String(103),
+ SOCAI_BIN: path.join(directory, "missing-socai"),
+ };
+ try {
+ const result = await saveOnboarding({ verify: false, installCli: false, env });
+ assert.equal(result.socai.installed, false, "socai CLI must not be installed when installCli is false");
+ } finally {
+ await rm(directory, { recursive: true, force: true });
+ }
+});
+
+test("resolveSocaiInstallDecision correctly handles non-interactive, interactive, explicit, and skip flags", () => {
+ // 1. Non-interactive default (isTTY: false, no flags) -> false
+ assert.equal(
+ resolveSocaiInstallDecision({ installed: false, install: false, skipInstall: false, isTTY: false }),
+ false,
+ "Non-interactive default must not install missing socai CLI",
+ );
+
+ // 2. Interactive empty answer (isTTY: true, answer: "") -> true
+ assert.equal(
+ resolveSocaiInstallDecision({ installed: false, install: false, skipInstall: false, isTTY: true, answer: "" }),
+ true,
+ "Interactive empty answer must default to true ([Y/n])",
+ );
+
+ // 3. Interactive negative answer (isTTY: true, answer: "n") -> false
+ assert.equal(
+ resolveSocaiInstallDecision({ installed: false, install: false, skipInstall: false, isTTY: true, answer: "n" }),
+ false,
+ "Interactive 'n' answer must return false",
+ );
+
+ // 4. Explicit --install -> true regardless of isTTY
+ assert.equal(
+ resolveSocaiInstallDecision({ installed: false, install: true, skipInstall: false, isTTY: false }),
+ true,
+ "Explicit --install must return true even when non-interactive",
+ );
+
+ // 5. Explicit --skip-install -> false regardless of isTTY
+ assert.equal(
+ resolveSocaiInstallDecision({ installed: false, install: false, skipInstall: true, isTTY: true, answer: "y" }),
+ false,
+ "Explicit --skip-install must return false",
+ );
+
+ // 6. Already installed -> false (when install is false)
+ assert.equal(
+ resolveSocaiInstallDecision({ installed: true, install: false, skipInstall: false, isTTY: true }),
+ false,
+ "Already installed CLI must not trigger auto-reinstall without --install",
+ );
+
+ // 7. Explicit --install when already installed -> true (reinstall semantics)
+ assert.equal(
+ resolveSocaiInstallDecision({ installed: true, install: true, skipInstall: false, isTTY: false }),
+ true,
+ "Explicit --install when already installed must return true to preserve reinstall semantics",
+ );
+});