-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Expand file tree
/
Copy pathadapters.test.ts
More file actions
1349 lines (1178 loc) · 56.3 KB
/
Copy pathadapters.test.ts
File metadata and controls
1349 lines (1178 loc) · 56.3 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 { describe, it, expect } from 'vitest';
import path from 'path';
import { amazonQAdapter } from '../../../src/core/command-generation/adapters/amazon-q.js';
import { antigravityAdapter } from '../../../src/core/command-generation/adapters/antigravity.js';
import { auggieAdapter } from '../../../src/core/command-generation/adapters/auggie.js';
import { bobAdapter } from '../../../src/core/command-generation/adapters/bob.js';
import { claudeAdapter } from '../../../src/core/command-generation/adapters/claude.js';
import { clineAdapter } from '../../../src/core/command-generation/adapters/cline.js';
import { commandCodeAdapter } from '../../../src/core/command-generation/adapters/command-code.js';
import { codebuddyAdapter } from '../../../src/core/command-generation/adapters/codebuddy.js';
import { continueAdapter } from '../../../src/core/command-generation/adapters/continue.js';
import { costrictAdapter } from '../../../src/core/command-generation/adapters/costrict.js';
import { crushAdapter } from '../../../src/core/command-generation/adapters/crush.js';
import { cursorAdapter } from '../../../src/core/command-generation/adapters/cursor.js';
import { devinAdapter } from '../../../src/core/command-generation/adapters/devin.js';
import { factoryAdapter } from '../../../src/core/command-generation/adapters/factory.js';
import { geminiAdapter } from '../../../src/core/command-generation/adapters/gemini.js';
import { githubCopilotAdapter } from '../../../src/core/command-generation/adapters/github-copilot.js';
import { iflowAdapter } from '../../../src/core/command-generation/adapters/iflow.js';
import { junieAdapter } from '../../../src/core/command-generation/adapters/junie.js';
import { kilocodeAdapter } from '../../../src/core/command-generation/adapters/kilocode.js';
import { kiroAdapter } from '../../../src/core/command-generation/adapters/kiro.js';
import { lingmaAdapter } from '../../../src/core/command-generation/adapters/lingma.js';
import { ohMyPiAdapter } from '../../../src/core/command-generation/adapters/oh-my-pi.js';
import { opencodeAdapter } from '../../../src/core/command-generation/adapters/opencode.js';
import { piAdapter } from '../../../src/core/command-generation/adapters/pi.js';
import { qoderAdapter } from '../../../src/core/command-generation/adapters/qoder.js';
import { qwenAdapter } from '../../../src/core/command-generation/adapters/qwen.js';
import { roocodeAdapter } from '../../../src/core/command-generation/adapters/roocode.js';
import { traeAdapter } from '../../../src/core/command-generation/adapters/trae.js';
import { codeassistantAdapter } from '../../../src/core/command-generation/adapters/codeassistant.js';
import { zcodeAdapter } from '../../../src/core/command-generation/adapters/zcode.js';
import type {
CommandContent,
ToolCommandAdapter,
} from '../../../src/core/command-generation/types.js';
import { CommandAdapterRegistry } from '../../../src/core/command-generation/registry.js';
import { generateCommand } from '../../../src/core/command-generation/generator.js';
import { getCommandContents } from '../../../src/core/shared/skill-generation.js';
import { parse as parseYaml } from 'yaml';
import { parse as parseToml } from 'smol-toml';
describe('command-generation/adapters', () => {
const sampleContent: CommandContent = {
id: 'explore',
name: 'OpenSpec Explore',
description: 'Enter explore mode for thinking',
category: 'Workflow',
tags: ['workflow', 'explore', 'experimental'],
body: 'This is the command body.\n\nWith multiple lines.',
};
describe('claudeAdapter', () => {
it('should have correct toolId', () => {
expect(claudeAdapter.toolId).toBe('claude');
});
it('should generate correct file path', () => {
const filePath = claudeAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.claude', 'commands', 'opsx', 'explore.md'));
});
it('should generate correct file path for different command IDs', () => {
expect(claudeAdapter.getFilePath('new')).toBe(path.join('.claude', 'commands', 'opsx', 'new.md'));
expect(claudeAdapter.getFilePath('bulk-archive')).toBe(path.join('.claude', 'commands', 'opsx', 'bulk-archive.md'));
});
it('should format file with correct YAML frontmatter', () => {
const output = claudeAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('name: "OpenSpec Explore"');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('allowed-tools: Bash(openspec:*)');
expect(output).toContain('category: "Workflow"');
expect(output).toContain('tags: ["workflow", "explore", "experimental"]');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.\n\nWith multiple lines.');
});
it('should handle empty tags', () => {
const contentNoTags: CommandContent = { ...sampleContent, tags: [] };
const output = claudeAdapter.formatFile(contentNoTags);
expect(output).toContain('tags: []');
});
});
describe('cursorAdapter', () => {
it('should have correct toolId', () => {
expect(cursorAdapter.toolId).toBe('cursor');
});
it('should generate correct file path with opsx- prefix', () => {
const filePath = cursorAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.cursor', 'commands', 'opsx-explore.md'));
});
it('should generate correct file paths for different commands', () => {
expect(cursorAdapter.getFilePath('new')).toBe(path.join('.cursor', 'commands', 'opsx-new.md'));
expect(cursorAdapter.getFilePath('bulk-archive')).toBe(path.join('.cursor', 'commands', 'opsx-bulk-archive.md'));
});
it('should format file with Cursor-specific frontmatter', () => {
const output = cursorAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('name: "/opsx-explore"');
expect(output).toContain('id: "opsx-explore"');
expect(output).toContain('category: "Workflow"');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
it('should not include tags in Cursor format', () => {
const output = cursorAdapter.formatFile(sampleContent);
expect(output).not.toContain('tags:');
});
});
describe('commandCodeAdapter', () => {
it('should have correct toolId', () => {
expect(commandCodeAdapter.toolId).toBe('command-code');
});
it('should generate correct file path with opsx- prefix', () => {
const filePath = commandCodeAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.commandcode', 'commands', 'opsx-explore.md'));
});
it('should format the documented plain Markdown command body', () => {
const output = commandCodeAdapter.formatFile(sampleContent);
expect(output).toBe(`${sampleContent.body}\n`);
expect(output).not.toContain('description:');
});
it('should pass invocation arguments into the OpenSpec input contract', () => {
const output = commandCodeAdapter.formatFile({
...sampleContent,
body: '# OpenSpec command\n\n**Input**: A change name or description.\n\nRun the workflow.',
});
expect(output).toContain(
'**Input**: A change name or description.\n**Provided arguments**: $ARGUMENTS'
);
});
it.each(['$ARGUMENTS', '$@', '${ARGUMENTS}', '${@}'])(
'should not duplicate an existing %s placeholder',
(placeholder) => {
const output = commandCodeAdapter.formatFile({
...sampleContent,
body: `**Input**: A change name.\n**Provided arguments**: ${placeholder}`,
});
expect(output.match(/\*\*Provided arguments\*\*:/g)).toHaveLength(1);
}
);
it('should preserve invocation arguments for every workflow that accepts them', () => {
const commandsWithoutArguments = getCommandContents()
.filter((content) => {
const output = generateCommand(content, commandCodeAdapter).fileContent;
return !output.includes('**Provided arguments**: $ARGUMENTS');
})
.map((content) => content.id);
// Onboarding is deliberately interactive and has no invocation input.
// This list is a tripwire for a new workflow that accidentally drops args.
expect(commandsWithoutArguments).toEqual(['onboard']);
});
it('is generated by generateCommand with hyphen command references', () => {
const contentWithCommands: CommandContent = {
...sampleContent,
body: 'Use /opsx:new to start, then /opsx:apply to implement.',
};
const output = generateCommand(contentWithCommands, commandCodeAdapter).fileContent;
expect(output).toContain('/opsx-new');
expect(output).toContain('/opsx-apply');
expect(output).not.toContain('/opsx:new');
expect(output).not.toContain('/opsx:apply');
});
});
describe('devinAdapter', () => {
it('should have correct toolId', () => {
expect(devinAdapter.toolId).toBe('devin');
});
it('should generate correct file path', () => {
const filePath = devinAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.devin', 'workflows', 'opsx-explore.md'));
});
it('should format file with YAML frontmatter', () => {
const output = devinAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('name: "OpenSpec Explore"');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('category: "Workflow"');
expect(output).toContain('tags: ["workflow", "explore", "experimental"]');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
// The body's `/opsx:*` references are rewritten to the `/opsx-*` form
// Devin registers by the generator, not here — adapters are pure
// formatters. Covered for devin in invocation.test.ts.
// Frontmatter escaping comes from the shared yaml.ts helpers and is
// covered for every registered adapter by the round-trip matrix in
// "YAML frontmatter escaping across adapters" below.
it('should handle empty tags', () => {
const contentNoTags: CommandContent = { ...sampleContent, tags: [] };
const output = devinAdapter.formatFile(contentNoTags);
expect(output).toContain('tags: []');
});
});
describe('amazonQAdapter', () => {
it('should have correct toolId', () => {
expect(amazonQAdapter.toolId).toBe('amazon-q');
});
it('should generate correct file path', () => {
const filePath = amazonQAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.amazonq', 'prompts', 'opsx-explore.md'));
});
it('should format file with description frontmatter', () => {
const output = amazonQAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
});
describe('antigravityAdapter', () => {
it('should have correct toolId', () => {
expect(antigravityAdapter.toolId).toBe('antigravity');
});
it('should generate correct file path', () => {
const filePath = antigravityAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.agents', 'workflows', 'opsx-explore.md'));
});
it('should format file with description frontmatter', () => {
const output = antigravityAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
});
describe('auggieAdapter', () => {
it('should have correct toolId', () => {
expect(auggieAdapter.toolId).toBe('auggie');
});
it('should generate correct file path', () => {
const filePath = auggieAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.augment', 'commands', 'opsx-explore.md'));
});
it('should format file with description and argument-hint', () => {
const output = auggieAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('argument-hint: command arguments');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
});
describe('bobAdapter', () => {
it('should have correct toolId', () => {
expect(bobAdapter.toolId).toBe('bob');
});
it('should generate correct file path', () => {
const filePath = bobAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.bob', 'commands', 'opsx-explore.md'));
});
it('should generate correct file paths for different commands', () => {
expect(bobAdapter.getFilePath('new')).toBe(path.join('.bob', 'commands', 'opsx-new.md'));
expect(bobAdapter.getFilePath('bulk-archive')).toBe(path.join('.bob', 'commands', 'opsx-bulk-archive.md'));
});
it('should format file with description and argument-hint frontmatter', () => {
const output = bobAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('argument-hint: command arguments');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.\n\nWith multiple lines.');
});
it('is generated by generateCommand with hyphen command references', () => {
const contentWithRefs: CommandContent = {
...sampleContent,
body: 'Run /opsx:apply to implement. Then use /opsx:verify.',
};
const output = generateCommand(contentWithRefs, bobAdapter).fileContent;
expect(output).toContain('/opsx-apply');
expect(output).toContain('/opsx-verify');
expect(output).not.toContain('/opsx:apply');
expect(output).not.toContain('/opsx:verify');
});
it('should escape YAML special characters in description', () => {
const contentWithSpecialChars: CommandContent = {
...sampleContent,
description: 'Fix: regression in "auth" feature',
};
const output = bobAdapter.formatFile(contentWithSpecialChars);
expect(output).toContain('description: "Fix: regression in \\"auth\\" feature"');
});
it('should escape newlines in description', () => {
const contentWithNewline: CommandContent = {
...sampleContent,
description: 'Line 1\nLine 2',
};
const output = bobAdapter.formatFile(contentWithNewline);
expect(output).toContain('description: "Line 1\\nLine 2"');
});
it('should handle empty description', () => {
const contentEmptyDesc: CommandContent = {
...sampleContent,
description: '',
};
const output = bobAdapter.formatFile(contentEmptyDesc);
expect(output).toContain('description: ""');
});
});
describe('clineAdapter', () => {
it('should have correct toolId', () => {
expect(clineAdapter.toolId).toBe('cline');
});
it('should generate correct file path', () => {
const filePath = clineAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.clinerules', 'workflows', 'opsx-explore.md'));
});
it('should format file with markdown header (no YAML frontmatter)', () => {
const output = clineAdapter.formatFile(sampleContent);
expect(output).toContain('# OpenSpec Explore');
expect(output).toContain('Enter explore mode for thinking');
expect(output).toContain('This is the command body.');
expect(output).not.toContain('---');
});
});
describe('codebuddyAdapter', () => {
it('should have correct toolId', () => {
expect(codebuddyAdapter.toolId).toBe('codebuddy');
});
it('should generate correct file path with nested opsx folder', () => {
const filePath = codebuddyAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.codebuddy', 'commands', 'opsx', 'explore.md'));
});
it('should format file with name, description, and argument-hint', () => {
const output = codebuddyAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('name: "OpenSpec Explore"');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('argument-hint: "[command arguments]"');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
});
describe('continueAdapter', () => {
it('should have correct toolId', () => {
expect(continueAdapter.toolId).toBe('continue');
});
it('should generate correct file path with .prompt extension', () => {
const filePath = continueAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.continue', 'prompts', 'opsx-explore.prompt'));
});
it('should format file with name, description, and invokable', () => {
const output = continueAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('name: "opsx-explore"');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('invokable: true');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
});
describe('costrictAdapter', () => {
it('should have correct toolId', () => {
expect(costrictAdapter.toolId).toBe('costrict');
});
it('should generate correct file path', () => {
const filePath = costrictAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.cospec', 'openspec', 'commands', 'opsx-explore.md'));
});
it('should format file with description and argument-hint', () => {
const output = costrictAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('argument-hint: command arguments');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
});
describe('crushAdapter', () => {
it('should have correct toolId', () => {
expect(crushAdapter.toolId).toBe('crush');
});
it('should generate correct file path with nested opsx folder', () => {
const filePath = crushAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.crush', 'commands', 'opsx', 'explore.md'));
});
it('should format file with name, description, category, and tags', () => {
const output = crushAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('name: "OpenSpec Explore"');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('category: "Workflow"');
expect(output).toContain('tags: ["workflow", "explore", "experimental"]');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
});
describe('factoryAdapter', () => {
it('should have correct toolId', () => {
expect(factoryAdapter.toolId).toBe('factory');
});
it('should generate correct file path', () => {
const filePath = factoryAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.factory', 'commands', 'opsx-explore.md'));
});
it('should format file with description and argument-hint', () => {
const output = factoryAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('argument-hint: command arguments');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
});
describe('geminiAdapter', () => {
it('should have correct toolId', () => {
expect(geminiAdapter.toolId).toBe('gemini');
});
it('should generate correct file path with .toml extension', () => {
const filePath = geminiAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.gemini', 'commands', 'opsx', 'explore.toml'));
});
it('should format file in TOML format', () => {
const output = geminiAdapter.formatFile(sampleContent);
expect(output).toContain('description = "Enter explore mode for thinking"');
expect(output).toContain('prompt = """');
expect(output).toContain('This is the command body.');
expect(output).toContain('"""');
});
it('escapes TOML-active characters in the description', () => {
const output = geminiAdapter.formatFile({
...sampleContent,
description: 'Say "hi" to C:\\Users and\nmore',
});
// Basic strings are escape-active: quotes, backslashes, and newlines
// must be written as escapes or the file stops parsing as TOML.
expect(output).toContain('description = "Say \\"hi\\" to C:\\\\Users and\\nmore"');
expect((parseToml(output) as { description: string }).description).toBe(
'Say "hi" to C:\\Users and\nmore'
);
});
it('keeps the prompt a single multiline string when the body carries fences and backslashes', () => {
const body = 'Windows path C:\\temp and a quote run: """ done';
const output = geminiAdapter.formatFile({ ...sampleContent, body });
// Backslashes must be escaped and no unescaped quote-triple may remain,
// or the """ delimiter ends the prompt early.
expect(output).toContain('C:\\\\temp');
expect(output).toContain('""\\" done');
const delimiters = output.match(/(?<!\\)"""/g) ?? [];
expect(delimiters).toHaveLength(2);
expect((parseToml(output) as { prompt: string }).prompt).toBe(`${body}\n`);
});
// Escaping claims are only proven by a real parser: every hostile body
// must yield a file smol-toml accepts, and the parsed prompt must
// round-trip to the original (modulo CRLF normalization).
const HOSTILE_BODIES: Array<[string, string, string]> = [
['control characters', 'null:\u0000 vt:\u000b ff:\u000c end', 'null:\u0000 vt:\u000b ff:\u000c end'],
// A lone CR is illegal raw in a multiline basic string (only LF and
// CRLF may appear); Python tomllib rejects it — so must never be
// emitted bare.
['a lone carriage return', 'a\rb', 'a\rb'],
['CRLF line endings (normalized to LF)', 'line one\r\nline two\r\n', 'line one\nline two\n'],
['a CR before a quote run', 'x\r""" y', 'x\r""" y'],
['a trailing backslash', 'ends with a backslash \\', 'ends with a backslash \\'],
['quote runs of four and five', 'four """" five """""', 'four """" five """""'],
];
for (const [label, body, expected] of HOSTILE_BODIES) {
it(`emits parseable TOML for a body with ${label}`, () => {
const output = geminiAdapter.formatFile({ ...sampleContent, body });
const parsed = parseToml(output) as { description: string; prompt: string };
expect(parsed.prompt).toBe(`${expected}\n`);
expect(parsed.description).toBe(sampleContent.description);
});
}
});
describe('githubCopilotAdapter', () => {
it('should have correct toolId', () => {
expect(githubCopilotAdapter.toolId).toBe('github-copilot');
});
it('should generate correct file path with .prompt.md extension', () => {
const filePath = githubCopilotAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.github', 'prompts', 'opsx-explore.prompt.md'));
});
it('should format file with description frontmatter', () => {
const output = githubCopilotAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
});
describe('iflowAdapter', () => {
it('should have correct toolId', () => {
expect(iflowAdapter.toolId).toBe('iflow');
});
it('should generate correct file path', () => {
const filePath = iflowAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.iflow', 'commands', 'opsx-explore.md'));
});
it('should format file with name, id, category, and description', () => {
const output = iflowAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('name: "/opsx-explore"');
expect(output).toContain('id: "opsx-explore"');
expect(output).toContain('category: "Workflow"');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
});
describe('kilocodeAdapter', () => {
it('should have correct toolId', () => {
expect(kilocodeAdapter.toolId).toBe('kilocode');
});
it('should generate correct file path', () => {
const filePath = kilocodeAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.kilocode', 'workflows', 'opsx-explore.md'));
});
it('should format file without frontmatter', () => {
const output = kilocodeAdapter.formatFile(sampleContent);
expect(output).not.toContain('---');
expect(output).toContain('This is the command body.');
});
});
describe('opencodeAdapter', () => {
it('should have correct toolId', () => {
expect(opencodeAdapter.toolId).toBe('opencode');
});
it('should generate correct file path', () => {
const filePath = opencodeAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.opencode', 'commands', 'opsx-explore.md'));
});
it('should format file with description frontmatter', () => {
const output = opencodeAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
it('should pass invocation arguments into the OpenSpec input contract', () => {
const output = opencodeAdapter.formatFile({
...sampleContent,
body: '# OpenSpec command\n\n**Input**: A change name or description.\n\nRun the workflow.',
});
expect(output).toContain(
'**Input**: A change name or description.\n**Provided arguments**: $ARGUMENTS'
);
});
it('should not duplicate an existing $ARGUMENTS placeholder', () => {
const output = opencodeAdapter.formatFile({
...sampleContent,
body: '**Input**: A change name.\nExisting input: $ARGUMENTS',
});
expect(output.match(/\$ARGUMENTS/g)).toHaveLength(1);
});
it('should not duplicate documented positional argument placeholders', () => {
const output = opencodeAdapter.formatFile({
...sampleContent,
body: '**Input**: Two values.\nFirst: $1\nSecond: $2',
});
expect(output).not.toContain('**Provided arguments**: $ARGUMENTS');
expect(output).toContain('First: $1\nSecond: $2');
});
it('should keep multi-line input guidance together before provided arguments', () => {
const output = opencodeAdapter.formatFile({
...sampleContent,
body: '**Input**: A topic, such as:\n- an idea\n- a problem\n\n**Steps**\n1. Explore.',
});
expect(output).toContain(
'**Input**: A topic, such as:\n- an idea\n- a problem\n**Provided arguments**: $ARGUMENTS'
);
});
it('should preserve CRLF while keeping multi-line input guidance together', () => {
const output = opencodeAdapter.formatFile({
...sampleContent,
body: '**Input**: A topic, such as:\r\n- an idea\r\n- a problem\r\n\r\nRun it.',
});
expect(output).toContain(
'**Input**: A topic, such as:\r\n- an idea\r\n- a problem\r\n**Provided arguments**: $ARGUMENTS\r\n\r\nRun it.'
);
});
it('should not add invocation arguments to an explicitly input-free workflow', () => {
const output = opencodeAdapter.formatFile({
...sampleContent,
body: '**Input**: None required (prompts for selection)\n\nPrompt the user.',
});
expect(output).not.toContain('$ARGUMENTS');
});
it('should preserve exactly one argument placeholder for each workflow that accepts input', () => {
for (const content of getCommandContents()) {
const output = generateCommand(content, opencodeAdapter).fileContent;
const acceptsInput = /^\*\*Input\*\*:(?!\s*None required\b)/im.test(content.body);
expect(output.match(/\$ARGUMENTS/g) ?? [], content.id).toHaveLength(acceptsInput ? 1 : 0);
}
});
it('is generated by generateCommand with hyphen command references', () => {
const contentWithCommands: CommandContent = {
...sampleContent,
body: 'Use /opsx:new to start, then /opsx:apply to implement.',
};
const output = generateCommand(contentWithCommands, opencodeAdapter).fileContent;
expect(output).toContain('/opsx-new');
expect(output).toContain('/opsx-apply');
expect(output).not.toContain('/opsx:new');
expect(output).not.toContain('/opsx:apply');
});
it('is generated by generateCommand with every reference hyphenated', () => {
const contentWithMultipleCommands: CommandContent = {
...sampleContent,
body: `/opsx:explore for ideas
/opsx:new to create
/opsx:continue to proceed
/opsx:apply to implement`,
};
const output = generateCommand(contentWithMultipleCommands, opencodeAdapter).fileContent;
expect(output).toContain('/opsx-explore');
expect(output).toContain('/opsx-new');
expect(output).toContain('/opsx-continue');
expect(output).toContain('/opsx-apply');
});
});
describe('qoderAdapter', () => {
it('should have correct toolId', () => {
expect(qoderAdapter.toolId).toBe('qoder');
});
it('should generate correct file path with nested opsx folder', () => {
const filePath = qoderAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.qoder', 'commands', 'opsx', 'explore.md'));
});
it('should format file with name, description, category, and tags', () => {
const output = qoderAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('name: "OpenSpec Explore"');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('category: "Workflow"');
expect(output).toContain('tags: ["workflow", "explore", "experimental"]');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
});
describe('qwenAdapter', () => {
it('should have correct toolId', () => {
expect(qwenAdapter.toolId).toBe('qwen');
});
it('should generate correct file path with .md extension', () => {
const filePath = qwenAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.qwen', 'commands', 'opsx-explore.md'));
});
it('should format file with description frontmatter', () => {
const output = qwenAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
it('should escape special YAML characters in description', () => {
const output = qwenAdapter.formatFile({
...sampleContent,
description: 'Review: plan & apply "changes"',
});
expect(output).toContain('description: "Review: plan & apply \\"changes\\""');
});
it('is generated by generateCommand with hyphen command references', () => {
// Qwen commands are invoked by filename (/opsx-<id>), like bob/opencode.
const contentWithRefs: CommandContent = {
...sampleContent,
body: 'Run /opsx:apply to implement. Then use /opsx:archive.',
};
const output = generateCommand(contentWithRefs, qwenAdapter).fileContent;
expect(output).toContain('/opsx-apply');
expect(output).toContain('/opsx-archive');
expect(output).not.toContain('/opsx:apply');
expect(output).not.toContain('/opsx:archive');
});
});
describe('piAdapter', () => {
it('should have correct toolId', () => {
expect(piAdapter.toolId).toBe('pi');
});
it('should generate correct file path', () => {
const filePath = piAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.pi', 'prompts', 'opsx-explore.md'));
});
it('should generate correct file paths for different commands', () => {
expect(piAdapter.getFilePath('new')).toBe(path.join('.pi', 'prompts', 'opsx-new.md'));
expect(piAdapter.getFilePath('bulk-archive')).toBe(path.join('.pi', 'prompts', 'opsx-bulk-archive.md'));
});
it('should format file with description frontmatter', () => {
const output = piAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
it('is generated by generateCommand with hyphen command references', () => {
const contentWithRefs: CommandContent = {
...sampleContent,
body: 'Run /opsx:apply to implement. Then /opsx:archive when done.',
};
const output = generateCommand(contentWithRefs, piAdapter).fileContent;
expect(output).toContain('/opsx-apply');
expect(output).toContain('/opsx-archive');
expect(output).not.toContain('/opsx:apply');
});
it('should inject template arguments into the input section', () => {
const contentWithInput: CommandContent = {
...sampleContent,
body: '**Input**: The argument after `/opsx:explore` is the topic.\n\n**Steps**\n1. Think.',
};
const output = piAdapter.formatFile(contentWithInput);
expect(output).toContain('**Provided arguments**: $@');
});
it('should escape YAML special characters in description', () => {
const contentWithSpecialChars: CommandContent = {
...sampleContent,
description: 'Fix: regression in "auth" feature',
};
const output = piAdapter.formatFile(contentWithSpecialChars);
expect(output).toContain('description: "Fix: regression in \\"auth\\" feature"');
});
it('should escape newlines in description', () => {
const contentWithNewline: CommandContent = {
...sampleContent,
description: 'Line 1\nLine 2',
};
const output = piAdapter.formatFile(contentWithNewline);
expect(output).toContain('description: "Line 1\\nLine 2"');
});
});
describe('ohMyPiAdapter', () => {
it('should have correct toolId', () => {
expect(ohMyPiAdapter.toolId).toBe('oh-my-pi');
});
it('should generate correct file path', () => {
const filePath = ohMyPiAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.omp', 'commands', 'opsx-explore.md'));
});
it('should generate correct file paths for different commands', () => {
expect(ohMyPiAdapter.getFilePath('new')).toBe(path.join('.omp', 'commands', 'opsx-new.md'));
expect(ohMyPiAdapter.getFilePath('bulk-archive')).toBe(path.join('.omp', 'commands', 'opsx-bulk-archive.md'));
});
it('should format file with description frontmatter', () => {
const output = ohMyPiAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.');
});
it('is generated by generateCommand with hyphen command references', () => {
const contentWithRefs: CommandContent = {
...sampleContent,
body: 'Run /opsx:apply to implement. Then /opsx:archive when done.',
};
const output = generateCommand(contentWithRefs, ohMyPiAdapter).fileContent;
expect(output).toContain('/opsx-apply');
expect(output).toContain('/opsx-archive');
expect(output).not.toContain('/opsx:apply');
});
it('should escape YAML special characters in description', () => {
const contentWithSpecialChars: CommandContent = {
...sampleContent,
description: 'Fix: regression in "auth" feature',
};
const output = ohMyPiAdapter.formatFile(contentWithSpecialChars);
expect(output).toContain('description: "Fix: regression in \\"auth\\" feature"');
});
it('should escape newlines in description', () => {
const contentWithNewline: CommandContent = {
...sampleContent,
description: 'Line 1\nLine 2',
};
const output = ohMyPiAdapter.formatFile(contentWithNewline);
expect(output).toContain('description: "Line 1\\nLine 2"');
});
it('should inject $@ after **Input**: heading when not already present', () => {
const contentWithInput: CommandContent = {
...sampleContent,
body: '**Input**: The argument is the change name.\n\nDo the work.',
};
const output = ohMyPiAdapter.formatFile(contentWithInput);
expect(output).toContain('**Input**: The argument is the change name.\n**Provided arguments**: $@');
});
it('injects $@ alongside generateCommand\'s hyphen rewrite', () => {
const contentWithInput: CommandContent = {
...sampleContent,
body: '**Input**: The argument is the change name.\n\nRun /opsx:apply.',
};
const output = generateCommand(contentWithInput, ohMyPiAdapter).fileContent;
expect(output).toContain('**Provided arguments**: $@');
expect(output).toContain('/opsx-apply');
});
it('should not inject $@ when $@ is already present in the body', () => {
const contentWithArgs: CommandContent = {
...sampleContent,
body: '**Input**: Accepts arguments.\n\nUser said: $@',
};
const output = ohMyPiAdapter.formatFile(contentWithArgs);
expect(output.match(/\$@/g)?.length).toBe(1);
});
it('should not inject $@ when $ARGUMENTS is already present in the body', () => {
const contentWithArguments: CommandContent = {
...sampleContent,
body: '**Input**: Accepts arguments.\n\nUser said: $ARGUMENTS',
};
const output = ohMyPiAdapter.formatFile(contentWithArguments);
expect(output).not.toContain('$@');
});
});
describe('roocodeAdapter', () => {
it('should have correct toolId', () => {
expect(roocodeAdapter.toolId).toBe('roocode');
});
it('should generate correct file path', () => {
const filePath = roocodeAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.roo', 'commands', 'opsx-explore.md'));
});
it('should format file with markdown header (no YAML frontmatter)', () => {
const output = roocodeAdapter.formatFile(sampleContent);
expect(output).toContain('# OpenSpec Explore');
expect(output).toContain('Enter explore mode for thinking');
expect(output).toContain('This is the command body.');
expect(output).not.toContain('---');
});
});
describe('traeAdapter', () => {
it('should have correct toolId', () => {
expect(traeAdapter.toolId).toBe('trae');
});
it('should generate correct file path', () => {
const filePath = traeAdapter.getFilePath('explore');
expect(filePath).toBe(path.join('.trae', 'commands', 'opsx-explore.md'));
});
it('should generate correct file paths for different commands', () => {
expect(traeAdapter.getFilePath('new')).toBe(path.join('.trae', 'commands', 'opsx-new.md'));
expect(traeAdapter.getFilePath('bulk-archive')).toBe(path.join('.trae', 'commands', 'opsx-bulk-archive.md'));
});
it('should format file with name and description frontmatter', () => {
const output = traeAdapter.formatFile(sampleContent);
expect(output).toContain('---\n');
expect(output).toContain('name: "OpenSpec Explore"');
expect(output).toContain('description: "Enter explore mode for thinking"');
expect(output).toContain('---\n\n');
expect(output).toContain('This is the command body.\n\nWith multiple lines.');
});
it('should escape YAML special characters in name', () => {
const contentWithSpecialChars: CommandContent = {
...sampleContent,
name: 'Test: Command',
};
const output = traeAdapter.formatFile(contentWithSpecialChars);
expect(output).toContain('name: "Test: Command"');
});
it('should escape YAML special characters in description', () => {
const contentWithSpecialChars: CommandContent = {
...sampleContent,
description: 'Fix: regression in "auth" feature',
};
const output = traeAdapter.formatFile(contentWithSpecialChars);
expect(output).toContain('description: "Fix: regression in \\"auth\\" feature"');
});
it('should escape newlines in description', () => {
const contentWithNewline: CommandContent = {
...sampleContent,
description: 'Line 1\nLine 2',
};
const output = traeAdapter.formatFile(contentWithNewline);
expect(output).toContain('description: "Line 1\\nLine 2"');
});
it('should handle empty description', () => {
const contentEmptyDesc: CommandContent = {
...sampleContent,
description: '',
};
const output = traeAdapter.formatFile(contentEmptyDesc);
expect(output).toContain('description: ""');
});
it('should escape carriage returns in description', () => {
const contentWithCR: CommandContent = {
...sampleContent,