Skip to content
Merged
32 changes: 20 additions & 12 deletions src/lib/global-cli-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,24 @@ import {
runSetupSparkAction as executeSetupSparkAction,
} from "./onboard-action";
import { recoverNamedGatewayRuntime as recoverNamedGatewayRuntimeAction } from "./gateway-runtime-action";
import { getNemoClawRuntimeBridge } from "./nemoclaw-runtime-bridge";
import { runOpenshell } from "./openshell-runtime";
import { help, version } from "./root-help-action";

type GatewayRecovery = { recovered: boolean };

type GlobalCliActionRuntimeHooks = {
recoverNamedGatewayRuntime?: () => Promise<GatewayRecovery>;
runOpenshell?: typeof runOpenshell;
};

let runtimeHooks: GlobalCliActionRuntimeHooks = {};

export function setGlobalCliActionRuntimeHooksForTest(
hooks: GlobalCliActionRuntimeHooks,
): void {
runtimeHooks = hooks;
}

export async function runOnboardAction(args: string[] = []): Promise<void> {
await executeOnboardAction(args);
}
Expand Down Expand Up @@ -57,12 +71,9 @@ export function showVersion(): void {
version();
}

export async function recoverNamedGatewayRuntime(): Promise<{ recovered: boolean }> {
const runtime = getNemoClawRuntimeBridge() as {
recoverNamedGatewayRuntime?: () => Promise<{ recovered: boolean }>;
};
if (typeof runtime.recoverNamedGatewayRuntime === "function") {
return runtime.recoverNamedGatewayRuntime();
export async function recoverNamedGatewayRuntime(): Promise<GatewayRecovery> {
if (typeof runtimeHooks.recoverNamedGatewayRuntime === "function") {
return runtimeHooks.recoverNamedGatewayRuntime();
}
return recoverNamedGatewayRuntimeAction();
}
Expand All @@ -76,11 +87,8 @@ export function runOpenshellProviderCommand(
timeout?: number;
},
) {
const runtime = getNemoClawRuntimeBridge() as {
runOpenshell?: typeof runOpenshell;
};
if (typeof runtime.runOpenshell === "function") {
return runtime.runOpenshell(args, opts);
if (typeof runtimeHooks.runOpenshell === "function") {
return runtimeHooks.runOpenshell(args, opts);
}
return runOpenshell(args, opts);
}
23 changes: 0 additions & 23 deletions src/lib/nemoclaw-runtime-bridge.ts

This file was deleted.

17 changes: 6 additions & 11 deletions test/credentials-cli-command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import { afterEach, describe, expect, it } from "vitest";

const require = createRequire(import.meta.url);
const REPO_ROOT = path.join(import.meta.dirname, "..");
const RUNTIME_PATH = require.resolve(path.join(REPO_ROOT, "dist", "nemoclaw.js"));
const COMMANDS_PATH = path.join(REPO_ROOT, "dist", "lib", "credentials-cli-command.js");

type RequireCacheEntry = NonNullable<(typeof require.cache)[string]>;
const GLOBAL_ACTIONS_PATH = path.join(REPO_ROOT, "dist", "lib", "global-cli-actions.js");
type CredentialsCommandModule = typeof import("../dist/lib/credentials-cli-command.js");
type SpawnLikeResult = { status: number | null; stdout?: string; stderr?: string };
type RuntimeRecovery = {
Expand Down Expand Up @@ -53,13 +51,10 @@ function installRuntimeBridge(bridge: Partial<RuntimeBridge> = {}): OpenshellCal
},
...bridge,
};
const cacheEntry = {
id: RUNTIME_PATH,
filename: RUNTIME_PATH,
loaded: true,
exports: runtime,
} as RequireCacheEntry;
require.cache[RUNTIME_PATH] = cacheEntry;
const globalActions = require(GLOBAL_ACTIONS_PATH) as {
setGlobalCliActionRuntimeHooksForTest: (hooks: RuntimeBridge) => void;
};
globalActions.setGlobalCliActionRuntimeHooksForTest(runtime);
return calls;
}

Expand Down Expand Up @@ -129,7 +124,7 @@ async function expectProcessExit(

afterEach(() => {
delete require.cache[COMMANDS_PATH];
delete require.cache[RUNTIME_PATH];
delete require.cache[GLOBAL_ACTIONS_PATH];
});

describe("credentials oclif commands", () => {
Expand Down
Loading