-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy pathonboard-selection.test.ts
More file actions
5642 lines (5134 loc) · 194 KB
/
Copy pathonboard-selection.test.ts
File metadata and controls
5642 lines (5134 loc) · 194 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
import assert from "node:assert/strict";
import { describe, it, expect } from "vitest";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { spawnSync } from "node:child_process";
import { testTimeout } from "./helpers/timeouts";
const CREDENTIAL_RETRY_PROMPT =
" Options: retry (re-enter key), back (change provider), exit [retry]: ";
const CREDENTIAL_RETRY_PROMPT_RE =
/Options: retry \(re-enter key\), back \(change provider\), exit \[retry\]: /;
const OLLAMA_CHAT_COMPLETIONS_TOOL_CALL_RESPONSE =
'{"choices":[{"message":{"role":"assistant","content":"","tool_calls":[{"type":"function","function":{"name":"emit_ok","arguments":"{\\"ok\\":true}"}}]}}]}';
const PROVIDER_SELECTION_TEST_TIMEOUT_MS = testTimeout(60_000);
function writeOllamaToolCallingCurl(fakeBin: string) {
fs.writeFileSync(
path.join(fakeBin, "curl"),
`#!/usr/bin/env bash
body='${OLLAMA_CHAT_COMPLETIONS_TOOL_CALL_RESPONSE}'
status="200"
outfile=""
while [ "$#" -gt 0 ]; do
case "$1" in
-o) outfile="$2"; shift 2 ;;
*) shift ;;
esac
done
if [ -n "$outfile" ]; then
printf '%s' "$body" > "$outfile"
printf '%s' "$status"
else
printf '%s' "$body"
fi
`,
{ mode: 0o755 },
);
}
function writeOpenAiStyleAuthRetryCurl(fakeBin: string, goodToken: string, models = ["gpt-5.4"]) {
fs.writeFileSync(
path.join(fakeBin, "curl"),
`#!/usr/bin/env bash
body='{"error":{"message":"forbidden"}}'
status="403"
outfile=""
auth=""
url=""
while [ "$#" -gt 0 ]; do
case "$1" in
-o) outfile="$2"; shift 2 ;;
-H)
if echo "$2" | grep -q '^Authorization: Bearer '; then
auth="$2"
fi
shift 2
;;
*) url="$1"; shift ;;
esac
done
# Also extract auth from ?key= query parameter (Gemini uses this instead of Bearer header)
url_auth=""
if echo "$url" | grep -q '[?&]key='; then
url_auth=$(echo "$url" | sed 's/.*[?&]key=\\([^&]*\\).*/\\1/')
fi
# Strip query params for URL path matching
url_path=$(echo "$url" | sed 's/?.*//')
if echo "$url_path" | grep -q '/models$'; then
body='{"data":[${models.map((model) => `{"id":"${model}"}`).join(",")}]}'
status="200"
elif (echo "$auth" | grep -q '${goodToken}' || echo "$url_auth" | grep -q '${goodToken}') && echo "$url_path" | grep -q '/responses$'; then
body='{"id":"resp_123"}'
status="200"
elif (echo "$auth" | grep -q '${goodToken}' || echo "$url_auth" | grep -q '${goodToken}') && echo "$url_path" | grep -q '/chat/completions$'; then
body='{"id":"chatcmpl-123"}'
status="200"
fi
printf '%s' "$body" > "$outfile"
printf '%s' "$status"
`,
{ mode: 0o755 },
);
}
function writeAnthropicStyleAuthRetryCurl(
fakeBin: string,
goodToken: string,
models = ["claude-sonnet-4-6"],
) {
fs.writeFileSync(
path.join(fakeBin, "curl"),
`#!/usr/bin/env bash
body='{"error":{"message":"forbidden"}}'
status="403"
outfile=""
auth=""
url=""
while [ "$#" -gt 0 ]; do
case "$1" in
-o) outfile="$2"; shift 2 ;;
-H)
if echo "$2" | grep -q '^x-api-key: '; then
auth="$2"
fi
shift 2
;;
*) url="$1"; shift ;;
esac
done
if echo "$url" | grep -q '/v1/models$'; then
body='{"data":[${models.map((model) => `{"id":"${model}"}`).join(",")}]}'
status="200"
elif echo "$auth" | grep -q '${goodToken}' && echo "$url" | grep -q '/v1/messages$'; then
body='{"id":"msg_123","content":[{"type":"text","text":"OK"}]}'
status="200"
fi
printf '%s' "$body" > "$outfile"
printf '%s' "$status"
`,
{ mode: 0o755 },
);
}
describe("onboard provider selection UX", { timeout: PROVIDER_SELECTION_TEST_TIMEOUT_MS }, () => {
it("prompts explicitly instead of silently auto-selecting detected Ollama", () => {
const repoRoot = path.join(import.meta.dirname, "..");
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-onboard-selection-"));
const fakeBin = path.join(tmpDir, "bin");
const scriptPath = path.join(tmpDir, "selection-check.js");
const onboardPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "onboard.js"));
const credentialsPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "credentials", "store.js"));
const runnerPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "runner.js"));
const registryPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "state", "registry.js"));
fs.mkdirSync(fakeBin, { recursive: true });
fs.writeFileSync(
path.join(fakeBin, "curl"),
`#!/usr/bin/env bash
body='{"id":"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});
let promptCalls = 0;
const messages = [];
const updates = [];
credentials.prompt = async (message) => {
promptCalls += 1;
messages.push(message);
return "";
};
credentials.ensureApiKey = async () => {};
runner.runCapture = (command) => {
// Normalize: onboard.ts still sends strings, local-inference.ts sends arrays.
// Once onboard.ts is migrated to argv (#1889), these mocks can assert Array.isArray.
const cmd = Array.isArray(command) ? command.join(" ") : command;
if (cmd.includes("command -v ollama")) return "/usr/bin/ollama";
if (cmd.includes("127.0.0.1:11434/api/tags")) return JSON.stringify({ models: [{ name: "nemotron-3-nano:30b" }] });
if (cmd.includes("ollama list")) return "nemotron-3-nano:30b abc 24 GB now\\nqwen3:32b def 20 GB now";
if (cmd.includes("127.0.0.1:8000/v1/models")) return "";
return "";
};
registry.updateSandbox = (_name, update) => updates.push(update);
const { setupNim } = require(${onboardPath});
(async () => {
const originalLog = console.log;
const lines = [];
console.log = (...args) => lines.push(args.join(" "));
try {
const result = await setupNim("selection-test", null);
originalLog(JSON.stringify({ result, promptCalls, messages, updates, lines }));
} finally {
console.log = originalLog;
}
})().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 || ""}`,
},
});
expect(result.status).toBe(0);
expect(result.stdout.trim()).not.toBe("");
const payload = JSON.parse(result.stdout.trim());
assert.equal(payload.result.provider, "nvidia-prod");
assert.equal(payload.result.model, "nvidia/nemotron-3-super-120b-a12b");
assert.equal(payload.result.preferredInferenceApi, "openai-completions");
assert.equal(payload.promptCalls, 2);
assert.match(payload.messages[0], /Choose \[/);
assert.match(payload.messages[1], /Choose model \[1\]/);
assert.ok(
payload.lines.some((line: string) => line.includes("Detected local inference option")),
);
assert.ok(payload.lines.some((line: string) => line.includes("Cloud models:")));
assert.ok(
payload.lines.some((line: string) => line.includes("Chat Completions API available")),
);
});
it("offers detected running vLLM without requiring a rerun", () => {
const repoRoot = path.join(import.meta.dirname, "..");
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-onboard-vllm-running-"));
const fakeBin = path.join(tmpDir, "bin");
const scriptPath = path.join(tmpDir, "vllm-running-check.js");
const onboardPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "onboard.js"));
const credentialsPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "credentials", "store.js"));
const runnerPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "runner.js"));
fs.mkdirSync(fakeBin, { recursive: true });
fs.writeFileSync(
path.join(fakeBin, "curl"),
`#!/usr/bin/env bash
body='{"id":"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 messages = [];
const lines = [];
const originalLog = console.log;
function findRunningVllmChoice() {
const option = lines.find((line) =>
/^\s*\d+\) Local vLLM \[experimental\] \(localhost:8000\) — running \(suggested\)/.test(line)
);
const match = option && option.match(/^\s*(\d+)\)/);
if (!match) {
throw new Error("Could not find running vLLM option in menu:\\n" + lines.join("\\n"));
}
return match[1];
}
credentials.prompt = async (message) => {
messages.push(message);
if (/Choose \[/.test(message)) return findRunningVllmChoice();
return "";
};
credentials.ensureApiKey = async () => {};
runner.runCapture = (command) => {
const cmd = Array.isArray(command) ? command.join(" ") : command;
if (cmd.includes("command -v ollama")) return "";
if (cmd.includes("127.0.0.1:11434/api/tags")) return "";
if (cmd.includes("127.0.0.1:8000/v1/models")) return JSON.stringify({ data: [{ id: "meta-llama/Llama-3.3-70B-Instruct" }] });
if (cmd.includes("docker images")) return "";
return "";
};
const { setupNim } = require(${onboardPath});
(async () => {
console.log = (...args) => lines.push(args.join(" "));
try {
const result = await setupNim({ type: "nvidia" }, null);
originalLog(JSON.stringify({ result, messages, lines }));
} finally {
console.log = originalLog;
}
})().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_EXPERIMENTAL: "",
NEMOCLAW_PROVIDER: "",
},
});
expect(result.status).toBe(0);
expect(result.stdout.trim()).not.toBe("");
const payload = JSON.parse(result.stdout.trim());
assert.equal(payload.result.provider, "vllm-local");
assert.equal(payload.result.model, "meta-llama/Llama-3.3-70B-Instruct");
assert.equal(payload.result.preferredInferenceApi, "openai-completions");
assert.equal(payload.messages.filter((message: string) => /Choose \[/.test(message)).length, 1);
assert.ok(
payload.lines.some((line: string) =>
line.includes("Detected local inference option: vLLM"),
),
);
assert.ok(
payload.lines.some((line: string) =>
/^\s*\d+\) Local vLLM \[experimental\] \(localhost:8000\) — running \(suggested\)/.test(
line,
),
),
);
assert.ok(!payload.lines.some((line: string) => line.includes("rerun the same command")));
});
it("does not turn non-interactive NEMOCLAW_PROVIDER=vllm into managed install-vllm", () => {
const repoRoot = path.join(import.meta.dirname, "..");
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-onboard-vllm-no-install-"));
const scriptPath = path.join(tmpDir, "vllm-no-install-check.js");
const onboardPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "onboard.js"));
const credentialsPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "credentials", "store.js"));
const runnerPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "runner.js"));
const vllmPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "inference", "vllm.js"));
const script = String.raw`
const credentials = require(${credentialsPath});
const runner = require(${runnerPath});
const vllm = require(${vllmPath});
credentials.prompt = async () => {
throw new Error("Unexpected prompt in non-interactive test");
};
credentials.ensureApiKey = async () => {
throw new Error("Unexpected ensureApiKey call in non-interactive test");
};
vllm.installVllm = async () => {
console.error("INSTALL_VLLM_CALLED");
return { ok: false };
};
runner.runCapture = (command) => {
const cmd = Array.isArray(command) ? command.join(" ") : command;
if (cmd.includes("command -v ollama")) return "";
if (cmd.includes("127.0.0.1:11434/api/tags")) return "";
if (cmd.includes("127.0.0.1:8000/v1/models")) return "";
if (cmd.includes("docker images")) return "";
return "";
};
const { setupNim } = require(${onboardPath});
(async () => {
await setupNim({ type: "nvidia" }, null);
})().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,
NEMOCLAW_NON_INTERACTIVE: "1",
NEMOCLAW_PROVIDER: "vllm",
NEMOCLAW_EXPERIMENTAL: "",
},
});
assert.equal(result.status, 1);
assert.match(result.stderr, /Requested provider 'vllm' is not available/);
assert.doesNotMatch(result.stderr, /INSTALL_VLLM_CALLED/);
});
it("surfaces a precise error when NEMOCLAW_PROVIDER=install-vllm but no vLLM profile is detected (#3765)", () => {
const repoRoot = path.join(import.meta.dirname, "..");
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-onboard-install-vllm-no-profile-"));
const scriptPath = path.join(tmpDir, "install-vllm-no-profile-check.js");
const onboardPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "onboard.js"));
const credentialsPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "credentials", "store.js"));
const runnerPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "runner.js"));
const vllmPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "inference", "vllm.js"));
const script = String.raw`
const credentials = require(${credentialsPath});
const runner = require(${runnerPath});
const vllm = require(${vllmPath});
credentials.prompt = async () => {
throw new Error("Unexpected prompt in non-interactive test");
};
credentials.ensureApiKey = async () => {
throw new Error("Unexpected ensureApiKey call in non-interactive test");
};
vllm.installVllm = async () => {
console.error("INSTALL_VLLM_CALLED");
return { ok: false };
};
runner.runCapture = (command) => {
const cmd = Array.isArray(command) ? command.join(" ") : command;
if (cmd.includes("command -v ollama")) return "";
if (cmd.includes("127.0.0.1:11434/api/tags")) return "";
if (cmd.includes("127.0.0.1:8000/v1/models")) return "";
if (cmd.includes("docker images")) return "";
return "";
};
const { setupNim } = require(${onboardPath});
// gpu=null forces detectVllmProfile to return null, the scenario the bug
// reports: explicit env-var opt-in with no profile detected.
(async () => {
await setupNim(null, null);
})().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,
NEMOCLAW_NON_INTERACTIVE: "1",
NEMOCLAW_PROVIDER: "install-vllm",
NEMOCLAW_EXPERIMENTAL: "1",
},
});
assert.equal(result.status, 1);
// The fix routes the explicit opt-in through the install-vllm dispatcher,
// which emits a precise message instead of the generic "Requested provider
// 'install-vllm' is not available in this environment." that hid the cause.
assert.match(result.stderr, /No vLLM install profile available for this host\./);
assert.doesNotMatch(result.stderr, /Requested provider 'install-vllm' is not available/);
assert.doesNotMatch(result.stderr, /INSTALL_VLLM_CALLED/);
});
it("logs a note when NEMOCLAW_PROVIDER=install-vllm is overridden by a running vLLM server (#3765)", () => {
const repoRoot = path.join(import.meta.dirname, "..");
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-onboard-install-vllm-running-"));
const scriptPath = path.join(tmpDir, "install-vllm-running-check.js");
const onboardPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "onboard.js"));
const credentialsPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "credentials", "store.js"));
const runnerPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "runner.js"));
const script = String.raw`
const credentials = require(${credentialsPath});
const runner = require(${runnerPath});
credentials.prompt = async () => {
throw new Error("Unexpected prompt in non-interactive test");
};
credentials.ensureApiKey = async () => {
throw new Error("Unexpected ensureApiKey call in non-interactive test");
};
runner.runCapture = (command) => {
const cmd = Array.isArray(command) ? command.join(" ") : command;
if (cmd.includes("command -v ollama")) return "";
if (cmd.includes("127.0.0.1:11434/api/tags")) return "";
// vLLM probe succeeds → vllmRunning becomes true.
if (cmd.includes("127.0.0.1:8000/v1/models")) return '{"data":[]}';
if (cmd.includes("docker images")) return "";
return "";
};
const { setupNim } = require(${onboardPath});
(async () => {
try {
await setupNim({ type: "nvidia" }, null);
} catch (e) {
// Downstream paths (model probe, gateway, etc.) are not mocked here; we
// only care about the menu-build log emitted before any failure.
}
})();
`;
fs.writeFileSync(scriptPath, script);
const result = spawnSync(process.execPath, [scriptPath], {
cwd: repoRoot,
encoding: "utf-8",
env: {
...process.env,
HOME: tmpDir,
NEMOCLAW_NON_INTERACTIVE: "1",
NEMOCLAW_PROVIDER: "install-vllm",
NEMOCLAW_EXPERIMENTAL: "1",
},
});
assert.match(
result.stdout,
/NEMOCLAW_PROVIDER=install-vllm requested, but vLLM is already running on localhost:8000 — selecting the running instance\./,
);
});
it("does not label NVIDIA Endpoints as recommended in the provider list", () => {
const repoRoot = path.join(import.meta.dirname, "..");
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-onboard-no-recommended-label-"));
const fakeBin = path.join(tmpDir, "bin");
const scriptPath = path.join(tmpDir, "no-recommended-label-check.js");
const onboardPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "onboard.js"));
const credentialsPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "credentials", "store.js"));
const runnerPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "runner.js"));
fs.mkdirSync(fakeBin, { recursive: true });
fs.writeFileSync(
path.join(fakeBin, "curl"),
`#!/usr/bin/env bash
body='{"id":"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 messages = [];
credentials.prompt = async (message) => {
messages.push(message);
return "";
};
credentials.ensureApiKey = async () => {};
runner.runCapture = () => "";
const { setupNim } = require(${onboardPath});
(async () => {
const originalLog = console.log;
const lines = [];
console.log = (...args) => lines.push(args.join(" "));
try {
await setupNim(null);
originalLog(JSON.stringify({ messages, lines }));
} finally {
console.log = originalLog;
}
})().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 || ""}`,
},
});
assert.equal(result.status, 0, result.stderr);
const payload = JSON.parse(result.stdout.trim());
assert.ok(payload.lines.some((line: string) => line.includes("NVIDIA Endpoints")));
assert.ok(
!payload.lines.some((line: string) => line.includes("NVIDIA Endpoints (recommended)")),
);
});
it("selects DeepSeek V4 Pro from the NVIDIA Endpoints model list", () => {
const repoRoot = path.join(import.meta.dirname, "..");
const tmpDir = fs.mkdtempSync(
path.join(os.tmpdir(), "nemoclaw-onboard-build-deepseek-selection-"),
);
const fakeBin = path.join(tmpDir, "bin");
const scriptPath = path.join(tmpDir, "build-deepseek-selection-check.js");
const curlArgsLog = path.join(tmpDir, "deepseek-curl-args.log");
const onboardPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "onboard.js"));
const credentialsPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "credentials", "store.js"));
const runnerPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "runner.js"));
fs.mkdirSync(fakeBin, { recursive: true });
fs.writeFileSync(
path.join(fakeBin, "curl"),
`#!/usr/bin/env bash
args_log=${JSON.stringify(curlArgsLog)}
printf '%s\\n' "$*" >> "$args_log"
body='{"id":"ok"}'
status="200"
outfile=""
streaming=""
while [ "$#" -gt 0 ]; do
case "$1" in
-o) outfile="$2"; shift 2 ;;
-N) streaming="1"; shift ;;
-w) shift 2 ;;
*) shift ;;
esac
done
if [ "$streaming" = "1" ]; then
body='data: {"id":"chatcmpl-test","choices":[{"delta":{"content":"OK"}}]}'$'\\n\\n''data: [DONE]'$'\\n'
fi
printf '%s' "$body" > "$outfile"
printf '%s' "$status"
`,
{ mode: 0o755 },
);
const script = String.raw`
const credentials = require(${credentialsPath});
const runner = require(${runnerPath});
const answers = ["1", "7"];
const messages = [];
credentials.prompt = async (message) => {
messages.push(message);
return answers.shift() || "";
};
credentials.ensureApiKey = async () => { process.env.NVIDIA_API_KEY = "nvapi-test"; };
runner.runCapture = (command) => {
const cmd = Array.isArray(command) ? command.join(" ") : command;
if (cmd.includes("command -v ollama")) return "";
if (cmd.includes("127.0.0.1:11434/api/tags")) return "";
if (cmd.includes("127.0.0.1:8000/v1/models")) return "";
return "";
};
const { setupNim } = require(${onboardPath});
(async () => {
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 result = await setupNim(null);
originalLog(JSON.stringify({ result, messages, 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 || ""}`,
},
});
assert.equal(result.status, 0, result.stderr);
const payload = JSON.parse(result.stdout.trim());
assert.equal(payload.result.provider, "nvidia-prod");
assert.equal(payload.result.model, "deepseek-ai/deepseek-v4-pro");
assert.equal(payload.result.preferredInferenceApi, "openai-completions");
assert.match(payload.messages[1], /Choose model \[1\]/);
assert.ok(payload.lines.some((line: string) => line.includes("DeepSeek V4 Pro")));
assert.ok(
payload.lines.some((line: string) => line.includes("Chat Completions API available")),
);
const curlInvocations = fs.readFileSync(curlArgsLog, "utf-8");
assert.match(curlInvocations, /chat\/completions/);
assert.match(curlInvocations, /(^|\s)-N(\s|$)/);
});
it("accepts a manually entered NVIDIA Endpoints model after validating it against /models", () => {
const repoRoot = path.join(import.meta.dirname, "..");
const tmpDir = fs.mkdtempSync(
path.join(os.tmpdir(), "nemoclaw-onboard-build-model-selection-"),
);
const fakeBin = path.join(tmpDir, "bin");
const scriptPath = path.join(tmpDir, "build-model-selection-check.js");
const onboardPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "onboard.js"));
const credentialsPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "credentials", "store.js"));
const runnerPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "runner.js"));
fs.mkdirSync(fakeBin, { recursive: true });
fs.writeFileSync(
path.join(fakeBin, "curl"),
`#!/usr/bin/env bash
body='{"id":"ok"}'
status="200"
outfile=""
url=""
while [ "$#" -gt 0 ]; do
case "$1" in
-o) outfile="$2"; shift 2 ;;
*) url="$1"; shift ;;
esac
done
if echo "$url" | grep -q '/v1/models$'; then
body='{"data":[{"id":"nvidia/nemotron-3-super-120b-a12b"},{"id":"custom/provider-model"}]}'
fi
printf '%s' "$body" > "$outfile"
printf '%s' "$status"
`,
{ mode: 0o755 },
);
const script = String.raw`
const credentials = require(${credentialsPath});
const runner = require(${runnerPath});
const answers = ["1", "8", "custom/provider-model"];
const messages = [];
credentials.prompt = async (message) => {
messages.push(message);
return answers.shift() || "";
};
credentials.ensureApiKey = async () => { process.env.NVIDIA_API_KEY = "nvapi-test"; };
runner.runCapture = (command) => {
// Normalize: onboard.ts still sends strings, local-inference.ts sends arrays.
// Once onboard.ts is migrated to argv (#1889), these mocks can assert Array.isArray.
const cmd = Array.isArray(command) ? command.join(" ") : command;
if (cmd.includes("command -v ollama")) return "";
if (cmd.includes("127.0.0.1:11434/api/tags")) return "";
if (cmd.includes("127.0.0.1:8000/v1/models")) return "";
return "";
};
const { setupNim } = require(${onboardPath});
(async () => {
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 result = await setupNim(null);
originalLog(JSON.stringify({ result, messages, 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 || ""}`,
},
});
assert.equal(result.status, 0, result.stderr);
const payload = JSON.parse(result.stdout.trim());
assert.equal(payload.result.provider, "nvidia-prod");
assert.equal(payload.result.model, "custom/provider-model");
assert.equal(payload.result.preferredInferenceApi, "openai-completions");
assert.match(payload.messages[1], /Choose model \[1\]/);
assert.match(payload.messages[2], /NVIDIA Endpoints model id:/);
assert.ok(payload.lines.some((line: string) => line.includes("Other...")));
});
it("reprompts for a manual NVIDIA Endpoints model when /models validation rejects it", () => {
const repoRoot = path.join(import.meta.dirname, "..");
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-onboard-build-model-retry-"));
const fakeBin = path.join(tmpDir, "bin");
const scriptPath = path.join(tmpDir, "build-model-retry-check.js");
const onboardPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "onboard.js"));
const credentialsPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "credentials", "store.js"));
const runnerPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "runner.js"));
fs.mkdirSync(fakeBin, { recursive: true });
fs.writeFileSync(
path.join(fakeBin, "curl"),
`#!/usr/bin/env bash
body='{"id":"ok"}'
status="200"
outfile=""
url=""
while [ "$#" -gt 0 ]; do
case "$1" in
-o) outfile="$2"; shift 2 ;;
*) url="$1"; shift ;;
esac
done
if echo "$url" | grep -q '/v1/models$'; then
body='{"data":[{"id":"nvidia/nemotron-3-super-120b-a12b"},{"id":"z-ai/glm-5.1"}]}'
fi
printf '%s' "$body" > "$outfile"
printf '%s' "$status"
`,
{ mode: 0o755 },
);
const script = String.raw`
const credentials = require(${credentialsPath});
const runner = require(${runnerPath});
const answers = ["1", "8", "bad/model", "z-ai/glm-5.1"];
const messages = [];
credentials.prompt = async (message) => {
messages.push(message);
return answers.shift() || "";
};
credentials.ensureApiKey = async () => { process.env.NVIDIA_API_KEY = "nvapi-test"; };
runner.runCapture = (command) => {
// Normalize: onboard.ts still sends strings, local-inference.ts sends arrays.
// Once onboard.ts is migrated to argv (#1889), these mocks can assert Array.isArray.
const cmd = Array.isArray(command) ? command.join(" ") : command;
if (cmd.includes("command -v ollama")) return "";
if (cmd.includes("127.0.0.1:11434/api/tags")) return "";
if (cmd.includes("127.0.0.1:8000/v1/models")) return "";
return "";
};
const { setupNim } = require(${onboardPath});
(async () => {
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 result = await setupNim(null);
originalLog(JSON.stringify({ result, messages, 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 || ""}`,
},
});
assert.equal(result.status, 0, result.stderr);
const payload = JSON.parse(result.stdout.trim());
assert.equal(payload.result.model, "z-ai/glm-5.1");
assert.equal(
payload.messages.filter((message: string) => /NVIDIA Endpoints model id:/.test(message))
.length,
2,
);
assert.ok(
payload.lines.some((line: string) => line.includes("is not available from NVIDIA Endpoints")),
);
});
it("shows curated Gemini models and supports Other for manual entry", () => {
const repoRoot = path.join(import.meta.dirname, "..");
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-onboard-gemini-selection-"));
const fakeBin = path.join(tmpDir, "bin");
const scriptPath = path.join(tmpDir, "gemini-selection-check.js");
const onboardPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "onboard.js"));
const credentialsPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "credentials", "store.js"));
const runnerPath = JSON.stringify(path.join(repoRoot, "dist", "lib", "runner.js"));
fs.mkdirSync(fakeBin, { recursive: true });
fs.writeFileSync(
path.join(fakeBin, "curl"),
`#!/usr/bin/env bash
body=""
status="404"
outfile=""
while [ "$#" -gt 0 ]; do
case "$1" in
-o) outfile="$2"; shift 2 ;;
-d) body="$2"; shift 2 ;;
*)
url="$1"
shift
;;
esac
done
if echo "$url" | grep -q '/chat/completions'; then
status="200"
body='{"choices":[{"message":{"content":"OK"}}]}'
fi
printf '%s' "$body" > "$outfile"
printf '%s' "$status"
`,
{ mode: 0o755 },
);
const script = String.raw`
const credentials = require(${credentialsPath});
const runner = require(${runnerPath});
const answers = ["6", "7", "gemini-custom"];
const messages = [];
credentials.prompt = async (message) => {
messages.push(message);
return answers.shift() || "";
};
runner.runCapture = () => "";
const { setupNim } = require(${onboardPath});
(async () => {
process.env.GEMINI_API_KEY = "gemini-secret";
const originalLog = console.log;
const lines = [];
console.log = (...args) => lines.push(args.join(" "));
try {
const result = await setupNim(null);
originalLog(JSON.stringify({ result, messages, lines }));
} finally {
console.log = originalLog;
}
})().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 || ""}`,
},
});
assert.equal(result.status, 0, result.stderr);
const payload = JSON.parse(result.stdout.trim());
assert.equal(payload.result.provider, "gemini-api");
assert.equal(payload.result.model, "gemini-custom");
assert.equal(payload.result.preferredInferenceApi, "openai-completions");
assert.match(payload.messages[0], /Choose \[/);
assert.match(payload.messages[1], /Choose model \[5\]/);
assert.match(payload.messages[2], /Google Gemini model id:/);
assert.ok(payload.lines.some((line: string) => line.includes("Google Gemini models:")));
assert.ok(payload.lines.some((line: string) => line.includes("gemini-2.5-flash")));
assert.ok(payload.lines.some((line: string) => line.includes("Other...")));