-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathai-config-spec.ts
More file actions
847 lines (695 loc) · 33.5 KB
/
Copy pathai-config-spec.ts
File metadata and controls
847 lines (695 loc) · 33.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
import * as path from "path";
import { App, Config, FS_TOKEN, FsFileSystem, GoogleAnalytics, IFileSystem, InquirerWrapper, ProjectConfig, TEMPLATE_MANAGER, Util } from "@igniteui/cli-core";
import * as coreDetect from "../../packages/core/util/detect-framework";
import { configureMCP, configureSkills, configureInstructions } from "../../packages/cli/lib/commands/ai-config";
import * as aiConfig from "../../packages/cli/lib/commands/ai-config";
import { addMcpServers } from "../../packages/core/util/mcp-config";
import { applyExclusiveToggle } from "../../packages/core/prompt/ExclusiveCheckbox";
const IGNITEUI_SERVER_KEY = "igniteui-cli";
const IGNITEUI_THEMING_SERVER_KEY = "igniteui-theming";
const igniteuiServer = { command: "npx", args: ["-y", "igniteui-cli", "mcp"] };
const igniteuiThemingServer = { command: "npx", args: ["-y", "igniteui-theming", "igniteui-theming-mcp"] };
function createMockFs(existingContent?: string): IFileSystem {
return {
fileExists: jasmine.createSpy("fileExists"),
readFile: existingContent
? jasmine.createSpy("readFile").and.returnValue(existingContent)
: jasmine.createSpy("readFile").and.throwError("ENOENT"),
writeFile: jasmine.createSpy("writeFile"),
directoryExists: jasmine.createSpy("directoryExists"),
glob: jasmine.createSpy("glob").and.returnValue([])
};
}
describe("Unit - ai-config command", () => {
const configPath = path.join(process.cwd(), ".vscode", "mcp.json");
beforeAll(() => {
spyOn(GoogleAnalytics, "post");
});
beforeEach(() => {
spyOn(Util, "log");
spyOn(Util, "greenCheck").and.returnValue("✓");
});
function writtenConfig(mockFs: IFileSystem): Record<string, unknown> {
const content = (mockFs.writeFile as jasmine.Spy).calls.mostRecent().args[1] as string;
return JSON.parse(content);
}
describe("configureMCP", () => {
it("creates .vscode/mcp.json with both servers when file does not exist", () => {
const mockFs = createMockFs();
App.container.set(FS_TOKEN, mockFs);
configureMCP(["vscode"]);
expect(mockFs.writeFile).toHaveBeenCalled();
const config = writtenConfig(mockFs);
expect((config.servers as any)[IGNITEUI_SERVER_KEY]).toEqual(igniteuiServer);
expect((config.servers as any)[IGNITEUI_THEMING_SERVER_KEY]).toEqual(igniteuiThemingServer);
});
it("creates config with mcpServers key for non-vscode assistants", () => {
const mockFs = createMockFs();
App.container.set(FS_TOKEN, mockFs);
configureMCP(["cursor"]);
expect(mockFs.writeFile).toHaveBeenCalledWith(".cursor/mcp.json", jasmine.any(String));
const config = writtenConfig(mockFs);
expect((config.mcpServers as any)[IGNITEUI_SERVER_KEY]).toEqual(igniteuiServer);
expect((config.mcpServers as any)[IGNITEUI_THEMING_SERVER_KEY]).toEqual(igniteuiThemingServer);
expect(config.servers).toBeUndefined();
});
it("adds both servers when file exists but servers object is empty", () => {
const mockFs = createMockFs(JSON.stringify({ servers: {} }));
App.container.set(FS_TOKEN, mockFs);
configureMCP(["vscode"]);
expect(mockFs.writeFile).toHaveBeenCalled();
const config = writtenConfig(mockFs);
expect((config.servers as any)[IGNITEUI_SERVER_KEY]).toEqual(igniteuiServer);
expect((config.servers as any)[IGNITEUI_THEMING_SERVER_KEY]).toEqual(igniteuiThemingServer);
});
it("adds missing igniteui-theming server when only igniteui-cli is present", () => {
const mockFs = createMockFs(JSON.stringify({
servers: { [IGNITEUI_SERVER_KEY]: igniteuiServer }
}));
App.container.set(FS_TOKEN, mockFs);
configureMCP(["vscode"]);
expect(mockFs.writeFile).toHaveBeenCalled();
const config = writtenConfig(mockFs);
expect((config.servers as any)[IGNITEUI_SERVER_KEY]).toEqual(igniteuiServer);
expect((config.servers as any)[IGNITEUI_THEMING_SERVER_KEY]).toEqual(igniteuiThemingServer);
});
it("adds missing igniteui-cli server when only igniteui-theming is present", () => {
const mockFs = createMockFs(JSON.stringify({
servers: { [IGNITEUI_THEMING_SERVER_KEY]: igniteuiThemingServer }
}));
App.container.set(FS_TOKEN, mockFs);
configureMCP(["vscode"]);
expect(mockFs.writeFile).toHaveBeenCalled();
const config = writtenConfig(mockFs);
expect((config.servers as any)[IGNITEUI_SERVER_KEY]).toEqual(igniteuiServer);
expect((config.servers as any)[IGNITEUI_THEMING_SERVER_KEY]).toEqual(igniteuiThemingServer);
});
it("is a no-op when both servers are already configured", () => {
const mockFs = createMockFs(JSON.stringify({
servers: {
[IGNITEUI_SERVER_KEY]: igniteuiServer,
[IGNITEUI_THEMING_SERVER_KEY]: igniteuiThemingServer
}
}, null, 2));
App.container.set(FS_TOKEN, mockFs);
const result = addMcpServers("vscode");
expect(result).toBe(false);
expect(mockFs.writeFile).not.toHaveBeenCalled();
});
it("updates config when server configuration is outdated", () => {
const mockFs = createMockFs(JSON.stringify({
servers: {
[IGNITEUI_SERVER_KEY]: { command: "npx", args: ["-y", "igniteui-cli", "old-command"] },
[IGNITEUI_THEMING_SERVER_KEY]: igniteuiThemingServer
}
}, null, 2));
App.container.set(FS_TOKEN, mockFs);
const result = addMcpServers("vscode");
expect(result).toBe(true);
expect(mockFs.writeFile).toHaveBeenCalled();
const config = writtenConfig(mockFs);
expect((config.servers as any)[IGNITEUI_SERVER_KEY]).toEqual(igniteuiServer);
expect((config.servers as any)[IGNITEUI_THEMING_SERVER_KEY]).toEqual(igniteuiThemingServer);
});
it("preserves existing third-party servers when adding igniteui servers", () => {
const thirdPartyServer = { command: "node", args: ["server.js"] };
const mockFs = createMockFs(JSON.stringify({
servers: { "other-server": thirdPartyServer }
}));
App.container.set(FS_TOKEN, mockFs);
configureMCP(["vscode"]);
expect(mockFs.writeFile).toHaveBeenCalled();
const config = writtenConfig(mockFs);
expect((config.servers as any)["other-server"]).toEqual(thirdPartyServer);
expect((config.servers as any)[IGNITEUI_SERVER_KEY]).toEqual(igniteuiServer);
expect((config.servers as any)[IGNITEUI_THEMING_SERVER_KEY]).toEqual(igniteuiThemingServer);
});
});
describe("exclusive checkbox behavior", () => {
it("clears other selections when None is selected", () => {
const items = [
{ value: "none", name: "None", checked: false, disabled: false },
{ value: "generic", name: "Generic", checked: true, disabled: false },
{ value: "claude", name: "Claude", checked: true, disabled: false }
];
const result = applyExclusiveToggle(items, 0, ["none"]);
expect(result[0]).toEqual(jasmine.objectContaining({ checked: true }));
expect(result[1]).toEqual(jasmine.objectContaining({ checked: false }));
expect(result[2]).toEqual(jasmine.objectContaining({ checked: false }));
});
it("clears None when another selection is made", () => {
const items = [
{ value: "none", name: "None", checked: true, disabled: false },
{ value: "generic", name: "Generic", checked: false, disabled: false }
];
const result = applyExclusiveToggle(items, 1, ["none"]);
expect(result[0]).toEqual(jasmine.objectContaining({ checked: false }));
expect(result[1]).toEqual(jasmine.objectContaining({ checked: true }));
});
});
describe("configureSkills", () => {
const angularSkillsDir = "node_modules/igniteui-angular/skills";
beforeEach(() => {
spyOn(Util, "warn");
});
function setupAngularConfig() {
spyOn(ProjectConfig, "hasLocalConfig").and.returnValue(true);
spyOn(ProjectConfig, "getConfig").and.returnValue({
project: { framework: "angular" }
} as unknown as Config);
}
it("warns when no skill files are found", () => {
const mockFs: IFileSystem = {
fileExists: jasmine.createSpy("fileExists").and.callFake((p: string) =>
p === "ignite-ui-cli.json"
),
readFile: jasmine.createSpy("readFile").and.returnValue(""),
writeFile: jasmine.createSpy("writeFile"),
directoryExists: jasmine.createSpy("directoryExists").and.returnValue(false),
glob: jasmine.createSpy("glob").and.returnValue([])
} as unknown as IFileSystem;
spyOn(App.container, "get").and.callFake(token => {
if (token === FS_TOKEN) {
return mockFs;
}
if (token === TEMPLATE_MANAGER) {
return { getFrameworkById: () => null } as any;
}
})
configureSkills(["claude"], "angular");
expect(Util.warn).toHaveBeenCalledWith(jasmine.stringContaining("No AI skill files found"), "yellow");
expect(Util.log).not.toHaveBeenCalled();
});
it("warns with failure count when some writes fail", () => {
const skillFile = `${angularSkillsDir}/angular.md`;
const mockFs: IFileSystem = {
fileExists: jasmine.createSpy("fileExists").and.callFake((p: string) =>
p === "ignite-ui-cli.json"
),
readFile: jasmine.createSpy("readFile").and.returnValue("skill content"),
writeFile: jasmine.createSpy("writeFile").and.throwError("EACCES: permission denied"),
directoryExists: jasmine.createSpy("directoryExists").and.callFake((p: string) =>
p === angularSkillsDir
),
glob: jasmine.createSpy("glob").and.callFake((d: string) =>
d === angularSkillsDir ? [skillFile] : []
)
} as unknown as IFileSystem;
spyOn(App.container, "get").and.returnValue(mockFs);
// srcFs reads (FsFileSystem.prototype) for source content
spyOn(FsFileSystem.prototype, "glob").and.callFake((d: string) =>
d === angularSkillsDir ? [skillFile] : []
);
spyOn(FsFileSystem.prototype, "readFile").and.returnValue("skill content");
configureSkills(["claude"], "angular");
expect(Util.warn).toHaveBeenCalledWith(jasmine.stringContaining("Failed to write 1 AI skill file(s) out of 1"), "yellow");
const logCalls = (Util.log as jasmine.Spy).calls.allArgs().map(a => a[0] as string);
expect(logCalls.some(m => m.includes("Created"))).toBe(false);
expect(logCalls.some(m => m.includes("Updated"))).toBe(false);
});
it("logs up-to-date when all files are already current", () => {
const skillFile = `${angularSkillsDir}/angular.md`;
const destFile = ".claude/skills/angular.md";
const content = "# Ignite UI skills";
const mockFs: IFileSystem = {
fileExists: jasmine.createSpy("fileExists").and.callFake((p: string) =>
p === "ignite-ui-cli.json" || p === destFile
),
readFile: jasmine.createSpy("readFile").and.returnValue(content),
writeFile: jasmine.createSpy("writeFile"),
directoryExists: jasmine.createSpy("directoryExists").and.callFake((p: string) =>
p === angularSkillsDir
),
glob: jasmine.createSpy("glob").and.callFake((d: string) =>
d === angularSkillsDir ? [skillFile] : []
)
} as unknown as IFileSystem;
spyOn(App.container, "get").and.returnValue(mockFs);
// srcFs reads (FsFileSystem.prototype) for source content
spyOn(FsFileSystem.prototype, "glob").and.callFake((d: string) =>
d === angularSkillsDir ? [skillFile] : []
);
spyOn(FsFileSystem.prototype, "readFile").and.returnValue(content);
configureSkills(["claude"], "angular");
expect(Util.log).toHaveBeenCalledWith(jasmine.stringContaining("already up-to-date"));
expect(Util.warn).not.toHaveBeenCalled();
});
it("logs created/updated count when skills are written successfully", () => {
const skillFile = `${angularSkillsDir}/angular.md`;
const mockFs: IFileSystem = {
fileExists: jasmine.createSpy("fileExists").and.callFake((p: string) =>
p === "ignite-ui-cli.json"
),
readFile: jasmine.createSpy("readFile").and.returnValue("skill content"),
writeFile: jasmine.createSpy("writeFile"),
directoryExists: jasmine.createSpy("directoryExists").and.callFake((p: string) =>
p === angularSkillsDir
),
glob: jasmine.createSpy("glob").and.callFake((d: string) =>
d === angularSkillsDir ? [skillFile] : []
)
} as unknown as IFileSystem;
spyOn(App.container, "get").and.returnValue(mockFs);
// srcFs reads (FsFileSystem.prototype) for source content
spyOn(FsFileSystem.prototype, "glob").and.callFake((d: string) =>
d === angularSkillsDir ? [skillFile] : []
);
spyOn(FsFileSystem.prototype, "readFile").and.returnValue("skill content");
configureSkills(["claude"], "angular");
expect(Util.log).toHaveBeenCalledWith(jasmine.stringContaining("1 AI skill file(s) created or updated"));
expect(Util.warn).not.toHaveBeenCalled();
});
it("logs per-file Created messages for new skill files", () => {
const skillFile = `${angularSkillsDir}/angular.md`;
const mockFs: IFileSystem = {
fileExists: jasmine.createSpy("fileExists").and.callFake((p: string) =>
p === "ignite-ui-cli.json"
),
readFile: jasmine.createSpy("readFile").and.returnValue("skill content"),
writeFile: jasmine.createSpy("writeFile"),
directoryExists: jasmine.createSpy("directoryExists").and.callFake((p: string) =>
p === angularSkillsDir
),
glob: jasmine.createSpy("glob").and.callFake((d: string) =>
d === angularSkillsDir ? [skillFile] : []
)
} as unknown as IFileSystem;
spyOn(App.container, "get").and.returnValue(mockFs);
spyOn(FsFileSystem.prototype, "glob").and.callFake((d: string) =>
d === angularSkillsDir ? [skillFile] : []
);
spyOn(FsFileSystem.prototype, "readFile").and.returnValue("skill content");
configureSkills(["claude"], "angular");
expect(Util.log).toHaveBeenCalledWith(" Created .claude/skills/angular.md");
});
it("logs per-file Updated messages for changed skill files", () => {
const skillFile = `${angularSkillsDir}/angular.md`;
const destFile = ".claude/skills/angular.md";
const mockFs: IFileSystem = {
fileExists: jasmine.createSpy("fileExists").and.callFake((p: string) =>
p === "ignite-ui-cli.json" || p === destFile
),
readFile: jasmine.createSpy("readFile").and.returnValue("old content"),
writeFile: jasmine.createSpy("writeFile"),
directoryExists: jasmine.createSpy("directoryExists").and.callFake((p: string) =>
p === angularSkillsDir
),
glob: jasmine.createSpy("glob").and.callFake((d: string) =>
d === angularSkillsDir ? [skillFile] : []
)
} as unknown as IFileSystem;
spyOn(App.container, "get").and.returnValue(mockFs);
spyOn(FsFileSystem.prototype, "glob").and.callFake((d: string) =>
d === angularSkillsDir ? [skillFile] : []
);
spyOn(FsFileSystem.prototype, "readFile").and.returnValue("new content");
configureSkills(["claude"], "angular");
expect(Util.log).toHaveBeenCalledWith(" Updated .claude/skills/angular.md");
});
it("does not log per-file messages for skipped (up-to-date) files", () => {
const skillFile = `${angularSkillsDir}/angular.md`;
const destFile = ".claude/skills/angular.md";
const content = "# Ignite UI skills";
const mockFs: IFileSystem = {
fileExists: jasmine.createSpy("fileExists").and.callFake((p: string) =>
p === "ignite-ui-cli.json" || p === destFile
),
readFile: jasmine.createSpy("readFile").and.returnValue(content),
writeFile: jasmine.createSpy("writeFile"),
directoryExists: jasmine.createSpy("directoryExists").and.callFake((p: string) =>
p === angularSkillsDir
),
glob: jasmine.createSpy("glob").and.callFake((d: string) =>
d === angularSkillsDir ? [skillFile] : []
)
} as unknown as IFileSystem;
spyOn(App.container, "get").and.returnValue(mockFs);
spyOn(FsFileSystem.prototype, "glob").and.callFake((d: string) =>
d === angularSkillsDir ? [skillFile] : []
);
spyOn(FsFileSystem.prototype, "readFile").and.returnValue(content);
configureSkills(["claude"], "angular");
const logCalls = (Util.log as jasmine.Spy).calls.allArgs().map(a => a[0] as string);
expect(logCalls.some(m => m.includes("Created"))).toBe(false);
expect(logCalls.some(m => m.includes("Updated"))).toBe(false);
});
it("logs package source with version when skills come from npm package", () => {
const skillFile = `${angularSkillsDir}/angular.md`;
const mockFs: IFileSystem = {
fileExists: jasmine.createSpy("fileExists").and.callFake((p: string) =>
p === "ignite-ui-cli.json"
),
readFile: jasmine.createSpy("readFile").and.returnValue("skill content"),
writeFile: jasmine.createSpy("writeFile"),
directoryExists: jasmine.createSpy("directoryExists").and.callFake((p: string) =>
p === angularSkillsDir
),
glob: jasmine.createSpy("glob").and.callFake((d: string) =>
d === angularSkillsDir ? [skillFile] : []
)
} as unknown as IFileSystem;
spyOn(App.container, "get").and.returnValue(mockFs);
spyOn(FsFileSystem.prototype, "glob").and.callFake((d: string) =>
d === angularSkillsDir ? [skillFile] : []
);
spyOn(FsFileSystem.prototype, "readFile").and.callFake((p: string) => {
if (p === "node_modules/igniteui-angular/package.json") {
return JSON.stringify({ version: "18.2.0" });
}
return "skill content";
});
configureSkills(["claude"], "angular");
expect(Util.log).toHaveBeenCalledWith("Using skills from igniteui-angular@18.2.0");
});
it("logs bundled source when skills come from templates", () => {
const mockFs: IFileSystem = {
fileExists: jasmine.createSpy("fileExists").and.returnValue(false),
readFile: jasmine.createSpy("readFile").and.returnValue(""),
writeFile: jasmine.createSpy("writeFile"),
directoryExists: jasmine.createSpy("directoryExists").and.returnValue(false),
glob: jasmine.createSpy("glob").and.returnValue([])
} as unknown as IFileSystem;
App.container.set(FS_TOKEN, mockFs);
App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", {
getFrameworkById: {
projectLibraries: [{
getProject: (id: string) => id === "ai-config" ? { templatePaths: ["/fake/files"] } : null
}]
}
}));
const fakeSkillsRoot = path.join("/fake/files", "skills");
spyOn(FsFileSystem.prototype, "glob").and.callFake((d: string) =>
d === fakeSkillsRoot ? [path.join(fakeSkillsRoot, "angular.md")] : []
);
spyOn(FsFileSystem.prototype, "readFile").and.returnValue("# skill content");
configureSkills(["claude"], "angular");
expect(Util.log).toHaveBeenCalledWith("Using bundled Ignite UI skills");
});
it("suppresses per-file and source messages when verbose is false", () => {
const skillFile = `${angularSkillsDir}/angular.md`;
const mockFs: IFileSystem = {
fileExists: jasmine.createSpy("fileExists").and.callFake((p: string) =>
p === "ignite-ui-cli.json"
),
readFile: jasmine.createSpy("readFile").and.returnValue("skill content"),
writeFile: jasmine.createSpy("writeFile"),
directoryExists: jasmine.createSpy("directoryExists").and.callFake((p: string) =>
p === angularSkillsDir
),
glob: jasmine.createSpy("glob").and.callFake((d: string) =>
d === angularSkillsDir ? [skillFile] : []
)
} as unknown as IFileSystem;
spyOn(App.container, "get").and.returnValue(mockFs);
spyOn(FsFileSystem.prototype, "glob").and.callFake((d: string) =>
d === angularSkillsDir ? [skillFile] : []
);
spyOn(FsFileSystem.prototype, "readFile").and.callFake((p: string) => {
if (p === "node_modules/igniteui-angular/package.json") {
return JSON.stringify({ version: "18.2.0" });
}
return "skill content";
});
configureSkills(["claude"], "angular", false);
const logCalls = (Util.log as jasmine.Spy).calls.allArgs().map(a => a[0] as string);
expect(logCalls.some(m => m.includes("Created"))).toBe(false);
expect(logCalls.some(m => m.includes("Using skills from"))).toBe(false);
expect(Util.log).toHaveBeenCalledWith(jasmine.stringContaining("AI skill file(s) created or updated"));
});
});
describe("configureInstructions", () => {
it("logs per-file Created messages for new instruction files", () => {
const mockFs = createMockFs();
App.container.set(FS_TOKEN, mockFs);
spyOn(FsFileSystem.prototype, "readFile").and.returnValue("# Instructions content");
App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", {
getFrameworkById: {
projectLibraries: [{
getProject: (id: string) => id === "ai-config" ? { templatePaths: ["/fake/files"] } : null
}]
}
}));
configureInstructions(["claude"], "angular");
expect(Util.log).toHaveBeenCalledWith(" Created .claude/CLAUDE.md");
expect(Util.log).toHaveBeenCalledWith(jasmine.stringContaining("1 instruction file(s) created or updated"));
});
it("logs per-file Updated messages for changed instruction files", () => {
const destFile = ".claude/CLAUDE.md";
const mockFs: IFileSystem = {
fileExists: jasmine.createSpy("fileExists").and.callFake((p: string) =>
p === destFile
),
readFile: jasmine.createSpy("readFile").and.returnValue("old instructions"),
writeFile: jasmine.createSpy("writeFile"),
directoryExists: jasmine.createSpy("directoryExists"),
glob: jasmine.createSpy("glob").and.returnValue([])
};
App.container.set(FS_TOKEN, mockFs);
spyOn(FsFileSystem.prototype, "readFile").and.returnValue("new instructions");
App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", {
getFrameworkById: {
projectLibraries: [{
getProject: (id: string) => id === "ai-config" ? { templatePaths: ["/fake/files"] } : null
}]
}
}));
configureInstructions(["claude"], "angular");
expect(Util.log).toHaveBeenCalledWith(" Updated .claude/CLAUDE.md");
expect(Util.log).toHaveBeenCalledWith(jasmine.stringContaining("1 instruction file(s) created or updated"));
});
it("logs up-to-date when all instruction files are current", () => {
const content = "# Instructions";
const destFile = ".claude/CLAUDE.md";
const mockFs: IFileSystem = {
fileExists: jasmine.createSpy("fileExists").and.callFake((p: string) =>
p === destFile
),
readFile: jasmine.createSpy("readFile").and.returnValue(content),
writeFile: jasmine.createSpy("writeFile"),
directoryExists: jasmine.createSpy("directoryExists"),
glob: jasmine.createSpy("glob").and.returnValue([])
};
App.container.set(FS_TOKEN, mockFs);
spyOn(FsFileSystem.prototype, "readFile").and.returnValue(content);
App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", {
getFrameworkById: {
projectLibraries: [{
getProject: (id: string) => id === "ai-config" ? { templatePaths: ["/fake/files"] } : null
}]
}
}));
configureInstructions(["claude"], "angular");
expect(Util.log).toHaveBeenCalledWith(jasmine.stringContaining("instruction file(s) already up-to-date"));
});
it("does not log when source content is not found", () => {
const mockFs = createMockFs();
App.container.set(FS_TOKEN, mockFs);
spyOn(FsFileSystem.prototype, "readFile").and.throwError("ENOENT");
App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", {
getFrameworkById: {
projectLibraries: [{
getProject: (id: string) => id === "ai-config" ? { templatePaths: ["/fake/files"] } : null
}]
}
}));
configureInstructions(["claude"], "angular");
expect(Util.log).not.toHaveBeenCalled();
});
it("suppresses per-file messages but keeps summary when verbose is false", () => {
const mockFs = createMockFs();
App.container.set(FS_TOKEN, mockFs);
spyOn(FsFileSystem.prototype, "readFile").and.returnValue("# Instructions content");
App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", {
getFrameworkById: {
projectLibraries: [{
getProject: (id: string) => id === "ai-config" ? { templatePaths: ["/fake/files"] } : null
}]
}
}));
configureInstructions(["claude"], "angular", false);
const logCalls = (Util.log as jasmine.Spy).calls.allArgs().map(a => a[0] as string);
expect(logCalls.some(m => m.includes("Created"))).toBe(false);
expect(Util.log).toHaveBeenCalledWith(jasmine.stringContaining("instruction file(s) created or updated"));
});
});
describe("handler", () => {
beforeEach(() => {
(GoogleAnalytics.post as jasmine.Spy).calls.reset();
App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", {
getFrameworkById: { projectLibraries: [] },
getFrameworkIds: ["angular"],
getFrameworkNames: ["Angular"],
getFrameworkByName: { id: "angular" }
}));
spyOn(Util, "warn");
});
it("prompts for agents when --agent is not provided", async () => {
App.container.set(FS_TOKEN, createMockFs());
spyOn(Util, "canPrompt").and.returnValue(true);
spyOn(InquirerWrapper, "checkbox").and.returnValues(
Promise.resolve(["claude"]),
Promise.resolve(["vscode"])
);
await aiConfig.default.handler({ _: ["ai-config"], $0: "ig", framework: "angular" });
expect(InquirerWrapper.checkbox).toHaveBeenCalledWith(jasmine.objectContaining({
message: "Which AI agents do you want to generate skills and instructions for?",
required: true
}));
expect(GoogleAnalytics.post).toHaveBeenCalledWith(jasmine.objectContaining({ t: "screenview", cd: "Ai Config" }));
expect(GoogleAnalytics.post).toHaveBeenCalledWith(jasmine.objectContaining({ t: "event", ea: "agent: claude; assistant: vscode", cd1: "angular" }));
});
it("uses defaults without prompting when canPrompt returns false", async () => {
App.container.set(FS_TOKEN, createMockFs());
spyOn(Util, "canPrompt").and.returnValue(false);
spyOn(InquirerWrapper, "checkbox");
await aiConfig.default.handler({ _: ["ai-config"], $0: "ig", framework: "angular" });
expect(InquirerWrapper.checkbox).not.toHaveBeenCalled();
expect(GoogleAnalytics.post).toHaveBeenCalledWith(jasmine.objectContaining({ t: "event", ea: "agent: generic, claude; assistant: generic", cd1: "angular" }));
});
it("logs skipping and does not post analytics when none is selected", async () => {
App.container.set(FS_TOKEN, createMockFs());
spyOn(Util, "canPrompt").and.returnValue(true);
spyOn(InquirerWrapper, "checkbox").and.returnValue(Promise.resolve(["none"]));
await aiConfig.default.handler({ _: ["ai-config"], $0: "ig", framework: "angular" });
expect(Util.log).toHaveBeenCalledWith(jasmine.stringContaining("Skipping"));
expect(GoogleAnalytics.post).toHaveBeenCalledWith(jasmine.objectContaining({ t: "screenview", cd: "Ai Config" }));
expect(GoogleAnalytics.post).toHaveBeenCalledWith(jasmine.objectContaining({ t: "event", ea: "agent: none; assistant: none", cd1: "angular" }));
});
it("still configures MCP when none is selected for skills", async () => {
const mockFs = createMockFs();
App.container.set(FS_TOKEN, mockFs);
spyOn(Util, "canPrompt").and.returnValue(true);
spyOn(InquirerWrapper, "checkbox").and.returnValues(
Promise.resolve(["none"]),
Promise.resolve(["vscode"])
);
await aiConfig.default.handler({ _: ["ai-config"], $0: "ig", framework: "angular" });
expect(mockFs.writeFile).toHaveBeenCalled();
const config = writtenConfig(mockFs);
expect(config.servers).toBeDefined();
expect(GoogleAnalytics.post).toHaveBeenCalledWith(jasmine.objectContaining({ t: "screenview", cd: "Ai Config" }));
expect(GoogleAnalytics.post).toHaveBeenCalledWith(jasmine.objectContaining({ ea: "agent: none; assistant: vscode", cd1: "angular" }));
expect(InquirerWrapper.checkbox).toHaveBeenCalledTimes(2);
expect(
(Util.log as jasmine.Spy).calls.allArgs()
.filter(([msg]) => String(msg).includes("Skipping"))
).toHaveSize(1);
expect(Util.log).toHaveBeenCalledWith("No AI configuration selected. Skipping.");
});
it("configures multiple agents when selected interactively", async () => {
App.container.set(FS_TOKEN, createMockFs());
spyOn(Util, "canPrompt").and.returnValue(true);
spyOn(InquirerWrapper, "checkbox").and.returnValues(
Promise.resolve(["claude", "cursor"]),
Promise.resolve(["vscode"])
);
await aiConfig.default.handler({ _: ["ai-config"], $0: "ig", framework: "angular" });
expect(InquirerWrapper.checkbox).toHaveBeenCalledWith(jasmine.objectContaining({
message: "Which AI agents do you want to generate skills and instructions for?"
}));
expect(GoogleAnalytics.post).toHaveBeenCalledWith(jasmine.objectContaining({ ea: "agent: claude, cursor; assistant: vscode", cd1: "angular" }));
});
it("skips prompt when --agent is provided", async () => {
App.container.set(FS_TOKEN, createMockFs());
spyOn(Util, "canPrompt").and.returnValue(true);
spyOn(InquirerWrapper, "checkbox").and.returnValue(Promise.resolve(["vscode"]));
await aiConfig.default.handler({ _: ["ai-config"], $0: "ig", agents: ["cursor"], framework: "angular" });
expect(InquirerWrapper.checkbox).not.toHaveBeenCalledWith(jasmine.objectContaining({
message: "Which AI agents do you want to generate skills and instructions for?"
}));
expect(GoogleAnalytics.post).toHaveBeenCalledWith(jasmine.objectContaining({ ea: "agent: cursor; assistant: vscode", cd1: "angular" }));
});
it("skips assistant prompt when --assistant is provided", async () => {
App.container.set(FS_TOKEN, createMockFs());
spyOn(Util, "canPrompt").and.returnValue(true);
spyOn(InquirerWrapper, "checkbox").and.returnValue(Promise.resolve(["claude"]));
await aiConfig.default.handler({ _: ["ai-config"], $0: "ig", assistants: ["cursor"], framework: "angular" });
expect(InquirerWrapper.checkbox).toHaveBeenCalledTimes(1);
});
it("prompts for assistant with correct message", async () => {
App.container.set(FS_TOKEN, createMockFs());
spyOn(Util, "canPrompt").and.returnValue(true);
spyOn(InquirerWrapper, "checkbox").and.returnValues(
Promise.resolve(["claude"]),
Promise.resolve(["vscode"])
);
await aiConfig.default.handler({ _: ["ai-config"], $0: "ig", framework: "angular" });
expect(InquirerWrapper.checkbox).toHaveBeenCalledWith(jasmine.objectContaining({
message: "Which coding assistants should MCP servers be configured for?"
}));
});
it("writes to correct config path for selected assistant", async () => {
const mockFs = createMockFs();
App.container.set(FS_TOKEN, mockFs);
spyOn(Util, "canPrompt").and.returnValue(true);
spyOn(InquirerWrapper, "checkbox").and.returnValues(
Promise.resolve(["claude"]),
Promise.resolve(["generic"])
);
await aiConfig.default.handler({ _: ["ai-config"], $0: "ig", framework: "angular" });
expect(mockFs.writeFile).toHaveBeenCalledWith(".mcp.json", jasmine.any(String));
const config = writtenConfig(mockFs);
expect((config.mcpServers as any)[IGNITEUI_SERVER_KEY]).toEqual(igniteuiServer);
});
it("logs and returns early when framework is jquery", async () => {
App.container.set(FS_TOKEN, createMockFs());
spyOn(Util, "canPrompt").and.returnValue(true);
spyOn(InquirerWrapper, "checkbox");
await aiConfig.default.handler({ _: ["ai-config"], $0: "ig", framework: "jquery" });
expect(Util.log).toHaveBeenCalledWith("AI Config currently not available for jQuery projects.");
expect(InquirerWrapper.checkbox).not.toHaveBeenCalled();
});
describe("framework resolution", () => {
const NO_DETECT_MESSAGE = "Framework not provided and couldn't detect project from config or structure.";
beforeEach(() => {
App.container.set(FS_TOKEN, createMockFs());
spyOn(Util, "canPrompt").and.returnValue(true);
spyOn(InquirerWrapper, "checkbox").and.returnValue(Promise.resolve(["none"]));
});
it("uses detected framework when --framework is not provided", async () => {
spyOn(coreDetect, "detectFramework").and.returnValue("react");
spyOn(InquirerWrapper, "select");
await aiConfig.default.handler({ _: ["ai-config"], $0: "ig" });
expect(coreDetect.detectFramework).toHaveBeenCalled();
expect(InquirerWrapper.select).not.toHaveBeenCalled();
expect(GoogleAnalytics.post).toHaveBeenCalledWith(jasmine.objectContaining({ t: "event", cd1: "react" }));
});
it("prompts for framework when --framework is absent and detection returns null", async () => {
spyOn(coreDetect, "detectFramework").and.returnValue(null);
spyOn(InquirerWrapper, "select").and.returnValue(Promise.resolve("Angular"));
await aiConfig.default.handler({ _: ["ai-config"], $0: "ig" });
expect(Util.log).toHaveBeenCalledWith(NO_DETECT_MESSAGE);
expect(InquirerWrapper.select).toHaveBeenCalledWith(jasmine.objectContaining({
message: "Choose framework:"
}));
expect(GoogleAnalytics.post).toHaveBeenCalledWith(jasmine.objectContaining({ t: "event", cd1: "angular" }));
});
it("shows framework choices from template manager when prompting", async () => {
spyOn(coreDetect, "detectFramework").and.returnValue(null);
spyOn(InquirerWrapper, "select").and.returnValue(Promise.resolve("Angular"));
await aiConfig.default.handler({ _: ["ai-config"], $0: "ig" });
expect(InquirerWrapper.select).toHaveBeenCalledWith(jasmine.objectContaining({
choices: ["Angular"]
}));
});
it("errors without prompting when framework is absent and canPrompt is false", async () => {
spyOn(coreDetect, "detectFramework").and.returnValue(null);
spyOn(InquirerWrapper, "select");
spyOn(Util, "error");
(Util.canPrompt as jasmine.Spy).and.returnValue(false);
await aiConfig.default.handler({ _: ["ai-config"], $0: "ig" });
expect(InquirerWrapper.select).not.toHaveBeenCalled();
expect(Util.log).toHaveBeenCalledWith(NO_DETECT_MESSAGE);
expect(Util.error).toHaveBeenCalledWith("Please provide --framework argument.", "red");
});
it("errors when provided framework is not supported", async () => {
spyOn(Util, "error");
// override the spy to return undefined (unknown framework)
(App.container.get(TEMPLATE_MANAGER) as jasmine.SpyObj<any>)
.getFrameworkById.and.returnValue(undefined);
await aiConfig.default.handler({ _: ["ai-config"], $0: "ig", framework: "unknown" });
expect(Util.error).toHaveBeenCalledWith("Framework not supported", "red");
});
});
});
});