Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/lib/onboard/setup-nim-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,58 @@ describe("createSetupNim", () => {
});
});

it("ignores recorded provider state when fresh setup disables recovery (#6237)", async () => {
const prompt = vi.fn(async () => unexpected("interactive provider prompt"));
const note = vi.fn();
const readRecordedProvider = vi.fn(() => "ollama-local");
const readRecordedNimContainer = vi.fn(() => null);
const readRecordedModel = vi.fn(() => "llama3.1");
const handleRemoteProviderSelection = vi.fn<SetupNimFlowDeps["handleRemoteProviderSelection"]>(
async (args, state) => {
expect(args).toMatchObject({
selected: { key: "build", label: "NVIDIA Endpoints" },
requestedModel: null,
recoveredFromSandbox: false,
recoveredModel: null,
sandboxName: "dcode-station",
});
state.model = "nvidia/test-model";
state.provider = "nvidia-prod";
state.endpointUrl = "https://integrate.api.nvidia.com/v1";
state.credentialEnv = "NVIDIA_INFERENCE_API_KEY";
state.preferredInferenceApi = "openai-completions";
return "selected";
},
);
const setupNim = createSetupNim(
makeDeps({
isNonInteractive: () => true,
prompt,
note,
readRecordedProvider,
readRecordedNimContainer,
readRecordedModel,
handleRemoteProviderSelection,
}),
);

const result = await setupNim(null, "dcode-station", null, false);

expect(prompt).not.toHaveBeenCalled();
expect(readRecordedProvider).not.toHaveBeenCalled();
expect(readRecordedNimContainer).not.toHaveBeenCalled();
expect(readRecordedModel).not.toHaveBeenCalled();
expect(note).toHaveBeenCalledTimes(1);
expect(note).toHaveBeenCalledWith(" [non-interactive] Provider: build");
expect(result).toMatchObject({
model: "nvidia/test-model",
provider: "nvidia-prod",
endpointUrl: "https://integrate.api.nvidia.com/v1",
credentialEnv: "NVIDIA_INFERENCE_API_KEY",
preferredInferenceApi: "openai-completions",
});
});

it("honors a rebuild route and preserves credential-reuse return contracts (#6245)", async () => {
const agent = { name: "langchain-deepagents-code" } as AgentDefinition;
const recoveredRegistryRoute = {
Expand Down
132 changes: 0 additions & 132 deletions test/onboard-resume-provider-recovery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,136 +614,4 @@ const { setupNim } = require(${onboardPath});
),
).toBe(true);
});

it("ignores stale recorded providers when fresh setup disables provider recovery", () => {
const repoRoot = path.join(import.meta.dirname, "..");
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-onboard-fresh-provider-"));
const fakeBin = path.join(tmpDir, "bin");
const scriptPath = path.join(tmpDir, "fresh-provider-recovery-check.js");
const onboardPath = JSON.stringify(path.join(repoRoot, "src", "lib", "onboard.ts"));
const sessionPath = JSON.stringify(
path.join(repoRoot, "src", "lib", "state", "onboard-session.ts"),
);
const registryPath = JSON.stringify(path.join(repoRoot, "src", "lib", "state", "registry.ts"));
const runnerPath = JSON.stringify(path.join(repoRoot, "src", "lib", "runner.ts"));
const credentialsPath = JSON.stringify(
path.join(repoRoot, "src", "lib", "credentials", "store.ts"),
);

fs.mkdirSync(fakeBin, { recursive: true });
fs.writeFileSync(
path.join(fakeBin, "curl"),
`#!/usr/bin/env bash
body='{"choices":[{"message":{"role":"assistant","content":"OK"}}]}'
status="200"
outfile=""
while [ "$#" -gt 0 ]; do
case "$1" in
-o) outfile="$2"; shift 2 ;;
*) shift ;;
esac
done
printf '%s' "$body" > "$outfile"
printf '%s' "$status"
`,
{ mode: 0o755 },
);

const script = String.raw`
const credentials = require(${credentialsPath});
const runner = require(${runnerPath});
const registry = require(${registryPath});
const onboardSession = require(${sessionPath});

runner.runCapture = () => "";
registry.getSandbox = () => null;
registry.listSandboxes = () => ({ sandboxes: [], defaultSandbox: null });
onboardSession.loadSession = () => ({
sandboxName: "dcode-station",
provider: "ollama-local",
model: "llama3.1",
});
const prompts = [];
credentials.prompt = async (message) => {
prompts.push(message);
return "";
};
credentials.ensureApiKey = async () => {};
process.env.NEMOCLAW_NON_INTERACTIVE = "1";
const { setupNim } = require(${onboardPath});

(async () => {
for (const key of [
"NEMOCLAW_PROVIDER",
"NEMOCLAW_PROVIDER_KEY",
"OPENAI_API_KEY",
"OPENROUTER_API_KEY",
"ANTHROPIC_API_KEY",
"GEMINI_API_KEY",
"COMPATIBLE_API_KEY",
"COMPATIBLE_ANTHROPIC_API_KEY",
]) {
delete process.env[key];
}
process.env.NVIDIA_INFERENCE_API_KEY = "nvapi-test";
process.env.NEMOCLAW_MODEL = "nvidia/test-model";
const originalLog = console.log;
const originalError = console.error;
const lines = [];
console.log = (...args) => lines.push(args.join(" "));
console.error = (...args) => lines.push(args.join(" "));
try {
const nonInteractive = await setupNim(null, "dcode-station", null, false);
process.env.NEMOCLAW_PROVIDER = "openai";
process.env.OPENAI_API_KEY = "sk-test";
process.env.NEMOCLAW_MODEL = "gpt-5.4";
const explicitProvider = await setupNim(null, "dcode-station", null, false);
delete process.env.NEMOCLAW_PROVIDER;
delete process.env.OPENAI_API_KEY;
process.env.NEMOCLAW_MODEL = "nvidia/test-model";
delete process.env.NEMOCLAW_NON_INTERACTIVE;
const interactive = await setupNim(null, "dcode-station", null, false);
originalLog(JSON.stringify({ nonInteractive, explicitProvider, interactive, prompts, lines }));
} finally {
console.log = originalLog;
console.error = originalError;
}
})().catch((error) => {
console.error(error);
process.exit(1);
});
`;
fs.writeFileSync(scriptPath, script);

const result = spawnSync(process.execPath, [scriptPath], {
cwd: repoRoot,
encoding: "utf-8",
env: {
...process.env,
HOME: tmpDir,
PATH: `${fakeBin}:${process.env.PATH || ""}`,
NEMOCLAW_TEST_NO_SLEEP: "1",
},
});

expect(result.status).toBe(0);
const payload = JSON.parse(result.stdout.trim());
expect(payload.nonInteractive.provider).toBe("nvidia-prod");
expect(payload.nonInteractive.model).toBe("nvidia/test-model");
expect(payload.nonInteractive.preferredInferenceApi).toBe("openai-completions");
expect(payload.explicitProvider.provider).toBe("openai-api");
expect(payload.explicitProvider.model).toBe("gpt-5.4");
expect(payload.interactive.provider).toBe("nvidia-prod");
expect(payload.interactive.preferredInferenceApi).toBe("openai-completions");
expect(payload.prompts[0]).toMatch(/^ Choose \[\d+\]: $/);
expect(
payload.lines.some((line: string) => line.includes("Select your inference provider")),
).toBe(true);
expect(
payload.lines.some((line: string) => line.includes("[non-interactive] Provider: build")),
).toBe(true);
expect(payload.lines.every((line: string) => !line.includes("recovered from sandbox"))).toBe(
true,
);
});
});
Loading