-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Expand file tree
/
Copy pathagent-args.test.ts
More file actions
1070 lines (964 loc) · 37.5 KB
/
Copy pathagent-args.test.ts
File metadata and controls
1070 lines (964 loc) · 37.5 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
import { existsSync, readFileSync, statSync } from 'node:fs';
import { test } from 'vitest';
import {
AGENT_DEFS, aider, antigravity, assert, claude, codex, copilot, cursorAgent, deepseek, devin, detectAgents, grokBuild, join, kilo, kimi, kiro, mkdtempSync, opencode, pi, qoder, qwen, rmSync, spawnEnvForAgent, tmpdir, vibe, writeFileSync, chmodSync,
} from './helpers/test-helpers.js';
import { writeAntigravityModelSelection } from '../../src/runtimes/defs/antigravity.js';
import { agentCapabilities } from '../../src/runtimes/capabilities.js';
import type { TestAgentDef } from './helpers/test-helpers.js';
// ---- Cursor Agent --trust capability (issue #4461) -------------------------
// `--trust` is only honored in `-p`/headless mode and only exists on newer
// cursor-agent builds. Older installs reject it with "unknown option
// '--trust'" and exit 1, killing Test and task execution. The flag is gated
// on the `--help` probe (capabilityFlags) like claude's --add-dir, so the
// baseline (no probe / probe failed -> caps = {}) must omit it.
test('cursor-agent omits --trust by default until the --help probe confirms support (issue #4461)', () => {
// Default state before any capability probe: agentCapabilities has no entry
// -> buildArgs gets `caps = {}` -> caps.trust is undefined -> falsy -> no
// --trust. This is also the "probe threw" case (timeout, binary missing,
// non-zero --help exit), which is exactly the older cursor-agent that
// rejects the flag. Omitting it keeps Test working there.
agentCapabilities.delete('cursor-agent');
const args = cursorAgent.buildArgs(
'',
[],
[],
{},
{ cwd: '/tmp/od-project' },
);
assert.deepEqual(args, [
'--print',
'--output-format',
'stream-json',
'--stream-partial-output',
'--force',
'--workspace',
'/tmp/od-project',
]);
assert.equal(args.includes('--trust'), false);
});
test('cursor-agent passes --trust once the --help probe detects it', () => {
agentCapabilities.set('cursor-agent', { trust: true });
try {
const args = cursorAgent.buildArgs(
'',
[],
[],
{},
{ cwd: '/tmp/od-project' },
);
assert.deepEqual(args, [
'--print',
'--output-format',
'stream-json',
'--stream-partial-output',
'--force',
'--trust',
'--workspace',
'/tmp/od-project',
]);
} finally {
agentCapabilities.delete('cursor-agent');
}
});
test('cursor-agent declares the --trust capability probe (issue #4461 root cause)', () => {
assert.deepEqual(cursorAgent.helpArgs, ['--help']);
assert.equal(cursorAgent.capabilityFlags?.['--trust'], 'trust');
});
test('opencode args keep the documented run/json argv and ignore unsupported reasoning options', () => {
agentCapabilities.delete('opencode');
const prompt = 'design a dashboard';
const baseArgs = opencode.buildArgs(prompt, [], [], {});
assert.equal(opencode.promptViaStdin, true);
assert.equal(opencode.reasoningOptions, undefined);
assert.deepEqual(opencode.helpArgs, ['run', '--help']);
assert.deepEqual(opencode.capabilityFlags?.['--dangerously-skip-permissions'], 'skipPermissions');
assert.equal(baseArgs.includes('-'), false);
assert.equal(baseArgs.includes(prompt), false);
assert.deepEqual(baseArgs, [
'run',
'--format',
'json',
]);
const withModel = opencode.buildArgs(
prompt,
[],
[],
{ model: 'anthropic/claude-sonnet-4-5' },
);
assert.deepEqual(withModel, [
'run',
'--format',
'json',
'-m',
'anthropic/claude-sonnet-4-5',
]);
const withReasoning = opencode.buildArgs(
prompt,
[],
[],
{
model: 'anthropic/claude-sonnet-4-5',
reasoning: 'high',
},
);
assert.equal(withReasoning.some((arg) => arg.includes('reason')), false);
assert.equal(withReasoning.includes('--thinking'), false);
assert.deepEqual(withReasoning, withModel);
assert.equal(withModel.includes('--dangerously-skip-permissions'), false);
assert.equal(withModel.includes('--model'), false);
});
test('opencode passes --dangerously-skip-permissions when the help probe finds it', () => {
agentCapabilities.set('opencode', { skipPermissions: true });
try {
const args = opencode.buildArgs('design a dashboard', [], [], {});
assert.deepEqual(args, [
'run',
'--format',
'json',
'--dangerously-skip-permissions',
]);
} finally {
agentCapabilities.delete('opencode');
}
});
// Copilot reads the prompt from stdin when `-p` is omitted entirely
// (upstream copilot-cli issue #1046, confirmed working as
// `echo "..." | copilot --model <id>`). The earlier `-p -` attempt
// was a dead end because Copilot takes `-` as a literal one-character
// prompt; omitting `-p` is a separate code path that does delegate to
// stdin under a non-TTY pipe. Pin `promptViaStdin: true` and the
// stdin-only argv shape so a future refactor can't silently bring
// `-p <prompt>` back and reintroduce the Windows ENAMETOOLONG
// regression (issue #705).
test('copilot delivers the prompt via stdin (no -p, no prompt body in argv)', () => {
const prompt = 'design a landing page';
const baseArgs = copilot.buildArgs(prompt, [], [], {});
assert.equal(copilot.promptViaStdin, true);
assert.ok(
!baseArgs.includes('-p'),
'copilot argv must not include -p; the prompt rides stdin',
);
assert.ok(
!baseArgs.includes(prompt),
'copilot argv must not include the prompt body; it rides stdin',
);
assert.deepEqual(baseArgs, [
'--allow-all-tools',
'--output-format',
'json',
]);
});
test('copilot args append model and extra dirs after the base flags without reintroducing -p', () => {
const prompt = 'design a landing page';
const args = copilot.buildArgs(
prompt,
[],
['/tmp/od-skills', '/tmp/od-design-systems'],
{ model: 'claude-sonnet-4.6' },
);
assert.ok(!args.includes('-p'));
assert.ok(!args.includes(prompt));
assert.deepEqual(args, [
'--allow-all-tools',
'--output-format',
'json',
'--model',
'claude-sonnet-4.6',
'--add-dir',
'/tmp/od-skills',
'--add-dir',
'/tmp/od-design-systems',
]);
});
test('copilot drops empty / non-string entries from extraAllowedDirs without reintroducing -p', () => {
const prompt = 'design a landing page';
const args = copilot.buildArgs(
prompt,
[],
['', null, '/tmp/od-skills', undefined] as unknown as string[],
{},
);
assert.ok(!args.includes('-p'));
// Only the one valid path survives.
const addDirIndex = args.indexOf('--add-dir');
assert.equal(args[addDirIndex + 1], '/tmp/od-skills');
assert.equal(args.filter((a) => a === '--add-dir').length, 1);
});
// Mirror of the Claude Code 200_000-char synthetic-prompt guard: even
// when the composed prompt is large enough to blow the Windows
// CreateProcess command-line cap (~32 KB direct, ~8 KB through a `.cmd`
// shim), no argv entry must ever carry the prompt body. This is the
// structural assertion that the issue #705 fix can't quietly regress.
test('copilot flags promptViaStdin and never embeds the prompt in argv', () => {
assert.equal(copilot.promptViaStdin, true);
const longPrompt = 'x'.repeat(200_000);
const args = copilot.buildArgs(longPrompt, [], [], {});
assert.ok(Array.isArray(args), 'copilot.buildArgs must return argv');
assert.equal(
args.includes(longPrompt),
false,
'prompt must not appear in argv',
);
for (const arg of args) {
assert.ok(
typeof arg === 'string' && arg.length < 1000,
`no argv entry should carry the prompt body (saw length ${arg.length})`,
);
}
});
test('kiro args use acp subcommand for json-rpc streaming', () => {
const args = kiro.buildArgs('', [], [], {});
assert.deepEqual(args, ['acp']);
assert.equal(kiro.streamFormat, 'acp-json-rpc');
});
test('devin args use acp subcommand for json-rpc streaming', () => {
const args = devin.buildArgs('', [], [], {});
assert.deepEqual(args, [
'--permission-mode',
'dangerous',
'--respect-workspace-trust',
'false',
'acp',
]);
assert.equal(devin.streamFormat, 'acp-json-rpc');
});
test('pi args use rpc mode without --no-session and append model/thinking options', () => {
const baseArgs = pi.buildArgs('', [], [], {}, {});
assert.deepEqual(baseArgs, ['--mode', 'rpc']);
assert.ok(!baseArgs.includes('--no-session'), 'pi must not pass --no-session');
assert.equal(pi.promptViaStdin, true);
assert.equal(pi.streamFormat, 'pi-rpc');
assert.equal(pi.supportsImagePaths, true);
const withModel = pi.buildArgs('', [], [], { model: 'anthropic/claude-sonnet-4-5' }, {});
assert.deepEqual(withModel, [
'--mode',
'rpc',
'--model',
'anthropic/claude-sonnet-4-5',
]);
const withThinking = pi.buildArgs('', [], [], { reasoning: 'high' }, {});
assert.deepEqual(withThinking, [
'--mode',
'rpc',
'--thinking',
'high',
]);
});
test('pi fetchModels reads the model table from stdout', async () => {
const dir = mkdtempSync(join(tmpdir(), 'od-pi-models-'));
try {
const bin = join(dir, process.platform === 'win32' ? 'pi.cmd' : 'pi');
if (process.platform === 'win32') {
writeFileSync(
bin,
'@echo off\r\nif "%~1"=="--list-models" (\r\n echo provider model context max-out thinking images\r\n echo anthropic claude-sonnet-4-5 200K 64K yes yes\r\n exit /b 0\r\n)\r\nexit /b 1\r\n',
);
} else {
writeFileSync(
bin,
'#!/bin/sh\nif [ "$1" = "--list-models" ]; then\n printf \'%s\\n\' \\\n \'provider model context max-out thinking images\' \\\n \'anthropic claude-sonnet-4-5 200K 64K yes yes\'\n exit 0\nfi\nexit 1\n',
);
chmodSync(bin, 0o755);
}
assert.ok(pi.fetchModels, 'pi must define fetchModels');
const models = await pi.fetchModels(bin, {});
assert.deepEqual(models, [
{ id: 'default', label: 'Default (CLI config)' },
{
id: 'anthropic/claude-sonnet-4-5',
label: 'anthropic/claude-sonnet-4-5',
},
]);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
test('pi args forward extraAllowedDirs as --append-system-prompt flags', () => {
const args = pi.buildArgs(
'',
[],
['/tmp/skills', '/tmp/design-systems'],
{},
{},
);
assert.deepEqual(args, [
'--mode',
'rpc',
'--append-system-prompt',
'/tmp/skills',
'--append-system-prompt',
'/tmp/design-systems',
]);
});
test('pi args filter relative paths from extraAllowedDirs', () => {
const args = pi.buildArgs(
'',
[],
['/tmp/skills', 'relative/path', '/tmp/design-systems'],
{},
{},
);
// Relative paths should be filtered out.
assert.deepEqual(args, [
'--mode',
'rpc',
'--append-system-prompt',
'/tmp/skills',
'--append-system-prompt',
'/tmp/design-systems',
]);
});
test('pi args combine model, thinking, and extraAllowedDirs', () => {
const args = pi.buildArgs(
'',
[],
['/tmp/skills'],
{ model: 'openai/gpt-5', reasoning: 'medium' },
{},
);
assert.deepEqual(args, [
'--mode',
'rpc',
'--model',
'openai/gpt-5',
'--thinking',
'medium',
'--append-system-prompt',
'/tmp/skills',
]);
});
test('qoder entry uses qodercli with stream-json stdin delivery and tier model hints', () => {
assert.equal(qoder.name, 'Qoder CLI');
assert.equal(qoder.bin, 'qodercli');
assert.deepEqual(qoder.versionArgs, ['--version']);
assert.equal(qoder.promptViaStdin, true);
assert.equal(qoder.streamFormat, 'qoder-stream-json');
assert.deepEqual(qoder.fallbackModels.map((m) => m.id), [
'default',
'lite',
'efficient',
'auto',
'performance',
'ultimate',
]);
});
test('qoder args use non-interactive print mode with cwd, model, and add-dir', () => {
const args = qoder.buildArgs(
'prompt must not appear in argv',
['/tmp/uploads/logo.png', '/tmp/uploads/hero concept.png'],
[
'/repo/skills',
'',
null as unknown as string,
'./relative-skills',
'relative-design-systems',
'/repo/design-systems',
],
{ model: 'performance' },
{ cwd: '/tmp/od-project' },
);
assert.deepEqual(args, [
'-p',
'--output-format',
'stream-json',
'--yolo',
'-w',
'/tmp/od-project',
'--model',
'performance',
'--add-dir',
'/repo/skills',
'--add-dir',
'/repo/design-systems',
'--attachment',
'/tmp/uploads/logo.png',
'--attachment',
'/tmp/uploads/hero concept.png',
]);
assert.equal(args.includes('prompt must not appear in argv'), false);
assert.equal(args.includes('./relative-skills'), false);
assert.equal(args.includes('relative-design-systems'), false);
});
test('qoder args omit default model and cwd when absent', () => {
const args = qoder.buildArgs('', [], [], { model: 'default' }, {});
assert.deepEqual(args, [
'-p',
'--output-format',
'stream-json',
'--yolo',
]);
assert.equal(args.includes('--model'), false);
assert.equal(args.includes('-w'), false);
});
test('qoder args omit empty, non-string, and relative add-dir entries', () => {
const args = qoder.buildArgs('', [], [
'',
null as unknown as string,
undefined as unknown as string,
42 as unknown as string,
'./skills',
'design-systems',
]);
assert.equal(args.includes('--add-dir'), false);
});
test('qoder args omit empty, non-string, and relative image attachment entries', () => {
const args = qoder.buildArgs('', [
'',
null as unknown as string,
undefined as unknown as string,
42 as unknown as string,
'./uploads/logo.png',
'uploads/hero.png',
'/tmp/uploads/logo.png',
], []);
assert.deepEqual(
args.filter((arg) => arg === '--attachment').length,
1,
);
assert.ok(args.includes('/tmp/uploads/logo.png'));
assert.equal(args.includes('./uploads/logo.png'), false);
assert.equal(args.includes('uploads/hero.png'), false);
});
test('qoder adapter inherits QODER_PERSONAL_ACCESS_TOKEN from daemon env', () => {
const env = spawnEnvForAgent('qoder', {
QODER_PERSONAL_ACCESS_TOKEN: 'qoder-pat',
PATH: '/usr/bin',
OD_DAEMON_URL: 'http://127.0.0.1:7456',
});
assert.equal(env.QODER_PERSONAL_ACCESS_TOKEN, 'qoder-pat');
assert.equal(env.PATH, '/usr/bin');
assert.equal(env.OD_DAEMON_URL, 'http://127.0.0.1:7456');
});
test('qoder adapter does not define static secret env', () => {
assert.equal(
(qoder as TestAgentDef & { env?: Record<string, string> }).env?.QODER_PERSONAL_ACCESS_TOKEN,
undefined,
);
});
test('detectAgents keeps qoder unavailable with fallback metadata when qodercli is missing', async () => {
const dir = mkdtempSync(join(tmpdir(), 'od-agents-empty-'));
try {
process.env.OD_AGENT_HOME = dir;
process.env.PATH = dir;
const agents = await detectAgents();
const detected = agents.find((agent) => agent.id === 'qoder');
assert.ok(detected);
assert.equal(detected.available, false);
assert.equal(detected.bin, 'qodercli');
assert.deepEqual(detected.models.map((m: { id: string }) => m.id), [
'default',
'lite',
'efficient',
'auto',
'performance',
'ultimate',
]);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
test('qwen args check promptViaStdin, base args, model args and exclude `-` sentinel', () => {
assert.equal(qwen.promptViaStdin, true);
const baseArgs = qwen.buildArgs('', [], [], {}, { cwd: '/tmp/od-project' });
assert.deepEqual(baseArgs, ['--yolo']);
assert.equal(baseArgs.includes('-'), false);
const withModel = qwen.buildArgs(
'',
[],
[],
{ model: 'qwen3-coder-plus' },
{ cwd: '/tmp/od-project' },
);
assert.deepEqual(withModel, ['--yolo', '--model', 'qwen3-coder-plus']);
assert.equal(withModel.includes('-'), false);
});
// `agy` exposes `-p` (print mode, alias for `--print`) plus `-` as
// the stdin sentinel — confirmed against `agy --help` on v1.0.3, where
// `Available subcommands` is `changelog / help / install / plugin /
// update` (no `chat`). Earlier review iterations pinned `['chat', '-']`
// based on a different agy build the looper reviewer environment uses;
// the installed CLI does not recognise it, exits 0 with no stdout, and
// the daemon would render the resulting empty reply as a "successful"
// agent response — exactly the failure mode the auth/quota guard at
// server.ts ~12090 is meant to catch but for the wrong reason.
test('antigravity delivers prompt via managed temp file instead of stdin', () => {
assert.equal(antigravity.bin, 'agy');
assert.equal(antigravity.streamFormat, 'plain');
assert.equal(antigravity.promptViaStdin, false);
assert.equal(antigravity.promptViaFile, true);
assert.throws(() => {
antigravity.buildArgs('hello', [], [], {}, {});
}, /requires runtimeContext\.promptFilePath/);
const expectedFileText = 'Read the system instructions, conversation history, and user request from the file /tmp/managed-prompt.md. Follow the instructions strictly and provide the final response to the user\'s latest request.';
const args = antigravity.buildArgs('write hello world', [], [], {}, {
promptFilePath: '/tmp/managed-prompt.md'
});
assert.deepEqual(args, ['--add-dir=/tmp', '-p', expectedFileText]);
const argsWithLog = antigravity.buildArgs('write hello world', [], [], {}, {
agentLogFilePath: '/tmp/od-agy-test.log',
promptFilePath: '/tmp/managed-prompt.md'
});
assert.deepEqual(argsWithLog, ['--log-file=/tmp/od-agy-test.log', '--add-dir=/tmp', '-p', expectedFileText]);
// No `--model` flag exists upstream, so buildArgs argv must stay the
// same regardless of which label the user picks.
// Pass a temp antigravitySettingsPath so buildArgs does not touch the
// real ~/.gemini/antigravity-cli/settings.json during a unit test run.
const settingsDir = mkdtempSync(join(tmpdir(), 'od-agy-argv-'));
try {
const withModel = antigravity.buildArgs('hi', [], [], {
model: 'Gemini 3.1 Pro (High)',
}, {
agentLogFilePath: '/tmp/od-agy-test.log',
antigravitySettingsPath: join(settingsDir, 'settings.json'),
promptFilePath: '/tmp/managed-prompt.md'
});
assert.equal(withModel.includes('--model'), false);
assert.deepEqual(withModel, ['--log-file=/tmp/od-agy-test.log', '--add-dir=/tmp', '-p', expectedFileText]);
} finally {
rmSync(settingsDir, { recursive: true, force: true });
}
// Argv must NOT carry `-c` even on follow-up turns. We tested resume
// mode and found agy's `-c` activates an internal agentic loop (tool
// calls, retries, fallback-to-cached-response) that overrides OD's
// system-prompt OVERRIDE — producing byte-identical form re-emissions
// on turn 2. The stateless path + sanitized transcript injection is
// what actually breaks the discovery loop. Pin both shapes so a
// future contributor doesn't silently reintroduce `-c` and hit the
// same regression.
const followUp = antigravity.buildArgs('next message', [], [], {}, {
hasPriorAssistantTurn: true,
promptFilePath: '/tmp/managed-prompt.md'
});
assert.deepEqual(followUp, ['--add-dir=/tmp', '-p', expectedFileText]);
assert.equal(followUp.includes('-c'), false);
const firstTurn = antigravity.buildArgs('first', [], [], {}, {
hasPriorAssistantTurn: false,
promptFilePath: '/tmp/managed-prompt.md'
});
assert.deepEqual(firstTurn, ['--add-dir=/tmp', '-p', expectedFileText]);
assert.equal(antigravity.resumesSessionViaCli, undefined);
assert.equal(antigravity.maxPromptArgBytes, undefined);
// Picker exposes the synthetic Default + the 8 labels agy's TUI
// Switch-Model surfaces for consumer-tier accounts. The set is small
// enough to ship statically; revisit when upstream adds an `agy
// models` subcommand (also tracked under issue #35).
assert.deepEqual(
antigravity.fallbackModels.map((m) => m.id),
[
'default',
'Gemini 3.1 Pro (High)',
'Gemini 3.1 Pro (Low)',
'Gemini 3.5 Flash (High)',
'Gemini 3.5 Flash (Medium)',
'Gemini 3.5 Flash (Low)',
'Claude Sonnet 4.6 (Thinking)',
'Claude Opus 4.6 (Thinking)',
'GPT-OSS 120B (Medium)',
],
);
// `agy` v1.0.3 has no `--model` flag (upstream #35), no `models`
// subcommand, and no `/model` slash command — a user-typed model id
// would be silently ignored at spawn, looking like an OD bug. The
// settings UI hides the "Custom (fill below)" option when this is
// `false`. Remove this opt-out once upstream wires #35.
assert.equal(antigravity.supportsCustomModel, false);
});
// `agy` reads `~/.gemini/antigravity-cli/settings.json` on every CLI
// startup — verified by capturing the `--log-file` line `Propagating
// selected model override to backend: label=…`. Routing OD's model
// picker through that file lets the user choose a model from Settings
// even though agy has no `--model` flag (upstream issue #35).
//
// Two behaviors must hold and are pinned here:
//
// 1. Picking "default" must NOT touch settings.json — respect the
// label the user previously set inside agy's own TUI.
// 2. Picking a concrete label must write that exact string into the
// `model` field while preserving every other key (e.g.
// `trustedWorkspaces` that agy populates on first-run consent).
test('antigravity persists model selection to agy settings.json', () => {
const dir = mkdtempSync(join(tmpdir(), 'od-antigravity-settings-'));
try {
const settingsPath = join(dir, 'settings.json');
// 1. Pre-seed the file as agy would after onboarding: a model label
// plus a trustedWorkspaces array the user has already consented to.
writeFileSync(
settingsPath,
JSON.stringify(
{
model: 'GPT-OSS 120B (Medium)',
trustedWorkspaces: ['/tmp/od-project'],
},
null,
2,
),
);
// 2. Write a new label and assert the model swap + trusted list intact.
writeAntigravityModelSelection('Gemini 3.1 Pro (High)', settingsPath);
const after = JSON.parse(readFileSync(settingsPath, 'utf8'));
assert.equal(after.model, 'Gemini 3.1 Pro (High)');
assert.deepEqual(after.trustedWorkspaces, ['/tmp/od-project']);
// 3. When the file doesn't exist (fresh install before onboarding),
// we must create it rather than crash the spawn pipeline.
const freshPath = join(dir, 'fresh', 'settings.json');
writeAntigravityModelSelection('Claude Sonnet 4.6 (Thinking)', freshPath);
assert.ok(existsSync(freshPath));
assert.equal(
JSON.parse(readFileSync(freshPath, 'utf8')).model,
'Claude Sonnet 4.6 (Thinking)',
);
// 4. When the existing file is corrupt JSON, we must rewrite it from
// scratch instead of leaving agy with an unparseable settings file.
const corruptPath = join(dir, 'corrupt-settings.json');
writeFileSync(corruptPath, '{not valid json');
writeAntigravityModelSelection('Gemini 3.5 Flash (Low)', corruptPath);
const recovered = JSON.parse(readFileSync(corruptPath, 'utf8'));
assert.equal(recovered.model, 'Gemini 3.5 Flash (Low)');
// 5. Atomic replacement must preserve the destination's existing mode
// so sensitive policies in settings.json do not become world-readable.
const modePath = join(dir, 'mode-settings.json');
writeFileSync(modePath, JSON.stringify({ model: 'old' }));
chmodSync(modePath, 0o600);
const expectedMode = statSync(modePath).mode & 0o777;
writeAntigravityModelSelection('Gemini 3.5 Pro', modePath);
const postStat = statSync(modePath);
assert.equal(postStat.mode & 0o777, expectedMode);
} finally {
rmSync(dir, { recursive: true, force: true });
}
});
// AMR routes model selection through ACP `session/set_model` and only
// accepts ids that survive the live `vela models` preflight, so a free
// text id silently fails at spawn. Same custom-model opt-out shape as
// antigravity — the declarative `supportsCustomModel: false` on the
// def is the single source of truth the settings UI consults, and the
// fallback "Custom" item should not appear in the model picker.
test('amr opts out of the Custom-model picker option', () => {
const amr = AGENT_DEFS.find((a) => a.id === 'amr');
assert.ok(amr, 'amr def must remain registered');
assert.equal(amr.supportsCustomModel, false);
});
test('kiro fetchModels falls back to fallbackModels when detection fails', async () => {
// fetchModels rejects when the binary doesn't exist; the daemon's
// probe() catches this and uses fallbackModels instead.
assert.ok(kiro.fetchModels, 'kiro must define fetchModels');
const result = await kiro
.fetchModels('/nonexistent/kiro-cli', {})
.catch(() => null);
assert.equal(result, null);
assert.ok(Array.isArray(kiro.fallbackModels));
const fallbackModel = kiro.fallbackModels[0];
assert.ok(fallbackModel);
assert.equal(fallbackModel.id, 'default');
});
test('aider args carry the non-TTY suppression flags, deliver the prompt via --message, and gate model behind an explicit selection', () => {
// Argv-only delivery: aider does not accept `-` as a stdin sentinel for
// either --message or --message-file, so the daemon must guard against
// ENAMETOOLONG before spawn. Same pattern as deepseek.
assert.equal(aider.promptViaStdin, undefined);
assert.equal(aider.maxPromptArgBytes, 30_000);
assert.equal(aider.streamFormat, 'plain');
const baseArgs = aider.buildArgs('hello world', [], [], {}, { cwd: '/tmp/od-project' });
assert.deepEqual(baseArgs, [
'--yes-always',
'--no-pretty',
'--no-git',
'--no-auto-commits',
'--no-suggest-shell-commands',
'--no-show-model-warnings',
'--message',
'hello world',
]);
// The default sentinel is dropped so the user's aider config / env can
// pick the model unconstrained — matches qwen/deepseek behavior.
const defaultModelArgs = aider.buildArgs(
'hi',
[],
[],
{ model: 'default' },
{ cwd: '/tmp/od-project' },
);
assert.equal(defaultModelArgs.includes('--model'), false);
const withModel = aider.buildArgs(
'edit foo.ts',
[],
[],
{ model: 'deepseek/deepseek-chat' },
{ cwd: '/tmp/od-project' },
);
assert.deepEqual(withModel, [
'--yes-always',
'--no-pretty',
'--no-git',
'--no-auto-commits',
'--no-suggest-shell-commands',
'--no-show-model-warnings',
'--model',
'deepseek/deepseek-chat',
'--message',
'edit foo.ts',
]);
});
test('kilo args use acp subcommand for json-rpc streaming', () => {
const args = kilo.buildArgs('', [], [], {});
assert.deepEqual(args, ['acp']);
assert.equal(kilo.streamFormat, 'acp-json-rpc');
});
test('kimi args use ACP so composed prompts do not travel through argv', () => {
const args = kimi.buildArgs('design a page', [], [], {});
assert.deepEqual(args, ['acp']);
assert.equal(args.includes('--yolo'), false);
assert.equal(kimi.streamFormat, 'acp-json-rpc');
assert.equal(kimi.eventParser, undefined);
assert.equal(kimi.mcpDiscovery, 'mature-acp');
assert.equal(kimi.externalMcpInjection, 'acp-merge');
assert.equal(kimi.maxPromptArgBytes, undefined);
});
test('kimi args leave model selection to the ACP session', () => {
const args = kimi.buildArgs('hello', [], [], { model: 'moonshot-v1-32k' });
assert.deepEqual(args, ['acp']);
});
test('kilo fetchModels falls back to fallbackModels when detection fails', async () => {
assert.ok(kilo.fetchModels, 'kilo must define fetchModels');
const result = await kilo.fetchModels('/nonexistent/kilo', {}).catch(() => null);
assert.equal(result, null);
assert.ok(Array.isArray(kilo.fallbackModels));
const fallbackModel = kilo.fallbackModels[0];
assert.ok(fallbackModel);
assert.equal(fallbackModel.id, 'default');
assert.equal(kilo.fallbackModels.length, 1);
});
// ---- reasoning-effort clamp ------------------------------------------------
// Drives clampCodexReasoning through the public buildArgs surface so the
// helper stays non-exported. The wire-level `-c model_reasoning_effort="..."`
// flag is what the codex CLI (and ultimately OpenAI) actually sees.
test('codex buildArgs clamps reasoning effort per model', () => {
const cases: Array<[string | undefined, string, string]> = [
// [model, reasoning, expected wire-level effort]
// gpt-5.5 family (and unknown / 'default' which we treat as 5.5):
// minimal -> low, others pass through.
[undefined, 'minimal', 'low'],
['default', 'minimal', 'low'],
['gpt-5.2', 'minimal', 'low'],
['gpt-5.3', 'minimal', 'low'],
['gpt-5.4', 'minimal', 'low'],
['gpt-5.5', 'minimal', 'low'],
['gpt-5.5', 'low', 'low'],
['gpt-5.5', 'medium', 'medium'],
['gpt-5.5', 'high', 'high'],
['vendor/gpt-5.5-foo', 'minimal', 'low'], // path-style id
// gpt-5.1: xhigh isn't supported, others pass through.
['gpt-5.1', 'xhigh', 'high'],
['gpt-5.1', 'high', 'high'],
// gpt-5.1-codex-mini: caps at medium / high only.
['gpt-5.1-codex-mini', 'minimal', 'medium'],
['gpt-5.1-codex-mini', 'low', 'medium'],
['gpt-5.1-codex-mini', 'medium', 'medium'],
['gpt-5.1-codex-mini', 'high', 'high'],
['gpt-5.1-codex-mini', 'xhigh', 'high'],
// Unknown / future families: pass through; let the API surface its error
// as the signal a new rule belongs in clampCodexReasoning.
['gpt-6', 'minimal', 'minimal'],
];
for (const [model, reasoning, expected] of cases) {
const args = codex.buildArgs(
'',
[],
[],
{ ...(model === undefined ? {} : { model }), reasoning },
{ cwd: '/tmp/od-project' },
);
assert.ok(
args.includes(`model_reasoning_effort="${expected}"`),
`(model=${model ?? '<none>'}, reasoning=${reasoning}) → expected ${expected}; args=${JSON.stringify(args)}`,
);
}
});
test('codex buildArgs omits model_reasoning_effort when reasoning is "default"', () => {
const args = codex.buildArgs(
'',
[],
[],
{ reasoning: 'default' },
{ cwd: '/tmp/od-project' },
);
assert.equal(
args.some(
(a) => typeof a === 'string' && a.startsWith('model_reasoning_effort='),
),
false,
);
});
test('grok-build uses --prompt-file and never embeds the prompt in argv or stdin', () => {
const prompt = 'summarize the current page layout';
const promptFilePath = '/tmp/od-grok-prompt/prompt.md';
const args = grokBuild.buildArgs(
prompt,
[],
[],
{ model: 'grok-4.3', reasoning: 'high' },
{ cwd: '/tmp/od-project', promptFilePath },
);
assert.equal(grokBuild.promptViaFile, true);
assert.equal(grokBuild.promptViaStdin, false);
assert.deepEqual(args, [
'--prompt-file',
promptFilePath,
'--no-plan',
'--always-approve',
'--model',
'grok-4.3',
]);
assert.equal(args.includes(prompt), false);
assert.equal(args.includes('-'), false);
assert.equal(args.includes('-p'), false);
assert.equal(args.includes('--single'), false);
assert.equal(args.filter((entry) => entry === '--prompt-file').length, 1);
});
test('grok-build disables plan mode and auto-approves headless tool calls (issue #5507)', () => {
const promptFilePath = '/tmp/od-grok-prompt/prompt.md';
const args = grokBuild.buildArgs('', [], [], { model: 'grok-build' }, { promptFilePath });
assert.deepEqual(args.slice(2, 4), ['--no-plan', '--always-approve']);
});
test('grok-build omits effort for default/build models but keeps it for reasoning models', () => {
const promptFilePath = '/tmp/od-grok-prompt/prompt.md';
const defaultArgs = grokBuild.buildArgs('', [], [], { model: 'default', reasoning: 'high' }, { promptFilePath });
assert.equal(defaultArgs.includes('--effort'), false);
const buildArgs = grokBuild.buildArgs('', [], [], { model: 'grok-build', reasoning: 'high' }, { promptFilePath });
assert.equal(buildArgs.includes('--effort'), false);
const reasoningArgs = grokBuild.buildArgs('', [], [], { model: 'grok-4.20-reasoning', reasoning: 'high' }, { promptFilePath });
assert.deepEqual(reasoningArgs, [
'--prompt-file',
promptFilePath,
'--no-plan',
'--always-approve',
'--model',
'grok-4.20-reasoning',
'--effort',
'high',
]);
});
test('grok-build requires a daemon-provided prompt file path', () => {
assert.throws(
() => grokBuild.buildArgs('hi', [], [], {}, { cwd: '/tmp/od-project' }),
/promptFilePath/,
);
});
test('claude flags promptViaStdin and never embeds the prompt in argv', () => {
// Long composed prompts (system prompt + design system + skill body +
// user message) routinely exceed Linux MAX_ARG_STRLEN (~128 KB) and the
// Windows CreateProcess command-line cap (~32 KB direct, ~8 KB via .cmd
// shim). The fix is to deliver the prompt on stdin instead of argv —
// these assertions guard that contract.
assert.equal(claude.promptViaStdin, true);
const longPrompt = 'x'.repeat(200_000);
const args = claude.buildArgs(
longPrompt,
[],
[],
{},
{ cwd: '/tmp/od-project' },
);
assert.ok(Array.isArray(args), 'claude.buildArgs must return argv');
assert.equal(
args.includes(longPrompt),
false,
'prompt must not appear in argv',
);
for (const arg of args) {
assert.ok(
typeof arg === 'string' && arg.length < 1000,
`no argv entry should carry the prompt body (saw length ${arg.length})`,
);
}
// `-p` (print mode) must still be present; without it claude drops into
// an interactive REPL that the daemon has no TTY for.
assert.ok(args.includes('-p'), 'claude argv must include -p');
});
// ---- Claude Code --add-dir capability (issue #430) -------------------------
// Skill seeds (`skills/<id>/assets/template.html`) and design-system specs
// (`design-systems/<id>/DESIGN.md`) live outside the project cwd. Without
// `--add-dir`, Claude Code's directory access policy blocks reads on any
// path outside the working directory. Bug was that we probed global `claude
// --help` for `--add-dir` but that flag only appears in `claude -p --help`.
test('claude buildArgs passes --add-dir when dirs are supplied (issue #430, probing-failed baseline)', () => {
// This is the default state before any capability probe runs: agentCapabilities
// has no entry -> buildArgs gets `caps = {}` -> caps.addDir is undefined ->
// undefined !== false -> true. This is also the "probing threw" case: timeout,
// binary not found, non-zero exit code from --help. Dirs are always passed
// unless capability probing explicitly detected --help and found no --add-dir.
const args = claude.buildArgs(
'',
[],
['/repo/skills', '/repo/design-systems'],
{},
);
const addDirIndex = args.indexOf('--add-dir');
assert.ok(addDirIndex >= 0, '--add-dir must be present by default (safe baseline)');