Skip to content

Commit 50559f2

Browse files
committed
test(init): restructure built-in skills describes and cover --built-in + template
Addresses review feedback on PR #60: - Move the 'built-in skills prompt (interactive init without template)' and 'built-in skills in non-interactive environments (CI)' describe blocks out of 'init command template mode' and make them siblings under a single outer 'init command' describe. The previous nesting implied these scenarios ran under template mode when they test the opposite, which is misleading when a single describe is selected by name. - Add two test cases in the 'template mode' describe that pin down the silent-ignore behavior of --built-in when a template is in play: once with skills declared (template skills install, no built-in path), once without (no install at all). This closes a previously untested invariant that future refactors could otherwise break. No production code changes. 14 init tests across 3 sibling describes.
1 parent 0e05326 commit 50559f2

1 file changed

Lines changed: 44 additions & 8 deletions

File tree

packages/cli/src/__tests__/commands/init.test.ts

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jest.mock('../../util/terminal', () => ({
8888

8989
import { initCommand } from '../../commands/init';
9090

91-
describe('init command template mode', () => {
91+
describe('init command', () => {
9292
beforeEach(() => {
9393
jest.clearAllMocks();
9494
process.exitCode = undefined;
@@ -121,7 +121,8 @@ describe('init command template mode', () => {
121121
process.exitCode = undefined;
122122
});
123123

124-
it('uses template values and installs multiple skills from same registry without prompts', async () => {
124+
describe('template mode', () => {
125+
it('uses template values and installs multiple skills from same registry without prompts', async () => {
125126
mockLoadInitTemplate.mockResolvedValue({
126127
environments: ['codex'],
127128
phases: ['requirements', 'design'],
@@ -192,14 +193,49 @@ describe('init command template mode', () => {
192193
expect(mockUi.warning).toHaveBeenCalledWith('Initialization cancelled.');
193194
});
194195

195-
it('sets non-zero exit code when template loading fails', async () => {
196-
mockLoadInitTemplate.mockRejectedValue(new Error('Invalid template at /tmp/init.yaml: bad field'));
196+
it('sets non-zero exit code when template loading fails', async () => {
197+
mockLoadInitTemplate.mockRejectedValue(new Error('Invalid template at /tmp/init.yaml: bad field'));
197198

198-
await initCommand({ template: '/tmp/init.yaml' });
199+
await initCommand({ template: '/tmp/init.yaml' });
199200

200-
expect(mockUi.error).toHaveBeenCalledWith('Invalid template at /tmp/init.yaml: bad field');
201-
expect(process.exitCode).toBe(1);
202-
expect(mockConfigManager.setEnvironments).not.toHaveBeenCalled();
201+
expect(mockUi.error).toHaveBeenCalledWith('Invalid template at /tmp/init.yaml: bad field');
202+
expect(process.exitCode).toBe(1);
203+
expect(mockConfigManager.setEnvironments).not.toHaveBeenCalled();
204+
});
205+
206+
it('silently ignores --built-in when the template declares skills', async () => {
207+
mockLoadInitTemplate.mockResolvedValue({
208+
environments: ['codex'],
209+
phases: ['requirements'],
210+
skills: [{ registry: 'codeaholicguy/ai-devkit', skill: 'debug' }]
211+
});
212+
213+
await initCommand({ template: './init.yaml', builtIn: true });
214+
215+
expect(mockSkillManager.addSkill).toHaveBeenCalledTimes(1);
216+
expect(mockSkillManager.addSkill).toHaveBeenCalledWith('codeaholicguy/ai-devkit', 'debug');
217+
const builtinPrompts = mockPrompt.mock.calls.filter((call: any[]) => {
218+
const questions = call[0];
219+
return Array.isArray(questions) && questions.some((q: any) => q?.name === 'installBuiltinSkills');
220+
});
221+
expect(builtinPrompts).toHaveLength(0);
222+
});
223+
224+
it('silently ignores --built-in when the template has no skills declared', async () => {
225+
mockLoadInitTemplate.mockResolvedValue({
226+
environments: ['codex'],
227+
phases: ['requirements']
228+
});
229+
230+
await initCommand({ template: './init.yaml', builtIn: true });
231+
232+
expect(mockSkillManager.addSkill).not.toHaveBeenCalled();
233+
const builtinPrompts = mockPrompt.mock.calls.filter((call: any[]) => {
234+
const questions = call[0];
235+
return Array.isArray(questions) && questions.some((q: any) => q?.name === 'installBuiltinSkills');
236+
});
237+
expect(builtinPrompts).toHaveLength(0);
238+
});
203239
});
204240

205241
describe('built-in skills prompt (interactive init without template)', () => {

0 commit comments

Comments
 (0)