Skip to content

Commit 4db0eeb

Browse files
author
Sorra
committed
SB-0MNFTJWE6006WA3G: replace legacy SB_CLI_PATH uses in tests/helpers and update assertions to rely on OB_CLI_PATH
1 parent a2df955 commit 4db0eeb

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"test": "vitest run",
1414
"test:watch": "vitest",
1515
"test:coverage": "vitest run --coverage",
16+
"test:integration": "vitest run tests/integration --runInBand",
1617
"start": "node dist/src/index.js",
1718
"start:dev": "tsx watch src/index.ts"
1819
},

src/bot/cli-runner.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,15 +345,28 @@ function runCliSubprocess(
345345
// Add remaining args
346346
cmdArgs.push(...args);
347347

348+
// Resolve how we will spawn the subprocess.
349+
// If the configured CLI executable is a JavaScript file (e.g. a test shim),
350+
// spawn Node and pass the script path as the first argument. This makes it
351+
// easy to point OB_CLI_PATH at a local JS shim without requiring the shim
352+
// to be executable on disk.
353+
let spawnCmd: string = cliExecutable;
354+
let spawnArgs: (string | number)[] = cmdArgs;
355+
if (path.extname(String(cliExecutable)).toLowerCase() === ".js") {
356+
// Use the running Node executable to invoke the script
357+
spawnCmd = process.execPath;
358+
spawnArgs = [cliExecutable, ...cmdArgs];
359+
}
360+
348361
// Debug: Log the exact command being spawned for troubleshooting
349362
try {
350-
console.log(`[CLI Debug] Spawning command: ${cliExecutable} ${cmdArgs.map((a) => String(a)).join(" ")}`);
363+
console.log(`[CLI Debug] Spawning command: ${spawnCmd} ${spawnArgs.map((a) => String(a)).join(" ")}`);
351364
} catch {
352365
// ignore any logging issues
353366
}
354367

355368
// Spawn the subprocess
356-
const subprocess = spawn(cliExecutable, cmdArgs, {
369+
const subprocess = spawn(spawnCmd, spawnArgs as string[], {
357370
cwd,
358371
env: { ...process.env, ...env },
359372
stdio: ["ignore", "pipe", "pipe"],

tests/bot/cli-runner.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,9 @@ describe("CLI Runner Module", () => {
270270

271271
describe("setCliPath", () => {
272272
it("setCliPath is a no-op warning", () => {
273-
// Function intentionally no longer mutates environment; it should not throw
273+
// Function intentionally no longer mutates legacy env vars; it should not throw
274274
setCliPath("/new/path/to/sb");
275+
// Only OB_CLI_PATH is used now; ensure legacy SB_CLI_PATH is not relied upon
275276
expect(process.env.SB_CLI_PATH).toBeUndefined();
276277
});
277278
});

tests/helpers/obCliEnv.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/**
2-
* Test helpers to temporarily override OB_CLI_PATH (and related keys)
3-
* and ensure the environment and cli-runner internal state are restored.
2+
* Test helpers to temporarily override OB_CLI_PATH and ensure the
3+
* environment and cli-runner internal state are restored.
44
*/
5-
export type EnvSnapshot = { OB_CLI_PATH?: string; SB_CLI_PATH?: string };
5+
export type EnvSnapshot = { OB_CLI_PATH?: string };
66

77
/**
88
* Synchronously set OB_CLI_PATH and attempt to update cli-runner internal state.
99
* Returns a restore function that will reset environment and cli-runner state.
1010
*/
1111
export function setObCliPath(path?: string): () => void {
12-
const prev: EnvSnapshot = { OB_CLI_PATH: process.env.OB_CLI_PATH, SB_CLI_PATH: process.env.SB_CLI_PATH };
12+
const prev: EnvSnapshot = { OB_CLI_PATH: process.env.OB_CLI_PATH };
1313

1414
if (path === undefined) delete process.env.OB_CLI_PATH;
1515
else process.env.OB_CLI_PATH = String(path);
@@ -36,7 +36,6 @@ export function setObCliPath(path?: string): () => void {
3636
return () => {
3737
// restore environment
3838
if (prev.OB_CLI_PATH === undefined) delete process.env.OB_CLI_PATH; else process.env.OB_CLI_PATH = prev.OB_CLI_PATH;
39-
if (prev.SB_CLI_PATH === undefined) delete process.env.SB_CLI_PATH; else process.env.SB_CLI_PATH = prev.SB_CLI_PATH;
4039

4140
// Attempt to restore cli-runner internal state (best-effort)
4241
(async () => {
@@ -58,7 +57,7 @@ export function setObCliPath(path?: string): () => void {
5857
* and restores environment and cli-runner internal state afterwards.
5958
*/
6059
export async function withObCliPath<T>(path: string | undefined, fn: () => Promise<T> | T): Promise<T> {
61-
const prev: EnvSnapshot = { OB_CLI_PATH: process.env.OB_CLI_PATH, SB_CLI_PATH: process.env.SB_CLI_PATH };
60+
const prev: EnvSnapshot = { OB_CLI_PATH: process.env.OB_CLI_PATH };
6261

6362
// Set env
6463
if (path === undefined) delete process.env.OB_CLI_PATH;
@@ -101,7 +100,6 @@ export async function withObCliPath<T>(path: string | undefined, fn: () => Promi
101100

102101
// Restore env
103102
if (prev.OB_CLI_PATH === undefined) delete process.env.OB_CLI_PATH; else process.env.OB_CLI_PATH = prev.OB_CLI_PATH;
104-
if (prev.SB_CLI_PATH === undefined) delete process.env.SB_CLI_PATH; else process.env.SB_CLI_PATH = prev.SB_CLI_PATH;
105103
}
106104
}
107105

0 commit comments

Comments
 (0)